Advertisement
hanhantu

login ci

Feb 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.42 KB | None | 0 0
  1. //controller Users//
  2. <?php
  3.  
  4. /*
  5. * To change this template, choose Tools | Templates
  6. * and open the template in the editor.
  7. */
  8.  
  9. class Users extends CI_Controller {
  10.  
  11. function __construct() {
  12. parent::__construct();
  13. $this->load->model('User');
  14. // for
  15. }
  16.  
  17. function login() {
  18.  
  19. $this->form_validation->set_rules('username', 'username', 'required');
  20. $this->form_validation->set_rules('password', 'password', 'required');
  21. $this->form_validation->set_error_delimiters('', '<br/>');
  22.  
  23. if ($this->form_validation->run() == TRUE) {
  24. $username = $this->input->post('username');
  25. $password = $this->input->post('password');
  26.  
  27. $user = $this->User->checkLogin($username, $password);
  28.  
  29. if (!empty($user)) {
  30. $sessionData['id_kasir'] = $user['id_kasir'];
  31. $sessionData['username'] = $user['username'];
  32. $sessionData['nama'] = $user['nama'];
  33. $sessionData['akses'] = $user['akses'];
  34. $sessionData['is_login'] = TRUE;
  35.  
  36. $this->session->set_userdata($sessionData);
  37.  
  38. if ($this->session->userdata('akses') == 'Admin') {
  39. $this->session->sess_expiration = 14400;
  40. redirect('admin/Dashboard');
  41. } else if ($this->session->userdata('akses') == 'Kasir'){
  42. $this->session->sess_expiration = 14400;
  43. redirect('kasir/Dashboard');
  44. }else{
  45. $this->session->sess_expiration = 14400;
  46. redirect('petugas/Dashboard');
  47. }
  48. }else{
  49. echo "<script>
  50. alert('Username/Password Salah atau Akun tidak aktif');
  51. </script>";
  52. }
  53. }
  54.  
  55. $this->load->view('users/login');
  56. }
  57.  
  58. function logout() {
  59.  
  60. $this->session->sess_destroy();
  61. redirect('users/login');
  62. }
  63.  
  64. }
  65.  
  66. ?>
  67.  
  68. //Models Users//
  69. <?php
  70.  
  71. /*
  72. * To change this template, choose Tools | Templates
  73. * and open the template in the editor.
  74. */
  75.  
  76. class User extends CI_Model {
  77.  
  78. var $table = 'tbl_kasir';
  79.  
  80. function __construct() {
  81. parent::__construct();
  82. }
  83.  
  84. function checkLogin($username, $password) {
  85. $this->db->select('*');
  86. $this->db->where('username', $username);
  87. $this->db->where('password', md5($password));
  88. $this->db->where('status', 'Aktif');
  89. $query = $this->db->get($this->table, 1);
  90.  
  91. if ($query->num_rows() == 1) {
  92. return $query->row_array();
  93. }
  94. }
  95.  
  96. }
  97.  
  98. ?>
  99.  
  100. //form login//
  101.  
  102. <!-- Login Form -->
  103. <?php echo form_open('users/login',array('class' => 'js-validation-login form-horizontal push-30-t')); ?>
  104. <div class="form-group">
  105. <div class="col-xs-12">
  106. <div class="form-material form-material-primary floating">
  107. <input class="form-control" type="text" id="username" name="username" value="<?php echo set_value('username') ?>">
  108. <label for="username">Username</label>
  109. </div>
  110. </div>
  111. </div>
  112. <div class="form-group">
  113. <div class="col-xs-12">
  114. <div class="form-material form-material-primary floating">
  115. <input class="form-control" type="password" id="password" name="password">
  116. <label for="password">Password</label>
  117. </div>
  118. </div>
  119. </div>
  120. <div class="form-group push-30-t">
  121. <div class="col-xs-12 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4">
  122. <button class="btn btn-sm btn-block btn-primary" type="submit">Log in</button>
  123. </div>
  124. </div>
  125. <?php echo form_close(); ?>
  126. <center>
  127. <small>
  128. <a class="font-w600" href="<?php echo base_url('tracking')?>" target="_blank">Tracking Buku Untuk Pembeli</a>
  129. </small>
  130. </center>
  131. <!-- END Login Form -->
  132.  
  133. //controller dashboard admin//
  134. <?php
  135.  
  136. defined('BASEPATH') OR exit('No direct script access allowed');
  137.  
  138. class Dashboard extends CI_Controller {
  139.  
  140. public function __construct()
  141. {
  142. parent::__construct();
  143. $this->general->cekAdminLogin();
  144. $this->_module = 'admin';
  145. $this->load->model('admin/M_dashboard','md');
  146. }
  147.  
  148. public function index()
  149. {
  150.  
  151. $year1 = $this->md->getTahun();
  152. $year = $year1['tahun'];
  153. $earning1 = $this->md->getTotal($year);
  154. $earning2 = $this->md->getTotal2($year);
  155.  
  156. $total1= array();
  157. $total2= array();
  158.  
  159.  
  160. foreach ($earning1 as $tot) {
  161. $total1[] = $tot->total_pasok;
  162. }
  163.  
  164.  
  165. $bulan = $this->md->getBulan();
  166. $label = array();
  167. foreach ($bulan as $m) {
  168. $label[] = $m->bulan;
  169. }
  170.  
  171. // batas
  172.  
  173. foreach ($earning2 as $tot) {
  174. $total2[] = $tot->keuntungan;
  175. }
  176.  
  177.  
  178. $bulan2 = $this->md->getBulan2();
  179. $label2 = array();
  180. foreach ($bulan2 as $m) {
  181. $label2[] = $m->bulan;
  182. }
  183.  
  184. // batas
  185.  
  186. $data = array(
  187. 'jumlah_buku' => $this->md->hitungBuku()->num_rows(),
  188. 'jumlah_distributor' => $this->md->hitungDis()->num_rows(),
  189. 'untung' => $this->md->hitungUntung(),
  190. 'untung_hari' => $this->md->hitungUntungHari()
  191. );
  192.  
  193. $data['label'] = json_encode($label);
  194. $data['tahun'] = $this->md->getTahun();
  195. $data['result1'] = json_encode($total1);
  196. $data['one'] = $year1['tahun'];
  197.  
  198. $data['label2'] = json_encode($label2);
  199. $data['tahun2'] = $this->md->getTahun2();
  200. $data['result2'] = json_encode($total2);
  201. $data['one2'] = $year1['tahun'];
  202.  
  203. $this->load->view('admin/dashboard',$data);
  204. }
  205. }
  206.  
  207. /* End of file c_adashboard.php */
  208. /* Location: ./application/controllers/admin/c_adashboard.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement