[375] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
| 2 |
|
---|
| 3 | class Admin_Acc 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 | $data['content'] = $this->get_admins();
|
---|
| 17 | $this->load->view('admin_acc/index', $data);
|
---|
| 18 | }else
|
---|
| 19 | {
|
---|
| 20 | $this->load->view('login');
|
---|
| 21 | }
|
---|
| 22 | }
|
---|
| 23 |
|
---|
[392] | 24 | public function get_admins()
|
---|
[375] | 25 | {
|
---|
| 26 | $this->load->helper('pagging');
|
---|
| 27 | $this->load->model('admin_model');
|
---|
| 28 | $data['current_page'] = $this->uri->segment(4, 1);
|
---|
| 29 | $data['itemsoptions'] = array(10, 25, 50, 100);
|
---|
| 30 | $data['perpage'] = 10;
|
---|
| 31 | $data['keyword'] = "";
|
---|
[392] | 32 | $data['sorting_order']="sorting_desc";
|
---|
| 33 | $data['sorting_field']="created_time";
|
---|
| 34 | if ($this->input->post('sorting_order')) {
|
---|
| 35 | if ($this->input->post('sorting_order') != "sorting")
|
---|
| 36 | {
|
---|
| 37 | $data['sorting_order'] = $this->input->post('sorting_order');
|
---|
| 38 | $data['sorting_field'] = $this->input->post('sorting_field');
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
[375] | 41 | if ($this->input->post('items'))
|
---|
| 42 | {
|
---|
| 43 | $data['perpage'] = $this->input->post('items');
|
---|
| 44 | }
|
---|
| 45 | if ($this->input->post('keyword')) {
|
---|
| 46 | $data['keyword'] = $this->input->post('keyword');
|
---|
| 47 | }
|
---|
| 48 | $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
|
---|
| 49 | $data['total'] = $this->admin_model->get_total_admins($data);
|
---|
| 50 | $data['admins'] = $this->admin_model->get_list_admins($data);
|
---|
| 51 | $data['paging_url'] = base_url() . "admin/quan_tri_vien/trang/";
|
---|
| 52 | $data['num_links'] = 2;
|
---|
| 53 | $data['paging'] = pagging($data);
|
---|
| 54 | if ($this->input->is_ajax_request())
|
---|
| 55 | {
|
---|
| 56 | return $this->load->view('admin_acc/listview', $data);
|
---|
| 57 | }
|
---|
| 58 | return $this->load->view('admin_acc/listview', $data, true);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | public function add_admin()
|
---|
| 62 | {
|
---|
| 63 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 64 | if ($admin_info)
|
---|
| 65 | {
|
---|
| 66 | $this->load->helper('email');
|
---|
| 67 | $result['success'] = 0;
|
---|
| 68 | $result = array();
|
---|
| 69 | $input = $this->input->post();
|
---|
| 70 | $this->load->model('admin_model');
|
---|
| 71 | if (strlen($input['full_name'])==0)
|
---|
| 72 | {
|
---|
| 73 | $result['errors']['full_name_err']="Tên Admin khÃŽng ÄÆ°á»£c Äá» trá»ng";
|
---|
| 74 | }
|
---|
| 75 | if (strlen($input['login_name'])==0)
|
---|
| 76 | {
|
---|
| 77 | $result['errors']['login_name_err']="Tên ÄÄng nháºp khÃŽng ÄÆ°á»£c Äá» trá»ng";
|
---|
| 78 | }
|
---|
| 79 | else
|
---|
| 80 | {
|
---|
| 81 | if ($this->admin_model->check_exist(array('field'=>'login_name','value'=>$input['login_name'])))
|
---|
| 82 | {
|
---|
| 83 | $result['errors']['login_name_err']="Tên ÄÄng nháºp Äã ÄÆ°á»£c sá» dụng";
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 | if (strlen($input['phone'])==0)
|
---|
| 87 | {
|
---|
| 88 | $result['errors']['phone_err']="Sá» Äiá»n thoại khÃŽng ÄÆ°á»£c Äá» trá»ng";
|
---|
| 89 | }
|
---|
| 90 | else
|
---|
| 91 | {
|
---|
| 92 | if ($this->admin_model->check_exist(array('field'=>'phone','value'=>$input['phone'])))
|
---|
| 93 | {
|
---|
| 94 | $result['errors']['phone_err']="Sá» Äiá»n thoại Äã ÄÆ°á»£c sá» dụng";
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 | if (strlen($input['passwd'])==0)
|
---|
| 98 | {
|
---|
| 99 | $result['errors']['pwd1_err']="Máºt khẩu khÃŽng ÄÆ°á»£c Äá» trá»ng";
|
---|
| 100 | }
|
---|
| 101 | if ($input['passwd'] != $input['pwd2'])
|
---|
| 102 | {
|
---|
| 103 | $result['errors']['pwd2_err']="Máºt khẩu khÃŽng trùng nhau";
|
---|
| 104 | }
|
---|
| 105 | if(strlen($input['email'])==0)
|
---|
| 106 | {
|
---|
| 107 | $result['errors']['email_err']="Email khÃŽng ÄÆ°á»£c Äá» trá»ng";
|
---|
| 108 | }else{
|
---|
| 109 | if(!valid_email($input['email']))
|
---|
| 110 | {
|
---|
| 111 | $result['errors']['email_err']="Email khÃŽng Äúng Äá»nh dạng";
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 | if (!isset($result['errors']))
|
---|
| 115 | {
|
---|
| 116 | unset($input['pwd2']);
|
---|
| 117 | $input['created_time']=date("Y-m-d H:i:s");
|
---|
| 118 | $input['updated_time']=date("Y-m-d H:i:s");
|
---|
| 119 | $this->admin_model->insert($input);
|
---|
| 120 | $result['success'] = 1;
|
---|
| 121 | }
|
---|
| 122 | echo json_encode($result);
|
---|
| 123 | }else{
|
---|
| 124 | $this->load->view('login');
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | public function edit_admin()
|
---|
| 129 | {
|
---|
| 130 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 131 | if ($admin_info)
|
---|
| 132 | {
|
---|
| 133 | $input = $this->input->post();
|
---|
| 134 | $result = array();
|
---|
| 135 | $result['success'] = 0;
|
---|
| 136 | $admin_id = (int)$this->uri->segment(4, 0);
|
---|
| 137 | if ($admin_id==0){
|
---|
| 138 | $result['success'] = 0;
|
---|
| 139 | }else
|
---|
| 140 | {
|
---|
| 141 | $this->load->model('admin_model');
|
---|
| 142 | $input['updated_time']=date("Y-m-d H:i:s");
|
---|
| 143 | $this->admin_model->update($admin_id, $input);
|
---|
| 144 | $result['success'] = 1;
|
---|
| 145 | }
|
---|
| 146 | echo json_encode($result);
|
---|
| 147 | }else
|
---|
| 148 | {
|
---|
| 149 | $this->load->view('login');
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | public function delete_admin()
|
---|
| 154 | {
|
---|
| 155 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 156 | if ($admin_info)
|
---|
| 157 | {
|
---|
| 158 | $result = array();
|
---|
| 159 | $result['success'] = 0;
|
---|
| 160 | $admin_id = (int)$this->uri->segment(4, 0);
|
---|
| 161 | if ($admin_id == 0){
|
---|
| 162 | $result['success'] = 0;
|
---|
| 163 | }else
|
---|
| 164 | {
|
---|
| 165 | $this->load->model('admin_model');
|
---|
| 166 | $this->admin_model->delete($admin_id);
|
---|
| 167 | $result['success'] = 1;
|
---|
| 168 | }
|
---|
| 169 | echo json_encode($result);
|
---|
| 170 | }else
|
---|
| 171 | {
|
---|
| 172 | $this->load->view('login');
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | public function get_admin_by_id()
|
---|
| 177 | {
|
---|
| 178 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 179 | if ($admin_info)
|
---|
| 180 | {
|
---|
| 181 | $result = array();
|
---|
| 182 | $result['success'] = 0;
|
---|
| 183 | $admin_id = (int)$this->uri->segment(4, 0);
|
---|
| 184 | if ($admin_id == 0)
|
---|
| 185 | {
|
---|
| 186 | $result['success'] = 0;
|
---|
| 187 | }else
|
---|
| 188 | {
|
---|
| 189 | $this->load->model('admin_model');
|
---|
| 190 | $data = $this->admin_model->search_by_id($admin_id);
|
---|
| 191 | $result['item'] = $data;
|
---|
| 192 | $result['success'] = 1;
|
---|
| 193 | }
|
---|
| 194 | echo json_encode($result);
|
---|
| 195 | }else
|
---|
| 196 | {
|
---|
| 197 | $this->load->view('login');
|
---|
| 198 | }
|
---|
| 199 | }
|
---|
| 200 | } |
---|