1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 11:50:30 +02:00

Easy editing of administrator perms from admin->users.

This commit is contained in:
CaMer0n
2009-11-12 05:11:47 +00:00
parent 71f9e1be72
commit d5ff425a49
5 changed files with 183 additions and 124 deletions

View File

@@ -9,8 +9,8 @@
* Administrators Management
*
* $Source: /cvs_backup/e107_0.8/e107_admin/administrator.php,v $
* $Revision: 1.16 $
* $Date: 2009-11-12 01:53:16 $
* $Revision: 1.17 $
* $Date: 2009-11-12 05:11:41 $
* $Author: e107coders $
*
*/
@@ -37,7 +37,8 @@ require_once('auth.php');
require_once(e_HANDLER."form_handler.php");
require_once(e_HANDLER."message_handler.php");
$frm = new e_form(true);
$emessage = &eMessage::getInstance();
$emessage = e107::getMessage();
$prm = e107::getUserPerms();
$action = '';
$sub_action = -1;
@@ -50,38 +51,9 @@ if (e_QUERY)
}
if (isset($_POST['update_admin']))
{ // Permissions updated
$modID = intval($_POST['a_id']);
if ($modID == 0)
{
exit;
}
$sql->db_Select("user", "*", "user_id=".$modID);
$row = $sql->db_Fetch();
$a_name = $row['user_name'];
$perm = "";
foreach($_POST['perms'] as $value)
{
$value = $tp->toDB($value);
if ($value == "0")
{
if (!getperms('0')) { $value = ""; break; }
$perm = "0"; break;
}
if ($value)
{
$perm .= $value.".";
}
}
admin_update($sql->db_Update("user", "user_perms='{$perm}' WHERE user_id='{$modID}' "), 'update', sprintf(ADMSLAN_2, $tp->toDB($_POST['ad_name'])), false, false);
$logMsg = str_replace(array('--ID--', '--NAME--'),array($modID, $a_name),ADMSLAN_72).$perm;
$admin_log->log_event('ADMIN_01',$logMsg,E_LOG_INFORMATIVE,'');
unset($modID, $ad_name, $a_perms);
if (isset($_POST['update_admin'])) // Permissions updated
{
$prm->updatePerms($_POST['a_id'],$_POST['perms']);
}
@@ -125,7 +97,7 @@ if (isset($_POST['del_admin']) && count($_POST['del_admin']))
if(isset($_POST['edit_admin']) || $action == "edit")
{
edit_administrator($row);
$prm->edit_administrator($row);
}
else
{
@@ -139,10 +111,9 @@ function show_admins()
$frm = e107::getForm();
$ns = e107::getRender();
$mes = e107::getMessage();
$tp = e107::getParser();
$prm = e107::getUserPerms();
require_once(e_HANDLER."user_handler.php");
$prm = new e_userperms;
$sql->db_Select("user", "*", "user_admin='1'");
@@ -176,7 +147,7 @@ function show_admins()
$text .= "
<tr>
<td>".$row['user_id']."</td>
<td><a href='".$e107->url->getUrl('core:user', 'main', "func=profile&id={$row['user_id']}")."'>".$row['user_name']."</a></td>
<td><a href='".e107::getUrl()->getUrl('core:user', 'main', "func=profile&id={$row['user_id']}")."'>".$row['user_name']."</a></td>
<td>
".$prm->renderperms($row['user_perms'],$row['user_id'],"words")."
</td>
@@ -186,7 +157,7 @@ function show_admins()
{
$text .= "
".$frm->submit_image("edit_admin[{$row['user_id']}]", 'edit', 'edit', LAN_EDIT)."
".$frm->submit_image("del_admin[{$row['user_id']}]", 'del', 'delete', $e107->tp->toJS(ADMSLAN_59."? [".$row['user_name']."]"))."
".$frm->submit_image("del_admin[{$row['user_id']}]", 'del', 'delete', $tp->toJS(ADMSLAN_59."? [".$row['user_name']."]"))."
";
}
@@ -208,75 +179,7 @@ function show_admins()
$ns->tablerender(ADMSLAN_13, $mes->render().$text);
}
function edit_administrator($row)
{
global $pref;
$lanlist = explode(",",e_LANLIST);
require_once(e_HANDLER."user_handler.php");
$prm = new e_userperms;
$ns = e107::getRender();
$sql = e107::getDb();
$frm = e107::getForm();
$a_id = $row['user_id'];
$ad_name = $row['user_name'];
$a_perms = $row['user_perms'];
$text = "
<form method='post' action='".e_SELF."' id='myform'>
<fieldset id='core-administrator-edit'>
<legend class='e-hideme'>".ADMSLAN_52."</legend>
<table cellpadding='0' cellspacing='0' class='adminform'>
<colgroup span='2'>
<col class='col-label' />
<col class='col-control' />
</colgroup>
<tbody>
<tr>
<td class='label'>".ADMSLAN_16.": </td>
<td class='control'>
".$ad_name."
<input type='hidden' name='ad_name' size='60' value='{$ad_name}' />
</td>
</tr>
<tr>
<td class='label'>".ADMSLAN_18."</td>
<td class='control'>
";
$groupedList = $prm->getPermList('grouped');
foreach($groupedList as $section=>$list)
{
$text .= "\t\t<div class='field-section'><h4>".$prm->renderSectionDiz($section)."</h4>"; //XXX Lan - General
foreach($list as $key=>$diz)
{
$text .= $prm->checkb($key, $a_perms, $diz);
}
$text .= "</div>";
}
$text .= "<div class='field-section'>
".$frm->admin_button('check_all', 'jstarget:perms', 'action', LAN_CHECKALL)."
".$frm->admin_button('uncheck_all', 'jstarget:perms', 'action', LAN_UNCHECKALL)."
</div>
</td>
</tr>
</tbody>
</table>
<div class='buttons-bar center'>
<input type='hidden' name='a_id' value='{$a_id}' />
".$frm->admin_button('update_admin', ADMSLAN_52, 'update')."
".$frm->admin_button('go_back', ADMSLAN_70)."
</div>
</fieldset>
</form>
";
$ns->tablerender(ADMSLAN_52, $text);
}
require_once("footer.php");

View File

@@ -10,8 +10,8 @@
* Administration Area - Users
*
* $Source: /cvs_backup/e107_0.8/e107_admin/users.php,v $
* $Revision: 1.66 $
* $Date: 2009-11-12 02:14:26 $
* $Revision: 1.67 $
* $Date: 2009-11-12 05:11:41 $
* $Author: e107coders $
*
*/
@@ -224,6 +224,9 @@ if (isset ($_POST['prune']))
$ns->tablerender(USRLAN_57,"<div style='text-align:center'><b>".$text."</b></div>");
unset ($text);
}
// ------- Quick Add User --------------
if (isset ($_POST['adduser']))
{
@@ -427,12 +430,21 @@ if (isset ($_POST['useraction']) && $_POST['useraction'] == 'test')
exit;
}
}
$prm = e107::getUserPerms();
// ------- Make Admin --------------
if (isset ($_POST['useraction']) && $_POST['useraction'] == "admin" && getperms('3'))
if ((varset($_POST['useraction'])== "admin" || varset($_POST['useraction'])== "adminperms") && getperms('3'))
{
$sql->db_Select("user","user_id, user_name","user_id='".$_POST['userid']."'");
$sql->db_Select("user","user_id, user_name, user_perms","user_id='".$_POST['userid']."'");
$row = $sql->db_Fetch();
$sql->db_Update("user","user_admin='1' WHERE user_id='".$_POST['userid']."' ");
if(varset($_POST['useraction'])== "admin")
{
$sql->db_Update("user","user_admin='1' WHERE user_id='".$_POST['userid']."' ");
}
$admin_log->log_event('USET_08',str_replace(array('--UID--','--NAME--'),array($row['user_id'],$row['user_name']),USRLAN_164),E_LOG_INFORMATIVE);
$user->show_message($row['user_name']." ".USRLAN_3." <a href='".e_ADMIN."administrator.php?edit.{$row['user_id']}'>".USRLAN_4."</a>");
$action = "main";
@@ -444,7 +456,19 @@ if (isset ($_POST['useraction']) && $_POST['useraction'] == "admin" && getperms(
{
$id = "DESC";
}
$prm->edit_administrator($row);
require_once ("footer.php");
exit;
}
if (varset($_POST['update_admin'])) // Update admin Perms.
{
$prm->updatePerms($_POST['a_id'],$_POST['perms']);
}
// ------- Remove Admin --------------
if (isset ($_POST['useraction']) && $_POST['useraction'] == "unadmin" && getperms('3'))
{
@@ -921,6 +945,7 @@ class users
else
if ($user_admin && $user_perms != "0" && getperms('3'))
{
$text .= "<option value='adminperms'>".USRLAN_221."</option>\n";
$text .= "<option value='unadmin'>".USRLAN_34."</option>\n";
}
}
@@ -1140,7 +1165,7 @@ class users
$e107 = e107 :: getInstance();
$type = $this->fields[$key]['type'];
$pref = e107::getConfig()->getPref();
$prm = new e_userperms;
$prm = e107::getUserPerms();
switch($key) // switch based on field.
{
@@ -1413,7 +1438,7 @@ class users
{
global $rs,$pref,$e_userclass;
$prm = new e_userperms;
$prm = e107::getUserPerms();
$list = $prm->getPermList();
$frm = e107::getForm();
$ns = e107::getRender();

View File

@@ -9,8 +9,8 @@
* e107 Main
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/e107_class.php,v $
* $Revision: 1.65 $
* $Date: 2009-11-10 23:13:30 $
* $Revision: 1.66 $
* $Date: 2009-11-12 05:11:41 $
* $Author: e107coders $
*/
@@ -135,7 +135,8 @@ class e107
'e_admin_form_ui' => '{e_HANDLER}admin_handler.php',
'DHTML_Calendar' => '{e_HANDLER}calendar/calendar_class.php',
'comment' => '{e_HANDLER}comment_class.php',
'e107_user_extended' => '{e_HANDLER}user_extended_class.php'
'e107_user_extended' => '{e_HANDLER}user_extended_class.php',
'e_userperms' => '{e_HANDLER}user_handler.php',
);
/**
@@ -832,6 +833,15 @@ class e107
{
return self::getSingleton('e_online', true);
}
/**
* Retrieve User Perms (admin perms) handler singleton object
* @return comment
*/
public static function getUserPerms()
{
return self::getSingleton('e_userperms', true);
}
/**

View File

@@ -9,8 +9,8 @@
* Handler - user-related functions
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/user_handler.php,v $
* $Revision: 1.15 $
* $Date: 2009-11-12 01:53:16 $
* $Revision: 1.16 $
* $Date: 2009-11-12 05:11:42 $
* $Author: e107coders $
*
*/
@@ -831,6 +831,126 @@ class e_userperms
*/
return $text;
}
/**
* Render edit admin perms form.
* @param array $row [optional] containing $row['user_id'], $row['user_name'], $row['user_perms'];
* @return
*/
function edit_administrator($row='')
{
global $pref;
$lanlist = explode(",",e_LANLIST);
require_once(e_HANDLER."user_handler.php");
$prm = $this;
$ns = e107::getRender();
$sql = e107::getDb();
$frm = e107::getForm();
$a_id = $row['user_id'];
$ad_name = $row['user_name'];
$a_perms = $row['user_perms'];
$text = "
<form method='post' action='".e_SELF."' id='myform'>
<fieldset id='core-administrator-edit'>
<legend class='e-hideme'>".ADMSLAN_52."</legend>
<table cellpadding='0' cellspacing='0' class='adminform'>
<colgroup span='2'>
<col class='col-label' />
<col class='col-control' />
</colgroup>
<tbody>
<tr>
<td class='label'>".ADMSLAN_16.": </td>
<td class='control'>
".$ad_name."
<input type='hidden' name='ad_name' size='60' value='{$ad_name}' />
</td>
</tr>
<tr>
<td class='label'>".ADMSLAN_18."</td>
<td class='control'>
";
$groupedList = $prm->getPermList('grouped');
foreach($groupedList as $section=>$list)
{
$text .= "\t\t<div class='field-section'><h4>".$prm->renderSectionDiz($section)."</h4>"; //XXX Lan - General
foreach($list as $key=>$diz)
{
$text .= $prm->checkb($key, $a_perms, $diz);
}
$text .= "</div>";
}
$text .= "<div class='field-section'>
".$frm->admin_button('check_all', 'jstarget:perms', 'action', LAN_CHECKALL)."
".$frm->admin_button('uncheck_all', 'jstarget:perms', 'action', LAN_UNCHECKALL)."
</div>
</td>
</tr>
</tbody>
</table>
<div class='buttons-bar center'>
<input type='hidden' name='a_id' value='{$a_id}' />
".$frm->admin_button('update_admin', ADMSLAN_52, 'update')."
".$frm->admin_button('go_back', ADMSLAN_70)."
</div>
</fieldset>
</form>
";
$ns->tablerender(ADMSLAN_52, $text);
}
/**
* Update user (admin) perms
* @param int $uid
* @param array $permArray eg. array('A','K','1');
* @return
*/
function updatePerms($uid,$permArray)
{
global $admin_log;
$sql = e107::getDb();
$tp = e107::getParser();
$modID = intval($uid);
if ($modID == 0)
{
exit;
}
$sql->db_Select("user", "*", "user_id=".$modID);
$row = $sql->db_Fetch();
$a_name = $row['user_name'];
$perm = "";
foreach($permArray as $value)
{
$value = $tp->toDB($value);
if ($value == "0")
{
if (!getperms('0')) { $value = ""; break; }
$perm = "0"; break;
}
if ($value)
{
$perm .= $value.".";
}
}
admin_update($sql->db_Update("user", "user_perms='{$perm}' WHERE user_id='{$modID}' "), 'update', sprintf(ADMSLAN_2, $tp->toDB($_POST['ad_name'])), false, false);
$logMsg = str_replace(array('--ID--', '--NAME--'),array($modID, $a_name),ADMSLAN_72).$perm;
$admin_log->log_event('ADMIN_01',$logMsg,E_LOG_INFORMATIVE,'');
}
}
?>

View File

@@ -9,8 +9,8 @@
* Language file - user admin
*
* $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_users.php,v $
* $Revision: 1.19 $
* $Date: 2009-08-10 15:34:28 $
* $Revision: 1.20 $
* $Date: 2009-11-12 05:11:47 $
* $Author: e107coders $
*
*/
@@ -231,8 +231,9 @@ define('LAN_NOTVERIFIED','Not Verified');
define('LAN_BANNED','Banned');
define('LAN_BOUNCED','Bounced');
define('USRLAN_220', 'All Userclasses');
define('USRLAN_220', 'All Userclasses');
define('USRLAN_221', 'Edit admin perms');
// These need review - there are duplicates above - they come from admin/lan_userclass.php.
define("UCSLAN_1", "Sending notification email to");