muhfadzrin

Mahasiswa.php

Feb 28th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.65 KB | None | 0 0
  1. <?php
  2.  
  3. class Mahasiswa extends Controller {
  4.     public function __construct()
  5.     {
  6.         if (!isset($_SESSION['login'])) {
  7.             header('Location: '. BASEURL);
  8.             exit;
  9.         }
  10.     }
  11.  
  12.     public function index()
  13.     {
  14.         $data['title'] = 'Halaman Mahasiswa';
  15.         $data['mhs'] = $this->model('Mahasiswa_model')->getAllMahasiswa();
  16.         $data['jurusan'] = [
  17.             'Teknik Informatika',
  18.             'Teknik Industri',
  19.             'Teknik Pangan',
  20.             'Teknik Planologi',
  21.             'Teknik Ligkungan',
  22.             'Sistem Informasi',
  23.             'Teknik Mesin'
  24.         ];
  25.  
  26.         $this->view('_templates/header', $data);
  27.         $this->view('mahasiswa/index', $data);
  28.         $this->view('_templates/footer');
  29.     }
  30.  
  31.     public function detail($id)
  32.     {
  33.         $data['title'] = 'Halaman Detail Mahasiswa';
  34.         $data['mhs'] = $this->model('Mahasiswa_model')->getMahasiswaById($id);
  35.  
  36.         $this->view('_templates/header', $data);
  37.         $this->view('mahasiswa/detail', $data);
  38.         $this->view('_templates/footer');
  39.     }
  40.  
  41.     public function tambah()
  42.     {
  43.         if ($this->model('Mahasiswa_model')->tambahDataMahasiswa($_POST) > 0) {
  44.             Flasher::setFlash('berhasil', 'ditambahkan', 'success');
  45.             header("Location: ". BASEURL ."/mahasiswa");
  46.             exit;
  47.         } else {
  48.             Flasher::setFlash('gagal', 'ditambahkan', 'danger');
  49.             header("Location: ". BASEURL ."/mahasiswa");
  50.             exit;
  51.         }
  52.     }
  53.  
  54.     public function hapus($id)
  55.     {
  56.         if ($this->model('Mahasiswa_model')->hapusDataMahasiswa($id) > 0) {
  57.             Flasher::setFlash('berhasil', 'dihapus', 'success');
  58.             header('Location: ' . BASEURL . '/mahasiswa');
  59.             exit;
  60.         } else {
  61.             Flasher::setFlash('gagal', 'dihapus', 'danger');
  62.             header('Location: ' . BASEURL . '/mahasiswa');
  63.             exit;
  64.         }
  65.     }
  66.  
  67.     public function ubah()
  68.     {
  69.         if ($this->model('Mahasiswa_model')->ubahDataMahasiswa($_POST) > 0) {
  70.             Flasher::setFlash('berhasil', 'diubah', 'success');
  71.             header('Location: ' . BASEURL . '/mahasiswa');
  72.             exit;
  73.         } else {
  74.             Flasher::setFlash('gagal', 'diubah', 'danger');
  75.             header('Location: ' . BASEURL . '/mahasiswa');
  76.             exit;
  77.         }
  78.     }
  79.  
  80.     public function cari()
  81.     {
  82.         $data['title'] = 'Halaman Mahasiswa';
  83.         $data['mhs'] = $this->model('Mahasiswa_model')->cariDataMahasiswa();
  84.         $data['jurusan'] = [
  85.             'Teknik Informatika',
  86.             'Teknik Industri',
  87.             'Teknik Pangan',
  88.             'Teknik Planologi',
  89.             'Teknik Ligkungan',
  90.             'Sistem Informasi',
  91.             'Teknik Mesin'
  92.         ];
  93.  
  94.         if (empty($data['mhs'])) {
  95.             echo '<script>
  96.                     alert("Nama mahasiswa tidak ditemukan");
  97.                 </script>';
  98.         }
  99.  
  100.         $this->view('_templates/header', $data);
  101.         $this->view('mahasiswa/index', $data);
  102.         $this->view('_templates/footer');
  103.     }
  104.  
  105.     public function getUbah()
  106.     {
  107.         echo json_encode($this->model('Mahasiswa_model')->getMahasiswaById($_POST["id"]));
  108.     }
  109. }
Add Comment
Please, Sign In to add comment