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

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

sms template

File size: 6.7 KB
RevLine 
[405]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');
[411]75        if (strlen($input['sms_content'])==0)
[405]76        {
[411]77            $result['errors'][]="Nội dung tin nhắn khÃŽng được để trống";
[405]78        }
[411]79        if (strlen($input['sms_reply'])==0)
[405]80        {
[411]81            $result['errors'][]="Tin nhắn trả về khÃŽng được để trống";
[405]82        }
83        else
84        {
[411]85            /*
86            if ($this->Smstemplate_model->isExist(array('field'=>'login_name','value'=>$input['login_name'],'id'=>$input['id'])))
[405]87            {
88                $result['errors'][]="Tên đăng nhập đã được sá»­ dụng";
89            }
[411]90             *
91             */
[405]92        }
[411]93        if (strlen($input['service_id'])==0)
[405]94        {
[411]95            $result['errors'][]="Mã dịch vụ khÃŽng được để trống";
[405]96        }
97        else
98        {
[411]99            /*
100            if ($this->Smstemplate_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'],'id'=>$input['id'])))
[405]101            {
102                $result['errors'][]="Số điện thoại đã được sá»­ dụng";
103            }
[411]104             *
105             */
[405]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    }
[409]117    public function viewSms()
[405]118    {
119        $id=$this->uri->segment(4);
120        $this->load->model('Smstemplate_model');
121        $data=$this->Smstemplate_model->getSmstemplate($id);
[409]122        $this->load->view('smstemplate/viewSms',$data);
[405]123    }
[409]124    public function editSms()
[405]125    {
126        $id=$this->uri->segment(4);
127        $this->load->model('Smstemplate_model');
128        $data=$this->Smstemplate_model->getSmstemplate($id);
[409]129        $this->load->view('smstemplate/editSms',$data);
[405]130    }
[409]131    public function dodeleteSms()
[405]132    {
133        $input=$this->input->post();
[409]134        $id=$input['sms_id'];
[405]135        $this->load->model('Smstemplate_model');
136        $data=$this->Smstemplate_model->delete($id);
137        $result['success']=1;
138        echo json_encode($result);
139    }
[409]140    public function deleteSms()
[405]141    {
142        $id=$this->uri->segment(4);
143        $this->load->model('Smstemplate_model');
144        $data=$this->Smstemplate_model->getSmstemplate($id);
[409]145        $this->load->view('smstemplate/deleteSms',$data);
[405]146    }
[409]147    public function updateSms()
[405]148    {
[409]149       
150        $input=  $this->input->post();
[405]151        $this->load->model('Smstemplate_model');
[409]152        if (strlen($input['sms_content'])==0)
[405]153        {
[409]154            $result['errors'][]="Nội dung tin nhắn khÃŽng được để trống";
[405]155        }
[409]156        if (strlen($input['sms_reply'])==0)
[405]157        {
[409]158            $result['errors'][]="Tin nhắn trả về khÃŽng được để trống";
[405]159        }
160        else
161        {
[409]162            /*
[405]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            }
[409]167             *
168             */
[405]169        }
[409]170        if (strlen($input['service_id'])==0)
[405]171        {
[409]172            $result['errors'][]="Mã dịch vụ khÃŽng được để trống";
[405]173        }
174        else
175        {
[409]176            /*
[405]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            }
[409]181             *
182             */
[405]183        }
[409]184       
[405]185        if (!isset($result['errors']))
[409]186        {
[405]187            $this->load->model('Smstemplate_model');
[409]188            $this->Smstemplate_model->update($input['sms_id'],$input);
[405]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.