ArticleAction.class.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维p2p借贷系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class ArticleAction extends CommonAction{
  10. public function index()
  11. {
  12. if(trim($_REQUEST['title'])!='')
  13. {
  14. $map['title'] = array('like','%'.trim($_REQUEST['title']).'%');
  15. }
  16. if(intval($_REQUEST['cate_id'])>0)
  17. {
  18. $map['cate_id'] = intval($_REQUEST['cate_id']);
  19. }
  20. $map['is_delete'] = 0;
  21. $cate_list = M("ArticleCate")->where("is_delete = 0")->findAll();
  22. $this->assign("cate_list",$cate_list);
  23. if (method_exists ( $this, '_filter' )) {
  24. $this->_filter ( $map );
  25. }
  26. $name=$this->getActionName();
  27. $model = D ($name);
  28. if (! empty ( $model )) {
  29. $this->_list ( $model, $map );
  30. }
  31. $this->display ();
  32. }
  33. public function add()
  34. {
  35. $cate_tree = M("ArticleCate")->where('is_delete = 0')->findAll();
  36. //$cate_tree = D("ArticleCate")->toFormatTree($cate_tree);
  37. $this->assign("cate_tree",$cate_tree);
  38. $this->assign("new_sort", M("Article")->where("is_delete=0")->max("sort")+1);
  39. $this->display();
  40. }
  41. public function edit() {
  42. $id = intval($_REQUEST ['id']);
  43. $condition['is_delete'] = 0;
  44. $condition['id'] = $id;
  45. $vo = M(MODULE_NAME)->where($condition)->find();
  46. $this->assign ( 'vo', $vo );
  47. $cate_tree = M("ArticleCate")->where('is_delete = 0')->findAll();
  48. //$cate_tree = D("ArticleCate")->toFormatTree($cate_tree);
  49. $this->assign("cate_tree",$cate_tree);
  50. $this->display ();
  51. }
  52. public function delete() {
  53. //删除指定记录
  54. $ajax = intval($_REQUEST['ajax']);
  55. $id = $_REQUEST ['id'];
  56. if (isset ( $id )) {
  57. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  58. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  59. foreach($rel_data as $data)
  60. {
  61. $info[] = $data['title'];
  62. }
  63. if($info) $info = implode(",",$info);
  64. $list = M(MODULE_NAME)->where ( $condition )->setField ( 'is_delete', 1 );
  65. if ($list!==false) {
  66. save_log($info.l("DELETE_SUCCESS"),1);
  67. clear_auto_cache("get_help_cache");
  68. clear_auto_cache("article_notice");
  69. $result['status'] = 1;
  70. $result['info'] = '删除成功';
  71. } else {
  72. save_log($info.l("DELETE_FAILED"),0);
  73. $result['status'] = 0;
  74. $result['info'] = '删除失败';
  75. }
  76. } else {
  77. $result['status'] = 0;
  78. $result['info'] = '请选择要删除的选项';
  79. }
  80. admin_ajax_return($result);
  81. }
  82. public function restore() {
  83. //删除指定记录
  84. $ajax = intval($_REQUEST['ajax']);
  85. $id = $_REQUEST ['id'];
  86. if (isset ( $id )) {
  87. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  88. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  89. foreach($rel_data as $data)
  90. {
  91. $info[] = $data['title'];
  92. }
  93. if($info) $info = implode(",",$info);
  94. $list = M(MODULE_NAME)->where ( $condition )->setField ( 'is_delete', 0 );
  95. if ($list!==false) {
  96. save_log($info.l("RESTORE_SUCCESS"),1);
  97. clear_auto_cache("get_help_cache");
  98. clear_auto_cache("article_notice");
  99. $this->success (l("RESTORE_SUCCESS"),$ajax);
  100. } else {
  101. save_log($info.l("RESTORE_FAILED"),0);
  102. $this->error (l("RESTORE_FAILED"),$ajax);
  103. }
  104. } else {
  105. $this->error (l("INVALID_OPERATION"),$ajax);
  106. }
  107. }
  108. public function foreverdelete() {
  109. //彻底删除指定记录
  110. $ajax = intval($_REQUEST['ajax']);
  111. $id = $_REQUEST ['id'];
  112. if (isset ( $id )) {
  113. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  114. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  115. foreach($rel_data as $data)
  116. {
  117. $info[] = $data['title'];
  118. }
  119. if($info) $info = implode(",",$info);
  120. $list = M(MODULE_NAME)->where ( $condition )->delete();
  121. //删除相关预览图
  122. // foreach($rel_data as $data)
  123. // {
  124. // @unlink(get_real_path().$data['preview']);
  125. // }
  126. if ($list!==false) {
  127. save_log($info.l("FOREVER_DELETE_SUCCESS"),1);
  128. clear_auto_cache("get_help_cache");
  129. clear_auto_cache("article_notice");
  130. $this->success (l("FOREVER_DELETE_SUCCESS"),$ajax);
  131. } else {
  132. save_log($info.l("FOREVER_DELETE_FAILED"),0);
  133. $this->error (l("FOREVER_DELETE_FAILED"),$ajax);
  134. }
  135. } else {
  136. $this->error (l("INVALID_OPERATION"),$ajax);
  137. }
  138. }
  139. public function insert() {
  140. B('FilterString');
  141. $ajax = intval($_REQUEST['ajax']);
  142. $data = M(MODULE_NAME)->create();
  143. //开始验证有效性
  144. $this->assign("jumpUrl",u(MODULE_NAME."/add"));
  145. if(!check_empty($data['title']))
  146. {
  147. $this->error(L("ARTICLE_TITLE_EMPTY_TIP"));
  148. }
  149. if(!check_empty($data['content'])&&$data['rel_url']=='')
  150. {
  151. $this->error(L("ARTICLE_CONTENT_EMPTY_TIP"));
  152. }
  153. if($data['cate_id']==0)
  154. {
  155. $this->error(L("ARTICLE_CATE_EMPTY_TIP"));
  156. }
  157. // 更新数据
  158. $log_info = $data['title'];
  159. $data['create_time'] = get_gmtime();
  160. $data['update_time'] = get_gmtime();
  161. $list=M(MODULE_NAME)->add($data);
  162. if (false !== $list) {
  163. //成功提示
  164. save_log($log_info.L("INSERT_SUCCESS"),1);
  165. clear_auto_cache("get_help_cache");
  166. clear_auto_cache("article_notice");
  167. $this->success(L("INSERT_SUCCESS"));
  168. } else {
  169. //错误提示
  170. save_log($log_info.L("INSERT_FAILED"),0);
  171. $this->error(L("INSERT_FAILED"));
  172. }
  173. }
  174. public function update() {
  175. B('FilterString');
  176. $data = M(MODULE_NAME)->create ();
  177. // if($_FILES['preview']['name']!='')
  178. // {
  179. // $result = $this->uploadImage();
  180. // if($result['status']==0)
  181. // {
  182. // $this->error($result['info'],$ajax);
  183. // }
  184. // //删除图片
  185. // @unlink(get_real_path().M("Article")->where("id=".$data['id'])->getField("preview"));
  186. // $data['preview'] = $result['data'][0]['bigrecpath'].$result['data'][0]['savename'];
  187. // }
  188. $log_info = M(MODULE_NAME)->where("id=".intval($data['id']))->getField("title");
  189. //开始验证有效性
  190. $this->assign("jumpUrl",u(MODULE_NAME."/edit",array("id"=>$data['id'])));
  191. if(!check_empty($data['title']))
  192. {
  193. $this->error(L("ARTICLE_TITLE_EMPTY_TIP"));
  194. }
  195. if(!check_empty($data['content'])&&$data['rel_url']=='')
  196. {
  197. $this->error(L("ARTICLE_CONTENT_EMPTY_TIP"));
  198. }
  199. if($data['cate_id']==0)
  200. {
  201. $this->error(L("ARTICLE_CATE_EMPTY_TIP"));
  202. }
  203. // 更新数据
  204. $data['update_time'] = get_gmtime();
  205. $list=M(MODULE_NAME)->save ($data);
  206. if (false !== $list) {
  207. //成功提示
  208. save_log($log_info.L("UPDATE_SUCCESS"),1);
  209. clear_auto_cache("get_help_cache");
  210. clear_auto_cache("article_notice");
  211. if(strim($data['title'])=='主播协议'){
  212. clear_auto_cache("article_agreement");
  213. }
  214. if(strim($data['title'])=='用户隐私政策'){
  215. clear_auto_cache("article_privacy");
  216. }
  217. $this->success(L("UPDATE_SUCCESS"));
  218. } else {
  219. //错误提示
  220. save_log($log_info.L("UPDATE_FAILED"),0);
  221. $this->error(L("UPDATE_FAILED"),0,$log_info.L("UPDATE_FAILED"));
  222. }
  223. }
  224. public function set_sort()
  225. {
  226. $id = intval($_REQUEST['id']);
  227. $sort = intval($_REQUEST['sort']);
  228. $log_info = M("Article")->where("id=".$id)->getField("title");
  229. if(!check_sort($sort))
  230. {
  231. $this->error(l("SORT_FAILED"),1);
  232. }
  233. M("Article")->where("id=".$id)->setField("sort",$sort);
  234. save_log($log_info.l("SORT_SUCCESS"),1);
  235. clear_auto_cache("get_help_cache");
  236. clear_auto_cache("article_notice");
  237. $this->success(l("SORT_SUCCESS"),1);
  238. }
  239. public function set_effect()
  240. {
  241. $id = intval($_REQUEST['id']);
  242. $ajax = intval($_REQUEST['ajax']);
  243. $info = M(MODULE_NAME)->where("id=".$id)->getField("title");
  244. $c_is_effect = M(MODULE_NAME)->where("id=".$id)->getField("is_effect"); //当前状态
  245. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  246. M(MODULE_NAME)->where("id=".$id)->setField("is_effect",$n_is_effect);
  247. save_log($info.l("SET_EFFECT_".$n_is_effect),1);
  248. clear_auto_cache("get_help_cache");
  249. clear_auto_cache("article_notice");
  250. $this->ajaxReturn($n_is_effect,l("SET_EFFECT_".$n_is_effect),1) ;
  251. }
  252. }
  253. ?>