24a37fdfd583a842d79180fbe3da4b4e464cc1f8
[platal.git] / modules / email.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 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 EmailModule extends PLModule
23 {
24 function handlers()
25 {
26 return array(
27 'emails' => $this->make_hook('emails', AUTH_COOKIE),
28 'emails/alias' => $this->make_hook('alias', AUTH_MDP),
29 'emails/antispam' => $this->make_hook('antispam', AUTH_MDP),
30 'emails/broken' => $this->make_hook('broken', AUTH_COOKIE),
31 'emails/redirect' => $this->make_hook('redirect', AUTH_MDP),
32 'emails/send' => $this->make_hook('send', AUTH_MDP),
33 'emails/antispam/submit' => $this->make_hook('submit', AUTH_COOKIE),
34 'emails/test' => $this->make_hook('test', AUTH_COOKIE, 'user', NO_AUTH),
35
36 'admin/emails/duplicated' => $this->make_hook('duplicated', AUTH_MDP, 'admin'),
37 'admin/emails/watch' => $this->make_hook('duplicated', AUTH_MDP, 'admin'),
38 'admin/emails/lost' => $this->make_hook('lost', AUTH_MDP, 'admin'),
39 );
40 }
41
42 function handler_emails(&$page, $action = null, $email = null)
43 {
44 global $globals;
45
46 $page->changeTpl('emails/index.tpl');
47 $page->assign('xorg_title','Polytechnique.org - Mes emails');
48
49 $uid = S::v('uid');
50
51 if ($action == 'best' && $email) {
52 // bestalias is the first bit : 1
53 // there will be maximum 8 bits in flags : 255
54 XDB::execute("UPDATE aliases SET flags=flags & (255 - 1) WHERE id={?}", $uid);
55 XDB::execute("UPDATE aliases SET flags=flags | 1 WHERE id={?} AND alias={?}",
56 $uid, $email);
57 }
58
59 // on regarde si on a affaire à un homonyme
60 $sql = "SELECT alias, (type='a_vie') AS a_vie,
61 (alias REGEXP '\\\\.[0-9]{2}$') AS cent_ans,
62 FIND_IN_SET('bestalias',flags) AS best, expire
63 FROM aliases
64 WHERE id = {?} AND type!='homonyme'
65 ORDER BY LENGTH(alias)";
66 $page->assign('aliases', XDB::iterator($sql, $uid));
67
68 $homonyme = XDB::query("SELECT alias FROM aliases INNER JOIN homonymes ON (id = homonyme_id) WHERE user_id = {?} AND type = 'homonyme'", $uid);
69 $page->assign('homonyme', $homonyme->fetchOneCell());
70
71 // Affichage des redirections de l'utilisateur.
72 $sql = "SELECT email
73 FROM emails
74 WHERE uid = {?} AND FIND_IN_SET('active', flags)";
75 $page->assign('mails', XDB::iterator($sql, $uid));
76
77 // Affichage des backends actifs de stockage des emails.
78 $sql = "SELECT mail_storage
79 FROM auth_user_md5
80 WHERE user_id = {?}";
81 $storages = XDB::query($sql, $uid)->fetchOneCell();
82 $page->assign('storage', explode(',', $storages));
83
84 // on regarde si l'utilisateur a un alias et si oui on l'affiche !
85 $forlife = S::v('forlife');
86 $res = XDB::query(
87 "SELECT alias
88 FROM virtual AS v
89 INNER JOIN virtual_redirect AS vr USING(vid)
90 WHERE (redirect={?} OR redirect={?})
91 AND alias LIKE '%@{$globals->mail->alias_dom}'",
92 $forlife.'@'.$globals->mail->domain, $forlife.'@'.$globals->mail->domain2);
93 $page->assign('melix', $res->fetchOneCell());
94 }
95
96 function handler_alias(&$page, $action = null, $value = null)
97 {
98 require_once 'validations.inc.php';
99
100 global $globals;
101
102 $page->changeTpl('emails/alias.tpl');
103 $page->assign('xorg_title','Polytechnique.org - Alias melix.net');
104
105 $uid = S::v('uid');
106 $forlife = S::v('forlife');
107
108 $page->assign('demande', AliasReq::get_request($uid));
109
110 if ($action == 'delete' && $value) {
111 //Suppression d'un alias
112 XDB::execute(
113 'DELETE virtual, virtual_redirect
114 FROM virtual
115 INNER JOIN virtual_redirect USING (vid)
116 WHERE alias = {?} AND (redirect = {?} OR redirect = {?})', $value,
117 $forlife.'@'.$globals->mail->domain, $forlife.'@'.$globals->mail->domain2);
118 }
119
120 //Récupération des alias éventuellement existants
121 $res = XDB::query(
122 "SELECT alias, emails_alias_pub
123 FROM auth_user_quick, virtual
124 INNER JOIN virtual_redirect USING(vid)
125 WHERE ( redirect={?} OR redirect= {?} )
126 AND alias LIKE '%@{$globals->mail->alias_dom}' AND user_id = {?}",
127 $forlife.'@'.$globals->mail->domain,
128 $forlife.'@'.$globals->mail->domain2, S::v('uid'));
129 list($alias, $visibility) = $res->fetchOneRow();
130 $page->assign('actuel', $alias);
131
132 if ($action == 'ask' && Env::has('alias') and Env::has('raison')) {
133 //Si l'utilisateur vient de faire une damande
134
135 $alias = Env::v('alias');
136 $raison = Env::v('raison');
137 $public = (Env::v('public', 'off') == 'on')?"public":"private";
138
139 $page->assign('r_alias', $alias);
140 $page->assign('r_raison', $raison);
141 if ($public == 'public') {
142 $page->assign('r_public', true);
143 }
144
145 //Quelques vérifications sur l'alias (caractères spéciaux)
146 if (!preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $alias)) {
147 $page->trig("L'adresse demandée n'est pas valide.
148 Vérifie qu'elle comporte entre 3 et 20 caractères
149 et qu'elle ne contient que des lettres non accentuées,
150 des chiffres ou les caractères - et .");
151 return;
152 } else {
153 //vérifier que l'alias n'est pas déja pris
154 $res = XDB::query('SELECT COUNT(*) FROM virtual WHERE alias={?}',
155 $alias.'@'.$globals->mail->alias_dom);
156 if ($res->fetchOneCell() > 0) {
157 $page->trig("L'alias $alias@{$globals->mail->alias_dom} a déja été attribué.
158 Tu ne peux donc pas l'obtenir.");
159 return;
160 }
161
162 //vérifier que l'alias n'est pas déja en demande
163 $it = new ValidateIterator ();
164 while($req = $it->next()) {
165 if ($req->type == "alias" and $req->alias == $alias . '@' . $globals->mail->alias_dom) {
166 $page->trig("L'alias $alias@{$globals->mail->alias_dom} a déja été demandé.
167 Tu ne peux donc pas l'obtenir pour l'instant.");
168 return ;
169 }
170 }
171
172 //Insertion de la demande dans la base, écrase les requêtes précédente
173 $myalias = new AliasReq($uid, $alias, $raison, $public);
174 $myalias->submit();
175 $page->assign('success',$alias);
176 return;
177 }
178 }
179 elseif ($action == 'set'
180 && ($value == 'public' || $value == 'private'))
181 {
182 if ($value == 'public') {
183 XDB::execute("UPDATE auth_user_quick SET emails_alias_pub = 'public'
184 WHERE user_id = {?}", S::v('uid'));
185 } else {
186 XDB::execute("UPDATE auth_user_quick SET emails_alias_pub = 'private'
187 WHERE user_id = {?}", S::v('uid'));
188 }
189
190 $visibility = $value;
191 }
192
193 $page->assign('mail_public', ($visibility == 'public'));
194 }
195
196 function handler_redirect(&$page, $action = null, $email = null)
197 {
198 global $globals;
199
200 require_once 'emails.inc.php';
201
202 $page->changeTpl('emails/redirect.tpl');
203
204 $uid = S::v('uid');
205 $forlife = S::v('forlife');
206
207 $page->assign('eleve', S::i('promo') >= date("Y") - 5);
208
209 $redirect = new Redirect(S::v('uid'));
210
211 // FS#703 : $_GET is urldecoded twice, hence
212 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
213 // Since there can be no spaces in emails, we can fix this with :
214 $email = str_replace(' ', '+', $email);
215
216 if ($action == 'remove' && $email) {
217 $retour = $redirect->delete_email($email);
218 $page->assign('retour', $retour);
219 }
220
221 if ($action == 'active' && $email) {
222 $redirect->modify_one_email($email, true);
223 }
224
225 if ($action == 'inactive' && $email) {
226 $redirect->modify_one_email($email, false);
227 }
228
229 if ($action == 'rewrite' && $email) {
230 $rewrite = @func_get_arg(3);
231 $redirect->modify_one_email_redirect($email, $rewrite);
232 }
233
234 if (Env::has('emailop')) {
235 $actifs = Env::v('emails_actifs', Array());
236 print_r(Env::v('emails_rewrite'));
237 if (Env::v('emailop') == "ajouter" && Env::has('email')) {
238 $page->assign('retour', $redirect->add_email(Env::v('email')));
239 } elseif (empty($actifs)) {
240 $page->assign('retour', ERROR_INACTIVE_REDIRECTION);
241 } elseif (is_array($actifs)) {
242 $page->assign('retour', $redirect->modify_email($actifs,
243 Env::v('emails_rewrite',Array())));
244 }
245 }
246
247 $res = XDB::query(
248 "SELECT alias
249 FROM virtual
250 INNER JOIN virtual_redirect USING(vid)
251 WHERE (redirect={?} OR redirect={?})
252 AND alias LIKE '%@{$globals->mail->alias_dom}'",
253 $forlife.'@'.$globals->mail->domain, $forlife.'@'.$globals->mail->domain2);
254 $melix = $res->fetchOneCell();
255 if ($melix) {
256 list($melix) = explode('@', $melix);
257 $page->assign('melix',$melix);
258 }
259
260 $res = XDB::query(
261 "SELECT alias,expire
262 FROM aliases
263 WHERE id={?} AND (type='a_vie' OR type='alias')
264 ORDER BY !FIND_IN_SET('usage',flags), LENGTH(alias)", $uid);
265
266 $page->assign('alias', $res->fetchAllAssoc());
267 $page->assign('emails',$redirect->emails);
268
269 require_once 'googleapps.inc.php';
270 $page->assign('googleapps', GoogleAppsAccount::account_status($uid));
271 }
272
273 function handler_antispam(&$page, $statut_filtre = null)
274 {
275 require_once 'emails.inc.php';
276 require_once('wiki.inc.php');
277 wiki_require_page('Xorg.Antispam');
278
279 $page->changeTpl('emails/antispam.tpl');
280
281 $bogo = new Bogo(S::v('uid'));
282 if (isset($statut_filtre)) {
283 $bogo->change($statut_filtre + 0);
284 }
285 $page->assign('filtre',$bogo->level());
286 }
287
288 function handler_submit(&$page)
289 {
290 require_once('wiki.inc.php');
291 wiki_require_page('Xorg.Mails');
292 $page->changeTpl('emails/submit_spam.tpl');
293
294 if (Post::has('send_email')) {
295 $upload = PlUpload::get($_FILES['mail'], S::v('forlife'), 'spam.submit', true);
296 if (!$upload) {
297 $page->trig('Une erreur a été rencontrée lors du transfert du fichier');
298 return;
299 }
300 $mime = $upload->contentType();
301 if ($mime != 'text/x-mail' && $mime != 'message/rfc822') {
302 $upload->clear();
303 $page->trig('Le fichier ne contient pas un mail complet');
304 return;
305 }
306 global $globals;
307 $box = Post::v('type') . '@' . $globals->mail->domain;
308 $mailer = new PlMailer();
309 $mailer->addTo($box);
310 $mailer->setFrom('"' . S::v('prenom') . ' ' . S::v('nom') . '" <web@' . $globals->mail->domain . '>');
311 $mailer->setTxtBody(Post::v('type') . ' soumis par ' . S::v('forlife') . ' via le web');
312 $mailer->addUploadAttachment($upload, Post::v('type') . '.mail');
313 $mailer->send();
314 $page->trig('Le message a été transmis à ' . $box);
315 $upload->clear();
316 }
317 }
318
319 function handler_send(&$page)
320 {
321 global $globals;
322 $page->changeTpl('emails/send.tpl');
323 $page->addJsLink('ajax.js');
324
325 $page->assign('xorg_title','Polytechnique.org - Envoyer un email');
326
327 // action si on recoit un formulaire
328 if (Post::has('save')) {
329 unset($_POST['save']);
330 if (trim(preg_replace('/-- .*/', '', Post::v('contenu'))) != "") {
331 $_POST['to_contacts'] = explode(';', @$_POST['to_contacts']);
332 $_POST['cc_contacts'] = explode(';', @$_POST['cc_contacts']);
333 $data = serialize($_POST);
334 XDB::execute("REPLACE INTO email_send_save
335 VALUES ({?}, {?})", S::i('uid'), $data);
336 }
337 exit;
338 } else if (Env::v('submit') == 'Envoyer') {
339 function getEmails($aliases)
340 {
341 if (!is_array($aliases)) {
342 return null;
343 }
344 $rel = Env::v('contacts');
345 $ret = array();
346 foreach ($aliases as $alias) {
347 $ret[$alias] = $rel[$alias];
348 }
349 return join(', ', $ret);
350 }
351
352 $error = false;
353 foreach ($_FILES as &$file) {
354 if ($file['name'] && !PlUpload::get($file, S::v('forlife'), 'emails.send', false)) {
355 $page->trig(PlUpload::$lastError);
356 $error = true;
357 break;
358 }
359 }
360
361 if (!$error) {
362 XDB::execute("DELETE FROM email_send_save
363 WHERE uid = {?}", S::i('uid'));
364
365 $to2 = getEmails(Env::v('to_contacts'));
366 $cc2 = getEmails(Env::v('cc_contacts'));
367 $txt = str_replace('^M', '', Env::v('contenu'));
368 $to = Env::v('to');
369 $subj = Env::v('sujet');
370 $from = Env::v('from');
371 $cc = trim(Env::v('cc'));
372 $bcc = trim(Env::v('bcc'));
373
374 if (empty($to) && empty($cc) && empty($to2) && empty($bcc) && empty($cc2)) {
375 $page->trig("Indique au moins un destinataire.");
376 $page->assign('uploaded_f', PlUpload::listFilenames(S::v('forlife'), 'emails.send'));
377 } else {
378 $mymail = new PlMailer();
379 $mymail->setFrom($from);
380 $mymail->setSubject($subj);
381 if (!empty($to)) { $mymail->addTo($to); }
382 if (!empty($cc)) { $mymail->addCc($cc); }
383 if (!empty($bcc)) { $mymail->addBcc($bcc); }
384 if (!empty($to2)) { $mymail->addTo($to2); }
385 if (!empty($cc2)) { $mymail->addCc($cc2); }
386 $files =& PlUpload::listFiles(S::v('forlife'), 'emails.send');
387 foreach ($files as $name=>&$upload) {
388 $mymail->addUploadAttachment($upload, $name);
389 }
390 if (Env::v('nowiki')) {
391 $mymail->setTxtBody(wordwrap($txt, 78, "\n"));
392 } else {
393 $mymail->setWikiBody($txt);
394 }
395 if ($mymail->send()) {
396 $page->trig("Ton mail a bien été envoyé.");
397 $_REQUEST = array('bcc' => S::v('bestalias').'@'.$globals->mail->domain);
398 PlUpload::clear(S::v('forlife'), 'emails.send');
399 } else {
400 $page->trig("Erreur lors de l'envoi du courriel, réessaye.");
401 $page->assign('uploaded_f', PlUpload::listFilenames(S::v('forlife'), 'emails.send'));
402 }
403 }
404 }
405 } else {
406 $res = XDB::query("SELECT data
407 FROM email_send_save
408 WHERE uid = {?}", S::i('uid'));
409 if ($res->numRows() == 0) {
410 PlUpload::clear(S::v('forlife'), 'emails.send');
411 $_REQUEST['bcc'] = S::v('bestalias').'@'.$globals->mail->domain;
412 } else {
413 $data = unserialize($res->fetchOneCell());
414 $_REQUEST = array_merge($_REQUEST, $data);
415 }
416 }
417
418 $res = XDB::query(
419 "SELECT u.prenom, u.nom, u.promo, a.alias as forlife
420 FROM auth_user_md5 AS u
421 INNER JOIN contacts AS c ON (u.user_id = c.contact)
422 INNER JOIN aliases AS a ON (u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags))
423 WHERE c.uid = {?}
424 ORDER BY u.nom, u.prenom", S::v('uid'));
425 $page->assign('contacts', $res->fetchAllAssoc());
426 $page->assign('maxsize', ini_get('upload_max_filesize') . 'o');
427 }
428
429 function handler_test(&$page, $forlife = null)
430 {
431 global $globals;
432 if (!S::has_perms() || !$forlife) {
433 $forlife = S::v('bestalias');
434 }
435 $mailer = new PlMailer('emails/test.mail.tpl');
436 $mailer->assign('email', $forlife . '@' . $globals->mail->domain);
437 $iterator = XDB::iterator("SELECT email
438 FROM emails AS e
439 INNER JOIN aliases AS a ON (e.uid = a.id)
440 WHERE FIND_IN_SET('active', e.flags) AND a.alias = {?}",
441 $forlife);
442 $mailer->assign('redirects', $iterator);
443 $res = XDB::query("SELECT FIND_IN_SET('femme', u.flags), prenom
444 FROM auth_user_md5 AS u
445 INNER JOIN aliases AS a ON (a.id = u.user_id)
446 WHERE a.alias = {?}", $forlife);
447 list($sexe, $prenom) = $res->fetchOneRow();
448 $mailer->assign('sexe', $sexe);
449 $mailer->assign('prenom', $prenom);
450 $mailer->send();
451 exit;
452 }
453
454 function handler_broken(&$page, $warn = null, $email = null)
455 {
456 require_once 'emails.inc.php';
457 require_once('wiki.inc.php');
458 wiki_require_page('Xorg.PatteCassée');
459
460 global $globals;
461
462 $page->changeTpl('emails/broken.tpl');
463
464 if ($warn == 'warn' && $email) {
465 $email = valide_email($email);
466 // vérifications d'usage
467 $sel = XDB::query(
468 "SELECT e.uid, a.alias
469 FROM emails AS e
470 INNER JOIN auth_user_md5 AS u ON e.uid = u.user_id
471 INNER JOIN aliases AS a ON (e.uid = a.id AND type!='homonyme'
472 AND FIND_IN_SET('bestalias',a.flags))
473 WHERE e.email={?}", $email);
474
475 if (list($uid, $dest) = $sel->fetchOneRow()) {
476 // envoi du mail
477 $message = "Bonjour !
478
479 Ce mail a été généré automatiquement par le service de patte cassée de
480 Polytechnique.org car un autre utilisateur, ".S::v('prenom').' '.S::v('nom').",
481 nous a signalé qu'en t'envoyant un mail, il avait reçu un message d'erreur
482 indiquant que ton adresse de redirection $email
483 ne fonctionnait plus !
484
485 Nous te suggérons de vérifier cette adresse, et le cas échéant de mettre
486 à jour sur le site <{$globals->baseurl}/emails> tes adresses
487 de redirection...
488
489 Pour plus de rensignements sur le service de patte cassée, n'hésites pas à
490 consulter la page <{$globals->baseurl}/emails/broken>.
491
492
493 A bientôt sur Polytechnique.org !
494 L'équipe d'administration <support@" . $globals->mail->domain . '>';
495
496 $mail = new PlMailer();
497 $mail->setFrom('"Polytechnique.org" <support@' . $globals->mail->domain . '>');
498 $mail->addTo("$dest@" . $globals->mail->domain);
499 $mail->setSubject("Une de tes adresse de redirection Polytechnique.org ne marche plus !!");
500 $mail->setTxtBody($message);
501 $mail->send();
502 $page->trig("Mail envoyé ! :o)");
503 }
504 } elseif (Post::has('email')) {
505 $email = valide_email(Post::v('email'));
506
507 list(,$fqdn) = explode('@', $email);
508 $fqdn = strtolower($fqdn);
509 if ($fqdn == 'polytechnique.org' || $fqdn == 'melix.org'
510 || $fqdn == 'm4x.org' || $fqdn == 'melix.net')
511 {
512 $page->assign('neuneu', true);
513 } else {
514 $page->assign('email',$email);
515 $sel = XDB::query(
516 "SELECT e1.uid, e1.panne != 0 AS panne, count(e2.uid) AS nb_mails,
517 u.nom, u.prenom, u.promo, a.alias AS forlife
518 FROM emails as e1
519 LEFT JOIN emails as e2 ON(e1.uid = e2.uid
520 AND FIND_IN_SET('active', e2.flags)
521 AND e1.email != e2.email)
522 INNER JOIN auth_user_md5 as u ON(e1.uid = u.user_id)
523 INNER JOIN aliases AS a ON (a.id = e1.uid AND a.type = 'a_vie')
524 WHERE e1.email = {?}
525 GROUP BY e1.uid", $email);
526 if ($x = $sel->fetchOneAssoc()) {
527 // on écrit dans la base que l'adresse est cassée
528 if (!$x['panne']) {
529 XDB::execute("UPDATE emails
530 SET panne=NOW(),
531 last=NOW(),
532 panne_level = 1
533 WHERE email = {?}", $email);
534 } else {
535 XDB::execute("UPDATE emails
536 SET panne_level = 1
537 WHERE email = {?} AND panne_level = 0", $email);
538 }
539 $page->assign_by_ref('x', $x);
540 }
541 }
542 }
543 }
544
545 function handler_duplicated(&$page, $action = 'list', $email = null)
546 {
547 $page->changeTpl('emails/duplicated.tpl');
548
549 $states = array('pending' => 'En attente...',
550 'safe' => 'Pas d\'inquiétude',
551 'unsafe' => 'Recherches en cours',
552 'dangerous' => 'Usurpations par cette adresse');
553 $page->assign('states', $states);
554
555 switch (Post::v('action')) {
556 case 'create':
557 if (trim(Post::v('emailN')) != '') {
558 Xdb::execute('INSERT IGNORE INTO emails_watch (email, state, detection, last, uid, description)
559 VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})',
560 trim(Post::v('emailN')), Post::v('stateN'), S::i('uid'), Post::v('descriptionN'));
561 };
562 break;
563
564 case 'edit':
565 Xdb::execute('UPDATE emails_watch
566 SET state = {?}, last = NOW(), uid = {?}, description = {?}
567 WHERE email = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), Post::v('emailN'));
568 break;
569
570 default:
571 if ($action == 'delete' && !is_null($email)) {
572 Xdb::execute('DELETE FROM emails_watch WHERE email = {?}', $email);
573 }
574 }
575 if ($action != 'create' && $action != 'edit') {
576 $action = 'list';
577 }
578 $page->assign('action', $action);
579
580 if ($action == 'list') {
581 $sql = "SELECT w.email, w.detection, w.state, a.alias AS forlife
582 FROM emails_watch AS w
583 LEFT JOIN emails AS e USING(email)
584 LEFT JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie')
585 ORDER BY w.state, w.email, a.alias";
586 $it = Xdb::iterRow($sql);
587
588 $table = array();
589 $props = array();
590 while (list($email, $date, $state, $forlife) = $it->next()) {
591 if (count($props) == 0 || $props['mail'] != $email) {
592 if (count($props) > 0) {
593 $table[] = $props;
594 }
595 $props = array('mail' => $email,
596 'detection' => $date,
597 'state' => $state,
598 'users' => array($forlife));
599 } else {
600 $props['users'][] = $forlife;
601 }
602 }
603 if (count($props) > 0) {
604 $table[] = $props;
605 }
606 $page->assign('table', $table);
607 } elseif ($action == 'edit') {
608 $sql = "SELECT w.detection, w.state, w.last, w.description,
609 a1.alias AS edit, a2.alias AS forlife
610 FROM emails_watch AS w
611 LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie')
612 LEFT JOIN emails AS e ON (w.email = e.email)
613 LEFT JOIN aliases AS a2 ON (a2.id = e.uid AND a2.type = 'a_vie')
614 WHERE w.email = {?}
615 ORDER BY a2.alias";
616 $it = Xdb::iterRow($sql, $email);
617
618 $props = array();
619 while (list($detection, $state, $last, $description, $edit, $forlife) = $it->next()) {
620 if (count($props) == 0) {
621 $props = array('mail' => $email,
622 'detection' => $detection,
623 'state' => $state,
624 'last' => $last,
625 'description' => $description,
626 'edit' => $edit,
627 'users' => array($forlife));
628 } else {
629 $props['users'][] = $forlife;
630 }
631 }
632 $page->assign('doublon', $props);
633 }
634 }
635 function handler_lost(&$page, $action = 'list', $email = null)
636 {
637 $page->changeTpl('emails/lost.tpl');
638
639 $page->assign('lost_emails', XDB::iterator('
640 SELECT u.user_id, a.alias
641 FROM auth_user_md5 AS u
642 INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = "a_vie")
643 LEFT JOIN emails AS e ON (u.user_id=e.uid AND FIND_IN_SET("active",e.flags))
644 WHERE e.uid IS NULL AND u.deces = 0
645 ORDER BY u.promo DESC, u.nom, u.prenom'));
646 }
647 }
648
649 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
650 ?>