<table width="100%"  border="0" cellspacing="8" cellpadding="8">
  <tr>
    <td><?
include("../index.cma.db.php");
mysql_connect("$server", "$username", "$password");
mysql_select_db("$database");
$query = "Select * from tab_dataperkara where t_id = '1'"; 
$result = mysql_query($query); 
if($row2 = mysql_fetch_array($result)){ 
$mytable = $row2['t_table'];
$edisi = $row2['t_tahun'];
$page2 = $_GET["page2"];
if(empty($action))
{
if (empty($order)) $order =  2;
if (empty($page2))  $page2  =  1;
if (empty($hits))  $hits  = 500;
$start = $hits*($page2-1);
$query = "SELECT * FROM $mytable WHERE berkas_tahap1p21tgl !='' && berkas_p20 ='' ORDER BY uid DESC";
$res = mysql_query("$query"); 
$xnum = mysql_num_rows($res);
$stw2 = (int)($xnum/$hits);
if ($xnum%$hits > 0) {$stw2++;}
$np = $page2+1;
$pp = $page2-1;
if ($page2 == 1) { $pp=1; }
if ($np > $stw2) { $np = $stw2;} 
echo "TOTAL PERKARA TAHAP PENUNTUTAN $edisi SEBANYAK <strong>$xnum</strong> TERSANGKA | ";
for ($i=1;$i<=$stw2;$i++) {if($page2==$i){
echo "<b> HAL $i |</b> ";} 
else{echo "<a href=\"?g=tut&i=index&page2=$i#tab1\"> $i |</a>";}}
print ('<br><br>');
$query  = "SELECT * FROM $mytable ";
if(!empty($squery)) { $query .= "LIKE \"%$squery%\" ";}
$query .= "WHERE berkas_tahap1p21tgl !='' && berkas_p20 ='' ORDER BY uid DESC LIMIT $start,$hits";
$res = mysql_query($query);
print ('<table id="myTable" width="100%"  border="0" cellspacing="1" cellpadding="1" bgcolor="#B05800">
        <thead><tr>
<td width="30%"><strong>NAMA TERSANGKA/SURAT DARI/PASAL</strong></td>
<td width="10%"><strong>P21</strong></td>
<td width="15%"><strong>PANTAUAN P21</strong></td>
<td width="10%"><strong>TAHAP 2</strong></td>
<td width="15%"><strong>STATUS TAHAP 2</strong></td>
<td width="10%"><strong>LIMPAH</strong></td>
<td width="10%"><strong>SKPP/DIVERSI</strong></td>
</tr></thead><tbody>');
 $x=0;
  while($row = mysql_fetch_array($res))
  {
   $x++;
   if($x==2) {$barva = "FF6600";$x=0;} else {$barva = "FFFFCC";$x=1;}
print ('<tr bgcolor=#'.$barva.'><td><b>'.$row['spdp_namatsk'] .'</b><br>');
$polisi1 = $row['spdp_dari'];
 mysql_connect("$server", "$username", "$password");
mysql_select_db("$database");
$sql=mysql_query("select * from tab_polisi where p_nomor = '$polisi1'");
while ($data=mysql_fetch_array($sql)){
print(''.$data['p_nama'].'');
}

$id = $row['uid'];

print ('<i><br>'. $row['spdp_pasal'].'</i><br>Jaksa:<b>');
$jaksa1 = $row['p16_jaksa1'];
 mysql_connect("$server", "$username", "$password");
mysql_select_db("$database");
$sql=mysql_query("select * from tab_personil where daftar_pegid = '$jaksa1'");
while ($data=mysql_fetch_array($sql)){
print('<b>'.$data['daftar_nama'].'</b>');
}
print ('</b></td>');
print ('<td><center>'.$row['berkas_tahap1p21tgl'].'</center></td>');
print ('<td>');
 //start
if ($row['berkas_tahap1p21tgl'] !== '' && $row['berkas_tahap2tgl'] == '') { //jika p21 ada maka di proses statusnya
date_default_timezone_set('ASIA/JAKARTA'); 
$tgl1 = $row['berkas_tahap1p21tgl']; //Tgl P21
$tgl2 = date('d/m/Y'); 
$pecah1 = explode("/", $tgl1);$date1 = $pecah1[0];$month1 = $pecah1[1];$year1 = $pecah1[2];
$pecah2 = explode("/", $tgl2);$date2 = $pecah2[0];$month2 = $pecah2[1];$year2 =  $pecah2[2];
$jd1 = GregorianToJD($month1, $date1, $year1);
$jd2 = GregorianToJD($month2, $date2, $year2);
$selisih = abs($jd2 - $jd1);
//$selisih2 = strtotime ( '-7 day' , strtotime ( $jd2 ) ) ;
$timelate1 = "30"; //TGL MAKSIMAL p21 jika lebih terbitkan P21A oleh Pratut
$selisih2 = $selisih - $timelate;
//----IF KEDUA 
if ($row['berkas_tahap2tgl'] == '') {
if($selisih>=$timelate1) { 
$id = $row['uid'];
print ('<center><img src="./images/idcred.gif" width="32" height="16">');
print ('<br>Left : '.$selisih.'day(s)From '.$timelate1.'days');
echo "<br><a href=\"index.tut.post.tahapan.php?uid=$id&table=$mytable&do=p21a\" onclick=\"NewWindow(this.href,'mywin','600','200','yes','center');return false\" onfocus=\"this.blur()\" class=\"menu\"><b>SET P21.A</b></a></center>";
}
//$query = "UPDATE $mytable SET late_p31 = '3' WHERE uid = '$id'";
//$result = mysql_query($query);
//TUTUP
elseif($selisih<$timelate1){ 
print ('<center><img src="./images/idcgreen.gif" width="32" height="16">');
print ('<br>Run: '.$selisih.'day(s) From '.$timelate1.'days</center>');  //telat
}}
elseif ($row['berkas_tahap1p21tgl'] !== '' && $row['berkas_tahap2tgl'] !== '') {
print ('<center><b>SUDAH TAHAP 2</b></center>');
} }
print ('</td>');
////-------------------------------------END STATUS p21
print ('<td>');
if ($row['berkas_tahap2tgl'] == "" && $row['berkas_tahap1p21tgl'] !== '') {
echo "<center><a href=\"index.tut.post.tahapan.php?uid=$id&table=$mytable&do=tahap2\" onclick=\"NewWindow(this.href,'mywin','600','200','yes','center');return false\" onfocus=\"this.blur()\" class=\"menu\"><b>POST TAHAP 2</b></a></center>";
} 
elseif ($row['berkas_tahap2tgl'] !== '' && $row['berkas_tahap1p21tgl'] !== '') {
print ('<center>'. $row['berkas_tahap2tgl'].'</center>');} 
print ('</td>');
print ('<td>');
 //start
if ($row['berkas_tahap2tgl'] !== '') {
date_default_timezone_set('ASIA/JAKARTA'); 
$tgl1 = $row['berkas_tahap2tgl']; 
$tgl2 = date('d/m/Y'); 
$pecah1 = explode("/", $tgl1);$date1 = $pecah1[0];$month1 = $pecah1[1];$year1 = $pecah1[2];
$pecah2 = explode("/", $tgl2);$date2 = $pecah2[0];$month2 = $pecah2[1];$year2 =  $pecah2[2];
$jd1 = GregorianToJD($month1, $date1, $year1);
$jd2 = GregorianToJD($month2, $date2, $year2);
$selisih = abs($jd2 - $jd1);
//$selisih2 = strtotime ( '-7 day' , strtotime ( $jd2 ) ) ;
$timelate2 = "20";
$selisih2 = $selisih - $timelate2;
//----
if ($row['berkas_limpahp31tgl'] == '') {
if($selisih>=$timelate2) { 
$id = $row['uid'];
print ('<center><img src="./images/idcred.gif" width="32" height="16" alt="SEGERA LIMPAH">');
print ('<br>Left : '.$selisih.'day(s)From '.$timelate2.'days <br><font color="red"><b>T7 Habis<br>'. $row['berkas_t2t7hbs'].'</b></font>');
echo "<a href=\"index.tut.post.tahapan.php?uid=$id&table=$mytable&do=p31\" onclick=\"NewWindow(this.href,'mywin','600','200','yes','center');return false\" onfocus=\"this.blur()\" class=\"menu\"><b>SET P-31</b></a></center>";
$query = "UPDATE $mytable SET late_p31 = '3' WHERE uid = '$id'";
$result = mysql_query($query);}//TUTUP
elseif($selisih<$timelate2){ 
print ('<center><img src="./images/idcgreen.gif" width="32" height="16">');
print ('<br>Run: '.$selisih.'day(s) From '.$timelate2.'days</center>');
}} //telat
if ($row['berkas_limpahp31tgl'] !== '') {
print ('<center><b>OK</b></enter>');
}}
print ('</td>');
print ('<td>');
if ($row['berkas_limpahp31tgl'] == "" && $row['berkas_tahap2tgl'] !== "") {
echo "<a href=\"index.tut.post.tahapan.php?uid=$id&table=$mytable&do=p31\" onclick=\"NewWindow(this.href,'mywin','600','200','yes','center');return false\" onfocus=\"this.blur()\" class=\"menu\"><b>SET P-31</b></a></center>";
}
elseif ($row['berkas_limpahp31tgl'] !== '' && $row['berkas_tahap2tgl'] !== "") {
print ('<center>SUDAH DILIMPAH<br>'. $row['berkas_limpahp31tgl'].'<center>');} 
print ('</td>');
 print ('<td>');
if ($row['berkas_skpp'] == "" && $row['berkas_diversitut'] == "" && $row['berkas_diversi'] == "" && $row['berkas_p20'] == "" ) {
echo "<center><b><a href=\"index.tut.post.tahapan.php?uid=$id&table=$mytable&do=skpp\" onclick=\"NewWindow(this.href,'mywin','600','300','yes','center');return false\" onfocus=\"this.blur()\">POST<br>SKPP/Diversi</a></b></center>";
} 
elseif ($row['berkas_skpp'] !== "" && $row['berkas_diversi'] == "" && $row['berkas_diversitut'] !== "" && $row['berkas_p20'] == "" ) {
print ('<font color="green"><b><center>DIHENTIKAN<br>DIVERSI/SKPP<br>'.$row['berkas_skpp'].'<br>'.$row['berkas_diversitut'].'</center></b></font>');
} 
print ('</td>');
print ('</tr>');} 
print ('</tbody></table>');
echo "<br><br>Ditampilkan $hits /Halaman";
}}
?>
      </td>
  </tr>
</table>
