removing code that could be used with plugin in SM 1.4.x. After init
[squirrelmail.git] / src / left_main.php
1 <?php
2
3 /**
4 * left_main.php
5 *
6 * This is the code for the left bar. The left bar shows the folders
7 * available, and has cookie information.
8 *
9 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15 /**
16 * Include the SquirrelMail initialization file.
17 */
18 require('../include/init.php');
19
20 /* SquirrelMail required files. */
21 require_once(SM_PATH . 'functions/imap_general.php');
22 require_once(SM_PATH . 'functions/date.php');
23 require_once(SM_PATH . 'templates/util_global.php');
24 require_once(SM_PATH . 'templates/util_left_main.php');
25
26 /* These constants are used for folder stuff. */
27 define('SM_BOX_UNCOLLAPSED', 0);
28 define('SM_BOX_COLLAPSED', 1);
29
30 /* get globals */
31 sqgetGlobalVar('username', $username, SQ_SESSION);
32 sqgetGlobalVar('key', $key, SQ_COOKIE);
33 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
34 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
35
36 sqgetGlobalVar('fold', $fold, SQ_GET);
37 sqgetGlobalVar('unfold', $unfold, SQ_GET);
38 /* end globals */
39
40 // open a connection on the imap port (143)
41 // why hide the output?
42 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, true);
43
44 /**
45 * Using stristr since very old preferences may contain "None" and "none".
46 */
47 if (!empty($left_refresh) &&
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".
51 "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
52 } else {
53 $xtra = '';
54 }
55
56 /**
57 * Include extra javascript files needed by template
58 */
59 $js_includes = $oTemplate->getJavascriptIncludes();
60 foreach ($js_includes as $js_file) {
61 $xtra .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
62 }
63
64 // get mailbox list and cache it
65 $mailboxes=sqimap_get_mailboxes($imapConnection,false,$show_only_subscribed_folders);
66
67 displayHtmlHeader( 'SquirrelMail', $xtra );
68
69 sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION);
70 /* If requested and not yet complete, attempt to autocreate folders. */
71 if ($auto_create_special && !isset($auto_create_done)) {
72 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
73 $folders_created = false;
74 foreach( $autocreate as $folder ) {
75 if (($folder != '') && ($folder != 'none')) {
76 // use $mailboxes array for checking if mailbox exists
77 if ( !sqimap_mailbox_exists($imapConnection, $folder, $mailboxes)) {
78 sqimap_mailbox_create($imapConnection, $folder, '');
79 $folders_created = true;
80 } else {
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);
88 $folders_created = true;
89 }
90 }
91 }
92 }
93
94 /* Let the world know that autocreation is complete! Hurrah! */
95 $auto_create_done = TRUE;
96 sqsession_register($auto_create_done, 'auto_create_done');
97 // reload mailbox list
98 if ($folders_created)
99 $mailboxes=sqimap_get_mailboxes($imapConnection,true,$show_only_subscribed_folders);
100 }
101
102 $clock = '';
103 if ($date_format != 6) {
104 /* First, display the clock. */
105 if ($hour_format == 1) {
106 $hr = 'H:i';
107 if ($date_format == 4) {
108 $hr .= ':s';
109 }
110 } else {
111 if ($date_format == 4) {
112 $hr = 'g:i:s a';
113 } else {
114 $hr = 'g:i a';
115 }
116 }
117
118 switch( $date_format ) {
119 case 0:
120 $clk = date('Y-m-d '.$hr. ' T', time());
121 break;
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:
133 $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
134 }
135 $clk = str_replace(' ','&nbsp;',$clk);
136
137 $clock = '<small><span style="white-space: nowrap;">'
138 . str_replace(' ', '&nbsp;', _("Last Refresh"))
139 . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />\n";
140 }
141
142 if ( $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
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
155 if (empty($unseen_type)) {
156 if (!empty($default_unseen_type)) {
157 $unseen_type = $default_unseen_type;
158 } else {
159 $unseen_type = 1;
160 }
161 }
162
163 if (empty($unseen_notify)) {
164 if (!empty($default_unseen_notify)) {
165 $unseen_notify = $default_unseen_notify;
166 } else {
167 $unseen_notify = 0;
168 }
169 }
170
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);
176 $mailbox_structure = getBoxStructure($boxes);
177
178 $oTemplate->assign('clock', $clock);
179 $oTemplate->assign('mailboxes', $mailbox_structure);
180
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');
199
200 sqimap_logout($imapConnection);
201 $oTemplate->display('footer.tpl');
202 ?>