source: pro-violet-viettel/sourcecode/application/modules/admin/controllers/smstemplate.php @ 757

Last change on this file since 757 was 590, checked in by namnd, 10 years ago
File size: 7.0 KB
Line 
1<?php
2
3if (!defined('BASEPATH'))
4    exit('No direct script access allowed');
5
6class 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');
16                $role_id = $admin_info['role_id'];
17        if ($admin_info) {
18                        if($role_id == 1){
19                                $data['content'] = $this->getSmstemplates();
20                                $this->load->view('smstemplate/index', $data);
21                        }else
22                        {
23                                show_404();
24                        }
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');
81        if (strlen($input['sms_content'])==0)
82        {
83            $result['errors'][]=array("content"=>"Nội dung tin nhắn khÃŽng được để trống","field"=>"sms_content");
84        }
85        if (strlen($input['sms_reply'])==0)
86        {
87            $result['errors'][]=array("content"=>"Tin nhắn trả về khÃŽng được để trống","field"=>"sms_reply");
88        }
89        else
90        {
91            /*
92            if ($this->Smstemplate_model->isExist(array('field'=>'login_name','value'=>$input['login_name'],'id'=>$input['id'])))
93            {
94                $result['errors'][]="Tên đăng nhập đã được sá»­ dụng";
95            }
96             *
97             */
98        }
99        if (strlen($input['commandcode'])==0)
100        {
101            $result['errors'][]=array("content"=>"Command code khÃŽng được để trống","field"=>"commandcode");
102        }
103        if (strlen($input['service_id'])==0)
104        {
105            $result['errors'][]=array("content"=>"Service id khÃŽng được để trống","field"=>"service_id");
106        }
107        else
108        {
109            /*
110            if ($this->Smstemplate_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'],'id'=>$input['id'])))
111            {
112                $result['errors'][]="Số điện thoại đã được sá»­ dụng";
113            }
114             *
115             */
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    }
127    public function viewSms()
128    {
129        $id=$this->uri->segment(4);
130        $this->load->model('Smstemplate_model');
131        $data=$this->Smstemplate_model->getSmstemplate($id);
132        $this->load->view('smstemplate/viewSms',$data);
133    }
134    public function editSms()
135    {
136        $id=$this->uri->segment(4);
137        $this->load->model('Smstemplate_model');
138        $data=$this->Smstemplate_model->getSmstemplate($id);
139        $this->load->view('smstemplate/editSms',$data);
140    }
141    public function dodeleteSms()
142    {
143        $input=$this->input->post();
144        $id=$input['sms_id'];
145        $this->load->model('Smstemplate_model');
146        $data=$this->Smstemplate_model->delete($id);
147        $result['success']=1;
148        echo json_encode($result);
149    }
150    public function deleteSms()
151    {
152        $id=$this->uri->segment(4);
153        $this->load->model('Smstemplate_model');
154        $data=$this->Smstemplate_model->getSmstemplate($id);
155        $this->load->view('smstemplate/deleteSms',$data);
156    }
157    public function updateSms()
158    {
159       
160        $input=  $this->input->post();
161        $this->load->model('Smstemplate_model');
162        if (strlen($input['sms_content'])==0)
163        {
164            $result['errors'][]="Nội dung tin nhắn khÃŽng được để trống";
165        }
166        if (strlen($input['sms_reply'])==0)
167        {
168            $result['errors'][]="Tin nhắn trả về khÃŽng được để trống";
169        }
170        else
171        {
172            /*
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            }
177             *
178             */
179        }
180        if (strlen($input['service_id'])==0)
181        {
182            $result['errors'][]="Mã dịch vụ khÃŽng được để trống";
183        }
184        else
185        {
186            /*
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            }
191             *
192             */
193        }
194       
195        if (!isset($result['errors']))
196        {
197            $this->load->model('Smstemplate_model');
198            $this->Smstemplate_model->update($input['sms_id'],$input);
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}
Note: See TracBrowser for help on using the repository browser.