admin/emails/broken: remove trailing spaces after email addresses
[platal.git] / modules / email.php
index 09d840a..78cef2d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2013 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -41,7 +41,7 @@ class EmailModule extends PLModule
             'admin/emails/duplicated' => $this->make_hook('duplicated',  AUTH_PASSWD, 'admin'),
             'admin/emails/watch'      => $this->make_hook('duplicated',  AUTH_PASSWD, 'admin'),
             'admin/emails/lost'       => $this->make_hook('lost',        AUTH_PASSWD, 'admin'),
-            'admin/emails/broken'     => $this->make_hook('broken_addr', AUTH_PASSWD, 'admin'),
+            'admin/emails/broken'     => $this->make_hook('broken_addr', AUTH_PASSWD, 'admin,edit_directory'),
         );
     }
 
@@ -98,9 +98,23 @@ class EmailModule extends PLModule
                               INNER JOIN  email_virtual_domains AS m ON (s.domain = m.id)
                               INNER JOIN  email_virtual_domains AS d ON (d.aliasing = m.id)
                                    WHERE  s.uid = {?}
-                                ORDER BY  !alias, s.email",
+                                ORDER BY  !alias, s.email, d.name",
                                  $user->id());
-        $page->assign('aliases', $aliases);
+        $aliases_forlife = array();
+        $aliases_hundred = array();
+        $aliases_other = array();
+        while ($a = $aliases->next()) {
+            if ($a['forlife']) {
+                $aliases_forlife[] = $a;
+            } elseif ($a['hundred_year']) {
+                $aliases_hundred[] = $a;
+            } else {
+                $aliases_other[] = $a;
+            }
+        }
+        $page->assign('aliases_forlife', $aliases_forlife);
+        $page->assign('aliases_hundred', $aliases_hundred);
+        $page->assign('aliases_other', $aliases_other);
 
         $alias = XDB::fetchOneCell('SELECT  COUNT(email)
                                       FROM  email_source_account
@@ -791,7 +805,8 @@ class EmailModule extends PLModule
                                                                               AND er.type != \'imap\' AND er.type != \'homonym\')
                                   LEFT JOIN  account_profiles       AS ap ON (ap.uid = a.uid AND FIND_IN_SET(\'owner\', ap.perms))
                                   LEFT JOIN  profile_display        AS pd ON (ap.pid = pd.pid)
-                                      WHERE  a.state = \'active\' AND er.redirect IS NULL AND FIND_IN_SET(\'mail\', at.perms)
+                                  LEFT JOIN  profiles               AS p ON (ap.pid = p.pid)
+                                      WHERE  a.state = \'active\' AND er.redirect IS NULL AND FIND_IN_SET(\'mail\', at.perms) AND p.deathdate IS NULL
                                    GROUP BY  a.uid
                                    ORDER BY  pd.promo, a.hruid'));
     }
@@ -852,6 +867,7 @@ class EmailModule extends PLModule
                 sort($broken_list);
 
                 foreach ($broken_list as $email) {
+                    $email = trim($email);
                     $userobj = null;
                     if ($user = mark_broken_email($email, true)) {
                         $userobj = User::getSilentWithUID($user['uid']);
@@ -892,6 +908,14 @@ class EmailModule extends PLModule
                                WHERE  flags = \'active\' AND broken_level = 1
                                       AND DATE_ADD(last, INTERVAL 1 YEAR) < CURDATE()');
 
+                // Sort $broken_user_list with (promo, sortname, pid)
+                $sortable_array = array();
+                foreach ($broken_user_list as $pid => $mails) {
+                    $profile = $broken_user_profiles[$pid];
+                    $sortable_array[$pid] = array($profile->promo(), $profile->sortName(), $pid);
+                }
+                asort($sortable_array);
+
                 // Output the list of users with recently broken addresses,
                 // along with the count of valid redirections.
                 pl_cached_content_headers('text/x-csv', 1);
@@ -899,7 +923,8 @@ class EmailModule extends PLModule
                 $csv = fopen('php://output', 'w');
                 fputcsv($csv, array('nom', 'promo', 'bounces', 'nbmails', 'url', 'corps', 'job', 'networking'), ';');
                 $corpsList = DirEnum::getOptions(DirEnum::CURRENTCORPS);
-                foreach ($broken_user_list as $pid => $mails) {
+                foreach (array_keys($sortable_array) as $pid) {
+                    $mails = $broken_user_list[$pid];
                     $profile = $broken_user_profiles[$pid];
                     $current_corps = $profile->getCorpsName();
                     $jobs = $profile->getJobs();
@@ -924,5 +949,5 @@ class EmailModule extends PLModule
     }
 }
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>