PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/admin_forums.php

https://github.com/Dratone/EveBB
PHP | 542 lines | 407 code | 93 blank | 42 comment | 107 complexity | ca5a60da163fd2ff710d63bde13fda93 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Copyright (C) 2008-2010 FluxBB
  4. * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
  5. * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  6. */
  7. // Tell header.php to use the admin template
  8. define('PUN_ADMIN_CONSOLE', 1);
  9. define('PUN_ROOT', dirname(__FILE__).'/');
  10. require PUN_ROOT.'include/common.php';
  11. require PUN_ROOT.'include/common_admin.php';
  12. if ($pun_user['g_id'] != PUN_ADMIN)
  13. message($lang_common['No permission']);
  14. // Load the admin_forums.php language file
  15. require PUN_ROOT.'lang/'.$admin_language.'/admin_forums.php';
  16. // Add a "default" forum
  17. if (isset($_POST['add_forum']))
  18. {
  19. confirm_referrer('admin_forums.php');
  20. $add_to_cat = intval($_POST['add_to_cat']);
  21. if ($add_to_cat < 1)
  22. message($lang_common['Bad request']);
  23. $db->query('INSERT INTO '.$db->prefix.'forums (forum_name, cat_id) VALUES(\''.$db->escape($lang_admin_forums['New forum']).'\', '.$add_to_cat.')') or error('Unable to create forum', __FILE__, __LINE__, $db->error());
  24. // Regenerate the quick jump cache
  25. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  26. require PUN_ROOT.'include/cache.php';
  27. generate_quickjump_cache();
  28. redirect('admin_forums.php', $lang_admin_forums['Forum added redirect']);
  29. }
  30. // Delete a forum
  31. else if (isset($_GET['del_forum']))
  32. {
  33. confirm_referrer('admin_forums.php');
  34. $forum_id = intval($_GET['del_forum']);
  35. if ($forum_id < 1)
  36. message($lang_common['Bad request']);
  37. if (isset($_POST['del_forum_comply'])) // Delete a forum with all posts
  38. {
  39. @set_time_limit(0);
  40. // Prune all posts and topics
  41. prune($forum_id, 1, -1);
  42. // Locate any "orphaned redirect topics" and delete them
  43. $result = $db->query('SELECT t1.id FROM '.$db->prefix.'topics AS t1 LEFT JOIN '.$db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $db->error());
  44. $num_orphans = $db->num_rows($result);
  45. if ($num_orphans)
  46. {
  47. for ($i = 0; $i < $num_orphans; ++$i)
  48. $orphans[] = $db->result($result, $i);
  49. $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
  50. }
  51. // Delete the forum and any forum specific group permissions
  52. $db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to delete forum', __FILE__, __LINE__, $db->error());
  53. $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
  54. // Delete any subscriptions for this forum
  55. $db->query('DELETE FROM '.$db->prefix.'forum_subscriptions WHERE forum_id='.$forum_id) or error('Unable to delete subscriptions', __FILE__, __LINE__, $db->error());
  56. // Regenerate the quick jump cache
  57. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  58. require PUN_ROOT.'include/cache.php';
  59. generate_quickjump_cache();
  60. redirect('admin_forums.php', $lang_admin_forums['Forum deleted redirect']);
  61. }
  62. else // If the user hasn't confirmed the delete
  63. {
  64. $result = $db->query('SELECT forum_name FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
  65. $forum_name = pun_htmlspecialchars($db->result($result));
  66. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Forums']);
  67. define('PUN_ACTIVE_PAGE', 'admin');
  68. require PUN_ROOT.'header.php';
  69. generate_admin_menu('forums');
  70. ?>
  71. <div class="blockform">
  72. <h2><span><?php echo $lang_admin_forums['Confirm delete head'] ?></span></h2>
  73. <div class="box">
  74. <form method="post" action="admin_forums.php?del_forum=<?php echo $forum_id ?>">
  75. <div class="inform">
  76. <fieldset>
  77. <legend><?php echo $lang_admin_forums['Confirm delete subhead'] ?></legend>
  78. <div class="infldset">
  79. <p><?php printf($lang_admin_forums['Confirm delete info'], $forum_name) ?></p>
  80. <p class="warntext"><?php echo $lang_admin_forums['Confirm delete warn'] ?></p>
  81. </div>
  82. </fieldset>
  83. </div>
  84. <p class="buttons"><input type="submit" name="del_forum_comply" value="<?php echo $lang_admin_common['Delete'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_admin_common['Go back'] ?></a></p>
  85. </form>
  86. </div>
  87. </div>
  88. <div class="clearer"></div>
  89. </div>
  90. <?php
  91. require PUN_ROOT.'footer.php';
  92. }
  93. }
  94. // Update forum positions
  95. else if (isset($_POST['update_positions']))
  96. {
  97. confirm_referrer('admin_forums.php');
  98. foreach ($_POST['position'] as $forum_id => $disp_position)
  99. {
  100. $disp_position = trim($disp_position);
  101. if ($disp_position == '' || preg_match('/[^0-9]/', $disp_position))
  102. message($lang_admin_forums['Must be integer message']);
  103. $db->query('UPDATE '.$db->prefix.'forums SET disp_position='.$disp_position.' WHERE id='.intval($forum_id)) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
  104. }
  105. // Regenerate the quick jump cache
  106. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  107. require PUN_ROOT.'include/cache.php';
  108. generate_quickjump_cache();
  109. redirect('admin_forums.php', $lang_admin_forums['Forums updated redirect']);
  110. }
  111. else if (isset($_GET['edit_forum']))
  112. {
  113. $forum_id = intval($_GET['edit_forum']);
  114. if ($forum_id < 1)
  115. message($lang_common['Bad request']);
  116. // Update group permissions for $forum_id
  117. if (isset($_POST['save']))
  118. {
  119. confirm_referrer('admin_forums.php');
  120. // Start with the forum details
  121. $forum_name = pun_trim($_POST['forum_name']);
  122. $forum_desc = pun_linebreaks(pun_trim($_POST['forum_desc']));
  123. $cat_id = intval($_POST['cat_id']);
  124. $sort_by = intval($_POST['sort_by']);
  125. $redirect_url = isset($_POST['redirect_url']) ? trim($_POST['redirect_url']) : null;
  126. if ($forum_name == '')
  127. message($lang_admin_forums['Must enter name message']);
  128. if ($cat_id < 1)
  129. message($lang_common['Bad request']);
  130. $forum_desc = ($forum_desc != '') ? '\''.$db->escape($forum_desc).'\'' : 'NULL';
  131. $redirect_url = ($redirect_url != '') ? '\''.$db->escape($redirect_url).'\'' : 'NULL';
  132. $parent_forum_id = intval($_POST['parent_forum']);
  133. $db->query('UPDATE '.$db->prefix.'forums SET forum_name=\''.$db->escape($forum_name).'\', forum_desc='.$forum_desc.', redirect_url='.$redirect_url.', sort_by='.$sort_by.', cat_id='.$cat_id.', parent_forum_id='.$parent_forum_id.' WHERE id='.$forum_id) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
  134. // Now let's deal with the permissions
  135. if (isset($_POST['read_forum_old']))
  136. {
  137. $result = $db->query('SELECT g_id, g_read_board, g_post_replies, g_post_topics FROM '.$db->prefix.'groups WHERE g_id!='.PUN_ADMIN) or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
  138. while ($cur_group = $db->fetch_assoc($result))
  139. {
  140. $read_forum_new = ($cur_group['g_read_board'] == '1') ? isset($_POST['read_forum_new'][$cur_group['g_id']]) ? '1' : '0' : intval($_POST['read_forum_old'][$cur_group['g_id']]);
  141. $post_replies_new = isset($_POST['post_replies_new'][$cur_group['g_id']]) ? '1' : '0';
  142. $post_topics_new = isset($_POST['post_topics_new'][$cur_group['g_id']]) ? '1' : '0';
  143. $fields = array(
  144. 'forum_id' => $forum_id,
  145. 'group_id' => $cur_group['g_id'],
  146. 'read_forum' => $read_forum_new,
  147. 'post_replies' => $post_replies_new,
  148. 'post_topics' => $post_topics_new
  149. );
  150. if (!$db->insert_or_update($fields, array('forum_id', 'group_id'), $db->prefix.'forum_perms')) {
  151. if (defined('PUN_DEBUG')) {
  152. error('Unable to add group to table.', __FILE__, __LINE__, $db->error());
  153. } //End if.
  154. $log .= "[".$cur_group['g_id']."]: Unable to add permissions [".$old_group."].\n";
  155. continue;
  156. } //End if.
  157. // Check if the new settings differ from the old
  158. /*if ($read_forum_new != $_POST['read_forum_old'][$cur_group['g_id']] || $post_replies_new != $_POST['post_replies_old'][$cur_group['g_id']] || $post_topics_new != $_POST['post_topics_old'][$cur_group['g_id']])
  159. {
  160. // If the new settings are identical to the default settings for this group, delete it's row in forum_perms
  161. if ($read_forum_new == '1' && $post_replies_new == $cur_group['g_post_replies'] && $post_topics_new == $cur_group['g_post_topics'])
  162. $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
  163. else
  164. {
  165. // Run an UPDATE and see if it affected a row, if not, INSERT
  166. $db->query('UPDATE '.$db->prefix.'forum_perms SET read_forum='.$read_forum_new.', post_replies='.$post_replies_new.', post_topics='.$post_topics_new.' WHERE group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id) or error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error());
  167. if (!$db->affected_rows())
  168. $db->query('INSERT INTO '.$db->prefix.'forum_perms (group_id, forum_id, read_forum, post_replies, post_topics) VALUES('.$cur_group['g_id'].', '.$forum_id.', '.$read_forum_new.', '.$post_replies_new.', '.$post_topics_new.')') or error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error());
  169. }
  170. }*/
  171. }
  172. }
  173. // Regenerate the quick jump cache
  174. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  175. require PUN_ROOT.'include/cache.php';
  176. generate_quickjump_cache();
  177. //message($lang_admin_forums['Forum updated redirect'].'<br/>
  178. //<br/>
  179. //<div class="codebox"><pre class="vscroll"><code>'.$log.'</code></pre></div>');
  180. redirect('admin_forums.php', $lang_admin_forums['Forum updated redirect']);
  181. }
  182. else if (isset($_POST['revert_perms']))
  183. {
  184. confirm_referrer('admin_forums.php');
  185. $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
  186. // Regenerate the quick jump cache
  187. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  188. require PUN_ROOT.'include/cache.php';
  189. generate_quickjump_cache();
  190. redirect('admin_forums.php?edit_forum='.$forum_id, $lang_admin_forums['Perms reverted redirect']);
  191. }
  192. // Fetch forum info
  193. $result = $db->query('SELECT id, forum_name, forum_desc, redirect_url, num_topics, sort_by, cat_id, parent_forum_id FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
  194. if (!$db->num_rows($result))
  195. message($lang_common['Bad request']);
  196. $cur_forum = $db->fetch_assoc($result);
  197. if (file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/sub_forum.php'))
  198. require PUN_ROOT.'lang/'.$pun_user['language'].'/sub_forum.php';
  199. else
  200. require PUN_ROOT.'lang/English/sub_forum.php';
  201. $parent_forums = Array();
  202. $result = $db->query('SELECT DISTINCT parent_forum_id FROM '.$db->prefix.'forums WHERE parent_forum_id != 0');
  203. while ($r = $db->fetch_row($result))
  204. $parent_forums[] = $r[0];
  205. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Forums']);
  206. define('PUN_ACTIVE_PAGE', 'admin');
  207. require PUN_ROOT.'header.php';
  208. generate_admin_menu('forums');
  209. ?>
  210. <div class="blockform">
  211. <h2><span><?php echo $lang_admin_forums['Edit forum head'] ?></span></h2>
  212. <div class="box">
  213. <form id="edit_forum" method="post" action="admin_forums.php?edit_forum=<?php echo $forum_id ?>">
  214. <p class="submittop"><input type="submit" name="save" value="<?php echo $lang_admin_common['Save changes'] ?>" tabindex="6" /></p>
  215. <div class="inform">
  216. <fieldset>
  217. <legend><?php echo $lang_admin_forums['Edit details subhead'] ?></legend>
  218. <div class="infldset">
  219. <table class="aligntop" cellspacing="0">
  220. <tr>
  221. <th scope="row"><?php echo $lang_admin_forums['Forum name label'] ?></th>
  222. <td><input type="text" name="forum_name" size="35" maxlength="80" value="<?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?>" tabindex="1" /></td>
  223. </tr>
  224. <tr>
  225. <th scope="row"><?php echo $lang_admin_forums['Forum description label'] ?></th>
  226. <td><textarea name="forum_desc" rows="3" cols="50" tabindex="2"><?php echo pun_htmlspecialchars($cur_forum['forum_desc']) ?></textarea></td>
  227. </tr>
  228. <tr>
  229. <th scope="row"><?php echo $lang_admin_forums['Category label'] ?></th>
  230. <td>
  231. <select name="cat_id" tabindex="3">
  232. <?php
  233. $result = $db->query('SELECT id, cat_name FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
  234. while ($cur_cat = $db->fetch_assoc($result))
  235. {
  236. $selected = ($cur_cat['id'] == $cur_forum['cat_id']) ? ' selected="selected"' : '';
  237. echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_cat['id'].'"'.$selected.'>'.pun_htmlspecialchars($cur_cat['cat_name']).'</option>'."\n";
  238. }
  239. ?>
  240. </select>
  241. </td>
  242. </tr>
  243. <tr>
  244. <th scope="row"><?php echo $lang_admin_forums['Sort by label'] ?></th>
  245. <td>
  246. <select name="sort_by" tabindex="4">
  247. <option value="0"<?php if ($cur_forum['sort_by'] == '0') echo ' selected="selected"' ?>><?php echo $lang_admin_forums['Last post'] ?></option>
  248. <option value="1"<?php if ($cur_forum['sort_by'] == '1') echo ' selected="selected"' ?>><?php echo $lang_admin_forums['Topic start'] ?></option>
  249. <option value="2"<?php if ($cur_forum['sort_by'] == '2') echo ' selected="selected"' ?>><?php echo $lang_admin_forums['Subject'] ?></option>
  250. </select>
  251. </td>
  252. </tr>
  253. <tr>
  254. <th scope="row"><?php echo $lang_admin_forums['Redirect label'] ?></th>
  255. <td><?php echo ($cur_forum['num_topics']) ? $lang_admin_forums['Redirect help'] : '<input type="text" name="redirect_url" size="45" maxlength="100" value="'.pun_htmlspecialchars($cur_forum['redirect_url']).'" tabindex="5" />'; ?></td>
  256. </tr>
  257. <tr>
  258. <th scope="row"><?php echo $lang_sub_forum['Parent forum'] ?></th>
  259. <td>
  260. <select name="parent_forum">
  261. <option value="0"><?php echo $lang_sub_forum['No parent forum'] ?></option>
  262. <?php
  263. if (!in_array($cur_forum['id'],$parent_forums))
  264. {
  265. $result = $db->query('SELECT c.id AS cid, c.cat_name, f.id, f.forum_name, f.redirect_url, f.parent_forum_id FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
  266. $cur_category = 0;
  267. while ($forum_list = $db->fetch_assoc($result))
  268. {
  269. if ($forum_list['cid'] != $cur_category) // A new category since last iteration?
  270. {
  271. if ($cur_category)
  272. echo "\t\t\t\t\t\t".'</optgroup>'."\n";
  273. echo "\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($forum_list['cat_name']).'">'."\n";
  274. $cur_category = $forum_list['cid'];
  275. }
  276. $selected = ($forum_list['id'] == $cur_forum['parent_forum_id']) ? ' selected="selected"' : '';
  277. if(!$forum_list['parent_forum_id'] && $forum_list['id'] != $cur_forum['id'])
  278. echo "\t\t\t\t\t\t\t".'<option value="'.$forum_list['id'].'"'.$selected.'>'.pun_htmlspecialchars($forum_list['forum_name']).'</option>'."\n";
  279. }
  280. }
  281. ?>
  282. </optgroup>
  283. </select>
  284. </td>
  285. </tr>
  286. </table>
  287. </div>
  288. </fieldset>
  289. </div>
  290. <div class="inform">
  291. <fieldset>
  292. <legend><?php echo $lang_admin_forums['Group permissions subhead'] ?></legend>
  293. <div class="infldset">
  294. <p><?php printf($lang_admin_forums['Group permissions info'], '<a href="admin_groups.php">'.$lang_admin_common['User groups'].'</a>') ?></p>
  295. <table id="forumperms" cellspacing="0">
  296. <thead>
  297. <tr>
  298. <th class="atcl">&#160;</th>
  299. <th><?php echo $lang_admin_forums['Read forum label'] ?></th>
  300. <th><?php echo $lang_admin_forums['Post replies label'] ?></th>
  301. <th><?php echo $lang_admin_forums['Post topics label'] ?></th>
  302. </tr>
  303. </thead>
  304. <tbody>
  305. <?php
  306. $result = $db->query('SELECT g.g_id, g.g_title, g.g_read_board, g.g_post_replies, g.g_post_topics, fp.read_forum, fp.post_replies, fp.post_topics FROM '.$db->prefix.'groups AS g LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (g.g_id=fp.group_id AND fp.forum_id='.$forum_id.') WHERE g.g_id!='.PUN_ADMIN.' ORDER BY g.g_id') or error('Unable to fetch group forum permission list', __FILE__, __LINE__, $db->error());
  307. while ($cur_perm = $db->fetch_assoc($result))
  308. {
  309. $read_forum = ($cur_perm['read_forum'] != '0') ? true : false;
  310. $post_replies = (($cur_perm['g_post_replies'] == '0' && $cur_perm['post_replies'] == '1') || ($cur_perm['g_post_replies'] == '1' && $cur_perm['post_replies'] != '0')) ? true : false;
  311. $post_topics = (($cur_perm['g_post_topics'] == '0' && $cur_perm['post_topics'] == '1') || ($cur_perm['g_post_topics'] == '1' && $cur_perm['post_topics'] != '0')) ? true : false;
  312. // Determine if the current settings differ from the default or not
  313. $read_forum_def = ($cur_perm['read_forum'] == '0') ? false : true;
  314. $post_replies_def = (($post_replies && $cur_perm['g_post_replies'] == '0') || (!$post_replies && ($cur_perm['g_post_replies'] == '' || $cur_perm['g_post_replies'] == '1'))) ? false : true;
  315. $post_topics_def = (($post_topics && $cur_perm['g_post_topics'] == '0') || (!$post_topics && ($cur_perm['g_post_topics'] == '' || $cur_perm['g_post_topics'] == '1'))) ? false : true;
  316. ?>
  317. <tr>
  318. <th class="atcl"><?php echo pun_htmlspecialchars($cur_perm['g_title']) ?></th>
  319. <td<?php if (!$read_forum_def) echo ' class="nodefault"'; ?>>
  320. <input type="hidden" name="read_forum_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($read_forum) ? '1' : '0'; ?>" />
  321. <input type="checkbox" name="read_forum_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($read_forum) ? ' checked="checked"' : ''; ?><?php echo ($cur_perm['g_read_board'] == '0') ? ' disabled="disabled"' : ''; ?> />
  322. </td>
  323. <td<?php if (!$post_replies_def && $cur_forum['redirect_url'] == '') echo ' class="nodefault"'; ?>>
  324. <input type="hidden" name="post_replies_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($post_replies) ? '1' : '0'; ?>" />
  325. <input type="checkbox" name="post_replies_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($post_replies) ? ' checked="checked"' : ''; ?><?php echo ($cur_forum['redirect_url'] != '') ? ' disabled="disabled"' : ''; ?> />
  326. </td>
  327. <td<?php if (!$post_topics_def && $cur_forum['redirect_url'] == '') echo ' class="nodefault"'; ?>>
  328. <input type="hidden" name="post_topics_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($post_topics) ? '1' : '0'; ?>" />
  329. <input type="checkbox" name="post_topics_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($post_topics) ? ' checked="checked"' : ''; ?><?php echo ($cur_forum['redirect_url'] != '') ? ' disabled="disabled"' : ''; ?> />
  330. </td>
  331. </tr>
  332. <?php
  333. }
  334. ?>
  335. </tbody>
  336. </table>
  337. <div class="fsetsubmit"><input type="submit" name="revert_perms" value="<?php echo $lang_admin_forums['Revert to default'] ?>" /></div>
  338. </div>
  339. </fieldset>
  340. </div>
  341. <p class="submitend"><input type="submit" name="save" value="<?php echo $lang_admin_common['Save changes'] ?>" /></p>
  342. </form>
  343. </div>
  344. </div>
  345. <div class="clearer"></div>
  346. </div>
  347. <?php
  348. require PUN_ROOT.'footer.php';
  349. }
  350. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Forums']);
  351. define('PUN_ACTIVE_PAGE', 'admin');
  352. require PUN_ROOT.'header.php';
  353. generate_admin_menu('forums');
  354. ?>
  355. <div class="blockform">
  356. <h2><span><?php echo $lang_admin_forums['Add forum head'] ?></span></h2>
  357. <div class="box">
  358. <form method="post" action="admin_forums.php?action=adddel">
  359. <div class="inform">
  360. <fieldset>
  361. <legend><?php echo $lang_admin_forums['Create new subhead'] ?></legend>
  362. <div class="infldset">
  363. <table class="aligntop" cellspacing="0">
  364. <tr>
  365. <th scope="row"><?php echo $lang_admin_forums['Add forum label'] ?><div><input type="submit" name="add_forum" value="<?php echo $lang_admin_forums['Add forum'] ?>" tabindex="2" /></div></th>
  366. <td>
  367. <select name="add_to_cat" tabindex="1">
  368. <?php
  369. $result = $db->query('SELECT id, cat_name FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
  370. if ($db->num_rows($result) > 0)
  371. {
  372. while ($cur_cat = $db->fetch_assoc($result))
  373. echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_cat['id'].'">'.pun_htmlspecialchars($cur_cat['cat_name']).'</option>'."\n";
  374. }
  375. else
  376. echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="0" disabled="disabled">'.$lang_admin_forums['No categories exist'].'</option>'."\n";
  377. ?>
  378. </select>
  379. <span><?php echo $lang_admin_forums['Add forum help'] ?></span>
  380. </td>
  381. </tr>
  382. </table>
  383. </div>
  384. </fieldset>
  385. </div>
  386. </form>
  387. </div>
  388. <?php
  389. // Display all the categories and forums
  390. $result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.disp_position, f.parent_forum_id FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
  391. if ($db->num_rows($result) > 0)
  392. {
  393. ?>
  394. <h2 class="block2"><span><?php echo $lang_admin_forums['Edit forums head'] ?></span></h2>
  395. <div class="box">
  396. <form id="edforum" method="post" action="admin_forums.php?action=edit">
  397. <p class="submittop"><input type="submit" name="update_positions" value="<?php echo $lang_admin_forums['Update positions'] ?>" tabindex="3" /></p>
  398. <?php
  399. $tabindex_count = 4;
  400. $cur_category = 0;
  401. while ($cur_forum = $db->fetch_assoc($result))
  402. {
  403. if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
  404. {
  405. if ($cur_category != 0)
  406. echo "\t\t\t\t\t\t\t".'</tbody>'."\n\t\t\t\t\t\t\t".'</table>'."\n\t\t\t\t\t\t".'</div>'."\n\t\t\t\t\t".'</fieldset>'."\n\t\t\t\t".'</div>'."\n";
  407. ?>
  408. <div class="inform">
  409. <fieldset>
  410. <legend><?php echo $lang_admin_forums['Category subhead'] ?> <?php echo pun_htmlspecialchars($cur_forum['cat_name']) ?></legend>
  411. <div class="infldset">
  412. <table cellspacing="0">
  413. <thead>
  414. <tr>
  415. <th class="tcl"><?php echo $lang_admin_common['Action'] ?></th>
  416. <th class="tc2"><?php echo $lang_admin_forums['Position label'] ?></th>
  417. <th class="tcr"><?php echo $lang_admin_forums['Forum label'] ?></th>
  418. </tr>
  419. </thead>
  420. <tbody>
  421. <?php
  422. $cur_category = $cur_forum['cid'];
  423. }
  424. ?>
  425. <tr>
  426. <td class="tcl"><a href="admin_forums.php?edit_forum=<?php echo $cur_forum['fid'] ?>"><?php echo $lang_admin_forums['Edit link'] ?></a> | <a href="admin_forums.php?del_forum=<?php echo $cur_forum['fid'] ?>"><?php echo $lang_admin_forums['Delete link'] ?></a></td>
  427. <td class="tc2"><input type="text" name="position[<?php echo $cur_forum['fid'] ?>]" size="3" maxlength="3" value="<?php echo $cur_forum['disp_position'] ?>" tabindex="<?php echo $tabindex_count ?>" /></td>
  428. <td class="tcr"><strong><?php echo ($cur_forum['parent_forum_id'] == 0 ? '' : '&nbsp;&nbsp;&nbsp;').pun_htmlspecialchars($cur_forum['forum_name']) ?></strong></td>
  429. </tr>
  430. <?php
  431. $tabindex_count += 2;
  432. }
  433. ?>
  434. </tbody>
  435. </table>
  436. </div>
  437. </fieldset>
  438. </div>
  439. <p class="submitend"><input type="submit" name="update_positions" value="<?php echo $lang_admin_forums['Update positions'] ?>" tabindex="<?php echo $tabindex_count ?>" /></p>
  440. </form>
  441. </div>
  442. <?php
  443. }
  444. ?>
  445. </div>
  446. <div class="clearer"></div>
  447. </div>
  448. <?php
  449. require PUN_ROOT.'footer.php';