24f32253c2e55dad2d73e1e58bb1e6450411f81f
6 * This is the code for the left bar. The left bar shows the folders
7 * available, and has cookie information.
9 * @copyright 1999-2010 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
15 /** This is the left_main page */
16 define('PAGE_NAME', 'left_main');
18 /* Disable browser caching */
19 header('Cache-Control: no-cache, no-store, must-revalidate');
20 header('Pragma: no-cache');
21 header('Expires: ' . gmdate(DATE_RFC1123
, time()-1));
24 * Include the SquirrelMail initialization file.
26 require('../include/init.php');
28 /* SquirrelMail required files. */
29 require_once(SM_PATH
. 'functions/imap_general.php');
30 require_once(SM_PATH
. 'functions/date.php');
31 require_once(SM_PATH
. 'functions/template/folder_list_util.php');
33 /* These constants are used for folder stuff. */
34 define('SM_BOX_UNCOLLAPSED', 0);
35 define('SM_BOX_COLLAPSED', 1);
38 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
40 sqgetGlobalVar('fold', $fold, SQ_GET
);
41 sqgetGlobalVar('unfold', $unfold, SQ_GET
);
44 // open a connection on the imap port (143)
45 // why hide the output?
46 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, true);
49 * Using stristr since very old preferences may contain "None" and "none".
51 if (!empty($left_refresh) &&
52 !stristr($left_refresh, 'none')){
53 $xtra = "\n<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
59 * Include extra javascript files needed by template
61 $js_includes = $oTemplate->get_javascript_includes(TRUE);
62 foreach ($js_includes as $js_file) {
63 $xtra .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
66 // get mailbox list and cache it
67 $mailboxes=sqimap_get_mailboxes($imapConnection,false,$show_only_subscribed_folders);
69 displayHtmlHeader( $org_title, $xtra );
70 $oErrorHandler->setDelayedErrors(true);
72 sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION
);
73 /* If requested and not yet complete, attempt to autocreate folders. */
74 if ($auto_create_special && !isset($auto_create_done)) {
75 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
76 $folders_created = false;
77 foreach( $autocreate as $folder ) {
78 if ($folder != '' && $folder != SMPREF_NONE
) {
80 * If $show_only_subscribed_folders is true, don't use
81 * $mailboxes array for checking if mailbox exists.
82 * Mailbox list contains only subscribed folders.
83 * sqimap_mailbox_create() will fail, if folder exists.
85 if ($show_only_subscribed_folders) {
86 $mailbox_cache = false;
88 $mailbox_cache = $mailboxes;
90 if ( !sqimap_mailbox_exists($imapConnection, $folder, $mailbox_cache)) {
91 sqimap_mailbox_create($imapConnection, $folder, '');
92 $folders_created = true;
94 // check for subscription is useless and expensive, just
95 // surpress the NO response. Unless we're on Mecury, which
96 // will just subscribe a folder again if it's already
98 if ( strtolower($imap_server_type) != 'mercury32' ||
99 !sqimap_mailbox_is_subscribed($imapConnection, $folder) ) {
100 sqimap_subscribe($imapConnection, $folder, false);
101 $folders_created = true;
107 /* Let the world know that autocreation is complete! Hurrah! */
108 $auto_create_done = TRUE;
109 sqsession_register($auto_create_done, 'auto_create_done');
110 // reload mailbox list
111 if ($folders_created)
112 $mailboxes=sqimap_get_mailboxes($imapConnection,true,$show_only_subscribed_folders);
116 if ($date_format != 6) {
117 /* First, display the clock. */
118 if ($hour_format == 1) {
120 if ($date_format == 4) {
124 if ($date_format == 4) {
131 switch( $date_format ) {
133 $clk = date('Y-m-d '.$hr. ' T', time());
136 $clk = date('m/d/y '.$hr, time());
139 $clk = date('d/m/y '.$hr, time());
143 $clk = date($hr, time());
146 $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
148 $clk = str_replace(' ',' ',$clk);
150 //FIXME don't build HTML here - do it in template
151 $clock = '<small><span style="white-space: nowrap;">'
152 . str_replace(' ', ' ', _("Last Refresh"))
153 . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />\n";
156 if ( $collapse_folders ) {
157 /* If directed, collapse or uncollapse a folder. */
159 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED
);
160 } else if (isset($unfold)) {
161 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED
);
165 /* Get unseen/total display prefs */
166 $unseen_type = getPref( $data_dir , $username , 'unseen_type' );
167 $unseen_notify = getPref( $data_dir , $username , 'unseen_notify' );
169 if (empty($unseen_type)) {
170 if (!empty($default_unseen_type)) {
171 $unseen_type = $default_unseen_type;
177 if (empty($unseen_notify)) {
178 if (!empty($default_unseen_notify)) {
179 $unseen_notify = $default_unseen_notify;
186 * pass $mailboxes now instead of $imapconnection - sqimap_get_mailboxes() has been separated from
187 * sqimap_mailbox_tree() so that the cached mailbox list can be used elsewhere in left_main and beyond
189 $boxes = sqimap_mailbox_tree($imapConnection,$mailboxes,$show_only_subscribed_folders);
190 $mailbox_structure = getBoxStructure($boxes);
192 $oTemplate->assign('clock', $clock);
193 $oTemplate->assign('mailboxes', $mailbox_structure);
196 * Build an array to pass user prefs to the template in order to avoid using
197 * globals, which are dirty, filthy things in templates. :)
200 #$settings['imapConnection'] = $imapConnection;
201 $settings['templateID'] = $sTemplateID;
202 $settings['unreadNotificationEnabled'] = $unseen_notify!=1;
203 $settings['unreadNotificationAllFolders'] = $unseen_notify == 3;
204 $settings['unreadNotificationDisplayTotal'] = $unseen_type == 2;
205 $settings['unreadNotificationCummulative'] = $unseen_cum==1;
206 $settings['useSpecialFolderColor'] = $use_special_folder_color;
207 $settings['messageRecyclingEnabled'] = $move_to_trash;
208 $settings['collapsableFoldersEnabled'] = $collapse_folders==1;
209 $oTemplate->assign('settings', $settings);
213 $oTemplate->assign('accesskey_folders_refresh', $accesskey_folders_refresh);
214 $oTemplate->assign('accesskey_folders_purge_trash', $accesskey_folders_purge_trash);
215 $oTemplate->assign('accesskey_folders_inbox', $accesskey_folders_inbox);
217 $oTemplate->display('left_main.tpl');
219 sqimap_logout($imapConnection);
220 $oTemplate->display('footer.tpl');