From 791bac8e09b325ab5f9c3f87eadb59b4e509c477 Mon Sep 17 00:00:00 2001 From: Jonathan Ernst Date: Mon, 17 Jan 2005 04:30:39 +0000 Subject: [PATCH] make it possible to add/remove administrators --- admin/adminUsers.php | 5 +++++ include/form_edit.php | 12 ++++++++++++ include/user.php | 15 +++++++++++++++ preferences.php | 27 +++++++++++++++++++-------- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/admin/adminUsers.php b/admin/adminUsers.php index 63c90ad..70e424c 100644 --- a/admin/adminUsers.php +++ b/admin/adminUsers.php @@ -71,6 +71,7 @@ if($_REQUEST['sSubmit']) echo " E-mail\n"; echo " Creation date\n"; echo " Last connected\n"; + echo " Roles\n"; echo "  \n"; echo "\n\n"; if(is_numeric($_REQUEST['iLimit']) && in_array($_REQUEST['sOrderBy'],array("email","realname","created"))) @@ -90,6 +91,10 @@ if($_REQUEST['sSubmit']) echo " ".$oRow->email."\n"; echo " ".$oRow->created."\n"; echo " ".$oRow->stamp."\n"; + echo " "; + if(isAdministrator($oRow->userid)) echo "A"; + if(isMaintainer($oRow->userid)) echo "M"; + echo " \n"; echo " [userid."&sSearch=".$sSearch."&iLimit=".$_REQUEST['iLimit']."&sOrderBy=".$_REQUEST['sOrderBy']."&sSubmit=true\">delete] [userid."&sSearch=".$sSearch."&iLimit=".$_REQUEST['iLimit']."&sOrderBy=".$_REQUEST['sOrderBy']."\">edit]\n"; echo "\n\n"; } diff --git a/include/form_edit.php b/include/form_edit.php index 3f30e44..06303e5 100644 --- a/include/form_edit.php +++ b/include/form_edit.php @@ -21,6 +21,18 @@   Real Name + + +   Administrator + " value="on"> + +   diff --git a/include/user.php b/include/user.php index 2c3bed7..4b340d1 100644 --- a/include/user.php +++ b/include/user.php @@ -361,6 +361,21 @@ function UserWantsEmail($userid) return ($ob->value == 'no' ? false : true); } +function isAdministrator($iUserId) +{ + $hResult = query_appdb("SELECT * FROM user_privs WHERE userid = ".$iUserId." AND priv = 'admin'"); + if(!$hResult) + return 0; + return mysql_num_rows($hResult); +} + +function isMaintainer($iUserId) +{ + $hResult = query_appdb("SELECT * FROM appMaintainers WHERE userId = ".$iUserId); + if(!$hResult) + return 0; + return mysql_num_rows($hResult); +} /** * get the email address of people to notify for this appId and versionId diff --git a/preferences.php b/preferences.php index 05a26e1..7ae1289 100644 --- a/preferences.php +++ b/preferences.php @@ -1,7 +1,7 @@ lookup_realname($iUserId); $ext_email = $user->lookup_email($iUserId); $CVSrelease = $user->lookup_CVSrelease($iUserId); - + // if we are managing anothe user + if($iUserId == $_REQUEST['userId']) + { + if(isAdministrator($iUserId)) + $ext_hasadmin = 'checked="true"'; + else + $ext_hasadmin = ""; + } include(BASE."include/"."form_edit.php"); echo "  Wine version "; @@ -96,11 +103,15 @@ if($_POST) if ($user->update($iUserId, $str_passwd, $_REQUEST['ext_realname'], $_REQUEST['ext_email'], $_REQUEST['CVSrelease'])) { addmsg("Preferences Updated", "green"); - - // we were managing an user, let's go back to the admin. - if($iUserId == $_REQUEST['userId']) + // we were managing an user, let's go back to the admin after updating tha admin status + if($iUserId == $_REQUEST['userId'] && havepriv("admin")) { - redirect(BASE."admin/adminUsersEdit.php?userId=".$iUserId."&sSearch=".$_REQUEST['sSearch']."&iLimit=".$_REQUEST['iLimit']."&sOrderBy=".$_REQUEST['sOrderBy']."&sSubmit=true"); + $user->userid = $iUserId; + if($_POST['ext_hasadmin']=="on") + $user->addpriv("admin"); + else + $user->delpriv("admin"); + redirect(BASE."admin/adminUsers.php?userId=".$iUserId."&sSearch=".$_REQUEST['sSearch']."&iLimit=".$_REQUEST['iLimit']."&sOrderBy=".$_REQUEST['sOrderBy']."&sSubmit=true"); } } else