PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/application/controllers/admin/dashboard.php

https://bitbucket.org/prat_h/rakbuku
PHP | 161 lines | 111 code | 15 blank | 35 comment | 15 complexity | cb2893f672e099b5fa6ffac7d1b38655 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Dashboard extends CI_Controller {
  3. function __construct() {
  4. parent::__construct();
  5. $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
  6. $this->output->set_header("Pragma: no-cache");
  7. $role = $this->session->userdata('role_name');
  8. if($this->is_login())
  9. {
  10. if(! ($role === 'admin'))
  11. {
  12. redirect('/');
  13. }
  14. }
  15. }
  16. public function index()
  17. {
  18. if($this->is_login())
  19. {
  20. $this->data['title'] = 'Dashboard';
  21. $this->load->view("admin/dashboard", $this->data);
  22. }
  23. else
  24. {
  25. $this->load->view("admin/login");
  26. }
  27. }
  28. /*------------------------------------------------------------------------
  29. | Method : login
  30. |-------------------------------------------------------------------------
  31. | Paramater : void
  32. | Return : void
  33. | Description : controller login
  34. | Author : Pratama Hasriyan
  35. ------------------------------------------------------------------------*/
  36. public function login()
  37. {
  38. $this->form_validation->set_rules('email', 'Email', 'required|valid_email|xss_clean');
  39. $this->form_validation->set_rules('password', 'Password', 'required|xss_clean');
  40. $role = $this->session->userdata('role_name');
  41. if($this->form_validation->run() == FALSE && $role == '') {
  42. $this->load->view('admin/login');
  43. } else {
  44. $email = $this->input->post('email');
  45. $pass = md5($this->input->post('password'));
  46. $par = array(
  47. 'ru.user_email' => $email,
  48. 'ru.user_pass' => $pass,
  49. 'rr.role_name' => 'admin'
  50. );
  51. $userdata = $this->user_model->do_login($par);
  52. if(!$userdata){
  53. $data['salah'] = "Password atau Username Salah";
  54. $this->load->view('admin/login', $data);
  55. }else {
  56. $newdata = array();
  57. $newdata['user_id'] = $userdata->user_id;
  58. $newdata['user_email'] = $userdata->user_email;
  59. $newdata['user_unique_url'] = strtolower($userdata->user_unique_url);
  60. $newdata['user_activation_key'] = $userdata->user_activation_key;
  61. $newdata['current_user'] = ($newdata['user_unique_url']=='') ? $newdata['user_activation_key'] : $newdata['user_unique_url'];
  62. $newdata['jur_id'] = $userdata->jur_id;
  63. $newdata['firstname'] = $userdata->user_firstname;
  64. $newdata['middlename'] = $userdata->user_middlename;
  65. $newdata['lastname'] = $userdata->user_lastname;
  66. $newdata['fullname'] = $newdata['firstname'].' '.$newdata['middlename'].' '.$newdata['lastname'];
  67. $newdata['logged_in'] = true;
  68. $newdata['role_name'] = $userdata->role_name;
  69. $this->session->set_userdata($newdata);
  70. redirect('admin/dashboard');
  71. }
  72. }
  73. }
  74. /*------------------------------------------------------------------------
  75. | Method : logout
  76. |-------------------------------------------------------------------------
  77. | Paramater : void
  78. | Return : void
  79. | Description : controller logout
  80. | Author : Pratama Hasriyan
  81. ------------------------------------------------------------------------*/
  82. public function logout() {
  83. $this->session->set_flashdata('redirectToCurrent', current_url());
  84. $this->session->sess_destroy();
  85. redirect('admin/dashboard');
  86. //redirect('/');
  87. }
  88. /*------------------------------------------------------------------------
  89. | Method : is_login
  90. |-------------------------------------------------------------------------
  91. | Paramater : void
  92. | Return : boolean
  93. | Description : mengecek apakah user telah melakukan login atau belum
  94. | Author : Pratama Hasriyan
  95. ------------------------------------------------------------------------*/
  96. public function is_login() {
  97. $userlogin = $this->session->userdata('logged_in');
  98. if($userlogin == ''){
  99. return false;
  100. }
  101. else {
  102. return true;
  103. }
  104. }
  105. /*------------------------------------------------------------------------
  106. | Method : paginating
  107. |-------------------------------------------------------------------------
  108. | Paramater : void
  109. | Return : void
  110. | Description : menampilkan pagination berdasarkan paramater confgnya.
  111. | Author : Pratama Hasriyan
  112. ------------------------------------------------------------------------*/
  113. public function paginating($mdl, $path, $urisegment, $perpage)
  114. {
  115. $config['base_url'] = site_url($path);
  116. if(gettype($mdl) === 'integer')
  117. {
  118. $config['total_rows'] = $mdl;
  119. }
  120. else
  121. {
  122. $config['total_rows'] = $this->$mdl->count();
  123. }
  124. $config['uri_segment'] = $urisegment;
  125. $config['per_page'] = $perpage;
  126. $this->pagination->initialize($config);
  127. $this->data['pagination'] = $this->pagination->create_links();
  128. }
  129. public function paginating_project($mdl, $path, $urisegment, $perpage) {
  130. $config['base_url'] = site_url($path);
  131. if(gettype($mdl) === 'integer')
  132. {
  133. $config['total_rows'] = $mdl;
  134. }
  135. else
  136. {
  137. $config['total_rows'] = $this->$mdl->count_all_published();
  138. }
  139. $config['uri_segment'] = $urisegment;
  140. $config['per_page'] = $perpage;
  141. $this->pagination->initialize($config);
  142. $this->data['pagination'] = $this->pagination->create_links();
  143. }
  144. }
  145. /* End of file welcome.php */
  146. /* Location: ./application/controllers/welcome.php */