* Invision Power Services * IP.Board v3.1.4 * ACP Restrictions * Last Updated: $Date: 2010-06-02 18:28:28 -0400 (Wed, 02 Jun 2010) $ * * * @author $Author: bfarber $ * @copyright (c) 2001 - 2009 Invision Power Services, Inc. * @license http://www.invisionpower.com/community/board/license.html * @package IP.Board * @subpackage Members * @link http://www.invisionpower.com * @since 1st march 2002 * @version $Revision: 6445 $ * */ if ( ! defined( 'IN_ACP' ) ) { print "
';print_r( $perms );exit();
//-------------------------------
// Print
//-------------------------------
$this->registry->output->html .= $this->html->restrictionsForm( $row_id, $type, $perms, $row['current'] );
}
/**
* List members and groups with restrictions
*
* @access private
* @return void Outputs to screen
* @since 2.1.0.2005-7-7
*/
private function _acppermsList()
{
//-------------------------------
// INIT
//-------------------------------
$members = '';
$groups = '';
//-------------------------------
// Get current ACP listed members
//-------------------------------
$this->DB->build( array( 'select' => 'p.*',
'from' => array( 'admin_permission_rows' => 'p' ),
'add_join' => array(
array(
'select' => 'm.members_display_name, m.member_id, m.member_group_id, m.mgroup_others',
'from' => array( 'members' => 'm' ),
'where' => "p.row_id_type='member' AND m.member_id=p.row_id",
'type' => 'left'
)
),
'order' => 'm.members_display_name DESC'
) );
$outer = $this->DB->execute();
while( $r = $this->DB->fetch($outer) )
{
//-------------------------------
// (Alex) Cross
//-------------------------------
$r['_date'] = ipsRegistry::getClass('class_localization')->getDate( $r['row_updated'], 'SHORT' );
if( $r['row_id_type'] == 'member' )
{
$r['_group_name'] = $this->caches['group_cache'][ $r['member_group_id'] ]['g_title'];
$r['_other_groups'] = 'Нет';
$_other_mgroups = IPSText::cleanPermString( $r['mgroup_others'] );
if( $_other_mgroups )
{
$other_mgroups = explode( ',', $_other_mgroups );
$formatted = array();
if( is_array($other_mgroups) AND count($other_mgroups) )
{
foreach( $other_mgroups as $omg )
{
$formatted[] = $this->caches['group_cache'][ $omg ]['g_title'];
}
$r['_other_groups'] = implode( ', ', $formatted );
}
}
$members .= $this->html->acpMemberRow($r);
}
else
{
$count = $this->DB->buildAndFetch(
array(
'select' => 'count(*) as total',
'from' => 'members',
'where' => "member_group_id = {$r['row_id']} OR mgroup_others LIKE '%,{$r['row_id']},%'",
)
);
$r['_group_name'] = $this->caches['group_cache'][ $r['row_id'] ]['g_title'];
$r['_total'] = $count['total'];
$groups .= $this->html->acpGroupRow($r);
}
}
$this->registry->output->html .= $this->html->acpPermsOverview( $members, $groups );
}
/**
* Remove ACP restrictions - this will make a restricted member or group have full permissions
*
* @access private
* @param string [member|group]
* @return void
* @since 2.1.0.2005-7-11
*/
private function _removePermissions( $type='member' )
{
//-------------------------------
// INIT
//-------------------------------
$row_id = $type == 'member' ? intval( $this->request['mid'] ) : intval( $this->request['gid'] );
//-------------------------------
// Check...
//-------------------------------
if ( ! $row_id )
{
$this->registry->output->global_message = sprintf( $this->lang->words['r_notypeid'], $type );
$this->_acppermsList();
return;
}
//-------------------------------
// Remove member's row
//-------------------------------
$this->DB->delete( 'admin_permission_rows', 'row_id=' . $row_id );
//-------------------------------
// Print
//-------------------------------
$this->registry->output->global_message = $this->lang->words['r_lifted'];
$this->_acppermsList();
}
/**
* ACP Perms: Add member form
*
* @access private
* @param string [member|group]
* @return void
* @since 2.1.0.2005-7-7
*/
private function _addRole( $type='member' )
{
$this->registry->output->extra_nav[] = array( '', $this->lang->words['r_nav'] );
//-------------------------------
// Show the form
//-------------------------------
$method = $type == 'member' ? 'restrictionsMemberForm' : 'restrictionsGroupForm';
$this->registry->output->html .= $this->html->$method();
}
/**
* ACP Perms: Finish adding the member
*
* Checks input, adds row to DB if OK
* This bud's for you
*
* @access private
* @return void
* @since 2.1.0.2005-7-8
*/
private function _addMemberDo()
{
//-------------------------------
// INIT
//-------------------------------
$name = trim( $this->request['entered_name'] );
$isok = 0;
//-------------------------------
// Check...
//-------------------------------
if ( ! $name )
{
$this->registry->output->global_message = $this->lang->words['r_entername'];
$this->_addRole( 'member' );
return;
}
//-------------------------------
// Get member...
//-------------------------------
$member = IPSMember::load( $name, 'groups' , 'displayname' );
//-------------------------------
// Check...
//-------------------------------
if ( ! $member['member_id'] )
{
$this->registry->output->global_message = sprintf( $this->lang->words['r_noname'], $name );
$this->_addRole( 'member' );
return;
}
//-------------------------------
// Already got 'em
//-------------------------------
$test = $this->DB->buildAndFetch( array( 'select' => 'row_id', 'from' => 'admin_permission_rows', 'where' => "row_id_type='member' AND row_id=" . $member['member_id'] ) );
if ( $test['row_id'] )
{
$this->registry->output->global_message = sprintf( $this->lang->words['r_namealready'], $name );
$this->_addRole( 'member' );
return;
}
//-------------------------------
// Don't restrict ourselves
//-------------------------------
if( $member['member_id'] == $this->memberData['member_id'] )
{
$this->registry->output->global_message = $this->lang->words['r_ownaccount'];
$this->_addRole( 'member' );
return;
}
//-------------------------------
// Primary ACP group?
//-------------------------------
if ( $member['g_access_cp'] )
{
$isok = 1;
}
//-------------------------------
// Secondary ACP group?
//-------------------------------
else if ( $member['mgroup_others'] )
{
foreach( explode( ',', IPSText::cleanPermString( $member['mgroup_others'] ) ) as $gid )
{
if ( $this->caches['group_cache'][ $gid ]['g_access_cp'] )
{
$isok = 1;
break;
}
}
}
//-------------------------------
// Not oK?
//-------------------------------
if ( ! $isok )
{
$this->registry->output->global_message = sprintf( $this->lang->words['r_noaccess'], $member['members_display_name'] );
$this->_addRole( 'member' );
return;
}
//-------------------------------
// Does we haz groop perms?
// Too many LOLCATZ >.<
//-------------------------------
$groups[] = $member['member_group_id'];
$restrict = array();
if( $member['mgroup_others'] )
{
$groups = array_merge( $groups, explode( ',', IPSText::cleanPermString( $member['mgroup_others'] ) ) );
}
$this->DB->build( array( 'select' => '*', 'from' => 'admin_permission_rows', 'where' => "row_id_type='group' AND row_id IN(" . implode( ',', $groups ) . ")" ) );
$this->DB->execute();
while( $r = $this->DB->fetch() )
{
$restrict = array_merge( $restrict, unserialize($r['row_perm_cache']) );
}
//-------------------------------
// A-OK
//-------------------------------
$this->DB->insert( 'admin_permission_rows', array( 'row_id' => $member['member_id'],
'row_id_type' => 'member',
'row_perm_cache' => serialize( $restrict ),
'row_updated' => time() ) );
$message = count($restrict) ? $this->lang->words['r_restrictbase'] : $this->lang->words['r_noacpaccessuntil'];
$this->registry->output->global_message = sprintf( $this->lang->words['r_addedmember'], $member['members_display_name'], $message );
$this->request[ 'mid'] = $member['member_id'] ;
$this->_restrictionsForm( 'member' );
}
/**
* ACP Perms: Finish adding the group
*
* @access private
* @return void
* @since 2.1.0.2005-7-8
*/
private function _addGroupDo()
{
//-------------------------------
// INIT
//-------------------------------
$g_id = intval( $this->request['entered_group'] );
$isok = 0;
//-------------------------------
// Check...
//-------------------------------
if ( !$g_id )
{
$this->registry->output->global_message = $this->lang->words['r_nogroup'];
$this->_addRole( 'group' );
return;
}
//-------------------------------
// Get member...
//-------------------------------
$group = $this->caches['group_cache'][ $g_id ];
//-------------------------------
// Check...
//-------------------------------
if ( ! $group['g_id'] )
{
$this->registry->output->global_message = $this->lang->words['r_nofindgroup'];
$this->_addRole( 'group' );
return;
}
//-------------------------------
// Already got 'em
//-------------------------------
$test = $this->DB->buildAndFetch( array( 'select' => 'row_id', 'from' => 'admin_permission_rows', 'where' => "row_id_type='group' AND row_id=" . $g_id ) );
if ( $test['row_id'] )
{
$this->registry->output->global_message = sprintf( $this->lang->words['r_groupalready'], $group['g_title'] );
$this->_addRole( 'group' );
return;
}
//-------------------------------
// Don't restrict ourselves
//-------------------------------
if( $g_id == $this->memberData['member_group_id'] )
{
$this->registry->output->global_message = $this->lang->words['r_ownaccount'];
$this->_addRole( 'group' );
return;
}
if( in_array( $g_id, explode( ',', IPSText::cleanPermString( $this->memberData['mgroup_others'] ) ) ) )
{
$this->registry->output->global_message = $this->lang->words['r_ownaccount'];
$this->_addRole( 'group' );
return;
}
//-------------------------------
// Primary ACP group?
//-------------------------------
if ( !$group['g_access_cp'] )
{
$this->registry->output->global_message = sprintf( $this->lang->words['r_groupnoacp'], $group['g_title'] );
$this->_addRole( 'group' );
return;
}
//-------------------------------
// A-OK
//-------------------------------
$this->DB->insert( 'admin_permission_rows', array( 'row_id' => $g_id,
'row_id_type' => 'group',
'row_perm_cache' => serialize( array() ),
'row_updated' => time() ) );
$this->registry->output->global_message = sprintf( $this->lang->words['r_addedgroup'], $group['g_title'] );
$this->_acppermsList();
}
}