Guest User

Untitled

a guest
Nov 30th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.83 KB | None | 0 0
  1. <?php
  2.  
  3. class Superadmin extends MY_Controller
  4. {
  5.  
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. //$this->session->userdata('is_login') == FALSE || redirect('admin/Login_admin');
  10. if($this->session->userdata('token'))
  11. $this->session->unset_userdata('token');
  12. $this->load->model('admin/Admin_m');
  13. }
  14.  
  15. public function index()
  16. {
  17. if(isset($this->session->id)=='')
  18. {
  19. redirect('admin/Login');
  20. }
  21.  
  22. $data['content'] = 'page/admin/superadmin';
  23. $data['admin'] = $this->Admin_m->get_all();
  24. $this->load->view('layout_admin', $data);
  25. }
  26.  
  27. public function editadmin($admin_id)
  28. {
  29. if(isset($this->session->id)=='')
  30. {
  31. redirect('admin/Login');
  32. }
  33.  
  34. $data['content'] = 'page/admin/superadminedit';
  35. $data['admin'] = $this->Admin_m->get_admin_by_id($admin_id);
  36.  
  37. if($this->form_validation->run() == FALSE)
  38. {
  39. $this->load->view('page/admin/superadminedit', $data);
  40. }
  41. else
  42. {
  43. $this->form_validation->set_rules('full_name', ' Full name', 'required');
  44. $this->form_validation->set_rules('user', 'Username', 'required');
  45. $this->form_validation->set_rules('password', 'Password', 'required|min_length[5]');
  46. // kondisi untuk input data jika password kosong
  47. if($this->input->post('password') == ''){
  48. $data =
  49. array(
  50. 'full_name' => $this->input->post('full_name'),
  51. 'user' => $this->input->post('user'),
  52. 'level' => $this->input->post('level'),
  53. );
  54. }
  55. else
  56. {
  57. $data =
  58. array(
  59. 'full_name' => $this->input->post('full_name'),
  60. 'user' => $this->input->post('user'),
  61. 'password' => hashpassword($this->input->post('password')),
  62. 'level' => $this->input->post('level'),
  63. );
  64. }
  65. $this->Admin_m->edit_admin($admin_id,$data);
  66. redirect('admin/superadmin/editadmin');
  67. }
  68. }
  69.  
  70.  
  71. public function deleteadmin($id)
  72. {
  73. if(isset($this->session->id)=='')
  74. {
  75. redirect('admin/Login');
  76. }
  77.  
  78. $this->load->model('Admin_m');
  79.  
  80. $this->Admin_m->delete($id);
  81.  
  82. //$this->session->set_flashdata('remove_success', 'Admin berhasil dihapus dari List');
  83.  
  84. redirect('admin/Superadmin');
  85. }
  86.  
  87. }
  88.  
  89. ?>
  90.  
  91. <?php
  92.  
  93. class Admin_m extends CI_Model
  94. {
  95. public function check_akunadmin($user= '' , $password = '')
  96. {
  97. return $this->db->get_where('admin_user',
  98. array('user' =>$user,
  99. 'password' => hashpassword($password)
  100. )
  101. )->row();
  102.  
  103. }
  104.  
  105. public function insert($data = array())
  106. {
  107. $this->db->insert('admin_user',$data);
  108. }
  109.  
  110. public function edit_admin($id, $data = array())
  111. {
  112. $this->db->where('id', $id);
  113. $this->db->set($data);
  114. $this->db->update('admin_user');
  115. }
  116.  
  117. public function get_admin_by_id($admin_id)
  118. {
  119. return $this->db->get_where('admin_user', array('id' => $admin_id))->row();
  120. }
  121.  
  122. public function get_all($per_page = 0, $offset = 0)
  123. {
  124. $this->db->order_by('id', 'desc');
  125. return $this->db->limit($per_page, $offset)->get('admin_user')->result();
  126. }
  127.  
  128. public function delete($id)
  129. {
  130. $this->db->where('id', $id);
  131. $this->db->delete('admin_user');
  132. }
  133.  
  134. }
  135.  
  136. ?>
  137.  
  138. <!DOCTYPE html>
  139. <html>
  140. <head>
  141. <meta charset="utf-8">
  142. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  143. <title>AdminLTE 2 | General Form Elements</title>
  144. <!-- Tell the browser to be responsive to screen width -->
  145. <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  146. <!-- Bootstrap 3.3.6 -->
  147. <link rel="stylesheet" href="<?php echo base_url();?>backendtampilan/bootstrap/css/bootstrap.min.css">
  148. <!-- Font Awesome -->
  149. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
  150. <!-- Ionicons -->
  151. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
  152. <!-- Theme style -->
  153. <link rel="stylesheet" href="<?php echo base_url();?>backendtampilan/dist/css/AdminLTE.min.css">
  154. <!-- AdminLTE Skins. Choose a skin from the css/skins
  155. folder instead of downloading all of them to reduce the load. -->
  156. <link rel="stylesheet" href="<?php echo base_url();?>backendtampilan/dist/css/skins/_all-skins.min.css">
  157.  
  158. <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  159. <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  160. <!--[if lt IE 9]>
  161. <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  162. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  163. <![endif]-->
  164. </head>
  165. <body class="hold-transition skin-blue sidebar-mini">
  166. <div class="wrapper">
  167.  
  168. <header class="main-header">
  169. <!-- Logo -->
  170. <a class="logo">
  171. <!-- mini logo for sidebar mini 50x50 pixels -->
  172. <span class="logo-mini"><b>A</b>LT</span>
  173. <!-- logo for regular state and mobile devices -->
  174. <span class="logo-lg"><b>Admin</b>LTE</span>
  175. </a>
  176. <!-- Header Navbar: style can be found in header.less -->
  177. </header>
  178. <!-- Left side column. contains the logo and sidebar -->
  179.  
  180. <!-- Content Wrapper. Contains page content -->
  181. <div class="content-wrapper">
  182. <!-- Content Header (Page header) -->
  183. <section class="content-header">
  184. <h1>
  185. Edit Admin
  186. </h1>
  187. </section>
  188.  
  189. <!-- Main content -->
  190. <section class="content">
  191. <div class="row">
  192. <!-- left column -->
  193. <div class="col-md-12">
  194. <!-- general form elements -->
  195. <div class="box box-primary">
  196. <div class="box-header with-border">
  197. <h3 class="box-title">Super Admin edit Page</h3> <br>
  198. <a href="<?php echo site_url('admin/superadmin')?>"><button class="btn btn-primary">Back to Super Admin</button></a>
  199. <?php if(validation_errors()): ?>
  200. <ul class="alert alert-danger"><?php echo validation_errors('<li>','</li>')?></ul>
  201. <?php endif;?>
  202. </div>
  203. <!-- /.box-header -->
  204. <!-- form start -->
  205. <form action="<?php echo base_url(). 'admin/superadmin/editadmin/'. $admin->id; ?>" method="post" enctype ="multipart/form-data">
  206. <div class="box-body">
  207. <div class="form-group">
  208. <label>ID</label>
  209. <input type="text" class="form-control" placeholder="ID" value="<?php echo $admin->id ?>" disabled>
  210. </div>
  211.  
  212. <div class="form-group">
  213. <label >Full Name</label>
  214. <input type="text" class="form-control" name="full_name" placeholder="Enter Name" value="<?php echo $admin->full_name ?>">
  215. </div>
  216.  
  217. <div class="form-group">
  218. <label>User</label>
  219. <input type="text" class="form-control" name="user" value="<?php echo $admin->user ?>">
  220. </div>
  221.  
  222. <div class="form-group">
  223. <label>New Password</label>
  224. <input type="text" class="form-control" name="password" placeholder="password" >
  225. </div>
  226.  
  227. <div class="form-group">
  228. <label>Level</label><br>
  229. <select name="level">
  230. <option value="0">Super Admin</option>
  231. <option value="1">Normal Admin</option>
  232. </select>
  233. </div>
  234.  
  235. </div>
  236. <!-- /.box-body -->
  237.  
  238. <div class="box-footer">
  239. <button type="submit" class="btn btn-primary">Submit</button>
  240. </div>
  241. </form>
  242. </div>
  243. <!-- /.box -->
  244. <!--/.col (right) -->
  245. </div>
  246. <!-- /.row -->
  247. </section>
  248. <!-- /.content -->
  249. </div>
  250. <!-- /.content-wrapper -->
  251. <footer class="main-footer">
  252. <div class="pull-right hidden-xs">
  253. </div>
  254. All rights reserved.
  255. </footer>
  256.  
  257.  
  258. <!-- ./wrapper -->
  259.  
  260. <!-- jQuery 2.2.3 -->
  261. <script src="<?php echo base_url();?>backendtampilan/plugins/jQuery/jquery-2.2.3.min.js"></script>
  262. <!-- Bootstrap 3.3.6 -->
  263. <script src="<?php echo base_url();?>backendtampilan/bootstrap/js/bootstrap.min.js"></script>
  264. <!-- FastClick -->
  265. <script src="<?php echo base_url();?>backendtampilan/plugins/fastclick/fastclick.js"></script>
  266. <!-- AdminLTE App -->
  267. <script src="<?php echo base_url();?>backendtampilan/dist/js/app.min.js"></script>
  268. <!-- AdminLTE for demo purposes -->
  269. <script src="<?php echo base_url();?>backendtampilan/dist/js/demo.js"></script>
  270. </body>
  271. </html>
Add Comment
Please, Sign In to add comment