source: trunk/web/punbb/admin_categories.php @ 1

Last change on this file since 1 was 1, checked in by dj3c1t, 12 years ago

import initial

File size: 9.2 KB
Line 
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
25
26// Tell header.php to use the admin template
27define('PUN_ADMIN_CONSOLE', 1);
28
29define('PUN_ROOT', './');
30require PUN_ROOT.'include/common.php';
31require PUN_ROOT.'include/common_admin.php';
32
33
34if ($pun_user['g_id'] > PUN_ADMIN)
35        message($lang_common['No permission']);
36
37
38// Add a new category
39if (isset($_POST['add_cat']))
40{
41        confirm_referrer('admin_categories.php');
42
43        $new_cat_name = trim($_POST['new_cat_name']);
44        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 ...');
50}
51
52
53// Delete a category
54else if (isset($_POST['del_cat']) || isset($_POST['del_cat_comply']))
55{
56        confirm_referrer('admin_categories.php');
57
58        $cat_to_delete = intval($_POST['cat_to_delete']);
59        if ($cat_to_delete < 1)
60                message($lang_common['Bad request']);
61
62        if (isset($_POST['del_cat_comply']))    // Delete a category with all forums and posts
63        {
64                @set_time_limit(0);
65
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());
67                $num_forums = $db->num_rows($result);
68
69                for ($i = 0; $i < $num_forums; ++$i)
70                {
71                        $cur_forum = $db->result($result, $i);
72
73                        // Prune all posts and topics
74                        prune($cur_forum, 1, -1);
75
76                        // 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());
78                }
79
80                // 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());
82                $num_orphans = $db->num_rows($result);
83
84                if ($num_orphans)
85                {
86                        for ($i = 0; $i < $num_orphans; ++$i)
87                                $orphans[] = $db->result($result, $i);
88
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());
90                }
91
92                // 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';
97                generate_quickjump_cache();
98
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());
104                $cat_name = $db->result($result);
105
106                $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Catégories';
107                require PUN_ROOT.'header.php';
108
109                generate_admin_menu('categories');
110
111?>
112        <div class="blockform">
113                <h2><span>Supprimer une catégorie</span></h2>
114                <div class="box">
115                        <form method="post" action="admin_categories.php">
116                                <div class="inform">
117                                <input type="hidden" name="cat_to_delete" value="<?php echo $cat_to_delete ?>" />
118                                        <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>
127                        </form>
128                </div>
129        </div>
130        <div class="clearer"></div>
131</div>
132<?php
133
134                require PUN_ROOT.'footer.php';
135        }
136}
137
138
139else if (isset($_POST['update']))       // Change position and name of the categories
140{
141        confirm_referrer('admin_categories.php');
142
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';
164        generate_quickjump_cache();
165
166        redirect('admin_categories.php', 'Catégories modifiées. Redirection ...');
167}
168
169
170// 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());
172$num_cats = $db->num_rows($result);
173
174for ($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';
179require PUN_ROOT.'header.php';
180
181generate_admin_menu('categories');
182
183?>
184        <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>
254        <div class="clearer"></div>
255</div>
256<?php
257
258require PUN_ROOT.'footer.php';
Note: See TracBrowser for help on using the repository browser.