1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
2 |
|
---|
3 | class Admin_Account 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 | $this->load->model('admin_model');
|
---|
16 | $data = $this->admin_model->get_list();
|
---|
17 | $this->load->view('admin_acc', array('data'=>$data));
|
---|
18 | }else
|
---|
19 | {
|
---|
20 | redirect("/admin/home");
|
---|
21 | }
|
---|
22 | }
|
---|
23 |
|
---|
24 | public function insert()
|
---|
25 | {
|
---|
26 | $admin_info = $this->session->userdata('adminInfo');
|
---|
27 | if($admin_info)
|
---|
28 | {
|
---|
29 | $login_name = $this->input->post('username');
|
---|
30 | $password = md5($this->input->post('password'));
|
---|
31 | $full_name = $this->input->post('fullname');
|
---|
32 | $email = $this->input->post('email');
|
---|
33 | $phone = $this->input->post('phone');
|
---|
34 | $created_time = date('Y-m-d H:i:s', time());
|
---|
35 | $updated_time = date('Y-m-d H:i:s', time());
|
---|
36 | $data = array('login_name'=>$login_name, 'full_name'=>$full_name, 'email'=>$email, 'phone'=>$phone, 'created_time'=>$created_time, 'updated_time'=>$updated_time);
|
---|
37 | $this->load->model('admin_model');
|
---|
38 | /*
|
---|
39 | $check = $this->admin_model->check_data($login_name);
|
---|
40 | if ($check)
|
---|
41 | {
|
---|
42 | $this->session->flashdata('insert_error');
|
---|
43 | echo "Tên ÄÄng nháºp Äã ÄÆ°á»£c sá» dụng !";
|
---|
44 | //redirect("/admin/home/admin_acc");
|
---|
45 | }else
|
---|
46 | {
|
---|
47 | $this->admin_model->insert($data);
|
---|
48 | redirect("/admin/admin_account");
|
---|
49 | }*/
|
---|
50 | $this->admin_model->insert($data);
|
---|
51 | redirect("/admin/admin_account");
|
---|
52 |
|
---|
53 | }else
|
---|
54 | {
|
---|
55 | redirect("/admin/home");
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | public function update()
|
---|
60 | {
|
---|
61 | $admin_info = $this->session->userdata('adminInfo');
|
---|
62 | if($admin_info)
|
---|
63 | {
|
---|
64 | $admin_id = (int)$this->input->post('id');
|
---|
65 | $login_name = $this->input->post('username');
|
---|
66 | //$password = $this->input->post('password');
|
---|
67 | $full_name = $this->input->post('fullname');
|
---|
68 | $email = $this->input->post('email');
|
---|
69 | $phone = $this->input->post('phone');
|
---|
70 | $updated_time = date('Y-m-d H:i:s', time());
|
---|
71 | $data = array('login_name'=>$login_name, 'full_name'=>$full_name, 'email'=>$email, 'phone'=>$phone, 'updated_time'=>$updated_time);
|
---|
72 | $this->load->model('user_model');
|
---|
73 | $this->user_model->update($admin_id, $data);
|
---|
74 | redirect("/admin/admin_account");
|
---|
75 | }else
|
---|
76 | {
|
---|
77 | redirect("/admin/home");
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | public function delete()
|
---|
82 | {
|
---|
83 | $admin_info = $this->session->userdata('adminInfo');
|
---|
84 | if($admin_info)
|
---|
85 | {
|
---|
86 | $admin_id = (int)$this->input->post('id');
|
---|
87 | //echo $admin_id;
|
---|
88 | $this->load->model('admin_model');
|
---|
89 | $this->admin_model->delete($admin_id);
|
---|
90 | redirect("/admin/admin_account");
|
---|
91 | }else
|
---|
92 | {
|
---|
93 | redirect("/admin/home");
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | public function check_data()
|
---|
98 | {
|
---|
99 | $login_name = $this->input->post('username');
|
---|
100 | //var_dump($login_name);
|
---|
101 | $this->load->model('admin_model');
|
---|
102 | $check = $this->admin_model->check_data($login_name);
|
---|
103 | if ($check){
|
---|
104 | echo 1;
|
---|
105 | }else
|
---|
106 | {
|
---|
107 | echo 0;
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|