3259b9d5c83e4cb0c855954115c6d9d129ec1ddb
[platal.git] / modules / admin.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 class AdminModule extends PLModule
23 {
24 function handlers()
25 {
26 return array(
27 'admin' => $this->make_hook('default', AUTH_MDP, 'admin'),
28 'admin/ax-xorg' => $this->make_hook('ax_xorg', AUTH_MDP, 'admin'),
29 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP, 'admin'),
30 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP, 'admin'),
31 'admin/homonyms' => $this->make_hook('homonyms', AUTH_MDP, 'admin'),
32 'admin/logger' => $this->make_hook('logger', AUTH_MDP, 'admin'),
33 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_MDP, 'admin'),
34 'admin/postfix/blacklist' => $this->make_hook('postfix_blacklist', AUTH_MDP, 'admin'),
35 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP, 'admin'),
36 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP, 'admin'),
37 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP, 'admin'),
38 'admin/skins' => $this->make_hook('skins', AUTH_MDP, 'admin'),
39 'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP, 'admin'),
40 'admin/user' => $this->make_hook('user', AUTH_MDP, 'admin'),
41 'admin/validate' => $this->make_hook('validate', AUTH_MDP, 'admin'),
42 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP, 'admin'),
43 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'),
44 );
45 }
46
47 function handler_default(&$page)
48 {
49 $page->changeTpl('admin/index.tpl');
50 $page->assign('xorg_title','Polytechnique.org - Administration');
51 }
52
53 function handler_postfix_delayed(&$page)
54 {
55 $page->changeTpl('admin/postfix_delayed.tpl');
56 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Retardés');
57
58 if (Env::has('del')) {
59 $crc = Env::v('crc');
60 XDB::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc);
61 $page->trig($crc." verra tous ses mails supprimés !");
62 } elseif (Env::has('ok')) {
63 $crc = Env::v('crc');
64 XDB::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
65 $page->trig($crc." a le droit de passer !");
66 }
67
68 $sql = XDB::iterator(
69 "SELECT crc, nb, update_time, create_time,
70 FIND_IN_SET('del', release) AS del,
71 FIND_IN_SET('ok', release) AS ok
72 FROM postfix_mailseen
73 WHERE nb >= 30
74 ORDER BY release != ''");
75
76 $page->assign_by_ref('mails', $sql);
77 }
78
79 function handler_postfix_regexpsbounces(&$page, $new = null) {
80 $page->changeTpl('admin/emails_bounces_re.tpl');
81 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Regexps Bounces');
82 $page->assign('new', $new);
83
84 if (Post::has('submit')) {
85 foreach (Env::v('lvl') as $id=>$val) {
86 XDB::query(
87 "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})",
88 $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id]
89 );
90 }
91 }
92
93 $page->assign('bre', XDB::iterator("SELECT * FROM emails_bounces_re ORDER BY pos"));
94 }
95
96 function handler_logger(&$page) {
97 require_once dirname(__FILE__).'/../classes/LoggerView.php';
98
99 if (!Env::has('logauth')) {
100 $_REQUEST['logauth'] = 'native';
101 }
102
103 $logview = new LoggerView;
104 $logview->run($page);
105
106 $page->fakeDiogenes();
107 $page->assign('xorg_title','Polytechnique.org - Administration - Logs des sessions');
108 }
109
110 function handler_user(&$page, $login = false) {
111 $page->changeTpl('admin/utilisateurs.tpl');
112 $page->assign('xorg_title','Polytechnique.org - Administration - Edit/Su/Log');
113 require_once("emails.inc.php");
114 require_once("user.func.inc.php");
115
116 if (S::has('suid')) {
117 $page->kill("déjà en SUID !!!");
118 }
119
120 if (Env::has('user_id')) {
121 $login = get_user_login(Env::i('user_id'));
122 } elseif (Env::has('login')) {
123 $login = get_user_login(Env::v('login'));
124 }
125
126 if(Env::has('logs_button') && $login) {
127 pl_redirect("admin/logger?login=$login&year=".date('Y')."&month=".date('m'));
128 }
129
130 if (Env::has('ax_button') && $login) {
131 pl_redirect("admin/synchro_ax/$login");
132 }
133
134 if(Env::has('suid_button') && $login) {
135 $_SESSION['log']->log("suid_start", "login by ".S::v('forlife'));
136 $_SESSION['suid'] = $_SESSION;
137 $r = XDB::query("SELECT id FROM aliases WHERE alias={?}", $login);
138 if($uid = $r->fetchOneCell()) {
139 start_connexion($uid,true);
140 pl_redirect("");
141 }
142 }
143
144 if ($login) {
145 $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe
146 FROM auth_user_md5 AS u
147 INNER JOIN aliases AS a ON ( a.id = u.user_id AND a.alias={?} AND type!='homonyme' )", $login);
148 $mr = $r->fetchOneAssoc();
149
150 $redirect = new Redirect($mr['user_id']);
151
152 // Check if there was a submission
153 foreach($_POST as $key => $val) {
154 switch ($key) {
155 case "add_fwd":
156 $email = trim(Env::v('email'));
157 if (!isvalid_email_redirection($email)) {
158 $page->trig("invalid email $email");
159 } else {
160 $redirect->add_email($email);
161 $page->trig("Ajout de $email effectué");
162 }
163 break;
164
165 case "del_fwd":
166 if (!empty($val)) {
167 $redirect->delete_email($val);
168 }
169 break;
170
171 case "del_alias":
172 if (!empty($val)) {
173 XDB::execute("DELETE FROM aliases WHERE id={?} AND alias={?}
174 AND type!='a_vie' AND type!='homonyme'", $mr['user_id'], $val);
175 fix_bestalias($mr['user_id']);
176 $page->trig($val." a été supprimé");
177 }
178 break;
179 case "activate_fwd":
180 if (!empty($val)) {
181 $redirect->modify_one_email($val, true);
182 }
183 break;
184 case "deactivate_fwd":
185 if (!empty($val)) {
186 $redirect->modify_one_email($val, false);
187 }
188 break;
189 case "add_alias":
190 XDB::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')",
191 $mr['user_id'], Env::v('email'));
192 break;
193
194 case "best":
195 // 'bestalias' is the first bit of the set : 1
196 // 255 is the max for flags (8 sets max)
197 XDB::execute("UPDATE aliases SET flags= flags & (255 - 1) WHERE id={?}", $mr['user_id']);
198 XDB::execute("UPDATE aliases
199 SET flags= flags | 1
200 WHERE id={?} AND alias={?}", $mr['user_id'], $val);
201 break;
202
203
204 // Editer un profil
205 case "u_edit":
206 require_once('secure_hash.inc.php');
207 $pass_encrypted = Env::v('newpass_clair') != "********" ? hash_encrypt(Env::v('newpass_clair')) : Env::v('passw');
208 $naiss = Env::v('naissanceN');
209 $deces = Env::v('decesN');
210 $perms = Env::v('permsN');
211 $prenm = Env::v('prenomN');
212 $nom = Env::v('nomN');
213 $promo = Env::i('promoN');
214 $sexe = Env::v('sexeN');
215 $comm = Env::v('commentN');
216
217 $query = "UPDATE auth_user_md5 SET
218 naissance = '$naiss',
219 deces = '$deces',
220 password = '$pass_encrypted',
221 perms = '$perms',
222 prenom = '".addslashes($prenm)."',
223 nom = '".addslashes($nom)."',
224 flags = '$sexe',
225 promo = $promo,
226 comment = '".addslashes($comm)."'
227 WHERE user_id = '{$mr['user_id']}'";
228 if (XDB::execute($query)) {
229 user_reindex($mr['user_id']);
230
231 require_once("diogenes/diogenes.hermes.inc.php");
232 $mailer = new HermesMailer();
233 $mailer->setFrom("webmaster@polytechnique.org");
234 $mailer->addTo("web@polytechnique.org");
235 $mailer->setSubject("INTERVENTION de ".S::v('forlife'));
236 $mailer->setTxtBody(preg_replace("/[ \t]+/", ' ', $query));
237 $mailer->send();
238
239 $page->trig("updaté correctement.");
240 }
241 if (Env::v('nomusageN') != $mr['nom_usage']) {
242 require_once('nomusage.inc.php');
243 set_new_usage($mr['user_id'], Env::v('nomusageN'), make_username(Env::v('prenomN'), Env::v('nomusageN')));
244 }
245 $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe
246 FROM auth_user_md5 AS u
247 INNER JOIN aliases AS a ON (u.user_id=a.id)
248 WHERE user_id = {?}", $mr['user_id']);
249 $mr = $r->fetchOneAssoc();
250 break;
251
252 // DELETE FROM auth_user_md5
253 case "u_kill":
254 user_clear_all_subs($mr['user_id']);
255 $page->trig("'{$mr['user_id']}' a été désinscrit !");
256 require_once("diogenes/diogenes.hermes.inc.php");
257 $mailer = new HermesMailer();
258 $mailer->setFrom("webmaster@polytechnique.org");
259 $mailer->addTo("web@polytechnique.org");
260 $mailer->setSubject("INTERVENTION de ".S::v('forlife'));
261 $mailer->setTxtBody("\nUtilisateur $login effacé");
262 $mailer->send();
263 break;
264 }
265 }
266
267 $res = XDB::query("SELECT UNIX_TIMESTAMP(start), host
268 FROM logger.sessions
269 WHERE uid={?} AND suid=0
270 ORDER BY start DESC
271 LIMIT 1", $mr['user_id']);
272 list($lastlogin,$host) = $res->fetchOneRow();
273 $page->assign('lastlogin', $lastlogin);
274 $page->assign('host', $host);
275
276 $page->assign('aliases', XDB::iterator(
277 "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
278 FROM aliases
279 WHERE id = {?} AND type!='homonyme'
280 ORDER BY type!= 'a_vie'", $mr["user_id"]));
281 $page->assign('xorgmails', $xorgmails);
282 $page->assign('email_panne', $email_panne);
283 $page->assign('emails',$redirect->emails);
284
285 $page->assign('mr',$mr);
286 }
287 }
288 function handler_homonyms(&$page, $op = 'list', $target = null) {
289 $page->changeTpl('admin/homonymes.tpl');
290 $page->assign('xorg_title','Polytechnique.org - Administration - Homonymes');
291 require_once("homonymes.inc.php");
292
293 if ($target) {
294 if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) {
295 $target=0;
296 } else {
297 $page->assign('nom',$nom);
298 $page->assign('prenom',$prenom);
299 $page->assign('forlife',$forlife);
300 $page->assign('loginbis',$loginbis);
301 }
302 }
303
304 $page->assign('op',$op);
305 $page->assign('target',$target);
306
307 // on a un $target valide, on prepare les mails
308 if ($target) {
309
310 // on examine l'op a effectuer
311 switch ($op) {
312 case 'mail':
313 send_warning_homonyme($prenom, $nom, $forlife, $loginbis);
314 switch_bestalias($target, $loginbis);
315 $op = 'list';
316 break;
317 case 'correct':
318 switch_bestalias($target, $loginbis);
319 XDB::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis);
320 XDB::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target);
321 send_robot_homonyme($prenom, $nom, $forlife, $loginbis);
322 $op = 'list';
323 break;
324 }
325 }
326
327 if ($op == 'list') {
328 $res = XDB::iterator(
329 "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife,
330 promo,prenom,nom,
331 IF(h.homonyme_id=s.id, a.expire, NULL) AS expire,
332 IF(h.homonyme_id=s.id, a.type, NULL) AS type
333 FROM aliases AS a
334 LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id)
335 INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie')
336 INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id)
337 WHERE a.type='homonyme' OR a.expire!=''
338 ORDER BY a.alias,promo");
339 $hnymes = Array();
340 while ($tab = $res->next()) {
341 $hnymes[$tab['homonyme']][] = $tab;
342 }
343 $page->assign_by_ref('hnymes',$hnymes);
344 }
345 }
346
347 function handler_ax_xorg(&$page) {
348 $page->changeTpl('admin/ax-xorg.tpl');
349 $page->assign('xorg_title','Polytechnique.org - Administration - AX/X.org');
350
351 // liste des différences
352 $res = XDB::query(
353 'SELECT u.promo,u.nom AS nom,u.prenom AS prenom,ia.nom AS nomax,ia.prenom AS prenomax,u.matricule AS mat,ia.matricule_ax AS matax
354 FROM auth_user_md5 AS u
355 INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax
356 WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom)
357 AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro))
358 OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1)
359 ORDER BY u.promo,u.nom,u.prenom');
360 $page->assign('diffs', $res->fetchAllAssoc());
361
362 // gens à l'ax mais pas chez nous
363 $res = XDB::query(
364 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom
365 FROM identification_ax as ia
366 LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax
367 WHERE u.nom IS NULL');
368 $page->assign('mank', $res->fetchAllAssoc());
369
370 // gens chez nous et pas à l'ax
371 $res = XDB::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL');
372 $page->assign('plus', $res->fetchAllAssoc());
373 }
374
375 function handler_deaths(&$page, $promo = 0, $validate = false) {
376 $page->changeTpl('admin/deces_promo.tpl');
377 $page->assign('xorg_title','Polytechnique.org - Administration - Deces');
378
379 if (!$promo)
380 $promo = Env::i('promo');
381 if (Env::has('sub10')) $promo -= 10;
382 if (Env::has('sub01')) $promo -= 1;
383 if (Env::has('add01')) $promo += 1;
384 if (Env::has('add10')) $promo += 10;
385
386 $page->assign('promo',$promo);
387
388 if ($validate) {
389 $new_deces = array();
390 $res = XDB::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo);
391 while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) {
392 $val = Env::v($mat);
393 if($val == $deces || empty($val)) continue;
394 XDB::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat);
395 $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val");
396 if($deces=='0000-00-00' or empty($deces)) {
397 require_once('notifs.inc.php');
398 register_watch_op($uid, WATCH_DEATH, $val);
399 require_once('user.func.inc.php');
400 user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email
401 }
402 }
403 $page->assign('new_deces',$new_deces);
404 }
405
406 $res = XDB::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo);
407 $page->assign('decedes', $res);
408 }
409
410 function handler_synchro_ax(&$page, $user = null, $action = null) {
411 $page->changeTpl('admin/synchro_ax.tpl');
412 $page->assign('xorg_title','Polytechnique.org - Administration - Synchro AX');
413
414 require_once('synchro_ax.inc.php');
415
416 if (is_ax_key_missing()) {
417 $page->assign('no_private_key', true);
418 $page->run();
419 }
420
421 require_once('user.func.inc.php');
422
423 if ($user)
424 $login = get_user_forlife($user);
425
426 if (Env::has('user')) {
427 $login = get_user_forlife(Env::v('user'));
428 if ($login === false) {
429 return;
430 }
431 }
432
433 if (Env::has('mat')) {
434 $res = XDB::query(
435 "SELECT alias
436 FROM aliases AS a
437 INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie')
438 WHERE matricule={?}", Env::i('mat'));
439 $login = $res->fetchOneCell();
440 }
441
442 if ($login) {
443 if ($action == 'import') {
444 ax_synchronize($login, S::v('uid'));
445 }
446 // get details from user, but looking only info that can be seen by ax
447 $user = get_user_details($login, S::v('uid'), 'ax');
448 $userax= get_user_ax($user['matricule_ax']);
449 require_once 'profil.func.inc.php';
450 $diff = diff_user_details($userax, $user, 'ax');
451
452 $page->assign('x', $user);
453 $page->assign('diff', $diff);
454 }
455 }
456
457 function handler_validate(&$page) {
458 $page->changeTpl('admin/valider.tpl');
459 $page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande');
460 require_once("validations.inc.php");
461
462 if(Env::has('uid') && Env::has('type') && Env::has('stamp')) {
463 $req = Validate::get_request(Env::v('uid'), Env::v('type'), Env::v('stamp'));
464 if($req) { $req->handle_formu(); }
465 }
466
467 $r = XDB::iterator('SHOW COLUMNS FROM requests_answers');
468 while (($a = $r->next()) && $a['Field'] != 'category');
469 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
470
471 $hidden = array();
472 if (Post::has('hide')) {
473 $hide = array();
474 foreach ($categories as $cat)
475 if (!Post::v($cat)) {
476 $hidden[$cat] = 1;
477 $hide[] = $cat;
478 }
479 setcookie('hide_requests', join(',',$hide), time()+(count($hide)?25920000:(-3600)), '/', '', 0);
480 } elseif (Env::has('hide_requests')) {
481 foreach (explode(',',Env::v('hide_requests')) as $hide_type)
482 $hidden[$hide_type] = true;
483 }
484 $page->assign('hide_requests', $hidden);
485
486 $page->assign('vit', new ValidateIterator());
487 }
488 function handler_validate_answers(&$page, $action = 'list', $id = null) {
489 require_once('../classes/PLTableEditor.php');
490 $page->assign('xorg_title','Polytechnique.org - Administration - Réponses automatiques de validation');
491 $page->assign('title', 'Gestion des réponses automatiques');
492 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
493 $table_editor->describe('category','catégorie',true);
494 $table_editor->describe('title','titre',true);
495 $table_editor->describe('answer','texte',false);
496 $table_editor->apply($page, $action, $id);
497 }
498 function handler_skins(&$page, $action = 'list', $id = null) {
499 require_once('../classes/PLTableEditor.php');
500 $page->assign('xorg_title','Polytechnique.org - Administration - Skins');
501 $page->assign('title', 'Gestion des skins');
502 $table_editor = new PLTableEditor('admin/skins','skins','id');
503 $table_editor->describe('name','nom',true);
504 $table_editor->describe('skin_tpl','nom du template',true);
505 $table_editor->describe('auteur','auteur',false);
506 $table_editor->describe('comment','commentaire',true);
507 $table_editor->describe('date','date',false);
508 $table_editor->describe('ext','extension du screenshot',false);
509 $table_editor->apply($page, $action, $id);
510 }
511 function handler_postfix_blacklist(&$page, $action = 'list', $id = null) {
512 require_once('../classes/PLTableEditor.php');
513 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Blacklist');
514 $page->assign('title', 'Blacklist de postfix');
515 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true);
516 $table_editor->describe('reject_text','Texte de rejet',true);
517 $table_editor->describe('email','email',true);
518 $table_editor->apply($page, $action, $id);
519 }
520 function handler_postfix_whitelist(&$page, $action = 'list', $id = null) {
521 require_once('../classes/PLTableEditor.php');
522 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Whitelist');
523 $page->assign('title', 'Whitelist de postfix');
524 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true);
525 $table_editor->describe('email','email',true);
526 $table_editor->apply($page, $action, $id);
527 }
528 function handler_logger_actions(&$page, $action = 'list', $id = null) {
529 require_once('../classes/PLTableEditor.php');
530 $page->assign('xorg_title','Polytechnique.org - Administration - Actions');
531 $page->assign('title', 'Gestion des actions de logger');
532 $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id');
533 $table_editor->describe('text','intitulé',true);
534 $table_editor->describe('description','description',true);
535 $table_editor->apply($page, $action, $id);
536 }
537 function handler_downtime(&$page, $action = 'list', $id = null) {
538 require_once('../classes/PLTableEditor.php');
539 $page->assign('xorg_title','Polytechnique.org - Administration - Coupures');
540 $page->assign('title', 'Gestion des coupures');
541 $table_editor = new PLTableEditor('admin/downtime','coupures','id');
542 $table_editor->describe('debut','date',true);
543 $table_editor->describe('duree','durée',false);
544 $table_editor->describe('resume','résumé',true);
545 $table_editor->describe('services','services affectés',true);
546 $table_editor->describe('description','description',false);
547 $table_editor->apply($page, $action, $id);
548 }
549 function handler_wiki(&$page, $action='list') {
550 require_once 'wiki.inc.php';
551
552 // update wiki perms
553 if ($action == 'update') {
554 $perms_read = Post::v('read');
555 $perms_edot = Post::v('edit');
556 if ($perms_read || $perms_edit) {
557 foreach ($_POST as $wiki_page => $val) if ($val == 'on') {
558 $wiki_page = str_replace('_', '/', $wiki_page);
559 if (!$perms_read || !$perms_edit)
560 list($perms0, $perms1) = wiki_get_perms($wiki_page);
561 if ($perms_read)
562 $perms0 = $perms_read;
563 if ($perms_edit)
564 $perms1 = $perms_edit;
565 wiki_set_perms($wiki_page, $perms0, $perms1);
566 }
567 }
568 }
569
570 $perms = wiki_perms_options();
571
572 // list wiki pages and their perms
573 $wiki_pages = array();
574 $dir = wiki_work_dir();
575 if (is_dir($dir)) {
576 if ($dh = opendir($dir)) {
577 while (($file = readdir($dh)) !== false) if (substr($file,0,1) >= 'A' && substr($file,0,1) <= 'Z') {
578 list($read,$edit) = wiki_get_perms($file);
579 $wiki_pages[$file] = array('read' => $perms[$read], 'edit' => $perms[$edit]);
580 }
581 closedir($dh);
582 }
583 }
584 ksort($wiki_pages);
585
586 $page->changeTpl('admin/wiki.tpl');
587 $page->assign('wiki_pages', $wiki_pages);
588 $page->assign('perms_opts', $perms);
589 }
590 }
591
592 ?>