source: pro-violet-viettel/sourcecode/application/modules/admin/controllers/user.php @ 707

Last change on this file since 707 was 690, checked in by namnd, 10 years ago
File size: 4.7 KB
Line 
1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3class User extends MX_Controller
4{
5       
6        const TOKENPW = 'violet';
7       
8        public function __construct()
9        {
10                parent::__construct();
11                $this->load->helper('cookie');
12        }
13       
14        public function index()
15        {
16                $admin_info = $this->session->userdata('adminInfo');
17                if ($admin_info)
18                {
19                        $data['content'] = $this->get_users();
20                        $this->load->view('user/index', $data);
21                }else
22                {
23                        $this->load->view('login');
24                }
25        }
26       
27        public function get_users()
28        {
29                $this->load->helper('pagging');
30                $this->load->model('user_model');
31                $data['current_page'] = $this->uri->segment(4, 1);
32                $data['itemsoptions'] = array(10, 25, 50, 100);
33                $data['perpage'] = 10;
34                $data['statusoptions'] = array(0=>"Tất cả", 1=>"Đã đăng kÜ", 2=>"Dùng thá»­");
35                $data['status'] = 0;
36                if ($this->input->post('status'))
37                {
38                        $data['status'] = (int)$this->input->post('status') ;
39                }
40                $data['keyword'] = "";
41                $data['sorting_order']="sorting_desc";
42        $data['sorting_field']="created_time";
43                if ($this->input->post('sorting_order')) {
44                        if ($this->input->post('sorting_order') != "sorting")
45                        {
46                                $data['sorting_order'] = $this->input->post('sorting_order');
47                                $data['sorting_field'] = $this->input->post('sorting_field');
48                        }
49                }
50                if ($this->input->post('items'))
51                {
52                        $data['perpage'] = $this->input->post('items');
53                }
54                if ($this->input->post('keyword')) {
55            $data['keyword'] = $this->input->post('keyword');
56        }
57                $data['daterange_start'] = "";
58                $data['daterange_end'] = "";
59                if ($this->input->post('daterange')){
60                        $daterange = explode(" - ", $this->input->post('daterange'));
61                        $data['daterange_start'] = date('Y-m-d H:i:s', strtotime($daterange[0]));
62                        $data['daterange_end'] = date('Y-m-d H:is:s', strtotime($daterange[1].' + 1 day'));
63                }
64                $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
65                $data['total'] = $this->user_model->get_total_users($data);
66                $us = $this->user_model->get_list_users($data);
67                $users = array();
68               
69                foreach($us as $u) {
70                        $id = $u['us_id'];
71                        //$username = $this->get_username($id);
72                        $userinfo = $this->get_userinfo($id);
73                        if($userinfo){
74                                $u['username'] = $userinfo['username'];
75                                $u['province'] = $userinfo['province'];
76                                array_push($users, $u);
77                        }
78                }
79               
80                $data['users'] = $users;
81                $data['paging_url'] = base_url() . "admin/nguoi_dung/trang/";
82                $data['num_links'] = 2;
83                $data['paging'] = pagging($data);
84                if ($this->input->is_ajax_request())
85                {
86                        return $this->load->view('user/listview', $data);
87                }
88                return $this->load->view('user/listview', $data, true);
89        }
90       
91        public function edit_user()
92        {
93                $admin_info = $this->session->userdata('adminInfo');
94                if ($admin_info)
95                {
96                        $input = $this->input->post();
97                        $result = array();
98                        $result['success'] = 0;
99                        $us_id = (int)$this->uri->segment(4, 0);
100                        if ($us_id==0){
101                                $result['success'] = 0;
102                        }else
103                        {
104                                $this->load->model('user_model');
105                                $input['updated_time'] = date("Y-m-d H:i:s");
106                                $this->user_model->update($us_id, $input);
107                                $result['success'] = 1;
108                        }
109                        echo json_encode($result);
110                }else
111                {
112                        $this->load->view('login');
113                }
114        }
115       
116        public function delete_user()
117        {
118                $admin_info = $this->session->userdata('adminInfo');
119                if ($admin_info)
120                {
121                        $result = array();
122                        $result['success'] = 0;
123                        $us_id = (int)$this->uri->segment(4, 0);
124                        if ($us_id == 0){
125                                $result['success'] = 0;
126                        }else
127                        {
128                                $this->load->model('user_model');
129                                $this->user_model->delete($us_id);
130                                $result['success'] = 1;
131                        }
132                        echo json_encode($result);
133                }else
134                {
135                        $this->load->view('login');
136                }
137        }
138       
139        public function get_user_by_id()
140        {
141                $admin_info = $this->session->userdata('adminInfo');
142                if ($admin_info)
143                {
144                        $result = array();
145                        $result['success'] = 0;
146                        $us_id = (int)$this->uri->segment(4, 0);
147                        if ($us_id == 0)
148                        {
149                                $result['success'] = 0;
150                        }else
151                        {
152                                $this->load->model('user_model');
153                                $data = $this->user_model->search_by_id($us_id);
154                                $result['item'] = $data;
155                                $result['success'] = 1;
156                        }
157                        echo json_encode($result);
158                }else
159                {
160                        $this->load->view('login');
161                }
162        }
163       
164        private function get_userinfo($us_id)
165        {
166                $src = 'violet';
167                $token = md5($us_id.self::TOKENPW);
168                $this->load->model('user_model');
169                $data = $this->user_model->get_user_info($src, $us_id, $token);
170                //var_dump($data);
171                $result = array();
172                parse_str($data, $result);
173                return $result;
174                /*
175                if (strpos($data, '&')){
176                        $arr_users = explode("&", $data);
177                        $str_username = $arr_users[1];
178                        $arr_username = explode("=", $str_username);
179                        return $arr_username[1];
180                }else
181                {
182                        return "";
183                }*/
184
185        }
186       
187}
Note: See TracBrowser for help on using the repository browser.