[6] | 1 | <?php |
---|
| 2 | |
---|
| 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 | */ |
---|
| 8 | |
---|
| 9 | // Tell header.php to use the admin template |
---|
| 10 | define('PUN_ADMIN_CONSOLE', 1); |
---|
| 11 | |
---|
| 12 | define('PUN_ROOT', dirname(__FILE__).'/'); |
---|
| 13 | require PUN_ROOT.'include/common.php'; |
---|
| 14 | require PUN_ROOT.'include/common_admin.php'; |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | if ($pun_user['g_id'] != PUN_ADMIN) |
---|
| 18 | message($lang_common['No permission']); |
---|
| 19 | |
---|
| 20 | // Load the admin_categories.php language file |
---|
| 21 | require PUN_ROOT.'lang/'.$admin_language.'/admin_categories.php'; |
---|
| 22 | |
---|
| 23 | // Add a new category |
---|
| 24 | if (isset($_POST['add_cat'])) |
---|
| 25 | { |
---|
| 26 | confirm_referrer('admin_categories.php'); |
---|
| 27 | |
---|
| 28 | $new_cat_name = pun_trim($_POST['new_cat_name']); |
---|
| 29 | if ($new_cat_name == '') |
---|
| 30 | message($lang_admin_categories['Must enter name message']); |
---|
| 31 | |
---|
| 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()); |
---|
| 33 | |
---|
| 34 | redirect('admin_categories.php', $lang_admin_categories['Category added redirect']); |
---|
| 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 | |
---|
| 46 | if (isset($_POST['del_cat_comply'])) // Delete a category with all forums and posts |
---|
| 47 | { |
---|
| 48 | @set_time_limit(0); |
---|
| 49 | |
---|
| 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()); |
---|
| 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 |
---|
| 61 | $db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$cur_forum) or error('Unable to delete forum', __FILE__, __LINE__, $db->error()); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | // Locate any "orphaned redirect topics" and delete them |
---|
| 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()); |
---|
| 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 | |
---|
| 73 | $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error()); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | // Delete the category |
---|
| 77 | $db->query('DELETE FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to delete category', __FILE__, __LINE__, $db->error()); |
---|
| 78 | |
---|
| 79 | // Regenerate the quick jump cache |
---|
| 80 | if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) |
---|
| 81 | require PUN_ROOT.'include/cache.php'; |
---|
| 82 | |
---|
| 83 | generate_quickjump_cache(); |
---|
| 84 | |
---|
| 85 | redirect('admin_categories.php', $lang_admin_categories['Category deleted redirect']); |
---|
| 86 | } |
---|
| 87 | else // If the user hasn't comfirmed the delete |
---|
| 88 | { |
---|
| 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()); |
---|
| 90 | $cat_name = $db->result($result); |
---|
| 91 | |
---|
| 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'); |
---|
| 94 | require PUN_ROOT.'header.php'; |
---|
| 95 | |
---|
| 96 | generate_admin_menu('categories'); |
---|
| 97 | |
---|
| 98 | ?> |
---|
| 99 | <div class="blockform"> |
---|
| 100 | <h2><span><?php echo $lang_admin_categories['Delete category head'] ?></span></h2> |
---|
| 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> |
---|
| 106 | <legend><?php echo $lang_admin_categories['Confirm delete subhead'] ?></legend> |
---|
| 107 | <div class="infldset"> |
---|
| 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> |
---|
| 110 | </div> |
---|
| 111 | </fieldset> |
---|
| 112 | </div> |
---|
| 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> |
---|
| 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 | |
---|
| 125 | else if (isset($_POST['update'])) // Change position and name of the categories |
---|
| 126 | { |
---|
| 127 | confirm_referrer('admin_categories.php'); |
---|
| 128 | |
---|
| 129 | $categories = $_POST['cat']; |
---|
| 130 | if (empty($categories)) |
---|
| 131 | message($lang_common['Bad request']); |
---|
| 132 | |
---|
| 133 | foreach ($categories as $cat_id => $cur_cat) |
---|
| 134 | { |
---|
| 135 | $cur_cat['name'] = pun_trim($cur_cat['name']); |
---|
| 136 | $cur_cat['order'] = trim($cur_cat['order']); |
---|
| 137 | |
---|
| 138 | if ($cur_cat['name'] == '') |
---|
| 139 | message($lang_admin_categories['Must enter name message']); |
---|
| 140 | |
---|
| 141 | if ($cur_cat['order'] == '' || preg_match('%[^0-9]%', $cur_cat['order'])) |
---|
| 142 | message($lang_admin_categories['Must enter integer message']); |
---|
| 143 | |
---|
| 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()); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | // Regenerate the quick jump cache |
---|
| 148 | if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) |
---|
| 149 | require PUN_ROOT.'include/cache.php'; |
---|
| 150 | |
---|
| 151 | generate_quickjump_cache(); |
---|
| 152 | |
---|
| 153 | redirect('admin_categories.php', $lang_admin_categories['Categories updated redirect']); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | // Generate an array with all categories |
---|
| 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()); |
---|
| 158 | $num_cats = $db->num_rows($result); |
---|
| 159 | |
---|
| 160 | for ($i = 0; $i < $num_cats; ++$i) |
---|
| 161 | $cat_list[] = $db->fetch_assoc($result); |
---|
| 162 | |
---|
| 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'); |
---|
| 165 | require PUN_ROOT.'header.php'; |
---|
| 166 | |
---|
| 167 | generate_admin_menu('categories'); |
---|
| 168 | |
---|
| 169 | ?> |
---|
| 170 | <div class="blockform"> |
---|
| 171 | <h2><span><?php echo $lang_admin_categories['Add categories head'] ?></span></h2> |
---|
| 172 | <div class="box"> |
---|
| 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"> |
---|
| 205 | <?php |
---|
| 206 | |
---|
| 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"; |
---|
| 209 | |
---|
| 210 | ?> |
---|
| 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> |
---|
| 238 | <?php |
---|
| 239 | |
---|
| 240 | foreach ($cat_list as $cur_cat) |
---|
| 241 | { |
---|
| 242 | |
---|
| 243 | ?> |
---|
| 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> |
---|
| 248 | <?php |
---|
| 249 | |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | ?> |
---|
| 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> |
---|
| 260 | </div> |
---|
| 261 | <?php endif; ?> </div> |
---|
| 262 | <div class="clearer"></div> |
---|
| 263 | </div> |
---|
| 264 | <?php |
---|
| 265 | |
---|
| 266 | require PUN_ROOT.'footer.php'; |
---|