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