Fixes previous fix on password update.
[platal.git] / modules / email.php
index f7cedd5..197ae8e 100644 (file)
@@ -131,6 +131,9 @@ class EmailModule extends PLModule
         // Fetch existing @alias_dom aliases.
         $alias = $user->emailAlias();
         $visibility = $user->hasProfile() && $user->profile()->alias_pub;
+        $page->assign('actuel', $alias);
+        $page->assign('user', $user);
+        $page->assign('mail_public', $visibility);
 
         if ($action == 'ask' && Env::has('alias') && Env::has('raison')) {
             S::assert_xsrf_token();
@@ -195,6 +198,7 @@ class EmailModule extends PLModule
                             $value, $user->profile()->id());
             }
             $visibility = ($value == 'public');
+            exit;
         }
 
         $page->assign('actuel', $alias);
@@ -246,15 +250,18 @@ class EmailModule extends PLModule
             $actifs = Env::v('emails_actifs', Array());
             print_r(Env::v('emails_rewrite'));
             if (Env::v('emailop') == "ajouter" && Env::has('email')) {
+                $error_email = false;
                 $new_email = Env::v('email');
                 if ($new_email == "new@example.org") {
                     $new_email = Env::v('email_new');
                 }
                 $result = $redirect->add_email($new_email);
                 if ($result == ERROR_INVALID_EMAIL) {
+                    $error_email = true;
                     $page->assign('email', $new_email);
                 }
                 $page->assign('retour', $result);
+                $page->assign('error_email', $error_email);
             } elseif (empty($actifs)) {
                 $result = ERROR_INACTIVE_REDIRECTION;
             } elseif (is_array($actifs)) {
@@ -268,7 +275,7 @@ class EmailModule extends PLModule
                              . $user->forlifeEmail() . ' ne fonctionnerait plus.');
             break;
           case ERROR_INVALID_EMAIL:
-            $page->trigError('Erreur: l\'email n\'est pas valide.');
+            $page->trigError('Erreur : l\'email n\'est pas valide.');
             break;
           case ERROR_LOOP_EMAIL:
             $page->trigError('Erreur : ' . $user->forlifeEmail()
@@ -661,13 +668,14 @@ class EmailModule extends PLModule
                 $page->assign('neuneu', true);
             } else {
                 $page->assign('email',$email);
-                $x = XDB::fetchOneAssoc("SELECT  e1.uid, e1.panne != 0 AS panne,
-                                                 (count(e2.uid) + IF(FIND_IN_SET('googleapps', eo.storage), 1, 0)) AS nb_mails
-                                           FROM  emails as e1
+                $x = XDB::fetchOneAssoc("SELECT  e1.uid, e1.panne != 0 AS panne, a.hruid,
+                                                 (COUNT(e2.uid) + IF(FIND_IN_SET('googleapps', eo.storage), 1, 0)) AS nb_mails
+                                           FROM  emails        AS e1
                                      INNER JOIN  email_options AS eo ON (eo.uid = e1.uid)
-                                      LEFT JOIN  emails as e2 ON(e1.uid = e2.uid
-                                                 AND FIND_IN_SET('active', e2.flags)
-                                                 AND e1.email != e2.email)
+                                     INNER JOIN  accounts      AS a  ON (e1.uid = a.uid)
+                                      LEFT JOIN  emails        AS e2 ON (e1.uid = e2.uid
+                                                                         AND FIND_IN_SET('active', e2.flags)
+                                                                         AND e1.email != e2.email)
                                           WHERE  e1.email = {?}
                                        GROUP BY  e1.uid", $email);
                 if ($x) {
@@ -917,19 +925,21 @@ class EmailModule extends PLModule
                     $sel = Xdb::query(
                         "SELECT  acc.uid, count(e.email) AS nb_mails,
                                  IFNULL(pd.public_name, acc.full_name) AS fullname,
-                                 IFNULL(pd.promo, 0) AS promo,
-                           FROM  aliases    AS a
-                     INNER JOIN  accounts   AS acc ON a.id = acc.uid
-                      LEFT JOIN  emails     AS e ON (e.uid = acc.uid
-                                                        AND FIND_IN_SET('active', e.flags) AND e.panne = 0)
-                      LEFT JOIN  account_profiles AS ap ON (acc.uid = ap.uid AND FIND_IN_SET('owner', ap.perms))
-                      LEFT JOIN  profile_display AS pd ON (pd.pid = ap.pid)
+                                 IFNULL(pd.promo, 0) AS promo
+                           FROM  aliases          AS a
+                     INNER JOIN  accounts         AS acc ON (a.uid = acc.uid)
+                      LEFT JOIN  emails           AS e   ON (e.uid = acc.uid
+                                                             AND FIND_IN_SET('active', e.flags) AND e.panne = 0)
+                      LEFT JOIN  account_profiles AS ap  ON (acc.uid = ap.uid AND FIND_IN_SET('owner', ap.perms))
+                      LEFT JOIN  profile_display  AS pd  ON (pd.pid = ap.pid)
                           WHERE  a.alias = {?}
                        GROUP BY  acc.uid", $alias);
 
                     if ($x = $sel->fetchOneAssoc()) {
                         if ($x['nb_mails'] == 0) {
-                            register_profile_update($x['uid'], 'broken');
+                            $user = User::getSilentWithUID($x['uid']);
+                            $profile = $user->profile();
+                            WatchProfileUpdate::register($profile, 'broken');
                         }
                         fputcsv($csv, array($x['fullname'], $x['promo'], $alias,
                                             join(',', $mails), $x['nb_mails'],