article.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. namespace app\admin;
  3. class article extends Base
  4. {
  5. function initialize()
  6. {
  7. parent::initialize();
  8. $this->type_text = json_decode(IN_ARTICLE_TYPE, true);
  9. $this->group_text = json_decode(IN_ARTICLE_GROUP, true);
  10. $this->Administrator(6);
  11. $this->header();
  12. }
  13. public function __destruct()
  14. {
  15. ?> <script>
  16. $('input[name=sort]').on('input', function () {
  17. var sort = $(this).val();
  18. if (sort != $(this).attr('data-sort'))
  19. $.ajax({
  20. url: '?c=ajax&a=article_sort',
  21. data: {id: $(this).attr('data-id'), sort: sort},
  22. type: 'post',
  23. success: function (ret) {
  24. console.log(ret)
  25. }
  26. });
  27. });
  28. </script>
  29. <?php
  30. $this->footer();
  31. }
  32. function index($_var_0 = [])
  33. {
  34. $_var_1 = SafeRequest("page", "get");
  35. $this->search = SafeRequest("search", "get");
  36. $this->search && ($_var_0[] = ["name|content", "like", "%" . $this->search . "%"]);
  37. $this->type = SafeRequest("type", "get");
  38. is_numeric($this->type) && ($_var_0[] = ["type", "=", $this->type]);
  39. $this->group = SafeRequest("group", "get");
  40. $this->group && ($_var_0[] = ["group", "=", $this->group]);
  41. $_var_2 = db("article")->where($_var_0)->order("id desc")->paginate(["page" => $_var_1]);
  42. $_var_3 = $_var_2->items();
  43. $_var_4 = getRender($_var_2, $_var_1);
  44. $_var_5 = $_var_2->total();
  45. ?><div class="container"><?php
  46. $this->searchForm("可以输入名称等关键词进行搜索", "", function () {
  47. ?> <select name="type" onchange="document.btnsearch.submit();">
  48. <option value="">全部类型</option>
  49. <?php
  50. foreach ($this->type_text as $_var_6 => $_var_7) {
  51. ?> <option value="<?php echo $_var_6;?>" <?php echo is_numeric($this->type) && $this->type == $_var_6 ? "selected=\"selected\"" : "";?>>
  52. <?php echo $_var_7;?> </option>
  53. <?php
  54. }
  55. ?> </select>
  56. <select name="group" onchange="document.btnsearch.submit();">
  57. <option value="">全部分组</option>
  58. <?php
  59. foreach ($this->group_text as $_var_6 => $_var_7) {
  60. ?> <option value="<?php echo $_var_6;?>" <?php echo $this->group == $_var_6 ? "selected=\"selected\"" : "";?>>
  61. <?php echo $_var_7;?> </option>
  62. <?php
  63. }
  64. ?> </select>
  65. <?php
  66. });
  67. ?>
  68. <script type="text/javascript" src="/xinadmin/js/article.js"></script>
  69. <td>
  70. <a href="javascript:;" onclick="x_admin_show('新增文章','?c=article&amp;a=edit')"><input type="button" value="新增文章" class="layui-btn"></a>
  71. </td>
  72. <table class="tb tb2">
  73. <tr><th class="partition">文章列表</th></tr>
  74. </table>
  75. <table class="layui-table">
  76. <thead>
  77. <tr>
  78. <th>ID</th>
  79. <th>名称</th>
  80. <th>分组</th>
  81. <th>类型</th>
  82. <th>排序</th>
  83. <th>状态</th>
  84. <th>编辑操作</th>
  85. </tr>
  86. </thead>
  87. <?php
  88. if ($_var_5 == 0) {
  89. ?><tr><td colspan="2" class="td27">没有文章管理</td></tr>
  90. <?php
  91. }
  92. if ($_var_3) {
  93. foreach ($_var_3 as $_var_8) {
  94. ?><tr class="hover">
  95. <td class="td25"><?php echo $_var_8["id"];?></td>
  96. <td><a href="/index/docs/<?php echo $_var_8["id"];?>" target="_blank"><?php echo $_var_8["name"];?></a>
  97. </td>
  98. <td><?php echo $this->group_text[$_var_8["group"]];?></td>
  99. <td><?php echo $this->type_text[$_var_8["type"]];?></td>
  100. <td><input type="text" name="sort" data-id="<?php echo $_var_8["id"];?>" value="<?php echo $_var_8["sort"];?>" data-value="<?php echo $_var_8["sort"];?>" style="width: 30px;"/></td>
  101. <td>
  102. <a href="?c=article&a=change_status&id=<?php echo $_var_8["id"];?>&status=<?php echo $_var_8["status"];?>&hash=<?php echo $_COOKIE["in_adminpassword"];?>">
  103. <img src="static/admincp/image/show_<?php echo $_var_8["status"] ? "yes" : "no";?>.gif" />
  104. </a>
  105. </td>
  106. <td>
  107. <a href="javascript:;" onclick="x_admin_show('编辑','?c=article&a=edit&id=<?php echo $_var_8["id"];?>')" class="act">编辑</a>
  108. <a href="javascript:;" class="act" onclick="del(<?php echo $_var_8["id"];?>,'<?php echo $_var_8["name"];?>')">删除</a>
  109. </td></tr><?php
  110. }
  111. }
  112. ?></table></div><?php echo $_var_4;?>
  113. <script>
  114. function del(id, name) {
  115. if (confirm('确定要删除文章“' + name + '”!'))
  116. location.href = "?c=article&a=del&hash=<?php echo $_COOKIE["in_adminpassword"];?>&id=" + id
  117. }
  118. </script>
  119. <?php
  120. }
  121. function del()
  122. {
  123. if (!submitcheck("hash", -1)) {
  124. $this->ShowMessage("链接来路不明,无法提交!", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
  125. }
  126. $_var_9 = intval(SafeRequest("id", "get"));
  127. $_var_10 = db("article")->where("id", $_var_9)->delete();
  128. $this->ShowMessage("恭喜您,删除成功!", "?c=article", "infotitle2", 1000, 1);
  129. }
  130. function edit()
  131. {
  132. $_var_11 = SafeRequest("id", "get");
  133. $_var_12 = $_var_11 ? "编辑" : "新增";
  134. $_var_13 = db("article")->where("id", $_var_11)->find();
  135. ?><div class="container"><?php
  136. $this->nav3();
  137. ?><table class="tb tb2">
  138. <form action="?c=article&a=save" method="post" name="form">
  139. <input type="hidden" name="id" value="<?php echo $_var_11;?>"/>
  140. <input type="hidden" name="hash" value="<?php echo $_COOKIE["in_adminpassword"];?>" />
  141. <tr><th colspan="15" class="partition"><?php echo $_var_12;?>文章</th></tr>
  142. <tr><td colspan="2" class="td27">文章名称:</td></tr>
  143. <tr><td class="vtop rowform">
  144. <input type="text" class="txt" value="<?php echo $_var_13["name"];?>" name="name" id="name">
  145. </td>
  146. <tr><td colspan="2" class="td27">分组:</td></tr>
  147. <tr><td class="vtop rowform">
  148. <select name="group"><?php
  149. foreach ($this->group_text as $_var_14 => $_var_15) {
  150. ?><option value="<?php echo $_var_14;?>" <?php echo $_var_13["group"] == $_var_14 ? "selected" : "";?>><?php echo $_var_15;?></option><?php
  151. }
  152. ?></select>
  153. </td>
  154. </tr>
  155. <tr><td colspan="2" class="td27">类型:</td></tr>
  156. <tr><td class="vtop rowform">
  157. <select name="type"><?php
  158. foreach ($this->type_text as $_var_14 => $_var_15) {
  159. ?><option value="<?php echo $_var_14;?>" <?php echo $_var_13["type"] == $_var_14 ? "selected" : "";?>><?php echo $_var_15;?></option><?php
  160. }
  161. ?></select>
  162. </td>
  163. </tr>
  164. <tr><td colspan="2" class="td27">内容:</td></tr>
  165. <tr><td class="vtop rowform">
  166. <textarea name="content" class="tarea" style="width:800px;height:400px;"><?php echo $_var_13["content"];?></textarea>
  167. </td>
  168. </tr>
  169. <tr><td colspan="15">
  170. <div class="fixsel">
  171. <input type="submit" class="btn" onclick="return CheckForm();" value="提交" />
  172. </div>
  173. </td></tr>
  174. </form>
  175. </table>
  176. </div>
  177. <?php
  178. $this->kindeditor();
  179. }
  180. function save()
  181. {
  182. if (!submitcheck("hash", 1)) {
  183. $this->ShowMessage("表单来路不明,无法提交!", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
  184. }
  185. $_var_16 = intval(SafeRequest("id", "post"));
  186. $_var_17 = SafeRequest("name", "post");
  187. if (!$_var_17) {
  188. $this->ShowMessage("文章名称不能为空", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
  189. }
  190. $_var_18 = SafeRequest("content", "post", 1);
  191. if (!$_var_18) {
  192. $this->ShowMessage("内容不能为空", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
  193. }
  194. $_var_19 = ["name" => $_var_17, "content" => $_var_18];
  195. $_var_19["group"] = SafeRequest("group", "post");
  196. $_var_19["type"] = SafeRequest("type", "post");
  197. if ($_var_16) {
  198. $_var_20 = db("article")->where("id", $_var_16)->update($_var_19);
  199. } else {
  200. if (db("article")->where("name", $_var_17)->where("group", $_var_19["group"])->where("type", $_var_19["type"])->count()) {
  201. $this->ShowMessage("已存在同名的文章", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
  202. }
  203. $_var_20 = db("article")->insert($_var_19);
  204. }
  205. $_var_20 && $this->ShowMessage("恭喜您,文章保存成功!", "?c=article", "infotitle2", 1000, 1);
  206. $this->ShowMessage("文章保存失败!请稍后重试!", $_SERVER["HTTP_REFERER"], "infotitle3", 3000, 1);
  207. }
  208. function change_status()
  209. {
  210. if (!submitcheck("hash", -1)) {
  211. $this->ShowMessage("链接来路不明,无法提交!", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
  212. }
  213. $_var_21 = intval(SafeRequest("id", "get"));
  214. $_var_22 = intval(SafeRequest("status", "get"));
  215. $_var_23 = db("article")->where("id", $_var_21)->update(["status" => intval(!$_var_22)]);
  216. $this->ShowMessage("恭喜您,状态切换成功!", "?c=article", "infotitle2", 1000, 1);
  217. }
  218. }