missing '}' in session_expired_post, thanks Rusty Nejdl
[squirrelmail.git] / src / left_main.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * left_main.php
5 *
35586184 6 * This is the code for the left bar. The left bar shows the folders
7 * available, and has cookie information.
8 *
47ccfad4 9 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 11 * @version $Id$
8f6f9ba5 12 * @package squirrelmail
1c52ba77 13 */
35586184 14
30967a1e 15/**
202bcbcc 16 * Include the SquirrelMail initialization file.
30967a1e 17 */
202bcbcc 18require('../include/init.php');
86725763 19
20/* SquirrelMail required files. */
202bcbcc 21require_once(SM_PATH . 'functions/imap_general.php');
b6d26135 22require_once(SM_PATH . 'functions/date.php');
202bcbcc 23require_once(SM_PATH . 'templates/util_global.php');
24require_once(SM_PATH . 'templates/util_left_main.php');
29997535 25
95e93571 26/* These constants are used for folder stuff. */
27define('SM_BOX_UNCOLLAPSED', 0);
28define('SM_BOX_COLLAPSED', 1);
a6d2e0de 29
f38b7cf0 30/* get globals */
31sqgetGlobalVar('username', $username, SQ_SESSION);
32sqgetGlobalVar('key', $key, SQ_COOKIE);
33sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
34sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
a32985a5 35
f38b7cf0 36sqgetGlobalVar('fold', $fold, SQ_GET);
37sqgetGlobalVar('unfold', $unfold, SQ_GET);
f38b7cf0 38/* end globals */
95e93571 39
40// open a connection on the imap port (143)
3cbf882e 41// why hide the output?
42$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, true);
95e93571 43
f43c35f8 44/**
3cbf882e 45 * Using stristr since very old preferences may contain "None" and "none".
f43c35f8 46 */
3cbf882e 47if (!empty($left_refresh) &&
d68323ff 48 !stristr($left_refresh, 'none')){
49 $xtra = "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\" />\n" .
50 "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n".
dcc1cc82 51 "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
95e93571 52} else {
53 $xtra = '';
54}
55
f23f6a3a 56/**
6373ad12 57 * Include extra javascript files needed by template
58 */
59$js_includes = $oTemplate->getJavascriptIncludes();
60foreach ($js_includes as $js_file) {
61 $xtra .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
ccc4580f 62}
202bcbcc 63
a462b928 64// get mailbox list and cache it
65$mailboxes=sqimap_get_mailboxes($imapConnection,false,$show_only_subscribed_folders);
66
dcc1cc82 67displayHtmlHeader( 'SquirrelMail', $xtra );
a462b928 68
852abae7 69sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION);
95e93571 70/* If requested and not yet complete, attempt to autocreate folders. */
71if ($auto_create_special && !isset($auto_create_done)) {
a3439b27 72 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
3bf08e48 73 $folders_created = false;
95e93571 74 foreach( $autocreate as $folder ) {
a3439b27 75 if (($folder != '') && ($folder != 'none')) {
d388a958 76 /**
77 * If $show_only_subscribed_folders is true, don't use
78 * $mailboxes array for checking if mailbox exists.
79 * Mailbox list contains only subscribed folders.
80 * sqimap_mailbox_create() will fail, if folder exists.
81 */
82 if ($show_only_subscribed_folders) {
83 $mailbox_cache = false;
84 } else {
85 $mailbox_cache = $mailboxes;
86 }
87 if ( !sqimap_mailbox_exists($imapConnection, $folder, $mailbox_cache)) {
95e93571 88 sqimap_mailbox_create($imapConnection, $folder, '');
3bf08e48 89 $folders_created = true;
852abae7 90 } else {
7b1f03c9 91 // check for subscription is useless and expensive, just
92 // surpress the NO response. Unless we're on Mecury, which
93 // will just subscribe a folder again if it's already
94 // subscribed.
95 if ( strtolower($imap_server_type) != 'mercury32' ||
96 !sqimap_mailbox_is_subscribed($imapConnection, $folder) ) {
97 sqimap_subscribe($imapConnection, $folder, false);
3bf08e48 98 $folders_created = true;
7b1f03c9 99 }
2d367c68 100 }
ebf18afa 101 }
2d367c68 102 }
a6d2e0de 103
95e93571 104 /* Let the world know that autocreation is complete! Hurrah! */
90de1755 105 $auto_create_done = TRUE;
a32985a5 106 sqsession_register($auto_create_done, 'auto_create_done');
3bf08e48 107 // reload mailbox list
108 if ($folders_created)
109 $mailboxes=sqimap_get_mailboxes($imapConnection,true,$show_only_subscribed_folders);
95e93571 110}
dcc1cc82 111
29997535 112$clock = '';
95e93571 113if ($date_format != 6) {
114 /* First, display the clock. */
115 if ($hour_format == 1) {
3208c2a5 116 $hr = 'H:i';
95e93571 117 if ($date_format == 4) {
118 $hr .= ':s';
a6d2e0de 119 }
95e93571 120 } else {
121 if ($date_format == 4) {
122 $hr = 'g:i:s a';
123 } else {
124 $hr = 'g:i a';
2d367c68 125 }
126 }
127
95e93571 128 switch( $date_format ) {
e4f5158a 129 case 0:
134e4174 130 $clk = date('Y-m-d '.$hr. ' T', time());
131 break;
95e93571 132 case 1:
133 $clk = date('m/d/y '.$hr, time());
134 break;
135 case 2:
136 $clk = date('d/m/y '.$hr, time());
137 break;
138 case 4:
139 case 5:
140 $clk = date($hr, time());
141 break;
142 default:
67eb95d7 143 $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
2d367c68 144 }
95e93571 145 $clk = str_replace(' ','&nbsp;',$clk);
146
29997535 147 $clock = '<small><span style="white-space: nowrap;">'
f8a1ed5a 148 . str_replace(' ', '&nbsp;', _("Last Refresh"))
3cbf882e 149 . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />\n";
95e93571 150}
151
95e93571 152if ( $collapse_folders ) {
153 /* If directed, collapse or uncollapse a folder. */
154 if (isset($fold)) {
155 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
156 } else if (isset($unfold)) {
157 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
158 }
159}
160
c5a52f46 161/* Get unseen/total display prefs */
162$unseen_type = getPref( $data_dir , $username , 'unseen_type' );
163$unseen_notify = getPref( $data_dir , $username , 'unseen_notify' );
164
3cbf882e 165if (empty($unseen_type)) {
166 if (!empty($default_unseen_type)) {
c5a52f46 167 $unseen_type = $default_unseen_type;
168 } else {
169 $unseen_type = 1;
170 }
171}
172
3cbf882e 173if (empty($unseen_notify)) {
174 if (!empty($default_unseen_notify)) {
c5a52f46 175 $unseen_notify = $default_unseen_notify;
176 } else {
177 $unseen_notify = 0;
178 }
179}
29997535 180
a462b928 181/**
182 * pass $mailboxes now instead of $imapconnection - sqimap_get_mailboxes() has been separated from
183 * sqimap_mailbox_tree() so that the cached mailbox list can be used elsewhere in left_main and beyond
184 */
185$boxes = sqimap_mailbox_tree($imapConnection,$mailboxes,$show_only_subscribed_folders);
29997535 186$mailbox_structure = getBoxStructure($boxes);
187
188$oTemplate->assign('clock', $clock);
29997535 189$oTemplate->assign('mailboxes', $mailbox_structure);
29997535 190
6373ad12 191/*
192 * Build an array to pass user prefs to the template in order to avoid using
193 * globals, which are dirty, filthy things in templates. :)
194 */
195$settings = array();
196$settings['imapConnection'] = $imapConnection;
197$settings['iconThemePath'] = $icon_theme_path;
198$settings['templateDirectory'] = $sTplDir;
199$settings['unreadNotificationEnabled'] = $unseen_notify!=1;
200$settings['unreadNotificationAllFolders'] = $unseen_notify == 3;
201$settings['unreadNotificationDisplayTotal'] = $unseen_type == 2;
202$settings['unreadNotificationCummulative'] = $unseen_cum==1;
203$settings['useSpecialFolderColor'] = $use_special_folder_color;
204$settings['messageRecyclingEnabled'] = $move_to_trash;
205$settings['collapsableFoldersEnabled'] = $collapse_folders==1;
206$oTemplate->assign('settings', $settings);
207
208$oTemplate->display('left_main.tpl');
dcc1cc82 209
29997535 210sqimap_logout($imapConnection);
5c4ff7bf 211$oTemplate->display('footer.tpl');
212?>