<?php 
session_start();
include './connection.php';
$datee=$_GET["nextdate"];
 

if($datee===""||$_GET["proceed"]==="")
{
	echo '<script>alert("Choose Date or Next Proceeding."); window.location.assign("./proceedings.php");  </script>';
	exit();
}
 
 		if($_GET["q"]=="0")
 		{
 			$datee=date("d/m/Y",strtotime($_GET["nextdate"])) ;
 		}

		$q1="SELECT * FROM caseproceedings WHERE pcourtid='".$_SESSION["court_id"]."' AND proceedingdate='".$datee."' AND caseid='".$_GET["caseid"]."'";


	$result=$conn->query($q1);
	if (!empty($result) && $result->num_rows > 0)
	 {
	 	$query="UPDATE caseproceedings SET status='1' ,proceeding='".$_GET["proceed"]."', proceedingdate='".$datee."'  WHERE pcourtid='".$_SESSION["court_id"]."' AND   caseid='".$_GET["caseid"]."'   ";

 			if(mysqli_query($conn,$query))
 			{
 					 
 				echo '<script>alert("Case Proceeding Has been Updated."); window.location.assign("./proceedings.php");  </script>';
 				exit();			

 			} else
 				{
 					echo '<script>alert("Case Proceeding Can not  Updated."); window.location.assign("./proceedings.php");  </script>';
 				}

 	

 	
	}
		else{
			$q11="UPDATE caseproceedings SET status='1'  WHERE pcourtid='".$_SESSION["court_id"]."' AND   caseid='".$_GET["caseid"]."'  ";

			
				$query1="INSERT INTO caseproceedings(caseid,proceeding,proceedingdate,pcourtid,status)VALUES('".$_GET["caseid"]."', '".$_GET["proceed"]."','".$datee."','".$_SESSION["court_id"]."','0')";
					if( mysqli_query($conn,$q11)&mysqli_query($conn,$query1))
						{
							 echo '<script>alert("Date Assigned to the Case successfully."); window.location.assign("./proceedings.php"); </script>';
						}
							else{
								 	echo '<script>alert("Can not Insert data..."); window.location.assign("./proceedings.php"); </script>';
								}
			}
			
	 

?>