Don't show warning mx on the front page if the user has another valid
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 13 Oct 2007 10:15:58 +0000 (12:15 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 13 Oct 2007 10:15:58 +0000 (12:15 +0200)
redirection
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
include/emails.inc.php
include/xorg.misc.inc.php
templates/events/index.tpl

index 2597086..a8eef27 100644 (file)
@@ -372,7 +372,7 @@ class Redirect
 
     public function get_broken_mx()
     {
-        $res = XDB::query("SELECT  host, text
+        $res = XDB::query("SELECT  host, text, state
                              FROM  mx_watch
                             WHERE  state != 'ok'");
         if (!$res->numRows()) {
@@ -388,15 +388,17 @@ class Redirect
                     $lcl_mxs = array($domain);
                 }
                 $broken = false;
+                $state  = false;
                 foreach ($mxs as &$mx) {
                     foreach ($lcl_mxs as $lcl) {
                         if (fnmatch($mx['host'], $lcl)) {
                             $broken = $mx['text'];
+                            $state  = $mx['state'];
                             break;
                         }
                     }
                     if ($broken) {
-                        $mails[] = array('mail' => $mail->email, 'text' => $broken);
+                        $mails[] = array('mail' => $mail->email, 'text' => $broken, 'state' => $state);
                         break;
                     }
                 }
index 96db292..2ecaab8 100644 (file)
@@ -287,6 +287,20 @@ function check_redirect($red = null)
     }
     $_SESSION['no_redirect'] = !$red->other_active('');
     $_SESSION['mx_failures'] = $red->get_broken_mx();
+    $warning = 0;
+    foreach ($red->emails as &$mail) {
+        if ($mail->active) {
+            $warning++;
+        }
+    }
+    foreach ($_SESSION['mx_failures'] as &$fail) {
+        if ($fail['state'] == 'broken') {
+            $warning -= 99999;
+        } else if ($fail['state'] == 'warning') {
+            $warning--;
+        }
+    }
+    $_SESSION['email_is_warning'] = ($warning <= 0 ? true : false);
 }
 
 function send_warning_mail($title)
index 72424d3..37d844e 100644 (file)
@@ -49,7 +49,7 @@ Bienvenue {$smarty.session.prenom}{if $birthday}
 </p>
 {/if}
 
-{if $smarty.session.mx_failures|@count}
+{if $smarty.session.email_is_warning}
 <fieldset>
   <legend>{icon name=error} Des problèmes sont actuellement recontrĂ©s sur tes redirections suivantes</legend>
   {foreach from=$smarty.session.mx_failures item=mail}