Location: PHPKode > projects > Tech Tickets > technician/tt_vendors.php
<?php include("../include/secure.php") ?>
<?php include("../include/connections.php") ?>
<?php mysql_select_db($database, $conn); ?>
<?php $self = ""; ?>
<html>
<head>
	<title>Vendors</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 vendor?"))
	window.location="tt_vendors.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">Vendors</font></h1><br>

<?
if ((!$_POST)&&(!$_GET)){
	
	$sql = 'SELECT * FROM tt_vendors WHERE Status <> 0 ORDER BY VendorName';
	$rs = mysql_query($sql,$conn);
	print "<table border=0 bgcolor=FFFFFF cellspacing=2 cellpadding=3 align=center>";
	print "<tr>";
	print "<td class=t1></td>";
	print "<td class=t1>Name</td>";
	print "<td class=t1>email</td>";
	print "<td class=t1>phone</td>";
	print "</tr>";
	while($row = mysql_fetch_array($rs)) {
		$id = $row["VendorID"];
		$name = $row["VendorName"];
		$email = $row["VendorEmail"];
		$phone = $row["VendorPhone"];
		print "<tr>";
		print "<td class=t2><input type='button' value='Edit' onclick=\"window.location='?id=$id&action=edit'\"></td>";
		print "<td class=t2>$name</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_vendors WHERE VendorID = ".$id;
		$rs = mysql_query($sql,$conn);
		if (mysql_num_rows($rs)>0){
			$row = mysql_fetch_array($rs);
			$id = $row["VendorID"];
			$name = $row["VendorName"];
			$email = $row["VendorEmail"];
			$phone = $row["VendorPhone"];
			$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><b>Edit Vendor</b></td></tr>";
		print "<tr><td class=t3>Name</td><td><input type=\"text\" name=\"name\" value=\"$name\" 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>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_vendors.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><b>Add Vendor</b></td></tr>";
		print "<tr><td class=t3>Name</td><td><input type=\"text\" name=\"name\" 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>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_vendors.php'\">";
		print "</td></tr>";
		print "</form>";
		print "</table>";
	}
	elseif ($action == "update"){
		
		if ($_POST){
		$id = $_POST['id'];
		$name = $_POST['name'];
		$email = $_POST['email'];
		$phone = $_POST['phone'];
		$status = $_POST["status"];
		}
		
		$sql = "UPDATE tt_vendors SET VendorName = '$name', VendorEmail = '$email', VendorPhone = '$phone', Status = '$status' WHERE VendorID = $id";
		//print "$sql";
		mysql_query($sql,$conn);
		
		//print "<input type=\"button\" value=\"movenext\" onclick=\"jumptonext();\">";
		print "<script>";
		//print "function jumptonext(){";
		print "window.location = \"tt_vendors.php\";";
		//print "}";
		print "</script>";
	}
	elseif ($action == "insert"){
		
		if ($_POST){
		$name = $_POST['name'];
		$email = $_POST['email'];
		$phone = $_POST['phone'];
		$status = $_POST["status"];
		}

		$sql = "INSERT INTO tt_vendors (VendorName,VendorEmail, VendorPhone, Status) VALUES ('".$name."','".$email."','".$phone."','".$status."')";
		//print "$sql";
		mysql_query($sql,$conn);
		
		//print "<input type=\"button\" value=\"movenext\" onclick=\"jumptonext();\">";
		print "<script>";
		//print "function jumptonext(){";
		print "window.location = \"tt_vendors.php\";";
		//print "}";
		print "</script>";
	}
	elseif ($action == "delete"){
		
		if ($_POST){
			$id = $_POST['id'];
		}elseif ($_GET){
			$id = $_GET['id'];
		}
		$sql = "UPDATE tt_vendors SET status = 0 WHERE VendorID = ".$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_vendors.php\";";
		//print "}";
		print "</script>";
	}
}
?>

<p>&nbsp;</p>
<?php include("footer.php"); ?>
</body>
</html>
<? mysql_close($conn); ?>
Return current item: Tech Tickets