phase 1 of interface improvements -- alternating row colors (needs some work)
[squirrelmail.git] / functions / mailbox_display.php
index 988f708fc9bfe8cb14d46bb516f0b2bfaad85779..ed3bf981cea18c8d67dc06888251f373d531cdf2 100644 (file)
       global $message_highlight_list;
       global $index_order;
 
+      if (!isset($GLOBALS["row_count"])) {
+        $GLOBALS["row_count"] = 0;
+      }
+      $GLOBALS["row_count"]++;
+      if ($GLOBALS["row_count"] % 2) {
+        if (!isset($color[12])) $color[12] = "#EAEAEA";
+        $color_string = $color[12];
+      } else {
+        $color_string = $color[4];
+      }
+
       $msg = $msgs[$key];
 
       $senderName = sqimap_find_displayable_name($msg['FROM']);
       $urlMailbox = urlencode($mailbox);
-      $subject = trim($msg['SUBJECT']);
-      if ($subject == '')
-         $subject = _("(no subject)");
+      $subject = processSubject($msg['SUBJECT']);
 
       echo "<TR>\n";
 
       if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true) 
       { 
          $flag = "<font color=$color[2]>"; 
-        $flag_end = '</font>'; 
+         $flag_end = '</font>'; 
       }
       else
       {
          $flag = '';
-        $flag_end = '';
+         $flag_end = '';
       }
-      if (!isset($msg['FLAG_SEEN']) && $msg['FLAG_SEEN'] == false) 
+      if (!isset($msg['FLAG_SEEN']) || $msg['FLAG_SEEN'] == false) 
       { 
          $bold = '<b>'; 
-        $bold_end = '</b>'; 
+         $bold_end = '</b>'; 
       }
       else
       {
          $bold = '';
-        $bold_end = '';
+         $bold_end = '';
       }
       if ($mailbox == $sent_folder) 
       { 
          $italic = '<i>'; 
-        $italic_end = '</i>'; 
+         $italic_end = '</i>'; 
       }
       else
       {
          $italic = '';
-        $italic_end = '';
+         $italic_end = '';
       }
       if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'])
       { 
          $fontstr = "<font color=\"$color[9]\">"; 
-        $fontstr_end = '</font>'; 
+         $fontstr_end = '</font>'; 
       }
       else
       {
          $fontstr = '';
-        $fontstr_end = '';
+         $fontstr_end = '';
       }
 
       for ($i=0; $i < count($message_highlight_list); $i++) {
@@ -84,7 +93,7 @@
       }
 
       if (!isset($hlt_color))
-         $hlt_color = $color[4];
+         $hlt_color = $color_string;
 
       if ($where && $what) {
          $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
                break;
             case 4: # subject
                echo "   <td bgcolor=$hlt_color>$bold";
-                  if (! isset($search_stuff)) { $search_stuff = ''; }
+                   if (! isset($search_stuff)) { $search_stuff = ''; }
                echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0$search_stuff\"";
                do_hook("subject_link");
-               echo ">$flag";
-               if (strlen($subject) > 55)
-                   echo substr($subject, 0, 50) . '...';
-               else
-                      echo $subject;
-               echo "$flag_end</a>$bold_end</td>\n";
+               echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
                break;
             case 5: # flags
                $stuff = false;
                echo "   <td bgcolor=$hlt_color align=center width=1% nowrap><b><small>\n";
                if (isset($msg['FLAG_ANSWERED']) && 
-                  $msg['FLAG_ANSWERED'] == true) {
+                   $msg['FLAG_ANSWERED'] == true) {
                   echo "A\n";
                   $stuff = true;
                }
          $j = 0;
          if ($sort == 6) {
             $end = $startMessage + $show_num - 1;
+            if ($numMessages < $show_num)
+                $end_loop = $numMessages;
+            else
+                $end_loop = $show_num;
          } else {
             $end = $numMessages;
+            $end_loop = $end;
          }
-        if ($end > $numMessages) $end = $numMessages;
-         while ($j < $end) {
-            $date[$j] = ereg_replace('  ', ' ', $date[$j]);
-            $tmpdate = explode(' ', trim($date[$j]));
+         if ($end > $numMessages) $end = $numMessages;
+         while ($j < $end_loop) {
+            if (isset($date[$j])) {
+                $date[$j] = ereg_replace('  ', ' ', $date[$j]);
+                $tmpdate = explode(' ', trim($date[$j]));
+            } else {
+                $tmpdate = $date = array("","","","","","");
+            }
 
             $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
             $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
          /* Only ignore messages flagged as deleted if we are using a
           * trash folder or auto_expunge */
          if (((isset($move_to_trash) && $move_to_trash) 
-             || (isset($auto_expunge) && $auto_expunge)) && $sort != 6)
+              || (isset($auto_expunge) && $auto_expunge)) && $sort != 6)
          {
             /** Find and remove the ones that are deleted */
             $i = 0;
             $j = 0;
             while ($j < $numMessages) {
-               if ($messages[$j]['FLAG_DELETED'] == true) {
+               if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
                   $j++;
                   continue;
                }
             }
             $numMessages = $i;
          } else {
-           if (! isset($messages))
-               $messages = array();
+            if (! isset($messages))
+                $messages = array();
             $msgs = $messages;
          }
       }         
          else
             $i = 1;
          reset($msort);
-        $k = 0;
+         $k = 0;
          do {
             $key = key($msort);
             next($msort);
          $i = $startMessage;
 
          reset($msort);
-        $k = 0;
+         $k = 0;
          do {
             $key = key($msort);
             next($msort);
       echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
       echo "$More</td><td align=right>\n";
       if (!$startMessage) $startMessage=1;
-      if ( $checkall == '1')
-         echo "\n<A HREF=\"right_main.php?mailbox=$urlMailbox&startMessage=$real_startMessage&sort=$sort\">" . _("Unselect All") . "</A>\n";
-      else
-         echo "\n<A HREF=\"right_main.php?mailbox=$urlMailbox&startMessage=$real_startMessage&sort=$sort&checkall=1\">" . _("Select All") . "</A>\n";
+      ShowSelectAllLink($startMessage, $sort);
 
       echo '</td></tr></table>';
       echo '</td></tr>';
       global $color, $index_order, $auto_expunge, $move_to_trash;
       global $checkall, $sent_folder;
       $urlMailbox = urlencode($mailbox);
-
          /** This is the beginning of the message list table.  It wraps around all messages */
       echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
 
       echo "<TR BGCOLOR=\"$color[4]\"><TD>";
       echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
       echo "$More</td><td align=right>\n";
-      if ( $checkall == '1')
-         echo "\n<A HREF=\"right_main.php?mailbox=$urlMailbox&startMessage=$startMessage&sort=$sort\">" . _("Unselect All") . "</A>\n";
-      else
-         echo "\n<A HREF=\"right_main.php?mailbox=$urlMailbox&startMessage=$startMessage&sort=$sort&checkall=1\">" . _("Select All") . "</A>\n";
+      ShowSelectAllLink($startMessage, $sort);
 
       echo '</td></tr></table>';
       echo '</td></tr>';
 
       $boxes = sqimap_mailbox_list($imapConnection);
       for ($i = 0; $i < count($boxes); $i++) {
-         if ($boxes[$i]['flags'][0] != 'noselect' &&
-            $boxes[$i]['flags'][1] != 'noselect' &&
-            $boxes[$i]['flags'][2] != 'noselect') {
+         if (!in_array("noselect", $boxes[$i]['flags'])) {
             $box = $boxes[$i]['unformatted'];
-            $box2 = replace_spaces($boxes[$i]['unformatted-disp']);
+            $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
             echo "         <OPTION VALUE=\"$box\">$box2</option>\n";
-    }
+         }
       }
       echo '         </SELECT></SMALL></TT>';
       echo '         <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
       echo '</TD></TR>';
 
       echo "<TR><TD BGCOLOR=\"$color[0]\">";
-      echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">";
+      echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=1 CELLSPACING=0 BGCOLOR=\"$color[0]\">";
       echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
 
       $urlMailbox=urlencode($mailbox);
       }
       echo "</TR>\n";
    }
+   
+   function ShowSelectAllLink($startMessage, $sort)
+   {
+       global $checkall, $PHP_SELF, $what, $where, $mailbox;
+       
+       echo "\n<A HREF=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
+           "&startMessage=$startMessage&sort=$sort&";
+       if ( isset($checkall) && $checkall == '1')
+           echo "checkall=0";
+       else
+           echo "checkall=1";
+       if (isset($where) && isset($what))
+           echo "&where=" . urlencode($where) . "&what=" . urlencode($what);
+       echo "\">";
+       if (isset($checkall) && $checkall == '1')
+           echo _("Unselect All");
+       else
+           echo _("Select All");
+       echo "</A>\n";
+   }
+
+   function processSubject($subject)
+   {
+      // Shouldn't ever happen -- caught too many times in the IMAP functions
+      if ($subject == '')
+          return _("(no subject)");
+         
+      if (strlen($subject) <= 55)
+          return $subject;
+         
+      $ent_strlen=strlen($subject);
+      $trim_val=50;
+      $ent_offset=0;
+      // see if this is entities-encoded string
+      // If so, Iterate through the whole string, find out
+      // the real number of characters, and if more
+      // than 55, substr with an updated trim value.
+      while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
+             ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
+      {
+        $trim_val += ($ent_loc_end-$ent_loc)+1;
+        $ent_strlen -= $ent_loc_end-$ent_loc;
+        $ent_offset = $ent_loc_end+1;
+      }
+      
+      if ($ent_strlen <= 55)
+          return $subject;
+
+      return substr($subject, 0, $trim_val) . '...';
+   }
+
 ?>