removing code that could be used with plugin in SM 1.4.x. After init
[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')) {
a462b928 76 // use $mailboxes array for checking if mailbox exists
77 if ( !sqimap_mailbox_exists($imapConnection, $folder, $mailboxes)) {
95e93571 78 sqimap_mailbox_create($imapConnection, $folder, '');
3bf08e48 79 $folders_created = true;
852abae7 80 } else {
7b1f03c9 81 // check for subscription is useless and expensive, just
82 // surpress the NO response. Unless we're on Mecury, which
83 // will just subscribe a folder again if it's already
84 // subscribed.
85 if ( strtolower($imap_server_type) != 'mercury32' ||
86 !sqimap_mailbox_is_subscribed($imapConnection, $folder) ) {
87 sqimap_subscribe($imapConnection, $folder, false);
3bf08e48 88 $folders_created = true;
7b1f03c9 89 }
2d367c68 90 }
ebf18afa 91 }
2d367c68 92 }
a6d2e0de 93
95e93571 94 /* Let the world know that autocreation is complete! Hurrah! */
90de1755 95 $auto_create_done = TRUE;
a32985a5 96 sqsession_register($auto_create_done, 'auto_create_done');
3bf08e48 97 // reload mailbox list
98 if ($folders_created)
99 $mailboxes=sqimap_get_mailboxes($imapConnection,true,$show_only_subscribed_folders);
95e93571 100}
dcc1cc82 101
29997535 102$clock = '';
95e93571 103if ($date_format != 6) {
104 /* First, display the clock. */
105 if ($hour_format == 1) {
3208c2a5 106 $hr = 'H:i';
95e93571 107 if ($date_format == 4) {
108 $hr .= ':s';
a6d2e0de 109 }
95e93571 110 } else {
111 if ($date_format == 4) {
112 $hr = 'g:i:s a';
113 } else {
114 $hr = 'g:i a';
2d367c68 115 }
116 }
117
95e93571 118 switch( $date_format ) {
e4f5158a 119 case 0:
134e4174 120 $clk = date('Y-m-d '.$hr. ' T', time());
121 break;
95e93571 122 case 1:
123 $clk = date('m/d/y '.$hr, time());
124 break;
125 case 2:
126 $clk = date('d/m/y '.$hr, time());
127 break;
128 case 4:
129 case 5:
130 $clk = date($hr, time());
131 break;
132 default:
67eb95d7 133 $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
2d367c68 134 }
95e93571 135 $clk = str_replace(' ','&nbsp;',$clk);
136
29997535 137 $clock = '<small><span style="white-space: nowrap;">'
f8a1ed5a 138 . str_replace(' ', '&nbsp;', _("Last Refresh"))
3cbf882e 139 . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />\n";
95e93571 140}
141
95e93571 142if ( $collapse_folders ) {
143 /* If directed, collapse or uncollapse a folder. */
144 if (isset($fold)) {
145 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
146 } else if (isset($unfold)) {
147 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
148 }
149}
150
c5a52f46 151/* Get unseen/total display prefs */
152$unseen_type = getPref( $data_dir , $username , 'unseen_type' );
153$unseen_notify = getPref( $data_dir , $username , 'unseen_notify' );
154
3cbf882e 155if (empty($unseen_type)) {
156 if (!empty($default_unseen_type)) {
c5a52f46 157 $unseen_type = $default_unseen_type;
158 } else {
159 $unseen_type = 1;
160 }
161}
162
3cbf882e 163if (empty($unseen_notify)) {
164 if (!empty($default_unseen_notify)) {
c5a52f46 165 $unseen_notify = $default_unseen_notify;
166 } else {
167 $unseen_notify = 0;
168 }
169}
29997535 170
a462b928 171/**
172 * pass $mailboxes now instead of $imapconnection - sqimap_get_mailboxes() has been separated from
173 * sqimap_mailbox_tree() so that the cached mailbox list can be used elsewhere in left_main and beyond
174 */
175$boxes = sqimap_mailbox_tree($imapConnection,$mailboxes,$show_only_subscribed_folders);
29997535 176$mailbox_structure = getBoxStructure($boxes);
177
178$oTemplate->assign('clock', $clock);
29997535 179$oTemplate->assign('mailboxes', $mailbox_structure);
29997535 180
6373ad12 181/*
182 * Build an array to pass user prefs to the template in order to avoid using
183 * globals, which are dirty, filthy things in templates. :)
184 */
185$settings = array();
186$settings['imapConnection'] = $imapConnection;
187$settings['iconThemePath'] = $icon_theme_path;
188$settings['templateDirectory'] = $sTplDir;
189$settings['unreadNotificationEnabled'] = $unseen_notify!=1;
190$settings['unreadNotificationAllFolders'] = $unseen_notify == 3;
191$settings['unreadNotificationDisplayTotal'] = $unseen_type == 2;
192$settings['unreadNotificationCummulative'] = $unseen_cum==1;
193$settings['useSpecialFolderColor'] = $use_special_folder_color;
194$settings['messageRecyclingEnabled'] = $move_to_trash;
195$settings['collapsableFoldersEnabled'] = $collapse_folders==1;
196$oTemplate->assign('settings', $settings);
197
198$oTemplate->display('left_main.tpl');
dcc1cc82 199
29997535 200sqimap_logout($imapConnection);
5c4ff7bf 201$oTemplate->display('footer.tpl');
202?>