/phpmyfaq/admin/record.show.php

https://github.com/cyrke/phpMyFAQ · PHP · 464 lines · 367 code · 44 blank · 53 comment · 39 complexity · ac26e193f1590527ca89996b6fb36fe5 MD5 · raw file

  1. <?php
  2. /**
  3. * Shows the list of records ordered by categories
  4. *
  5. * PHP Version 5.3
  6. *
  7. * This Source Code Form is subject to the terms of the Mozilla Public License,
  8. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  9. * obtain one at http://mozilla.org/MPL/2.0/.
  10. *
  11. * @category phpMyFAQ
  12. * @package Administration
  13. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  14. * @author Minoru TODA <todam@netjapan.co.jp>
  15. * @copyright 2003-2012 phpMyFAQ Team
  16. * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
  17. * @link http://www.phpmyfaq.de
  18. * @since 2003-02-23
  19. */
  20. if (!defined('IS_VALID_PHPMYFAQ')) {
  21. header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']));
  22. exit();
  23. }
  24. printf("<header><h2>%s</h2><header>\n", $PMF_LANG['ad_entry_aor']);
  25. if ($permission['editbt'] || $permission['delbt']) {
  26. // (re)evaluate the Category object w/o passing the user language
  27. $category = new PMF_Category($faqConfig, false);
  28. $category->setUser($currentAdminUser);
  29. $category->setGroups($currentAdminGroups);
  30. $category->transform(0);
  31. // Set the Category for the helper class
  32. $categoryHelper = new PMF_Helper_Category();
  33. $categoryHelper->setCategory($category);
  34. $category->buildTree();
  35. $linkverifier = new PMF_Linkverifier($faqConfig, $user->getLogin());
  36. if ($linkverifier->isReady()) {
  37. ?>
  38. <script type="text/javascript">
  39. <!--
  40. function getImageElement(id, lang)
  41. {
  42. return $('#imgurl_' + lang + '_' + id);
  43. }
  44. function getSpanElement(id, lang)
  45. {
  46. return $('#spanurl_' + lang + '_' + id);
  47. }
  48. function getDivElement(id, lang)
  49. {
  50. return $('#divurl_' + lang + '_' + id);
  51. }
  52. function onDemandVerifyURL(id, lang, target)
  53. {
  54. var target = getSpanElement(id, lang);
  55. var widthPx = 780;
  56. var heigthPx = 450;
  57. var leftPx = (screen.width - widthPx)/2;
  58. var topPx = (screen.height - heigthPx)/2;
  59. Fenster = window.open('index.php?action=ajax&ajax=onDemandURL&id=' + id + '&artlang=' + lang, 'onDemandURLVerification', 'toolbar=no, location=no, status=no, menubar=no, width=' + widthPx + ', height=' + heigthPx + ', left=' + leftPx + ', top=' + topPx + ', resizable=yes, scrollbars=yes');
  60. Fenster.focus();
  61. verifyEntryURL(id, lang);
  62. }
  63. function verifyEntryURL(id, lang)
  64. {
  65. //var target = getImageElement(id, lang);
  66. var target = getSpanElement(id, lang);
  67. // !!IMPORTANT!! DISABLE ONLOAD. If you do not do this, you will get infinite loop!
  68. getImageElement(id, lang).onload = "";
  69. //target.src = "images/url-checking.png";
  70. getDivElement(id, lang).className = "url-checking";
  71. target.innerHTML = "<?php print($PMF_LANG['ad_linkcheck_feedback_url-checking']); ?>";
  72. var url = 'index.php';
  73. var pars = 'action=ajax&ajax=verifyURL&id=' + id + '&artlang=' + lang;
  74. var myAjax = new jQuery.ajax({url: url,
  75. type: 'get',
  76. data: pars,
  77. complete: verifyEntryURL_success,
  78. error: verifyEntryURL_failure});
  79. function verifyEntryURL_success(XmlRequest)
  80. {
  81. //target.src = "images/url-" + XmlRequest.responseText + ".png";
  82. var allResponses = new Array();
  83. allResponses['batch1'] = "<?php print($PMF_LANG['ad_linkcheck_feedback_url-batch1']); ?>";
  84. allResponses['batch2'] = "<?php print($PMF_LANG['ad_linkcheck_feedback_url-batch2']); ?>";
  85. allResponses['batch3'] = "<?php print($PMF_LANG['ad_linkcheck_feedback_url-batch3']); ?>";
  86. allResponses['checking'] = "<?php print($PMF_LANG['ad_linkcheck_feedback_url-checking']); ?>";
  87. allResponses['disabled'] = "<?php print($PMF_LANG['ad_linkcheck_feedback_url-disabled']); ?>";
  88. allResponses['linkbad'] = "<?php print($PMF_LANG['ad_linkcheck_feedback_url-linkbad']); ?>";
  89. allResponses['linkok'] = "<?php print($PMF_LANG['ad_linkcheck_feedback_url-linkok']); ?>";
  90. allResponses['noaccess'] = "<?php print($PMF_LANG['ad_linkcheck_feedback_url-noaccess']); ?>";
  91. allResponses['noajax'] = "<?php print($PMF_LANG['ad_linkcheck_feedback_url-noajax']); ?>";
  92. allResponses['nolinks'] = "<?php print($PMF_LANG['ad_linkcheck_feedback_url-nolinks']); ?>";
  93. allResponses['noscript'] = "<?php print($PMF_LANG['ad_linkcheck_feedback_url-noscript']); ?>";
  94. getDivElement(id, lang).className = "url-" + XmlRequest.responseText;
  95. if (typeof(allResponses[XmlRequest.responseText]) == "undefined") {
  96. getDivElement(id, lang).className = "url-noajax ";
  97. target.html(allResponses['noajax']);
  98. } else {
  99. target.html(allResponses[XmlRequest.responseText]);
  100. }
  101. }
  102. function verifyEntryURL_failure(XmlRequest)
  103. {
  104. getDivElement(id, lang).className = "url-noaccess";
  105. target.html("<?php print($PMF_LANG['ad_linkcheck_feedback_url-noaccess']); ?>");
  106. }
  107. }
  108. //-->
  109. </script>
  110. <?php
  111. }
  112. $comment = new PMF_Comment($faqConfig);
  113. $faq = new PMF_Faq($faqConfig);
  114. $date = new PMF_Date($faqConfig);
  115. $selectedCategory = PMF_Filter::filterInput(INPUT_GET, 'category', FILTER_VALIDATE_INT, 0);
  116. $orderBy = PMF_Filter::filterInput(INPUT_GET, 'orderby', FILTER_SANITIZE_STRING, 1);
  117. $sortBy = PMF_Filter::filterInput(INPUT_GET, 'sortby', FILTER_SANITIZE_STRING);
  118. if (1 !== $orderBy) {
  119. switch ($orderBy) {
  120. case 'id':
  121. $orderBy = 1;
  122. break;
  123. case 'title':
  124. $orderBy = 2;
  125. break;
  126. case 'date':
  127. $orderBy = 3;
  128. break;
  129. }
  130. }
  131. ?>
  132. <form id="recordSelection" name="recordSelection" method="post">
  133. <?php
  134. $numCommentsByFaq = $comment->getNumberOfComments();
  135. $numRecordsByCat = $category->getNumberOfRecordsOfCategory();
  136. $matrix = $category->getCategoryRecordsMatrix();
  137. foreach ($matrix as $catkey => $value) {
  138. $numCommentsByCat[$catkey] = 0;
  139. foreach ($value as $faqkey => $value) {
  140. if (isset($numCommentsByFaq[$faqkey])) {
  141. $numCommentsByCat[$catkey] += $numCommentsByFaq[$faqkey];
  142. }
  143. }
  144. }
  145. $faq->getAllRecords($orderBy, null, $sortBy);
  146. foreach ($faq->faqRecords as $record) {
  147. if (!isset($numActiveByCat[$record['category_id']])) {
  148. $numActiveByCat[$record['category_id']] = 0;
  149. }
  150. $numActiveByCat[$record['category_id']] += $record['active'] == 'yes' ? 1 : 0;
  151. }
  152. if (count($faq->faqRecords) > 0) {
  153. $old = 0;
  154. $all_ids = array();
  155. $visits = new PMF_Visits($faqConfig);
  156. $numVisits = array();
  157. foreach ($visits->getAllData() as $visit) {
  158. $numVisits[$visit['id']] = $visit['lang'];
  159. }
  160. foreach ($faq->faqRecords as $record) {
  161. $catInfo = '';
  162. $cid = $record['category_id'];
  163. if (isset($numRecordsByCat[$cid]) && ($numRecordsByCat[$cid] > 0)) {
  164. $catInfo .= sprintf(
  165. '<span class="label label-info" id="category_%d_item_count">%d %s</span> ',
  166. $cid,
  167. $numRecordsByCat[$cid],
  168. $PMF_LANG['msgEntries']
  169. );
  170. }
  171. if (isset($numRecordsByCat[$cid]) && $numRecordsByCat[$cid] > $numActiveByCat[$cid]) {
  172. $catInfo .= sprintf(
  173. '<span class="label label-important"><span id="js-active-records-%d">%d</span> %s</span> ',
  174. $cid,
  175. $numRecordsByCat[$cid] - $numActiveByCat[$cid],
  176. $PMF_LANG['ad_record_inactive']
  177. );
  178. }
  179. if (isset($numCommentsByCat[$cid]) && ($numCommentsByCat[$cid] > 0)) {
  180. $catInfo .= sprintf('<span class="label label-inverse">%d %s</span>',
  181. $numCommentsByCat[$cid],
  182. $PMF_LANG['ad_start_comments']
  183. );
  184. }
  185. $catInfo .= '';
  186. if ($cid != $old) {
  187. if ($old == 0) {
  188. printf('<a name="cat_%d"></a>', $cid);
  189. } else {
  190. print " </tbody>\n </table>\n </div>";
  191. }
  192. ?>
  193. <p>
  194. <a class="btn" href="javascript:void(0);"
  195. onclick="showhideCategory('category_<?php print $cid; ?>');">
  196. <i class="icon icon-arrow-right"></i>
  197. <strong><?php print $category->getPath($cid); ?></strong>
  198. <?php print $catInfo;?>
  199. </a>
  200. </p>
  201. <div id="category_<?php print $cid; ?>" class="categorybox <?php print ($selectedCategory == $cid) ? '' : 'hide'; ?>">
  202. <table class="table table-striped">
  203. <thead>
  204. <tr>
  205. <th colspan="2" style="width: 24px;">
  206. <a href="?action=view&amp;category=<?php print $cid; ?>&amp;orderby=id&amp;sortby=desc">
  207. &uarr;
  208. </a>
  209. <a href="?action=view&amp;category=<?php print $cid; ?>&amp;orderby=id&amp;sortby=asc">
  210. &darr;
  211. </a>
  212. </th>
  213. <th>
  214. #
  215. </th>
  216. <th style="width: 72px;">
  217. <input type="checkbox" id="sticky_category_block_<?php print $cid; ?>"
  218. onclick="saveStatusForCategory(<?php print $cid; ?>, 'sticky')" />
  219. &nbsp;<?php print $PMF_LANG['ad_record_sticky'] ?>
  220. </th>
  221. <th>
  222. <a href="?action=view&amp;category=<?php print $cid; ?>&amp;orderby=title&amp;sortby=desc">
  223. &uarr;
  224. </a>
  225. <a href="?action=view&amp;category=<?php print $cid; ?>&amp;orderby=title&amp;sortby=asc">
  226. &darr;
  227. </a>
  228. </th>
  229. <th>
  230. <a href="?action=view&amp;category=<?php print $cid; ?>&amp;orderby=date&amp;sortby=desc">
  231. &uarr;
  232. </a>
  233. <a href="?action=view&amp;category=<?php print $cid; ?>&amp;orderby=date&amp;sortby=asc">
  234. &darr;
  235. </a>
  236. </th>
  237. <th colspan="3">
  238. &nbsp;
  239. </th>
  240. <th style="width: 84px;">
  241. <?php if ($permission['approverec']) { ?>
  242. <input type="checkbox" id="active_category_block_<?php print $cid; ?>"
  243. onclick="saveStatusForCategory(<?php print $cid; ?>, 'active')" />
  244. &nbsp;<?php print $PMF_LANG['ad_record_active'] ?>
  245. <?php } ?>
  246. </th>
  247. </tr>
  248. </thead>
  249. <tbody>
  250. <?php
  251. }
  252. ?>
  253. <tr class="record_<?php echo $record['id'] . '_' . $record['lang']; ?>'">
  254. <td style="width: 24px; text-align: right;">
  255. <a href="?action=editentry&amp;id=<?php print $record['id']; ?>&amp;lang=<?php print $record['lang']; ?>">
  256. <?php print $record['id']; ?>
  257. </a>
  258. </td>
  259. <td style="width: 16px;">
  260. <?php print $record['lang']; ?>
  261. </td>
  262. <td style="width: 24px;">
  263. <a href="?action=editentry&amp;id=<?php print $record['id']; ?>&amp;lang=<?php print $record['lang']; ?>"
  264. title="<?php print $PMF_LANG["ad_user_edit"]; ?> '<?php print str_replace("\"", "´", $record['title']); ?>'">
  265. <?php print $record['solution_id']; ?>
  266. </a>
  267. </td>
  268. <td style="width: 56px;">
  269. <input type="checkbox" lang="<?php print $record['lang'] ?>"
  270. onclick="saveStatus(<?php print $cid . ', [' . $record['id'] . ']' ?>, 'sticky');"
  271. id="sticky_record_<?php print $cid . '_' . $record['id'] ?>"
  272. <?php $record['sticky'] ? print 'checked="checked"' : print ' ' ?> />
  273. </td>
  274. <td>
  275. <a href="?action=editentry&amp;id=<?php print $record['id']; ?>&amp;lang=<?php print $record['lang']; ?>"
  276. title="<?php print $PMF_LANG["ad_user_edit"]; ?> '<?php print str_replace("\"", "´", $record['title']); ?>'">
  277. <?php print $record['title']; ?>
  278. </a>
  279. <?php
  280. if (isset($numCommentsByFaq[$record['id']])) {
  281. printf(
  282. '<br/><a class="label label-inverse" href="?action=comments#record_id_%d">%d %s</a>',
  283. $record['id'],
  284. $numCommentsByFaq[$record['id']],
  285. $PMF_LANG['ad_start_comments']
  286. );
  287. }
  288. ?></td>
  289. <td style="width: 48px;">
  290. <?php print $date->format($record['date']); ?>
  291. </td>
  292. <td style="width: 96px;">
  293. <?php print $linkverifier->getEntryStateHTML($record['id'], $record['lang']); ?>
  294. </td>
  295. <td style="width: 16px;">
  296. <a href="javascript:void(0);"
  297. onclick="javascript:deleteRecord(<?php print $record['id']; ?>, '<?php print $record['lang']; ?>'); return false;"
  298. title="<?php print $PMF_LANG["ad_user_delete"]; ?>">
  299. <i class="icon-trash"></i>
  300. </a>
  301. </td>
  302. <td style="width: 16px;">
  303. <a href="?action=copyentry&amp;id=<?php print $record['id']; ?>&amp;lang=<?php print $record['lang']; ?>"
  304. title="<?php print $PMF_LANG['ad_categ_copy']; ?>">
  305. <i class="icon-share"></i>
  306. </a>
  307. </td>
  308. <td>
  309. <?php if ($permission['approverec'] && isset($numVisits[$record['id']])) { ?>
  310. <input type="checkbox" lang="<?php print $record['lang'] ?>"
  311. onclick="saveStatus(<?php print $cid . ', [' . $record['id'] . ']' ?>, 'active');"
  312. id="active_record_<?php print $cid . '_' . $record['id'] ?>"
  313. <?php 'yes' == $record['active'] ? print 'checked="checked"' : print ' ' ?> />
  314. <?php } else { ?>
  315. <span class="label label-important"><i class="icon-white icon-ban-circle"></i></span>
  316. <?php } ?>
  317. </td>
  318. </tr>
  319. <?php
  320. $old = $cid;
  321. $all_ids[$cid][] = $record['id'];
  322. }
  323. ?>
  324. </tbody>
  325. </table>
  326. </div>
  327. </form>
  328. <script type="text/javascript">
  329. /* <![CDATA[ */
  330. /**
  331. * Saves the sticky record status for the whole category
  332. *
  333. * @param integer id id
  334. * @param string type status type
  335. *
  336. * @return void
  337. */
  338. function saveStatusForCategory(id, type)
  339. {
  340. var id_map = [];
  341. <?php
  342. foreach ($all_ids as $cat_id => $record_ids) {
  343. echo " id_map[" . $cat_id . "] = [" . implode(',', $record_ids) . "];\n";
  344. }
  345. ?>
  346. for (var i = 0; i < id_map[id].length; i++) {
  347. var status = $('#' + type + '_category_block_' + id).attr('checked');
  348. $('#' + type + '_record_' + id + '_' + id_map[id][i]).attr('checked', status);
  349. }
  350. saveStatus(id, id_map[id], type);
  351. }
  352. /**
  353. * Ajax call for saving the sticky record status
  354. *
  355. * @param integer cid category id
  356. * @param integer ids ids
  357. * @param string type status type
  358. *
  359. * @return void
  360. */
  361. function saveStatus(cid, ids, type)
  362. {
  363. $('#saving_data_indicator').html('<img src="images/indicator.gif" /> saving ...');
  364. var data = {action: "ajax", ajax: 'records', ajaxaction: "save_" + type + "_records"};
  365. for (var i = 0; i < ids.length; i++) {
  366. var status = $('#' + type + '_record_' + cid + '_' + ids[i]).attr('checked');
  367. var lang = $('#' + type + '_record_' + cid + '_' + ids[i]).attr('lang');
  368. data['items[' + i + '][]'] = [ids[i], lang, status];
  369. // Updating the current record if it's also contained in another category
  370. var same_records = $('input').filter(function() {
  371. return this.id.match(new RegExp(type + '_record_(\\d+)_' + ids[i]));
  372. });
  373. if ('active' === type) {
  374. for (var j = 0; j < same_records.length; j++) {
  375. $('#' + same_records[j].id).attr('checked', status);
  376. var catid = same_records[j].id.match(/active_record_(\d+)_\d+/)[1];
  377. var current_item_count = $('#js-active-records-' + catid).html();
  378. var delta = status ? 1 : -1;
  379. $('#js-active-records-' + catid).html(current_item_count * 1 + delta);
  380. }
  381. } else {
  382. for (var j = 0; j < same_records.length; j++) {
  383. $('#' + same_records[j].id).attr('checked', status);
  384. }
  385. }
  386. }
  387. $.get("index.php", data, null);
  388. $('#saving_data_indicator').html('<?php print $PMF_LANG['ad_entry_savedsuc']; ?>');
  389. }
  390. /**
  391. * Ajax call for deleting records
  392. *
  393. * @param integer record_id Record id
  394. * @param string record_lang Record language
  395. * @return void
  396. */
  397. function deleteRecord(record_id, record_lang)
  398. {
  399. if (confirm('<?php print addslashes($PMF_LANG["ad_entry_del_1"] . " " . $PMF_LANG["ad_entry_del_3"]); ?>')) {
  400. $('#saving_data_indicator').html('<img src="images/indicator.gif" /> deleting ...');
  401. $.ajax({
  402. type: "POST",
  403. url: "index.php?action=ajax&ajax=records&ajaxaction=delete_record",
  404. data: "record_id=" + record_id + "&record_lang=" + record_lang,
  405. success: function(msg) {
  406. $('#saving_data_indicator').html('<?php print $PMF_LANG['ad_entry_delsuc']; ?>');
  407. $('.record_' + record_id + '_' + record_lang).fadeOut('slow');
  408. }
  409. });
  410. }
  411. }
  412. /* ]]> */
  413. </script>
  414. <?php
  415. } else {
  416. print $PMF_LANG['err_nothingFound'];
  417. }
  418. } else {
  419. print $PMF_LANG['err_NotAuth'];
  420. }