admincp_faq.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: admincp_faq.php 25246 2011-11-02 03:34:53Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. cpheader();
  12. $operation = $operation ? $operation : 'list';
  13. if($operation == 'list') {
  14. if(!submitcheck('faqsubmit')) {
  15. shownav('extended', 'faq');
  16. showsubmenu('faq');
  17. showformheader('faq&operation=list');
  18. showtableheader();
  19. echo '<tr><th class="td25"></th><th><strong>'.$lang['display_order'].'</stong></th><th style="width:350px"><strong>'.$lang['faq_thread'].'</strong></th><th></th></tr>';
  20. $faqparent = $faqsub = array();
  21. $faqlists = $faqselect = '';
  22. foreach(C::t('forum_faq')->fetch_all_by_fpid() as $faq) {
  23. if(empty($faq['fpid'])) {
  24. $faqparent[$faq['id']] = $faq;
  25. $faqselect .= "<option value=\"$faq[id]\">$faq[title]</option>";
  26. } else {
  27. $faqsub[$faq['fpid']][] = $faq;
  28. }
  29. }
  30. foreach($faqparent as $parent) {
  31. $disabled = !empty($faqsub[$parent['id']]) ? 'disabled' : '';
  32. showtablerow('', array('', 'class="td23 td28"'), array(
  33. "<input class=\"checkbox\" type=\"checkbox\" name=\"delete[]\" value=\"$parent[id]\" $disabled>",
  34. "<input type=\"text\" class=\"txt\" size=\"3\" name=\"displayorder[$parent[id]]\" value=\"$parent[displayorder]\">",
  35. "<div class=\"parentnode\"><input type=\"text\" class=\"txt\" size=\"30\" name=\"title[$parent[id]]\" value=\"".dhtmlspecialchars($parent['title'])."\"></div>",
  36. "<a href=\"".ADMINSCRIPT."?action=faq&operation=detail&id=$parent[id]\" class=\"act\">".$lang['detail']."</a>"
  37. ));
  38. if(!empty($faqsub[$parent['id']])) {
  39. foreach($faqsub[$parent['id']] as $sub) {
  40. showtablerow('', array('', 'class="td23 td28"'), array(
  41. "<input class=\"checkbox\" type=\"checkbox\" name=\"delete[]\" value=\"$sub[id]\">",
  42. "<input type=\"text\" class=\"txt\" size=\"3\" name=\"displayorder[$sub[id]]\" value=\"$sub[displayorder]\">",
  43. "<div class=\"node\"><input type=\"text\" class=\"txt\" size=\"30\" name=\"title[$sub[id]]\" value=\"".dhtmlspecialchars($sub['title'])."\"></div>",
  44. "<a href=\"".ADMINSCRIPT."?action=faq&operation=detail&id=$sub[id]\" class=\"act\">".$lang['detail']."</a>"
  45. ));
  46. }
  47. }
  48. echo '<tr><td></td><td></td><td colspan="2"><div class="lastnode"><a href="###" onclick="addrow(this, 1, '.$parent['id'].')" class="addtr">'.cplang('faq_additem').'</a></div></td></tr>';
  49. }
  50. echo '<tr><td></td><td></td><td colspan="2"><div><a href="###" onclick="addrow(this, 0, 0)" class="addtr">'.cplang('faq_addcat').'</a></div></td></tr>';
  51. echo <<<EOT
  52. <script type="text/JavaScript">
  53. var rowtypedata = [
  54. [[1,''], [1,'<input name="newdisplayorder[]" value="" size="3" type="text" class="txt">', 'td25'], [1, '<input name="newtitle[]" value="" size="30" type="text" class="txt">'], [1, '<input type="hidden" name="newfpid[]" value="0" />']],
  55. [[1,''], [1,'<input name="newdisplayorder[]" value="" size="3" type="text" class="txt">', 'td25'], [1, '<div class=\"node\"><input name="newtitle[]" value="" size="30" type="text" class="txt"></div>'], [1, '<input type="hidden" name="newfpid[]" value="{1}" />']]
  56. ];
  57. </script>
  58. EOT;
  59. showsubmit('faqsubmit', 'submit', 'del');
  60. showtablefooter();
  61. showformfooter();
  62. } else {
  63. if($_GET['delete']) {
  64. C::t('forum_faq')->delete($_GET['delete']);
  65. }
  66. if(is_array($_GET['title'])) {
  67. foreach($_GET['title'] as $id => $val) {
  68. C::t('forum_faq')->update($id, array(
  69. 'displayorder' => $_GET['displayorder'][$id],
  70. 'title' => $_GET['title'][$id]
  71. ));
  72. }
  73. }
  74. if(is_array($_GET['newtitle'])) {
  75. foreach($_GET['newtitle'] as $k => $v) {
  76. $v = trim($v);
  77. if($v) {
  78. C::t('forum_faq')->insert(array(
  79. 'fpid' => intval($_GET['newfpid'][$k]),
  80. 'displayorder' => intval($_GET['newdisplayorder'][$k]),
  81. 'title' => $v
  82. ));
  83. }
  84. }
  85. }
  86. cpmsg('faq_list_update', 'action=faq&operation=list', 'succeed');
  87. }
  88. } elseif($operation == 'detail') {
  89. $id = $_GET['id'];
  90. if(!submitcheck('detailsubmit')) {
  91. $faq = C::t('forum_faq')->fetch($id);
  92. if(!$faq) {
  93. cpmsg('faq_nonexistence', '', 'error');
  94. }
  95. foreach(C::t('forum_faq')->fetch_all_by_fpid(0) as $parent) {
  96. $faqselect .= "<option value=\"$parent[id]\" ".($faq['fpid'] == $parent['id'] ? 'selected' : '').">$parent[title]</option>";
  97. }
  98. shownav('extended', 'faq');
  99. showsubmenu('faq');
  100. showformheader("faq&operation=detail&id=$id");
  101. showtableheader();
  102. showtitle('faq_edit');
  103. showsetting('faq_title', 'titlenew', $faq['title'], 'text');
  104. if(!empty($faq['fpid'])) {
  105. showsetting('faq_sortup', '', '', '<select name="fpidnew"><option value=\"\">'.$lang['none'].'</option>'.$faqselect.'</select>');
  106. showsetting('faq_identifier', 'identifiernew', $faq['identifier'], 'text');
  107. showsetting('faq_keywords', 'keywordnew', $faq['keyword'], 'text');
  108. showsetting('faq_content', 'messagenew', $faq['message'], 'textarea');
  109. }
  110. showsubmit('detailsubmit');
  111. showtablefooter();
  112. showformfooter();
  113. } else {
  114. if(!$_GET['titlenew']) {
  115. cpmsg('faq_no_title', '', 'error');
  116. }
  117. if(!empty($_GET['identifiernew'])) {
  118. if(C::t('forum_faq')->check_identifier($_GET['identifiernew'], $id)) {
  119. cpmsg('faq_identifier_invalid', '', 'error');
  120. }
  121. }
  122. if(strlen($_GET['keywordnew']) > 50) {
  123. cpmsg('faq_keyword_toolong', '', 'error');
  124. }
  125. $fpidnew = $_GET['fpidnew'] ? intval($_GET['fpidnew']) : 0;
  126. $titlenew = trim($_GET['titlenew']);
  127. $messagenew = trim($_GET['messagenew']);
  128. $identifiernew = trim($_GET['identifiernew']);
  129. $keywordnew = trim($_GET['keywordnew']);
  130. C::t('forum_faq')->update($id, array(
  131. 'fpid' => $fpidnew,
  132. 'identifier' => $identifiernew,
  133. 'keyword' => $keywordnew,
  134. 'title' => $titlenew,
  135. 'message' => $messagenew,
  136. ));
  137. cpmsg('faq_list_update', 'action=faq&operation=list', 'succeed');
  138. }
  139. }
  140. ?>