<LINK href="images/index.css" rel="stylesheet" type="text/css">
<?PHP
date_default_timezone_set('ASIA/JAKARTA');
$tu_dbtahun1 = $_POST["tu_dbtahun"];
$jenis1 = $_POST["jenis"];
$berkas_anak1 = $_POST["berkasanak"];
$spdp_agenda1 = $_POST["s_agenda"];
$spdp_namaset = $_POST["s_nama"];
if ($spdp_namaset == "0")  {
$spdp_nama1 = "TANPA NAMA";} 
elseif ($spdp_namaset !== "0") {
$spdp_nama1 = $spdp_namaset;} 
$spdp_nik1 = $_POST["s_nik"];
$day1 = $_POST["day1"];
$month1 = $_POST["month1"];
$year1 = $_POST["year1"];
$spdp_tgl1 = "{$_POST[day1]}/{$_POST[month1]}/{$_POST[year1]}";
$spdp_nomorspdp1 = $_POST["s_nomorspdp"];
$spdp_nolaporan1 = $_POST["s_nolaporan"];
$spdp_dari1 = $_POST["s_spdpdari"]; //input database perkara
$spdp_dari2 = $_POST["spdpdari"]; //onchange database table surat
$namapenyidik1 = $_POST["namapenyidik"];
$telppenyidik1 = $_POST["telppenyidik"];
$telppelapor1 = $_POST["telppelapor"];
$spdp_terimatgl1 = "{$_POST[day2]}/{$_POST[month2]}/{$_POST[year2]}";
$spdp_pasalspdp1 = $_POST["s_pasalspdp"];
$tu_lamp1 = $_POST["tu_lamp"];
$error = "";
if ($spdp_nama1 == ""){$error = "Nama Tsk<BR>";}
if ($spdp_tgl1 == ""){$error = "Tanggal SPDP<BR>";}
if ($spdp_pasalspdp1 == ""){$error = "Pasal SPDP belum terisi<BR>";}
//cek agenda
include("../index.cma.db.php");
$query = "Select * from tab_dataperkara where t_id = '1'"; 
$result = mysql_query($query); 
if($row2 = mysql_fetch_array($result)){ 
$mytable = $row2['t_table'];
$query = "Select * from $mytable where spdp_noagenda = '$spdp_agenda1'";
$result = mysql_query($query); 
if ($row = mysql_fetch_array($result)){ 
if  ($row["spdp_noagenda"] == $spdp_agenda1){$error = "
<table width=\"100%\"  border=\"0\" cellspacing=\"8\" cellpadding=\"8\">
  <tr>
    <td bgcolor=\"#FF3300\"><b>DALAM DATABASE PIDANA UMUM TERDAPAT AGENDA SPDP GANDA YAITU NOMOR : $spdp_agenda1 SOLUSI : HAPUS MELALUI MENU PEJABAT PIDUM</td>
  </tr>
</table>
";

}
}
}
$query = "Select * from $tu_dbtahun1 where tu_noagenda = '$spdp_agenda1'";
$result = mysql_query($query); 
if ($row = mysql_fetch_array($result)){ 
if ($row["tu_noagenda"] == $spdp_agenda1){$error = "
<table width=\"100%\"  border=\"0\" cellspacing=\"8\" cellpadding=\"8\">
  <tr>
    <td bgcolor=\"#FF9933\"><b>DALAM DATABASE PERSURATAN TERDAPAT AGENDA SURAT GANDA YAITU NOMOR : $spdp_agenda1 SOLUSI : HAPUS MELALUI MENU PEJABAT PERSURATAN
</td>
  </tr>
</table>
";}
}
if ($error == ""){
//Start Database Surat
$query = "INSERT INTO $tu_dbtahun1 (tu_tglsrt, tu_tglterima, tu_noagenda, tu_asalsrt, tu_nosrt, tu_lamp, tu_perihal, tu_print) 
VALUES('$spdp_tgl1','$spdp_terimatgl1','$spdp_agenda1','$spdp_dari2','$spdp_nomorspdp1','$tu_lamp1','SPDP An.$spdp_nama1 - $spdp_pasalspdp1','1')";
$result = mysql_query($query);
//input database perkara
$day = 29; //Format waktu paling telat sesuai SOP
$data_tanggal_form = $spdp_terimatgl1;
if (!function_exists('jin_date_sql')) {
function jin_date_sql($date) 
{$exp = explode('/',$date);if(count($exp) == 3) {$date = $exp[2].'/'.$exp[1].'/'.$exp[0];}return $date;
}}
$convert = jin_date_sql($data_tanggal_form);
$tglawal = strtotime("$convert");
$tgl=date("d/m/Y",$tglawal);
$spdp_telattgl1=date("d/m/Y",strtotime("+".$day." day",$tglawal));
//-----------end
include("../index.cma.db.php");
$query = "Select * from tab_dataperkara where t_id = '1'"; 
$result = mysql_query($query); 
if($row2 = mysql_fetch_array($result)){ 
$mytable = $row2['t_table'];

$query = "INSERT INTO $mytable (spdp_noagenda, berkas_anak, spdp_namatsk, spdp_nik,spdp_dari, spdp_namapenyidik,spdp_telppenyidik,spdp_telppelapor,spdp_tgl, spdp_no, spdp_nolp, spdp_terimatgl, spdp_telattgl, spdp_pasal) VALUES ('$spdp_agenda1','$berkas_anak1','$spdp_nama1','$spdp_nik1','$spdp_dari1','$namapenyidik1','$telppenyidik1','$telppelapor1','$spdp_tgl1','$spdp_nomorspdp1','$spdp_nolaporan1','$spdp_terimatgl1','$spdp_telattgl1','$spdp_pasalspdp1')";
$result = mysql_query($query);
//Database SPDP end
if ($telppelapor1 == "0"){
print ('<table width="100%"  border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td bgcolor="#FF3300"><table width="100%"  border="0" cellspacing="4" cellpadding="4">
      <tr>
        <td>TANPA NOMOR TELP PELAPOR</td>
      </tr>
    </table></td>
  </tr>
</table>');
}
elseif ($telppelapor1 !== "0"){
//Sms Pelapor
$isipesan3 = "SPDP An.Tsk $spdp_nama1 $smspasal2 Telah diterima di Kejaksaan (DontReply)";
$DestinationNumber=addslashes(strip_tags($telppelapor1));	
$TextDecoded=addslashes(strip_tags($isipesan3)); 
$sql="INSERT INTO outbox (`UpdatedInDB` ,`InsertIntoDB` ,`SendingDateTime` ,`Text` ,`DestinationNumber` ,`Coding` ,`UDH` ,`Class` ,`TextDecoded` ,`ID` ,`MultiPart` ,`RelativeValidity` ,`SenderID` ,`SendingTimeOut` ,`DeliveryReport` ,`CreatorID`)
VALUES (NOW() , NOW(), '0000-00-00 00:00:00', NULL , '$DestinationNumber', 'Default_No_Compression', NULL , '-1', '$TextDecoded', NULL , 'false', '-1', NULL , '0000-00-00 00:00:00', 'default', '')";
mysql_query($sql); 
//End Sms Penyidik
$date = date("d");
$month = date("m");
$year = date("Y");
print ('<table width="100%"  border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td bgcolor="#FF3300"><table width="100%"  border="0" cellspacing="4" cellpadding="4">
      <tr>
        <td>SPDP AN TSK. <b>'.$spdp_nama1.' </b>BARU BERHASIL TERKIRIM KE PELAPOR/PENGADU DI NOMOR : <b>'.$telppelapor1.'</b> ISI PESAN : <b>'.$isipesan3.'</b></td>
      </tr>
    </table></td>
  </tr>
</table>');
}
print ('<table width="100%"  border="0" cellspacing="2" cellpadding="2">
	  <tr>
        <td><a href="index.php?g=postingspdp&i=index&day='.$day1.'&month='.$month1.'&year='.$year1.'&table='.$tahun.'&jenis='.$jenis1.'" class="menu">KLIK DISINI UNTUK KEMBALI</a></td>
      </tr>
  </tr>
</table>');
}}
else
{
echo "$error.";
} 
?>
