46 |
jpm |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
usersdeleting.php
|
|
|
4 |
|
|
|
5 |
Copyright 2002 Patrick PAUL
|
|
|
6 |
Copyright 2003 David DELON
|
|
|
7 |
* Copyright 2013 Jean-Pascal MILCENT
|
|
|
8 |
This program is free software; you can redistribute it and/or modify
|
|
|
9 |
it under the terms of the GNU General Public License as published by
|
|
|
10 |
the Free Software Foundation; either version 2 of the License, or
|
|
|
11 |
(at your option) any later version.
|
|
|
12 |
|
|
|
13 |
This program is distributed in the hope that it will be useful,
|
|
|
14 |
but 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, MA 02111-1307 USA
|
|
|
21 |
*/
|
|
|
22 |
|
|
|
23 |
// Data managment
|
|
|
24 |
$origineLink = $this->Href();
|
|
|
25 |
$messages = array();
|
|
|
26 |
if ($this->UserIsAdmin() === false) {
|
|
|
27 |
$msg = "Il est nécessaire d'être administrateur de ce wikini pour accéder à la gestion des utilisateurs.";
|
|
|
28 |
$messages[] = array('type' => 'warning', 'txt' => $msg);
|
|
|
29 |
} else {
|
|
|
30 |
$msg_accueil = "Zone de sécurité renforcé : identifiez vous avec l'identifiant et le mot de passe de connexion à la base de données de ce Wikini";
|
|
|
31 |
$msg_echec = "Accès limité aux administrateurs de ce Wikini ayant accès aux paramètres d'installation (identifiant et mot de passe de la base de données).\n".
|
|
|
32 |
"Votre tentative d'identification a échoué.\n".
|
|
|
33 |
"Actualiser la page pour essayer à nouveau si vous avez en votre possession les paramètres nécessaires.";
|
|
|
34 |
$wikiAuthHttp = new WikiAuthHttp($msg_accueil, $msg_echec, $this->config['mysql_user'], $this->config['mysql_password']);
|
|
|
35 |
$wikiAuthHttp->authentifier();
|
|
|
36 |
|
|
|
37 |
$prefix = $this->config['table_prefix'];
|
|
|
38 |
|
|
|
39 |
// Data update, insert or delete
|
|
|
40 |
if (isset($_POST['action'])) {
|
|
|
41 |
if ($_POST['action'] == 'deleteUser') {
|
|
|
42 |
if (isset($_POST['users']) === false) {
|
|
|
43 |
$messages[] = array('type' => 'error', 'txt' => 'Veuillez sélectionner au moins un utilisateur.');
|
|
|
44 |
} else {
|
|
|
45 |
$usersDeleted = array();
|
|
|
46 |
$usersEscaped = array();
|
|
|
47 |
foreach ($_POST['users'] as $user_name) {
|
|
|
48 |
$usersDeleted[] = $user_name;
|
|
|
49 |
$usersEscaped[] = "'".mysql_real_escape_string($user_name)."'";
|
|
|
50 |
}
|
|
|
51 |
$sqlUsersToDelete = implode(',', $usersEscaped);
|
|
|
52 |
}
|
|
|
53 |
$queryDeleteUser = "DELETE FROM {$prefix}users ".
|
|
|
54 |
"WHERE name IN ($sqlUsersToDelete) ";
|
|
|
55 |
$this->Query($queryDeleteUser);
|
|
|
56 |
|
|
|
57 |
$usersDeleted = implode(', ', $usersDeleted);
|
|
|
58 |
if (empty($usersDeleted) == false) {
|
|
|
59 |
$msg = "Les utilisateurs suivant ont été supprimés : $usersDeleted.";
|
|
|
60 |
$messages[] = array('type' => 'success', 'txt' => $msg);
|
|
|
61 |
}
|
|
|
62 |
} else if ($_POST['action'] == 'deletePage') {
|
|
|
63 |
$deletedPages = array();
|
|
|
64 |
if (!empty($_POST['suppr'])) {
|
|
|
65 |
foreach ($_POST['suppr'] as $page) {
|
|
|
66 |
// Effacement de la page en utilisant la méthode DeleteOrphanedPage
|
|
|
67 |
$this->DeleteOrphanedPage($page);
|
|
|
68 |
$deletedPages[] = $page;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
$deletedPages = implode(', ', $deletedPages);
|
|
|
72 |
if (empty($deletedPages) == false) {
|
|
|
73 |
$msg = "Les pages suivantes ont été supprimées : $deletedPages.";
|
|
|
74 |
$messages[] = array('type' => 'success', 'txt' => $msg);
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
$restoredPages = array();
|
|
|
79 |
if (!empty($_POST['rev'])) {
|
|
|
80 |
foreach ($_POST['rev'] as $rev_id) {
|
|
|
81 |
// Sélectionne la révision
|
|
|
82 |
$id = "'".mysql_real_escape_string($rev_id)."'";
|
|
|
83 |
$query = 'SELECT * '.
|
|
|
84 |
"FROM {$prefix}pages ".
|
|
|
85 |
"WHERE id = $id ".
|
|
|
86 |
'LIMIT 1';
|
|
|
87 |
$revision = $this->LoadSingle($query);
|
|
|
88 |
|
|
|
89 |
// Fait de la dernière version de cette révision une version archivée
|
|
|
90 |
$tag = "'".mysql_real_escape_string($revision['tag'])."'";
|
|
|
91 |
$queryUpdate =
|
|
|
92 |
"UPDATE {$prefix}pages " .
|
|
|
93 |
"SET latest = 'N' ".
|
|
|
94 |
"WHERE latest = 'Y' " .
|
|
|
95 |
"AND tag = $tag " .
|
|
|
96 |
"LIMIT 1";
|
|
|
97 |
$this->Query($queryUpdate);
|
|
|
98 |
$restoredPages[] = $revision['tag'];
|
|
|
99 |
|
|
|
100 |
// add new revision
|
|
|
101 |
$owner = "'".mysql_real_escape_string($revision['owner'] )."'";
|
|
|
102 |
$user = "'".mysql_real_escape_string('WikiAdmin')."'";
|
|
|
103 |
$body = "'".mysql_real_escape_string(chop($revision['body']))."'";
|
|
|
104 |
$queryInsert = "INSERT INTO {$prefix}pages SET ".
|
|
|
105 |
"tag = $tag, ".
|
|
|
106 |
"time = NOW(), ".
|
|
|
107 |
"owner = $owner, ".
|
|
|
108 |
"user = $user, ".
|
|
|
109 |
"latest = 'Y', ".
|
|
|
110 |
"body = $body";
|
|
|
111 |
$this->Query($queryInsert);
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
$restoredPages = implode(', ', $restoredPages);
|
|
|
116 |
if (empty($restoredPages) == false) {
|
|
|
117 |
$msg = "Les pages suivantes ont été restaurées à une version antérieure: $restoredPages.";
|
|
|
118 |
$messages[] = array('type' => 'success', 'txt' => $msg);
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
// Data loading
|
|
|
124 |
$queryAllUsers = 'SELECT name, email, motto, revisioncount, changescount, doubleclickedit, signuptime, show_comments '.
|
|
|
125 |
"FROM {$prefix}users ".
|
|
|
126 |
'ORDER BY signuptime DESC';
|
|
|
127 |
$users = $this->LoadAll($queryAllUsers);
|
|
|
128 |
$users_infos = array();
|
|
|
129 |
foreach($users as $user) {
|
|
|
130 |
$user_name = mysql_real_escape_string($user['name']);
|
|
|
131 |
$result = $this->LoadSingle("SELECT COUNT(*) AS pages FROM {$prefix}pages WHERE user = '$user_name'");
|
|
|
132 |
$user['pages_user'] = $result['pages'];
|
|
|
133 |
|
|
|
134 |
$result = $this->LoadSingle("SELECT COUNT(*) AS pages FROM {$prefix}pages WHERE latest = 'Y' AND owner = '$user_name'");
|
|
|
135 |
$user['pages_owner'] = $result['pages'];
|
|
|
136 |
|
|
|
137 |
$user['has_pages'] = ($user['pages_user'] != 0 || $user['pages_owner'] != 0) ? true : false;
|
|
|
138 |
|
|
|
139 |
$user['pages_link'] = $this->Href('', '', "action=seeUserPage&user={$user['name']}");
|
|
|
140 |
|
|
|
141 |
$users_infos[] = $user;
|
|
|
142 |
}
|
|
|
143 |
if (count($users_infos) == 0) {
|
|
|
144 |
$msg = "Ce Wikini ne possède pas d'utilisateur";
|
|
|
145 |
$messages[] = array('type' => 'info', 'txt' => $msg);
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
if (isset($_GET['action'])) {
|
|
|
149 |
if ($_GET['action'] == 'seeUserPage' && $_GET['user'] != '') {
|
|
|
150 |
$actionLink = $this->Href('', '', "action=seeUserPage&user={$_GET['user']}");
|
|
|
151 |
|
|
|
152 |
$userPages['name'] = $_GET['user'];
|
|
|
153 |
$userName = "'".mysql_real_escape_string($_GET['user'])."'";
|
|
|
154 |
$queryAllUserPages = "SELECT tag ".
|
|
|
155 |
"FROM {$prefix}pages ".
|
|
|
156 |
"WHERE owner = $userName OR ".
|
|
|
157 |
" user = $userName ".
|
|
|
158 |
"ORDER BY time DESC ";
|
|
|
159 |
$pages = $this->LoadAll($queryAllUserPages);
|
|
|
160 |
if (count($pages) == 0) {
|
|
|
161 |
$msg = "Cet utilisateur ne possède plus aucune page.";
|
|
|
162 |
$messages[] = array('type' => 'error', 'txt' => $msg);
|
|
|
163 |
} else {
|
|
|
164 |
foreach ($pages as $page) {
|
|
|
165 |
if (! isset($userPages['pages'][$page['tag']])) {
|
|
|
166 |
$pageTag = "'".mysql_real_escape_string($page['tag'])."'";
|
|
|
167 |
$infos = $this->LoadSingle("SELECT * FROM {$prefix}pages WHERE tag = $pageTag AND latest = 'Y'");
|
|
|
168 |
$infos['link'] = $this->Href('', $page['tag']);
|
|
|
169 |
$infos['revisions'] = $this->LoadAll("SELECT * FROM {$prefix}pages WHERE tag = $pageTag ORDER BY time DESC");
|
|
|
170 |
$userPages['pages'][$page['tag']] = $infos;
|
|
|
171 |
}
|
|
|
172 |
}
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
// Template HTML
|
|
|
179 |
$html = '';
|
|
|
180 |
if ($_GET['action'] == 'seeUserPage') {
|
|
|
181 |
$html .= '<ul class="breadcrumb">
|
|
|
182 |
<li>Retour : </li>
|
|
|
183 |
<li><a href="'.$origineLink.'">Gestion des utilisateurs</a> <span class="divider">></span></li>
|
|
|
184 |
<li class="active">Pages utilisateur '.$userPages['name'].'</li>
|
|
|
185 |
</ul>';
|
|
|
186 |
}
|
|
|
187 |
$html .= '<h2>Gestion des utilisateurs</h2>';
|
|
|
188 |
|
|
|
189 |
if (count($messages) != 0) {
|
|
|
190 |
foreach ($messages as $msg) {
|
|
|
191 |
$html .= '<p class="alert alert-'.$msg['type'].'">';
|
|
|
192 |
$html .= $msg['txt'].'<br />';
|
|
|
193 |
$html .= '</p>';
|
|
|
194 |
}
|
|
|
195 |
}
|
|
|
196 |
if ($this->UserIsAdmin()) {
|
|
|
197 |
if ($_GET['action'] == 'seeUserPage' && isset($userPages)) {
|
|
|
198 |
if (count($userPages['pages']) > 0) {
|
|
|
199 |
$html .= '<h3 id="user-pages-modal-label">'."Pages de l'utilisateur {$userPages['name']}".'</h3>'.
|
|
|
200 |
'<p class="alert alert-info">Sélectionnez une ou plusieurs pages à supprimer et/ou versions à restaurer puis cliquer sur le bouton en bas de page.</p>';
|
|
|
201 |
|
|
|
202 |
$html .= '<form action="'.$actionLink.'" method="post">';
|
|
|
203 |
$html .= '<table class="table table-bordered">
|
|
|
204 |
<thead>
|
|
|
205 |
<tr>
|
|
|
206 |
<th>[supprimer] Page</th>
|
|
|
207 |
<th>Propriétaire</th>
|
|
|
208 |
<th>[restaurer] Version du</th>
|
|
|
209 |
<th>Auteur modification</th>
|
|
|
210 |
</tr>
|
|
|
211 |
</thead>';
|
|
|
212 |
|
|
|
213 |
foreach ($userPages['pages'] as $page) {
|
|
|
214 |
$html .= '<tr class="success">'.
|
|
|
215 |
'<td>'.
|
|
|
216 |
'<span class="has-tooltip" title="Supprimer la page '.$page['tag'].' et toutes ses versions !">'.
|
|
|
217 |
'<input name="suppr[]" value="'.$page['tag'].'" type="checkbox"/>'.
|
|
|
218 |
'</span> '.
|
|
|
219 |
'<a href="'.$page['link'].'">'.
|
|
|
220 |
$page['tag'].
|
|
|
221 |
'</a>'.
|
|
|
222 |
'</td>'.
|
|
|
223 |
'<td>'.$page['owner'].'</td>'.
|
|
|
224 |
'<td>'.$page['time'].'</td>'.
|
|
|
225 |
'<td>'.$page['user'].'</td>'.
|
|
|
226 |
'</tr>';
|
|
|
227 |
$revisionsNbre = count($page['revisions']);
|
|
|
228 |
if ($revisionsNbre != 0) {
|
|
|
229 |
for ($i = 1; $i < $revisionsNbre; $i++) {
|
|
|
230 |
$revision = $page['revisions'][$i];
|
|
|
231 |
$html .= '<tr>'.
|
|
|
232 |
'<td> </td>'.
|
|
|
233 |
'<td>'.$revision['owner'].'</td>'.
|
|
|
234 |
'<td>'.
|
|
|
235 |
'<span class="has-tooltip" title="Restaurer la version du '.$revision['time'].' de la page '.$page["tag"].'">'.
|
|
|
236 |
'<input name="rev[]" value="'.$revision['id'].'" type="checkbox"/> '.
|
|
|
237 |
'</span>'.
|
|
|
238 |
$revision['time'].
|
|
|
239 |
'</td>'.
|
|
|
240 |
'<td>'.$revision['user'].'</td>'.
|
|
|
241 |
'</tr>';
|
|
|
242 |
}
|
|
|
243 |
}
|
|
|
244 |
}
|
|
|
245 |
$html .= '</table>
|
|
|
246 |
<div class="form-actions">
|
|
|
247 |
<button class="btn btn-danger has-tooltip" type="submit" name="action" value="deletePage" title="Supprime les pages sélectionnés ou restaure des anciennes versions">
|
|
|
248 |
Supprimer des pages et/ou restaurer des versions
|
|
|
249 |
</button>
|
|
|
250 |
</div>
|
|
|
251 |
</form>';
|
|
|
252 |
}
|
|
|
253 |
} else {
|
|
|
254 |
$html .= '<form action="'.$origineLink.'" method="post">';
|
|
|
255 |
|
|
|
256 |
$html .= '<p class="alert alert-info">Sélectionnez un ou plusieurs utilisateurs à supprimer puis cliquer sur le bouton supprimer en bas de page.</p>
|
|
|
257 |
<table class="table table-striped table-hover table-bordered table-condensed">
|
|
|
258 |
<thead>
|
|
|
259 |
<tr>
|
|
|
260 |
<th> </th>
|
|
|
261 |
<th>Nom & Devise</th>
|
|
|
262 |
<th>Courriel</th>
|
|
|
263 |
<th>Inscription</th>
|
|
|
264 |
<th>
|
|
|
265 |
<span class="has-tooltip" title="Nombre de pages (hors archive) dont l\'utilisateur est le propriétaire.">Pages proprio.</span>
|
|
|
266 |
/
|
|
|
267 |
<span class="has-tooltip" title="Nombre de pages toutes versions confondues modifiées par l\'utilisateur.">Modif.</span>
|
|
|
268 |
</th>
|
|
|
269 |
<th>
|
|
|
270 |
<span class="has-tooltip" title="Nombre de révisions visible par l\'utilisateur">révisions</span> /
|
|
|
271 |
<span class="has-tooltip" title="Nombre de changements visible par l\'utilisateur">changements</span> /
|
|
|
272 |
<span class="has-tooltip" title="L\'utilisateur peut éditer les page en réalisant un double clic.">clic</span> /
|
|
|
273 |
<span class="has-tooltip" title="L\'utilisateur veut voir les commentaires sur la page.">commentaire</span>
|
|
|
274 |
</th>
|
|
|
275 |
</tr>
|
|
|
276 |
</thead>
|
|
|
277 |
<tbody>';
|
|
|
278 |
if (isset($users_infos)) {
|
|
|
279 |
foreach ($users_infos as $user) {
|
|
|
280 |
$html .= '<tr>
|
|
|
281 |
<td><input type="checkbox" name="users[]" value="'.$user['name'].'"/></td>
|
|
|
282 |
<td>'.
|
|
|
283 |
$user['name'].
|
|
|
284 |
(empty($user['motto']) ? '' : '<br /><em><cite>'.$user['motto'].'</cite></em>').
|
|
|
285 |
'</td>
|
|
|
286 |
<td><a href="mailto:'.$user['email'].'">'.$user['email'].'</a></td>
|
|
|
287 |
<td>'.$user['signuptime'].'</td>
|
|
|
288 |
<td>'.
|
|
|
289 |
($user['has_pages'] ? '<a href="'.$user['pages_link'].'">' : '').
|
|
|
290 |
$user['pages_owner'].' / '.$user['pages_user'].
|
|
|
291 |
($user['has_pages'] ? '</a>' : '').
|
|
|
292 |
'</td>
|
|
|
293 |
<td>'.$user['revisioncount'].' / '.$user['changescount'].' / '.$user['doubleclickedit'].' / '.$user['show_comments'].'</td>
|
|
|
294 |
</tr>';
|
|
|
295 |
}
|
|
|
296 |
}
|
|
|
297 |
$html .= '</tbody>
|
|
|
298 |
</table>
|
|
|
299 |
<div class="form-actions">
|
|
|
300 |
<button class="btn btn-danger has-tooltip" type="submit" name="action" value="deleteUser" title="Supprime les utilisateurs sélectionnés de la base de données">
|
|
|
301 |
Supprimer des utilisateurs
|
|
|
302 |
</button>
|
|
|
303 |
</div>
|
|
|
304 |
</form>';
|
|
|
305 |
}
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
// Sortie
|
|
|
309 |
echo isset($this->config['encoding']) ? mb_convert_encoding($html, $this->config['encoding'], 'iso-8859-15') : $html;
|
|
|
310 |
|
|
|
311 |
// Functions & class
|
|
|
312 |
class WikiAuthHttp {
|
|
|
313 |
private $message_accueil;
|
|
|
314 |
private $message_echec;
|
|
|
315 |
private $identifiant;
|
|
|
316 |
private $mot_de_passe;
|
|
|
317 |
|
|
|
318 |
public function __construct($message_accueil, $message_echec, $identifiant, $mot_de_passe) {
|
|
|
319 |
$this->message_accueil = $message_accueil;
|
|
|
320 |
$this->message_echec = $message_echec;
|
|
|
321 |
$this->identifiant = $identifiant;
|
|
|
322 |
$this->mot_de_passe = $mot_de_passe;
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
public function authentifier() {
|
|
|
326 |
$authentifie = $this->etreAutorise();
|
|
|
327 |
if ($authentifie === false) {
|
|
|
328 |
$this->envoyerAuth();
|
|
|
329 |
}
|
|
|
330 |
return $authentifie;
|
|
|
331 |
}
|
|
|
332 |
|
|
|
333 |
private function envoyerAuth() {
|
|
|
334 |
header('HTTP/1.0 401 Unauthorized');
|
|
|
335 |
header('WWW-Authenticate: Basic realm="'.$this->message_accueil.'"');
|
|
|
336 |
header('Content-type: text/plain; charset=ISO-8859-15');
|
|
|
337 |
print $this->message_echec;
|
|
|
338 |
exit(0);
|
|
|
339 |
}
|
|
|
340 |
|
|
|
341 |
private function etreAutorise() {
|
|
|
342 |
$identifiant = $this->getAuthIdentifiant();
|
|
|
343 |
$mdp = $this->getAuthMotDePasse();
|
|
|
344 |
$autorisation = ($identifiant == $this->identifiant && $mdp == $this->mot_de_passe) ? true : false;
|
|
|
345 |
return $autorisation;
|
|
|
346 |
}
|
|
|
347 |
|
|
|
348 |
private function getAuthIdentifiant() {
|
|
|
349 |
$id = (isset($_SERVER['PHP_AUTH_USER'])) ? $_SERVER['PHP_AUTH_USER'] : null;
|
|
|
350 |
return $id;
|
|
|
351 |
}
|
|
|
352 |
|
|
|
353 |
private function getAuthMotDePasse() {
|
|
|
354 |
$mdp = (isset($_SERVER['PHP_AUTH_PW'])) ? $_SERVER['PHP_AUTH_PW'] : null;
|
|
|
355 |
return $mdp;
|
|
|
356 |
}
|
|
|
357 |
}
|
|
|
358 |
?>
|