<?php session_start();
include './connection.php';


$caseid=$_POST["id"];
$dtype=$_POST["dtype"];
$ddate=$_POST["ddate"];
$ddate=date("d/m/Y",strtotime($ddate));

	$query="INSERT INTO tbl_disposals (`case_id`, `court_id`, `dated`, `type`, `status`)VALUES('".$caseid."','".$_SESSION["court_id"]."','".$ddate."','".$dtype."','1')";
 	$q11="UPDATE caseproceedings SET status='1', proceeding='".$dtype."' WHERE   caseid='".$caseid."' ";
	$updquery="UPDATE `caseinfo` SET  `status`='0' WHERE ID=".$caseid."";
	
	
	$checkif="SELECT * FROM `tbl_disposals` WHERE case_id='".$caseid."'";
	$result=$conn->query($checkif);
	if($result->num_rows > 0 )
	{
	     echo '<script>alert("Case is already in disposed list."); window.location.assign("./proceedings.php");  </script>';
	             exit();
	}
	
	
	$q1="SELECT * FROM caseproceedings WHERE pcourtid='".$_SESSION["court_id"]."' AND proceedingdate='".$ddate."' AND caseid='".$caseid."'";


	$result1=$conn->query($q1);
	
	if (!empty($result1) && $result1->num_rows > 0)
	 {
	     $conn->query($updquery);
	     $conn->query($q11);
	    $conn->query($query);
	      echo '<script>alert("Case has been added to '.$dtype.' List of Cases."); window.location.assign("./proceedings.php");  </script>';
	         
	 }else{
	     $query1="INSERT INTO caseproceedings(caseid,proceeding,proceedingdate,pcourtid,status)VALUES('".$caseid."', '".$dtype."','".$ddate."','".$_SESSION["court_id"]."','0')";
					if(mysqli_query($conn,$query1))
						{
						      $conn->query($q11);
	                        $conn->query($query);
							 echo '<script>alert(" Case has been added to '.$dtype.' List of Cases."); window.location.assign("./proceedings.php"); </script>';
						}else{		 echo '<script>alert("There is issue Can not add the case."); window.location.assign("./proceedings.php"); </script>';}
	     
	 }
	
	
	
	
 
?>