[339] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
[324] | 2 |
|
---|
| 3 | class Home extends MX_Controller
|
---|
| 4 | {
|
---|
| 5 | public function __construct()
|
---|
| 6 | {
|
---|
| 7 | parent::__construct();
|
---|
| 8 | $this->load->helper('cookie');
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 | public function index ()
|
---|
| 12 | {
|
---|
| 13 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 14 | if ($admin_info)
|
---|
| 15 | {
|
---|
| 16 | $this->load->view('index');
|
---|
| 17 | }else
|
---|
| 18 | {
|
---|
| 19 | $this->load->view ( 'login');
|
---|
| 20 | }
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | public function login()
|
---|
| 24 | {
|
---|
| 25 | $username = $this->input->post('user_admin');
|
---|
| 26 | $password = $this->input->post('password');
|
---|
| 27 |
|
---|
| 28 | $this->load->model(array('admin_model'));
|
---|
| 29 | $data = $this->admin_model->check_login($username, $password);
|
---|
| 30 | if ($data == null)
|
---|
| 31 | {
|
---|
| 32 | $this->session->set_flashdata('login_error', TRUE);
|
---|
| 33 | redirect("/admin/home");
|
---|
| 34 | }
|
---|
| 35 | else
|
---|
| 36 | {
|
---|
| 37 | $admindata = array('user_admin' => $username, "logined_in" => TRUE);
|
---|
| 38 | $this->session->set_userdata('adminInfo', $admindata);
|
---|
| 39 | redirect("/admin/home");
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | public function logout()
|
---|
| 44 | {
|
---|
| 45 | $this->session->sess_destroy();
|
---|
| 46 | redirect("/admin/home");
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[339] | 49 | public function admin_acc()
|
---|
| 50 | {
|
---|
[342] | 51 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 52 | if($admin_info){
|
---|
| 53 | $this->load->model('admin_model');
|
---|
| 54 | $data = $this->admin_model->get_list();
|
---|
| 55 | //var_dump($data);
|
---|
| 56 | $this->load->view('admin_acc', array('data'=>$data));
|
---|
| 57 | }else
|
---|
| 58 | {
|
---|
| 59 | redirect("/admin/home");
|
---|
| 60 | }
|
---|
[339] | 61 | }
|
---|
| 62 |
|
---|
[349] | 63 | public function insert()
|
---|
| 64 | {
|
---|
| 65 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 66 | if($admin_info)
|
---|
| 67 | {
|
---|
| 68 | $login_name = $this->input->post('username');
|
---|
| 69 | $password = $this->input->post('password');
|
---|
| 70 | $full_name = $this->input->post('fullname');
|
---|
| 71 | $email = $this->input->post('email');
|
---|
| 72 | $phone = $this->input->post('phone');
|
---|
| 73 | $created_time = date('Y-m-d H:i:s', time());
|
---|
| 74 | $updated_time = date('Y-m-d H:i:s', time());
|
---|
| 75 | $data = array('login_name'=>$login_name, 'full_name'=>$full_name, 'email'=>$email, 'phone'=>$phone, 'created_time'=>$created_time, 'updated_time'=>$updated_time);
|
---|
| 76 | $this->load->model('admin_model');
|
---|
| 77 | $this->admin_model->insert($data);
|
---|
| 78 | redirect("/admin/home/admin_acc");
|
---|
| 79 |
|
---|
| 80 | }else
|
---|
| 81 | {
|
---|
| 82 | redirect("/admin/home");
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | public function update()
|
---|
| 87 | {
|
---|
| 88 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 89 | if($admin_info)
|
---|
| 90 | {
|
---|
| 91 | $admin_id = (int)$this->input->post('id');
|
---|
| 92 | $login_name = $this->input->post('username');
|
---|
| 93 | //$password = $this->input->post('password');
|
---|
| 94 | $full_name = $this->input->post('fullname');
|
---|
| 95 | $email = $this->input->post('email');
|
---|
| 96 | $phone = $this->input->post('phone');
|
---|
| 97 | $updated_time = date('Y-m-d H:i:s', time());
|
---|
| 98 | $data = array('login_name'=>$login_name, 'full_name'=>$full_name, 'email'=>$email, 'phone'=>$phone, 'updated_time'=>$updated_time);
|
---|
| 99 | $this->load->model('admin_model');
|
---|
| 100 | $this->admin_model->update($admin_id, $data);
|
---|
| 101 | redirect("/admin/home/admin_acc");
|
---|
| 102 | }else
|
---|
| 103 | {
|
---|
| 104 | redirect("/admin/home");
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | public function delete()
|
---|
| 109 | {
|
---|
| 110 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 111 | if($admin_info)
|
---|
| 112 | {
|
---|
| 113 | $admin_id = (int)$this->input->post('id');
|
---|
| 114 | //echo $admin_id;
|
---|
| 115 | $this->load->model('admin_model');
|
---|
| 116 | $this->admin_model->delete($admin_id);
|
---|
| 117 | redirect("/admin/home/admin_acc");
|
---|
| 118 | }else
|
---|
| 119 | {
|
---|
| 120 | redirect("/admin/home");
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[324] | 125 | } |
---|