Area around checkboxes is now also responsive to the fancy row highlighting and auto...
[squirrelmail.git] / functions / mailbox_display.php
index b2d1ce21834f2020ab00091d98b4209cdf241314..ad3355a2d1456d045f13ede080bc93c9f087e61f 100644 (file)
@@ -98,7 +98,9 @@ function printMessageInfo($aMsg) {
         $email_address,
         $show_recipient_instead,    /* show recipient name instead of default identity */
         $use_icons,                 /* indicates to use icons or text markers */
-        $icon_theme;                /* icons theming */
+        $icon_theme,                /* icons theming */
+        $javascript_on,
+        $fancy_index_highlite;
 
     $color_string = $color[4];
 
@@ -298,20 +300,102 @@ function printMessageInfo($aMsg) {
     if (!isset($hlt_color)) {
         $hlt_color = $color_string;
     }
+
     $col = 0;
     $sSubject = str_replace(' ', ' ', decodeHeader($sSubject));
     $subject = processSubject($sSubject, $iIndent);
 
-    echo html_tag( 'tr','','','','valign="top"') . "\n";
+
+    $row_extra = 'valign="top"';
+
+
+    // this stuff does the auto row highlighting on mouseover
+    //
+    if ($javascript_on && $fancy_index_highlite) {
+
+        $mouseoverColor = $color[5];
+
+        // set this to an empty string to turn off extra 
+        // highlighting of checked rows
+        //
+        //$clickedColor = '';
+        if (!empty($color[16]))
+           $clickedColor = $color[16];
+        else
+           $clickedColor = $color[2];
+
+        $row_extra .= ' onmouseover="setPointer(this, ' . $t . ', \'over\', \'' . $hlt_color . '\', \'' . $mouseoverColor . '\', \'' . $clickedColor . '\');" onmouseout="setPointer(this, ' . $t . ', \'out\', \'' . $hlt_color . '\', \'' . $mouseoverColor . '\', \'' . $clickedColor . '\');" onmousedown="setPointer(this, ' . $t . ', \'click\', \'' . $hlt_color . '\', \'' . $mouseoverColor . '\', \'' . $clickedColor . '\');"';
+
+    }
+
+
+    if ($javascript_on && $fancy_index_highlite)
+        echo "<script language='javascript' type='text/javascript'>\n<!--\n"
+           . "orig_row_colors[" . $t . "] = '" . $hlt_color . "';\n//-->\n</script>";
+    echo html_tag( 'tr', '', '', '', $row_extra) . "\n";
+
+
+    // this does the auto-checking of the checkbox no matter 
+    // where on the row you click
+    //
+    $javascript_auto_click = '';
+    $checkbox_javascript = '';
+    if ($javascript_on && $fancy_index_highlite) {
+        $javascript_auto_click = ' onMouseDown="row_click(\'msg[' . $t . ']\')"';
+        $checkbox_javascript = ' onClick="this.checked = !this.checked;"';
+    }
+
 
     if (sizeof($index_order)) {
+
+        // figure out which columns should serve as labels for checkbox:
+        // we try to grab the two columns before and after the checkbox,
+        // except the subject column, since it is the link that opens
+        // the message view
+        //
+        // if $javascript_on is set, then the highlighting code takes 
+        // care of this; just skip it
+        //
+        $show_label_columns = array();
+        if (!($javascript_on && $fancy_index_highlite)) {
+            $get_next_two = 0;
+            $last_order_part = 0;
+            $last_last_order_part = 0;
+            foreach ($index_order as $index_order_part) {
+    
+                if ($index_order_part == 1) {
+                    $get_next_two = 1;
+                    if ($last_last_order_part != 4)
+                       $show_label_columns[] = $last_last_order_part;
+                    if ($last_order_part != 4)
+                       $show_label_columns[] = $last_order_part;
+    
+                } else if ($get_next_two > 0 && $get_next_two < 3 && $index_order_part != 4) {
+                    $show_label_columns[] = $index_order_part;
+                    $get_next_two++;
+                }
+                $last_last_order_part = $last_order_part;
+                $last_order_part = $index_order_part;
+            }
+        }
+
+
+        // build the actual columns for display
+        //
         foreach ($index_order as $index_order_part) {
+            if (in_array($index_order_part, $show_label_columns)) {
+                $label_start = '<label for="msg[' . $t . ']">';
+                $label_end = '</label>';
+            } else {
+                $label_start = '';
+                $label_end = '';
+            }
             switch ($index_order_part) {
             case 1: /* checkbox */
                 echo html_tag( 'td',
-                    addCheckBox("msg[$t]", $checkall, $iId),
+                    addCheckBox("msg[$t]", $checkall, $iId, $checkbox_javascript),
                             'center',
-                            $hlt_color );
+                            $hlt_color, $javascript_auto_click);
                 break;
             case 2: /* from */
                 if ($senderAddress != $senderName) {
@@ -321,21 +405,21 @@ function printMessageInfo($aMsg) {
                     $title = '';
                 }
                 echo html_tag( 'td',
-                            $italic . $bold . $flag . $fontstr . $senderName .
-                            $fontstr_end . $flag_end . $bold_end . $italic_end,
+                            $label_start . $italic . $bold . $flag . $fontstr . $senderName .
+                            $fontstr_end . $flag_end . $bold_end . $italic_end . $label_end,
                             'left',
-                            $hlt_color, $title );
+                            $hlt_color, $title . $javascript_auto_click);
                 break;
             case 3: /* date */
                 if ($sDate == '') {
                     $sDate = _("Unknown date");
                 }
                 echo html_tag( 'td',
-                            $bold . $flag . $fontstr . $sDate .
-                            $fontstr_end . $flag_end . $bold_end,
+                            $label_start . $bold . $flag . $fontstr . $sDate .
+                            $fontstr_end . $flag_end . $bold_end . $label_end,
                             'center',
                             $hlt_color,
-                            'style="white-space: nowrap;"' );
+                            'style="white-space: nowrap;"' . $javascript_auto_click );
                 break;
             case 4: /* subject */
                 $td_str = $bold;
@@ -345,6 +429,15 @@ function printMessageInfo($aMsg) {
                 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
                         .  '&amp;passed_id='. $iId
                         .  '&amp;startMessage='.$start_msg.$searchstr.'"';
+
+                // don't highlight the row or check the checkbox 
+                // when clicking subject link (when fancy highlighting is on)
+                //
+                // parentNode property is DOM Level 1
+                //
+                if ($javascript_on && $fancy_index_highlite)
+                    $td_str .= ' onmousedown="row_click(\'msg[' . $t . ']\'); setPointer(this.parentNode.parentNode, ' . $t . ', \'click\', \'' . $hlt_color . '\', \'' . $mouseoverColor . '\', \'' . $clickedColor . '\');"';
+
                 $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
                 if ($subject != $sSubject) {
                     $title = get_html_translation_table(HTML_SPECIALCHARS);
@@ -354,7 +447,7 @@ function printMessageInfo($aMsg) {
                     $td_str .= " title=\"$title\"";
                 }
                 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
-                echo html_tag( 'td', $td_str, 'left', $hlt_color );
+                echo html_tag( 'td', $td_str, 'left', $hlt_color, $javascript_auto_click );
                 break;
             case 5: /* flags */
 
@@ -403,10 +496,10 @@ function printMessageInfo($aMsg) {
                     $td_str .= '<img src="' . $msg_icon . '.png" border="0" alt="'. $msg_alt . '" title="' . $msg_title . '" height="12" width="18" />';
                     $td_str .= '</small></b>';
                     echo html_tag( 'td',
-                                $td_str,
+                                $label_start . $td_str . $label_end,
                                 'right',
                                 $hlt_color,
-                                'style="white-space: nowrap;"' );
+                                'style="white-space: nowrap;"' . $javascript_auto_click );
                 }
 
                 // plain text message markers
@@ -441,18 +534,18 @@ function printMessageInfo($aMsg) {
                     }
                     $td_str .= '</small></b>';
                     echo html_tag( 'td',
-                                $td_str,
+                                $label_start . $td_str . $label_end,
                                 'center',
                                 $hlt_color,
-                                'style="white-space: nowrap;"' );
+                                'style="white-space: nowrap;"' . $javascript_auto_click );
                 }
                 break;
             case 6: /* size */
                 echo html_tag( 'td',
-                            $bold . $fontstr . show_readable_size($iSize) .
-                            $fontstr_end . $bold_end,
+                            $label_start . $bold . $fontstr . show_readable_size($iSize) .
+                            $fontstr_end . $bold_end . $label_end,
                             'right',
-                            $hlt_color );
+                            $hlt_color, $javascript_auto_click );
                 break;
             }
             ++$col;
@@ -1425,9 +1518,18 @@ function ShowSortButton($aMailbox, $Down, $Up ) {
  * @param array $aMailbox
  */
 function get_selectall_link($aMailbox) {
-    global $checkall, $javascript_on;
+    global $checkall, $javascript_on, $fancy_index_highlite, $color;
     global $PHP_SELF;
 
+    // set this to an empty string to turn off extra 
+    // highlighting of checked rows
+    //
+    //$clickedColor = '';
+    if (!empty($color[16]))
+       $clickedColor = $color[16];
+    else
+       $clickedColor = $color[2];
+
     $result = '';
     if ($javascript_on) {
         $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']);
@@ -1435,12 +1537,14 @@ function get_selectall_link($aMailbox) {
         $form_name = "FormMsgs" . $safe_name;
         $result = '<script language="JavaScript" type="text/javascript">'
                 . "\n<!-- \n"
+                . "var orig_row_colors = new Array();\n"
                 . "function " . $func_name . "() {\n"
                 . "  for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
                 . "    if(document." . $form_name . ".elements[i].type == 'checkbox' && "
                 . "       document." . $form_name . ".elements[i].name.substring(0,3) == 'msg'){\n"
                 . "      document." . $form_name . ".elements[i].checked = "
                 . "        !(document." . $form_name . ".elements[i].checked);\n"
+                . ($fancy_index_highlite ? "      setPointer(document." . $form_name . ".elements[i].parentNode.parentNode, document." . $form_name . ".elements[i].name.substring(4, document." . $form_name . ".elements[i].name.length - 1), 'click', orig_row_colors[document." . $form_name . ".elements[i].name.substring(4, document." . $form_name . ".elements[i].name.length - 1)], orig_row_colors[document." . $form_name . ".elements[i].name.substring(4, document." . $form_name . ".elements[i].name.length - 1)], '" . $clickedColor . "');\n" : '')
                 . "    }\n"
                 . "  }\n"
                 . "}\n"