Location: PHPKode > projects > QUICKLYWEB > quicklyweb/admin/showtickets.php
<?
session_start();
header("Cache-control: private");

require("quicklyweb.php");
require("security/hybrid.php");

beginDocument($lShowTicket, $SESSION['sess_user']);

if ($TicketID) {
	$result = DBquery("SELECT * from Tickets WHERE TicketID=$TicketID", $db);
	$ticketrow = DBfetch_array($result);
	
	$whoopened = explode( ":", $ticketrow["Opener"] );
	
 	if ($whoopened[0] == "User") {
        	$result = DBquery("SELECT * FROM UserInfo WHERE UserID='$whoopened[1]'", $db);
        	$user_row = DBfetch_array($result);
	}
	else {
		$result = DBquery("SELECT * FROM Customers WHERE CustomerID='$whoopened[1]'", $db);
        	$user_row = DBfetch_array($result);
	}

if (!$_SESSION['sess_admin']) {
	if ($ticketrow["CustomerID"] != $_SESSION['sess_customer'])
		{
			                beginPrettyTable("2", $title);
                echo "<form method='GET' action='publicprofile.php'><tr>\n";
                echo "<td span=2><div class=data>Sorry, that ticket was not found!</div></td></tr><tr>";
                echo "<td><div class=data>Return to your account</div></td><td><input type='image' type='submit' value='submit' src='images/logout.png' alt='Back to Account'></td></tr></form>\n";			
		endPrettyTable();
		exit;
			}
		}

	beginPrettyTable("2", "$lTicketDetails");
	makeStaticField($lTicketID,     $ticketrow["TicketID"]);
	makeStaticField($lCustomerID,   $ticketrow["CustomerID"]);
	makeStaticField($lStatus,       $ticketrow["Status"]);
	makeStaticField($lDescription,  $ticketrow["Description"]);
	makeStaticField($lDateOpened,   $ticketrow["OpenDate"]);
	makeStaticField($lTimeOpened,   $ticketrow["OpenTime"]);
	
	if($ticketrow["Status"] != "Open") {
	makeStaticField($lDateClosed,   $ticketrow["CloseDate"]);
	makeStaticField($lTimeClosed,   $ticketrow["CloseTime"]);
		}
	if ($whoopened[0] == "User") {
	makeStaticField($lOpener,       $user_row["Firstname"]." ".$user_row["Lastname"]);
	}
	else {
		if (!$user_row["First"]) {
		 makeStaticField($lOpener,       $user_row["Company"]);
		}
		else {
		makeStaticField($lOpener,       $user_row["First"]." ".$user_row["Last"]);
		}
	}
	endPrettyTable();
	# Show any work tickets
  $result = DBquery("SELECT * from TicketWork WHERE TicketID=$TicketID", $db);
	$num = DBnum_rows($result);
	if ($num > 0) {
		echo "<h3>Work on this ticket:</h3>\n";
		while ($work_row = DBfetch_array($result)) {
			beginPrettyTable("2", "$lTicketWorkDetails");
			makeStaticField($lTicketWorkID,     $work_row["TicketWorkID"]);
			makeStaticField($lDescription,      $work_row["Description"]);
			$uid=$work_row["UserID"];
			$result2 = DBquery("SELECT Firstname,Lastname from UserInfo WHERE UserID=$uid", $db);
			$user_row = DBfetch_array($result2);
			$fname = $user_row["Firstname"]." ".$user_row["Lastname"];
			$worker = sprintf("%d (%s)",$uid,$fname);
			makeStaticField($lID,               $worker);
			makeStaticField($lDateWorked,       $work_row["WorkDate"]);
			makeStaticField($lTimeWorked,       $work_row["WorkTime"]);
			$url=$work_row["DocURL"];
			if ($url != "" && $url != "http://" ) {
				$url="<a href='$url'>$url</a>";
				makeStaticField($lDocURL, $url);
			}
			endPrettyTable();
		}
	}
} else {
	$class = "odd";

	# Read Priority Table
	$pres = DBquery("SELECT * FROM Priority", $db);
	checkDBError($db);
	$parr = array();
	while($res_row = DBfetch_array($pres)) {
		$pri  = $res_row["PriorityID"];
		$prin = $res_row["PriorityName"];
		$parr[$pri]=$prin;
	}

	# Read UserID Table
	$ures = DBquery("SELECT * FROM Users", $db);
	checkDBError($db);
	$uarr = array();
	while($res_row = DBfetch_array($ures)) {
		$usr = $res_row["UserID"];
		$ui_res = $db->query("SELECT Firstname,Lastname FROM UserInfo WHERE UserID=$usr");
		$ui_row = DBfetch_array($ui_res);
		$usrn = $ui_row["Firstname"]." ".$ui_row["Lastname"];
		$uarr[$usr]=$usrn;
	}

	$result = DBquery("SELECT * from Tickets WHERE Status='Open'", $db);
	beginPrettyTable("4", $lTicketDetails);
	beginBorderedTable(4);
	echo "<tr>";
	echo "<td align='center'><b>$lTicketID</b></td>";
	echo "<td align='center'><b>$lSubject</b></td>";
	echo "<td align='center'><b>$lPriority</b></td>\n";
	echo "<td align='center'><b>$lAssigned</b></td>\n";
	echo "</tr>";
	while ($row = DBfetch_array($result)) {
		if ($class == "odd") { $class = "even"; } else { $class = "odd"; }
		printf("<tr class='%s'>",$class);
		$tic = $row["TicketID"];
		$pri = $parr[$row["PriorityID"]];
		$asgn = "Administrator";
		$aid = $row["AssignedID"];
		if ($aid) {
			$asgn = $uarr[$aid];
		}
		echo "<td align='center'>";
		printf("<a href='showtickets.php?TicketID=%s'>%s</a>%s",$tic, $tic, $tdup);
		echo "</td>";
		printf("<td>%s</td>",$row["Subject"]);
		printf("<td>%s</td>",$pri);
		printf("<td>%s</td>",$asgn);
		echo "</tr>\n";
	}
	endBorderedTable();
	endPrettyTable();
	#beginPrettyTable("1", $lTicketDetails);
	#echo $lNoTicketsFound;
	#endPrettyTable();
	# Show Open Tickets
	# Show Closed Tickets that need to be Billed!
	# Show Closed Tickets
}
endDocument();
?>
Return current item: QUICKLYWEB