Location: PHPKode > projects > Helpdesk Solutions > helpdesk/scripts/request/add_request.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 = "Add 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;|
";

$start_datetime = date("H:i:s, D, M jS Y");		//The date in readable format
$today_datetime = date("Y-m-d H:i:s");			//The date to be put in database

//Get user contact information to add into form from passed user id
if (($select_userid) && (!$submit)) {
	$sql="SELECT f_name, l_name, email, work_num, mobile_num, fax FROM help_users WHERE user_id='$select_userid'";
	$result=mysql_query($sql,$conn);
	while ($row = mysql_fetch_array($result)) {
		$f_name = $row['f_name'];
		$l_name = $row['l_name'];
		$email = $row['email'];
		$work_num = $row['work_num'];
		$mobile_num = $row['mobile_num'];
		$fax = $row['fax'];
	}
	$users_name = "$f_name $l_name";
}



//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=assn_id>";
if (!$assn_id) {
	$select_start = "<option value=''>=Select an Option=</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 == $assn_id) {
		$select_start = "<option value='$sup_id'>$sup_name</option>";
	} else {
		$select2 .= "<option value='$sup_id'>$sup_name</option>";
	}
}
$assn_select = $select_beg.$select_start.$select2.'</select>';

//Generate a random number so that the unique request id can be obtained from the requests database
if (!$request_num) {
	user_gennum($conn);
}

//user_getDropMenu('per_id','per_name','get_per_id','permissions',$conn,$get_per_id,'no');
$per_select = $select;

user_getDropMenu('prio_name','prio_name','get_prio_id','priorities',$conn,$get_prio_id,'no');
$prio_select = $select;

user_getDropMenu('status_name','status_name','get_status_id','log_status',$conn,$get_status_id,'no');
$status_select = $select;

user_getDropMenu('type_name','type_name','get_type_id','request_type',$conn,$get_type_id,'no');
$type_select = $select;

//This sections checks the radio button on from previous submit
if ($contact_by) {
	if ($contact_by == "1") { $on1 = "checked=on"; }
	if ($contact_by == "2") { $on2 = "checked=on"; }
	if ($contact_by == "3") { $on3 = "checked=on"; }
	if ($contact_by == "4") { $on4 = "checked=on"; }
}

//This lot gets all the values from the database for selecting different configuration stuff.

if ($submit) {
	//Do the Checks

	if (!$assn_id) { $msg[] = "- Assigned to."; $err = "1";}
	if (!$get_prio_id) { $msg[] = "- Priority."; $err = "1";}
	if (!$get_status_id) { $msg[] = "- Status."; $err = "1";}
	if (!$get_type_id) { $msg[] = "- Type."; $err = "1";}
	if (!$summary) { $msg[] = "- Summary."; $err = "1";}
	if (!$prob_desc) { $msg[] = "- Problem Description."; $err = "1";}
	if (!$contact_by) { $msg[] = "- Contact Method."; $err = "1";}


	if ($contact_by) {
		if ($contact_by == '1') { if (!$email) { $msg[] = "- Selected Contact Method does not contain a value."; $err = "1";}	}
		if ($contact_by == '2') { if (!$work_num) { $msg[] = "- Selected Contact Method does not contain a value."; $err = "1";}	}
		if ($contact_by == '3') { if (!$fax) { $msg[] = "- Selected Contact Method does not contain a value."; $err = "1";}	}
		if ($contact_by == '4') { if (!$mobile_num) { $msg[] = "- Selected Contact Method does not contain a value."; $err = "1";}	}
	}

	if ($err == "1") {
		$warning_temp = implode('<br> ', $msg);
	}

	//Now to validate the fields:
	
	if (!$err) {

		user_getname($user_id,$conn);
		$log_name = $genout;
		user_getname($assn_id,$conn);
		$ass_name = $genout;

		calc_response($today_datetime,$get_prio_id,$conn);
		

		$sql = "UPDATE requests
		SET
		request_used = 'yes',
		user_name = '$users_name',
		user_id = '$select_userid',
		work_num = '$work_num',
		email = '$email',
		fax = '$fax',
		mobile_num = '$mobile_num',
		contact_by = '$contact_by',
		logged_by_name = '$log_name',
		logged_by_id = '$user_id',
		assigned_to_name = '$ass_name',
		assigned_to_id = '$assn_id',
		start_datetime = '$today_datetime',
		respond_bytime = '$plus_datetime2',
		call_prio = '$get_prio_id',
		call_type = '$get_type_id',
		call_state = '$get_status_id',
		linked_logs = '$linked',
		log_summary = '$summary',
		prob_desc = '$prob_desc',
		intern_anal = '$intern_anal',
		contact_history = '$contact_history',
		solution = '$solution'
		WHERE request_id = '$request_num'
		";
		//echo $sql;
		$result = mysql_query($sql,$conn) or die(mysql_errno().":2 ".mysql_error());	
		$warning = "<td class=success>** Request saved to database. ";

	}
}

//Get the response time from dbase to show on screen after request has been added to dbase.
$sql = "SELECT request_id, respond_bytime FROM requests WHERE request_id = '$request_num'";
$result = mysql_query($sql,$conn) or die(mysql_errno().":2 ".mysql_error());
while ($row = mysql_fetch_array($result)) {
	$respond_bytime = $row['respond_bytime'];
	//echo "Respond time: $respond_bytime <br>";
	if ($respond_bytime) {
		convert_date($respond_bytime);
		$logged_date = $output_date;
	}
}

if (!$logged_date) {
	$respond_by = "<em class=smalltxt>(Time and date will appear when request has been added)";
} else {
	$respond_by = $logged_date;
}

$bottom = "
<h1>Add a Request</h1>
<em class=greentext>*</em>  Please select prefered user contact method.<br>
<em class=redtext>*</em>  Required fields.<br>
<form method=get action='$phpself'>
<table cellspacing=4 border=0>
<tr><td class=user nowrap>Request No.:<td width=210 align=left>$request_num 
	<td class=user nowrap>Logged By:<td width=210>$name $user_id

<tr><td class=user nowrap>Users Name:<td align=left>$users_name
	

<tr><td class=user nowrap>E-Mail:<td align=left><input type=text name=email value='$email' size=20><input $on1 type=radio name=contact_by value=1><em class=greentext>*</em>
	<td class=user nowrap>Fax No.:<td width=210><input type=text name=fax value='$fax' size=15><input $on3 type=radio name=contact_by value=3><em class=greentext>*</em>

<tr><td class=user nowrap>Ext No.:<td width=210><input type=text name=work_num value='$work_num' size=15><input $on2 type=radio name=contact_by value=2><em class=greentext>*</em>
	<td class=user nowrap>Mobile No.:<td align=left><input type=text name=mobile_num value='$mobile_num' size=15><input $on4 type=radio name=contact_by value=4><em class=greentext>*</em>

<tr><td class=pass nowrap>Assigned To:<td align=left>$assn_select<em class=redtext>*</em>
	<td class=pass nowrap>Priority:<td width=210>$prio_select<em class=redtext>*</em>
	

<tr><td class=pass nowrap>Time & Date Started:<td align=left>$start_datetime
	<td class=pass nowrap>Status:<td width=210>$status_select<em class=redtext>*</em>

<tr><td class=pass nowrap>Respond by Time & Date:<td align=left colspan=2>$respond_by

<tr><td class=other nowrap>Summary:<td align=left><input type=text name=summary value='$summary' size=30 maxlength=30><em class=redtext>*</em>
	<td class=other nowrap>Type of problem:<td width=210>$type_select<em class=redtext>*</em>

<tr><td class=other nowrap>Linked Requests:<td align=left><input type=text name=linked value='$linked' size=25>

<tr><td class=other nowrap valign=top>Problem Description:<td align=left colspan=3><textarea name=prob_desc cols=60 rows=5 wrap=virtual>$prob_desc</textarea><em class=redtext>*</em>

<tr><td class=other nowrap valign=top>Internal Analysis:<td align=left colspan=3><textarea name=intern_anal cols=60 rows=5 wrap=virtual>$intern_anal</textarea>

<tr><td class=other nowrap valign=top>Contact History:<td align=left colspan=3><textarea name=contact_history cols=60 rows=5 wrap=virtual>$contact_history</textarea>

<tr><td class=other nowrap valign=top>Solution:<td align=left colspan=3><textarea name=solution cols=60 rows=5 wrap=virtual>$solution</textarea>

<input type=hidden name=users_name value='$users_name'>
<input type=hidden name=request_num value='$request_num'>
<input type=hidden name=select_userid value='$select_userid'>
<input type=hidden name=plus_datetime value='$plus_datetime'>
</table>
<br>
<input type=submit name=submit value='Add Request'>
</form>

";

if ($warning_temp) {
	$warning .= "<td class=warning>** Please fill in the following Values:<br><br>$warning_temp";
}

include($DOCUMENT_ROOT.'/helpdesk/include/template.inc.php');

?>
Return current item: Helpdesk Solutions