Location: PHPKode > projects > Admbook > admin/user-add.php
<?php
	class Timer {
		var $startTime;
		var $endTime;
		function start() {
			$this->startTime = gettimeofday();
		}
		function stop() {
			$this->endTime = gettimeofday();
		}
		function elapsed() {
			return (($this->endTime["sec"] - $this->startTime["sec"]) * 1000000 + ($this->endTime["usec"] - $this->startTime["usec"])) / 1000000;
		}
	}
	$timer = new Timer();
	$timer->start();
	session_start();
	include("../settings-data.php");
	include("../lib.php");
	checkPermissions($login, $password);
	include("../users-data.php");
	session_register("error");
	session_register("style");
	session_register("userName");
	session_register("userMail");
	session_register("newUserPassword");
	session_register("confirmUserPassword");
	session_register("userStatus");
	$error = "";
	$style = "";
	if (!isset($user))
		$user = array();
	if (!isset($userName))
		$userName = "";
	if (!isset($userMail))
		$userMail = "";
	if (!isset($userPassword))
		$userPassword = "";
	if (!isset($confirmUserPassword))
		$confirmUserPassword = "";
	if (!isset($userStatus))
		$userStatus = "enabled";
	$userName = strtolower(translateHtml($userName, false));
	$userMail = strtolower(translateHtml($userMail, false));
	if ($userName == "")
	{
		$error .= "User name is empty<br/>";
		$style .= "\n.username {\n\tcolor : ".$constant['error-color']."\n}\n";
	}
	else if (strlen($userName) > 30)
	{
		$error .= "User name is long.<br/>";
		$style .= "\n.username {\n\tcolor : ".$constant['error-color']."\n}\n";
	}
	else
	{
		foreach($user as $v1)
		{
			foreach ($v1 as $v2)
			{
				if ($userName == $v2)
				{
					$error .= "User name already registered.<br/>";
					$style .= "\n.username {\n\tcolor : ".$constant['error-color']."\n}\n";
					break 2;
				}
			}
		}
	}
	if ($userMail == "")
	{
		$error .= "User mail is empty<br/>";
		$style .= "\n.usermail {\n\tcolor : ".$constant['error-color']."\n}\n";
	}
	else if (strlen($userMail) > 128)
	{
		$error .= "User mail is long.<br/>";
		$style .= "\n.usermail {\n\tcolor : ".$constant['error-color']."\n}\n";
	}
	else
	{
		if (!validEmail($userMail))
		{
			$error .= "Wrong user mail<br/>";
			$style .= "\n.usermail {\n\tcolor : ".$constant['error-color']."\n}\n";
		}
	}
	$passwordLength = strlen($newUserPassword);
	if ($passwordLength < 4)
	{
		$error .= "'New user password' is short<br>";
		$style .= "\n.userpassword {\n\tcolor : ".$constant['error-color']."\n}\n";
	}
	if ($newUserPassword != $confirmUserPassword)
	{
		$error .= "'New user password' and 'confirm password' different<br>";
		$style .= "\n.adminpassword {\n\tcolor : ".$constant['error-color']."\n}\n";
	}
	if ($passwordLength > 3 && $newUserPassword == $confirmUserPassword)
	{
		$updateUserPassword = md5($newUserPassword);
	}
	if ($userStatus == "enabled")
		$userStatus = 1;
	else
		$userStatus = 0;
	if ($error != "")
	{
		Header("Location: user-list.php?page=".$page);exit;
	}
	$cnt = 0;
	$newUserList = "<?php\n";
	$newUserList .= "\t\$user[0]['name'] = \"".$userName."\";\n";
	$newUserList .= "\t\$user[0]['mail'] = \"".$userMail."\";\n";
	$newUserList .= "\t\$user[0]['password'] = \"".$updateUserPassword."\";\n";
	$newUserList .= "\t\$user[0]['url'] = \"\";\n";
	$newUserList .= "\t\$user[0]['icq'] = \"\";\n";
	$newUserList .= "\t\$user[0]['country'] = \"\";\n";
	$newUserList .= "\t\$user[0]['city'] = \"\";\n";
	$newUserList .= "\t\$user[0]['day'] = \"\";\n";
	$newUserList .= "\t\$user[0]['month'] = \"\";\n";
	$newUserList .= "\t\$user[0]['year'] = \"\";\n";
	$newUserList .= "\t\$user[0]['time'] = \"".time()."\";\n";
	$newUserList .= "\t\$user[0]['status'] = \"".$userStatus."\";\n\n";
	$contentCnt = sizeof($user);
	for($i = 0; $i < $contentCnt; $i++)
	{
		$cnt++;
		while(list($key, $value) = each($user[$i]))
		{
			$newUserList .= "\t\$user[".$cnt."]['".$key."'] = \"".$value."\";\n";
		}
		if ($i != $contentCnt-1)
			$newUserList .= "\n";
	}
	$newUserList .= "?>";
	reWriteDataInFile ($newUserList,"../users-data.php");
	session_unregister("error");
	session_unregister("style");
	session_unregister("userName");
	session_unregister("userMail");
	session_unregister("newUserPassword");
	session_unregister("confirmUserPassword");
	session_unregister("userStatus");
	$timer->stop();
	Header("Location: user-list.php?".$timer->elapsed());exit;
?>
Return current item: Admbook