[405] | 1 | <?php |
---|
| 2 | |
---|
| 3 | if (!defined('BASEPATH')) |
---|
| 4 | exit('No direct script access allowed'); |
---|
| 5 | |
---|
| 6 | class Smstemplate extends MX_Controller { |
---|
| 7 | |
---|
| 8 | public function __construct() { |
---|
| 9 | parent::__construct(); |
---|
| 10 | $this->load->helper('cookie'); |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | public function index() { |
---|
| 14 | $data = array(); |
---|
| 15 | $admin_info = $this->session->userdata('adminInfo'); |
---|
[590] | 16 | $role_id = $admin_info['role_id']; |
---|
[405] | 17 | if ($admin_info) { |
---|
[590] | 18 | if($role_id == 1){ |
---|
| 19 | $data['content'] = $this->getSmstemplates(); |
---|
| 20 | $this->load->view('smstemplate/index', $data); |
---|
| 21 | }else |
---|
| 22 | { |
---|
| 23 | show_404(); |
---|
| 24 | } |
---|
[405] | 25 | } else { |
---|
| 26 | $this->load->view('login'); |
---|
| 27 | } |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | public function getSmstemplates($filters = array()) { |
---|
| 31 | $this->load->helper('pagging'); |
---|
| 32 | $this->load->model('Smstemplate_model'); |
---|
| 33 | $data['current_page'] = $this->uri->segment(4, 1); |
---|
| 34 | $data['itemsoptions'] = array(10, 25, 50, 100); |
---|
| 35 | $data['perpage'] = 10; |
---|
| 36 | $data['keyword'] = ""; |
---|
| 37 | $data['sorting_order']="sorting_desc"; |
---|
| 38 | $data['sorting_field']="sms_id"; |
---|
| 39 | |
---|
| 40 | if ($this->input->post('sorting_order')) { |
---|
| 41 | if ($this->input->post('sorting_order') != "sorting") |
---|
| 42 | { |
---|
| 43 | $data['sorting_order']=$this->input->post('sorting_order'); |
---|
| 44 | $data['sorting_field']=$this->input->post('sorting_field'); |
---|
| 45 | } |
---|
| 46 | } |
---|
| 47 | if ($this->input->post('items')) { |
---|
| 48 | $data['perpage'] = $this->input->post('items'); |
---|
| 49 | } |
---|
| 50 | if ($this->input->post('keyword')) { |
---|
| 51 | $data['search_field']=""; |
---|
| 52 | $data['keyword'] = $this->input->post('keyword'); |
---|
| 53 | |
---|
| 54 | if (preg_match("/[0-9]/", $data['keyword'])) |
---|
| 55 | { |
---|
| 56 | $data['search_field']="cellphone"; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | $data['start'] = ($data['current_page'] - 1) * $data['perpage']; |
---|
| 62 | $data['total'] = $this->Smstemplate_model->countSmstemplate($data); |
---|
| 63 | |
---|
| 64 | $data['smstemplates'] = $this->Smstemplate_model->getSmstemplates($data); |
---|
| 65 | |
---|
| 66 | $data['paging_url'] = base_url() . "/admin/mau_tin_nhan/trang/"; |
---|
| 67 | $data['num_links'] = 2; |
---|
| 68 | $data['paging'] = pagging($data); |
---|
| 69 | |
---|
| 70 | if ($this->input->is_ajax_request()) { |
---|
| 71 | return $this->load->view('smstemplate/listview', $data); |
---|
| 72 | } |
---|
| 73 | return $this->load->view('smstemplate/listview', $data, true); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | public function addSmstemplate() { |
---|
| 77 | $result['success'] = 0; |
---|
| 78 | $result = array(); |
---|
| 79 | $input = $this->input->post(); |
---|
| 80 | $this->load->model('Smstemplate_model'); |
---|
[411] | 81 | if (strlen($input['sms_content'])==0) |
---|
[405] | 82 | { |
---|
[576] | 83 | $result['errors'][]=array("content"=>"Ná»i dung tin nhắn khÃŽng ÄÆ°á»£c Äá» trá»ng","field"=>"sms_content"); |
---|
[405] | 84 | } |
---|
[411] | 85 | if (strlen($input['sms_reply'])==0) |
---|
[405] | 86 | { |
---|
[576] | 87 | $result['errors'][]=array("content"=>"Tin nhắn trả vá» khÃŽng ÄÆ°á»£c Äá» trá»ng","field"=>"sms_reply"); |
---|
[405] | 88 | } |
---|
| 89 | else |
---|
| 90 | { |
---|
[411] | 91 | /* |
---|
| 92 | if ($this->Smstemplate_model->isExist(array('field'=>'login_name','value'=>$input['login_name'],'id'=>$input['id']))) |
---|
[405] | 93 | { |
---|
| 94 | $result['errors'][]="Tên ÄÄng nháºp Äã ÄÆ°á»£c sá» dụng"; |
---|
| 95 | } |
---|
[411] | 96 | * |
---|
| 97 | */ |
---|
[405] | 98 | } |
---|
[576] | 99 | if (strlen($input['commandcode'])==0) |
---|
| 100 | { |
---|
| 101 | $result['errors'][]=array("content"=>"Command code khÃŽng ÄÆ°á»£c Äá» trá»ng","field"=>"commandcode"); |
---|
| 102 | } |
---|
[411] | 103 | if (strlen($input['service_id'])==0) |
---|
[405] | 104 | { |
---|
[576] | 105 | $result['errors'][]=array("content"=>"Service id khÃŽng ÄÆ°á»£c Äá» trá»ng","field"=>"service_id"); |
---|
[405] | 106 | } |
---|
| 107 | else |
---|
| 108 | { |
---|
[411] | 109 | /* |
---|
| 110 | if ($this->Smstemplate_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'],'id'=>$input['id']))) |
---|
[405] | 111 | { |
---|
| 112 | $result['errors'][]="Sá» Äiá»n thoại Äã ÄÆ°á»£c sá» dụng"; |
---|
| 113 | } |
---|
[411] | 114 | * |
---|
| 115 | */ |
---|
[405] | 116 | } |
---|
| 117 | if (!isset($result['errors'])) |
---|
| 118 | { |
---|
| 119 | $this->load->model('Smstemplate_model'); |
---|
| 120 | $this->Smstemplate_model->insert($input); |
---|
| 121 | $result['success'] = 1; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | echo json_encode($result); |
---|
| 126 | } |
---|
[409] | 127 | public function viewSms() |
---|
[405] | 128 | { |
---|
| 129 | $id=$this->uri->segment(4); |
---|
| 130 | $this->load->model('Smstemplate_model'); |
---|
| 131 | $data=$this->Smstemplate_model->getSmstemplate($id); |
---|
[409] | 132 | $this->load->view('smstemplate/viewSms',$data); |
---|
[405] | 133 | } |
---|
[409] | 134 | public function editSms() |
---|
[405] | 135 | { |
---|
| 136 | $id=$this->uri->segment(4); |
---|
| 137 | $this->load->model('Smstemplate_model'); |
---|
| 138 | $data=$this->Smstemplate_model->getSmstemplate($id); |
---|
[409] | 139 | $this->load->view('smstemplate/editSms',$data); |
---|
[405] | 140 | } |
---|
[409] | 141 | public function dodeleteSms() |
---|
[405] | 142 | { |
---|
| 143 | $input=$this->input->post(); |
---|
[409] | 144 | $id=$input['sms_id']; |
---|
[405] | 145 | $this->load->model('Smstemplate_model'); |
---|
| 146 | $data=$this->Smstemplate_model->delete($id); |
---|
| 147 | $result['success']=1; |
---|
| 148 | echo json_encode($result); |
---|
| 149 | } |
---|
[409] | 150 | public function deleteSms() |
---|
[405] | 151 | { |
---|
| 152 | $id=$this->uri->segment(4); |
---|
| 153 | $this->load->model('Smstemplate_model'); |
---|
| 154 | $data=$this->Smstemplate_model->getSmstemplate($id); |
---|
[409] | 155 | $this->load->view('smstemplate/deleteSms',$data); |
---|
[405] | 156 | } |
---|
[409] | 157 | public function updateSms() |
---|
[405] | 158 | { |
---|
[409] | 159 | |
---|
| 160 | $input= $this->input->post(); |
---|
[405] | 161 | $this->load->model('Smstemplate_model'); |
---|
[409] | 162 | if (strlen($input['sms_content'])==0) |
---|
[405] | 163 | { |
---|
[409] | 164 | $result['errors'][]="Ná»i dung tin nhắn khÃŽng ÄÆ°á»£c Äá» trá»ng"; |
---|
[405] | 165 | } |
---|
[409] | 166 | if (strlen($input['sms_reply'])==0) |
---|
[405] | 167 | { |
---|
[409] | 168 | $result['errors'][]="Tin nhắn trả vá» khÃŽng ÄÆ°á»£c Äá» trá»ng"; |
---|
[405] | 169 | } |
---|
| 170 | else |
---|
| 171 | { |
---|
[409] | 172 | /* |
---|
[405] | 173 | if ($this->Smstemplate_model->isExist(array('field'=>'login_name','value'=>$input['login_name'],'id'=>$input['id']))) |
---|
| 174 | { |
---|
| 175 | $result['errors'][]="Tên ÄÄng nháºp Äã ÄÆ°á»£c sá» dụng"; |
---|
| 176 | } |
---|
[409] | 177 | * |
---|
| 178 | */ |
---|
[405] | 179 | } |
---|
[409] | 180 | if (strlen($input['service_id'])==0) |
---|
[405] | 181 | { |
---|
[409] | 182 | $result['errors'][]="Mã dá»ch vụ khÃŽng ÄÆ°á»£c Äá» trá»ng"; |
---|
[405] | 183 | } |
---|
| 184 | else |
---|
| 185 | { |
---|
[409] | 186 | /* |
---|
[405] | 187 | if ($this->Smstemplate_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'],'id'=>$input['id']))) |
---|
| 188 | { |
---|
| 189 | $result['errors'][]="Sá» Äiá»n thoại Äã ÄÆ°á»£c sá» dụng"; |
---|
| 190 | } |
---|
[409] | 191 | * |
---|
| 192 | */ |
---|
[405] | 193 | } |
---|
[409] | 194 | |
---|
[405] | 195 | if (!isset($result['errors'])) |
---|
[409] | 196 | { |
---|
[405] | 197 | $this->load->model('Smstemplate_model'); |
---|
[409] | 198 | $this->Smstemplate_model->update($input['sms_id'],$input); |
---|
[405] | 199 | $result['success'] = 1; |
---|
| 200 | } |
---|
| 201 | echo json_encode($result); |
---|
| 202 | } |
---|
| 203 | public function test() { |
---|
| 204 | |
---|
| 205 | |
---|
| 206 | for ($i = 1; $i <= 50; $i++) { |
---|
| 207 | $input['sms_content']="Chuc mung {full_name} da dang ky thanh cong".$i; |
---|
| 208 | $input['sms_reply']="sms reply".$i; |
---|
| 209 | $input['service_id']=$i; |
---|
| 210 | $input['commandcode']="commandcode".$i; |
---|
| 211 | $this->load->model('Smstemplate_model'); |
---|
| 212 | $this->Smstemplate_model->insert($input); |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | } |
---|