<?php session_start();
   require_once("../config/config.php");
   //require_once("../config/commonsetting.php");
   
   $myformId=SESS_MASTER;
   $myIp= ipCheck() ;
   $dateceated=date("Y-m-d G:i:s");
   $createdby='0';
   $full_name		=   secureSuperGlobalPOST($_REQUEST[SESS_MASTER.'name']);
   $ticket_cat		=   secureSuperGlobalPOST($_REQUEST[SESS_MASTER.'ticket_cat']);
   $message	=   secureSuperGlobalPOST($_REQUEST[SESS_MASTER.'message']);
     $user_id=$_SESSION[ADD_TAG.'_UserId_user'];
   
      $sql = "SELECT * FROM ticket_master ORDER BY rowId ASC";
   	 
      	$myquery=$conn->query($sql); 
   	$mydara= $myquery->fetchAll()  ;
   	
   	$rows_found = $myquery->rowCount();
   	 
   	if($rows_found==0){
   	$ticket_no='1001';
   		}else{
   			 
   			foreach( $mydara as $row ) {
   				$ticket_no		= $row['ticket_no'];
   				$u_id		= $row['user_id'];
   
   				 if($u_id==$user_id){
                       $activestatus		= $row['activestatus'];
                          $user_type		= $row['user_type'];
   
                        if($activestatus=='0'&&$user_type=='2'){
                              
   				             $status = $activestatus;
                               
   
                        header("location:../user-profile");
   
   
   
                        }
   
   				 }
   				
   			}
   
   			$ticket_no=$ticket_no+1;	
   		}
   
    if($_POST&&$status==''){
     try{
   		$olgaquery="INSERT INTO ticket_master SET createdIp='$myIp',datecreated='$dateceated',createdby='$createdby',  full_name='$full_name',ticket_category='$ticket_cat',ticket_status='0',user_id='$user_id',ticket_no='$ticket_no',user_type='2',activestatus='0'"; 
   		$stmt = $conn->prepare($olgaquery);
   		if($stmt->execute()){
   			$last_insert_id = $conn->lastInsertId();
   
   			$olgaquerys="INSERT INTO ticket_message SET createdIp='$myIp',datecreated='$dateceated',createdby='$createdby',  message='$message',user_id='$user_id',ticket_id='$last_insert_id',user_type='2',activestatus='0'"; 
   		$stmts = $conn->prepare($olgaquerys);
   		if($stmts->execute()){
   
   			$_SESSION["ticket_user"] = $last_insert_id ;
   			
   			 header("location:../user-profile-ids/5");
   
   			}
   		}
    
    
      }
            
           // show error
           catch(PDOException $exception){
               die('ERROR: ' . $exception->getMessage());
           }
       }
   
   
   ?>