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