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

Last change on this file since 576 was 576, checked in by quyenla, 10 years ago
File size: 6.9 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'][]=array("content"=>"Nội dung tin nhắn khÃŽng được để trống","field"=>"sms_content");
78        }
79        if (strlen($input['sms_reply'])==0)
80        {
81            $result['errors'][]=array("content"=>"Tin nhắn trả về khÃŽng được để trống","field"=>"sms_reply");
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['commandcode'])==0)
94        {
95            $result['errors'][]=array("content"=>"Command code khÃŽng được để trống","field"=>"commandcode");
96        }
97        if (strlen($input['service_id'])==0)
98        {
99            $result['errors'][]=array("content"=>"Service id khÃŽng được để trống","field"=>"service_id");
100        }
101        else
102        {
103            /*
104            if ($this->Smstemplate_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'],'id'=>$input['id'])))
105            {
106                $result['errors'][]="Số điện thoại đã được sá»­ dụng";
107            }
108             *
109             */
110        }
111        if (!isset($result['errors']))
112        {
113            $this->load->model('Smstemplate_model');
114            $this->Smstemplate_model->insert($input);
115            $result['success'] = 1;
116        }
117
118       
119        echo json_encode($result);
120    }
121    public function viewSms()
122    {
123        $id=$this->uri->segment(4);
124        $this->load->model('Smstemplate_model');
125        $data=$this->Smstemplate_model->getSmstemplate($id);
126        $this->load->view('smstemplate/viewSms',$data);
127    }
128    public function editSms()
129    {
130        $id=$this->uri->segment(4);
131        $this->load->model('Smstemplate_model');
132        $data=$this->Smstemplate_model->getSmstemplate($id);
133        $this->load->view('smstemplate/editSms',$data);
134    }
135    public function dodeleteSms()
136    {
137        $input=$this->input->post();
138        $id=$input['sms_id'];
139        $this->load->model('Smstemplate_model');
140        $data=$this->Smstemplate_model->delete($id);
141        $result['success']=1;
142        echo json_encode($result);
143    }
144    public function deleteSms()
145    {
146        $id=$this->uri->segment(4);
147        $this->load->model('Smstemplate_model');
148        $data=$this->Smstemplate_model->getSmstemplate($id);
149        $this->load->view('smstemplate/deleteSms',$data);
150    }
151    public function updateSms()
152    {
153       
154        $input=  $this->input->post();
155        $this->load->model('Smstemplate_model');
156        if (strlen($input['sms_content'])==0)
157        {
158            $result['errors'][]="Nội dung tin nhắn khÃŽng được để trống";
159        }
160        if (strlen($input['sms_reply'])==0)
161        {
162            $result['errors'][]="Tin nhắn trả về khÃŽng được để trống";
163        }
164        else
165        {
166            /*
167            if ($this->Smstemplate_model->isExist(array('field'=>'login_name','value'=>$input['login_name'],'id'=>$input['id'])))
168            {
169                $result['errors'][]="Tên đăng nhập đã được sá»­ dụng";
170            }
171             *
172             */
173        }
174        if (strlen($input['service_id'])==0)
175        {
176            $result['errors'][]="Mã dịch vụ khÃŽng được để trống";
177        }
178        else
179        {
180            /*
181            if ($this->Smstemplate_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'],'id'=>$input['id'])))
182            {
183                $result['errors'][]="Số điện thoại đã được sá»­ dụng";
184            }
185             *
186             */
187        }
188       
189        if (!isset($result['errors']))
190        {
191            $this->load->model('Smstemplate_model');
192            $this->Smstemplate_model->update($input['sms_id'],$input);
193            $result['success'] = 1;
194        }
195        echo json_encode($result);
196    }
197    public function test() {
198       
199       
200        for ($i = 1; $i <= 50; $i++) {
201            $input['sms_content']="Chuc mung {full_name} da dang ky thanh cong".$i;
202            $input['sms_reply']="sms reply".$i;
203            $input['service_id']=$i;
204            $input['commandcode']="commandcode".$i;
205            $this->load->model('Smstemplate_model');
206            $this->Smstemplate_model->insert($input);
207        }
208    }
209
210}
Note: See TracBrowser for help on using the repository browser.