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
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        {
[576]77            $result['errors'][]=array("content"=>"Nội dung tin nhắn khÃŽng được để trống","field"=>"sms_content");
[405]78        }
[411]79        if (strlen($input['sms_reply'])==0)
[405]80        {
[576]81            $result['errors'][]=array("content"=>"Tin nhắn trả về khÃŽng được để trống","field"=>"sms_reply");
[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        }
[576]93        if (strlen($input['commandcode'])==0)
94        {
95            $result['errors'][]=array("content"=>"Command code khÃŽng được để trống","field"=>"commandcode");
96        }
[411]97        if (strlen($input['service_id'])==0)
[405]98        {
[576]99            $result['errors'][]=array("content"=>"Service id khÃŽng được để trống","field"=>"service_id");
[405]100        }
101        else
102        {
[411]103            /*
104            if ($this->Smstemplate_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'],'id'=>$input['id'])))
[405]105            {
106                $result['errors'][]="Số điện thoại đã được sá»­ dụng";
107            }
[411]108             *
109             */
[405]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    }
[409]121    public function viewSms()
[405]122    {
123        $id=$this->uri->segment(4);
124        $this->load->model('Smstemplate_model');
125        $data=$this->Smstemplate_model->getSmstemplate($id);
[409]126        $this->load->view('smstemplate/viewSms',$data);
[405]127    }
[409]128    public function editSms()
[405]129    {
130        $id=$this->uri->segment(4);
131        $this->load->model('Smstemplate_model');
132        $data=$this->Smstemplate_model->getSmstemplate($id);
[409]133        $this->load->view('smstemplate/editSms',$data);
[405]134    }
[409]135    public function dodeleteSms()
[405]136    {
137        $input=$this->input->post();
[409]138        $id=$input['sms_id'];
[405]139        $this->load->model('Smstemplate_model');
140        $data=$this->Smstemplate_model->delete($id);
141        $result['success']=1;
142        echo json_encode($result);
143    }
[409]144    public function deleteSms()
[405]145    {
146        $id=$this->uri->segment(4);
147        $this->load->model('Smstemplate_model');
148        $data=$this->Smstemplate_model->getSmstemplate($id);
[409]149        $this->load->view('smstemplate/deleteSms',$data);
[405]150    }
[409]151    public function updateSms()
[405]152    {
[409]153       
154        $input=  $this->input->post();
[405]155        $this->load->model('Smstemplate_model');
[409]156        if (strlen($input['sms_content'])==0)
[405]157        {
[409]158            $result['errors'][]="Nội dung tin nhắn khÃŽng được để trống";
[405]159        }
[409]160        if (strlen($input['sms_reply'])==0)
[405]161        {
[409]162            $result['errors'][]="Tin nhắn trả về khÃŽng được để trống";
[405]163        }
164        else
165        {
[409]166            /*
[405]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            }
[409]171             *
172             */
[405]173        }
[409]174        if (strlen($input['service_id'])==0)
[405]175        {
[409]176            $result['errors'][]="Mã dịch vụ khÃŽng được để trống";
[405]177        }
178        else
179        {
[409]180            /*
[405]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            }
[409]185             *
186             */
[405]187        }
[409]188       
[405]189        if (!isset($result['errors']))
[409]190        {
[405]191            $this->load->model('Smstemplate_model');
[409]192            $this->Smstemplate_model->update($input['sms_id'],$input);
[405]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.