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