Emaildata.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Emaildata extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_shop','shop');
  7. $this->load->_model('Model_emaildata','emaildata');
  8. }
  9. //定义方法的调用规则 获取URI第二段值
  10. public function _remap($arg,$arg_array)
  11. {
  12. if($arg == 'add')//添加
  13. {
  14. $this->_add();
  15. }
  16. else if($arg == 'edit')//修改
  17. {
  18. $this->_edit($arg_array);
  19. }
  20. else if($arg == 'del')//修改
  21. {
  22. $this->_del();
  23. }
  24. else
  25. {
  26. $this->_index();
  27. }
  28. }
  29. //管理
  30. public function _index()
  31. {
  32. if(isset($_SESSION['api']))
  33. {
  34. $user = $this->user->get_api($_SESSION['api']);
  35. $usp = $user;
  36. $fgshop = "";$sid = "";
  37. $usersp = explode('|',trim($user['shop'],'|'));
  38. foreach ($usersp as $value)
  39. {
  40. $fgshop .= " shop = ".$value." or";
  41. $sid .= " id = ".$value." or";
  42. }
  43. }
  44. $post = $this->input->post(NULL, TRUE);
  45. if(isset($post['page']))
  46. {
  47. $page = $this->input->post('page',true);
  48. $perpage = $this->input->post('perpage',true);
  49. $shop = $this->input->post('shop',true);
  50. $where = "1=1 and (".rtrim($fgshop,'or').")";
  51. if($shop)
  52. {
  53. $where .= " and shop = '$shop'";
  54. }
  55. //数据排序
  56. $order_str = "id desc";
  57. if(empty($page))
  58. {
  59. $start = 0;
  60. $perpage = 1;
  61. }
  62. else
  63. {
  64. $start = ($page - 1)*$perpage;
  65. }
  66. //取得信息列表
  67. $info_list = $this->emaildata->find_all($where,'id,shop,smtp_user,smtp_pass,smtp_host,smtp_port,protocol,smtp_crypto',$order_str,$start,$perpage);
  68. //格式化数据
  69. foreach ($info_list as $key=>$value)
  70. {
  71. $shop = $this->shop->read($value['shop']);
  72. $info_list[$key]['shop'] = $shop['shopname'];
  73. }
  74. $total = $this->emaildata->find_count($where);
  75. $pagenum = ceil($total/$perpage);
  76. $over = $total-($start+$perpage);
  77. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  78. echo json_encode($rows);exit;
  79. }
  80. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  81. $this->data['wlshop'] = $wlshop;
  82. $this->_Template('emaildata',$this->data);
  83. }
  84. //添加
  85. public function _add()
  86. {
  87. if(isset($_SESSION['api']))
  88. {
  89. $user = $this->user->get_api($_SESSION['api']);
  90. $usp = $user;
  91. $fgshop = "";$sid = "";
  92. $usersp = explode('|',trim($user['shop'],'|'));
  93. foreach ($usersp as $value)
  94. {
  95. $fgshop .= " shop = ".$value." or";
  96. $sid .= " id = ".$value." or";
  97. }
  98. }
  99. $post = $this->input->post(NULL, TRUE);
  100. if(isset($post['shop']))
  101. {
  102. $post['time'] = time();
  103. if($this->emaildata->insert($post))
  104. {
  105. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  106. }
  107. else
  108. {
  109. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  110. }
  111. }
  112. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  113. $this->data['wlshop'] = $wlshop;
  114. $this->_Template('emaildata_add',$this->data);
  115. }
  116. //修改
  117. public function _edit($arg_array)
  118. {
  119. if(isset($_SESSION['api']))
  120. {
  121. $user = $this->user->get_api($_SESSION['api']);
  122. $usp = $user;
  123. $fgshop = "";$sid = "";
  124. $usersp = explode('|',trim($user['shop'],'|'));
  125. foreach ($usersp as $value)
  126. {
  127. $fgshop .= " shop = ".$value." or";
  128. $sid .= " id = ".$value." or";
  129. }
  130. }
  131. $post = $this->input->post(NULL, TRUE);
  132. $id = $this->input->post('id', TRUE);
  133. if(isset($post['id']))
  134. {
  135. if($this->emaildata->save($post,$id))
  136. {
  137. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  138. }
  139. else
  140. {
  141. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  142. }
  143. }
  144. $arg_array = $arg_array[0];
  145. $email = $this->emaildata->read($arg_array);
  146. $this->data['emaildata'] = $email;
  147. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  148. $this->data['wlshop'] = $wlshop;
  149. $this->_Template('emaildata_edit',$this->data);
  150. }
  151. //删除
  152. public function _del()
  153. {
  154. $post = $this->input->post(NULL, TRUE);
  155. if(isset($post['s']))
  156. {
  157. $id_arr = $this->input->post('s');
  158. $id_arr = explode(',',$id_arr);
  159. if(!$id_arr)
  160. {
  161. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  162. }
  163. //循环删除记录
  164. foreach ($id_arr as $v)
  165. {
  166. $this->emaildata->remove($v);
  167. }
  168. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  169. }
  170. }
  171. }