list($h, $m, $s) = explode(":", $jmAkhir);
     list($thn, $mth, $dy) = explode("-", $tglAkhir);
     $dtAkhir = mktime($h, $m, $s, intval($mth), $dy, $thn);
     $dtSelisih = $dtAkhir - $dtAwal;
     //exit("Error:".$dtSelisih."___".$dtAkhir."___".$dtAwal."___".$mth."__".$dy."__".$thn);
     $totalmenit = $dtSelisih / 60;
     $jam = explode(".", $totalmenit / 60);
     $sisamenit = $totalmenit / 60 - $jam[0];
     $sisamenit2 = $sisamenit * 60;
     $jml_jam = $jam[0];
     //end ambil selisih waktu
     $sUpdate = "update " . $dbname . ".it_request set jumlah='" . $jml_jam . "',waktuselesai='" . $tlgjmskrng . "',saranpelaksana='" . $saran . "'\r\n                          where notransaksi='" . $notransaksi . "'";
     if (mysql_query($sUpdate)) {
         #send an email to incharge person
         $to = getUserEmail($rGet['karyawanid']);
         $namakaryawan = getNamaKaryawan($rGet['karyawanid']);
         $subject = "[Notifikasi]Permintaan layanan " . $rGet['keterangan'] . " a/n " . $namakaryawan;
         $body = "<html>\r\n                             <head>\r\n                             <body>\r\n                               <dd>Dengan Hormat,</dd><br>\r\n                               <p align=justify>\r\n                               Permintaan layanan " . $rGet['keterangan'] . " pada tanggal " . tanggalnormal($rGet['tanggal']) . " oleh saudara ke departemen IT\r\n                               dengan deskripsi " . $rGet['deskripsi'] . ".\r\n                               <br>\r\n                               <br>\r\n                               Telah selesai dilaksanakan pada tanggal " . tanggalnormald($tlgjmskrng) . ", mohon kesediaan saudara untuk memberi penilaian terhadap layanan kami dari menuIT->Permintaan Layanan\r\n                               <br>\r\n                               <br>\r\n                               Regards,<br>\r\n                               Owl-Plantation System.\r\n                             </body>\r\n                             </head>\r\n                           </html>\r\n                           ";
         $kirim = kirimEmail($to, '', $subject, $body);
         #this has return but disobeying;
     }
     break;
 case 'getDetail':
     $sData = "select distinct * from " . $dbname . ".it_request where notransaksi='" . $notransaksi . "' ";
     $qData = mysql_query($sData) or die(mysql_error($conn));
     $rData = mysql_fetch_assoc($qData);
     $dataTab .= "<div style=overflow:auto;width:420px;height:880px;>";
     $dataTab .= "<fieldset><legend>" . $_SESSION['lang']['desc'] . "</legend>";
     $dataTab .= "<div align=justify>" . $rData['deskripsi'] . "</p>";
     $dataTab .= "</fieldset><br />";
     $dataTab .= "<fieldset><legend>" . $_SESSION['lang']['saran'] . " " . $arrNmkary[$rData['karyawanid']] . " [user] </legend>";
function mailCoy($userid)
{
    #send an email to incharge person
    $to = getUserEmail($userid);
    $namakaryawan = getNamaKaryawan($_SESSION['standard']['userid']);
    if ($_SESSION['language'] == 'EN') {
        $subject = "[Notifikasi] PR Submission for approval, submitted by: " . $namakaryawan;
        $body = "<html>\r\n                             <head>\r\n                             <body>\r\n                               <dd>Dear Sir/Madam,</dd><br>\r\n                               <br>\r\n                               Today,  " . date('d-m-Y') . ",  on behalf of " . $namakaryawan . " submit a PR, requesting for your approval. To follow up, please follow the link below.\r\n                               <br>\r\n                               <br>\r\n                               <br>\r\n                               Regards,<br>\r\n                               Owl-Plantation System.\r\n                             </body>\r\n                             </head>\r\n                           </html>\r\n                           ";
    } else {
        $subject = "[Notifikasi]Persetujuan PP a/n " . $namakaryawan;
        $body = "<html>\r\n                             <head>\r\n                             <body>\r\n                               <dd>Dengan Hormat,</dd><br>\r\n                               <br>\r\n                               Pada hari ini, tanggal " . date('d-m-Y') . " karyawan a/n  " . $namakaryawan . " mengajukan Permintaan Pembelian Barang\r\n                               kepada bapak/ibu. Untuk menindak-lanjuti, silahkan ikuti link dibawah.\r\n                               <br>\r\n                               <br>\r\n                               <br>\r\n                               Regards,<br>\r\n                               Owl-Plantation System.\r\n                             </body>\r\n                             </head>\r\n                           </html>\r\n                           ";
    }
    $kirim = kirimEmail($to, '', $subject, $body);
    #this has return but disobeying;
}
     }
     break;
 case 'insert_persetujuan':
     $sql = "SELECT * FROM " . $dbname . ".`log_prapoht` WHERE `nopp`='" . $nopp . "' ";
     $query = mysql_query($sql) or die(mysql_error());
     $rest = mysql_fetch_assoc($query);
     if ($rest['close'] > 1) {
         echo "Warning: Status closed, Can't update the status";
         exit;
     } elseif ($rest['hasilpersetujuan1'] < 1) {
         $stat_cls = 1;
         $strx = "update " . $dbname . ". log_prapoht set persetujuan1='" . $user_id . "',close='" . $stat_cls . "'  where nopp='" . $nopp . "'";
         if (mysql_query($strx)) {
             #send an email to incharge person
             $to = getUserEmail($user_id);
             $namakaryawan = getNamaKaryawan($_SESSION['standard']['userid']);
             if ($_SESSION['language'] == 'EN') {
                 $subject = "[Notifikasi] PR Submission for approval, submitted by: " . $namakaryawan;
                 $body = "<html>\n\t\t\t\t\t\t\t <head>\n\t\t\t\t\t\t\t <body>\n\t\t\t\t\t\t\t   <dd>Dear Sir/Madam,</dd><br>\n\t\t\t\t\t\t\t   <br>\n\t\t\t\t\t\t\t   Today,  " . date('d-m-Y') . ",  on behalf of " . $namakaryawan . " submit a PR, requesting for your approval. To follow up, please follow the link below.\n\t\t\t\t\t\t\t   <br>\n\t\t\t\t\t\t\t   <br>\n\t\t\t\t\t\t\t   <br>\n\t\t\t\t\t\t\t   Regards,<br>\n\t\t\t\t\t\t\t   Owl-Plantation System.\n\t\t\t\t\t\t\t </body>\n\t\t\t\t\t\t\t </head>\n\t\t\t\t\t\t   </html>\n\t\t\t\t\t\t   ";
             } else {
                 $subject = "[Notifikasi]Persetujuan PP a/n " . $namakaryawan;
                 $body = "<html>\n\t\t\t\t\t\t\t <head>\n\t\t\t\t\t\t\t <body>\n\t\t\t\t\t\t\t   <dd>Dengan Hormat,</dd><br>\n\t\t\t\t\t\t\t   <br>\n\t\t\t\t\t\t\t   Pada hari ini, tanggal " . date('d-m-Y') . " karyawan a/n  " . $namakaryawan . " mengajukan Permintaan Pembelian Barang\n\t\t\t\t\t\t\t   kepada bapak/ibu. Untuk menindak-lanjuti, silahkan ikuti link dibawah.\n\t\t\t\t\t\t\t   <br>\n\t\t\t\t\t\t\t   <br>\n\t\t\t\t\t\t\t   <br>\n\t\t\t\t\t\t\t   Regards,<br>\n\t\t\t\t\t\t\t   Owl-Plantation System.\n\t\t\t\t\t\t\t </body>\n\t\t\t\t\t\t\t </head>\n\t\t\t\t\t\t   </html>\n\t\t\t\t\t\t   ";
             }
             $kirim = kirimEmail($to, '', $subject, $body);
             #this has return but disobeying;
         } else {
             echo " Gagal," . addslashes(mysql_error($conn));
         }
     } else {
         echo "Warning: Documents already in the process";
         exit;
 if ($rData['persetujuan2'] != '') {
     $to .= "," . $rData['persetujuan2'];
 }
 if ($rData['persetujuan3'] != '') {
     $to .= "," . $rData['persetujuan3'];
 }
 if ($rData['persetujuan4'] != '') {
     $to .= "," . $rData['persetujuan4'];
 }
 if ($rData['persetujuan5'] != '') {
     $to .= "," . $rData['persetujuan5'];
 }
 #send an email to incharge person
 $to = getUserEmail($to);
 $namakaryawan = getNamaKaryawan($rData['dibuat']);
 $nmpnlk = getNamaKaryawan($rData['persetujuan' . $_POST['kolom']]);
 if ($_SESSION['language'] == 'EN') {
     $subject = "[Notification] Partially or all items on PR No:" . $_POST['nopp'] . " submitted by " . $namakaryawan . " rejected by " . $nmpnlk;
     $body = "<html>\r\n                             <head>\r\n                             <body>\r\n                               <dd>Dear Sir/Madam,</dd><br>\r\n                               <br>\r\n                                Purchase Request No:" . $_POST['nopp'] . " rejected by [" . $nmpnlk . "]  corresponding to below notes:\r\n                               <br>\r\n                               Item rejected : <ul>";
     $sBrg = "select kodebarang,alasanstatus from " . $dbname . ".log_prapodt where nopp='" . $_POST['nopp'] . "' and status='3'";
     $qBrg = mysql_query($sBrg) or die(mysql_error($conn));
     while ($rBrg = mysql_fetch_assoc($qBrg)) {
         $body .= "<li>" . $nmBarang[$rBrg['kodebarang']] . ", note : " . $rBrg['alasanstatus'] . "</li>";
     }
     $body .= "</ul><br>\r\n                               <br>\r\n                               Regards,<br>\r\n                               Owl-Plantation System.\r\n                             </body>\r\n                             </head>\r\n                           </html>\r\n                           ";
 } else {
     $subject = "[Notifikasi] Sebagian atau Seluruhnya PP No :" . $_POST['nopp'] . " dari " . $namakaryawan . " ditolak oleh " . $nmpnlk;
     $body = "<html>\r\n                             <head>\r\n                             <body>\r\n                               <dd>Dengan Hormat,</dd><br>\r\n                               <br>\r\n                               Permintaan pembelian no." . $_POST['nopp'] . " ditolak oleh [" . $nmpnlk . "] dengan alasan.\r\n                               <br>\r\n                               Item yang ditolak adalah : <ul>";
     $sBrg = "select kodebarang,alasanstatus from " . $dbname . ".log_prapodt where nopp='" . $_POST['nopp'] . "' and status='3'";
     $qBrg = mysql_query($sBrg) or die(mysql_error($conn));
     while ($rBrg = mysql_fetch_assoc($qBrg)) {
     }
     break;
 case 'updatePelaksana':
     $sCek = "select distinct * from " . $dbname . ".it_request where notransaksi='" . $notransaksi . "'";
     $qCek = mysql_query($sCek) or die(mysql_error($conn));
     $rCek = mysql_fetch_assoc($qCek);
     if ($rCek['statusatasan'] != '1') {
         exit("Error: Status Atasan Tidak di Setujui");
     }
     $sUpdate = "update " . $dbname . ".it_request set pelaksana='" . $pelaksana . "',waktupelaksanaan='" . $tlgjmskrng . "',statusmanagerit='1'\r\n                          where notransaksi='" . $notransaksi . "'";
     if (mysql_query($sUpdate)) {
         #send an email to incharge person
         $to = getUserEmail($pelaksana);
         $namakaryawan = getNamaKaryawan($pelaksana);
         $subject = "[Notifikasi]Permintaan layanan " . $rGet['keterangan'] . " a/n " . $namakaryawan;
         $body = "<html>\r\n                             <head>\r\n                             <body>\r\n                               <dd>Dengan Hormat,</dd><br>\r\n                               <p align=justify>\r\n                               Karyawan a/n: " . getNamaKaryawan($rCek['karyawanid']) . " meminta layanan " . $optNmKeg[$rCek['kodekegiatan']] . " pada tanggal " . tanggalnormal($rGet['tanggal']) . " ke departemen IT\r\n                               dengan deskripsi " . $rGet['deskripsi'] . ".\r\n                               <br>\r\n                               <br>\r\n                               mohon dibantu, dan jika sudah selesai jangan lupa update status pelaksanaannya dari menu IT->request response\r\n                               <br>\r\n                               <br>\r\n                               Regards,<br>\r\n                               Owl-Plantation System.\r\n                             </body>\r\n                             </head>\r\n                           </html>\r\n                           ";
         $kirim = kirimEmail($to, '', $subject, $body);
         #this has return but disobeying;
     }
     break;
 case 'updateTolak':
     $sUpdate = "update " . $dbname . ".it_request set statusmanagerit='" . $ketTolak . "'\r\n                          where notransaksi='" . $notransaksi . "'";
     if (!mysql_query($sUpdate)) {
         echo " Gagal:" . addslashes(mysql_error($conn)) . "___" . $sUpdate;
     }
     break;
 case 'getDetail':
     $sData = "select distinct * from " . $dbname . ".it_request where notransaksi='" . $notransaksi . "' ";
     $qData = mysql_query($sData) or die(mysql_error($conn));
     $rData = mysql_fetch_assoc($qData);
     $dataTab .= "<div style=overflow:auto;width:420px;height:300px;>";
        $tab .= "</table></fieldset><input type='hidden' id=karyaid value=" . $krywnId . " /><input type=hidden id=tglIjin value=" . tanggalnormal($tglijin) . "/>";
        echo $tab;
        break;
    case 'forwardData':
        $sup = "update " . $dbname . ".sdm_ijin set persetujuan1='" . $atasan . "' where {$where}";
        if (mysql_query($sup)) {
            $sKar = "select distinct * from " . $dbname . ".sdm_ijin where {$where}";
            $qKar = mysql_query($sKar) or die(mysql_error($conn));
            $rKar = mysql_fetch_assoc($qKar);
            $strf = "select sisa from " . $dbname . ".sdm_cutiht where karyawanid=" . $krywnId . " \r\n                        and periodecuti=" . $rKar['periodecuti'];
            $res = mysql_query($strf);
            $sisa = '';
            while ($barf = mysql_fetch_object($res)) {
                $sisa = $barf->sisa;
            }
            if ($sisa == '') {
                $sisa = 0;
            }
            $to = getUserEmail($atasan);
            $namakaryawan = getNamaKaryawan($krywnId);
            $subject = "[Notifikasi]Persetujuan Ijin Keluar Kantor a/n " . $namakaryawan;
            $body = "<html>\r\n                    <head>\r\n                    <body>\r\n                    <dd>Dengan Hormat,</dd><br>\r\n                    <br>\r\n                    Pada hari ini, tanggal " . date('d-m-Y') . " karyawan a/n  " . $namakaryawan . " mengajukan Ijin/" . $rKar['jenisijin'] . " (" . $rKar['keperluan'] . ")\r\n                    kepada bapak/ibu. Untuk menindak-lanjuti, silahkan ikuti link dibawah.\r\n                    <br>\r\n                    <br>\r\n                    Note: Sisa cuti ybs periode " . $rKar['periodecuti'] . ":" . $sisa . " Hari\r\n                    <br>\r\n                    <br>\r\n                    Regards,<br>\r\n                    Owl-Plantation System.\r\n                    </body>\r\n                    </head>\r\n                    </html>\r\n                    ";
            $kirim = kirimEmail($to, '', $subject, $body);
            #this has return but disobeying;
        } else {
            echo "DB Error : " . mysql_error($conn);
        }
        break;
    default:
        break;
}