PageRenderTime 23ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyfaq/admin/ajax.records.php

https://github.com/cyrke/phpMyFAQ
PHP | 138 lines | 87 code | 24 blank | 27 comment | 25 complexity | 45151a40ed4674a478b7a439d2d4537e MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * AJAX: handling of Ajax record calls
  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 Anatoliy Belsky <anatoliy.belsky@mayflower.de>
  14. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  15. * @copyright 2009-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 2009-03-31
  19. */
  20. if (!defined('IS_VALID_PHPMYFAQ')) {
  21. header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']));
  22. exit();
  23. }
  24. $ajax_action = PMF_Filter::filterInput(INPUT_GET, 'ajaxaction', FILTER_SANITIZE_STRING);
  25. // Expected is an array of the structure:
  26. // array( 0 => array((int)id, (string)langugage, (int) checked)),
  27. // 1 => .....
  28. // )
  29. $items = isset($_GET['items']) && is_array($_GET['items']) ? $_GET['items'] : array();
  30. if (!isset($items[0][2])) {
  31. $items[0][2] = 0;
  32. }
  33. switch($ajax_action) {
  34. // save active FAQs
  35. case 'save_active_records':
  36. if ($permission['approverec']) {
  37. if (!empty($items)) {
  38. $faq = new PMF_Faq($faqConfig);
  39. foreach ($items as $item) {
  40. if (is_array($item) && count($item) == 3 && PMF_Language::isASupportedLanguage($item[1])) {
  41. print $faq->updateRecordFlag((int)$item[0], addslashes($item[1]), $item[2], 'active');
  42. }
  43. }
  44. }
  45. } else {
  46. print $PMF_LANG['err_NotAuth'];
  47. }
  48. break;
  49. // save sticky FAQs
  50. case 'save_sticky_records':
  51. if ($permission['editbt']) {
  52. if (!empty($items)) {
  53. $faq = new PMF_Faq($faqConfig);
  54. foreach ($items as $item) {
  55. if (is_array($item) && count($item) == 3 && PMF_Language::isASupportedLanguage($item[1])) {
  56. print $faq->updateRecordFlag((int)$item[0], addslashes($item[1]), (int)$item[2], 'sticky');
  57. }
  58. }
  59. }
  60. } else {
  61. print $PMF_LANG['err_NotAuth'];
  62. }
  63. break;
  64. // search FAQs for suggestions
  65. case 'search_records':
  66. if ($permission['editbt']) {
  67. $faq = new PMF_Faq($faqConfig);
  68. $faqSearch = new PMF_Search($faqConfig);
  69. $faqSearchResult = new PMF_Search_Resultset($user, $faq, $faqConfig);
  70. $searchResult = '';
  71. $searchString = PMF_Filter::filterInput(INPUT_POST, 'search', FILTER_SANITIZE_STRIPPED);
  72. if (!is_null($searchString)) {
  73. $searchResult = $faqSearch->search($searchString, false);
  74. $faqSearchResult->reviewResultset($searchResult);
  75. $searchHelper = new PMF_Helper_Search($faqConfig);
  76. $searchHelper->setSearchterm($searchString);
  77. print $searchHelper->renderAdminSuggestionResult($faqSearchResult);
  78. }
  79. } else {
  80. print $PMF_LANG['err_NotAuth'];
  81. }
  82. break;
  83. // delete FAQs
  84. case 'delete_record':
  85. if ($permission['delbt']) {
  86. $recordId = PMF_Filter::filterInput(INPUT_POST, 'record_id', FILTER_VALIDATE_INT);
  87. $recordLang = PMF_Filter::filterInput(INPUT_POST, 'record_lang', FILTER_SANITIZE_STRING);
  88. $logging = new PMF_Logging($faqConfig);
  89. $logging->logAdmin($user, 'Deleted FAQ ID ' . $recordId);
  90. $faq->deleteRecord($recordId, $recordLang);
  91. print $PMF_LANG['ad_entry_delsuc'];
  92. } else {
  93. print $PMF_LANG['err_NotAuth'];
  94. }
  95. break;
  96. // delete open questions
  97. case 'delete_question':
  98. if ($permission['delquestion']) {
  99. $checks = array(
  100. 'filter' => FILTER_VALIDATE_INT,
  101. 'flags' => FILTER_REQUIRE_ARRAY
  102. );
  103. $questionIds = PMF_Filter::filterInputArray(INPUT_POST, array('questions' => $checks));
  104. if (!is_null($questionIds['questions'])) {
  105. foreach ($questionIds['questions'] as $questionId) {
  106. $faq->deleteQuestion((int)$questionId);
  107. }
  108. }
  109. print $PMF_LANG['ad_entry_delsuc'];
  110. } else {
  111. print $PMF_LANG['err_NotAuth'];
  112. }
  113. break;
  114. }