+
+ function handler_duplicated(&$page, $action = 'list', $email = null)
+ {
+ $page->changeTpl('emails/duplicated.tpl');
+
+ $states = array('pending' => 'En attente...',
+ 'safe' => 'Pas d\'inquiétude',
+ 'unsafe' => 'Recherches en cours',
+ 'dangerous' => 'Usurpations par cette adresse');
+ $page->assign('states', $states);
+
+ if (Post::has('action')) {
+ S::assert_xsrf_token();
+ }
+ switch (Post::v('action')) {
+ case 'create':
+ if (trim(Post::v('emailN')) != '') {
+ Xdb::execute('INSERT IGNORE INTO emails_watch (email, state, detection, last, uid, description)
+ VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})',
+ trim(Post::v('emailN')), Post::v('stateN'), S::i('uid'), Post::v('descriptionN'));
+ };
+ break;
+
+ case 'edit':
+ Xdb::execute('UPDATE emails_watch
+ SET state = {?}, last = NOW(), uid = {?}, description = {?}
+ WHERE email = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), Post::v('emailN'));
+ break;
+
+ default:
+ if ($action == 'delete' && !is_null($email)) {
+ Xdb::execute('DELETE FROM emails_watch WHERE email = {?}', $email);
+ }
+ }
+ if ($action != 'create' && $action != 'edit') {
+ $action = 'list';
+ }
+ $page->assign('action', $action);
+
+ if ($action == 'list') {
+ $sql = "SELECT w.email, w.detection, w.state, a.alias AS forlife
+ FROM emails_watch AS w
+ LEFT JOIN emails AS e USING(email)
+ LEFT JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie')
+ ORDER BY w.state, w.email, a.alias";
+ $it = Xdb::iterRow($sql);
+
+ $table = array();
+ $props = array();
+ while (list($email, $date, $state, $forlife) = $it->next()) {
+ if (count($props) == 0 || $props['mail'] != $email) {
+ if (count($props) > 0) {
+ $table[] = $props;
+ }
+ $props = array('mail' => $email,
+ 'detection' => $date,
+ 'state' => $state,
+ 'users' => array($forlife));
+ } else {
+ $props['users'][] = $forlife;
+ }
+ }
+ if (count($props) > 0) {
+ $table[] = $props;
+ }
+ $page->assign('table', $table);
+ } elseif ($action == 'edit') {
+ $sql = "SELECT w.detection, w.state, w.last, w.description,
+ a1.alias AS edit, a2.alias AS forlife
+ FROM emails_watch AS w
+ LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie')
+ LEFT JOIN emails AS e ON (w.email = e.email)
+ LEFT JOIN aliases AS a2 ON (a2.id = e.uid AND a2.type = 'a_vie')
+ WHERE w.email = {?}
+ ORDER BY a2.alias";
+ $it = Xdb::iterRow($sql, $email);
+
+ $props = array();
+ while (list($detection, $state, $last, $description, $edit, $forlife) = $it->next()) {
+ if (count($props) == 0) {
+ $props = array('mail' => $email,
+ 'detection' => $detection,
+ 'state' => $state,
+ 'last' => $last,
+ 'description' => $description,
+ 'edit' => $edit,
+ 'users' => array($forlife));
+ } else {
+ $props['users'][] = $forlife;
+ }
+ }
+ $page->assign('doublon', $props);
+ }
+ }
+ function handler_lost(&$page, $action = 'list', $email = null)
+ {
+ $page->changeTpl('emails/lost.tpl');
+
+ $page->assign('lost_emails', XDB::iterator('
+ SELECT u.user_id, a.alias
+ FROM auth_user_md5 AS u
+ INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = "a_vie")
+ LEFT JOIN emails AS e ON (u.user_id=e.uid AND FIND_IN_SET("active",e.flags))
+ WHERE e.uid IS NULL AND
+ FIND_IN_SET("googleapps", u.mail_storage) = 0 AND
+ u.deces = 0
+ ORDER BY u.promo DESC, u.nom, u.prenom'));
+ }