More global cleanup. Now all SESSION and COOKIE use sqgetglobalvar, what's
[squirrelmail.git] / src / right_main.php
CommitLineData
59177427 1<?php
895905c0 2
c57b0888 3/**
4 * right_main.php
5 *
76911253 6 * Copyright (c) 1999-2003 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
86725763 15/* Path for SquirrelMail required files. */
16define('SM_PATH','../');
17
18/* SquirrelMail required files. */
08185f2a 19require_once(SM_PATH . 'include/validate.php');
8650e9e1 20require_once(SM_PATH . 'functions/global.php');
86725763 21require_once(SM_PATH . 'functions/imap.php');
22require_once(SM_PATH . 'functions/date.php');
86725763 23require_once(SM_PATH . 'functions/mime.php');
24require_once(SM_PATH . 'functions/mailbox_display.php');
25require_once(SM_PATH . 'functions/display_messages.php');
26require_once(SM_PATH . 'functions/html.php');
c57b0888 27
28/***********************************************************
29 * incoming variables from URL: *
30 * $sort Direction to sort by date *
31 * values: 0 - descending order *
32 * values: 1 - ascending order *
33 * $startMessage Message to start at *
34 * $mailbox Full Mailbox name *
35 * *
36 * incoming from cookie: *
c57b0888 37 * $key pass *
a32985a5 38 * incoming from session: *
39 * $username duh *
40 * *
c57b0888 41 ***********************************************************/
42
a32985a5 43
44/* lets get the global vars we may need */
1e12d1ff 45sqgetGlobalVar('key', $key, SQ_COOKIE);
46sqgetGlobalVar('username', $username, SQ_SESSION);
47sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
48sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
49sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
50
51sqgetGlobalVar('mailbox', $mailbox);
52sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
53sqgetGlobalVar('session', $session, SQ_GET);
54sqgetGlobalVar('note', $note, SQ_GET);
55
56if ( sqgetGlobalVar('startMessage', $temp) ) {
57 $startMessage = (int) $temp;
a32985a5 58}
1e12d1ff 59if ( sqgetGlobalVar('PG_SHOWNUM', $temp) ) {
60 $PG_SHOWNUM = (int) $temp;
a32985a5 61}
1e12d1ff 62if ( sqgetGlobalVar('PG_SHOWALL', $temp, SQ_GET) ) {
63 $PG_SHOWALL = (int) $temp;
a32985a5 64}
1e12d1ff 65if ( sqgetGlobalVar('newsort', $temp, SQ_GET) ) {
66 $newsort = (int) $temp;
a32985a5 67}
1e12d1ff 68if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
69 $checkall = (int) $temp;
a32985a5 70}
1e12d1ff 71if ( sqgetGlobalVar('set_thread', $temp, SQ_GET) ) {
72 $set_thread = (int) $temp;
a32985a5 73}
1e12d1ff 74if ( !sqgetGlobalVar('composenew', $composenew, SQ_GET) ) {
8cc72ada 75 $composenew = false;
76}
a32985a5 77/* end of get globals */
78
79
c57b0888 80/* Open a connection on the imap port (143) */
6f223ace 81
c57b0888 82$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
83
cf710efe 84if (isset($PG_SHOWALL)) {
85 if ($PG_SHOWALL) {
86 $PG_SHOWNUM=999999;
87 $show_num=$PG_SHOWNUM;
a32985a5 88 sqsession_register($PG_SHOWNUM, 'PG_SHOWNUM');
cf710efe 89 }
90 else {
a32985a5 91 sqsession_unregister('PG_SHOWNUM');
cf710efe 92 unset($PG_SHOWNUM);
93 }
94}
95else if( isset( $PG_SHOWNUM ) ) {
bdfb67f8 96 $show_num = $PG_SHOWNUM;
97}
98
c57b0888 99if (isset($newsort) && $newsort != $sort) {
100 setPref($data_dir, $username, 'sort', $newsort);
101}
102
e372ee8c 103
104
105/* If the page has been loaded without a specific mailbox, */
106/* send them to the inbox */
107if (!isset($mailbox)) {
108 $mailbox = 'INBOX';
109 $startMessage = 1;
110}
111
112
113if (!isset($startMessage) || ($startMessage == '')) {
114 $startMessage = 1;
115}
116
117/* compensate for the UW vulnerability. */
118if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
119 substr($mailbox, 0, 1) == '/')) {
120 $mailbox = 'INBOX';
121}
122
7c612fdd 123/* decide if we are thread sorting or not */
794d59c0 124if ($allow_thread_sort == TRUE) {
7c612fdd 125 if (isset($set_thread)) {
126 if ($set_thread == 1) {
78cc4b12 127 setPref($data_dir, $username, "thread_$mailbox", 1);
7c612fdd 128 $thread_sort_messages = '1';
129 }
130 elseif ($set_thread == 2) {
78cc4b12 131 setPref($data_dir, $username, "thread_$mailbox", 0);
7c612fdd 132 $thread_sort_messages = '0';
133 }
134 }
135 else {
78cc4b12 136 $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox");
7c612fdd 137 }
138}
139else {
140 $thread_sort_messages = 0;
141}
142
a32985a5 143do_hook ('generic_header');
7c612fdd 144
c57b0888 145sqimap_mailbox_select($imapConnection, $mailbox);
6f223ace 146
8cc72ada 147if ($composenew) {
148 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
0cb19b37 149 "&session=$session";
11af81b9 150 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
6f223ace 151} else {
152 displayPageHeader($color, $mailbox);
153}
c57b0888 154do_hook('right_main_after_header');
c57b0888 155if (isset($note)) {
fab3baa6 156 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n";
c57b0888 157}
158
a32985a5 159if (isset($_SESSION['just_logged_in'])) {
160 $just_logged_in = $_SESSION['just_logged_in'];
161 if ($just_logged_in == true) {
162 $just_logged_in = false;
163
164 if (strlen(trim($motd)) > 0) {
165 echo html_tag( 'table',
166 html_tag( 'tr',
167 html_tag( 'td',
168 html_tag( 'table',
169 html_tag( 'tr',
170 html_tag( 'td', $motd, 'center' )
171 ) ,
172 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
173 )
174 ) ,
175 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
176 }
23d6bd09 177 }
c57b0888 178}
179
7c612fdd 180if (isset($newsort)) {
181 $sort = $newsort;
a32985a5 182 sqsession_register($sort, 'sort');
7c612fdd 183}
184
c57b0888 185/*********************************************************************
186 * Check to see if we can use cache or not. Currently the only time *
187 * when you will not use it is when a link on the left hand frame is *
188 * used. Also check to make sure we actually have the array in the *
189 * registered session data. :) *
190 *********************************************************************/
191if (! isset($use_mailbox_cache)) {
192 $use_mailbox_cache = 0;
193}
194
d7c82551 195if ($use_mailbox_cache && sqsession_is_registered('msgs')) {
c57b0888 196 showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $use_mailbox_cache);
197} else {
d7c82551 198 if (sqsession_is_registered('msgs')) {
c57b0888 199 unset($msgs);
23d6bd09 200 }
201
d7c82551 202 if (sqsession_is_registered('msort')) {
c57b0888 203 unset($msort);
23d6bd09 204 }
a37f3771 205
d7c82551 206 if (sqsession_is_registered('numMessages')) {
c57b0888 207 unset($numMessages);
2016e645 208 }
e452ce9b 209
c57b0888 210 $numMessages = sqimap_get_num_messages ($imapConnection, $mailbox);
23d6bd09 211
c57b0888 212 showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
213 $startMessage, $sort, $color, $show_num,
214 $use_mailbox_cache);
23d6bd09 215
d7c82551 216 if (sqsession_is_registered('msgs') && isset($msgs)) {
a32985a5 217 sqsession_register($msgs, 'msgs');
b831fe0b 218 $_SESSION['msgs'] = $msgs;
c57b0888 219 }
1108e8bb 220
d7c82551 221 if (sqsession_is_registered('msort') && isset($msort)) {
a32985a5 222 sqsession_register($msort, 'msort');
b831fe0b 223 $_SESSION['msort'] = $msort;
c57b0888 224 }
9f2215a1 225
a32985a5 226 sqsession_register($numMessages, 'numMessages');
b831fe0b 227 $_SESSION['numMessages'] = $numMessages;
c57b0888 228}
c57b0888 229do_hook('right_main_bottom');
230sqimap_logout ($imapConnection);
23d6bd09 231
fab3baa6 232echo '</body></html>';
21c3249f 233
978d53dc 234?>