fallback to client side sorting if server side sorting is selected but not supported...
[squirrelmail.git] / src / right_main.php
CommitLineData
59177427 1<?php
895905c0 2
c57b0888 3/**
4 * right_main.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
c57b0888 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This is where the mailboxes are listed. This controls most of what
10 * goes on in SquirrelMail.
11 *
12 * $Id$
13 */
14
15require_once('../src/validate.php');
16require_once('../functions/imap.php');
17require_once('../functions/date.php');
18require_once('../functions/array.php');
19require_once('../functions/mime.php');
20require_once('../functions/mailbox_display.php');
21require_once('../functions/display_messages.php');
22
23/***********************************************************
24 * incoming variables from URL: *
25 * $sort Direction to sort by date *
26 * values: 0 - descending order *
27 * values: 1 - ascending order *
28 * $startMessage Message to start at *
29 * $mailbox Full Mailbox name *
30 * *
31 * incoming from cookie: *
32 * $username duh *
33 * $key pass *
34 ***********************************************************/
35
3392dc86 36$bob = getHashedFile($username, $data_dir, "username.pref");
37
c57b0888 38/* Open a connection on the imap port (143) */
6f223ace 39
c57b0888 40$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
41
bdfb67f8 42if( isset( $PG_SHOWNUM ) ) {
43 $show_num = $PG_SHOWNUM;
44}
45
c57b0888 46if (isset($newsort) && $newsort != $sort) {
47 setPref($data_dir, $username, 'sort', $newsort);
48}
49
7c612fdd 50/* decide if we are thread sorting or not */
51global $allow_thread_sort;
52if ($allow_thread_sort == TRUE) {
53 if (isset($set_thread)) {
54 if ($set_thread == 1) {
78cc4b12 55 setPref($data_dir, $username, "thread_$mailbox", 1);
7c612fdd 56 $thread_sort_messages = '1';
57 }
58 elseif ($set_thread == 2) {
78cc4b12 59 setPref($data_dir, $username, "thread_$mailbox", 0);
7c612fdd 60 $thread_sort_messages = '0';
61 }
62 }
63 else {
78cc4b12 64 $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox");
7c612fdd 65 }
66}
67else {
68 $thread_sort_messages = 0;
69}
70
71
c57b0888 72/* If the page has been loaded without a specific mailbox, */
73/* send them to the inbox */
74if (!isset($mailbox)) {
75 $mailbox = 'INBOX';
76 $startMessage = 1;
77}
7c612fdd 78
79
c57b0888 80if (!isset($startMessage) || ($startMessage == '')) {
81 $startMessage = 1;
82}
83
84/* compensate for the UW vulnerability. */
85if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
86 substr($mailbox, 0, 1) == '/')) {
87 $mailbox = 'INBOX';
88}
7c612fdd 89 global $color;
6f223ace 90
7c612fdd 91 if( isset($do_hook) && $do_hook ) {
92 do_hook ("generic_header");
93 }
c57b0888 94
95sqimap_mailbox_select($imapConnection, $mailbox);
6f223ace 96
97if (isset($composenew)) {
98 $width= getPref($username, $data_dir, 'editor_size', 76);
99 if ($width < 65) {
100 $pix_width = 560;
101 } else {
102 $width = (.9*$width);
103 $pix_width = intval($width).'0';
104 }
105 $features = "toolbar=no, width=$pix_width, height=650, scrollbars=yes, resizable=yes target=_blank";
106 $location = 'compose.php?mailbox='. urlencode($mailbox).'&attachedmessages=true&session='."$session";
107 $onload= "window.open(\"$location\",\"compose_window_$session\", \"$features\");";
108 displayPageHeader($color, $mailbox, $onload);
109} else {
110 displayPageHeader($color, $mailbox);
111}
c57b0888 112echo "<br>\n";
113
114do_hook('right_main_after_header');
c57b0888 115if (isset($note)) {
116 echo "<CENTER><B>$note</B></CENTER><BR>\n";
117}
118
119if ($just_logged_in == true) {
120 $just_logged_in = false;
121
122 if (strlen(trim($motd)) > 0) {
bd9bbfef 123 echo "<br><table align=center width=\"70%\" cellpadding=0 cellspacing=3 border=0 bgcolor=\"$color[9]\">" .
c57b0888 124 '<tr><td>' .
bd9bbfef 125 "<table width=\"100%\" cellpadding=5 cellspacing=1 border=0 bgcolor=\"$color[4]\">" .
c57b0888 126 "<tr><td align=center>$motd";
127 do_hook('motd');
128 echo '</td></tr>' .
129 '</table>' .
130 '</td></tr></table>';
23d6bd09 131 }
c57b0888 132}
133
7c612fdd 134if (isset($newsort)) {
135 $sort = $newsort;
136 session_register('sort');
137}
138
c57b0888 139/*********************************************************************
140 * Check to see if we can use cache or not. Currently the only time *
141 * when you will not use it is when a link on the left hand frame is *
142 * used. Also check to make sure we actually have the array in the *
143 * registered session data. :) *
144 *********************************************************************/
145if (! isset($use_mailbox_cache)) {
146 $use_mailbox_cache = 0;
147}
148
d46fbcf8 149/* There is a problem with registered vars in 4.1 */
88cb1b4d 150/*
ae7c2608 151if( substr( phpversion(), 0, 3 ) == '4.1' ) {
d46fbcf8 152 $use_mailbox_cache = FALSE;
153}
88cb1b4d 154*/
d46fbcf8 155
c57b0888 156if ($use_mailbox_cache && session_is_registered('msgs')) {
157 showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $use_mailbox_cache);
158} else {
159 if (session_is_registered('msgs')) {
160 unset($msgs);
23d6bd09 161 }
162
c57b0888 163 if (session_is_registered('msort')) {
164 unset($msort);
23d6bd09 165 }
a37f3771 166
c57b0888 167 if (session_is_registered('numMessages')) {
168 unset($numMessages);
2016e645 169 }
e452ce9b 170
c57b0888 171 $numMessages = sqimap_get_num_messages ($imapConnection, $mailbox);
23d6bd09 172
c57b0888 173 showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
174 $startMessage, $sort, $color, $show_num,
175 $use_mailbox_cache);
23d6bd09 176
c57b0888 177 if (session_is_registered('msgs') && isset($msgs)) {
178 session_register('msgs');
b831fe0b 179 $_SESSION['msgs'] = $msgs;
c57b0888 180 }
1108e8bb 181
c57b0888 182 if (session_is_registered('msort') && isset($msort)) {
183 session_register('msort');
b831fe0b 184 $_SESSION['msort'] = $msort;
c57b0888 185 }
9f2215a1 186
c57b0888 187 session_register('numMessages');
b831fe0b 188 $_SESSION['numMessages'] = $numMessages;
c57b0888 189}
c57b0888 190do_hook('right_main_bottom');
191sqimap_logout ($imapConnection);
23d6bd09 192
bd9bbfef 193echo '</BODY></HTML>';
21c3249f 194
b831fe0b 195?>