From 0bb37159d61e6f963f22614a01cb480fa98ec8f1 Mon Sep 17 00:00:00 2001 From: tokul Date: Mon, 1 Nov 2004 11:31:05 +0000 Subject: [PATCH] Adding compact page selection options. Thanks to Felix Egli for idea, patch and other fixes. Fixed incorrect declaration of $data_dir variable Removed getPref calls for page selector, because they are already loaded in load_prefs git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@8312 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/mailbox_display.php | 325 +++++++++++++++++++++------------- include/load_prefs.php | 2 + include/options/display.php | 67 +++---- src/search.php | 16 +- 4 files changed, 253 insertions(+), 157 deletions(-) diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 32e5d40c..e9291462 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -159,8 +159,8 @@ function printMessageInfo($aMsg) { // If the From address is the same as $email_address, then handle as Sent $from_array = parseAddress($sFrom, 1); if (!isset($email_address)) { - global $datadir, $username; - $email_address = getPref($datadir, $username, 'email_address'); + global $data_dir, $username; + $email_address = getPref($data_dir, $username, 'email_address'); } $bHandleAsSent = ((isset($from_array[0][0])) && ($from_array[0][0] == $email_address)); } else { @@ -1008,7 +1008,7 @@ function fetchMessageHeaders($imapConnection, &$aMailbox) { * @param array $aMailbox associative array with mailbox related vars */ function showMessagesForMailbox($imapConnection, &$aMailbox) { - global $color; + global $color, $javascript_on, $compact_paginator; // to retrieve the internaldate pref: (I know this is not the right place to do that, move up in front // and use a properties array as function argument to provide user preferences @@ -1023,12 +1023,25 @@ function showMessagesForMailbox($imapConnection, &$aMailbox) { $aMailbox['PAGEOFFSET'] + $iLimit - 1 : $aMailbox['EXISTS']; $paginator_str = get_paginator_str($aMailbox['NAME'], $aMailbox['PAGEOFFSET'], - $aMailbox['EXISTS'], $aMailbox['LIMIT'], $aMailbox['SHOWALL'][$iSetIndx]); + $aMailbox['EXISTS'], $aMailbox['LIMIT'], $aMailbox['SHOWALL'][$iSetIndx]); $msg_cnt_str = get_msgcnt_str($aMailbox['PAGEOFFSET'], $iEnd,$aMailbox['EXISTS']); do_hook('mailbox_index_before'); -?> + + if ($javascript_on && $compact_paginator) { + // Insert compact paginator javascript + echo "\n\n" + . "\n" + . "\n"; + } ?> +
@@ -1054,9 +1067,13 @@ function showMessagesForMailbox($imapConnection, &$aMailbox) {
- + + + + + @@ -1259,14 +1276,16 @@ function mail_message_listing_beginning ($imapConnection, * Function to add the last row in a message list, it contains the paginator and info about * the number of messages. * - * @param integer $num_msgs number of messages in a mailbox + * @param array $aMailbox associative array with mailbox related information * @param string $paginator_str Paginator string [Prev | Next] [ 1 2 3 ... 91 92 94 ] [Show all] * @param string $msg_cnt_str Message count string Viewing Messages: 21 to 1861 (20 total) */ -function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str) { -global $color; -if ($num_msgs) { - /* space between list and footer */ +function mail_message_listing_end($aMailbox, $paginator_str, $msg_cnt_str) { + global $color; + + if ($aMailbox['EXISTS']) { + /* space between list and footer */ + ?> @@ -1485,7 +1504,7 @@ function get_selectall_link($aMailbox) { $result .= '&where=' . urlencode($aMailbox['SEARCH'][0]); if (isset($aMailbox['SEARCH'][1]) && ! sqgetGlobalVar('what',$tmp,SQ_GET)) { $result .= '&what=' . urlencode($aMailbox['SEARCH'][1]); - } + } } $result .= "\">"; $result .= _("All"); @@ -1547,7 +1566,9 @@ function get_paginator_link($box, $start_msg, $text) { * @return string $result paginate string with links to pages */ function get_paginator_str($box, $iOffset, $iTotal, $iLimit, $bShowAll) { - global $username, $data_dir; + global $username, $data_dir, $javascript_on; + // page selector globals + global $page_selector, $page_selector_max, $compact_paginator; sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER); /* Initialize paginator string chunks. */ @@ -1562,10 +1583,6 @@ function get_paginator_str($box, $iOffset, $iTotal, $iLimit, $bShowAll) { $spc = ' '; /* This will be used as a space. */ $sep = '|'; /* This will be used as a seperator. */ - /* Get some paginator preference values. */ - $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON); - $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX); - /* Make sure that our start message number is not too big. */ $iOffset = min($iOffset, $iTotal); @@ -1575,130 +1592,147 @@ function get_paginator_str($box, $iOffset, $iTotal, $iLimit, $bShowAll) { 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")); + if ($compact_paginator) { + 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, '>'); + } + } else { + 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 && $pg_sel && ($iTotal > $iLimit)) { + 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($pg_max, $tot_pgs - 1); /* Visible Pages */ - /* Compute the size of the four quarters of the page links. */ + if (!$compact_paginator) { + $vis_pgs = min($page_selector_max, $tot_pgs - 1); /* Visible Pages */ - /* If we can, just show all the pages. */ - if (($tot_pgs - 1) <= $pg_max) { - $q1_pgs = $cur_pg - 1; - $q2_pgs = $q3_pgs = 0; - $q4_pgs = $tot_pgs - $cur_pg; + /* Compute the size of the four quarters of the page links. */ - /* 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; + /* If we can, just show all the pages. */ + if (($tot_pgs - 1) <= $page_selector_max) { $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; + $q2_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); + + /* 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) . '
'; - */ + /* + * 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. */ + /* 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) { + /* 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; - } + /* 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; + /* 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; - } + /* 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)) { + /* And last, print the forth quarter page links. */ + if (($q4_pgs == 0) && ($cur_pg < $tot_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; + } 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 = "" . _("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 ($compact_paginator) { + if ( $prv_str || $nxt_str ) { + $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 : ''); + } else { + if ( $prv_str || $nxt_str ) { + $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 paginator string. */ return ($result); } diff --git a/include/load_prefs.php b/include/load_prefs.php index 869c5edf..7270b9fa 100644 --- a/include/load_prefs.php +++ b/include/load_prefs.php @@ -239,7 +239,9 @@ $mdn_user_support = getPref($data_dir, $username, 'mdn_user_support', SMPREF_ON) $include_self_reply_all = getPref($data_dir, $username, 'include_self_reply_all', SMPREF_ON); +/* Page selector options */ $page_selector = getPref($data_dir, $username, 'page_selector', SMPREF_ON); +$compact_paginator = getPref($data_dir, $username, 'compact_paginator', SMPREF_OFF); $page_selector_max = getPref($data_dir, $username, 'page_selector_max', 10); /* SqClock now in the core */ diff --git a/include/options/display.php b/include/options/display.php index cf00a711..44101a7e 100644 --- a/include/options/display.php +++ b/include/options/display.php @@ -109,44 +109,44 @@ function load_optpage_data_display() { $language_values = array(); if ( strtoupper($available_languages)=='ALL') { - foreach ($languages as $lang_key => $lang_attributes) { - if (isset($lang_attributes['NAME'])) { - $language_values[$lang_key] = $lang_attributes['NAME']; - if ( isset($show_alternative_names) && - $show_alternative_names && - isset($lang_attributes['ALTNAME']) ) { - $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME']; - } - } - } + foreach ($languages as $lang_key => $lang_attributes) { + if (isset($lang_attributes['NAME'])) { + $language_values[$lang_key] = $lang_attributes['NAME']; + if ( isset($show_alternative_names) && + $show_alternative_names && + isset($lang_attributes['ALTNAME']) ) { + $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME']; + } + } + } } else if (strtoupper($available_languages)!='NONE') { - // admin can set list of available languages in config - $available_languages_array=explode (" ",$available_languages); + // admin can set list of available languages in config + $available_languages_array=explode (" ",$available_languages); foreach ($available_languages_array as $lang_key ) { - if (isset($languages[$lang_key]['NAME'])) { - $language_values[$lang_key] = $languages[$lang_key]['NAME']; - if ( isset($show_alternative_names) && - $show_alternative_names && - isset($languages[$lang_key]['ALTNAME']) ) { - $language_values[$lang_key] .= " / " . $languages[$lang_key]['ALTNAME']; - } - } - } + if (isset($languages[$lang_key]['NAME'])) { + $language_values[$lang_key] = $languages[$lang_key]['NAME']; + if ( isset($show_alternative_names) && + $show_alternative_names && + isset($languages[$lang_key]['ALTNAME']) ) { + $language_values[$lang_key] .= " / " . $languages[$lang_key]['ALTNAME']; + } + } + } } asort($language_values); $language_values = array_merge(array('' => _("Default")), $language_values); $language = $squirrelmail_language; if (strtoupper($available_languages)!='NONE') { - // if set to 'none', interface will use only default language - $optvals[SMOPT_GRP_GENERAL][] = array( - 'name' => 'language', - 'caption' => _("Language"), - 'type' => SMOPT_TYPE_STRLIST, - 'refresh' => SMOPT_REFRESH_ALL, - 'posvals' => $language_values, - 'htmlencoded' => true - ); + // if set to 'none', interface will use only default language + $optvals[SMOPT_GRP_GENERAL][] = array( + 'name' => 'language', + 'caption' => _("Language"), + 'type' => SMOPT_TYPE_STRLIST, + 'refresh' => SMOPT_REFRESH_ALL, + 'posvals' => $language_values, + 'htmlencoded' => true + ); } /* Set values for the "use javascript" option. */ @@ -224,6 +224,13 @@ function load_optpage_data_display() { 'refresh' => SMOPT_REFRESH_NONE ); + $optvals[SMOPT_GRP_MAILBOX][] = array( + 'name' => 'compact_paginator', + 'caption' => _("Use Compact Page Selector"), + 'type' => SMOPT_TYPE_BOOLEAN, + 'refresh' => SMOPT_REFRESH_NONE + ); + $optvals[SMOPT_GRP_MAILBOX][] = array( 'name' => 'page_selector_max', 'caption' => _("Maximum Number of Pages to Show"), diff --git a/src/search.php b/src/search.php index e08aa062..e37c467b 100644 --- a/src/search.php +++ b/src/search.php @@ -860,8 +860,8 @@ function asearch_print_form_basic($imapConnection, &$boxes, $mailbox_array, $bio /** Print the $msgs messages from $mailbox mailbox */ -function asearch_print_mailbox_msgs($imapConnection, &$aMailbox, $color) -{ +function asearch_print_mailbox_msgs($imapConnection, &$aMailbox, $color) { + global $javascript_on, $compact_paginator; /** * A mailbox can contain different sets with uid's. Default, for normal * message list view we use '0' as setindex and for search a different @@ -884,6 +884,18 @@ function asearch_print_mailbox_msgs($imapConnection, &$aMailbox, $color) $paginator_str = get_paginator_str($aMailbox['NAME'], $aMailbox['PAGEOFFSET'], $cnt, $aMailbox['LIMIT'], $aMailbox['SHOWALL'][$iSetIndx]); + if ($javascript_on && $compact_paginator) { + echo "\n\n" + . "\n" + . "\n"; + } + $msg_cnt_str = get_msgcnt_str($aMailbox['PAGEOFFSET'], $iEnd,$cnt); echo ''; -- 2.25.1