PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/phpmyfaq/admin/category.showstructure.php

https://github.com/cyrke/phpMyFAQ
PHP | 156 lines | 118 code | 13 blank | 25 comment | 18 complexity | 45412eb508f2b889a33645843b44e5f3 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * build table of all categories in all languages
  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 Rudi Ferrari <bookcrossers@gmx.de>
  15. * @copyright 2006-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 2006-09-18
  19. */
  20. if (!defined('IS_VALID_PHPMYFAQ')) {
  21. header('Location: http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['SCRIPT_NAME']));
  22. exit();
  23. }
  24. ?>
  25. <header>
  26. <h2><?php print $PMF_LANG['ad_menu_categ_structure'] ?></h2>
  27. </header>
  28. <?php
  29. if ($permission['editcateg']) {
  30. $category = new PMF_Category($faqConfig, false);
  31. $category->setUser($currentAdminUser);
  32. $category->setGroups($currentAdminGroups);
  33. $currentLink = $_SERVER['SCRIPT_NAME'];
  34. $currentLanguage = $languageCodes[strtoupper($LANGCODE)];
  35. $all_languages = array();
  36. $all_lang = array();
  37. $showcat = PMF_Filter::filterInput(INPUT_POST, 'showcat', FILTER_SANITIZE_STRING);
  38. // translate an existing category
  39. if (!is_null($showcat) && $showcat == 'yes') {
  40. $parent_id = PMF_Filter::filterInput(INPUT_POST, 'parent_id', FILTER_VALIDATE_INT);
  41. $category_data = array(
  42. 'id' => PMF_Filter::filterInput(INPUT_POST, 'id', FILTER_VALIDATE_INT),
  43. 'lang' => PMF_Filter::filterInput(INPUT_POST, 'lang', FILTER_SANITIZE_STRING),
  44. 'parent_id' => $parent_id,
  45. 'name' => PMF_Filter::filterInput(INPUT_POST, 'name', FILTER_SANITIZE_STRING),
  46. 'description' => PMF_Filter::filterInput(INPUT_POST, 'description', FILTER_SANITIZE_STRING),
  47. 'user_id' => PMF_Filter::filterInput(INPUT_POST, 'user_id', FILTER_VALIDATE_INT));
  48. // translate.category only returns non-existent languages to translate too
  49. if ($category->addCategory($category_data, $parent_id, $category_data['id'])) {
  50. printf('<p class="alert alert-success">%s</p>', $PMF_LANG['ad_categ_translated']);
  51. } else {
  52. printf('<p class="alert alert-error">%s</p>', $faqConfig->getDb()->error());
  53. }
  54. }
  55. $category->getMissingCategories();
  56. $category->buildTree();
  57. ?>
  58. <table class="table table-striped">
  59. <thead>
  60. <tr>
  61. <th><?php print $currentLanguage ?></th>
  62. <?php
  63. // get languages in use for all categories
  64. $all_languages = $faqConfig->getLanguage()->languageAvailable(0, $table='faqcategories');
  65. foreach ($all_languages as $lang) {
  66. $all_lang[$lang] = $languageCodes[strtoupper($lang)];
  67. }
  68. asort($all_lang);
  69. foreach($all_lang as $lang => $language) {
  70. if ($language != $currentLanguage) {
  71. printf("<th>" . $language . "</th>\n", $language);
  72. }
  73. }
  74. ?>
  75. </tr>
  76. </thead>
  77. <tbody>
  78. <?php
  79. foreach ($category->catTree as $cat) {
  80. print "<tr>\n";
  81. $indent = '';
  82. for ($i = 0; $i < $cat['indent']; $i++) {
  83. $indent .= '&nbsp;&nbsp;&nbsp;';
  84. }
  85. // category translated in this language?
  86. ($cat['lang'] == $LANGCODE) ? $catname = $cat['name'] : $catname = $cat['name'].' ('.$languageCodes[strtoupper($cat['lang'])].')';
  87. // show category name in actual language
  88. print '<td>';
  89. if ($cat['lang'] != $LANGCODE) {
  90. // translate category
  91. printf(
  92. '<a href="%s?action=translatecategory&amp;cat=%s&amp;trlang=%s" title="%s"><span title="%s" class="icon-share"></span></a></a>',
  93. $currentLink,
  94. $cat['id'],
  95. $LANGCODE,
  96. $PMF_LANG['ad_categ_translate'],
  97. $PMF_LANG['ad_categ_translate']
  98. );
  99. }
  100. printf("&nbsp;%s<strong>%s</strong>",
  101. $indent,
  102. $catname);
  103. print "</td>\n";
  104. // get languages in use for categories
  105. $id_languages = $category->getCategoryLanguagesTranslated($cat["id"]);
  106. foreach($all_lang as $lang => $language) {
  107. if ($language == $currentLanguage) {
  108. continue;
  109. }
  110. if (array_key_exists($language, $id_languages)) {
  111. $spokenLanguage = PMF_String::preg_replace('/\(.*\)/', '', $id_languages[$language]);
  112. printf('<td title="%s: %s">',
  113. $PMF_LANG['ad_categ_titel'],
  114. $spokenLanguage
  115. );
  116. printf(
  117. '<span title="%s: %s" class="label label-success"><i class="icon-check icon-white"></i></span></td>',
  118. $PMF_LANG['ad_categ_titel'],
  119. $spokenLanguage
  120. );
  121. } else {
  122. printf('<td><a href="%s?action=translatecategory&amp;cat=%s&amp;trlang=%s" title="%s">',
  123. $currentLink,
  124. $cat['id'],
  125. $lang,
  126. $PMF_LANG['ad_categ_translate']);
  127. printf(
  128. '<span title="%s" class="label label-inverse"><i class="icon-share icon-white"></i></span></a>',
  129. $PMF_LANG['ad_categ_translate']
  130. );
  131. }
  132. print "</td>\n";
  133. }
  134. print "</tr>\n";
  135. }
  136. ?>
  137. </tbody>
  138. </table>
  139. <?php
  140. printf('<p>%s</p>', $PMF_LANG['ad_categ_remark_overview']);
  141. } else {
  142. print $PMF_LANG['err_NotAuth'];
  143. }