Location: PHPKode > projects > Helpdesk Solutions > helpdesk/scripts/admin/admin_adduser.php
<?
include($DOCUMENT_ROOT.'/helpdesk/include/database.php');
include($DOCUMENT_ROOT.'/helpdesk/include/new_user.php');

session_start();

if ($valid != "yes") {
	header("Location: /helpdesk/login.php");
	exit;
}

$head = "Add a User";
$bttm_menu = " &nbsp;&nbsp;<a class=bttm_menu href='/helpdesk/scripts/main_adminmenu.php'>Main Menu</a>&nbsp;&nbsp;|
				&nbsp;&nbsp;<a class=bttm_menu href='/helpdesk/scripts/admin/admin_viewuser.php'>View Users</a>&nbsp;&nbsp;|
				&nbsp;&nbsp;<a class=bttm_menu href='/helpdesk/scripts/admin/admin_adduser.php'>Add a User</a>&nbsp;&nbsp;|
				&nbsp;&nbsp;<a class=bttm_menu href='/helpdesk/scripts/admin/admin_moduserview.php'>Modify a User</a>&nbsp;&nbsp;|
				&nbsp;&nbsp;<a class=bttm_menu href='/helpdesk/scripts/admin/admin_remuser.php'>Remove a User</a>&nbsp;&nbsp;|
				&nbsp;&nbsp;<a class=bttm_menu href='/helpdesk/logout.php'>Log Out</a>&nbsp;&nbsp;|
";
user_getDropMenu('per_id','per_name','get_per_id','permissions',$conn,$get_per_id,'no');
$per_select = $select;

user_getDropMenu('dept_name','dept_name','get_dept_id','department',$conn,$get_dept_id,'no');
$dept_select = $select;

user_getDropMenu('build_name','build_name','get_build_id','buildings',$conn,$get_build_id,'no');
$build_select = $select;

user_getDropMenu('site_name','site_name','get_site_id','sites',$conn,$get_site_id,'no');
$site_select = $select;


$bottom = "
<h1>Add a User</h1>

<form method=get action='$phpself'>
<table>
<th class=table_header colspan=3>Name and Contact Information</th>
<tr><td class=user width=180>First Name:<td>&nbsp;&nbsp;<td width=210><input type=text name=f_name value='$f_name' size=15>*<td>
<tr><td class=user>Middle Name:<td>&nbsp;&nbsp;<td><input type=text name=m_name value='$m_name' size=15><td class=bluetext_user>Just enter one middle name if more than one.
<tr><td class=user>Surname Name:<td>&nbsp;&nbsp;<td><input type=text name=l_name value='$l_name' size=15>*<td>
<tr><td class=user>E-Mail:<td>&nbsp;&nbsp;<td><input type=text name=email value='$email' size=30>*<td class=bluetext_user>The E-Mail needs to be valid.
<tr><td class=user>Work Phone No.:<td>&nbsp;&nbsp;<td><input type=text name=work_num value='$work_num' size=10>*<td>
<tr><td class=user>Mobile Phone No.:<td>&nbsp;&nbsp;<td><input type=text name=mobile_num value='$mobile_num' size=15><td>
<tr><td class=user>Fax Phone No.:<td>&nbsp;&nbsp;<td><input type=text name=fax_num value='$fax_num' size=15><td>
</table>
<br>
<table>
<th class=table_header>Login Details</th>
<tr><td class=pass width=180>Username:<td>&nbsp;&nbsp;<td width=210><input type=text name=username_temp value='$username_temp' size=15>*<td class=bluetext_user>Must be Unique. Usually in the format of -(firstname)(first letter of middle name)(first 3 letters of surname)-.
<tr><td class=pass>Password:<td>&nbsp;&nbsp;<td><input type=password name=password value='$password' size=10>*<td class=bluetext_user>No less than 5 characters.
<tr><td class=pass>Verify Password:<td>&nbsp;&nbsp;<td><input type=password name=password_val value='$password_val' size=10>*<td>
<tr><td class=pass>Access Level:<td>&nbsp;&nbsp;<td>$per_select<td>
</table>
<br>
<table border=0>
<th class=table_header colspan=2>Further Details</th>
<tr><td class=other width=180>Job Title:<td>&nbsp;&nbsp;<td><input type=text name=job_title value='$job_title' size=30><td>
<tr><td class=other>Department:<td>&nbsp;&nbsp;<td>$dept_select<td class=bluetext_user>
<tr><td class=other>Building:<td>&nbsp;&nbsp;<td>$build_select<td class=bluetext_user>
<tr><td class=other>Site:<td>&nbsp;&nbsp;<td>$site_select<td class=bluetext_user>
<tr><td class=other valign=top>Comments:<td>&nbsp;&nbsp;<td colspan=3><textarea name=comments value='$comments' cols=60 rows=5 wrap=virtual></textarea>
</table>
<br>
<input type=submit name=submit value='Add User to System'>
</form>

";


//This lot gets all the values from the database for selecting different configuration stuff.
if ($submit) {
	//Do the Checks

	if (!$f_name) { $msg[] = "- First Name."; $err = "1";}
	if (!$l_name) { $msg[] = "- Surname."; $err = "1";}
	if (!$email) { $msg[] = "- E-Mail."; $err = "1";}
	if (!$work_num) { $msg[] = "- Work Phone No."; $err = "1";}
	if (!$username_temp) { $msg[] = "- Username."; $err = "1";}
	if (!$password) { $msg[] = "- Password."; $err = "1";}
	if (!$password_val) { $msg[] = "- Verification Password."; $err = "1";}
	if (!$get_per_id) { $msg[] = "- Access Level."; $err = "1";}
	if (!$get_dept_id) { $msg[] = "- Department."; $err = "1";}
	if (!$get_build_id) { $msg[] = "- Building."; $err = "1";}
	if (!$get_site_id) { $msg[] = "- Site."; $err = "1";}
	if ($password != $password_val) { $msg[] = "- Passwords Do not match."; $err = "1";}

	if ($username_temp) {
		$sql="SELECT username FROM help_users";
		$result=mysql_query($sql,$conn);
		while ($row = mysql_fetch_array($result)) {
			$username_check = $row['username'];
			if ($username_check == $username_temp) {
				$msg[] = "- Username already exists - Please choose another."; $err = "1";
			}
		}
	}

	if ($err == "1") {
		$warning_temp = implode('<br> ', $msg);
	}

	//Now to validate the fields:
	if (!$err) {
		if (account_namevalid($username_temp) && account_pwvalid($password) && validate_email($email)) {
			$username_temp=strtolower($username_temp);
			$password=strtolower($password);
			
			$hash=md5($password);
			$sql = "INSERT INTO help_users (user_id,username,password,per_id,f_name,m_name,l_name,work_num,mobile_num,email,fax,job_title,dept_id, build_id,site_id,comments,mod_date) VALUES ('','$username_temp','$hash','$get_per_id','$f_name','$m_name','$l_name','$work_num','$mobile_num','$email','$fax_num','$job_title','$get_dept_id','$get_build_id','$get_site_id','$comments','$mod_date')";
			$result=mysql_query($sql,$conn);
			//echo $sql;
			if (!$result) {
				$warning .= '<td class=warning>** Database error - '.db_error();
			} else {
				$warning .= '<td class=success>** Successfully Added. <br> Please select a link from above';
			}	
		}
	}


} else {
	//$bottom = $bottom2;
}

if ($warning_temp) {
	$warning .= "<td class=warning>** Please fill in the following Values:<br>$warning_temp";
}

include($DOCUMENT_ROOT.'/helpdesk/include/template.inc.php');
?>
Return current item: Helpdesk Solutions