array(
'controller' => 'users_admin_ui',
'path' => null,
'ui' => 'users_admin_form_ui',
'uipath' => null,
//'perm' => '0',
)
);
protected $adminMenu = array(
'main/list' => array('caption'=> LAN_MANAGE, 'perm' => '0'),
'main/add' => array('caption'=> LAN_USER_QUICKADD, 'perm' => '4|U0|U1'),
'main/prefs' => array('caption'=> LAN_OPTIONS, 'perm' => '4|U2'),
'main/ranks' => array('caption'=> LAN_USER_RANKS, 'perm' => '4|U3')
);
/*
FIXME - move user prune to Schedule tasks (cron)
$var ['prune']['text'] = LAN_USER_PRUNE;
$var ['prune']['link'] = e_ADMIN.'users.php?action=prune';// Will be moved to "Schedule tasks"
$var ['prune']['perm'] = '4';
*/
protected $adminMenuAliases = array(
'main/edit' => 'main/list',
'main/admin' => 'main/list',
'main/userclass'=> 'main/list',
'main/test' => 'main/list',
);
protected $menuTitle = 'users';
/**
* Run observers/headers override
*
* @return users_admin
*/
public function runObservers($run_header = true)
{
// Catch useraction
if (isset($_POST['useraction']))
{
if(is_array($_POST['useraction']))
{
foreach ($_POST['useraction'] as $key => $val)
{
if ($val)
{
$_POST['useraction'] = $val;
$_POST['userip'] = $_POST['userip'][$key];
$_POST['userid'] = (int) $key;
break;
}
}
}
// FIXME IMPORTANT - permissions per action/trigger
// map useraction to UI trigger
switch ($_POST['useraction'])
{
### etrigger_delete
case 'deluser':
if($_POST['userid'])
{
$id = $_POST['userid'];
$_POST['etrigger_delete'] = array($id => $id);
$user = e107::getDb()->retrieve('user', 'user_email, user_name', 'user_id='.$id);
// TODO lan
$this->getController()->deleteConfirmMessage = "You are about to delete {$user['user_name']} ({$user['user_email']}) with ID #{$id}. Are you sure?";//
}
break;
// map to List{USERACTION}Trigger()
case 'unban':
case 'ban':
case 'verify':
case 'reqverify':
case 'resend':
case 'loginas':
case 'unadmin':
$_POST['etrigger_'.$_POST['useraction']] = $_POST['userid'];
break;
// redirect to AdminObserver/AdminPage()
case 'admin':
case 'adminperms':
$this->getRequest()
->setQuery(array())
->setMode('main')
->setAction('admin')
->setId($_POST['userid']);
$this->getController()->redirect();
break;
// redirect to UserclassObserver/UserclassPage()
case 'userclass':
$this->getRequest()
->setQuery(array())
->setMode('main')
->setAction('userclass')
->setId($_POST['userid']);
$this->getController()->redirect();
break;
// redirect to TestObserver/TestPage
case 'test':
$this->getRequest()
->setQuery(array())
->setMode('main')
->setAction('test')
->setId($_POST['userid']);
$this->getController()->redirect();
break;
// redirect to TestObserver/TestPage
case 'usersettings':
$this->getRequest()
->setQuery(array())
->setMode('main')
->setAction('edit')
->setId($_POST['userid']);
$this->getController()->redirect();
//XXX Broken to the point of being unusable. //header('location:'.e107::getUrl()->create('user/profile/edit', 'id='.(int) $_POST['userid'], 'full=1&encode=0'));
// exit;
break;
}
}
return parent::runObservers($run_header);
}
}
class users_admin_ui extends e_admin_ui
{
protected $pluginTitle = LAN_USER;
protected $pluginName = 'core';
protected $table = "user";
// protected $listQry = "SELECT SQL_CALC_FOUND_ROWS * FROM #users"; // without any Order or Limit.
protected $listQry = "SELECT SQL_CALC_FOUND_ROWS u.*,ue.* from #user AS u left join #user_extended AS ue ON u.user_id = ue.user_extended_id "; // without any Order or Limit.
protected $editQry = "SELECT u.*,ue.* FROM #user AS u left join #user_extended AS ue ON u.user_id = ue.user_extended_id WHERE user_id = {ID}";
protected $pid = "user_id";
protected $perPage = 10;
protected $batchDelete = true;
protected $listOrder = 'user_id DESC';
/**
* Show confirm screen before (batch/single) delete
* @var boolean
*/
public $deleteConfirmScreen = true;
/**
* @var boolean
*/
protected $batchCopy = false;
/**
* List (numerical array) of only disallowed for this controller actions
*/
protected $disallow = array('create');
protected $tabs = array('Basic', 'Extended');
//TODO - finish 'user' type, set 'data' to all editable fields, set 'noedit' for all non-editable fields
protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'user_id' => array('title' => LAN_ID, 'tab'=>0, 'type' =>'integer', 'width' => '5%','forced' => true),
// 'user_status' => array('title' => LAN_STATUS, 'type' => 'method', 'alias'=>'user_status', 'width' => 'auto','forced' => true, 'nosort'=>TRUE),
'user_ban' => array('title' => LAN_STATUS, 'tab'=>0, 'type' => 'method', 'width' => 'auto', 'filter'=>true, 'batch'=>true,'thclass'=>'center', 'class'=>'center'),
'user_name' => array('title' => LAN_USER_01, 'tab'=>0, 'type' => 'text', 'data'=>'str', 'width' => 'auto','thclass' => 'left first'), // Display name
'user_loginname' => array('title' => LAN_USER_02, 'tab'=>0, 'type' => 'text', 'data'=>'str', 'width' => 'auto'), // User name
'user_login' => array('title' => LAN_USER_03, 'tab'=>0, 'type' => 'text', 'data'=>'str', 'width' => 'auto'), // Real name (no real vetting)
'user_customtitle' => array('title' => LAN_USER_04, 'tab'=>0, 'type' => 'text', 'data'=>'str', 'width' => 'auto'), // No real vetting
'user_password' => array('title' => LAN_USER_05, 'tab'=>0, 'type' => 'method', 'data'=>'str', 'width' => 'auto'), //TODO add md5 option to form handler?
'user_sess' => array('title' => 'Session', 'tab'=>0, 'noedit'=>true, 'type' => 'text', 'width' => 'auto'), // Photo
'user_image' => array('title' => LAN_USER_07, 'tab'=>0, 'type' => 'dropdown', 'data'=>'str', 'width' => 'auto'), // Avatar
'user_email' => array('title' => LAN_EMAIL, 'tab'=>0, 'type' => 'text', 'inline'=>true, 'data'=>'str', 'width' => 'auto'),
'user_hideemail' => array('title' => LAN_USER_10, 'tab'=>0, 'type' => 'boolean', 'data'=>'int', 'width' => 'auto', 'thclass'=>'center', 'class'=>'center', 'filter'=>true, 'batch'=>true, 'readParms'=>'trueonly=1'),
'user_xup' => array('title' => 'Xup', 'tab'=>0, 'noedit'=>true, 'type' => 'text', 'width' => 'auto'),
'user_class' => array('title' => LAN_USER_12, 'tab'=>0, 'type' => 'userclasses' , 'inline'=>true, 'writeParms' => 'classlist=classes', 'inline'=>true, 'filter'=>true, 'batch'=>true),
'user_join' => array('title' => LAN_USER_14, 'tab'=>0, 'noedit'=>true, 'type' => 'datestamp', 'width' => 'auto', 'writeParms'=>'readonly=1'),
'user_lastvisit' => array('title' => LAN_USER_15, 'tab'=>0, 'noedit'=>true, 'type' => 'datestamp', 'width' => 'auto'),
'user_currentvisit' => array('title' => LAN_USER_16, 'tab'=>0, 'noedit'=>true, 'type' => 'datestamp', 'width' => 'auto'),
'user_comments' => array('title' => LAN_USER_17, 'tab'=>0, 'noedit'=>true, 'type' => 'int', 'width' => 'auto','thclass'=>'right','class'=>'right'),
'user_lastpost' => array('title' => 'Last Post', 'tab'=>0, 'noedit'=>true, 'type' => 'datestamp', 'width' => 'auto'),
'user_ip' => array('title' => LAN_USER_18, 'tab'=>0, 'noedit'=>true, 'type' => 'ip', 'width' => 'auto'),
// 'user_prefs' => array('title' => LAN_USER_20, 'type' => 'text', 'width' => 'auto'),
'user_visits' => array('title' => LAN_USER_21, 'tab'=>0, 'noedit'=>true, 'type' => 'int', 'width' => 'auto','thclass'=>'right','class'=>'right'),
'user_admin' => array('title' => LAN_USER_22, 'tab'=>0, 'type' => 'boolean', 'width' => 'auto', 'thclass'=>'center', 'class'=>'center', 'filter'=>true, 'batch'=>true, 'readParms'=>'trueonly=1'),
'user_perms' => array('title' => LAN_USER_23, 'tab'=>0, 'type' => 'method', 'data'=>'str', 'width' => 'auto'),
'user_pwchange' => array('title' => LAN_USER_24, 'tab'=>0, 'noedit'=>true, 'type'=>'datestamp' , 'width' => 'auto'),
);
protected $fieldpref = array('user_ban','user_name','user_loginname','user_login','user_email','user_class','user_admin');
protected $prefs = array(
// 'anon_post' => array('title'=>PRFLAN_32, 'type'=>'boolean'),
'avatar_upload' => array('title' => USRLAN_44, 'type' => 'boolean', 'writeParms' => 'label=yesno', 'data' => 'int',),
'photo_upload' => array('title' => USRLAN_53, 'type' => 'boolean', 'writeParms' => 'label=yesno', 'data' => 'int',),
'im_width' => array('title' => USRLAN_47, 'type' => 'number', 'writeParms' => array('maxlength' => 4), 'help' => USRLAN_48, 'data' => 'int', ),
'im_height' => array('title' => USRLAN_49, 'type' => 'number', 'writeParms' => array('maxlength' => 4), 'help' => USRLAN_50, 'data' => 'int', ),
'profile_rate' => array('title' => USRLAN_126, 'type' => 'boolean', 'writeParms' => 'label=yesno', 'data' => 'int',),
'profile_comments' => array('title' => USRLAN_127, 'type' => 'boolean', 'writeParms' => 'label=yesno', 'data' => 'int',),
'force_userupdate' => array('title' => USRLAN_133, 'type' => 'boolean', 'writeParms' => 'label=yesno', 'help' => USRLAN_134, 'data' => 'int',),
'del_unv' => array('title' => USRLAN_93, 'type' => 'number', 'writeParms' => array('maxlength' => 5, 'post' => USRLAN_95), 'help' => USRLAN_94, 'data' => 'int',),
'track_online' => array('title' => USRLAN_130, 'type' => 'boolean', 'writeParms' => 'label=yesno', 'help' => USRLAN_131, 'data' => 'int',),
'memberlist_access' => array('title' => USRLAN_146, 'type' => 'userclass', 'writeParms' => 'classlist=public,member,guest,admin,main,classes,nobody', 'data' => 'int',),
'signature_access' => array('title' => USRLAN_194, 'type' => 'userclass', 'writeParms' => 'classlist=member,admin,main,classes,nobody', 'data' => 'int',),
'user_new_period' => array('title' => USRLAN_190, 'type' => 'number', 'writeParms' => array('maxlength' => 3, 'post' => LANDT_04s), 'help' => USRLAN_191, 'data' => 'int',),
);
protected $extended = array();
function init()
{
$sql = e107::getDb();
$tp = e107::getParser();
if($this->getAction() == 'edit')
{
$this->fields['user_class']['noedit'] = true;
}
// Extended fields - FIXME - better field types
if($sql->select('user_extended_struct', 'user_extended_struct_name,user_extended_struct_text', "user_extended_struct_type > 0 AND user_extended_struct_text != '_system_' ORDER BY user_extended_struct_parent ASC"))
{
// TODO FIXME use the handler to build fields and field attributes
// FIXME a way to load 3rd party language files for extended user fields
e107::coreLan('user_extended');
while ($row = $sql->fetch())
{
$field = "user_".$row['user_extended_struct_name'];
$title = ucfirst(str_replace("user_","",$field));
$label = $tp->toHtml($row['user_extended_struct_text'],false,'defs');
$this->fields[$field] = array('title' => $label,'width' => 'auto', 'data'=>false,'type'=>'text', 'tab'=>1, 'noedit'=>false);
$this->extended[] = $field;
}
}
$this->fields['user_signature']['writeParms']['data'] = e107::getUserClass()->uc_required_class_list("classes");
$this->fields['user_signature'] = array('title' => LAN_USER_09, 'type' => 'textarea', 'data'=>'str', 'width' => 'auto');
$this->fields['options'] = array('title'=> LAN_OPTIONS, 'type' => 'method', 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last', 'class' => 'left');
if(!getperms('4|U0')) // Quick Add User Access Only.
{
unset($this->fields['checkboxes']);
unset($this->fields['options']);
}
$this->fields['user_image']['writeParms'] = $this->getAvatarList();
//FIXME - handle user extended search...
//$this->_alias_parsed = false;
//$this->parseAliases();
// if(isset ($_POST['adduser']))
// {
// addUser();
// }
}
protected function getAvatarList()
{
$avs = array(''=>LAN_NONE);
$upload = array();
$sys = array();
$uploaded = e107::getFile()->get_files(e_AVATAR_UPLOAD);
foreach($uploaded as $f)
{
$id = '-upload-'.$f['fname'];
$upload[$id] = $f['fname'];
}
$system = e107::getFile()->get_files(e_AVATAR_DEFAULT);
foreach($system as $f)
{
$id = $f['fname'];
$sys[$id] = $f['fname'];
}
$avs['uploaded'] = $upload;
$avs['system'] = $sys;
return $avs;
}
public function beforeUpdate($new_data, $old_data, $id)
{
$tp = e107::getParser();
if(empty($new_data['user_password']))
{
$new_data['user_password'] = $old_data['user_password'];
}
else
{
$new_data['user_password'] = md5($new_data['user_password']); //TODO add support for salted passwords etc.
}
if(!empty($new_data['perms']))
{
$new_data['user_perms'] = implode(".",$new_data['perms']);
}
// Handle the Extended Fields.
$update = array();
foreach($this->extended as $key) // Grab Extended field data.
{
$update[$key] = ($new_data[$key]);
}
if(!empty($update))
{
if(!e107::getDb()->count('user_extended', '(user_extended_id)', "user_extended_id=".intval($new_data['submit_value'])))
{
$update['user_extended_id'] = intval($new_data['submit_value']);
if(e107::getDb()->insert('user_extended', $update))
{
e107::getMessage()->addSuccess('Extended Fields Updated'); //TODO Replace with Generic or existing LAN.
}
else
{
e107::getMessage()->addError('Extended Fields Update Failed'); //TODO Replace with Generic or existing LAN.
e107::getMessage()->addDebug(print_a($update,true));
}
}
else
{
$update['WHERE'] = 'user_extended_id='. intval($new_data['submit_value']);
if(e107::getDb()->update('user_extended',$update))
{
e107::getMessage()->addSuccess('Extended Fields Updated'); //TODO Replace with Generic or existing LAN.
}
else
{
e107::getMessage()->addError('Extended Fields Update Failed'); //TODO Replace with Generic or existing LAN.
e107::getMessage()->addDebug(print_a($update,true));
}
}
}
return $new_data;
}
/**
* Unban user trigger
* @param int $userid
* @return void
*/
public function ListUnbanTrigger($userid)
{
$sql = e107::getDb();
$sysuser = e107::getSystemUser($userid, false);
if(!$sysuser->getId())
{
// TODO lan
e107::getMessage()->addError('User not found.');
return;
}
$sql->db_Update("user", "user_ban='0' WHERE user_id='".$userid."' ");
$sql->db_Delete("banlist"," banlist_ip='{$row['user_ip']}' ");
e107::getAdminLog()->log_event('USET_06', str_replace(array('--UID--', '--NAME--', '--EMAIL--'), array($sysuser->getId(), $sysuser->getName(), $sysuser->getValue('email')), USRLAN_162), E_LOG_INFORMATIVE);
e107::getMessage()->addSuccess("(".$sysuser->getId().".".$sysuser->getName()." - ".$sysuser->getValue('email').") ".USRLAN_9);
// List data reload
$this->getTreeModel()->load(true);
}
/**
* Ban user trigger
* @param int $userid
* @return void
*/
public function ListBanTrigger($userid)
{
$sql = e107::getDb();
$mes = e107::getMessage();
$admin_log = e107::getAdminLog();
$iph = e107::getIPHandler();
$sysuser = e107::getSystemUser($userid, false);
if(!$sysuser->getId())
{
// TODO lan
$mes->addError('User not found.');
return;
}
$row = $sysuser->getData();
if (($row['user_perms'] == "0") || ($row['user_perms'] == "0."))
{
$mes->addWarning(USRLAN_7);
}
else
{
if ($sql->update("user","user_ban='1' WHERE user_id='".$userid."' "))
{
e107::getLog()->add('USET_05', str_replace(array('--UID--','--NAME--'), array($row['user_id'], $row['user_name']), USRLAN_161), E_LOG_INFORMATIVE);
$mes->addSuccess("(".$userid.".".$row['user_name']." - {$row['user_email']}) ".USRLAN_8);
}
if (trim($row['user_ip']) == "")
{
$mes->addInfo(USRLAN_135);
}
else
{
if($sql->count('user', '(*)', "user_ip = '{$row['user_ip']}' AND user_ban=0 AND user_id <> {$userid}") > 0)
{
// Other unbanned users have same IP address
$mes->addWarning(str_replace("{IP}", $iph->ipDecode($row['user_ip']), USRLAN_136));
}
else
{
if ($iph->add_ban(6, USRLAN_149.$row['user_name'].'/'.$row['user_loginname'], $row['user_ip'], USERID))
{
// Successful IP ban
$mes->addSuccess(str_replace("{IP}", $iph->ipDecode($row['user_ip']), USRLAN_137));
}
else
{
// IP address on whitelist
$mes->addWarning(str_replace("{IP}", $iph->ipDecode($row['user_ip']), USRLAN_150));
}
}
}
}
// List data reload
$this->getTreeModel()->load(true);
}
/**
* Activate user trigger
*/
public function ListVerifyTrigger($userid)
{
$e_event = e107::getEvent();
$admin_log = e107::getAdminLog();
$sysuser = e107::getSystemUser($userid, false);
$userMethods = e107::getUserSession();
$mes = e107::getMessage();
$uid = intval($userid);
if ($sysuser->getId())
{
$sysuser->set('user_ban', '0')
->set('user_sess', '');
$row = $sysuser->getData();
if ($userMethods->userClassUpdate($row, 'userall'))
{
$sysuser->set('user_class', $row['user_class']);
}
$userMethods->addNonDefaulted($row);
$sysuser->setData($row)->save();
e107::getLog()->add('USET_10', str_replace(array('--UID--', '--NAME--', '--EMAIL--'), array($sysuser->getId(), $sysuser->getName(), $sysuser->getValue('email')), USRLAN_166), E_LOG_INFORMATIVE);
$e_event->trigger('userfull', $row);
$mes->addSuccess(USRLAN_86." (#".$sysuser->getId()." : ".$sysuser->getName().' - '.$sysuser->getValue('email').")");
$this->getTreeModel()->load(true);
if ((int) e107::pref('core', 'user_reg_veri') == 2)
{
$message = USRLAN_114." ".$row['user_name'].",\n\n".USRLAN_122." ".SITENAME.".\n\n".USRLAN_123."\n\n";
$message .= str_replace("{SITEURL}", SITEURL, USRLAN_139);
$options = array(
'mail_subject' => USRLAN_113.' '.SITENAME,
'mail_body' => nl2br($message),
);
if($sysuser->email('email', $options))
{
// TODO lan
$mes->addSuccess("Email sent to: ".$sysuser->getName().' ('.$sysuser->getValue('email').')');
}
else
{
$mes->addError("Failed to send email to: ".$sysuser->getName().' ('.$sysuser->getValue('email').')');
}
}
}
else
{
// TODO lan
$mes->addError('User not found.');
return;
}
}
/**
* Main admin login as system user trigger
*/
public function ListLoginasTrigger($userid)
{
$mes = e107::getMessage();
if(e107::getUser()->getSessionDataAs())
{
$mes->addWarning(USRLAN_AS_3);
}
elseif(e107::getUser()->loginAs($userid))
{
$sysuser = e107::getSystemUser($userid);
$user = e107::getUser();
// TODO - lan
$mes->addSuccess('Successfully logged in as '.$sysuser->getName().' [logout]')
->addSuccess('Please, Leave Admin to browse the system as this user. Use "Logout" option in Administration to end front-end session');
$search = array('--UID--', '--NAME--', '--EMAIL--', '--ADMIN_UID--', '--ADMIN_NAME--', '--ADMIN_EMAIL--');
$replace = array($sysuser->getId(), $sysuser->getName(), $sysuser->getValue('email'), $user->getId(), $user->getName(), $user->getValue('email'));
// TODO - lan
$lan = 'Administrator --ADMIN_EMAIL-- (#--ADMIN_UID--, --ADMIN_NAME--) has logged in as the user --EMAIL-- (#--UID--, --NAME--)';
e107::getAdminLog()->log_event('USET_100', str_replace($search, $replace, $lan), E_LOG_INFORMATIVE);
e107::getEvent()->trigger('loginas', array('user_id' => $sysuser->getId(), 'admin_id' => $user->getId()));
}
}
/**
* Main admin logout as a system user trigger
*/
public function LogoutasObserver()
{
$user = e107::getUser();
$sysuser = e107::getSystemUser($user->getSessionDataAs(), false);
if(e107::getUser()->logoutAs() && $sysuser && $sysuser->getId())
{
// TODO - lan
e107::getMessage()->addSuccess('Successfully logged out from '.$sysuser->getName().' ('.$sysuser->getValue('email').') account', 'default', true);
$search = array('--UID--', '--NAME--', '--EMAIL--', '--ADMIN_UID--', '--ADMIN_NAME--', '--ADMIN_EMAIL--');
$replace = array($sysuser->getId(), $sysuser->getName(), $sysuser->getValue('email'), $user->getId(), $user->getName(), $user->getValue('email'));
// TODO - lan
$lan = 'Administrator --ADMIN_EMAIL-- (#--ADMIN_UID--, --ADMIN_NAME--) has logged out as the user --EMAIL-- (#--UID--, --NAME--)';
e107::getAdminLog()->log_event('USET_101', str_replace($search, $replace, $lan), E_LOG_INFORMATIVE);
e107::getEvent()->trigger('logoutas', array('user_id' => $sysuser->getId(), 'admin_id' => $user->getId()));
$this->redirect('list', 'main', true);
}
// TODO - lan
if(!$sysuser->getId()) e107::getMessage()->addError('User not found.');
}
public function LogoutasPage()
{
// System Message only on non-successful logout as another user
}
/**
* Remove admin status trigger
*/
public function ListUnadminTrigger($userid)
{
$user = e107::getUser();
$sysuser = e107::getSystemUser($userid, false);
$mes = e107::getMessage();
if(!$user->checkAdminPerms('3'))
{
// TODO lan
$mes->addError("You don't have enough permissions to do this.", 'default', true);
// TODO lan
$lan = 'Security violation (not enough permissions) - Administrator --ADMIN_UID-- (--ADMIN_NAME--, --ADMIN_EMAIL--) tried to remove admin status from --UID-- (--NAME--, --EMAIL--)';
$search = array('--UID--', '--NAME--', '--EMAIL--', '--ADMIN_UID--', '--ADMIN_NAME--', '--ADMIN_EMAIL--');
$replace = array($sysuser->getId(), $sysuser->getName(), $sysuser->getValue('email'), $user->getId(), $user->getName(), $user->getValue('email'));
e107::getAdminLog()->log_event('USET_08', str_replace($search, $replace, $lan), E_LOG_INFORMATIVE);
$this->redirect('list', 'main', true);
}
if ($sysuser->isMainAdmin())
{
$mes->addError(USRLAN_5);
}
else
{
if($sysuser->set('user_admin', '0')->set('user_perms', '')->save())
{
e107::getAdminLog()->log_event('USET_09',str_replace(array('--UID--', '--NAME--', '--EMAIL--'),array($sysuser->getId(), $sysuser->getName(), $sysuser->getValue('email')), USRLAN_165),E_LOG_INFORMATIVE);
$mes->addSuccess($sysuser->getName()." (".$sysuser->getValue('email').") ".USRLAN_6);
$this->getTreeModel()->load(true);
}
else
{
// TODO lan
$mes->addError('Unknown error. Action failed.');
}
}
}
/**
* Admin manage observer
* @return void
*/
public function AdminObserver()
{
if($this->getPosted('go_back'))
{
$this->redirect('list', 'main', true);
}
$userid = $this->getId();
$sql = e107::getDb();
$user = e107::getUser();
$sysuser = e107::getSystemUser($userid, false);
$admin_log = e107::getAdminLog();
$mes = e107::getMessage();
if(!$user->checkAdminPerms('3'))
{
// TODO lan
$mes->addError("You don't have enough permissions to do this.", 'default', true);
// TODO lan
$lan = 'Security violation (not enough permissions) - Administrator --ADMIN_UID-- (--ADMIN_NAME--, --ADMIN_EMAIL--) tried to make --UID-- (--NAME--, --EMAIL--) system admin';
$search = array('--UID--', '--NAME--', '--EMAIL--', '--ADMIN_UID--', '--ADMIN_NAME--', '--ADMIN_EMAIL--');
$replace = array($sysuser->getId(), $sysuser->getName(), $sysuser->getValue('email'), $user->getId(), $user->getName(), $user->getValue('email'));
e107::getLog()->add('USET_08', str_replace($search, $replace, $lan), E_LOG_INFORMATIVE);
$this->redirect('list', 'main', true);
}
if(!$sysuser->getId())
{
// TODO lan
$mes->addError("User not found.", 'default', true);
$this->redirect('list', 'main', true);
}
if($this->getPosted('update_admin'))
{
e107::getUserPerms()->updatePerms($userid, $_POST['perms']);
$this->redirect('list', 'main', true);
}
if(!$sysuser->isAdmin()) // Security Check Only. Admin status check is added during 'updatePerms'.
{
// $sysuser->set('user_admin', 1)->save(); //"user","user_admin='1' WHERE user_id={$userid}"
// $lan = str_replace(array('--UID--', '--NAME--', '--EMAIL--'), array($sysuser->getId(), $sysuser->getName(), $sysuser->getValue('email')), USRLAN_164);
// e107::getLog()->add('USET_08', $lan, E_LOG_INFORMATIVE);
// $mes->addSuccess($lan);
$mes->addWarning("You are about to make User #".$sysuser->getId()." : ".$sysuser->getName()." (".$sysuser->getValue('email').") an administrator."); ///TODO LAN
$mes->addWarning("Set the permissions and click Update to proceed or Back to abort.");
}
}
/**
* Admin manage page
*/
public function AdminPage()
{
$request = $this->getRequest();
$response = $this->getResponse();
$sysuser = e107::getSystemUser($request->getId(), false);
//$sysuser->load($request->getId(), true);
$prm = e107::getUserPerms();
$frm = e107::getForm();
$response->appendBody($frm->open('adminperms'))
->appendBody($prm->renderPermTable('grouped', $sysuser->getValue('perms')))
->appendBody($prm->renderCheckAllButtons())
->appendBody($prm->renderSubmitButtons())
->appendBody($frm->close());
// TODO lan
$this->addTitle(str_replace(array('{NAME}', '{EMAIL}'), array($sysuser->getName(), $sysuser->getValue('email')), 'Update administrator {NAME} ({EMAIL})'));
}
protected function checkAllowed($class_id) // check userclass change is permitted.
{
$e_userclass = e107::getUserClass();
if (!isset ($e_userclass->class_tree[$class_id]))
{
return false;
}
if (!getperms("0") && !check_class($e_userclass->class_tree[$class_id]['userclass_editclass']))
{
return false;
}
return true;
}
protected function manageUserclass($userid, $uclass, $mode = false)
{
$request = $this->getRequest();
$response = $this->getResponse();
$sysuser = e107::getSystemUser($userid, false);
$admin_log = e107::getAdminLog();
$e_userclass = e107::getUserClass();
$sql = e107::getDb();
$remuser = true;
$mes = e107::getMessage();
if(!$sysuser->getId())
{
// TODO lan
$mes->addError('User not found.');
return false;
}
$curClass = array();
if($mode !== 'update')
{
$curClass = $sysuser->getValue('class') ? explode(',', $sysuser->getValue('class')) : array();
}
foreach ($uclass as $a)
{
$a = intval($a);
if(!$this->checkAllowed($a))
{
// TODO lan
$mes->addError('Insufficient permissions, operation aborted.');
return false;
}
if($a != 0) // if 0 - then do not add.
{
$curClass[] = $a;
}
}
if($mode == "remove") // remove selected classes
{
$curClass = array_diff($curClass, $uclass);
}
elseif($mode == "clear") // clear all classes
{
$curClass = array();
}
$curClass = array_unique($curClass);
$svar = is_array($curClass) ? implode(",", $curClass) : "";
$check = $sysuser->set('user_class', $svar)->save();
if($check)
{
$message = UCSLAN_9;
if ($this->getPosted('notifyuser'))
{
$options = array();
$message .= "
".UCSLAN_1.": ".$sysuser->getName()."
";
$messaccess = '';
foreach ($curClass as $a)
{
if (!isset ($e_userclass->fixed_classes[$a]))
{
$messaccess .= $e_userclass->class_tree[$a]['userclass_name']." - ".$e_userclass->class_tree[$a]['userclass_description']."\n";
}
}
if ($messaccess == '') $messaccess = UCSLAN_12."\n";
$message = UCSLAN_3." ".$sysuser->getName().",\n\n".UCSLAN_4." ".SITENAME."\n( ".SITEURL." )\n\n".UCSLAN_5.": \n\n".$messaccess."\n".UCSLAN_10."\n".SITEADMIN;
// $admin_log->e_log_event(4,__FILE__."|".__FUNCTION__."@".__LINE__,"DBG","User class change",str_replace("\n","
",$message),FALSE,LOG_TO_ROLLING);
$options['mail_subject'] = UCSLAN_2;
$options['mail_body'] = nl2br($message);
$sysuser->email('email', $options);
//sendemail($send_to,$subject,$message);
}
e107::getLog()->add('USET_14', str_replace(array('--UID--','--CLASSES--'), array($id, $svar), UCSLAN_11), E_LOG_INFORMATIVE);
$mes->addSuccess(nl2br($message));
}
else
{
// $mes->add("Update Failed", E_MESSAGE_ERROR);
if($check === false)
{
$sysuser->setMessages(); // move messages to the default stack
}
else
{
$mes->addInfo(LAN_NO_CHANGE);
}
}
}
/**
* Update user class trigger
*/
public function UserclassUpdateclassTrigger()
{
$this->manageUserclass($this->getId(), $this->getPosted('userclass'), 'update');
}
/**
* Back to user list trigger (userclass page)
*/
public function UserclassBackTrigger()
{
$this->redirect('list', 'main', true);
}
/**
* Manage userclasses page
*/
public function UserclassPage()
{
$request = $this->getRequest();
$response = $this->getResponse();
$sysuser = e107::getSystemUser($request->getId(), false);
$e_userclass = e107::getUserClass();
$userid = $this->getId();
$frm = e107::getForm();
$caption = UCSLAN_6." ".$sysuser->getName().' - '.$sysuser->getValue('email')." (".$sysuser->getClassList(true).")";
$this->addTitle($caption);
$text = "
'.htmlspecialchars($this->getParam('testSucces')).''; $text .= "
".LAN_MAINADMIN." | ".$frm->text('calc_name[main_admin]', $val)." | N/A | ".$frm->checkbox('calc_pfx[main_admin]', 1, $info['lan_pfx'] ? true : false)." | ".$ui->RankImageDropdown($imageList,'calc_img[main_admin]',$info['image'])." |
".LAN_ADMIN." | ".$frm->text('calc_name[admin]', $val)." | N/A | ".$frm->checkbox('calc_pfx[admin]', 1, $info['lan_pfx'] ? true : false)." | ".$ui->RankImageDropdown($imageList, 'calc_img[admin]', $info['image'])." |
".USRLAN_212." | ".$frm->number("calc_lower[{$k}]", $r['thresh'])." | ".$frm->checkbox("calc_pfx[{$k}]", 1, $r['lan_pfx'] ? true : false)." | ".$ui->RankImageDropdown($imageList, "calc_img[$k]", $r['image'])." ". $frm->submit_image("etrigger_delete[{$r['id']}]", LAN_DELETE, 'delete', LAN_CONFIRMDEL.": [{$r['name']}]?")." | |
".USRLAN_214." | ".$frm->text('new_calc_name', '')." | ".$frm->number('new_calc_lower', '')." | ".$frm->checkbox('new_calc_pfx', 1, false)." | ".$ui->RankImageDropdown($imageList, 'new_calc_img')." |