Advertisement
cdsatrian

sms-nilai-ipk

Aug 6th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.08 KB | None | 0 0
  1. <html>
  2.   <head>
  3.     <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  4.     <meta http-equiv='refresh' content='2; url=sms.php'>
  5.     <meta name="author" content="C4Hy4"/>
  6.     <meta name="updater" content="C4Hy4"/>
  7.     <title>SMS Autoresponse</title>
  8.     <style type="text/css">
  9.       @import url(http://fonts.googleapis.com/css?family=Share);
  10.       body {
  11.     background: #fff;
  12.     font-family : 'Share',Arial, Helvetica, sans-serif;
  13.         margin:50px 0px; padding:0px;
  14.     text-align:center; 
  15.       }
  16.       .container {
  17.         width:390px;
  18.     margin:0px auto;
  19.     text-align:left;
  20.     padding:15px;
  21.         margin-top:5px;
  22.         margin-bottom:5px;
  23.         border:1px solid #D9E2E9;
  24.         -webkit-border-radius: 8px;
  25.         -moz-border-radius: 8px;
  26.         border-radius: 8px;
  27.     //border:1px dashed #333;
  28.       }
  29.       .format_list {
  30.         width:390px;
  31.         margin:0px auto;
  32.         -webkit-border-radius: 5px;
  33.         -moz-border-radius: 5px;
  34.         border-radius: 5px;        
  35.       }
  36.     </style>
  37.   </head>
  38.   <body>
  39.     <div id="container">
  40.       <h1> SMS FORMAT: </h1>
  41.       <fieldset class="format_list">
  42.         <legend><h2>Nilai per Semester</h2></legend>
  43.         <div class="format_sms">
  44.           <div>format: N#NIM#SEMESTER </div>
  45.           <div>contoh: N#201201#I </div>
  46.         </div>
  47.       </fieldset>
  48.       <fieldset class="format_list">
  49.         <legend><h2>Nilai IPK</h2></legend>
  50.         <div class="format_sms">
  51.           <div>format: I#NIM</div>
  52.           <div>contoh:  I#201201</div>
  53.         </div>
  54.       </fieldset>
  55.       <fieldset class="format_list">
  56.         <legend><h2>Bantuan</h2></legend>
  57.         <div class="format_sms">
  58.           <div>format: H#NIM</div>
  59.           <div>contoh:  H#201201</div>
  60.         </div>
  61.       </fieldset>      
  62.     </div>
  63. <?php
  64. //koneksi ke database
  65. mysql_connect("localhost","root","root");
  66. mysql_select_db("smsd");
  67.  
  68. //fungsi pengiriman SMS/memasukkan data ke table outbox
  69. function send_sms($no,$pesan){
  70.   $masuk = mysql_query(
  71.    "INSERT INTO outbox "
  72.   ."(InsertIntoDB,SendingDateTime,DestinationNumber,TextDecoded,SendingTimeOut,DeliveryReport,CreatorID)"
  73.   ." VALUES (sysdate(),sysdate(),'".$no."','".$pesan."',sysdate(),'yes','system')"
  74.   );
  75.   return $masuk;
  76. }
  77. //cek sms masuk
  78. $sql = mysql_query("SELECT ID,TextDecoded,SenderNumber FROM inbox WHERE Processed='false'");
  79. while ($data = mysql_fetch_object($sql)) {
  80.   $keyword = strtoupper($data->TextDecoded);
  81.   $explode = explode("#",trim($keyword));
  82.   $param1 = isset($explode[2])?$explode[2]:'';
  83.   $nim = $explode[1];
  84.   $code= $explode[0];
  85.   $cek_hp = mysql_query("SELECT hp FROM mahasiswa WHERE hp='".$data->SenderNumber."' AND nim='".$nim."'");
  86.   $cari = mysql_num_rows($cek_hp);
  87.   $pesan='';
  88.   if ($cari == 0) {
  89.     $pesan = "No Anda tidak terdaftar, daftarkan nomor handphone Anda ke bagian Administrator Sistem "
  90.             ."untuk mendapatkan informasi nilai melalui SMS.";
  91.     $masuk = send_sms($data->SenderNumber,$pesan);
  92.   }else {
  93.     // Nilai per semester
  94.     if($code=='N' && $param1!=''){
  95.       $qry="SELECT m.makul_singkat, n.nilai "
  96.        ."FROM nilai n, makul m "
  97.        ."WHERE m.semester='".$param1."' "
  98.        ." AND n.nim='".$nim."' "
  99.        ." AND n.kd_makul=m.kd_makul "
  100.        ." AND n.semester=m.semester";
  101.       $record_nilai = mysql_query($qry);
  102.       $ketemu = mysql_num_rows($record_nilai);
  103.       if ($ketemu == 0) {
  104.         $pesan = "Nilai yang Anda minta belum ada / Keyword Anda salah.";
  105.         $masuk = send_sms($data->SenderNumber,$pesan);
  106.         } else {
  107.         while ($hasil = mysql_fetch_object($record_nilai)){
  108.           $pesan.=$hasil->makul_singkat.":".$hasil->nilai."\n";
  109.         }
  110.         $masuk = send_sms($data->SenderNumber,$pesan);
  111.       }  
  112.     // Nilai IPK  
  113.     }elseif($code=="I"){
  114.       $qry="SELECT m.sks,n.nilai "
  115.       ."FROM nilai n, makul m "
  116.       ."WHERE n.kd_makul = m.kd_makul "
  117.       ."  AND n.nim = '".$nim."'";
  118.       $record_ipk=mysql_query($qry);
  119.       $ketemu = mysql_num_rows($record_ipk);
  120.       if ($ketemu == 0) {
  121.         $pesan = "Nilai yang Anda minta belum ada / Keyword Anda salah.";
  122.         $masuk = send_sms($data->SenderNumber,$pesan);
  123.       }else{
  124.         $tot_sks=0;
  125.         $tot_nilai=0;
  126.         while ($hasil = mysql_fetch_object($record_ipk)){
  127.           $tot_sks+=$hasil->sks;
  128.           $tot_nilai+=$hasil->sks*$hasil->nilai;
  129.         }
  130.         $ipk=$tot_nilai/$tot_sks;
  131.         $pesan = "NIM : ".$nim.", IPK : ".$ipk;
  132.         $masuk = send_sms($data->SenderNumber,$pesan);
  133.       }
  134.     }elseif($code=="H"){  
  135.       $pesan = "format sms, nilai : N#NIM#SEMESTER , IPK : I#NIM , Bantuan : H#NIM ";
  136.       $masuk = send_sms($data->SenderNumber,$pesan);
  137.     }else{
  138.       $pesan = "Keyword Anda salah/ perintah tidak tersedia";
  139.       $masuk = send_sms($data->SenderNumber,$pesan);
  140.     }
  141.   }
  142.   if ($masuk) {
  143.     //pilih mau diubah atau dihapus dari tabel, bila data sudah diproses
  144.     //$ubah = mysql_query("UPDATE inbox SET Processed='true' WHERE ID='".$data->ID."'");
  145.     mysql_query("DELETE FROM inbox WHERE ID='".$data->ID."'");
  146.   }  
  147. }
  148. ?>
  149. </body>
  150. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement