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
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() {
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' );
[375]22                }
23        }
24       
[765]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Ü",
[767]42                                2 => "Dùng thá»­",
43                                3=> "Dùng thá»­ hạn chế",
44                                4=> "Hết hạn"
[765]45                );
46                $data ['status'] = 0;
47                if ($this->input->post ( 'status' )) {
48                        $data ['status'] = ( int ) $this->input->post ( 'status' );
[408]49                }
[765]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' );
[396]57                        }
58                }
[765]59                if ($this->input->post ( 'items' )) {
60                        $data ['perpage'] = $this->input->post ( 'items' );
[375]61                }
[765]62                if ($this->input->post ( 'keyword' )) {
63                        $data ['keyword'] = $this->input->post ( 'keyword' );
[690]64                }
[765]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 ();
[579]78               
[765]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'];
[767]84                                $u['fullname'] = $userinfo['fullname'];
[690]85                        }
[765]86                        array_push ( $users, $u );
[579]87                }
[408]88               
[765]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 );
[375]96                }
[765]97                return $this->load->view ( 'user/listview', $data, true );
[375]98        }
99       
[765]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;
[396]114                        }
[765]115                        echo json_encode ( $result );
116                } else {
117                        $this->load->view ( 'login' );
[396]118                }
119        }
120       
[765]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;
[396]133                        }
[765]134                        echo json_encode ( $result );
135                } else {
136                        $this->load->view ( 'login' );
[396]137                }
138        }
139       
[765]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;
[396]153                        }
[765]154                        echo json_encode ( $result );
155                } else {
156                        $this->load->view ( 'login' );
[396]157                }
158        }
159       
[765]160        private function get_userinfo($us_id) {
[408]161                $src = 'violet';
[765]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 );
[690]168                return $result;
169                /*
[765]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                 */
[408]172        }
[375]173}
Note: See TracBrowser for help on using the repository browser.