<?php
include 'include/db.php';
if(isset($_REQUEST['send_docket_request']))
{
// set default date format
date_default_timezone_set('Asia/Kolkata');      
$date=date("Y-m-d H:i:s");      //  for 24 hour

$id=$_REQUEST['unique_id'];
$type=$_REQUEST['type'];
$title=mysqli_real_escape_string($conn,$_REQUEST['subject']);
$mobile=mysqli_real_escape_string($conn,$_REQUEST['mobile']);
$msg=mysqli_real_escape_string($conn,$_REQUEST['msg']);
$issues_id=issues_id_create();
$query="insert into docket_request(docket_user_id,docket_user_mobile,docket_type,docket_title,docket_msg,issues_id,docket_date,docket_status)
        values('$id','$mobile','$type','$title','$msg','$issues_id','$date',0)";
$connection=mysqli_query($conn,$query);
if($connection)
{
    if($_SERVER['HTTP_REFERER']=='https://www.astrosyspvtltd.com/mlm2/user_help.php')
    {
        echo '<script> alert("Docket request send successfully"); window.location="user_help.php"; </script>';
    }
    else
    {
        echo '<script> alert("Docket request send successfully"); window.location="dashboard.php"; </script>';
    }
}
else
{
    echo '<script> alert("Docket not send"); window.location="dashboard.php"; </script>';
}


}  //  check submit button click or not
if($_REQUEST['resolve'])
{
    $id=$_REQUEST['hidden_id'];
   $query11="update docket_request set docket_status=1 where docked_request_id='$id'";
   $connection11=mysqli_query($conn,$query11);
   if($connection11)
   {
       echo '<script> alert("Docket request successfully resolved"); window.location="show_docket_request.php"; </script>';
   }
    
}


//  issues unique id generate
function issues_id_create(){
       include 'include/db.php';
       $qr2="select MAX(issues_id) from docket_request LIMIT 1";
        $con2=mysqli_query($conn,$qr2);
        if(mysqli_num_rows($con2)>0)
        {
        	while($rw=mysqli_fetch_array($con2))
        	{
        		 $xyz=$rw['MAX(issues_id)'];
        		 $ap=substr($xyz,3);
        		 $old_unique_id=intval($ap);  //  convert string to int
        	}
        	for ($num = $old_unique_id; $num <= $old_unique_id+1; $num++)
            $net_val=sprintf("%'.05d", $num);
            return 'isu'.$net_val;
        }
   }

?>