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

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