Location: PHPKode > projects > Helpdesk Over Web > how/sysmgmt/newuser.php
<?php

// Purpose : Allow creation of new user. 

// Include Configuration File
require_once ('../includes/config.inc'); 

// Set the page title and include the HTML header.
$page_title = 'Helpdesk Over Web - Add System User';
include ('../includes/header.html');

// Check if form is submitted or blank.
if (isset($_POST['submit'])) // Check if the form has been submitted.
	{
	require_once ('../includes/mysql_connect.php'); // Connect to the database.
	 //If functions to check required fields were filled in. 
	if (empty($_POST['login'])) {
		$login = FALSE;
		echo '<H4><font color="red">ERROR - No Login Specified!</font></H4>';
	} else {
		$login = $_POST['login'];
	}
	if (empty($_POST['fullname'])) {
		$fullname = FALSE;
		echo '<H4><font color="red">ERROR - No User Full Name Specified!</font></H4>';
	} else {
		$fullname = $_POST['fullname'];
	}

	$role = $_POST['role'];
	$tel = $_POST['tel'];
	$email = $_POST['email'];
	$password = $_POST['password'];
	
	// If all OK, insert new user into database.
	if($login && $fullname)
	{
		$query = "INSERT INTO systemusers (HOWLogin, Password, Tel, Email, FullName, Role) VALUES ('$login', PASSWORD('$password'), '$tel', '$email', '$fullname', '$role');";
		$result = mysql_query($query)
		   or die("Invalid query: " . mysql_error());
		echo ("<H2>Operation Complete.</H2>");  
		echo ("<H4>User " . $fullname . " (" . $login . ") created.</H4>");
		echo ("<H4><A HREF='sysusers.php'>[ Main User Administration ]</A></H4>");

		// Include standard HTML footer
		include ('../includes/footer.html');
		exit();
	}
}
	// Output text/instructions for user.
	echo "<H1>System Users</H1>";
	echo "<H3>Create New User</H3>";
	echo "<P>Enter user details in the fields below.</P>";
	echo "<TABLE WIDTH='500' PADDING='2' SPACING='2'>";
	echo "<form action='newuser.php' method='post'>";
	echo "<TR><TD ALIGN='RIGHT'><B>System Login:<FONT COLOR='red' SIZE='-2'><B>*</B></FONT></B></TD><TD>&nbsp;&nbsp;<input type='text' name='login' size='12' maxlength='10' class='textbox'>&nbsp;&nbsp;[maximum of 10 characters]</TD></TR>";
	echo "<TR><TD ALIGN='RIGHT'><B>Full Name:<FONT COLOR='red' SIZE='-2'><B>*</B></FONT></B></TD><TD>&nbsp;&nbsp;<input type='text' name='fullname' size='60' maxlength='50' class='textbox'></TD></TR>";
	echo "<TR><TD ALIGN='RIGHT'><B>Password:<FONT COLOR='red' SIZE='-2'><B>*</B></FONT></B></TD><TD>&nbsp;&nbsp;<input type='text' name='password' value='password1234' size='20' class='textbox'>&nbsp;&nbsp;[user can change this once logged in]</TD></TR>";
	echo "<TR><TD ALIGN='RIGHT'><B>User Role:<FONT COLOR='red' SIZE='-2'><B>*</B></FONT></B></TD><TD>&nbsp;&nbsp;<select name='role' class='textbox'><option>Engineer</option><option>Helpdesk Manager<option>Senior Management</TD></TR>";
	echo "<TR><TD ALIGN='RIGHT'><B>Telephone:</B></TD><TD>&nbsp;&nbsp;<input type='text' name='tel' size='18' class='textbox'></TD></TR>";
	echo "<TR><TD ALIGN='RIGHT'><B>Email:</B></TD><TD>&nbsp;&nbsp;<input type='text' name='email' size='40' class='textbox'></TD></TR>";
	echo "<TR><TD ALIGN='CENTER' COLSPAN='2'><input type='submit' value=' Create User Account ' name='submit'>&nbsp;&nbsp;<input type='reset' value='Clear'></TD></TR>";
	echo "</TABLE></FORM>";
	echo "<FONT COLOR='red' SIZE='-2'><B>* INDICATES REQUIRED FIELD</B></FONT>";
	echo "<H4>[ <A HREF='sysusers.php'>User Administration Main Page</A> ]</H4>";

// Include standard HTML footer
include ('../includes/footer.html');
?>
Return current item: Helpdesk Over Web