bug3
[aidenligne_francais_universite.git] / fluxbb / admin_prune.php
CommitLineData
c495c100
P
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
38if (isset($_GET['action']) || isset($_POST['prune']) || isset($_POST['prune_comply']))
39{
40 if (isset($_POST['prune_comply']))
41 {
42 confirm_referrer('admin_prune.php');
43
44 $prune_from = $_POST['prune_from'];
45 $prune_sticky = isset($_POST['prune_sticky']) ? '1' : '0';
46 $prune_days = intval($_POST['prune_days']);
47 $prune_date = ($prune_days) ? time() - ($prune_days*86400) : -1;
48
49 @set_time_limit(0);
50
51 if ($prune_from == 'all')
52 {
53 $result = $db->query('SELECT id FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
54 $num_forums = $db->num_rows($result);
55
56 for ($i = 0; $i < $num_forums; ++$i)
57 {
58 $fid = $db->result($result, $i);
59
60 prune($fid, $prune_sticky, $prune_date);
61 update_forum($fid);
62 }
63 }
64 else
65 {
66 $prune_from = intval($prune_from);
67 prune($prune_from, $prune_sticky, $prune_date);
68 update_forum($prune_from);
69 }
70
71 // Locate any "orphaned redirect topics" and delete them
72 $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());
73 $num_orphans = $db->num_rows($result);
74
75 if ($num_orphans)
76 {
77 for ($i = 0; $i < $num_orphans; ++$i)
78 $orphans[] = $db->result($result, $i);
79
80 $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
81 }
82
83 redirect('admin_prune.php', 'Messages supprimés. Redirection ...');
84 }
85
86
87 $prune_days = $_POST['req_prune_days'];
88 if (!@preg_match('#^\d+$#', $prune_days))
89 message('Le nombre de jours d\'ancienneté doit être un entier positif.');
90
91 $prune_date = time() - ($prune_days*86400);
92 $prune_from = $_POST['prune_from'];
93
94 // Concatenate together the query for counting number or topics to prune
95 $sql = 'SELECT COUNT(id) FROM '.$db->prefix.'topics WHERE last_post<'.$prune_date.' AND moved_to IS NULL';
96
97 if (!$prune_sticky)
98 $sql .= ' AND sticky=\'0\'';
99
100 if ($prune_from != 'all')
101 {
102 $prune_from = intval($prune_from);
103 $sql .= ' AND forum_id='.$prune_from;
104
105 // Fetch the forum name (just for cosmetic reasons)
106 $result = $db->query('SELECT forum_name FROM '.$db->prefix.'forums WHERE id='.$prune_from) or error('Unable to fetch forum name', __FILE__, __LINE__, $db->error());
107 $forum = '"'.pun_htmlspecialchars($db->result($result)).'"';
108 }
109 else
110 $forum = 'tous les forums';
111
112 $result = $db->query($sql) or error('Unable to fetch topic prune count', __FILE__, __LINE__, $db->error());
113 $num_topics = $db->result($result);
114
115 if (!$num_topics)
116 message('Il n\'y a pas de sujets anciens de '.$prune_days.' jours. Diminuez la valeur de Jours d\'ancienneté et essayez à nouveau.');
117
118
119 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Élagage';
120 require PUN_ROOT.'header.php';
121
122 generate_admin_menu('prune');
123
124?>
125 <div class="blockform">
126 <h2><span>Élagage des forums</span></h2>
127 <div class="box">
128 <form method="post" action="admin_prune.php?action=foo">
129 <div class="inform">
130 <input type="hidden" name="prune_days" value="<?php echo $prune_days ?>" />
131 <input type="hidden" name="prune_sticky" value="<?php echo $prune_sticky ?>" />
132 <input type="hidden" name="prune_from" value="<?php echo $prune_from ?>" />
133 <fieldset>
134 <legend>Confirmez la suppression des messages</legend>
135 <div class="infldset">
136 <p>Êtes-vous sûr de vouloir supprimer toutes les discussions plus anciennes de <?php echo $prune_days ?> jours de <?php echo $forum ?>? (<?php echo $num_topics ?> discussions)</p>
137 <p>ATTENTION ! L'élagage des forums est irréversible, les messages seront définitivement supprimés.</p>
138 </div>
139 </fieldset>
140 </div>
141 <p><input type="submit" name="prune_comply" value=" Élaguer " /><a href="javascript:history.go(-1)">Retour</a></p>
142 </form>
143 </div>
144 </div>
145 <div class="clearer"></div>
146</div>
147<?php
148
149 require PUN_ROOT.'footer.php';
150}
151
152
153else
154{
155 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Élagage des forums';
156 $required_fields = array('req_prune_days' => 'Days old');
157 $focus_element = array('prune', 'req_prune_days');
158 require PUN_ROOT.'header.php';
159
160 generate_admin_menu('prune');
161
162?>
163 <div class="blockform">
164 <h2><span>Élagage des forums</span></h2>
165 <div class="box">
166 <form id="prune" method="post" action="admin_prune.php?action=foo" onsubmit="return process_form(this)">
167 <div class="inform">
168 <input type="hidden" name="form_sent" value="1" />
169 <fieldset>
170 <legend>Supprimer les messages anciens</legend>
171 <div class="infldset">
172 <table class="aligntop" cellspacing="0">
173 <tr>
174 <th scope="row">Jours d'ancienneté</th>
175 <td>
176 <input type="text" name="req_prune_days" size="3" maxlength="3" tabindex="1" />
177 <span>Le nombre de jours d'ancienneté qu'un sujet doit avoir pour être supprimé. Autrement dit, si vous saisissez 30, tous les sujets qui ne contiennent pas de messages datés de moins de 30 jours seront supprimés.</span>
178 </td>
179 </tr>
180 <tr>
181 <th scope="row">Supprimer les discussions épinglées</th>
182 <td>
183 <input type="radio" name="prune_sticky" value="1" tabindex="2" checked="checked" />&nbsp;<strong>Oui</strong>&nbsp;&nbsp;&nbsp;<input type="radio" name="prune_sticky" value="0" />&nbsp;<strong>Non</strong>
184 <span>Lorsque cette option est activée les discussions épinglées seront également supprimées.</span>
185 </td>
186 </tr>
187 <tr>
188 <th scope="row">Forum</th>
189 <td>
190 <select name="prune_from" tabindex="3">
191 <option value="all">Tous les forums</option>
192<?php
193
194 $result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id WHERE f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
195
196 $cur_category = 0;
197 while ($forum = $db->fetch_assoc($result))
198 {
199 if ($forum['cid'] != $cur_category) // Are we still in the same category?
200 {
201 if ($cur_category)
202 echo "\t\t\t\t\t\t\t\t\t\t\t".'</optgroup>'."\n";
203
204 echo "\t\t\t\t\t\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($forum['cat_name']).'">'."\n";
205 $cur_category = $forum['cid'];
206 }
207
208 echo "\t\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$forum['fid'].'">'.pun_htmlspecialchars($forum['forum_name']).'</option>'."\n";
209 }
210
211?>
212 </optgroup>
213 </select>
214 <span>Choisissez le forum dans lequel vous voulez effectuer l'élagage.</span>
215 </td>
216 </tr>
217 </table>
218 <p class="topspace">Utilisez cette fonctionnalité avec précaution. L'élagage des forums est irréversible. Pour de meilleures performances, au cours du processus d'élagage vous devriez mettre les forums en mode maintenance.</p>
219 <div class="fsetsubmit"><input type="submit" name="prune" value=" Élaguer " tabindex="5" /></div>
220 </div>
221 </fieldset>
222 </div>
223 </form>
224 </div>
225 </div>
226 <div class="clearer"></div>
227</div>
228<?php
229
230 require PUN_ROOT.'footer.php';
231}