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

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