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