Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rsr.v5.1.dev/web/punbb/admin_categories.php

    r1 r3  
    11<?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 */
    258
    269// Tell header.php to use the admin template
    2710define('PUN_ADMIN_CONSOLE', 1);
    2811
    29 define('PUN_ROOT', './');
     12define('PUN_ROOT', dirname(__FILE__).'/');
    3013require PUN_ROOT.'include/common.php';
    3114require PUN_ROOT.'include/common_admin.php';
    3215
    3316
    34 if ($pun_user['g_id'] > PUN_ADMIN)
     17if ($pun_user['g_id'] != PUN_ADMIN)
    3518        message($lang_common['No permission']);
    3619
     20// Load the admin_categories.php language file
     21require PUN_ROOT.'lang/'.$admin_language.'/admin_categories.php';
    3722
    3823// Add a new category
     
    4126        confirm_referrer('admin_categories.php');
    4227
    43         $new_cat_name = trim($_POST['new_cat_name']);
     28        $new_cat_name = pun_trim($_POST['new_cat_name']);
    4429        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']);
    5035}
    51 
    5236
    5337// Delete a category
     
    6044                message($lang_common['Bad request']);
    6145
    62         if (isset($_POST['del_cat_comply']))    // Delete a category with all forums and posts
     46        if (isset($_POST['del_cat_comply'])) // Delete a category with all forums and posts
    6347        {
    6448                @set_time_limit(0);
    6549
    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());
    6751                $num_forums = $db->num_rows($result);
    6852
     
    7559
    7660                        // 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());
    7862                }
    7963
    8064                // 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());
    8266                $num_orphans = $db->num_rows($result);
    8367
     
    8771                                $orphans[] = $db->result($result, $i);
    8872
    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());
    9074                }
    9175
    9276                // 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
    9783                generate_quickjump_cache();
    9884
    99                 redirect('admin_categories.php', 'Catégorie supprimée. Redirection ...');
    100         }
    101         else    // If the user hasn't comfirmed the delete
    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());
    10490                $cat_name = $db->result($result);
    10591
    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');
    10794                require PUN_ROOT.'header.php';
    10895
     
    11198?>
    11299        <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>
    114101                <div class="box">
    115102                        <form method="post" action="admin_categories.php">
     
    117104                                <input type="hidden" name="cat_to_delete" value="<?php echo $cat_to_delete ?>" />
    118105                                        <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 ?>"&#160;?</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&#160;!</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>
    127114                        </form>
    128115                </div>
     
    136123}
    137124
    138 
    139 else if (isset($_POST['update']))       // Change position and name of the categories
     125else if (isset($_POST['update'])) // Change position and name of the categories
    140126{
    141127        confirm_referrer('admin_categories.php');
    142128
    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
    164151        generate_quickjump_cache();
    165152
    166         redirect('admin_categories.php', 'Catégories modifiées. Redirection ...');
     153        redirect('admin_categories.php', $lang_admin_categories['Categories updated redirect']);
    167154}
    168155
    169 
    170156// 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());
    172158$num_cats = $db->num_rows($result);
    173159
    174160for ($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']);
     164define('PUN_ACTIVE_PAGE', 'admin');
    179165require PUN_ROOT.'header.php';
    180166
     
    183169?>
    184170        <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>&#160;</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>&#160;</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>
    254262        <div class="clearer"></div>
    255263</div>
Note: See TracChangeset for help on using the changeset viewer.