Location: PHPKode > projects > DATA system > datasystem-0.8.7/html/u/adduser.php
<?
/*
 *  adduser.php
 *  New user creation
 *
 *  Changes:
 *  Nov.05,2003  Shinya Meguro
 *   - Here document is used.
 */

adminonly();

if (GET) {

	pageheader("main", "Add new user");

	$groups = db_listgroupnames();
	$txt = "";
	//vardump($groups);

	foreach ($groups as $Group)
		$txt .= "     <option>$Group</option>\n";

	print <<<__EOD__
 <form method="post" action="adduser.php">
  <h3>Add new user</h3>
  <table>
   <tr>
    <td align="right" valign="top">Login name:</td>
    <td><input type="text" name="uname" value="" size="32" maxlength="16">(16 chars max) ['a' to 'z', number, '_' are used.]</td>
   </tr>
   <tr>
    <td align="right" valign="top">Password:</td>
    <td><input type="password" name="pwd" value="" size="32" maxlength="16">(16 chars max)</td>
   </tr>
   <tr>
    <td align="right" valign="top">User info:</td>
    <td><textarea name="inf" cols="60" rows="4"></textarea></td>
   </tr>
__EOD__;

	if ($txt)
		print <<<__EOD__
   <tr>
    <td align="right" valign="top">Groups:</td>
    <td>
     <select name="grp[]" size="6" multiple="multiple">
     $txt
     </select><br />(select groups that the user should belong to)
    </td>
   </tr>
__EOD__;

	print <<<__EOD__
   <tr>
    <td align="right" valign="top">Access rights:</td>
    <td>
     <table>
      <tr><td><input type="checkbox" name="cadmin" value="SET" /></td><td>admin</td></tr>
      <tr><td><input type="checkbox" name="cupload" value="SET" /></td><td>upload</td></tr>
     </table>
    </td>
   </tr>
   <tr>
    <td></td>
    <td><input type="submit" name="doSubmit" value="Add user"></td>
   </tr>
  </table>
 </form>
__EOD__;

	pagefooter();

}
elseif (POST and ($params["doSubmit"]=="Add user"))
{

	pageheader("main", "Adding new user");

	$Pgroups = array();
	$Prights = array();

	if (array_key_exists('uname',$params) && !($params['uname']=='')) {
		if (preg_match('/^([a-z]+[\w\d_]*)$/', trim($params['uname']), $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.");
	}

	if (isset($params["pwd"])) $Ppwd = trim($params["pwd"]);
	if( strlen($Ppwd) < 4 )
		errorfooter("Password is too short (less than 4 characters) or empty.");
	$Ppwd = md5($Ppwd);

	if (isset($params["inf"])) $Pinfo = addslashes(trim($params["inf"]));

	if (isset($params["grp"]))
		foreach($params["grp"] as $g)
			$Pgroups[] = addslashes(trim($g));

	if (isset($params["cadmin"]) AND $params["cadmin"]=="SET" ) $Prights[] = "admin";
	if (isset($params["cupload"]) AND $params["cupload"]=="SET" ) $Prights[] = "upload";


	db_adduser($Puname, $Ppwd, $Pinfo, $Pgroups, $Prights);

	setLocation("./listusers.php");

}
?>
Return current item: DATA system