Location: PHPKode > projects > Tech Tickets > technician/tt_users.php
<?php include("../include/secure.php") ?>
<?php include("../include/connections.php") ?>
<?php mysql_select_db($database, $conn); ?>
<?php $self = ""; ?>
<html>
<head>
	<title>Users</title>
	<link href="../include/style.css" type="text/css" rel="stylesheet" />
	<style type="text/css">
	<!--
	td.t1{
		background-color:666666;
		color:#FFFFFF;
		font-family:Verdana, Arial, Helvetica, sans-serif;
		font-size:12px;
	}
	td.t2{
		background-color:CCCCCC;
		color:#000000;
		font-family:Verdana, Arial, Helvetica, sans-serif;
		font-size:12px;
	}
	td.t3{
		background-color:EFEFEF;
		color:#000000;
		font-family:Verdana, Arial, Helvetica, sans-serif;
		font-size:12px;
	}
	-->
	</style>
	<script>
	function deleteconfirm(id)
	{
	if(confirm("Are you sure you want to delete this user?"))
		window.location="tt_users.php?id="+id+"&action=delete"
	}
	</script>
</head>
<body topmargin="0">
<?php include("header.php"); ?>
<?php include("a_header.php"); ?>

<h1 align="center"><font face="Verdana, Arial, Helvetica, sans-serif">Users</font></h1><br>

<?
if ((!$_POST)&&(!$_GET)){
	
	$sql = 'SELECT * FROM tt_users WHERE Status <> 0 ORDER BY lastname';
	$rs = mysql_query($sql,$conn);
	print "<table border=0 bgcolor=FFFFFF cellspacing=2 cellpadding=3 align=center>";
	print "<tr bgcolor=666666>";
	print "<td></td>";
	print "<td class=t1>First Name</td>";
	print "<td class=t1>Last Name</td>";
	print "<td class=t1>Email</td>";
	print "<td class=t1>Phone</td>";
	print "</tr>";
	while($row = mysql_fetch_array($rs)) {
		$id = $row["UserID"];
		$firstname = $row["FirstName"];
		$lastname = $row["LastName"];
		$email = $row["Email"];
		$phone = $row["Phone"];
		if ($role=="T"){$role='Tech';}
		if ($role=="U"){$role='User';}
		print "<tr bgcolor=CCCCCC>";
		print "<td class=t2><input type='button' value='Edit' onclick=\"window.location='?id=$id&action=edit'\"></td>";
		print "<td class=t2>$firstname</td>";
		print "<td class=t2>$lastname</td>";
		print "<td class=t2>$email</td>";
		print "<td class=t2>$phone</td>";
		print "</tr>";
	}
	print "<tr><td colspan=6 align=center>";
	print "<input type='button' value='Add New User' onclick=\"window.location='?action=add'\"> ";
	print "<input type='button' value='Back' onclick=\"window.location='tt_admin.php'\">";
	print "</td></tr>";
	print "</table>";
	mysql_free_result($rs);
	
}else{
	
	if ($_POST){
		$action = $_POST['action'];
	}elseif ($_GET){
		$action = $_GET['action'];
	}
	
	if ($action == "edit"){
		
		if ($_POST){
			$id = $_POST['id'];
		}elseif ($_GET){
			$id = $_GET['id'];
		}
		
		$sql = "SELECT * FROM tt_users WHERE UserID = ".$id;
		$rs = mysql_query($sql,$conn);
		if (mysql_num_rows($rs)>0){
			$row = mysql_fetch_array($rs);
			$id = $row["UserID"];
			$firstname = $row["FirstName"];
			$lastname = $row["LastName"];
			$password = $row["Password"];
			$email = $row["Email"];
			$phone = $row["Phone"];
			$role = $row["Role"];
			$status = $row["Status"];
		}
		mysql_free_result($rs);
		
		print "<table border=0 bgcolor=FFFFFF cellspacing=2 cellpadding=3 align=center>";
		print "<form enctype=\"multipart/form-data\" action=\"$self\" method=\"post\">";
		print "<input type='hidden' name='action' value='update'>";
		print "<input type='hidden' name='id' value='$id'>";
		print "<tr><td class=t1 colspan=2 align=center><font color=FFFFFF><b>Edit User</b></font></td></tr>";
		print "<tr><td class=t3>First Name</td><td><input type=\"text\" name=\"firstname\" value=\"$firstname\" style=\"width=300;\"></td></tr>";
		print "<tr><td class=t3>Last Name</td><td><input type=\"text\" name=\"lastname\" value=\"$lastname\" style=\"width=300;\"></td></tr>";
		print "<tr><td class=t3>Password</td><td><input type=\"password\" name=\"password\" value=\"$password\" style=\"width=300;\"></td></tr>";
		print "<tr><td class=t3>Email </td><td><input type=\"text\" name=\"email\" value=\"$email\" style=\"width=300;\"></td></tr>";
		print "<tr><td class=t3>Phone</td><td><input type=\"text\" name=\"phone\" value=\"$phone\" style=\"width=300;\"></td></tr>";
		print "<tr><td class=t3>Role</td><td><select name='role'>";
		if($role=="U"){
			print "<option value='U' selected>User</option>";
			print "<option value='T'>Tech</option>";
		}
		if($role=="T"){
			print "<option value='U'>User</option>";
			print "<option value='T' selected>Tech</option>";
		}
		print "</select></td></tr>";
		print "<tr bgcolor=ffffff><td bgcolor=efefef>Status</td><td><select name='status'>";
		if($status=="0"){
			print "<option value='0' selected>Inactive</option>";
			print "<option value='1'>Active</option>";
		}
		if($status=="1"){
			print "<option value='0'>Inactive</option>";
			print "<option value='1' selected>Active</option>";
		}
		print "</select></td></tr>";
		
		print "<tr bgcolor=ffffff><td colspan='2' align='center'>";
		print "<input type='submit' value='Save'> ";
		print "<input type='button' value='Close' onclick=\"window.location='tt_users.php'\"> ";
		print "<input type='button' value='Delete' onclick=\"deleteconfirm($id);\">";
		print "</td></tr>";

		print "</form>";
		print "</table>";
		
	}
	elseif ($action == "add"){
		$createdate = DATE("m/d/y");
		print "<table border=0 bgcolor=FFFFFF cellspacing=2 cellpadding=3 align=center>";
		print "<form enctype=\"multipart/form-data\" action=\"$self\" method=\"post\">";
		print "<input type='hidden' name='action' value='insert'>";
		print "<tr><td class=t1 colspan=2 align=center><font color=FFFFFF><b>Add New User</b></font></td></tr>";
		print "<tr><td class=t3>First Name</td><td><input type=\"text\" name=\"firstname\" value=\"\" style=\"width=300;\"></td></tr>";
		print "<tr><td class=t3>Last Name</td><td><input type=\"text\" name=\"lastname\" value=\"\" style=\"width=300;\"></td></tr>";
		print "<tr><td class=t3>Password</td><td><input type=\"password\" name=\"password\" value=\"\" style=\"width=300;\"></td></tr>";
		print "<tr><td class=t3>Email</td><td><input type=\"text\" name=\"email\" value=\"\" style=\"width=300;\"></td></tr>";
		print "<tr><td class=t3>Phone</td><td><input type=\"text\" name=\"phone\" value=\"\" style=\"width=300;\"></td></tr>";
		print "<tr><td class=t3>Role</td><td><select name='role'><option value='U'>User</option><option value='T'>Tech</option></select></td></tr>";
		print "<tr><td class=t3>Status</td><td><select name='status'><option value='0'>Inactive</option><option value='1'>Active</option></select></td></tr>";
		print "<tr><td colspan=\"2\" align=\"center\">";
		print "<input type='submit' value='Save'> ";
		print "<input type='button' value='Close' onclick=\"window.location='tt_users.php'\">";
		print "</td></tr>";
		print "</form>";
		print "</table>";
	}
	elseif ($action == "update"){
		
		if ($_POST){
		
		$id = $_POST['id'];
		$firstname = $_POST['firstname'];
		$lastname = $_POST['lastname'];
		$password = $_POST['password'];
		$email = $_POST['email'];
		$phone = $_POST['phone'];
		$role = $_POST["role"];
		$status = $_POST["status"];
		}
		
		$sql = "UPDATE tt_users SET FirstName = '$firstname', LastName = '$lastname', Password = '$password', Email = '$email', Phone = '$phone', Role = '$role', Status = '$status' WHERE UserID = $id";
		//print "$sql";
		mysql_query($sql,$conn);
		
		//print "<input type=\"button\" value=\"movenext\" onclick=\"jumptonext();\">";
		print "<script>";
		//print "function jumptonext(){";
		print "window.location = \"tt_users.php\";";
		//print "}";
		print "</script>";
	}
	elseif ($action == "insert"){
		
		if ($_POST){
		$firstname = $_POST['firstname'];
		$lastname = $_POST['lastname'];
		$email = $_POST['email'];
		$phone = $_POST['phone'];
		$role = $_POST["role"];
		$status = $_POST["status"];
		}

		$sql = "INSERT INTO tt_users (FirstName, LastName, Password, Email, Phone, Role, Status) VALUES ('".$firstname."','".$lastname."','".$password."','".$email."','".$phone."','".$role."','".$status."')";
		//print "$sql";
		mysql_query($sql,$conn);
		
		//print "<input type=\"button\" value=\"movenext\" onclick=\"jumptonext();\">";
		print "<script>";
		//print "function jumptonext(){";
		print "window.location = \"tt_users.php\";";
		//print "}";
		print "</script>";
	}
	elseif ($action == "delete"){
		
		if ($_POST){
			$id = $_POST['id'];
		}elseif ($_GET){
			$id = $_GET['id'];
		}
		$sql = "UPDATE tt_users SET status = 0 WHERE UserID = ".$id;
		//$sql = "DELETE FROM players WHERE id = ".$id;
		mysql_query($sql,$conn);
		
		//print "<input type=\"button\" value=\"movenext\" onclick=\"jumptonext();\">";
		print "<script>";
		//print "function jumptonext(){";
		print "window.location = \"tt_users.php\";";
		//print "}";
		print "</script>";
	}
}
?>
<p>&nbsp;</p>
<?php include("footer.php"); ?>
</body>
</html>
<? mysql_close($conn); ?>
Return current item: Tech Tickets