<?php
session_start();
include './connection.php';
 if(empty($_SESSION["user_id"])||$_SESSION["Logdin"]===false||empty($_SESSION["court_id"]))
{
    header("Location:login.php");
    exit();
}

?>





<!DOCTYPE html>
<html>
<head>
 

 
   
<style type="text/css">
    table,   td {
  border: 1px solid black;
  border-collapse: collapse;
  word-wrap: break-word;
 
        }
th  {
  border: 1px solid black;
  padding-top: 5px;
  padding-bottom: 5px;
  font-size: 18px;
}
 
body{
    font-family: jameel noori nastaleeq,Times New Roman;
}
</style>
</head>
<body>
 

<table id="myTable" style="width:100%;text-align:center;float:center;margin-left: 5px;margin-top:1px;">
 
	<tr style="color: black;background-color: lightgray;">
        
        <th> آئیندہ کاروائی </th>
        <th> آئیندہ پیشی </th>
	   <th>کاروائی</th>
	   <th>نوعیت/جرم</th>
         <th>عنوان مقدمہ</th>
    	<th>رجوعہ</th>
        <th>  مقدمہ/علت نمبر  </th>
        <th>شمار</th>
		
        
    </tr> 
<?php

$date=date("d/m/Y",strtotime($_POST["cdate"]));
 
 
$q="Select * from courts where ID=".$_SESSION["court_id"]."";
    $resul=$conn->query($q);
    if (!empty($resul) && $resul->num_rows > 0)
     {
 
 $r=$resul->fetch_assoc();
 echo '<h3 style="text-align:center;margin-top:2px;">Cause List for the Court of &nbsp '.$r["courtname"].'<br>'.$date.':مورخہ';
    }


 
 
$q1="SELECT * FROM caseproceedings WHERE pcourtid='".$_SESSION["court_id"] ."' AND proceedingdate='".$date."' ";
    $result=$conn->query($q1);
    if (!empty($result) && $result->num_rows > 0)
     {
 $i=1;
while( $row1=$result->fetch_assoc())
{
	$q11="Select * from caseinfo Where ID='".$row1["caseid"]."' AND currentcourtid='".$_SESSION["court_id"]."'";
    $result1=$conn->query($q11);
    if (!empty($result1) && $result1->num_rows > 0)
     {
       
     	$row=$result1->fetch_assoc();
     	if($row["casenature"]=="2")
     	{
     	    
     	    	echo "<tr>";

			$qq="SELECT * FROM caseproceedings WHERE caseid='".$row1["caseid"]."' AND status='0' AND  proceedingdate!='".$row1["proceedingdate"]."'";
			$res=$conn->query($qq);
            if( $res->num_rows > 0)
            {
                $rr=$res->fetch_assoc();  
                 echo '<td>'.$rr["proceeding"].'</td>';
                 echo '<td>'.$rr["proceedingdate"].'</td>';
            }
            else
            {
                    echo '<td></td>';
                    echo '<td></td>'; 
             }
                    echo '<td  id="pr">'.$row1["proceeding"].'</td>';
                    
                      $result6=$conn->query("SELECT * FROM tbl_criminal WHERE case_id='".$row["ID"]."'");
                     	$row6=$result6->fetch_assoc();
                     	
                     echo '<td>'.$row["casetype"].'/PS.'.$row6["ps"].'</td>';
                     
                     
                    echo '<td>'.$row["casetitle"].'</td>';
                    echo '<td width="35px">'.$row["instdate"].'/FIR-Date:'.$row6["fir_date"].'</td>';
                    echo '<td>(FIR No.'.$row6["fir_no"].')<a href="caseinfo.php?id='.$row1["caseid"].'&title='.$row["casetitle"].'">'.$row["caseno"].'</a></td>';
                    echo '<td>'.$i.'</td>';
                    $i++;
                    						 
    					echo "</tr>";
     	}
     	else{
     	    	echo "<tr>";

			$qq="SELECT * FROM caseproceedings WHERE caseid='".$row1["caseid"]."' AND status='0' AND  proceedingdate!='".$row1["proceedingdate"]."'";
			$res=$conn->query($qq);
            if( $res->num_rows > 0)
            {
                $rr=$res->fetch_assoc();  
                 echo '<td>'.$rr["proceeding"].'</td>';
                 echo '<td>'.$rr["proceedingdate"].'</td>';
            }
            else
            {
                    echo '<td></td>';
                    echo '<td></td>'; 
             }
                    echo '<td id="pr">'.$row1["proceeding"].'</td>';
                     echo '<td>'.$row["casetype"].'</td>';
                    echo '<td>'.$row["casetitle"].'</td>';
                    echo '<td width="35px">'.$row["instdate"].'</td>';
                    echo '<td><a href="caseinfo.php?id='.$row1["caseid"].'&title='.$row["casetitle"].'">'.$row["caseno"].'</a></td>';
                    echo '<td>'.$i.'</td>';
                    $i++;
                    						 
    					echo "</tr>";
    			 }
     	}
     
    
	}
}

		?>
</table>
<br>
دستخط ریڈر عدالت ھذا
<script>

 window.onload = sortTable();
function sortTable() {
  var table, rows, switching, i, x,y, shouldSwitch;
  table = document.getElementById("myTable");
  switching = true;
  /*Make a loop that will continue until
  no switching has been done:*/
  while (switching) {
    //start by saying: no switching is done:
    switching = false;
    rows = table.rows;
    /*Loop through all table rows (except the
    first, which contains table headers):*/
    for (i = 1; i < (rows.length - 1); i++) {
      //start by saying there should be no switching:
      shouldSwitch = false;
      /*Get the two elements you want to compare,
      one from current row and one from the next:*/
      x = rows[i].getElementsByTagName("TD")[2];
   y = rows[i+1].getElementsByTagName("TD")[2];
      //check if the two rows should switch place:
      if (x.innerText !="حاضری"&y.innerText=="حاضری")   {
        shouldSwitch = true;
        break;
      }
      
    }
    if (shouldSwitch) {
      /*If a switch has been marked, make the switch
      and mark that a switch has been done:*/
      rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
     
      switching = true;
    }
  }
   
   let j=1;
    for(j=1;j<rows.length;j++)
    {
         rows[j].getElementsByTagName("TD")[7].innerText=j;
    }   
}
</script>
 
</body>
</html>

























     











 