PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/legacy/includes/pages/admin/topics.php

http://novaboard.googlecode.com/
PHP | 162 lines | 103 code | 26 blank | 33 comment | 17 complexity | 5871fb2f85ef13492c48098200b1614a MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. /*
  3. +--------------------------------------------------------------------------
  4. | NovaBoard
  5. | ========================================
  6. | By The NovaBoard team
  7. | Released under the Artistic License 2.0
  8. | http://www.novaboard.net
  9. | ========================================
  10. |+--------------------------------------------------------------------------
  11. | topics.php - topic settings
  12. */
  13. if (!defined('NOVA_RUN'))
  14. {
  15. exit('<h1>ACCESS DENIED</h1>You cannot access this file directly.');
  16. }
  17. template_hook("pages/admin/topics.template.php", "start");
  18. if ($can_change_forum_settings == 0)
  19. {
  20. nova_redirect('index.php?page=error&error=11', 'error/11');
  21. }
  22. if ($_POST['list_posts'] != '')
  23. {
  24. $token_id = escape_string($_POST['token_id']);
  25. $token_name = "token_topics_$token_id";
  26. $list_topics = (int) $_POST['list_topics'];
  27. $list_posts = (int) $_POST['list_posts'];
  28. $hot_topic = (int) $_POST['hot_topic'];
  29. $store_post_history = (int) $_POST['store_post_history'];
  30. $quick_edit = (int) $_POST['quick_edit'];
  31. $auto_merge = (int) $_POST['auto_merge'];
  32. $trashcan = array(
  33. 'enabled' => (int) $_POST['trashcan_enabled'],
  34. 'forum' => (int) $_POST['trashcan_forum'],
  35. 'move' => (int) $_POST['trashcan_move'],
  36. 'delete_1' => (int) $_POST['trashcan_delete_1'],
  37. 'delete_2' => (int) $_POST['trashcan_delete_2']
  38. );
  39. $trashcan_query = '';
  40. if (isset($_POST[$token_name]) && isset($_SESSION[$token_name]) && $_SESSION[$token_name] == $_POST[$token_name])
  41. {
  42. if (!$trashcan['enabled'])
  43. {
  44. mysql_query('UPDATE ' . $db_prefix . 'settings SET trashcan_enabled = 0');
  45. }
  46. else
  47. {
  48. if ($trashcan_forum != $trashcan['forum'])
  49. {
  50. /*
  51. If this is a direct switch between two forums, we have to
  52. use an intermediary otherwise legit posts will be moved
  53. into the trashcan forum.
  54. */
  55. $workaround = false;
  56. if ($trashcan_forum == $trashcan['move'])
  57. {
  58. # Fake forum id..
  59. $forum_id = -1;
  60. # So we know to fix this later
  61. $workaround = true;
  62. }
  63. else
  64. {
  65. $forum_id = $trashcan['move'];
  66. }
  67. /*
  68. Move posts out of the new trashcan forum:
  69. */
  70. mysql_query('UPDATE ' . $db_prefix . 'posts SET forum_id = ' . $forum_id . ' WHERE forum_id = ' . $trashcan['forum']);
  71. /*
  72. Move posts from the current trashcan forum to the new one:
  73. */
  74. mysql_query('UPDATE ' . $db_prefix . 'posts SET forum_id = ' . $trashcan['forum'] . ' WHERE forum_id = ' . $trashcan_forum);
  75. /*
  76. If a fake forum was used to move the posts, put them in the correct place:
  77. */
  78. if ($workaround)
  79. {
  80. mysql_query('UPDATE ' . $db_prefix . 'posts SET forum_id = ' . $trashcan['move'] . ' WHERE forum_id = ' . $forum_id);
  81. }
  82. }
  83. $trashcan_time = $trashcan['delete_1'] . ';' . $trashcan['delete_2'];
  84. $trashcan_query = ',
  85. trashcan_enabled = ' . $trashcan['enabled'] . ',
  86. trashcan_forum = ' . $trashcan['forum'] . ',
  87. trashcan_delete_time = "' . $trashcan_time . '"
  88. ';
  89. $extra = (!$trashcan_enabled && $trashcan['enabled']) ? ', trashcan_delete_ran = ' . time() : '';
  90. }
  91. mysql_query('
  92. UPDATE
  93. ' . $db_prefix . 'settings
  94. SET
  95. list_topics = ' . $list_topics . ',
  96. list_posts = ' . $list_posts . ',
  97. hot_topic = ' . $hot_topic . ',
  98. store_post_history = ' . $store_post_history . ',
  99. quick_edit = ' . $quick_edit . ',
  100. auto_merge = ' . $auto_merge
  101. . $trashcan_query
  102. . $extra
  103. );
  104. # Delete settings cache
  105. $Cache->delete('settings');
  106. # Run auto-cache to update board index
  107. require $nova_root . 'scripts/php/auto_cache.php';
  108. template_hook("pages/admin/topics.template.php", "form");
  109. nova_redirect("index.php?page=admin&act=topics","admin/topics");
  110. }
  111. else
  112. {
  113. nova_redirect("index.php?page=error&error=28","error/28");
  114. }
  115. }
  116. else
  117. {
  118. $token_id = md5(microtime());
  119. $token = md5(uniqid(rand(), true));
  120. $token_name = 'token_topics_' . $token_id;
  121. $_SESSION[$token_name] = $token;
  122. /*
  123. Get forums
  124. */
  125. $query = mysql_query('SELECT id, name, parent FROM ' . $db_prefix . 'categories');
  126. $forums = array();
  127. while ($row = mysql_fetch_assoc($query))
  128. {
  129. $forums[$row['parent']][$row['id']] = $row;
  130. }
  131. $trashcan = explode(';', $trashcan_delete_time);
  132. template_hook('pages/admin/topics.template.php', 2);
  133. }
  134. template_hook("pages/admin/topics.template.php", "end");
  135. ?>