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

Last change on this file since 422 was 411, checked in by quyenla, 11 years ago

sms template

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