query($user_query); $assigned_user_name = $adb->query_result($user_rt,0,"user_name"); $parent_type = $_REQUEST['parent_type']; $parent_id = $_REQUEST['parent_id']; $contact_id = $_REQUEST['contact_id']; $priority = $_REQUEST['priority']; $category = $_REQUEST['category']; $status = $_REQUEST['status']; $subject = $_REQUEST['subject']; $description = $_REQUEST['description']; $datemodified = date('YmdHis'); //$updatelog = "Ticket Created. Assigned To"; $return_action = $_REQUEST['return_action']; $return_module = $_REQUEST['return_module']; $return_id = $_REQUEST['return_id']; $mode = $_REQUEST['mode']; $estimated_finishing_date=$_REQUEST['estimated_finishing_date']; $estimated_finishing_time=$_REQUEST['estimated_finishing_time']; $estimated_date_and_time = $estimated_finishing_date.$estimated_finishing_time; if(isset($mode) && $mode != '' && $mode == 'Edit') { $ticketid = $_REQUEST['id']; //Updating History $tktresult = $adb->query("select * from troubletickets where id='".$ticketid."'"); $updatelog = $adb->query_result($tktresult,0,"update_log"); $old_user_id = $adb->query_result($tktresult,0,"assigned_user_id"); $old_status = $adb->query_result($tktresult,0,"status"); $old_priority = $adb->query_result($tktresult,0,"priority"); if($old_user_id != $assigned_user_id || $old_status != $status || $old_priority != $priority) { $updatelog .= date("l dS F Y h:i:s A").' by '.$current_user->user_name.'--//--'; } if($old_user_id != $assigned_user_id) { $updatelog .= ' Transferred to '.$assigned_user_name.'\.'; } if($old_status != $status) { $updatelog .= ' Status Changed to '.$status.'\.'; } if($old_priority != $priority) { $updatelog .= ' Priority Changed to '.$priority.'\.'; } if($old_user_id != $assigned_user_id || $old_status != $status || $old_priority != $priority) { $updatelog .= '--//--'; } $query="update troubletickets set groupname='".$groupname."',contact_id='".$contact_id."',priority='".$priority."',status='".$status."',parent_id='".$parent_id."',parent_type='".$parent_type."',category='".$category."',title='".$subject."',description='".$description."',update_log='".$updatelog."',date_modified=".$adb->formatString("troubletickets","date_modified",$datemodified).",assigned_user_id='".$assigned_user_id."', estimate_finish_time = '".$estimated_date_and_time."' where id=".$ticketid; //echo $query; $adb->query($query); save_customfields($ticketid); } else { $updatelog = date("l dS F Y h:i:s A").' by '.$current_user->user_name; $updatelog .='--//--Ticket created. Assigned to '.$assigned_user_name.'--//--'; //Inserting value into troubletickets table $query="insert into troubletickets values('','".$groupname."','".$contact_id."','".$priority."','".$status."','".$parent_id."','".$parent_type."','".$category."','".$subject."','".$description."','".$updatelog."','','".$datemodified."','".$datemodified."','".$assigned_user_id."','','".$estimated_date_and_time."')"; $adb->query($query); //Retreiving the id $idquery = "select max(id) as id from troubletickets"; $idresult = $adb->query($idquery); $customticketid = $adb->query_result($idresult,0,"id"); save_customfields($customticketid); if(! isset($return_id) || trim($return_id == '')) { $return_id = $customticketid; } } if($_REQUEST['send_mail']=='on') { $mail = new PHPMailer(); $sql="select * from users where id='".$_REQUEST['assigned_user_id']."'"; $result = $adb->query($sql); // $mailid=mysql_result($result,0,"email1"); if(!@$toname=$adb->query_result($result,0,"last_name")){} $sql="select * from contacts where id='".$_REQUEST['contact_id']."'"; $result = $adb->query($sql); if(!@$mailid=$adb->query_result($result,0,"email1")){} $sql1="select email1 from users where user_name='" .$current_user->user_name ."'" ; $result1 = $adb->query($sql1); $from = $adb->query_result($result1,0,"email1"); $str = "
Ticket Id: | ".$return_id." |
Category: | ".$_REQUEST['category']." |
Group: | ".$_REQUEST['assigned_group_name']." |
Status: | ".$_REQUEST['status']." |
Priority: | ".$_REQUEST['priority']." |
Submitted By: | ".$current_user->user_name." |
Assigned To: | ".$toname." |
Contact: | ".$_REQUEST['contact_name']." |
Summary: | ".$subject." |
"; // echo "Mailer Error: " . $mail->ErrorInfo; } } $loc = "Location: index.php?action=".$return_action."&module=".$return_module."&record=".$return_id; //echo "locisss ".$loc; header($loc); //Code to save the custom field info into database function save_customfields($entity_id) { global $adb; $dbquery="select * from customfields where module='HelpDesk'"; $result = $adb->query($dbquery); $custquery = 'select * from ticketcf where ticketid="'.$entity_id.'"'; $cust_result = $adb->query($custquery); if($adb->num_rows($result) != 0) { $columns=''; $values=''; $update=''; $noofrows = $adb->num_rows($result); for($i=0; $i<$noofrows; $i++) { $fldName=$adb->query_result($result,$i,"fieldlabel"); $colName=$adb->query_result($result,$i,"column_name"); if(isset($_REQUEST[$colName])) { $fldvalue=$_REQUEST[$colName]; if(get_magic_quotes_gpc() == 1) { $fldvalue = stripslashes($fldvalue); } } else { $fldvalue = ''; } if(isset($_REQUEST['id']) && $_REQUEST['id'] != '' && $adb->num_rows($cust_result) !=0) { //Update Block if($i == 0) { $update = $colName.'="'.$fldvalue.'"'; } else { $update .= ', '.$colName.'="'.$fldvalue.'"'; } } else { //Insert Block if($i == 0) { $columns='ticketid, '.$colName; $values='"'.$entity_id.'", "'.$fldvalue.'"'; } else { $columns .= ', '.$colName; $values .= ', "'.$fldvalue.'"'; } } } if(isset($_REQUEST['id']) && $_REQUEST['id'] != '' && $adb->num_rows($cust_result) !=0) { //Update Block $query = 'update ticketcf SET '.$update.' where ticketid="'.$entity_id.'"'; $adb->query($query); } else { //Insert Block $query = 'insert into ticketcf ('.$columns.') values('.$values.')'; $adb->query($query); } } else { if(isset($_REQUEST['id']) && $_REQUEST['id'] != '' && $adb->num_rows($cust_result) !=0) { //Update Block } else { //Insert Block $query = 'insert into ticketcf (ticketid) values('.$entity_id.')'; $adb->query($query); } } } ?>