- /* 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) * 0.75);
- $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
- $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) * 0.75);
- $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
- $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) . '<br>'; */
-
- /************************************************************/
- /* 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) * $show_num) + 1;
- $pg_str .= get_paginator_link($box, $start, $use, $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) * $show_num) + 1;
- $pg_str .= get_paginator_link($box, $start, $use, $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) * $show_num) + 1;
- $pg_str .= get_paginator_link($box, $start, $use, $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) * $show_num) + 1;
- $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
- }
- }
- } else if ($PG_SHOWNUM == 999999) {
- $pg_str = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
- . "&startMessage=1&mailbox=$box\" TARGET=\"right\">"
- . _("Paginate") . '</A>' . $spc;
- }
-
- /* If necessary, compute the 'show all' string. */
- if (($prv_str != '') || ($nxt_str != '')) {
- $all_str = "<A HREF=\"right_main.php?PG_SHOWNUM=999999"
- . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
- . "TARGET=\"right\">" . _("Show All") . '</A>';
- }
-
- /* Last but not least, get the value for the toggle all link. */
- $tgl_str = get_selectall_link($start_msg, $sort);
-
- /* Put all the pieces of the paginator string together. */
- $result = '';
- $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
- $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
- $result .= ($pg_str != '' ? $pg_str : '');
- $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
- $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
-
- /* If the resulting string is blank, return a non-breaking space. */
- if ($result == '') {
- $result = ' ';
- }
-
- /* Return our final magical paginator string. */
- return ($result);
+ /* 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) * 0.75);
+ $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
+ $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) * 0.75);
+ $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
+ $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) . '<br>';
+ */
+
+ /* 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) * $show_num) + 1;
+ $pg_str .= get_paginator_link($box, $start, $use, $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) * $show_num) + 1;
+ $pg_str .= get_paginator_link($box, $start, $use, $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) * $show_num) + 1;
+ $pg_str .= get_paginator_link($box, $start, $use, $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) * $show_num) + 1;
+ $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
+ }
+ }
+ } else if ($PG_SHOWNUM == 999999) {
+ $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
+ . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
+ . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
+ }
+
+ /* If necessary, compute the 'show all' string. */
+ if (($prv_str != '') || ($nxt_str != '')) {
+ $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
+ . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
+ . "TARGET=\"right\">" . _("Show All") . '</A>';
+ }
+
+ /* Last but not least, get the value for the toggle all link. */
+ $tgl_str = get_selectall_link($start_msg, $sort);
+
+ /* 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 = '';
+ $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
+ $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
+ $result .= ($pg_str != '' ? $pg_str : '');
+ $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
+ $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
+
+ /* If the resulting string is blank, return a non-breaking space. */
+ if ($result == '') {
+ $result = ' ';
+ }
+
+ /* Return our final magical paginator string. */
+ return ($result);