[1] | 1 | <?php |
---|
| 2 | |
---|
[3] | 3 | /** |
---|
| 4 | * Copyright (C) 2008-2011 FluxBB |
---|
| 5 | * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB |
---|
| 6 | * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher |
---|
| 7 | */ |
---|
[1] | 8 | |
---|
| 9 | // Tell header.php to use the admin template |
---|
| 10 | define('PUN_ADMIN_CONSOLE', 1); |
---|
| 11 | |
---|
[3] | 12 | define('PUN_ROOT', dirname(__FILE__).'/'); |
---|
[1] | 13 | require PUN_ROOT.'include/common.php'; |
---|
| 14 | require PUN_ROOT.'include/common_admin.php'; |
---|
| 15 | |
---|
| 16 | |
---|
[3] | 17 | if ($pun_user['g_id'] != PUN_ADMIN) |
---|
[1] | 18 | message($lang_common['No permission']); |
---|
| 19 | |
---|
[3] | 20 | // Load the admin_categories.php language file |
---|
| 21 | require PUN_ROOT.'lang/'.$admin_language.'/admin_categories.php'; |
---|
[1] | 22 | |
---|
| 23 | // Add a new category |
---|
| 24 | if (isset($_POST['add_cat'])) |
---|
| 25 | { |
---|
| 26 | confirm_referrer('admin_categories.php'); |
---|
| 27 | |
---|
[3] | 28 | $new_cat_name = pun_trim($_POST['new_cat_name']); |
---|
[1] | 29 | if ($new_cat_name == '') |
---|
[3] | 30 | message($lang_admin_categories['Must enter name message']); |
---|
[1] | 31 | |
---|
[3] | 32 | $db->query('INSERT INTO '.$db->prefix.'categories (cat_name) VALUES(\''.$db->escape($new_cat_name).'\')') or error('Unable to create category', __FILE__, __LINE__, $db->error()); |
---|
[1] | 33 | |
---|
[3] | 34 | redirect('admin_categories.php', $lang_admin_categories['Category added redirect']); |
---|
[1] | 35 | } |
---|
| 36 | |
---|
| 37 | // Delete a category |
---|
| 38 | else if (isset($_POST['del_cat']) || isset($_POST['del_cat_comply'])) |
---|
| 39 | { |
---|
| 40 | confirm_referrer('admin_categories.php'); |
---|
| 41 | |
---|
| 42 | $cat_to_delete = intval($_POST['cat_to_delete']); |
---|
| 43 | if ($cat_to_delete < 1) |
---|
| 44 | message($lang_common['Bad request']); |
---|
| 45 | |
---|
[3] | 46 | if (isset($_POST['del_cat_comply'])) // Delete a category with all forums and posts |
---|
[1] | 47 | { |
---|
| 48 | @set_time_limit(0); |
---|
| 49 | |
---|
[3] | 50 | $result = $db->query('SELECT id FROM '.$db->prefix.'forums WHERE cat_id='.$cat_to_delete) or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error()); |
---|
[1] | 51 | $num_forums = $db->num_rows($result); |
---|
| 52 | |
---|
| 53 | for ($i = 0; $i < $num_forums; ++$i) |
---|
| 54 | { |
---|
| 55 | $cur_forum = $db->result($result, $i); |
---|
| 56 | |
---|
| 57 | // Prune all posts and topics |
---|
| 58 | prune($cur_forum, 1, -1); |
---|
| 59 | |
---|
| 60 | // Delete the forum |
---|
[3] | 61 | $db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$cur_forum) or error('Unable to delete forum', __FILE__, __LINE__, $db->error()); |
---|
[1] | 62 | } |
---|
| 63 | |
---|
| 64 | // Locate any "orphaned redirect topics" and delete them |
---|
[3] | 65 | $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()); |
---|
[1] | 66 | $num_orphans = $db->num_rows($result); |
---|
| 67 | |
---|
| 68 | if ($num_orphans) |
---|
| 69 | { |
---|
| 70 | for ($i = 0; $i < $num_orphans; ++$i) |
---|
| 71 | $orphans[] = $db->result($result, $i); |
---|
| 72 | |
---|
[3] | 73 | $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error()); |
---|
[1] | 74 | } |
---|
| 75 | |
---|
| 76 | // Delete the category |
---|
[3] | 77 | $db->query('DELETE FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to delete category', __FILE__, __LINE__, $db->error()); |
---|
[1] | 78 | |
---|
[3] | 79 | // Regenerate the quick jump cache |
---|
| 80 | if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) |
---|
| 81 | require PUN_ROOT.'include/cache.php'; |
---|
| 82 | |
---|
[1] | 83 | generate_quickjump_cache(); |
---|
| 84 | |
---|
[3] | 85 | redirect('admin_categories.php', $lang_admin_categories['Category deleted redirect']); |
---|
[1] | 86 | } |
---|
[3] | 87 | else // If the user hasn't comfirmed the delete |
---|
[1] | 88 | { |
---|
[3] | 89 | $result = $db->query('SELECT cat_name FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to fetch category info', __FILE__, __LINE__, $db->error()); |
---|
[1] | 90 | $cat_name = $db->result($result); |
---|
| 91 | |
---|
[3] | 92 | $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Categories']); |
---|
| 93 | define('PUN_ACTIVE_PAGE', 'admin'); |
---|
[1] | 94 | require PUN_ROOT.'header.php'; |
---|
| 95 | |
---|
| 96 | generate_admin_menu('categories'); |
---|
| 97 | |
---|
| 98 | ?> |
---|
| 99 | <div class="blockform"> |
---|
[3] | 100 | <h2><span><?php echo $lang_admin_categories['Delete category head'] ?></span></h2> |
---|
[1] | 101 | <div class="box"> |
---|
| 102 | <form method="post" action="admin_categories.php"> |
---|
| 103 | <div class="inform"> |
---|
| 104 | <input type="hidden" name="cat_to_delete" value="<?php echo $cat_to_delete ?>" /> |
---|
| 105 | <fieldset> |
---|
[3] | 106 | <legend><?php echo $lang_admin_categories['Confirm delete subhead'] ?></legend> |
---|
[1] | 107 | <div class="infldset"> |
---|
[3] | 108 | <p><?php printf($lang_admin_categories['Confirm delete info'], pun_htmlspecialchars($cat_name)) ?></p> |
---|
| 109 | <p class="warntext"><?php echo $lang_admin_categories['Delete category warn'] ?></p> |
---|
[1] | 110 | </div> |
---|
| 111 | </fieldset> |
---|
| 112 | </div> |
---|
[3] | 113 | <p class="buttons"><input type="submit" name="del_cat_comply" value="<?php echo $lang_admin_common['Delete'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_admin_common['Go back'] ?></a></p> |
---|
[1] | 114 | </form> |
---|
| 115 | </div> |
---|
| 116 | </div> |
---|
| 117 | <div class="clearer"></div> |
---|
| 118 | </div> |
---|
| 119 | <?php |
---|
| 120 | |
---|
| 121 | require PUN_ROOT.'footer.php'; |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | |
---|
[3] | 125 | else if (isset($_POST['update'])) // Change position and name of the categories |
---|
[1] | 126 | { |
---|
| 127 | confirm_referrer('admin_categories.php'); |
---|
| 128 | |
---|
[3] | 129 | $categories = $_POST['cat']; |
---|
| 130 | if (empty($categories)) |
---|
| 131 | message($lang_common['Bad request']); |
---|
[1] | 132 | |
---|
[3] | 133 | foreach ($categories as $cat_id => $cur_cat) |
---|
[1] | 134 | { |
---|
[3] | 135 | $cur_cat['name'] = pun_trim($cur_cat['name']); |
---|
| 136 | $cur_cat['order'] = trim($cur_cat['order']); |
---|
[1] | 137 | |
---|
[3] | 138 | if ($cur_cat['name'] == '') |
---|
| 139 | message($lang_admin_categories['Must enter name message']); |
---|
[1] | 140 | |
---|
[3] | 141 | if ($cur_cat['order'] == '' || preg_match('%[^0-9]%', $cur_cat['order'])) |
---|
| 142 | message($lang_admin_categories['Must enter integer message']); |
---|
[1] | 143 | |
---|
[3] | 144 | $db->query('UPDATE '.$db->prefix.'categories SET cat_name=\''.$db->escape($cur_cat['name']).'\', disp_position='.$cur_cat['order'].' WHERE id='.intval($cat_id)) or error('Unable to update category', __FILE__, __LINE__, $db->error()); |
---|
[1] | 145 | } |
---|
| 146 | |
---|
[3] | 147 | // Regenerate the quick jump cache |
---|
| 148 | if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) |
---|
| 149 | require PUN_ROOT.'include/cache.php'; |
---|
| 150 | |
---|
[1] | 151 | generate_quickjump_cache(); |
---|
| 152 | |
---|
[3] | 153 | redirect('admin_categories.php', $lang_admin_categories['Categories updated redirect']); |
---|
[1] | 154 | } |
---|
| 155 | |
---|
| 156 | // Generate an array with all categories |
---|
[3] | 157 | $result = $db->query('SELECT id, cat_name, disp_position FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error()); |
---|
[1] | 158 | $num_cats = $db->num_rows($result); |
---|
| 159 | |
---|
| 160 | for ($i = 0; $i < $num_cats; ++$i) |
---|
[3] | 161 | $cat_list[] = $db->fetch_assoc($result); |
---|
[1] | 162 | |
---|
[3] | 163 | $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Categories']); |
---|
| 164 | define('PUN_ACTIVE_PAGE', 'admin'); |
---|
[1] | 165 | require PUN_ROOT.'header.php'; |
---|
| 166 | |
---|
| 167 | generate_admin_menu('categories'); |
---|
| 168 | |
---|
| 169 | ?> |
---|
| 170 | <div class="blockform"> |
---|
[3] | 171 | <h2><span><?php echo $lang_admin_categories['Add categories head'] ?></span></h2> |
---|
[1] | 172 | <div class="box"> |
---|
[3] | 173 | <form method="post" action="admin_categories.php"> |
---|
| 174 | <div class="inform"> |
---|
| 175 | <fieldset> |
---|
| 176 | <legend><?php echo $lang_admin_categories['Add categories subhead'] ?></legend> |
---|
| 177 | <div class="infldset"> |
---|
| 178 | <table class="aligntop" cellspacing="0"> |
---|
| 179 | <tr> |
---|
| 180 | <th scope="row"><?php echo $lang_admin_categories['Add category label'] ?><div><input type="submit" name="add_cat" value="<?php echo $lang_admin_categories['Add new submit'] ?>" tabindex="2" /></div></th> |
---|
| 181 | <td> |
---|
| 182 | <input type="text" name="new_cat_name" size="35" maxlength="80" tabindex="1" /> |
---|
| 183 | <span><?php printf($lang_admin_categories['Add category help'], '<a href="admin_forums.php">'.$lang_admin_common['Forums'].'</a>') ?></span> |
---|
| 184 | </td> |
---|
| 185 | </tr> |
---|
| 186 | </table> |
---|
| 187 | </div> |
---|
| 188 | </fieldset> |
---|
| 189 | </div> |
---|
| 190 | </form> |
---|
| 191 | </div> |
---|
| 192 | |
---|
| 193 | <?php if ($num_cats): ?> <h2 class="block2"><span><?php echo $lang_admin_categories['Delete categories head'] ?></span></h2> |
---|
| 194 | <div class="box"> |
---|
| 195 | <form method="post" action="admin_categories.php"> |
---|
| 196 | <div class="inform"> |
---|
| 197 | <fieldset> |
---|
| 198 | <legend><?php echo $lang_admin_categories['Delete categories subhead'] ?></legend> |
---|
| 199 | <div class="infldset"> |
---|
| 200 | <table class="aligntop" cellspacing="0"> |
---|
| 201 | <tr> |
---|
| 202 | <th scope="row"><?php echo $lang_admin_categories['Delete category label'] ?><div><input type="submit" name="del_cat" value="<?php echo $lang_admin_common['Delete'] ?>" tabindex="4" /></div></th> |
---|
| 203 | <td> |
---|
| 204 | <select name="cat_to_delete" tabindex="3"> |
---|
[1] | 205 | <?php |
---|
| 206 | |
---|
[3] | 207 | foreach ($cat_list as $cur_cat) |
---|
| 208 | 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"; |
---|
[1] | 209 | |
---|
| 210 | ?> |
---|
[3] | 211 | </select> |
---|
| 212 | <span><?php echo $lang_admin_categories['Delete category help'] ?></span> |
---|
| 213 | </td> |
---|
| 214 | </tr> |
---|
| 215 | </table> |
---|
| 216 | </div> |
---|
| 217 | </fieldset> |
---|
| 218 | </div> |
---|
| 219 | </form> |
---|
| 220 | </div> |
---|
| 221 | <?php endif; ?> |
---|
| 222 | |
---|
| 223 | <?php if ($num_cats): ?> <h2 class="block2"><span><?php echo $lang_admin_categories['Edit categories head'] ?></span></h2> |
---|
| 224 | <div class="box"> |
---|
| 225 | <form method="post" action="admin_categories.php"> |
---|
| 226 | <div class="inform"> |
---|
| 227 | <fieldset> |
---|
| 228 | <legend><?php echo $lang_admin_categories['Edit categories subhead'] ?></legend> |
---|
| 229 | <div class="infldset"> |
---|
| 230 | <table id="categoryedit" cellspacing="0" > |
---|
| 231 | <thead> |
---|
| 232 | <tr> |
---|
| 233 | <th class="tcl" scope="col"><?php echo $lang_admin_categories['Category name label'] ?></th> |
---|
| 234 | <th scope="col"><?php echo $lang_admin_categories['Category position label'] ?></th> |
---|
| 235 | </tr> |
---|
| 236 | </thead> |
---|
| 237 | <tbody> |
---|
[1] | 238 | <?php |
---|
| 239 | |
---|
[3] | 240 | foreach ($cat_list as $cur_cat) |
---|
[1] | 241 | { |
---|
| 242 | |
---|
| 243 | ?> |
---|
[3] | 244 | <tr> |
---|
| 245 | <td class="tcl"><input type="text" name="cat[<?php echo $cur_cat['id'] ?>][name]" value="<?php echo pun_htmlspecialchars($cur_cat['cat_name']) ?>" size="35" maxlength="80" /></td> |
---|
| 246 | <td><input type="text" name="cat[<?php echo $cur_cat['id'] ?>][order]" value="<?php echo $cur_cat['disp_position'] ?>" size="3" maxlength="3" /></td> |
---|
| 247 | </tr> |
---|
[1] | 248 | <?php |
---|
| 249 | |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | ?> |
---|
[3] | 253 | </tbody> |
---|
| 254 | </table> |
---|
| 255 | <div class="fsetsubmit"><input type="submit" name="update" value="<?php echo $lang_admin_common['Update'] ?>" /></div> |
---|
| 256 | </div> |
---|
| 257 | </fieldset> |
---|
| 258 | </div> |
---|
| 259 | </form> |
---|
[1] | 260 | </div> |
---|
[3] | 261 | <?php endif; ?> </div> |
---|
[1] | 262 | <div class="clearer"></div> |
---|
| 263 | </div> |
---|
| 264 | <?php |
---|
| 265 | |
---|
| 266 | require PUN_ROOT.'footer.php'; |
---|