Location: PHPKode > projects > Helpdesk Solutions > helpdesk/scripts/request/select_delrequest.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 = "Delete a Request";
$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/request/view_requests.php'>View Requests</a>&nbsp;&nbsp;|
				&nbsp;&nbsp;<a class=bttm_menu href='/helpdesk/scripts/request/select_user.php'>Create Request</a>&nbsp;&nbsp;|
				&nbsp;&nbsp;<a class=bttm_menu href='/helpdesk/scripts/request/search_request.php'>Search for a  Request</a>&nbsp;&nbsp;|
				&nbsp;&nbsp;<a class=bttm_menu href='/helpdesk/logout.php'>Log Out</a>&nbsp;&nbsp;|
";


$order_name = "requests";



//Checks if the current user has an order already set in dbase.
if (!$submit) {
	if (existorder($conn,$user_id,$order_name)) {
		getorder($conn,$user_id,$order_name); //Sets sessions at same time
		//echo "The order exists and the values are:<br> View: $view<br> request: $sorted<br> order: $ordering<br> supp: $support_view<br>";
		$view_in = $view;
		$request_sorted = $sorted;
		$user_order = $ordering;
		$sup_view = $support_view;
	} else {
		//add default values if no values have been set
		//$order_name = "users";
		//echo "Add the basic values cos there was no existing order<br>";
		$view_in = "all";
		$request_sorted = 'start_datetime';
		$user_order = '2';
		$sup_view = $user_id;
		addorder($user_id,$order_name,$view_in,$request_sorted,$user_order,$sup_view,$conn); //Sets sessions at same time
	}
}
//Any changes made to the order are added to the dbase here
if ($submit) {
	addorder($user_id,$order_name,$view_in,$request_sorted,$user_order,$sup_view,$conn);  //Sets sessions at same time
}

//Selects all helpdesk support users and adds them to a drop down list
$sql = "SELECT user_id, f_name, l_name, per_id FROM help_users WHERE per_id=1 OR per_id=2 OR per_id=3";
$result = mysql_query($sql,$conn) or die(mysql_errno().":2 ".mysql_error());
$select_beg = "<select name=sup_view>";
if (!$sup_view) {
	$select_start = "<option value='all'>All Staff</option>";
}
while ($row = mysql_fetch_array($result)) {
	$sup_id = $row['user_id'];
	$sup_fname = $row['f_name'];
	$sup_lname = $row['l_name'];
	$sup_name = "$sup_fname $sup_lname";
	if ($sup_id == $sup_view) {
		$select_start = "<option value='$sup_id'>$sup_name</option>";
	} else {
		$select2 .= "<option value='$sup_id'>$sup_name</option>";
	}
}
if ($sup_view == "all") {
	//echo "does equal all<br>";
	$select_start = "<option value='all'>All Staff</option>";
	$head_display = "<th nowrap class=table_header>Assigned To";
} else {
	$select2 .= "<option value='all'>All Staff</option>";
}
$assn_select = $select_beg.$select_start.$select2.'</select>';




//Drop down Menus
user_getDropMenu('view_name','view_name','view_in','view_order',$conn,$view_in,'no');
$view_select = $select;

user_getDropMenu('requests_dname','requests_sortedby','request_sorted','sortedby_requests',$conn,$request_sorted,'no');
$sorted_select = $select;

user_getDropMenu('order_id','order_name','user_order','order_order',$conn,$user_order,'no');
$order_select = $select;

//Set the sql for sorting the list
//echo "The view here is: $sup_view";
if ($sup_view) {
	if ($sup_view == "all") {
		$sql_where = "";
	}else {
		$sql_where = "WHERE assigned_to_id = '$sup_view'";  //The id # of the support staff
	}
}
if ($user_order) {
	if ($user_order == "2") {
		$sql_order = "DESC";
	} else {
		$sql_order = "ASC";
	}
}

if ($view_in) {
	//echo "There is a View<br>";
	//echo "Where is: $sql_where<br>";
	//echo "view in: $view_in<br>";
	if (($sql_where) && ($view_in == "Closed")) {
		//echo "In here? <br>";
		$sql_where .= " AND call_state = 'Closed'";
	} else if (($sup_view == "all") && ($view_in == "Closed")) {
		$sql_where = " WHERE call_state = 'Closed'";
	}
}  //****This needs working on when closed requests have been completed


//Retrieve permission names from database
//get_pernames($conn);

//echo "<br>Id here is: $user_id";

$user_list = "<table><tr>
								<th nowrap class=table_header>No.
								<th nowrap class=table_header>User Name
								<th nowrap class=table_header>Contact
								<th nowrap class=table_header>Summary
								<th nowrap class=table_header>Priority
								<th nowrap class=table_header>Status
								$head_display
								<th nowrap class=table_header>Complete within
								<th nowrap class=table_header>Date Created
							</tr>";

$sql = "SELECT * FROM requests $sql_where ORDER BY $request_sorted $sql_order";
//echo "$sql <br>";
//echo $sql;
$result = mysql_query($sql,$conn) or die(mysql_errno().":2 ".mysql_error());
while ($row = mysql_fetch_array($result)) {
	$request_id = $row['request_id'];
	$user_name = $row['user_name'];
	$request_used = $row['request_used'];
	$seluser_id = $row['user_id'];
	$contact_by = $row['contact_by'];
	$log_summary = $row['log_summary'];
	$call_prio = $row['call_prio'];
	$assigned_to_name = $row['assigned_to_name'];
	$call_state = $row['call_state'];
	$respond_bytime = $row['respond_bytime'];
	$start_datetime = $row['start_datetime'];

	respond_within($respond_bytime,$conn);

	get_contactnum($seluser_id,$contact_by,$conn);

	$respond_bytime = $elapsed;

	if ($sup_view == "all") {
		$list_display = "<td nowrap>| $chg <a class=pass_sml href='/helpdesk/scripts/request/mod_request.php?select_requestid=$request_id'>$assigned_to_name</a>";
	}
	
	if ($call_prio == "High") $call_prio = "<em class=smallred2>$call_prio</em>";
	if ($call_prio == "Medium") $call_prio = "<em class=smallorange2>$call_prio</em>";
	if ($call_prio == "Low") $call_prio = "<em class=smallyellow2>$call_prio</em>";

	if (!$alt) {
		$alt = "1";
	}
	if ($alt == "1") {
		$alt = "2";
		$chg = "<strong>";
	} else if ($alt == "2") {
		$alt = "1";
		$chg = "";
	}

	if ($user_sorted == "l_name") {
		$name_order = "$l_name $f_name";
	} else {
		$name_order = "$f_name $l_name";
	}
	$link = "";

	//if (($view_in != "open") && ($call_state != "Closed")) {

	if ($request_used == "yes") {

	$user_list .= "
		<tr>
			<td nowrap>$chg <a class=name_sml 
			href='/helpdesk/scripts/request/del_request.php?select_requestid=$request_id'>$request_id</a>
			<td nowrap>| $chg <a class=user_sml 
			href='/helpdesk/scripts/request/del_request.php?select_requestid=$request_id'>$user_name</a>
			<td nowrap>| $chg <a class=user_sml href='/helpdesk/scripts/request/del_request.php?select_requestid=$request_id'>$contact_num</a>
			<td nowrap>| $chg <a class=pass_sml href='/helpdesk/scripts/request/del_request.php?select_requestid=$request_id'>$log_summary</a>
			<td nowrap>| $chg <a class=pass_sml 
			href='/helpdesk/scripts/request/del_request.php?select_requestid=$request_id'>$call_prio</a>
			<td nowrap>| $chg <a class=pass_sml href='/helpdesk/scripts/request/del_request.php?select_requestid=$request_id'>$call_state</a>
			$list_display
			<td nowrap>| $chg <a class=other_sml href='/helpdesk/scripts/request/del_request.php?select_requestid=$request_id'>$respond_bytime</a>
			<td nowrap>| $chg <a class=other_sml href='/helpdesk/scripts/request/del_request.php?select_requestid=$request_id'>$start_datetime</a>

			
		</tr>";

	//}
	}
}


$bottom = "
<h3>Please select the Request you wish to delete:</h3>
<form method=get action=$phpself>
<tr class=standard><td nowrap class=bluetext>View Helpdesk Requests for $assn_select

<table>
<tr class=standard><td nowrap class=bluetext>View $view_select Groups, Sorted $sorted_select in $order_select order.
<input type=submit name=submit value='Go'>
</table>
</form>

<table>
$user_list
</table>
";
//echo "<br>Main User View2: $user_view";
//echo "<br>IS Set?:  $user_order_isset";
include($DOCUMENT_ROOT.'/helpdesk/include/template.inc.php');
?>
Return current item: Helpdesk Solutions