Advertisement
cdsatrian

sms krs,kru,akademik

Feb 8th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.74 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  5.     <meta http-equiv='refresh' content='5; url=sms.php'>
  6.     <meta name="author" content="C4Hy4"/>
  7.     <meta name="updater" content="C4Hy4"/>
  8.     <title>SMS Autoresponse</title>
  9.     <style type="text/css">
  10.       //@import url(http://fonts.googleapis.com/css?family=Share);
  11.       body {
  12.         background: #fff;
  13.         //font-family : 'Share',Arial, Helvetica, sans-serif;
  14.         font-family : Arial, Helvetica, sans-serif;
  15.         margin:50px 0px; padding:0px;
  16.         text-align:center;  
  17.       }
  18.       .container {
  19.         width:390px;
  20.         margin:0px auto;
  21.         text-align:left;
  22.         padding:15px;
  23.         margin-top:5px;
  24.         margin-bottom:5px;
  25.         border:1px solid #D9E2E9;
  26.         -webkit-border-radius: 8px;
  27.         -moz-border-radius: 8px;
  28.         border-radius: 8px;
  29.       //border:1px dashed #333;
  30.       }
  31.       .format_list {
  32.         width:390px;
  33.         margin:0px auto;
  34.         -webkit-border-radius: 5px;
  35.         -moz-border-radius: 5px;
  36.         border-radius: 5px;        
  37.       }
  38.     </style>
  39.   </head>
  40.   <body>
  41.     <div id="container">
  42.       <h1> SMS FORMAT: </h1>
  43.       <fieldset class="format_list">
  44.         <legend><h2>INFORMASI KRS</h2></legend>
  45.         <div class="format_sms">
  46.           <div>format: NIM#KRS </div>
  47.           <div>contoh: 200922436#KRS </div>
  48.         </div>
  49.       </fieldset>
  50.       <fieldset class="format_list">
  51.         <legend><h2>INFORMASI KRU</h2></legend>
  52.         <div class="format_sms">
  53.           <div>format: NIM#KRU</div>
  54.           <div>contoh: 200922436#KRU</div>
  55.         </div>
  56.       </fieldset>
  57.       <fieldset class="format_list">
  58.         <legend><h2>INFORMASI AKADEMIK</h2></legend>
  59.         <div class="format_sms">
  60.           <div>format: NIM#AKADEMIK</div>
  61.           <div>contoh:  200922436#AKADEMIK</div>
  62.         </div>
  63.       </fieldset>      
  64.     </div>
  65. <?php
  66. //database configuration  
  67. $dbhost="localhost";
  68. $dbuser="root";
  69. $dbpass="root";
  70. $dbname="dbsms";
  71. //database connection  
  72. $db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);  
  73. //fungsi pengiriman SMS/memasukkan data ke table outbox
  74. function send_sms($db,$no,$pesan){
  75.   $masuk = $db->query(
  76.    "INSERT INTO outbox "
  77.   ."(InsertIntoDB,SendingDateTime,DestinationNumber,TextDecoded,SendingTimeOut,DeliveryReport,CreatorID)"
  78.   ." VALUES (sysdate(),sysdate(),'".$no."','".$pesan."',sysdate(),'yes','system')"
  79.   );
  80.   return $masuk;
  81. }
  82. //cek sms masuk
  83. $result = $db->query("SELECT ID,TextDecoded,SenderNumber FROM inbox WHERE Processed='false'");
  84. while ($data = $result->fetch_object()) {
  85.   $keyword = strtoupper($data->TextDecoded);
  86.   $explode = explode("#",trim($keyword));
  87.   $nim = $explode[0];
  88.   $code= $explode[1];
  89.   $queryhp="SELECT IF(SUBSTR(TRIM(hp),1,1)='0',CONCAT('+62',SUBSTR(TRIM(hp),2)),TRIM(hp)) AS nohp "
  90.           ."FROM mahasiswa "
  91.           ."WHERE nim='".$nim."' "
  92.           ."HAVING nohp='".$data->SenderNumber."'";
  93.   if ($cek_hp = $db->query($queryhp)){
  94.     if($cek_hp->num_rows>0){
  95.       // INFO KRS
  96.       if($code=='KRS')
  97.       {
  98.         $qry="SELECT pesan "
  99.             ."FROM KRS "
  100.             ."ORDER BY SendingDateTime DESC LIMIT 1";
  101.         if($record_krs = $db->query($qry))
  102.         {
  103.           $hasil = $record_krs->fetch_object();
  104.           $pesan =$hasil->pesan."\n";
  105.           $masuk = send_sms($db,$data->SenderNumber,$pesan);
  106.           $record_krs->close();
  107.         }
  108.         else
  109.         {
  110.           $pesan = "Info KRS yang Anda minta belum ada";
  111.           $masuk = send_sms($db,$data->SenderNumber,$pesan);
  112.         }  
  113.       }
  114.       // INFO KRU      
  115.       elseif($code=='KRU')
  116.       {
  117.         $qry="SELECT pesan "
  118.             ."FROM KRU "
  119.             ."ORDER BY SendingDateTime DESC LIMIT 1";
  120.         if ($record_kru = $db->query($qry))
  121.         {
  122.           $hasil = $record_kru->fetch_object();
  123.           $pesan =$hasil->pesan."\n";
  124.           $masuk = send_sms($db,$data->SenderNumber,$pesan);
  125.           $record_kru->close();      
  126.         }
  127.         else
  128.         {
  129.           $pesan = "Info KRU yang Anda minta belum ada";
  130.           $masuk = send_sms($db,$data->SenderNumber,$pesan);
  131.         }  
  132.       }
  133.       // INFO AKADEMIK  
  134.       elseif($code=='AKADEMIK')
  135.       {
  136.         $qry="SELECT pesan "
  137.             ."FROM AKADEMIK "
  138.             ."ORDER BY SendingDateTime DESC LIMIT 1";
  139.         if ($record_akademik = $db->query($qry))
  140.         {
  141.           $hasil = $record_akademik->fetch_object();
  142.           $pesan = $hasil->pesan."\n";
  143.           $masuk = send_sms($db,$data->SenderNumber,$pesan);
  144.           $record_akademik->close();
  145.         }
  146.         else
  147.         {
  148.           $pesan = "Info AKADEMIK yang Anda minta belum ada";
  149.           $masuk = send_sms($db,$data->SenderNumber,$pesan);
  150.         }
  151.       }
  152.       // INFO BANTUAN
  153.       elseif($code=="INFO")
  154.       {  
  155.         $pesan = "format sms, KRS : NIM#KRS , KRU : NIM#KRU , AKADEMIK : NIM#AKADEMIK, Bantuan : NIM#INFO ";
  156.         $masuk = send_sms($db,$data->SenderNumber,$pesan);
  157.       }
  158.       else
  159.       {
  160.         $pesan = "Keyword Anda salah/ perintah tidak tersedia";
  161.         $masuk = send_sms($db,$data->SenderNumber,$pesan);
  162.       }
  163.     }else{
  164.       $pesan = "No Anda tidak terdaftar, daftarkan nomor handphone Anda ke bagian Administrator Sistem "
  165.               ."untuk mendapatkan informasi nilai melalui SMS.";
  166.       $masuk = send_sms($db,$data->SenderNumber,$pesan);
  167.     }  
  168.   }
  169.   if ($masuk) {
  170.     //pilih mau diubah atau dihapus dari tabel, bila data sudah diproses
  171.     //$ubah = $db->query("UPDATE inbox SET Processed='true' WHERE ID='".$data->ID."'");
  172.     $db->query("DELETE FROM inbox WHERE ID='".$data->ID."'");
  173.   }  
  174. }
  175. $db->close();
  176. ?>
  177. </body>
  178. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement