FaqAction.class.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class FaqAction extends CommonAction
  10. {
  11. public function index()
  12. {
  13. if (strim($_REQUEST['question']) != '') {//name
  14. $map['question'] = array('like', '%' . strim($_REQUEST['question']) . '%');
  15. }
  16. if (strim($_REQUEST['group']) != '') {
  17. $map['group'] = strim($_REQUEST['group']);
  18. }
  19. if (method_exists($this, '_filter')) {
  20. $this->_filter($map);
  21. }
  22. $name = $this->getActionName();
  23. $model = D($name);
  24. if (!empty ($model)) {
  25. $this->_list($model, $map);
  26. }
  27. $list = $this->get("list");
  28. $group = $GLOBALS['db']->getAll("select distinct(`group`) from " . DB_PREFIX . "faq");
  29. $this->assign("group", $group);
  30. $this->display();
  31. }
  32. public function add()
  33. {
  34. $group = $GLOBALS['db']->getAll("select distinct(`group`) from " . DB_PREFIX . "faq");
  35. $this->assign("group", $group);
  36. $this->assign("new_sort", M("Faq")->max("sort") + 1);
  37. $this->display();
  38. }
  39. public function edit()
  40. {
  41. $id = intval($_REQUEST ['id']);
  42. $condition['id'] = $id;
  43. $vo = M(MODULE_NAME)->where($condition)->find();
  44. $this->assign('vo', $vo);
  45. $group = $GLOBALS['db']->getAll("select distinct(`group`) from " . DB_PREFIX . "faq");
  46. $this->assign("group", $group);
  47. $this->display();
  48. }
  49. public function foreverdelete()
  50. {
  51. //彻底删除指定记录
  52. $ajax = intval($_REQUEST['ajax']);
  53. $id = $_REQUEST ['id'];
  54. if (isset ($id)) {
  55. $condition = array('id' => array('in', explode(',', $id)));
  56. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  57. foreach ($rel_data as $data) {
  58. $info[] = $data['question'];
  59. }
  60. if ($info) $info = implode(",", $info);
  61. $list = M(MODULE_NAME)->where($condition)->delete();
  62. if ($list !== false) {
  63. save_log($info . l("FOREVER_DELETE_SUCCESS"), 1);
  64. $this->success(l("FOREVER_DELETE_SUCCESS"), $ajax);
  65. } else {
  66. save_log($info . l("FOREVER_DELETE_FAILED"), 0);
  67. $this->error(l("FOREVER_DELETE_FAILED"), $ajax);
  68. }
  69. } else {
  70. $this->error(l("INVALID_OPERATION"), $ajax);
  71. }
  72. }
  73. public function insert()
  74. {
  75. B('FilterString');
  76. $ajax = intval($_REQUEST['ajax']);
  77. $data = M(MODULE_NAME)->create();
  78. //开始验证有效性
  79. $this->assign("jumpUrl", u(MODULE_NAME . "/add"));
  80. if (!check_empty($data['group'])) {
  81. if (!check_empty($_REQUEST['define_group'])) {
  82. $this->error("请输入分组");
  83. } else {
  84. $data['group'] = strim($_REQUEST['define_group']);
  85. }
  86. }
  87. if (!check_empty($data['question'])) {
  88. $this->error("请输入问题");
  89. }
  90. if (!check_empty($data['answer'])) {
  91. $this->error("请输入答案");
  92. }
  93. // 更新数据
  94. $log_info = $data['question'];
  95. $list = M(MODULE_NAME)->add($data);
  96. if (false !== $list) {
  97. //成功提示
  98. save_log($log_info . L("INSERT_SUCCESS"), 1);
  99. $this->success(L("INSERT_SUCCESS"));
  100. } else {
  101. //错误提示
  102. save_log($log_info . L("INSERT_FAILED"), 0);
  103. $this->error(L("INSERT_FAILED"));
  104. }
  105. }
  106. public function update()
  107. {
  108. B('FilterString');
  109. $data = M(MODULE_NAME)->create();
  110. $log_info = M(MODULE_NAME)->where("id=" . intval($data['id']))->getField("question");
  111. //开始验证有效性
  112. $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id'])));
  113. if (!check_empty($data['group'])) {
  114. if (!check_empty($_REQUEST['define_group'])) {
  115. $this->error("请输入分组");
  116. } else {
  117. $data['group'] = strim($_REQUEST['define_group']);
  118. }
  119. }
  120. if (!check_empty($data['question'])) {
  121. $this->error("请输入问题");
  122. }
  123. if (!check_empty($data['answer'])) {
  124. $this->error("请输入答案");
  125. }
  126. $list = M(MODULE_NAME)->save($data);
  127. if (false !== $list) {
  128. //成功提示
  129. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  130. $this->success(L("UPDATE_SUCCESS"));
  131. } else {
  132. //错误提示
  133. save_log($log_info . L("UPDATE_FAILED"), 0);
  134. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  135. }
  136. }
  137. public function set_sort()
  138. {
  139. $id = intval($_REQUEST['id']);
  140. $sort = intval($_REQUEST['sort']);
  141. $log_info = M("Faq")->where("id=" . $id)->getField("question");
  142. if (!check_sort($sort)) {
  143. $this->error(l("SORT_FAILED"), 1);
  144. }
  145. M("Faq")->where("id=" . $id)->setField("sort", $sort);
  146. save_log($log_info . l("SORT_SUCCESS"), 1);
  147. $this->success(l("SORT_SUCCESS"), 1);
  148. }
  149. public function set_effect()
  150. {
  151. $faq_id = intval($_REQUEST['id']);
  152. $ajax = intval($_REQUEST['ajax']);
  153. $info = M(MODULE_NAME)->where("id=" . $faq_id)->getField("question");
  154. $c_is_effect = M("Faq")->where("id=" . $faq_id)->getField("is_effect");//当前状态
  155. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  156. M("Faq")->where("id=" . $faq_id)->setField("is_effect", $n_is_effect);
  157. save_log($info . l("SET_EFFECT_" . $n_is_effect), 1);
  158. clear_auto_cache("get_help_cache");
  159. clear_auto_cache("article_notice");
  160. $this->ajaxReturn($n_is_effect, l("SET_EFFECT_" . $n_is_effect), 1);
  161. }
  162. public function set_show()
  163. {
  164. $faq_id = intval($_REQUEST['id']);
  165. $ajax = intval($_REQUEST['ajax']);
  166. $info = M(MODULE_NAME)->where("id=" . $faq_id)->getField("question");
  167. $o_is_show = M("Faq")->where("id=" . $faq_id)->getField("is_show");//当前状态
  168. $n_is_show = $o_is_show == 0 ? 1 : 0; //需设置的状态
  169. M("Faq")->where("id=" . $faq_id)->setField("is_show", $n_is_show);
  170. save_log($info . l("SET_SHOW_" . $n_is_show), 1);
  171. clear_auto_cache("get_help_cache");
  172. clear_auto_cache("article_notice");
  173. $this->ajaxReturn($n_is_show, l("SET_SHOW_" . $n_is_show), 1);
  174. }
  175. }
  176. ?>