]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/pagenav.inc
Imported Upstream version 0.6+dfsg
[roundcube.git] / program / steps / mail / pagenav.inc
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/mail/pagenav.inc                                        |
6  |                                                                       |
7  | This file is part of the Roundcube Webmail client                     |
8  | Copyright (C) 2005-2009, The Roundcube Dev Team                       |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Updates message page navigation controls                            |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Aleksander Machniak <alec@alec.pl>                            |
16  +-----------------------------------------------------------------------+
17
18  $Id: show.inc 4176 2010-11-04 09:59:55Z alec $
19
20 */
21
22 $uid = get_input_value('_uid', RCUBE_INPUT_GET);
23
24 // Select mailbox first, for better performance
25 $mbox_name = $IMAP->get_mailbox_name();
26 $IMAP->select_mailbox($mbox_name);
27
28 // Get messages count (only messages, no threads here)
29 $cnt  = $IMAP->messagecount(NULL, 'ALL');
30
31 if ($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] == 'DESC'
32     && empty($_REQUEST['_search']) && !$CONFIG['skip_deleted'] && !$IMAP->threading
33 ) {
34     // this assumes that we are sorted by date_DESC
35     $seq   = $IMAP->get_id($uid);
36     $index = $cnt - $seq;
37
38     $prev  = $IMAP->get_uid($seq + 1);
39     $first = $IMAP->get_uid($cnt);
40     $next  = $IMAP->get_uid($seq - 1);
41     $last  = $IMAP->get_uid(1);
42 }
43 else {
44     // Only if we use custom sorting
45     $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
46
47     $index = array_search($IMAP->get_id($uid), $a_msg_index);
48
49     $count = count($a_msg_index);
50     $prev  = isset($a_msg_index[$index-1]) ? $IMAP->get_uid($a_msg_index[$index-1]) : -1;
51     $first = $count > 1 ? $IMAP->get_uid($a_msg_index[0]) : -1;
52     $next  = isset($a_msg_index[$index+1]) ? $IMAP->get_uid($a_msg_index[$index+1]) : -1;
53     $last  = $count > 1 ? $IMAP->get_uid($a_msg_index[$count-1]) : -1;
54 }
55
56 // Set UIDs and activate navigation buttons
57 if ($prev > 0) {
58     $OUTPUT->set_env('prev_uid', $prev);
59     $OUTPUT->command('enable_command', 'previousmessage', 'firstmessage', true);
60 }
61 if ($next > 0) {
62     $OUTPUT->set_env('next_uid', $next);
63     $OUTPUT->command('enable_command', 'nextmessage', 'lastmessage', true);
64 }
65 if ($first > 0)
66     $OUTPUT->set_env('first_uid', $first);
67 if ($last > 0)
68     $OUTPUT->set_env('last_uid', $last);
69
70 // Don't need a real messages count value
71 $OUTPUT->set_env('messagecount', 1);
72
73 // Set rowcount text
74 $OUTPUT->command('set_rowcount', rcube_label(array(
75     'name' => 'messagenrof',
76     'vars' => array('nr'  => $index+1, 'count' => $cnt)
77 )));
78
79 $OUTPUT->send();
80