Location: PHPKode > projects > Helpdesk Solutions > helpdesk/scripts/admin/admin_moduser.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 = "Modify 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;|
";


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_new != $password_val_new) { $msg[] = "- Passwords Do not match."; $err = "1";}

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

	//Now to validate the fields:
	if (!$err) {
		if (account_namevalid($username_temp) && validate_email($email)) {
			$username_temp=strtolower($username_temp);
			if (($password_new) && (account_pwvalid($password_new))) {
				$password_new=strtolower($password_new);
				$hash=md5($password_new);
				$pass_in = "password = '$hash',";
			}


				$sql = "UPDATE help_users SET 

				username = '$username_temp',
				$pass_in
				per_id = '$get_per_id',
				f_name = '$f_name',
				m_name = '$m_name',
				l_name = '$l_name',
				work_num = '$work_num',
				mobile_num = '$mobile_num',
				email = '$email',
				fax = '$fax',
				job_title = '$job_title',
				dept_id = '$get_dept_id',
				build_id = '$get_build_id',
				site_id = '$get_site_id',
				comments = '$comments',
				mod_date = '$mod_date'
				WHERE user_id = '$select_userid'
				";
				//echo $sql;
				$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';
					
				}
			//}
		

		}
	}


}







//Get the user info

$sql = "SELECT * FROM help_users WHERE user_id = '$select_userid'";
$result = mysql_query($sql,$conn);
while ($row = mysql_fetch_array($result)) {
	$user_id_dis = $row['user_id'];
	$f_name = $row['f_name'];
	$m_name = $row['m_name'];
	$l_name = $row['l_name'];
	$email = $row['email'];
	$work_num = $row['work_num'];
	$mobile_num = $row['mobile_num'];
	$fax = $row['fax'];
	$username_temp = $row['username'];
	$job_title = $row['job_title'];
	$get_per_id = $row['per_id'];
	$get_dept_id = $row['dept_id'];
	$get_build_id = $row['build_id'];
	$get_site_id = $row['site_id'];
	$comments = $row['comments'];
}




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>Modify 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 value='$fax' 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_new value='$password_new' size=10>*<td class=redtext>** Enter a password here only if you wish to change the old password! Original will not be changed if left blank.
<tr><td class=pass>Verify Password:<td>&nbsp;&nbsp;<td><input type=password name=password_val_new value='$password_val_new' 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 nowrap>Job Title:<td>&nbsp;&nbsp;<td><input type=text name=job_title value='$job_title' size=30><td>
<tr><td class=other nowrap>Department:<td>&nbsp;&nbsp;<td>$dept_select<td class=bluetext_user>
<tr><td class=other nowrap>Building:<td>&nbsp;&nbsp;<td>$build_select<td class=bluetext_user>
<tr><td class=other nowrap>Site:<td>&nbsp;&nbsp;<td>$site_select<td class=bluetext_user>
<tr><td class=other nowrap 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=hidden name=select_userid value='$select_userid'>
<input type=submit name=submit value='Save Modifications'>
</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) { $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 ($err == "1") {
		$warning_temp = implode('<br> ', $msg);
	}

	//Now to validate the fields:
	if (!$err) {
		if (account_namevalid($username) && account_pwvalid($password) && validate_email($email)) {
			$username=strtolower($username);
			$password=strtolower($password);
			
			//does the name exist in the database?
			$sql="SELECT * FROM help_users WHERE username='$username'";
			$result=mysql_query($sql,$conn);
			if ($result && db_numrows($result) > 0) {
				$warning .= "<td class=warning>** Username already exists. Please try another. ";
			} else {
				$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