Advertisement
cdsatrian

file function.php

Apr 16th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.10 KB | None | 0 0
  1. <?php
  2.  
  3. // mengecek apakah sebuah nomor hp sudah teregistrasi atau belum
  4. function ceknohp($nohp)
  5. {
  6.   $query = "SELECT * FROM mahasiswa WHERE telepon = '$nohp'";
  7.   $hasil = mysql_query($query);
  8.   if (mysql_num_rows($hasil) > 0) return 1;
  9.   else return 0;
  10. }
  11.  
  12. // cek kesesuaian nomor hp dan pin
  13. function cekpin($nohp, $pin)
  14. {
  15.   $query = "SELECT * FROM mahasiswa WHERE telepon = '$nohp'";
  16.   $hasil = mysql_query($query);
  17.   $data = mysql_fetch_array($hasil);
  18.   if ($pin == $data['pin']) return 1;
  19.   else return 0;
  20. }
  21.  
  22. // baca nilai matakuliah berdasarkan kode mk dan no hp si mahasiswa
  23. function bacanilai($nohp, $kodemk)
  24. {
  25.   $query = "SELECT c.nm_mtk, CASE b.nilai "
  26.           ."WHEN '4' THEN 'A' "
  27.           ."WHEN '3' THEN 'B' "
  28.           ."WHEN '2' THEN 'C' "
  29.           ."WHEN '1' THEN 'D' "
  30.           ."ELSE 'E' END AS grade "
  31.           ."FROM mahasiswa a "
  32.           ."LEFT JOIN nilai b USING(id_nim) "
  33.           ."LEFT JOIN matakuliah c USING(id_mtk) "
  34.           ."WHERE  a.telepon = '$nohp' "
  35.           ."AND c.kd_mtk = '$kodemk'";
  36.   $hasil = mysql_query($query);
  37.   if (mysql_num_rows($hasil) > 0)
  38.   {
  39.     $data = mysql_fetch_array($hasil);
  40.     return "Nilai ".$data['nm_mtk']." Anda : ".$data['grade'];
  41.   }
  42.   else return "Matakuliah tidak ditemukan";  
  43. }
  44.  
  45. function bacajadwal($kodekls, $kodemk)
  46. {
  47.   $query ="SELECT b.nm_mtk,d.hari,a.jam_mulai,a.jam_selesai "
  48.          ."FROM jadwal a "
  49.          ."LEFT JOIN matakuliah b USING(id_mtk) "
  50.          ."LEFT JOIN kelas c USING(id_kelas) "
  51.          ."LEFT JOIN hari d USING(id_hari) "
  52.          ."WHERE b.kd_mtk='$kodemk' "
  53.          ."AND c.kd_kelas='$kodekls' ";
  54.   $hasil = mysql_query($query);
  55.   if (mysql_num_rows($hasil) > 0)
  56.   {
  57.     $data = mysql_fetch_array($hasil);
  58.     return "Jadwal ".$data['nm_mtk']." Hari : ".$data['hari']
  59.           ." Waktu : ".$data['jam_mulai']."s.d.".$data['jam_selesai'];
  60.   }
  61.   else
  62.   {
  63.      return "Matakuliah tidak ditemukan";  
  64.   }
  65. }
  66.  
  67. // baca nilai matakuliah per semester berdasarkan no hp si mahasiswa
  68. function nilai_per_semester($nohp, $smt)
  69. {
  70.   $query = "SELECT c.nm_mtk, CASE b.nilai "
  71.           ."WHEN '4' THEN 'A' "
  72.           ."WHEN '3' THEN 'B' "
  73.           ."WHEN '2' THEN 'C' "
  74.           ."WHEN '1' THEN 'D' "
  75.           ."ELSE 'E' END AS grade, "
  76.           ."b.nilai,c.sks "
  77.           ."FROM mahasiswa a "
  78.           ."LEFT JOIN nilai b USING(id_nim) "
  79.           ."LEFT JOIN matakuliah c USING(id_mtk) "
  80.           ."WHERE  a.telepon = '$nohp' "
  81.           ."AND c.semester = '$smt'";
  82.   $hasil = mysql_query($query);
  83.   if (mysql_num_rows($hasil) > 0)
  84.   {
  85.     $nilai=$sks=0;
  86.     $msg="DAFTAR NILAI SESMETER $smt\n";
  87.     while($data = mysql_fetch_array($hasil)){
  88.       $nilai+=$data['nilai']*$data['sks'];
  89.       $sks+=$data['sks'];
  90.       $msg.="Nilai ".$data['nm_mtk'].":".$data['grade']."\n";
  91.     }
  92.     return $msg."Nilai IPK semester $smt:".round($nilai/$sks,2);
  93.   }
  94.   else return "Nilai tidak ditemukan";  
  95. }
  96. //baca jadwal perkelas berdasarkan kode kelas,thn Akademik "Y"
  97. function jadwal_per_kelas($kodekls)
  98. {
  99.   $query ="SELECT c.nm_kelas,b.nm_mtk,d.hari,a.jam_mulai,a.jam_selesai "
  100.          ."FROM jadwal a "
  101.          ."LEFT JOIN thnakademik e USING(id_thn) "
  102.          ."LEFT JOIN matakuliah b USING(id_mtk) "
  103.          ."LEFT JOIN kelas c USING(id_kelas) "
  104.          ."LEFT JOIN hari d USING(id_hari) "
  105.          ."WHERE c.kd_kelas='$kodekls' "
  106.          ."AND c.aktif='Y' "
  107.          ."AND e.aktif='Y' ";
  108.   $hasil = mysql_query($query);
  109.   print_r($query);
  110.   if (mysql_num_rows($hasil) > 0)
  111.   {
  112.     $msg="";
  113.     while($data = mysql_fetch_array($hasil)){
  114.       $msg.=($msg=="")?"DAFTAR JADWAL KELAS ".$data['nm_kelas']."\n":'';
  115.       $msg.=$data['nm_mtk']." Hari : ".$data['hari']
  116.            ." Waktu : ".$data['jam_mulai']." s.d ".$data['jam_selesai']."\n";
  117.     }
  118.     return $msg;
  119.   }
  120.   else return "Jadwal tidak ditemukan";
  121. }
  122. // kirim sms
  123. function sendsms($nohp, $pesan, $modem)
  124. {
  125.   $pesan = str_replace("'", "\'", $pesan);
  126.   if (strlen($pesan)<=160)
  127.   {
  128.     $query = "INSERT INTO outbox (DestinationNumber, TextDecoded, SenderID, CreatorID)
  129.              VALUES ('$nohp', '$pesan', '$modem', 'Gammu')";
  130.     $hasil = mysql_query($query);
  131.   }
  132.   else
  133.   {
  134.     $jmlSMS = ceil(strlen($pesan)/153);
  135.     $pecah  = str_split($pesan, 153);
  136.     $query = "SHOW TABLE STATUS LIKE 'outbox'";
  137.     $hasil = mysql_query($query);
  138.     $data  = mysql_fetch_array($hasil);
  139.     $newID = $data['Auto_increment'];
  140.     $random = rand(1, 255);
  141.     $headerUDH = sprintf("%02s", strtoupper(dechex($random)));
  142.     for ($i=1; $i<=$jmlSMS; $i++)
  143.     {
  144.       $udh = "050003".$headerUDH.sprintf("%02s", $jmlSMS).sprintf("%02s", $i);
  145.       $msg = $pecah[$i-1];
  146.       if ($i == 1)
  147.       {  
  148.         $query = "INSERT INTO outbox (DestinationNumber, UDH, TextDecoded, ID, MultiPart, SenderID, CreatorID)
  149.              VALUES ('$nohp', '$udh', '$msg', '$newID', 'true', '$modem', 'Gammu')";
  150.       }
  151.       else $query = "INSERT INTO outbox_multipart(UDH, TextDecoded, ID, SequencePosition)
  152.               VALUES ('$udh', '$msg', '$newID', '$i')";
  153.       echo $query;die();
  154.       mysql_query($query);
  155.     }
  156.   }
  157. }
  158.  
  159. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement