added explicit include of global.php
[squirrelmail.git] / src / right_main.php
1 <?php
2
3 /**
4 * right_main.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
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
15 /* Path for SquirrelMail required files. */
16 define('SM_PATH','../');
17
18 /* SquirrelMail required files. */
19 require_once(SM_PATH . 'include/validate.php');
20 require_once(SM_PATH . 'functions/global.php');
21 require_once(SM_PATH . 'functions/imap.php');
22 require_once(SM_PATH . 'functions/date.php');
23 require_once(SM_PATH . 'functions/mime.php');
24 require_once(SM_PATH . 'functions/mailbox_display.php');
25 require_once(SM_PATH . 'functions/display_messages.php');
26 require_once(SM_PATH . 'functions/html.php');
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: *
37 * $key pass *
38 * incoming from session: *
39 * $username duh *
40 * *
41 ***********************************************************/
42
43
44 /* lets get the global vars we may need */
45 sqgetGlobalVar('key', $key, SQ_COOKIE);
46 sqgetGlobalVar('username', $username, SQ_SESSION);
47 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
48 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
49 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
50
51 sqgetGlobalVar('mailbox', $mailbox);
52 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
53 sqgetGlobalVar('session', $session, SQ_GET);
54 sqgetGlobalVar('note', $note, SQ_GET);
55
56 if ( sqgetGlobalVar('startMessage', $temp) ) {
57 $startMessage = (int) $temp;
58 }
59 if ( sqgetGlobalVar('PG_SHOWNUM', $temp) ) {
60 $PG_SHOWNUM = (int) $temp;
61 }
62 if ( sqgetGlobalVar('PG_SHOWALL', $temp, SQ_GET) ) {
63 $PG_SHOWALL = (int) $temp;
64 }
65 if ( sqgetGlobalVar('newsort', $temp, SQ_GET) ) {
66 $newsort = (int) $temp;
67 }
68 if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
69 $checkall = (int) $temp;
70 }
71 if ( sqgetGlobalVar('set_thread', $temp, SQ_GET) ) {
72 $set_thread = (int) $temp;
73 }
74 if ( !sqgetGlobalVar('composenew', $composenew, SQ_GET) ) {
75 $composenew = false;
76 }
77 /* end of get globals */
78
79
80 /* Open a connection on the imap port (143) */
81
82 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
83
84 if (isset($PG_SHOWALL)) {
85 if ($PG_SHOWALL) {
86 $PG_SHOWNUM=999999;
87 $show_num=$PG_SHOWNUM;
88 sqsession_register($PG_SHOWNUM, 'PG_SHOWNUM');
89 }
90 else {
91 sqsession_unregister('PG_SHOWNUM');
92 unset($PG_SHOWNUM);
93 }
94 }
95 else if( isset( $PG_SHOWNUM ) ) {
96 $show_num = $PG_SHOWNUM;
97 }
98
99 if (isset($newsort) && $newsort != $sort) {
100 setPref($data_dir, $username, 'sort', $newsort);
101 }
102
103
104
105 /* If the page has been loaded without a specific mailbox, */
106 /* send them to the inbox */
107 if (!isset($mailbox)) {
108 $mailbox = 'INBOX';
109 $startMessage = 1;
110 }
111
112
113 if (!isset($startMessage) || ($startMessage == '')) {
114 $startMessage = 1;
115 }
116
117 /* compensate for the UW vulnerability. */
118 if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
119 substr($mailbox, 0, 1) == '/')) {
120 $mailbox = 'INBOX';
121 }
122
123 /* decide if we are thread sorting or not */
124 if ($allow_thread_sort == TRUE) {
125 if (isset($set_thread)) {
126 if ($set_thread == 1) {
127 setPref($data_dir, $username, "thread_$mailbox", 1);
128 $thread_sort_messages = '1';
129 }
130 elseif ($set_thread == 2) {
131 setPref($data_dir, $username, "thread_$mailbox", 0);
132 $thread_sort_messages = '0';
133 }
134 }
135 else {
136 $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox");
137 }
138 }
139 else {
140 $thread_sort_messages = 0;
141 }
142
143 do_hook ('generic_header');
144
145 sqimap_mailbox_select($imapConnection, $mailbox);
146
147 if ($composenew) {
148 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
149 "&session=$session";
150 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
151 } else {
152 displayPageHeader($color, $mailbox);
153 }
154 do_hook('right_main_after_header');
155 if (isset($note)) {
156 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n";
157 }
158
159 if (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 }
177 }
178 }
179
180 if (isset($newsort)) {
181 $sort = $newsort;
182 sqsession_register($sort, 'sort');
183 }
184
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 *********************************************************************/
191 if (! isset($use_mailbox_cache)) {
192 $use_mailbox_cache = 0;
193 }
194
195 if ($use_mailbox_cache && sqsession_is_registered('msgs')) {
196 showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $use_mailbox_cache);
197 } else {
198 if (sqsession_is_registered('msgs')) {
199 unset($msgs);
200 }
201
202 if (sqsession_is_registered('msort')) {
203 unset($msort);
204 }
205
206 if (sqsession_is_registered('numMessages')) {
207 unset($numMessages);
208 }
209
210 $numMessages = sqimap_get_num_messages ($imapConnection, $mailbox);
211
212 showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
213 $startMessage, $sort, $color, $show_num,
214 $use_mailbox_cache);
215
216 if (sqsession_is_registered('msgs') && isset($msgs)) {
217 sqsession_register($msgs, 'msgs');
218 $_SESSION['msgs'] = $msgs;
219 }
220
221 if (sqsession_is_registered('msort') && isset($msort)) {
222 sqsession_register($msort, 'msort');
223 $_SESSION['msort'] = $msort;
224 }
225
226 sqsession_register($numMessages, 'numMessages');
227 $_SESSION['numMessages'] = $numMessages;
228 }
229 do_hook('right_main_bottom');
230 sqimap_logout ($imapConnection);
231
232 echo '</body></html>';
233
234 ?>