daily pastebin goal
60%
SHARE
TWEET

Untitled

codingbaper Jul 12th, 2018 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.    
  3. // Membuat Fungsi menjalankan query database
  4.     function run_query($query){
  5.         global $conn;
  6.         return mysqli_query($conn, $query);
  7.     }
  8. // Membuat funsgi escape untuk semua inputan string
  9.     function escape($data){
  10.         global $conn;
  11.         return mysqli_real_escape_string($conn, $data);
  12.     }
  13. // Mendapatkan data user
  14.     function data_users(){
  15.         $query = "SELECT id_users, name, username,status,terjemah_tanggal(tgl_reg) as tgl_reg FROM tb_users";
  16.         $result = run_query($query);
  17.         return $result;
  18.     }
  19. // Mendapatkan data team
  20.     function data_teams(){
  21.         $query = "SELECT * FROM tb_teams, tb_bidang WHERE tb_bidang.id_bidang=tb_teams.id_bidangFK";
  22.         $result = run_query($query);
  23.         return $result;
  24.     }
  25. // Mendaftarkan user untuk administrator admin web
  26.     function register_users($nama,$username,$password,$status,$tgl_reg){
  27.         $query = "INSERT INTO tb_users (name,username,password,status,tgl_reg) VALUES ('$nama','$username','$password','$status','$tgl_reg')";
  28.         if(run_query($query)) return true;
  29.         else return false;
  30.     }
  31. // Mendaftarkan team tenaga kerja
  32.     function register_teams($name_teams,$bidang,$alamat,$contact_teams,$pay){
  33.         $query = "INSERT INTO tb_teams (name_teams,id_bidangFK,alamat,contact_teams,pay) VALUES ('$name_teams',$bidang,'$alamat','$contact_teams',$pay)";
  34.         if(run_query($query)) return true;
  35.         else return false;
  36.     }
  37. // Mengecek apakah username sudah dipakai
  38.     function cek_username($username){
  39.         $query = "SELECT * FROM tb_users WHERE username = '$username'";
  40.         $result = run_query($query);
  41.         if(mysqli_num_rows($result) != 0) return true;
  42.         else return false;
  43.     }
  44. // Mengecek username pada kondisi update
  45.     function cek_username_update($username){
  46.         $query = "SELECT * FROM tb_users WHERE username = '$username'";
  47.         $result = run_query($query);
  48.         if(mysqli_num_rows($result) <= 1) return true;
  49.         else return false;
  50.     }
  51. // Mengambil data user dengan metode get menggunakan parameter id_users, digunakan sebagai update data users
  52.     function get_users($id_users){
  53.         $query = "SELECT * FROM tb_users WHERE id_users=$id_users";
  54.         $result = run_query($query);
  55.         return mysqli_fetch_assoc($result);
  56.     }
  57. // Mengambil data teams dengan metode get menggunakan parameter id_teams, digunakan sebagai update data teams
  58.     function get_teams($id_teams){
  59.         $query = "SELECT * FROM tb_teams WHERE id_teams=$id_teams";
  60.         $result = run_query($query);
  61.         return mysqli_fetch_assoc($result);
  62.     }
  63. // Funsgi untuk update users
  64.     function update_users($nama,$username,$password,$status,$tgl_reg,$id_users){
  65.         $query = "UPDATE tb_users SET name='$nama',username='$username',password='$password',status='$status',tgl_reg='$tgl_reg' WHERE id_users=$id_users";
  66.         if(run_query($query)) return true;
  67.         else return false;
  68.     }
  69. // Funsgi untuk update users
  70.     function update_teams($name_teams,$bidang,$alamat,$contact_teams,$id_teams,$pay){
  71.         $query = "UPDATE tb_teams SET name_teams='$name_teams',id_bidangFK=$bidang,alamat='$alamat',contact_teams='$contact_teams', pay=$pay WHERE id_teams=$id_teams";
  72.         if(run_query($query)) return true;
  73.         else return false; 
  74.     }
  75. // Fungsi untuk menghapus data user, dengan parameter id_user yang digunakan untuk kondisi pada query SQL (WHERE)
  76.     function delete_users($id_users){
  77.         $query = "DELETE FROM tb_users WHERE id_users=$id_users";
  78.         if(run_query($query)) return true;
  79.         else return false;
  80.     }
  81. // Fungsi untuk menghapus data team, dengan parameter id_team yang digunakan untuk kondisi pada query SQL (WHERE)
  82.     function delete_teams($id_teams){
  83.         $query = "DELETE FROM tb_teams WHERE id_teams=$id_teams";
  84.         if(run_query($query)) return true;
  85.         else return false;
  86.     }
  87. // Fungsi untuk menapilkan jumlah team, digunakan untuk menampilkan jumlah team pada page home
  88.     function jumlah_teams(){
  89.         $query = "SELECT * FROM tb_teams";
  90.         $result = run_query($query);
  91.         return mysqli_num_rows($result);
  92.     }
  93. // Fungsi untuk menapilkan jumlah booking, digunakan untuk menampilkan jumlah booking pada page home
  94.     function jumlah_booking(){
  95.         $query = "SELECT * FROM tb_booking WHERE status = 'belum selesai'";
  96.         $result = run_query($query);
  97.         return mysqli_num_rows($result);
  98.     }
  99. // Fungsi untuk menapilkan jumlah admin, digunakan untuk menampilkan jumlah admin pada page home
  100.     function jumlah_admin(){
  101.         $query = "SELECT * FROM tb_users";
  102.         $result = run_query($query);
  103.         return mysqli_num_rows($result);
  104.     }
  105. // Fungsi untuk login admin
  106.     function login_users($username,$password){
  107.         $username = escape($username);
  108.         $password = escape($password);
  109.  
  110.         $query = "SELECT password FROM tb_users WHERE username = '$username'";
  111.         $result = run_query($query);
  112.         $hash = mysqli_fetch_assoc($result)['password'];
  113.         if(password_verify($password,$hash)) return true;
  114.         else return false;
  115.     }
  116. // Fungsi multi level user, membedakaan antara admin dan keuangan
  117.     function cek_admin($username){
  118.         $query = "SELECT status FROM tb_users WHERE username = '$username'";
  119.         $result = run_query($query);
  120.         $status = mysqli_fetch_assoc($result)['status'];
  121.         if($status == 'Admin') return true;
  122.         else return false;
  123.     }
  124. // Mengambil data user dari get session
  125.     function get_from_session($session){
  126.         $query = "SELECT * FROM tb_users WHERE username='$session'";
  127.         $result = run_query($query);
  128.         return mysqli_fetch_assoc($result);
  129.     }
  130. // Membuat kode booking acak otomatis, dan langsung tampil pada inputan
  131.     function code_booking(){
  132.         $query = "select max(code_booking) from tb_booking";
  133.         $carikode = run_query($query);
  134.         $datakode = mysqli_fetch_array($carikode);
  135.         if ($datakode) {
  136.             $nilaikode = substr($datakode[0], 1);
  137.             $kode = (int) $nilaikode;
  138.             $kode = $kode + 1;
  139.             $kode_otomatis = "P".str_pad($kode, 4, "0", STR_PAD_LEFT);
  140.         }else{
  141.             $kode_otomatis = "P0001";
  142.         }
  143.         return $kode_otomatis;
  144.     }
  145. // Fungsi looping data team, digunakan pada select daftar team
  146.     function loop_teams(){
  147.         $query = "SELECT * FROM tb_teams";
  148.         $result = run_query($query);
  149.         return $result;
  150.     }
  151. // Funsgi daftar booking
  152.     function register_booking($tgl_booking,$code_booking,$pembooking,$name_teams){
  153.         $query = "INSERT INTO tb_booking (tgl_booking,code_booking,name_booking,id_teamsFK,status) VALUES ('$tgl_booking','$code_booking','$pembooking','$name_teams','belum selesai')";
  154.         return run_query($query);
  155.     }
  156. // Mengambil data booking
  157.     function data_booking(){
  158.         $query = "SELECT terjemah_tanggal(tgl_booking) AS tgl_booking, code_booking, name_booking, name_teams, name_bidang, pay FROM tb_booking,tb_teams,tb_bidang WHERE tb_booking.id_teamsFK=tb_teams.id_teams AND tb_bidang.id_bidang=tb_teams.id_bidangFK AND status = 'belum selesai'";
  159.         $result = run_query($query);
  160.         return $result;
  161.     }
  162. // Fungsi untuk menghapus data booking, dengan parameter code booking yang digunakan untuk kondisi pada query SQL (WHERE)
  163.     function delete_booking($code){
  164.         $query = "DELETE FROM tb_booking WHERE code_booking='$code'";
  165.         if(run_query($query)) return true;
  166.         else return false;
  167.     }
  168. // Mengambil data bookingan dengan paramater code bookingnya
  169.     function get_data_booking($code){
  170.         $query = "SELECT terjemah_tanggal(tgl_booking) AS tgl_booking, name_bidang, name_booking, code_booking, name_teams, id_teamsFK, pay FROM tb_booking, tb_teams, tb_bidang WHERE tb_booking.id_teamsFK=tb_teams.id_teams AND tb_teams.id_bidangFK=tb_bidang.id_bidang AND code_booking='$code'";
  171.         $result = run_query($query);
  172.         return $result;
  173.     }
  174. // Fungsi untuk mengecek teams yang free pada tgl ttt, ketika user mendaftarkan bookingan
  175.     function cek_free_teams($name_teams, $tgl_booking){
  176.         $query = "SELECT id_teamsFK, tgl_booking FROM tb_booking WHERE id_teamsFK='$name_teams' AND tgl_booking='$tgl_booking' AND status='belum selesai' ";
  177.         $result = run_query($query);
  178.         if(mysqli_num_rows($result) == 0) return true;
  179.         else return false;
  180.     }
  181. // Fungsi update status bookingan menjadi selesai, sehingga transaksi dinyatakan selesai dan data bookingan masuk ke history
  182.     function payments_done($code){
  183.         $query = "UPDATE tb_booking SET status='selesai' WHERE code_booking='$code'";
  184.         if(run_query($query)) return true;
  185.         else return false;
  186.     }
  187. // Menampilkan data bookingan yang sudah selesai / data history
  188.     function data_booking_selesai(){
  189.         $query = "SELECT terjemah_tanggal(tgl_booking) AS tgl_booking, code_booking, name_booking, name_teams, name_bidang, pay FROM tb_booking, tb_teams, tb_bidang WHERE tb_booking.id_teamsFK=tb_teams.id_teams AND tb_bidang.id_bidang=tb_teams.id_bidangFK AND status = 'selesai'";
  190.         $result = run_query($query);
  191.         return $result;
  192.     }
  193. // Fungsi untuk menapilkan jumlah transaksi yang sudah selesai, digunakan untuk menampilkan jumlahnya pada page home
  194.     function jumlah_payments_done(){
  195.         $query = "SELECT * FROM tb_booking, tb_teams, tb_bidang WHERE tb_booking.id_teamsFK=tb_teams.id_teams AND tb_teams.id_bidangFK=tb_bidang.id_bidang AND status = 'selesai'";
  196.         $result = run_query($query);
  197.         return mysqli_num_rows($result);
  198.     }
  199. // Mengambil data bidang
  200.     function data_bidang(){
  201.         $query = "SELECT * FROM tb_bidang";
  202.         $result = run_query($query);
  203.         return $result;
  204.     }
  205. // Update data booking
  206.     function update_booking($tanggal,$nama_booking,$id_teams,$code_booking,$code){
  207.         $query = "UPDATE tb_booking SET code_booking='$code_booking', id_teamsFK=$id_teams,name_booking='$nama_booking',tgl_booking='$tanggal' WHERE code_booking='$code'";
  208.         if(run_query($query)) return true;
  209.         else return false;
  210.     }
  211.  ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top