From: stekkel Date: Thu, 14 Apr 2005 21:34:30 +0000 (+0000) Subject: Templates X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=49db257d60e10c98388c55e33a4d29f9848070e9;p=squirrelmail.git Templates git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@9275 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/templates/default/js/default.js b/templates/default/js/default.js new file mode 100644 index 00000000..b9850507 --- /dev/null +++ b/templates/default/js/default.js @@ -0,0 +1,261 @@ +/** + * This array is used to remember mark status of rows in browse mode + */ +var marked_row = new Array; +var orig_row_colors = new Array(); + + +/* + * (un)Checks checkbox for the row that the current table cell is in + * when it gets clicked. + * + * @param string the name of the checkbox that should be (un)checked + */ +function row_click(chkboxName) { + chkbox = document.getElementById(chkboxName); + if (chkbox) { + // initialize orig_row_color if not defined already + if (!orig_row_colors[chkboxName]) { + orig_row_colors[chkboxName] = chkbox.parentNode.getAttribute('bgcolor'); + } + chkbox.checked = (chkbox.checked ? false : true); + } +} +/* + * This function is used to initialize the orig_row_color array so we do not + * need to predefine the entire array + */ +function rowOver(chkboxName, overColor, clickedColor) { + chkbox = document.getElementById(chkboxName); + if (chkbox) { + if (!orig_row_colors[chkboxName]) { + bgColor = chkbox.parentNode.getAttribute('bgcolor'); + orig_row_colors[chkboxName] = bgColor; + } else { + bgColor = orig_row_colors[chkboxName]; + } + j = chkbox.name.length - 1 + setPointer(chkbox.parentNode.parentNode, j,'over' , bgColor, overColor, clickedColor); + } +} + +/* + * (un)Checks all checkboxes for the message list from a specific form + * when it gets clicked. + * + * @param string the id of the form where all checkboxes should be (un)checked + * @param boolean use fancy row coloring when a checkbox is checked + * @param string new color of the checked rows + */ +function toggle_all(formname, fancy, clickedColor) { + TargetForm = document.getElementById(formname); + j = 0; + for (var i = 0; i < TargetForm.elements.length; i++) { + if (TargetForm.elements[i].type == 'checkbox' && TargetForm.elements[i].name.substring(0,3) == 'msg') { + if (fancy) { + array_key = TargetForm.elements[i].getAttribute('id'); + if (TargetForm.elements[i].checked == false) { + // initialize orig_row_color if not defined already + if (!orig_row_colors[array_key]) { + orig_row_colors[array_key] = TargetForm.elements[i].parentNode.getAttribute('bgcolor'); + } + } + origColor = orig_row_colors[array_key]; + setPointer(TargetForm.elements[i].parentNode.parentNode, j,'click' , origColor, origColor, clickedColor); + j++ + } + TargetForm.elements[i].checked = !(TargetForm.elements[i].checked); + } + } +} + +/* + * Sets/unsets the pointer and marker in browse mode + * + * @param object the table row + * @param integer the row number + * @param string the action calling this script (over, out or click) + * @param string the default background color + * @param string the color to use for mouseover + * @param string the color to use for marking a row + * + * @return boolean whether pointer is set or not + */ +function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor) +{ + var theCells = null; + + // 1. Pointer and mark feature are disabled or the browser can't get the + // row -> exits + if ((thePointerColor == '' && theMarkColor == '') + || typeof(theRow.style) == 'undefined') { + return false; + } + + // 2. Gets the current row and exits if the browser can't get it + if (typeof(document.getElementsByTagName) != 'undefined') { + theCells = theRow.getElementsByTagName('td'); + } + else if (typeof(theRow.cells) != 'undefined') { + theCells = theRow.cells; + } + else { + return false; + } + + // 3. Gets the current color... + var rowCellsCnt = theCells.length; + var domDetect = null; + var currentColor = null; + var newColor = null; + // 3.1 ... with DOM compatible browsers except Opera that does not return + // valid values with "getAttribute" + if (typeof(window.opera) == 'undefined' + && typeof(theCells[0].getAttribute) != 'undefined') { + currentColor = theCells[0].getAttribute('bgcolor'); + domDetect = true; + } + // 3.2 ... with other browsers + else { + currentColor = theCells[0].style.backgroundColor; + domDetect = false; + } // end 3 + + // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it + if (currentColor.indexOf("rgb") >= 0) + { + var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1, + currentColor.indexOf(')')); + var rgbValues = rgbStr.split(","); + currentColor = "#"; + var hexChars = "0123456789ABCDEF"; + for (var i = 0; i < 3; i++) + { + var v = rgbValues[i].valueOf(); + currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16); + } + } + + // 4. Defines the new color + // 4.1 Current color is the default one + if (currentColor == '' + || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) { + if (theAction == 'over' && thePointerColor != '') { + newColor = thePointerColor; + } + else if (theAction == 'click' && theMarkColor != '') { + newColor = theMarkColor; + marked_row[theRowNum] = true; + // deactivated onclick marking of the checkbox because it's also executed + // when an action (clicking on the checkbox itself) on a single item is + // performed. Then the checkbox would get deactived, even though we need + // it activated. Maybe there is a way to detect if the row was clicked, + // and not an item therein... + //document.getElementById('msg[' + theRowNum + ']').checked = true; + } + } + // 4.1.2 Current color is the pointer one + else if (currentColor.toLowerCase() == thePointerColor.toLowerCase() + && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) { + if (theAction == 'out') { + newColor = theDefaultColor; + } + else if (theAction == 'click' && theMarkColor != '') { + newColor = theMarkColor; + marked_row[theRowNum] = true; + //document.getElementById('msg[' + theRowNum + ']').checked = true; + } + } + // 4.1.3 Current color is the marker one + else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) { + if (theAction == 'click') { + newColor = (thePointerColor != '') + ? thePointerColor + : theDefaultColor; + marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum]) + ? true + : null; + //document.getElementById('msg[' + theRowNum + ']').checked = false; + } + } // end 4 + + // 5. Sets the new color... + if (newColor) { + var c = null; + // 5.1 ... with DOM compatible browsers except Opera + if (domDetect) { + for (c = 0; c < rowCellsCnt; c++) { + theCells[c].setAttribute('bgcolor', newColor, 0); + } // end for + } + // 5.2 ... with other browsers + else { + for (c = 0; c < rowCellsCnt; c++) { + theCells[c].style.backgroundColor = newColor; + } + } + } // end 5 + + return true; +} // end of the 'setPointer()' function + +function comp_in_new_form(comp_uri, button, myform, iWidth, iHeight) { + comp_uri += "&" + button.name + "=1"; + for ( var i=0; i < myform.elements.length; i++ ) { + if ( myform.elements[i].type == "checkbox" && myform.elements[i].checked ) + comp_uri += "&" + myform.elements[i].name + "=1"; + } + if (!iWidth) iWidth = 640; + if (!iHeight) iHeight = 550; + sArg = "width=" + iWidth + ",height=" + iHeight + ",scrollbars=yes,resizable=yes,status=yes"; + var newwin = window.open(comp_uri, "_blank", sArg); +} + +function comp_in_new(comp_uri, iWidth, iHeight) { + if (!iWidth) iWidth = 640; + if (!iHeight) iHeight = 550; + sArg = "width=" + iWidth + ",height=" + iHeight + ",scrollbars=yes,resizable=yes,status=yes"; + var newwin = window.open(comp_uri , "_blank", sArg); +} + +/* + * Reload the read_body screen on sending an mdn receipt + */ +function sendMDN() { + mdnuri=window.location+'&sendreceipt=1'; + var newwin = window.open(mdnuri,'right'); +} + +function checkForm(smaction) { + /* + * this part is used for setting the focus in the compose screen + */ + if (smaction) { + if (smaction == "select") { + document.forms['compose'].body.select(); + } else if (smaction == "focus") { + document.forms['compose'].body.focus(); + } + } else { + /* + * All other forms that need to set the focus + */ + var f = document.forms.length; + var i = 0; + var pos = -1; + while( pos == -1 && i < f ) { + var e = document.forms[i].elements.length; + var j = 0; + while( pos == -1 && j < e ) { + if ( document.forms[i].elements[j].type == 'text' || document.forms[i].elements[j].type == 'password' ) { + pos = j; + } + j++; + } + i++; + } + if( pos >= 0 ) { + document.forms[i-1].elements[pos].focus(); + } + } +} diff --git a/templates/default/message_list.tpl b/templates/default/message_list.tpl new file mode 100644 index 00000000..659f8833 --- /dev/null +++ b/templates/default/message_list.tpl @@ -0,0 +1,525 @@ +'.$pageOffset.'', ''.$end_msg.'', $iNumberOfMessages); +} else if ($pageOffset == $end_msg) { + $msg_cnt_str = sprintf(_("Viewing Message: %s (%s total)"), ''.$pageOffset.'', $iNumberOfMessages); +} + + + +if (!($sort & SQSORT_THREAD) && $enablesort) { + $aSortSupported = array(SQM_COL_SUBJ => array(SQSORT_SUBJ_ASC , SQSORT_SUBJ_DESC), + SQM_COL_DATE => array(SQSORT_DATE_ASC , SQSORT_DATE_DESC), + SQM_COL_INT_DATE => array(SQSORT_INT_DATE_ASC, SQSORT_INT_DATE_DESC), + SQM_COL_FROM => array(SQSORT_FROM_ASC , SQSORT_FROM_DESC), + SQM_COL_TO => array(SQSORT_TO_ASC , SQSORT_TO_DESC), + SQM_COL_CC => array(SQSORT_CC_ASC , SQSORT_CC_DESC), + SQM_COL_SIZE => array(SQSORT_SIZE_ASC , SQSORT_SIZE_DESC)); +} else { + $aSortSupported = array(); +} + +// 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(); +$index_order_part = array(); +if (!($javascript_on && $fancy_index_highlite)) { + $get_next_two = 0; + $last_order_part = 0; + $last_last_order_part = 0; + foreach ($aOrder as $index_order_part) { + if ($index_order_part == SQM_COL_CHECK) { + $get_next_two = 1; + if ($last_last_order_part != SQM_COL_SUBJ) + $show_label_columns[] = $last_last_order_part; + if ($last_order_part != SQM_COL_SUBJ) + $show_label_columns[] = $last_order_part; + + } else if ($get_next_two > 0 && $get_next_two < 3 && $index_order_part != SQM_COL_SUBJ) { + $show_label_columns[] = $index_order_part; + $get_next_two++; + } + $last_last_order_part = $last_order_part; + $last_order_part = $index_order_part; + } +} + +// 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]; + + +?> +
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + +
+ + + fetch('paginator.tpl'); + echo $paginator_str . $thread_link_str ."\n"; ?> + + +
+
+ + + + + +
+ + + $value) { + switch ($value[1]) { + case 'submit': + if ($key != 'moveButton') { // add move in a different table cell +?> +   + +   +\n"; + break; + default: break; + } + } +?> + + + + +   + + + + + + +
+
+ +
+ + + + +
+ + + + + + + + + + $aMsg) { + echo $sLine; + +/** +* Display message header row in messages list +* +*/ + + $aColumns = $aMsg['columns']; + + /** + * Check usage of images for attachments, flags and priority + * Aaaaaaaaaah fix me. DO NOT USE the string "None" if you mean FALSE, no icon theme + */ + $bIcons = ($use_icons && $icon_theme) ? true : false; + + /** + * Location of icon images + */ + if ($bIcons) { + $sImageLocation = SM_PATH . 'images/themes/' . $icon_theme . '/'; + } + + /** + * Check the flags and set a class var. + */ + if (isset($aColumns[SQM_COL_FLAGS])) { + $aFlags = $aColumns[SQM_COL_FLAGS]['value']; + if ($bIcons) { + + $sFlags = getFlagIcon($aFlags, $sImageLocation); + } else { + $sFlags = getFlagText($aFlags); + } + /* add the flag string to the value index */ + $aColumns[SQM_COL_FLAGS]['value'] = $sFlags; + } + /** + * Check the priority column + */ + if (isset($aColumns[SQM_COL_PRIO])) { + /* FIX ME, we should use separate templates for icons */ + if ($bIcons) { + $sValue = ' ' ; break; + case 5: $sValue .= 'prio_low.png" border="0" height="10" width="5" alt="" /> ' ; break; + default: $sValue .= 'transparent.png" border="0" width="5" alt="" /> ' ; break; + } + } else { + $sValue = ''; + switch ($aColumns[SQM_COL_PRIO]['value']) { + case 1: + case 2: $sValue .= "!"; break; + case 5: $sValue .= "?"; break; + default: break; + } + } + $aColumns[SQM_COL_PRIO]['value'] = $sValue; + } + + /** + * Check the attachment column + */ + if (isset($aColumns[SQM_COL_ATTACHMENT])) { + /* FIX ME, we should use separate templates for icons */ + if ($bIcons) { + $sValue = '' + : 'transparent.png" border="0" width="6" alt="" />'; + } else { + $sValue = ($aColumns[SQM_COL_ATTACHMENT]['value']) ? '+' : ''; + } + $aColumns[SQM_COL_ATTACHMENT]['value'] = $sValue; + } + + + $bgcolor = $color[4]; + + /** + * If alternating row colors is set, adapt the bgcolor + */ + if (isset($alt_index_colors) && $alt_index_colors) { + if (!($i % 2)) { + if (!isset($color[12])) { + $color[12] = '#EAEAEA'; + } + $bgcolor = $color[12]; + } + + } + $bgcolor = (isset($aMsg['row']['color'])) ? $aMsg['row']['color']: $bgcolor; + $class = 'msg_row'; + + $row_extra = ''; + + // this stuff does the auto row highlighting on mouseover + // + if ($javascript_on && $fancy_index_highlite) { + $row_extra .= ' onmouseover="rowOver(\''.$form_id . "_msg$i','". $mouseoverColor . '\', \'' . $clickedColor . '\');" onmouseout="setPointer(this, ' . $i . ', \'out\', \'' . $bgcolor . '\', \'' . $mouseoverColor . '\', \'' . $clickedColor . '\');" onmousedown="setPointer(this, ' . $i . ', \'click\', \'' . $bgcolor . '\', \'' . $mouseoverColor . '\', \'' . $clickedColor . '\');"'; + } + // this does the auto-checking of the checkbox no matter + // where on the row you click + // + $javascript_auto_click = ''; + if ($javascript_on && $fancy_index_highlite) { + // include the form_id in order to show multiple messages lists. Otherwise id isn't unique + $javascript_auto_click = " onMouseDown=\"row_click('$form_id"."_msg$i')\""; + } + +?> +> +'; $sEnd = ''; + } + if (in_array('deleted',$aFlags) && $aFlags['deleted']) { + $sPre = "" . $sPre; + $sEnd .= ''; + } else { + if (in_array('flagged',$aFlags) && $aFlags['flagged']) { + $sPre = "" . $sPre; + $sEnd .= ''; + } + } + /** + * Because the order of the columns and which columns to show is a user preference + * we have to do some php coding to display the columns in the right order + */ + foreach ($aOrder as $iCol) { + if (in_array($index_order_part, $show_label_columns)) { + $sLabelStart = ''; + } else { + $sLabelStart = ''; + $sLabelEnd = ''; + } + $aCol = (isset($aColumns[$iCol])) ? $aColumns[$iCol] : ''; + $title = (isset($aCol['title'])) ? $aCol['title'] : ''; + $link = (isset($aCol['link'])) ? $aCol['link'] : ''; + $value = (isset($aCol['value'])) ? $aCol['value'] : ''; + $target = (isset($aCol['target'])) ? $aCol['target'] : ''; + if ($iCol !== SQM_COL_CHECK) { + $value = $sLabelStart.$sPre.$value.$sEnd.$sLabelEnd; + } + + + switch ($iCol) { + case SQM_COL_CHECK: + echo ' + "; + if ($align['left'] == 'left') { + $sText .= str_repeat('  ',$indent); + } + $sText .= "'; + if ($align['left'] == 'right') { + $sText .= str_repeat('  ',$indent); + } + echo $sText."\n"; + break; + case SQM_COL_SIZE: + case SQM_COL_FLAGS: + $sText = " \n"; + echo $sText; + break; + case SQM_COL_INT_DATE: + case SQM_COL_DATE: + $sText = " \n"; + echo $sText; + break; + default: + $sText = " +"; + ++$i; + +/* + * End displaying row part + */ + } + +?> + +
+ +
+ +'; + } else { + $link = $baseurl . "&startMessage=$pageOffset&&checkall="; + if (sqgetGlobalVar('checkall',$checkall,SQ_GET)) { + $link .= ($checkall) ? '0' : '1'; + } else { + $link .= '1'; + } + echo ""._("All").''; + } + break; + case SQM_COL_FROM: echo _("From"); break; + case SQM_COL_DATE: echo _("Date"); break; + case SQM_COL_SUBJ: echo _("Subject"); break; + case SQM_COL_FLAGS: echo ' '; break; + case SQM_COL_SIZE: echo _("Size"); break; + case SQM_COL_PRIO: echo '!'; break; + case SQM_COL_ATTACHMENT: echo '+'; break; + case SQM_COL_INT_DATE: echo _("Received"); break; + case SQM_COL_TO: echo _("To"); break; + case SQM_COL_CC: echo _("Cc"); break; + case SQM_COL_BCC: echo _("Bcc"); break; + default: break; + } + // add the sort buttons + if (isset($aSortSupported[$iCol])) { + if ($sort == $aSortSupported[$iCol][0]) { + $newsort = $aSortSupported[$iCol][1]; + $img = 'up_pointer.png'; + } else if ($sort == $aSortSupported[$iCol][1]) { + $newsort = 0; + $img = 'down_pointer.png'; + } else { + $newsort = $aSortSupported[$iCol][0]; + $img = 'sort_none.png'; + } + /* Now that we have everything figured out, show the actual button. */ + echo " "; + echo 'sort'; + } +?> + +
' ?> + " id="" value="" />"; + $sText .= "$value"; + $sText .= $value. "\n"; + break; + } + } +?> +
+
+
+ + + + +
+ + + + + +
+
+
+ +
+
\ No newline at end of file diff --git a/templates/default/paginator.tpl b/templates/default/paginator.tpl new file mode 100644 index 00000000..c79e15bd --- /dev/null +++ b/templates/default/paginator.tpl @@ -0,0 +1,46 @@ + + + + + + + 1, + SQM_COL_FROM => 25, + SQM_COL_DATE => 10, + SQM_COL_SUBJ => 100, + SQM_COL_FLAGS => 2, + SQM_COL_SIZE => 5, + SQM_COL_PRIO => 1, + SQM_COL_ATTACHMENT => 1, + SQM_COL_INT_DATE => 10, + SQM_COL_TO => 25, + SQM_COL_CC => 25, + SQM_COL_BCC => 25 + ); + + /** + * Calculate the width of the subject column based on the + * widths of the other columns + */ + if (isset($aOrder[SQM_COL_SUBJ])) { + foreach($aOrder as $iCol) { + if ($iCol != SQM_COL_SUBJ) { + $aWidthTpl[SQM_COL_SUBJ] -= $aWidthTpl[$iCol]; + } + } + } + foreach($aOrder as $iCol) { + $aWidth[$iCol] = $aWidthTpl[$iCol]; + } + + $iCheckTotalWidth = $iTotalWidth = 0; + foreach($aOrder as $iCol) { $iTotalWidth += $aWidth[$iCol];} + + $iTotalWidth = ($iTotalWidth) ? $iTotalWidth : 100; // divide by zero check. shouldn't be needed + // correct the width to 100% + foreach($aOrder as $iCol) { + $aWidth[$iCol] = round( (100 / $iTotalWidth) * $aWidth[$iCol] , 0); + $iCheckTotalWidth += $aWidth[$iCol]; + } + if ($iCheckTotalWidth > 100) { // correction needed + $iCol = array_search(max($aWidth),$aWidth); + $aWidth[$iCol] -= $iCheckTotalWidth-100; + } + return $aWidth; +} + +/** + * Function to retrieve the correct flag icon belonging to the set of + * provided flags + * + * @param array $aFlags associative array with seen,deleted,anwered and flag keys. + * @param string $sImageLocation directory location of flagicons + * @return string $sFlags string with the correct img html tag + * @author Marc Groot Koerkamp + */ +function getFlagIcon($aFlags, $sImageLocation) { + $sFlags = ''; + + /** + * 0 = unseen + * 1 = seen + * 2 = deleted + * 3 = deleted seen + * 4 = answered + * 5 = answered seen + * 6 = answered deleted + * 7 = answered deleted seen + * 8 = flagged + * 9 = flagged seen + * 10 = flagged deleted + * 11 = flagged deleted seen + * 12 = flagged answered + * 13 = flagged aswered seen + * 14 = flagged answered deleted + * 15 = flagged anserwed deleted seen + */ + + /** + * Use static vars to avoid initialisation of the array on each displayed row + */ + static $aFlagImages, $aFlagValues; + if (!isset($aFlagImages)) { + $aFlagImages = array( + array('msg_new.png','('._("New").')'), + array('msg_read.png','('._("Read").')'), + array('msg_new_deleted.png','('._("Deleted").')'), + array('msg_read_deleted.png','('._("Deleted").')'), + array('msg_new_reply.png','('._("Answered").')'), + array('msg_read_reply.png','('._("Answered").')'), + array('msg_read_deleted_reply.png','('._("Answered").')'), + array('flagged.png', '('._("Flagged").')'), + array('flagged.png', '('._("Flagged").')'), + array('flagged.png', '('._("Flagged").')'), + array('flagged.png', '('._("Flagged").')'), + array('flagged.png', '('._("Flagged").')'), + array('flagged.png', '('._("Flagged").')'), + array('flagged.png', '('._("Flagged").')'), + array('flagged.png', '('._("Flagged").')'), + array('flagged.png', '('._("Flagged").')') + ); // as you see the list is not completed yet. + $aFlagValues = array('seen' => 1, + 'deleted' => 2, + 'answered' => 4, + 'flagged' => 8, + 'draft' => 16); + } + + /** + * The flags entry contain all items displayed in the flag column. + */ + $iFlagIndx = 0; + foreach ($aFlags as $flag => $flagvalue) { + /* FIX ME, we should use separate templates for icons */ + switch ($flag) { + case 'deleted': + case 'answered': + case 'seen': + case 'flagged': if ($flagvalue) $iFlagIndx+=$aFlagValues[$flag]; break; + default: break; + } + } + if (isset($aFlagImages[$iFlagIndx])) { + $aFlagEntry = $aFlagImages[$iFlagIndx]; + } else { + $aFlagEntry = end($aFlagImages); + } + + $sFlags = ''.$aFlagEntry[1].'' ; + if (!$sFlags) { $sFlags = ' '; } + return $sFlags; +} + +/** + * Function to retrieve the correct flag text belonging to the set of + * provided flags + * + * @param array $aFlags associative array with seen,deleted,anwered and flag keys. + * @return string $sFlags string with the correct flag text + * @author Marc Groot Koerkamp + */ +function getFlagText($aFlags) { + $sFlags = ''; + + /** + * 0 = unseen + * 1 = seen + * 2 = deleted + * 3 = deleted seen + * 4 = answered + * 5 = answered seen + * 6 = answered deleted + * 7 = answered deleted seen + * 8 = flagged + * 9 = flagged seen + * 10 = flagged deleted + * 11 = flagged deleted seen + * 12 = flagged answered + * 13 = flagged aswered seen + * 14 = flagged answered deleted + * 15 = flagged anserwed deleted seen + */ + /** + * Use static vars to avoid initialisation of the array on each displayed row + */ + static $aFlagText, $aFlagValues; + if (!isset($aFlagText)) { + $aFlagText = array( + array(' ', '('._("New").')'), + array(' ', '('._("Read").')'), + array(_("D") , '('._("Deleted").')'), + array(_("D") , '('._("Deleted").')'), + array(_("A") , '('._("Answered").')'), + array(_("A") , '('._("Answered").')'), + array(_("D") , '('._("Answered").')'), + array(_("F") , '('._("Flagged").')'), + array(_("F") , '('._("Flagged").')'), + array(_("F") , '('._("Flagged").')'), + array(_("F") , '('._("Flagged").')'), + array(_("F") , '('._("Flagged").')'), + array(_("F") , '('._("Flagged").')'), + array(_("F") , '('._("Flagged").')'), + array(_("F") , '('._("Flagged").')'), + array(_("F") , '('._("Flagged").')') + ); // as you see the list is not completed yet. + $aFlagValues = array('seen' => 1, + 'deleted' => 2, + 'answered' => 4, + 'flagged' => 8, + 'draft' => 16); + } + + /** + * The flags entry contain all items displayed in the flag column. + */ + $iFlagIndx = 0; + foreach ($aFlags as $flag => $flagvalue) { + /* FIX ME, we should use separate templates for icons */ + switch ($flag) { + case 'deleted': + case 'answered': + case 'seen': + case 'flagged': if ($flagvalue) $iFlagIndx+=$aFlagValues[$flag]; break; + default: break; + } + } + if (isset($aFlagText[$iFlagIndx])) { + $sFlags = $aFlagText[$iFlagIndx][0]; + } else { + $aLast = end($aFlagText); + $sFlags = $aLast[0]; + } + if (!$sFlags) { $sFlags = ' '; } + return $sFlags; +} +?> diff --git a/templates/util_paginator.php b/templates/util_paginator.php new file mode 100644 index 00000000..dfebb9a5 --- /dev/null +++ b/templates/util_paginator.php @@ -0,0 +1,345 @@ +$text"; + + return ($result); +} + +/** + * This function computes the comapact paginator string. + * + * @param string $box mailbox name + * @param integer $iOffset offset in total number of messages + * @param integer $iTotal total number of messages + * @param integer $iLimit maximum number of messages to show on a page + * @param bool $bShowAll show all messages at once (non paginate mode) + * @return string $result paginate string with links to pages + */ +function get_compact_paginator_str($box, $iOffset, $iTotal, $iLimit, $bShowAll, $javascript_on, $page_selector) { + + sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER); + + /* Initialize paginator string chunks. */ + $prv_str = ''; + $nxt_str = ''; + $pg_str = ''; + $all_str = ''; + + $box = urlencode($box); + + /* Create simple strings that will be creating the paginator. */ + $spc = ' '; /* This will be used as a space. */ + $sep = '|'; /* This will be used as a seperator. */ + + /* Make sure that our start message number is not too big. */ + $iOffset = min($iOffset, $iTotal); + + /* Compute the starting message of the previous and next page group. */ + $next_grp = $iOffset + $iLimit; + $prev_grp = $iOffset - $iLimit; + + if (!$bShowAll) { + /* Compute the basic previous and next strings. */ + if (($next_grp <= $iTotal) && ($prev_grp >= 0)) { + $prv_str = get_paginator_link($box, $prev_grp, '<'); + $nxt_str = get_paginator_link($box, $next_grp, '>'); + } else if (($next_grp > $iTotal) && ($prev_grp >= 0)) { + $prv_str = get_paginator_link($box, $prev_grp, '<'); + $nxt_str = '>'; + } else if (($next_grp <= $iTotal) && ($prev_grp < 0)) { + $prv_str = '<'; + $nxt_str = get_paginator_link($box, $next_grp, '>'); + } + + /* Page selector block. Following code computes page links. */ + if ($iLimit != 0 && $page_selector && ($iTotal > $iLimit)) { + /* Most importantly, what is the current page!!! */ + $cur_pg = intval($iOffset / $iLimit) + 1; + + /* Compute total # of pages and # of paginator page links. */ + $tot_pgs = ceil($iTotal / $iLimit); /* Total number of Pages */ + + $last_grp = (($tot_pgs - 1) * $iLimit) + 1; + } + } else { + $pg_str = "" ._("Paginate") . ''; + } + + /* Put all the pieces of the paginator string together. */ + /** + * Hairy code... But let's leave it like it is since I am not certain + * a different approach would be any easier to read. ;) + */ + $result = ''; + if ( $prv_str || $nxt_str ) { + + /* Compute the 'show all' string. */ + $all_str = "" . _("Show All") . ''; + + $result .= '[' . get_paginator_link($box, 1, '<<') . ']'; + $result .= '[' . $prv_str . ']'; + + $pg_url = $php_self . '?mailbox=' . $box; + + $result .= '[' . $nxt_str . ']'; + $result .= '[' . get_paginator_link($box, $last_grp, '>>') . ']'; + + if ($page_selector) { + $result .= $spc . ''; + + if ($javascript_on) { + $result .= ''; + } else { + $result .= addSubmit(_("Go")); + } + } + } + + $result .= ($pg_str != '' ? '['.$pg_str.']' . $spc : ''); + $result .= ($all_str != '' ? $spc . '['.$all_str.']' . $spc . $spc : ''); + + /* If the resulting string is blank, return a non-breaking space. */ + if ($result == '') { + $result = ' '; + } + /* Return our final magical paginator string. */ + return ($result); +} + +/** + * This function computes the paginator string. + * + * @param string $box mailbox name + * @param integer $iOffset offset in total number of messages + * @param integer $iTotal total number of messages + * @param integer $iLimit maximum number of messages to show on a page + * @param bool $bShowAll show all messages at once (non paginate mode) + * @return string $result paginate string with links to pages + */ +function get_paginator_str($box, $iOffset, $iTotal, $iLimit, $bShowAll,$page_selector, $page_selector_max) { + + sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER); + + /* Initialize paginator string chunks. */ + $prv_str = ''; + $nxt_str = ''; + $pg_str = ''; + $all_str = ''; + + $box = urlencode($box); + + /* Create simple strings that will be creating the paginator. */ + $spc = ' '; /* This will be used as a space. */ + $sep = '|'; /* This will be used as a seperator. */ + + /* Make sure that our start message number is not too big. */ + $iOffset = min($iOffset, $iTotal); + + /* Compute the starting message of the previous and next page group. */ + $next_grp = $iOffset + $iLimit; + $prev_grp = $iOffset - $iLimit; + + if (!$bShowAll) { + /* Compute the basic previous and next strings. */ + + if (($next_grp <= $iTotal) && ($prev_grp >= 0)) { + $prv_str = get_paginator_link($box, $prev_grp, _("Previous")); + $nxt_str = get_paginator_link($box, $next_grp, _("Next")); + } else if (($next_grp > $iTotal) && ($prev_grp >= 0)) { + $prv_str = get_paginator_link($box, $prev_grp, _("Previous")); + $nxt_str = _("Next"); + } else if (($next_grp <= $iTotal) && ($prev_grp < 0)) { + $prv_str = _("Previous"); + $nxt_str = get_paginator_link($box, $next_grp, _("Next")); + } + + /* Page selector block. Following code computes page links. */ + if ($iLimit != 0 && $page_selector && ($iTotal > $iLimit)) { + /* Most importantly, what is the current page!!! */ + $cur_pg = intval($iOffset / $iLimit) + 1; + + /* Compute total # of pages and # of paginator page links. */ + $tot_pgs = ceil($iTotal / $iLimit); /* Total number of Pages */ + + $vis_pgs = min($page_selector_max, $tot_pgs - 1); /* Visible Pages */ + + /* Compute the size of the four quarters of the page links. */ + + /* If we can, just show all the pages. */ + if (($tot_pgs - 1) <= $page_selector_max) { + $q1_pgs = $cur_pg - 1; + $q2_pgs = $q3_pgs = 0; + $q4_pgs = $tot_pgs - $cur_pg; + + /* Otherwise, compute some magic to choose the four quarters. */ + } else { + /* + * Compute the magic base values. Added together, + * these values will always equal to the $pag_pgs. + * NOTE: These are DEFAULT values and do not take + * the current page into account. That is below. + */ + $q1_pgs = floor($vis_pgs/4); + $q2_pgs = round($vis_pgs/4, 0); + $q3_pgs = ceil($vis_pgs/4); + $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0); + + /* Adjust if the first quarter contains the current page. */ + if (($cur_pg - $q1_pgs) < 1) { + $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs; + $q1_pgs = $cur_pg - 1; + $q2_pgs = 0; + $q3_pgs += ceil($extra_pgs / 2); + $q4_pgs += floor($extra_pgs / 2); + + /* Adjust if the first and second quarters intersect. */ + } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) { + $extra_pgs = $q2_pgs; + $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4); + $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4); + $q3_pgs += ceil($extra_pgs / 2); + $q4_pgs += floor($extra_pgs / 2); + + /* Adjust if the fourth quarter contains the current page. */ + } else if (($cur_pg + $q4_pgs) >= $tot_pgs) { + $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs; + $q3_pgs = 0; + $q4_pgs = $tot_pgs - $cur_pg; + $q1_pgs += floor($extra_pgs / 2); + $q2_pgs += ceil($extra_pgs / 2); + + /* Adjust if the third and fourth quarter intersect. */ + } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) { + $extra_pgs = $q3_pgs; + $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4); + $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4); + $q1_pgs += floor($extra_pgs / 2); + $q2_pgs += ceil($extra_pgs / 2); + } + } + + /* + * I am leaving this debug code here, commented out, because + * it is a really nice way to see what the above code is doing. + * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " + * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '
'; + */ + + /* Print out the page links from the compute page quarters. */ + + /* Start with the first quarter. */ + if (($q1_pgs == 0) && ($cur_pg > 1)) { + $pg_str .= "...$spc"; + } else { + for ($pg = 1; $pg <= $q1_pgs; ++$pg) { + $start = (($pg-1) * $iLimit) + 1; + $pg_str .= get_paginator_link($box, $start, $pg) . $spc; + } + if ($cur_pg - $q2_pgs - $q1_pgs > 1) { + $pg_str .= "...$spc"; + } + } + + /* Continue with the second quarter. */ + for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) { + $start = (($pg-1) * $iLimit) + 1; + $pg_str .= get_paginator_link($box, $start, $pg) . $spc; + } + + /* Now print the current page. */ + $pg_str .= $cur_pg . $spc; + + /* Next comes the third quarter. */ + for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) { + $start = (($pg-1) * $iLimit) + 1; + $pg_str .= get_paginator_link($box, $start, $pg) . $spc; + } + + /* And last, print the forth quarter page links. */ + if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) { + $pg_str .= "...$spc"; + } else { + if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) { + $pg_str .= "...$spc"; + } + for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) { + $start = (($pg-1) * $iLimit) + 1; + $pg_str .= get_paginator_link($box, $start,$pg) . $spc; + } + } + + $last_grp = (($tot_pgs - 1) * $iLimit) + 1; + } + } else { + $pg_str = "" ._("Paginate") . ''; + } + + /* Put all the pieces of the paginator string together. */ + /** + * Hairy code... But let's leave it like it is since I am not certain + * a different approach would be any easier to read. ;) + */ + $result = ''; + if ( $prv_str || $nxt_str ) { + + /* Compute the 'show all' string. */ + $all_str = "" . _("Show All") . ''; + + $result .= '['; + $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : ''); + $result .= ($nxt_str != '' ? $nxt_str : ''); + $result .= ']' . $spc ; + } + + $result .= ($pg_str != '' ? $spc . '['.$spc.$pg_str.']' . $spc : ''); + $result .= ($all_str != '' ? $spc . '['.$all_str.']' . $spc . $spc : ''); + + /* If the resulting string is blank, return a non-breaking space. */ + if ($result == '') { + $result = ' '; + } + /* Return our final magical compact paginator string. */ + return ($result); +} +?> \ No newline at end of file