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