[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 | {
|
---|
[360] | 13 |
|
---|
[324] | 14 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 15 | if ($admin_info)
|
---|
| 16 | {
|
---|
| 17 | $this->load->view('index');
|
---|
| 18 | }else
|
---|
| 19 | {
|
---|
| 20 | $this->load->view ( 'login');
|
---|
| 21 | }
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | public function login()
|
---|
| 25 | {
|
---|
[360] | 26 |
|
---|
[324] | 27 | $username = $this->input->post('user_admin');
|
---|
| 28 | $password = $this->input->post('password');
|
---|
| 29 |
|
---|
| 30 | $this->load->model(array('admin_model'));
|
---|
| 31 | $data = $this->admin_model->check_login($username, $password);
|
---|
| 32 | if ($data == null)
|
---|
| 33 | {
|
---|
| 34 | $this->session->set_flashdata('login_error', TRUE);
|
---|
| 35 | redirect("/admin/home");
|
---|
| 36 | }
|
---|
| 37 | else
|
---|
| 38 | {
|
---|
| 39 | $admindata = array('user_admin' => $username, "logined_in" => TRUE);
|
---|
| 40 | $this->session->set_userdata('adminInfo', $admindata);
|
---|
| 41 | redirect("/admin/home");
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public function logout()
|
---|
| 46 | {
|
---|
| 47 | $this->session->sess_destroy();
|
---|
| 48 | redirect("/admin/home");
|
---|
| 49 | }
|
---|
| 50 |
|
---|
[339] | 51 | public function admin_acc()
|
---|
| 52 | {
|
---|
[342] | 53 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 54 | if($admin_info){
|
---|
| 55 | $this->load->model('admin_model');
|
---|
| 56 | $data = $this->admin_model->get_list();
|
---|
| 57 | $this->load->view('admin_acc', array('data'=>$data));
|
---|
| 58 | }else
|
---|
| 59 | {
|
---|
| 60 | redirect("/admin/home");
|
---|
| 61 | }
|
---|
[339] | 62 | }
|
---|
| 63 |
|
---|
[349] | 64 | public function insert()
|
---|
| 65 | {
|
---|
| 66 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 67 | if($admin_info)
|
---|
| 68 | {
|
---|
| 69 | $login_name = $this->input->post('username');
|
---|
| 70 | $password = $this->input->post('password');
|
---|
| 71 | $full_name = $this->input->post('fullname');
|
---|
| 72 | $email = $this->input->post('email');
|
---|
| 73 | $phone = $this->input->post('phone');
|
---|
| 74 | $created_time = date('Y-m-d H:i:s', time());
|
---|
| 75 | $updated_time = date('Y-m-d H:i:s', time());
|
---|
| 76 | $data = array('login_name'=>$login_name, 'full_name'=>$full_name, 'email'=>$email, 'phone'=>$phone, 'created_time'=>$created_time, 'updated_time'=>$updated_time);
|
---|
| 77 | $this->load->model('admin_model');
|
---|
| 78 | $this->admin_model->insert($data);
|
---|
| 79 | redirect("/admin/home/admin_acc");
|
---|
| 80 |
|
---|
| 81 | }else
|
---|
| 82 | {
|
---|
| 83 | redirect("/admin/home");
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | public function update()
|
---|
| 88 | {
|
---|
| 89 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 90 | if($admin_info)
|
---|
| 91 | {
|
---|
| 92 | $admin_id = (int)$this->input->post('id');
|
---|
| 93 | $login_name = $this->input->post('username');
|
---|
| 94 | //$password = $this->input->post('password');
|
---|
| 95 | $full_name = $this->input->post('fullname');
|
---|
| 96 | $email = $this->input->post('email');
|
---|
| 97 | $phone = $this->input->post('phone');
|
---|
| 98 | $updated_time = date('Y-m-d H:i:s', time());
|
---|
| 99 | $data = array('login_name'=>$login_name, 'full_name'=>$full_name, 'email'=>$email, 'phone'=>$phone, 'updated_time'=>$updated_time);
|
---|
| 100 | $this->load->model('admin_model');
|
---|
| 101 | $this->admin_model->update($admin_id, $data);
|
---|
| 102 | redirect("/admin/home/admin_acc");
|
---|
| 103 | }else
|
---|
| 104 | {
|
---|
| 105 | redirect("/admin/home");
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | public function delete()
|
---|
| 110 | {
|
---|
| 111 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 112 | if($admin_info)
|
---|
| 113 | {
|
---|
| 114 | $admin_id = (int)$this->input->post('id');
|
---|
| 115 | //echo $admin_id;
|
---|
| 116 | $this->load->model('admin_model');
|
---|
| 117 | $this->admin_model->delete($admin_id);
|
---|
| 118 | redirect("/admin/home/admin_acc");
|
---|
| 119 | }else
|
---|
| 120 | {
|
---|
| 121 | redirect("/admin/home");
|
---|
[357] | 122 | }
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | public function user_profile()
|
---|
| 126 | {
|
---|
| 127 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 128 | if($admin_info)
|
---|
| 129 | {
|
---|
| 130 | $this->load->view('user_profile');
|
---|
| 131 | }else
|
---|
| 132 | {
|
---|
| 133 | redirect("/admin/home");
|
---|
[349] | 134 | }
|
---|
| 135 | }
|
---|
| 136 |
|
---|
[324] | 137 | } |
---|