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

Last change on this file since 767 was 767, checked in by namnd, 10 years ago
File size: 5.3 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Ü",
42                                2 => "Dùng thá»­",
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 ['keyword'] = "";
51                $data ['sorting_order'] = "sorting_desc";
52                $data ['sorting_field'] = "created_time";
53                if ($this->input->post ( 'sorting_order' )) {
54                        if ($this->input->post ( 'sorting_order' ) != "sorting") {
55                                $data ['sorting_order'] = $this->input->post ( 'sorting_order' );
56                                $data ['sorting_field'] = $this->input->post ( 'sorting_field' );
57                        }
58                }
59                if ($this->input->post ( 'items' )) {
60                        $data ['perpage'] = $this->input->post ( 'items' );
61                }
62                if ($this->input->post ( 'keyword' )) {
63                        $data ['keyword'] = $this->input->post ( 'keyword' );
64                }
65                $data ['daterange_start'] = "";
66                $data ['daterange_end'] = "";
67                if ($this->input->post ( 'daterange' )) {
68                        $daterange = explode ( " - ", $this->input->post ( 'daterange' ) );
69                        $daterange [0] = str_replace ( '/', '-', $daterange [0] );
70                        $daterange [1] = str_replace ( '/', '-', $daterange [1] );
71                        $data ['daterange_start'] = date ( 'Y-m-d H:i:s', strtotime ( $daterange [0] ) );
72                        $data ['daterange_end'] = date ( 'Y-m-d H:is:s', strtotime ( $daterange [1] . ' + 1 day' ) );
73                }
74                $data ['start'] = ($data ['current_page'] - 1) * $data ['perpage'];
75                $data ['total'] = $this->user_model->get_total_users ( $data );
76                $us = $this->user_model->get_list_users ( $data );
77                $users = array ();
78               
79                foreach ( $us as $u ) {
80                        $u ['province'] = isset($provinces[$u ['province']]) ? $provinces[$u ['province']] : $u ['province'];
81                        $userinfo = $this->get_userinfo ( $u ['us_id'] );
82                        if ($userinfo) {
83                                $u ['username'] = $userinfo ['username'];
84                                $u['fullname'] = $userinfo['fullname'];
85                        }
86                        array_push ( $users, $u );
87                }
88               
89                $data ['users'] = $users;
90                $data ['paging_url'] = base_url () . "admin/nguoi_dung/trang/";
91                $data ['num_links'] = 2;
92                $data ['paging'] = pagging ( $data );
93               
94                if ($this->input->is_ajax_request ()) {
95                        return $this->load->view ( 'user/listview', $data );
96                }
97                return $this->load->view ( 'user/listview', $data, true );
98        }
99       
100        public function edit_user() {
101                $admin_info = $this->session->userdata ( 'adminInfo' );
102                if ($admin_info) {
103                        $input = $this->input->post ();
104                        $result = array ();
105                        $result ['success'] = 0;
106                        $us_id = ( int ) $this->uri->segment ( 4, 0 );
107                        if ($us_id == 0) {
108                                $result ['success'] = 0;
109                        } else {
110                                $this->load->model ( 'user_model' );
111                                $input ['updated_time'] = date ( "Y-m-d H:i:s" );
112                                $this->user_model->update ( $us_id, $input );
113                                $result ['success'] = 1;
114                        }
115                        echo json_encode ( $result );
116                } else {
117                        $this->load->view ( 'login' );
118                }
119        }
120       
121        public function delete_user() {
122                $admin_info = $this->session->userdata ( 'adminInfo' );
123                if ($admin_info) {
124                        $result = array ();
125                        $result ['success'] = 0;
126                        $us_id = ( int ) $this->uri->segment ( 4, 0 );
127                        if ($us_id == 0) {
128                                $result ['success'] = 0;
129                        } else {
130                                $this->load->model ( 'user_model' );
131                                $this->user_model->delete ( $us_id );
132                                $result ['success'] = 1;
133                        }
134                        echo json_encode ( $result );
135                } else {
136                        $this->load->view ( 'login' );
137                }
138        }
139       
140        public function get_user_by_id() {
141                $admin_info = $this->session->userdata ( 'adminInfo' );
142                if ($admin_info) {
143                        $result = array ();
144                        $result ['success'] = 0;
145                        $us_id = ( int ) $this->uri->segment ( 4, 0 );
146                        if ($us_id == 0) {
147                                $result ['success'] = 0;
148                        } else {
149                                $this->load->model ( 'user_model' );
150                                $data = $this->user_model->search_by_id ( $us_id );
151                                $result ['item'] = $data;
152                                $result ['success'] = 1;
153                        }
154                        echo json_encode ( $result );
155                } else {
156                        $this->load->view ( 'login' );
157                }
158        }
159       
160        private function get_userinfo($us_id) {
161                $src = 'violet';
162                $token = md5 ( $us_id . self::TOKENPW );
163                $this->load->model ( 'user_model' );
164                $data = $this->user_model->get_user_info ( $src, $us_id, $token );
165                // var_dump($data);
166                $result = array ();
167                parse_str ( $data, $result );
168                return $result;
169                /*
170                 * if (strpos($data, '&')){ $arr_users = explode("&", $data); $str_username = $arr_users[1]; $arr_username = explode("=", $str_username); return $arr_username[1]; }else { return ""; }
171                 */
172        }
173}
Note: See TracBrowser for help on using the repository browser.