Example #1
0
function get_paginator_str($box, $start_msg, $end_msg, $num_msgs, $show_num, $sort)
{
    global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
    /* Initialize paginator string chunks. */
    $prv_str = '';
    $nxt_str = '';
    $pg_str = '';
    $all_str = '';
    $tgl_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. */
    /* 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. */
    $start_msg = min($start_msg, $num_msgs);
    /* Decide whether or not we will use the mailbox cache. */
    /* Not sure why $use_mailbox_cache is even passed in.   */
    if ($sort == 6) {
        $use = 0;
    } else {
        $use = 1;
    }
    /* Compute the starting message of the previous and next page group. */
    $next_grp = $start_msg + $show_num;
    $prev_grp = $start_msg - $show_num;
    /* Compute the basic previous and next strings. */
    if ($next_grp <= $num_msgs && $prev_grp >= 0) {
        $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
        $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
    } else {
        if ($next_grp > $num_msgs && $prev_grp >= 0) {
            $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
            $nxt_str = "<font color=\"{$color['9']}\">" . _("Next") . "</font>\n";
        } else {
            if ($next_grp <= $num_msgs && $prev_grp < 0) {
                $prv_str = "<font color=\"{$color['9']}\">" . _("Previous") . '</font>';
                $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
            }
        }
    }
    /* Page selector block. Following code computes page links. */
    if ($pg_sel && $num_msgs > $show_num) {
        /* Most importantly, what is the current page!!! */
        $cur_pg = intval($start_msg / $show_num) + 1;
        /* Compute total # of pages and # of paginator page links. */
        $tot_pgs = ceil($num_msgs / $show_num);
        /* 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 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;
            /* 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 >= $tot_pgs - $q4_pgs) {
                            $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) . '<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" . "&amp;use_mailbox_cache={$use}&amp;startMessage=1&amp;mailbox={$box}\" " . ">" . _("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" . "&amp;use_mailbox_cache={$use}&amp;startMessage=1&amp;mailbox={$box}\" " . ">" . _("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 = '&nbsp;';
    }
    /* Return our final magical paginator string. */
    return $result;
}
/**
 * Prints the table header for the messages list view
 *
 * @param array $aMailbox
 */
function printHeader($aMailbox)
{
    global $index_order, $internal_date_sort, $color;
    if ($aMailbox['SORT_METHOD'] != 'THREAD') {
        $showsort = true;
    } else {
        $showsort = false;
    }
    echo html_tag('tr', '', 'center', $color[5]);
    /* calculate the width of the subject column based on the
     * widths of the other columns */
    $widths = array(1 => 1, 2 => 25, 3 => 5, 4 => 0, 5 => 1, 6 => 5);
    $subjectwidth = 100;
    foreach ($index_order as $item) {
        $subjectwidth -= $widths[$item];
    }
    foreach ($index_order as $item) {
        switch ($item) {
            case 1:
                /* checkbox */
                echo html_tag('td', get_selectall_link($aMailbox), '', '', 'width="1%"');
                break;
            case 5:
                /* flags */
                echo html_tag('td', '', '', '', 'width="1%"');
                break;
            case 2:
                /* from */
                if (handleAsSent($aMailbox['NAME'])) {
                    echo html_tag('td', '', 'left', '', 'width="25%"') . '<b>' . _("To") . '</b>';
                    if ($showsort) {
                        ShowSortButton($aMailbox, SQSORT_TO_ASC, SQSORT_TO_DEC);
                    }
                } else {
                    echo html_tag('td', '', 'left', '', 'width="25%"') . '<b>' . _("From") . '</b>';
                    if ($showsort) {
                        ShowSortButton($aMailbox, SQSORT_FROM_ASC, SQSORT_FROM_DEC);
                    }
                }
                echo "</td>\n";
                break;
            case 3:
                /* date */
                echo html_tag('td', '', 'left', '', 'width="5%" nowrap') . '<b>' . _("Date") . '</b>';
                if ($showsort) {
                    if ($internal_date_sort) {
                        ShowSortButton($aMailbox, SQSORT_INT_DATE_ASC, SQSORT_INT_DATE_DEC);
                    } else {
                        ShowSortButton($aMailbox, SQSORT_DATE_ASC, SQSORT_DATE_DEC);
                    }
                }
                echo "</td>\n";
                break;
            case 4:
                /* subject */
                echo html_tag('td', '', 'left', '', 'width="' . $subjectwidth . '%"') . '<b>' . _("Subject") . '</b>';
                if ($showsort) {
                    ShowSortButton($aMailbox, SQSORT_SUBJ_ASC, SQSORT_SUBJ_DEC);
                }
                echo "</td>\n";
                break;
            case 6:
                /* size */
                echo html_tag('td', '', 'center', '', 'width="5%" nowrap') . '<b>' . _("Size") . '</b>';
                if ($showsort) {
                    ShowSortButton($aMailbox, SQSORT_SIZE_ASC, SQSORT_SIZE_DEC);
                }
                echo "</td>\n";
                break;
        }
    }
    echo "</tr>\n";
}
Example #3
0
function printSearchMessages($msgs, $mailbox, $cnt, $imapConnection, $where, $what, $usecache = false, $newsort = false)
{
    global $sort, $color, $allow_server_sort, $allow_server_thread;
    if ($cnt > 0) {
        if (!empty($allow_server_sort) && $allow_server_sort || !empty($allow_server_thread) && $allow_server_thread) {
            $msort = $msgs;
        } else {
            $msort = calc_msort($msgs, $sort);
        }
        if ($mailbox == 'INBOX') {
            $showbox = _("INBOX");
        } else {
            $showbox = imap_utf7_decode_local($mailbox);
        }
        echo html_tag('div', '<b><big>' . _("Folder:") . ' ' . htmlspecialchars($showbox) . '</big></b>', 'center') . "\n";
        $msg_cnt_str = get_msgcnt_str(1, $cnt, $cnt);
        $toggle_all = get_selectall_link(1, $sort);
        $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
        $form_name = "FormMsgs" . $safe_name;
        echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' . "\n" . '<input type="hidden" name="mailbox" value="' . htmlspecialchars($mailbox) . '">' . "\n" . '<input type="hidden" name="startMessage" value="1">' . "\n";
        echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
        echo '<tr><td>';
        mail_message_listing_beginning($imapConnection, $mailbox, $sort, $msg_cnt_str, $toggle_all, 1);
        echo '</td></tr>';
        echo '<tr><td height="5" bgcolor="' . $color[4] . '"></td></tr>';
        echo '<tr><td>';
        echo '    <table width="100%" cellpadding="1" cellspacing="0" align="center"' . ' border="0" bgcolor="' . $color[9] . '">';
        echo '     <tr><td>';
        echo '       <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="' . $color[5] . '">';
        echo '<tr><td>';
        printHeader($mailbox, 6, $color, false);
        displayMessageArray($imapConnection, $cnt, 1, $msort, $mailbox, $sort, $color, $cnt, $where, $what);
        echo '</td></tr></table></td></tr></table>';
        mail_message_listing_end($cnt, '', $msg_cnt_str, $color);
        echo "\n</table></form>\n\n";
    }
}