Changeset 3 for branches/rsr.v5.1.dev/web/punbb/admin_categories.php
- Timestamp:
- Nov 14, 2011, 11:17:15 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rsr.v5.1.dev/web/punbb/admin_categories.php
r1 r3 1 1 <?php 2 /*********************************************************************** 3 4 Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org) 5 6 This file is part of PunBB. 7 8 PunBB is free software; you can redistribute it and/or modify it 9 under the terms of the GNU General Public License as published 10 by the Free Software Foundation; either version 2 of the License, 11 or (at your option) any later version. 12 13 PunBB is distributed in the hope that it will be useful, but 14 WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21 MA 02111-1307 USA 22 23 ************************************************************************/ 24 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 */ 25 8 26 9 // Tell header.php to use the admin template 27 10 define('PUN_ADMIN_CONSOLE', 1); 28 11 29 define('PUN_ROOT', './');12 define('PUN_ROOT', dirname(__FILE__).'/'); 30 13 require PUN_ROOT.'include/common.php'; 31 14 require PUN_ROOT.'include/common_admin.php'; 32 15 33 16 34 if ($pun_user['g_id'] >PUN_ADMIN)17 if ($pun_user['g_id'] != PUN_ADMIN) 35 18 message($lang_common['No permission']); 36 19 20 // Load the admin_categories.php language file 21 require PUN_ROOT.'lang/'.$admin_language.'/admin_categories.php'; 37 22 38 23 // Add a new category … … 41 26 confirm_referrer('admin_categories.php'); 42 27 43 $new_cat_name = trim($_POST['new_cat_name']);28 $new_cat_name = pun_trim($_POST['new_cat_name']); 44 29 if ($new_cat_name == '') 45 message( 'Vous devez saisir un nom pour la nouvelle catégorie.');46 47 $db->query('INSERT INTO '.$db->prefix.'categories (cat_name) VALUES(\''.$db->escape($new_cat_name).'\')') or error(' Impossible de créer la catégorie', __FILE__, __LINE__, $db->error());48 49 redirect('admin_categories.php', 'Catégorie ajoutée. Redirection ...');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']); 50 35 } 51 52 36 53 37 // Delete a category … … 60 44 message($lang_common['Bad request']); 61 45 62 if (isset($_POST['del_cat_comply'])) 46 if (isset($_POST['del_cat_comply'])) // Delete a category with all forums and posts 63 47 { 64 48 @set_time_limit(0); 65 49 66 $result = $db->query('SELECT id FROM '.$db->prefix.'forums WHERE cat_id='.$cat_to_delete) or error(' Impossible de retrouver la liste des forums', __FILE__, __LINE__, $db->error());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()); 67 51 $num_forums = $db->num_rows($result); 68 52 … … 75 59 76 60 // Delete the forum 77 $db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$cur_forum) or error(' Impossible de supprimer le forum', __FILE__, __LINE__, $db->error());61 $db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$cur_forum) or error('Unable to delete forum', __FILE__, __LINE__, $db->error()); 78 62 } 79 63 80 64 // Locate any "orphaned redirect topics" and delete them 81 $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(' Impossible de retrouver les sujets de redirection', __FILE__, __LINE__, $db->error());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()); 82 66 $num_orphans = $db->num_rows($result); 83 67 … … 87 71 $orphans[] = $db->result($result, $i); 88 72 89 $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error(' Impossible de supprimer les sujets de redirection', __FILE__, __LINE__, $db->error());73 $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error()); 90 74 } 91 75 92 76 // Delete the category 93 $db->query('DELETE FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Impossible de supprimer la catégorie', __FILE__, __LINE__, $db->error()); 94 95 // Regenerate the quickjump cache 96 require_once PUN_ROOT.'include/cache.php'; 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 97 83 generate_quickjump_cache(); 98 84 99 redirect('admin_categories.php', 'Catégorie supprimée. Redirection ...');100 } 101 else 102 { 103 $result = $db->query('SELECT cat_name FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error(' Impossible de retrouver les informations de la catégorie', __FILE__, __LINE__, $db->error());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()); 104 90 $cat_name = $db->result($result); 105 91 106 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Catégories'; 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'); 107 94 require PUN_ROOT.'header.php'; 108 95 … … 111 98 ?> 112 99 <div class="blockform"> 113 <h2><span> Supprimer une catégorie</span></h2>100 <h2><span><?php echo $lang_admin_categories['Delete category head'] ?></span></h2> 114 101 <div class="box"> 115 102 <form method="post" action="admin_categories.php"> … … 117 104 <input type="hidden" name="cat_to_delete" value="<?php echo $cat_to_delete ?>" /> 118 105 <fieldset> 119 <legend> Confirmez la supression de la catégorie</legend>120 <div class="infldset"> 121 <p> Ãtes vous sûr de vouloir supprimer la catégorie "<?php echo $cat_name ?>" ?</p>122 <p >ATTENTION ! Supprimer cette catégorie supprimera en même temps tous les forums et messages (s'il y en a) présents dans cette catégorie !</p>123 </div> 124 </fieldset> 125 </div> 126 <p ><input type="submit" name="del_cat_comply" value=" Supprimer " /><a href="javascript:history.go(-1)">Retour</a></p>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> 127 114 </form> 128 115 </div> … … 136 123 } 137 124 138 139 else if (isset($_POST['update'])) // Change position and name of the categories 125 else if (isset($_POST['update'])) // Change position and name of the categories 140 126 { 141 127 confirm_referrer('admin_categories.php'); 142 128 143 $cat_order = $_POST['cat_order']; 144 $cat_name = $_POST['cat_name']; 145 146 $result = $db->query('SELECT id, disp_position FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Impossible de retrouver la liste des catégories', __FILE__, __LINE__, $db->error()); 147 $num_cats = $db->num_rows($result); 148 149 for ($i = 0; $i < $num_cats; ++$i) 150 { 151 if ($cat_name[$i] == '') 152 message('Vous devez saisir un nom de catégorie.'); 153 154 if (!preg_match('#^\d+$#', $cat_order[$i])) 155 message('La position doit être un nombre entier.'); 156 157 list($cat_id, $position) = $db->fetch_row($result); 158 159 $db->query('UPDATE '.$db->prefix.'categories SET cat_name=\''.$db->escape($cat_name[$i]).'\', disp_position='.$cat_order[$i].' WHERE id='.$cat_id) or error('Impossible de modifier les catégories', __FILE__, __LINE__, $db->error()); 160 } 161 162 // Regenerate the quickjump cache 163 require_once PUN_ROOT.'include/cache.php'; 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 164 151 generate_quickjump_cache(); 165 152 166 redirect('admin_categories.php', 'Catégories modifiées. Redirection ...');153 redirect('admin_categories.php', $lang_admin_categories['Categories updated redirect']); 167 154 } 168 155 169 170 156 // Generate an array with all categories 171 $result = $db->query('SELECT id, cat_name, disp_position FROM '.$db->prefix.'categories ORDER BY disp_position') or error(' Impossible de retrouver la liste des catégories', __FILE__, __LINE__, $db->error());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()); 172 158 $num_cats = $db->num_rows($result); 173 159 174 160 for ($i = 0; $i < $num_cats; ++$i) 175 $cat_list[] = $db->fetch_ row($result);176 177 178 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Catégories';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'); 179 165 require PUN_ROOT.'header.php'; 180 166 … … 183 169 ?> 184 170 <div class="blockform"> 185 <h2><span>Ajouter/supprimer/modifier les catégories</span></h2> 186 <div class="box"> 187 <form method="post" action="admin_categories.php?action=foo"> 188 <div class="inform"> 189 <fieldset> 190 <legend>Ajouter/supprimer une catégorie</legend> 191 <div class="infldset"> 192 <table class="aligntop" cellspacing="0"> 193 <tr> 194 <th scope="row">Ajouter une catégorie<div><input type="submit" name="add_cat" value=" Ajouter " tabindex="2" /></div></th> 195 <td> 196 <input type="text" name="new_cat_name" size="35" maxlength="80" tabindex="1" /> 197 <span>Saisissez le nom de la catégorie que vous souhaitez ajouter. Vous pourrez modifier ce nom plus tard (voir ci-dessous). Pour ajouter des forums à une nouvelle catégorie, allez à la page de gestion des <a href="admin_forums.php">Forums</a>.</span> 198 </td> 199 </tr> 200 <?php if ($num_cats): ?> <tr> 201 <th scope="row">Supprimer une catégorie<div><input type="submit" name="del_cat" value=" Supprimer " tabindex="4" /></div></th> 202 <td> 203 <select name="cat_to_delete" tabindex="3"> 204 <?php 205 206 while (list(, list($cat_id, $cat_name, ,)) = @each($cat_list)) 207 echo "\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cat_id.'">'.pun_htmlspecialchars($cat_name).'</option>'."\n"; 208 209 ?> 210 </select> 211 <span>Choisissez le nom de la catégorie que vous souhaitez supprimer. Vous serez invités à confirmer votre choix de catégorie à supprimer avant qu'elle ne soit effectivement supprimée.</span> 212 </td> 213 </tr> 214 <?php endif; ?> </table> 215 </div> 216 </fieldset> 217 </div> 218 <?php if ($num_cats): ?> <div class="inform"> 219 <fieldset> 220 <legend>Modifier les catégories</legend> 221 <div class="infldset"> 222 <table id="categoryedit" cellspacing="0" > 223 <thead> 224 <tr> 225 <th class="tcl" scope="col">Nom</th> 226 <th scope="col">Position</th> 227 <th> </th> 228 </tr> 229 </thead> 230 <tbody> 231 <?php 232 233 @reset($cat_list); 234 for ($i = 0; $i < $num_cats; ++$i) 235 { 236 list(, list($cat_id, $cat_name, $position)) = @each($cat_list); 237 238 ?> 239 <tr><td><input type="text" name="cat_name[<?php echo $i ?>]" value="<?php echo pun_htmlspecialchars($cat_name) ?>" size="35" maxlength="80" /></td><td><input type="text" name="cat_order[<?php echo $i ?>]" value="<?php echo $position ?>" size="3" maxlength="3" /></td><td> </td></tr> 240 <?php 241 242 } 243 244 ?> 245 </tbody> 246 </table> 247 <div class="fsetsubmit"><input type="submit" name="update" value=" Modifier " /></div> 248 </div> 249 </fieldset> 250 </div> 251 <?php endif; ?> </form> 252 </div> 253 </div> 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> 254 262 <div class="clearer"></div> 255 263 </div>
Note: See TracChangeset
for help on using the changeset viewer.