<?php  
require "commonincludefiles.php";
error_reporting(1);
	
if($_SESSION["cCompany_id"]!="" && isset($_SESSION["cCompany_id"]))
{
	$objSupportInquiryMgmt = new clsMgmt();
	
	
 	$objSupportInquiryMgmt ->cust_id  = $_REQUEST["cust_id"] ; 
	
	
	$objSupportInquiryMgmt ->date1 = $_REQUEST['date1'] ;
	 //$objSupportInquiryMgmt ->customer_orgname       = $_REQUEST["customer_idhedden"] ;
    
	$objSupportInquiryMgmt ->address	= $_REQUEST['address'];
	$objSupportInquiryMgmt ->commu_person	= $_REQUEST['commu_person'];	
	$objSupportInquiryMgmt ->mobno	= $_REQUEST['mobno'];
	$objSupportInquiryMgmt ->phoneNo	= $_REQUEST['phoneNo'];	
	$objSupportInquiryMgmt ->cp_mobno	= $_REQUEST['cp_mobno'];	
	$objSupportInquiryMgmt ->problem_det	= $_REQUEST['problem_det'];	
	$objSupportInquiryMgmt ->completed_det	= $_REQUEST['completed_det'];	
	$objSupportInquiryMgmt ->status	= $_REQUEST['status'];
	$objSupportInquiryMgmt ->pending_reason	= $_REQUEST['pending_reason'];
	$objSupportInquiryMgmt ->pending_work	= $_REQUEST['pending_work'];	
	$objSupportInquiryMgmt->user_id  	= $_REQUEST["user_idhedden"] ;
	$objSupportInquiryMgmt ->user_name	= $_REQUEST['user_name'] ;
	$objSupportInquiryMgmt ->assign_user_id	= $_REQUEST['assign_user_idhedden'] ;
	
	$objSupportInquiryMgmt ->support_sdate	= $_REQUEST['support_sdate'];	
	$objSupportInquiryMgmt->support_edate  	= $_REQUEST["support_edate"] ;
	$objSupportInquiryMgmt ->support_timefrom	= $_REQUEST['support_timefrom'] ;
	$objSupportInquiryMgmt ->support_timeto	= $_REQUEST['support_timeto'] ;
	
	$objSupportInquiryMgmt ->cpmail1	= $_REQUEST['cpmail1'] ;
	
	$user_id =  $_SESSION["cUserId"]; //example from session variable
$cur_date = date('dmyHis'); //timestamp ticket submitted

	
	$objSupportInquiryMgmt ->ticket  = '#'.$user_id.'-'. $cur_date;
	
			
	/*if($_POST['send_sms']=='on')
	{
		$objCircularMgmt->send_sms	= 1;
	}*/
	 $objSupportInquiryMgmt ->customer_id  = $_REQUEST["customer_idhedden"] ; 
	    
if($objSupportInquiryMgmt->cust_id == "0" ||  $objSupportInquiryMgmt->cust_id== ""){ 
		$objSupportInquiryMgmt->add(); 
	} 
	else{
		if($_REQUEST['act'] == "del"){
			$objSupportInquiryMgmt->delete();
		 }else{
			 $objSupportInquiryMgmt->edit();
		}
		//echo'{"success":"false"}';
	
	 }
	 
 	if($_REQUEST['status'] =='on work')
		{
		$ach = "select lm.*,sp.* from lms_customer as lm,lms_cust as sp where lm.customer_id=sp.customer_id and
			lm.customer_id= ".$_REQUEST["customer_idhedden"]."";
			
			//echo $ach; exit;
	$resach = dbQuery($ach);
	$record = dbArray($resach);		
		
$to = $_REQUEST["cpmail1"];
$subject = 'Ticket Received - Software Support';

$message = "
<html>
<head>
<title ></title>
</head>
<body>
<p>This Is Auto Genrated Mail</p></br></br>
<p>Dear <b>".$record['customer_orgname']."</b></p>

<table border='1'>
<tr>
<th align='left'>Ticket </th>
<td>#$user_id - $cur_date</td>
</tr>
<tr>
<th align='left'>Worked By </th>
<td>".$_SESSION["cName"]."</td>
</tr>
<tr>
<th align='left'>Problem Details </th>
<td>".$_REQUEST["problem_det"]."</td>
</tr>
<tr>
<th align='left'>Work Status </th>
<td>".$_REQUEST['status']."</td>
</tr>
<tr>
<th align='left'>Conatact </th>
<td>'079-40054004,079-26870704'</td>
</tr>
<tr>
<th align='left'>From </th>
<td>'Aum Imagineering PVT LTD</td>
</tr>

</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";


// More headers
$headers .= 'From: <support@auminfosys.com>' . "\r\n";
//$headers .= 'Cc: myboss@example.com' . "\r\n";

mail($to,$subject,$message,$headers);
	
		}
	if($_REQUEST['status'] =='Completed')
		{
			//echo "hello"; exit;
		$ach = "select lm.*,sp.* from lms_customer as lm,lms_cust as sp where lm.customer_id=sp.customer_id and
			lm.customer_id= ".$_REQUEST["customer_idhedden"]."";
			
			//echo $ach; exit;
	$resach = dbQuery($ach);
	$record = dbArray($resach);		
		
$to = $_REQUEST["cpmail1"];
$subject = 'Ticket Resolved - Software Support';

$message = "
<html>
<head>
<title ></title>
</head>
<body>
<p>This Is Auto Genrated Mail</p></br></br>
<p>Dear <b>".$record['customer_orgname']."</b></p>
<table border='1'>
<tr>
<th align='left'>Ticket </th>
<td>#$user_id - $cur_date</td>
</tr>
<tr>
<th align='left'>Worked By </th>
<td>".$_SESSION["cName"]."</td>
</tr>
<tr>
<th align='left'>Completed Details </th>
<td>".$_REQUEST["completed_det"]."</td>
</tr>
<tr>
<th align='left'>Work Status </th>
<td>".$_REQUEST['status']."</td>
</tr>
<tr>
<th align='left'>Conatact </th>
<td>'079-40054004,079-26870704'</td>
</tr>
<tr>
<th align='left'>From </th>
<td>'Aum Imagineering PVT LTD</td>
</tr>

</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";


// More headers
$headers .= 'From: <support@auminfosys.com>' . "\r\n";
//$headers .= 'Cc: myboss@example.com' . "\r\n";

mail($to,$subject,$message,$headers);
	
		}
	 echo'{"success":"true"}';
	
	
	/*if($objSupportInquiryMgmt->cust_id=="0" || $objSupportInquiryMgmt->cust_id==""){
	
		$objSupportInquiryMgmt->add();
	}
	else{		
		$objSupportInquiryMgmt->edit();  
	}						
	echo '{"success":"true","msg":""}';
}
else {
	echo '{"success":"false","msg":"session expiry"}';*/
}	         
?>