Location: PHPKode > projects > DATA system > datasystem-0.8.7/html/u/moduser.php
<?
/*
 *  moduser.php
 *  Modify user permission script
 *
 *  Changes:
 *  Nov.05,2003  Shinya Meguro
 *   - Here Document is used.
 *   - User id is not used as option value.
 *   - Group id is not used as option value.
 *   - Hidden value is not user id but user name.
 */

adminonly();

if (GET) {

    pageheader("main", "Modify user permissions");

    // Get a list of users
    $Names = db_unamelist();
    $Text = "<option value=\"0\" selected=\"selected\"></option>\n";
    foreach($Names as $Name) {
        $Text .= "<option value=\"$Name\">$Name</option>\n";
	}

    print <<<__EOD__
 <form method="post" action="moduser.php">
  <h3>Modify user permissions</h3>
  <table>
   <tr>
    <td valign="top" align="right">Select user:</td>
    <td>
     <select name="user">
    $Text
     </select>
    </td>
   </tr>
   <tr>
    <td></td>
    <td><input type="submit" name="doSubmit" value="Select"></td>
   </tr>
  </table>
 </form>
__EOD__;

    pagefooter();


} elseif (POST && ($params["doSubmit"] == "Select")) {

	pageheader("main", "Changing user permissions");

	if (array_key_exists('user',$params) && !($params['user']=='')) {
		if (preg_match('/^([a-z]+[\w\d_]*)$/', trim($params['user']), $matches)) {
			$Puname = $matches[1];
		} else {
			errorfooter("User name must be start a-z and can be use 'a' to 'z', number and under score(_).");
		}
	} else {
		errorfooter("User name must be set.");
	}

    $User = db_chkUserParam($Puname);



    $groups="";    // groups which user belongs to
    if( !count($User['Groups']) )
        $groups .= "<none>";
    else
        foreach($User['Groups'] as $gname)
            $groups .= $gname." ";

    $grouplist=""; // all group list
    if (count($User['Gnames']))
    {
        $grouplist .= "<tr>\n    <td></td>\n    <td>\n";
        $grouplist .= "     <select name=\"grp[]\" size=\"6\" multiple=\"multiple\">\n";
        foreach($User['Gnames'] as $name)
            $grouplist .= "     <option ".(in_array($name,$User['Groups'])?" selected=\"selected\"":"").">$name</option>\n";
        $grouplist .="     </select></td>\n   </tr>\n";
    }

    $fg_admin = $User["Flags"]["admin"] ? "checked=\"checked\"" : "";
    $fg_upload = $User["Flags"]["upload"] ? "checked=\"checked\"" : "";



    print <<<__EOD__
<h3>User: $Puname</h3>
<form method="post" action="moduser.php">
<input type="hidden" name="uname" value="$Puname" />
<table>
   <tr>
     <td align="right" valign="top">Groups:</td>
     <td>
      $groups
     </td>
   </tr>
   $grouplist

  <tr><td valign="top">Info</td><td><textarea name="info" cols="60" rows="4">{$User['Info']}</textarea></td></tr>
  <tr><td>admin</td><td><input type="checkbox" name="cadmin" value="SET" $fg_admin /></td></tr>
  <tr><td>upload</td><td><input type="checkbox" name="cupload" value="SET" $fg_upload /></td></tr>
  <tr><td></td><td><input type="submit" name="doSubmit" value="Update"></td></tr>
</table>\n</form>
__EOD__;

    pagefooter();


}
elseif (POST && ($params["doSubmit"] == "Update") )
{

    // check global variables
    if (isset($params["uname"])) $uname = addslashes(trim($params["uname"]));
    if (isset($params["grp"])) $grp = $params["grp"]; else $grp = array();
    if (isset($params["info"])) $info = $params["info"];
    isset($params["cadmin"]) ? $cadmin = $params["cadmin"] : $cadmin ="";
    isset($params["cupload"]) ? $cupload = $params["cupload"] : $cupload="";

    pageheader("main", "Changing user permissions");

    db_moduser($uname, $grp, $info, $cadmin, $cupload );

	setLocation("./listusers.php");

}

?>
Return current item: DATA system