source: pro-violet-viettel/sourcecode/application/modules/collaborator/controllers/user.php

Last change on this file was 906, checked in by namnd, 10 years ago
File size: 3.8 KB
Line 
1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3if ( ! defined('_SBG_REGISTER_FOR'))                                    define('_SBG_REGISTER_FOR',                             'DK');
4if ( ! defined('_SBG_REGISTER_VIP_FOR'))                                define('_SBG_REGISTER_VIP_FOR',                                 'VIP');
5if ( ! defined('_SBG_CHARGING_FOR'))                                    define('_SBG_CHARGING_FOR',                             'NAP');
6
7class User extends MX_Controller {
8       
9        function __construct()
10        {
11                parent::__construct();
12                $this->load->helper('cookie');
13                $this->load->helper('language');
14                $this->lang->load('messages', 'message');
15                $this->load->helper(array('form', 'url'));
16        }
17       
18        public function index(){
19                $collaborator_info = $this->session->userdata('collaboratorInfo');
20                if ($collaborator_info) {
21                        $data = array();
22                        $this->load->view('collaborator/user/index', $data);
23                }else{
24                        $this->load->view(login);
25                }
26        }
27       
28        public function upload()
29        {
30                $collaborator_info = $this->session->userdata('collaboratorInfo');
31        if ($collaborator_info) {
32                        $collaborator = $collaborator_info['login_name'];
33                        $config['upload_path'] = './upload/uploads/';
34                        $config['allowed_types'] = '*';
35                        $this->load->library('upload', $config);
36                       
37                        if ( $this->upload->do_upload() == false)
38                        {
39                                $error = array('error' => $this->upload->display_errors('', ''));
40                                $data['success'] = 0;
41                                $data['upload_error'] = $error;
42                        }
43                        else
44                        {
45                                $data = array('upload_data' => $this->upload->data());
46                                $file = $data['upload_data']['full_path'];
47                                $process = $this->processData($file, $collaborator);
48                                if ($process){
49                                        $data['process'] = $process;
50                                }else{
51                                        $data['process'] = null;                               
52                                }
53                                $data['success'] = 1;
54                        }
55                        $result = $this->load->view('collaborator/user/result', $data, true);
56                        echo json_encode($result);
57
58                }else{
59                        $this->load->view('login');
60                }
61        }
62       
63        protected function readExcelFile($file){
64                $this->load->library("PHPExcel");
65                $objPHPExcel = PHPExcel_IOFactory::load($file);
66                $cell_collection = $objPHPExcel->getActiveSheet()->getCellCollection();
67               
68                foreach ($cell_collection as $cell):
69                        $column = $objPHPExcel->getActiveSheet()->getCell($cell)->getColumn();
70                        $row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
71                        $data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
72                       
73                        if ($row == 1){
74                                $header[$row][$column] = $data_value;
75                        } else {
76                                $arr_data[$row][$column] = $data_value;
77                        }
78                endforeach;
79                $data['header'] = $header;
80                $data['values'] = $arr_data;
81                return $data['values'];
82        }
83       
84        protected function processData($file, $collaborator){
85                $sentNumber = $collaborator;
86                $this->load->model('services/services_model');
87                $this->load->model('frontend/user_model');
88                $this->load->model('collaborator_model');
89                $data = $this->readExcelFile($file);
90
91                $result = array();
92                $user = array();
93                if ($data){
94                        foreach ($data as $index => $value):
95                                $user['fullname'] = $value['B'];
96                                $user['province'] = $value['C'];
97                                $user['district'] = $value['D'];
98                                $arrPD = $this->collaborator_model->getProvinceAndDistict($user['province'], $user['district']);
99                                $user['province'] = $arrPD['province'];
100                                $user['district'] = $arrPD['district'];
101                                $user['school'] = $value['E'];
102                                $user['username'] = $this->services_model->formatPhoneNumber((string)$value['F'], 2);
103                                $user['service'] = $value['G'];
104                                $user['amount'] = $value['H'];
105                                $user['collboratorId'] = $value['I'];
106                               
107                               
108                                if ($user['username']){
109       
110                                        if (!preg_match('/^([0-9]{10,11}$)$/', $user['username'])) {
111                                                $result[$index-1]['success'] = 0;
112                                                $result[$index-1]['error'] = lang('_SBG_MO_PHONENUM_WRONG_FORMAT_MSG');
113                                                $result[$index-1]['user'] = $user;
114                                        }else{
115                                                $result[$index-1] = $this->collaborator_model->processUser($user, $sentNumber);
116                                        }
117                                }
118                               
119                        endforeach;
120                }
121                return $result;
122        }
123}
Note: See TracBrowser for help on using the repository browser.