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

Last change on this file since 771 was 770, checked in by quyenla, 10 years ago

admin roles

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