1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
2 |
|
---|
3 | if ( ! defined('_SBG_REGISTER_FOR')) define('_SBG_REGISTER_FOR', 'DK');
|
---|
4 | if ( ! defined('_SBG_REGISTER_VIP_FOR')) define('_SBG_REGISTER_VIP_FOR', 'VIP');
|
---|
5 | if ( ! defined('_SBG_CHARGING_FOR')) define('_SBG_CHARGING_FOR', 'NAP');
|
---|
6 |
|
---|
7 | class 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 | show_404();
|
---|
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'] = 'xls|xlsx';
|
---|
35 | /*$config['max_size'] = '100';
|
---|
36 | $config['max_width'] = '1024';
|
---|
37 | $config['max_height'] = '768';*/
|
---|
38 |
|
---|
39 | $this->load->library('upload', $config);
|
---|
40 |
|
---|
41 | if ( $this->upload->do_upload() == false)
|
---|
42 | {
|
---|
43 | $error = array('error' => $this->upload->display_errors('', ''));
|
---|
44 | $data['success'] = 0;
|
---|
45 | $data['process'] = $error;
|
---|
46 | }
|
---|
47 | else
|
---|
48 | {
|
---|
49 | $data = array('upload_data' => $this->upload->data());
|
---|
50 | $file = $data['upload_data']['full_path'];
|
---|
51 | //$result = $this->processData($file);
|
---|
52 | $process = $this->processData($file, $collaborator);
|
---|
53 | if ($process){
|
---|
54 | $data['process'] = $process;
|
---|
55 |
|
---|
56 | }else{
|
---|
57 | $data['process'] = null;
|
---|
58 | }
|
---|
59 | $data['success'] = 1;
|
---|
60 | }
|
---|
61 | $result = $this->load->view('collaborator/user/result', $data, true);
|
---|
62 | echo json_encode($result);
|
---|
63 | }else{
|
---|
64 | show_404();
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | protected function readExcelFile($file){
|
---|
69 | $this->load->library("PHPExcel");
|
---|
70 | $objPHPExcel = PHPExcel_IOFactory::load($file);
|
---|
71 | $cell_collection = $objPHPExcel->getActiveSheet()->getCellCollection();
|
---|
72 |
|
---|
73 | foreach ($cell_collection as $cell):
|
---|
74 | $column = $objPHPExcel->getActiveSheet()->getCell($cell)->getColumn();
|
---|
75 | $row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
|
---|
76 | $data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
|
---|
77 |
|
---|
78 | if ($row == 1){
|
---|
79 | $header[$row][$column] = $data_value;
|
---|
80 | } else {
|
---|
81 | $arr_data[$row][$column] = $data_value;
|
---|
82 | }
|
---|
83 | endforeach;
|
---|
84 | $data['header'] = $header;
|
---|
85 | $data['values'] = $arr_data;
|
---|
86 | return $data['values'];
|
---|
87 | }
|
---|
88 |
|
---|
89 | protected function processData($file, $collaborator){
|
---|
90 | $sentNumber = $collaborator;
|
---|
91 | $this->load->model('services/services_model');
|
---|
92 | $this->load->model('frontend/user_model');
|
---|
93 | $this->load->model('collaborator_model');
|
---|
94 | $data = $this->readExcelFile($file);
|
---|
95 | $result = array();
|
---|
96 | $user = array();
|
---|
97 | if ($data){
|
---|
98 | foreach ($data as $index => $value):
|
---|
99 | $user['fullname'] = $value['B'];
|
---|
100 | $user['province'] = $value['C'];
|
---|
101 | $user['district'] = $value['D'];
|
---|
102 | $arrPD = $this->collaborator_model->getProvinceAndDistict($user['province'], $user['district']);
|
---|
103 | $user['province'] = $arrPD['province'];
|
---|
104 | $user['district'] = $arrPD['district'];
|
---|
105 | $user['school'] = $value['E'];
|
---|
106 | $user['username'] = $this->services_model->formatPhoneNumber($value['F'], 2);
|
---|
107 | $user['service'] = $value['G'];
|
---|
108 | $user['amount'] = $value['H'];
|
---|
109 | $user['collboratorId'] = $value['I'];
|
---|
110 |
|
---|
111 | if ($user['username']){
|
---|
112 |
|
---|
113 | if (!preg_match('/^([0-9]{10,11}$)$/', $user['username'])) {
|
---|
114 | $result[$index]['success'] = 0;
|
---|
115 | $result[$index]['error'] = lang('_SBG_MO_PHONENUM_WRONG_FORMAT_MSG');
|
---|
116 | $result[$index]['user'] = $user;
|
---|
117 | }else{
|
---|
118 | $result[$index] = $this->collaborator_model->processUser($user, $sentNumber);
|
---|
119 |
|
---|
120 |
|
---|
121 | }
|
---|
122 | $result[$index]['date'] = date('d-m-Y H:i:s');
|
---|
123 | }
|
---|
124 |
|
---|
125 | endforeach;
|
---|
126 | }
|
---|
127 |
|
---|
128 | return $result;
|
---|
129 | }
|
---|
130 | } |
---|