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 © 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 | /** |
16 | * Path for SquirrelMail required files. |
17 | * @ignore |
18 | */ |
dcc1cc82 |
19 | define('SM_PATH','../'); |
86725763 |
20 | |
21 | /* SquirrelMail required files. */ |
5c4ff7bf |
22 | include_once(SM_PATH . 'include/validate.php'); |
86725763 |
23 | require_once(SM_PATH . 'functions/imap.php'); |
24 | require_once(SM_PATH . 'functions/plugin.php'); |
25 | require_once(SM_PATH . 'functions/page_header.php'); |
26 | require_once(SM_PATH . 'functions/html.php'); |
b6d26135 |
27 | require_once(SM_PATH . 'functions/date.php'); |
142499d4 |
28 | |
29997535 |
29 | /** add required includes */ |
30 | include_once(SM_PATH . 'templates/util_global.php'); |
31 | include_once(SM_PATH . 'templates/util_left_main.php'); |
32 | |
95e93571 |
33 | /* These constants are used for folder stuff. */ |
34 | define('SM_BOX_UNCOLLAPSED', 0); |
35 | define('SM_BOX_COLLAPSED', 1); |
a6d2e0de |
36 | |
2d367c68 |
37 | /* --------------------- FUNCTIONS ------------------------- */ |
525b7ae6 |
38 | |
a6d2e0de |
39 | |
29997535 |
40 | |
95e93571 |
41 | /** |
29997535 |
42 | * Recursive functions to output a tree of folders. |
43 | * They are called on a list of boxes and iterates over that tree. |
ffb1a3d9 |
44 | * |
29997535 |
45 | * NOTE: These functions are deprecated and replaced with templates in 1.5.2. |
46 | * They remain until the advanced tree tempalte is completed also, |
47 | * at which point both functions below will be removed |
48 | * |
3cbf882e |
49 | * @since 1.3.0 |
29997535 |
50 | * @deprecated |
ffb1a3d9 |
51 | */ |
29997535 |
52 | function ListBoxes ($boxes, $j=0) { |
53 | return ''; |
f23f6a3a |
54 | } |
55 | |
c8fa94cf |
56 | function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) { |
48879ef0 |
57 | global $data_dir, $username, $color, $unseen_notify, $unseen_type, $unseen_cum, |
134e4174 |
58 | $move_to_trash, $trash_folder, $collapse_folders, $use_special_folder_color; |
f23f6a3a |
59 | |
3cbf882e |
60 | if (empty($boxes)) { |
ccc4580f |
61 | return; |
3cbf882e |
62 | } |
4bdcd5e0 |
63 | |
f23f6a3a |
64 | /* use_folder_images only works if the images exist in ../images */ |
c8fa94cf |
65 | $use_folder_images = true; |
f23f6a3a |
66 | |
67 | $pre = ''; |
68 | $end = ''; |
69 | $collapse = false; |
6c8fee24 |
70 | $unseen_found = false; |
71 | $unseen = 0; |
a6172cd5 |
72 | |
a6172cd5 |
73 | $mailbox = $boxes->mailboxname_full; |
74 | $mailboxURL = urlencode($mailbox); |
f23f6a3a |
75 | |
48879ef0 |
76 | /* get collapse information */ |
77 | if ($collapse_folders) { |
78 | $form_entry = $j.'F'; |
79 | if (isset($mbx) && isset($mbx[$form_entry])) { |
80 | $collapse = $mbx[$form_entry]; |
81 | setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full , |
82 | $collapse ? SM_BOX_COLLAPSED : SM_BOX_UNCOLLAPSED); |
83 | } else { |
84 | $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox); |
85 | $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse); |
86 | } |
87 | $img_src = ($collapse ? '../images/plus.png' : '../images/minus.png'); |
88 | $collapse_link = '<a href="javascript:void(0)">' . |
89 | " <img src=\"$img_src\" border=\"1\" id=$j onclick=\"hidechilds(this)\" style=\"cursor:hand\" /></a>"; |
90 | } else { |
91 | $collapse_link=''; |
92 | } |
93 | |
ccc4580f |
94 | /* get unseen/total messages information */ |
6c8fee24 |
95 | /* Only need to display info when option is set */ |
48879ef0 |
96 | if (isset($unseen_notify) && ($unseen_notify > 1)) { |
97 | /* handle Cumulative Unread Message Notification */ |
98 | if ($collapse && $unseen_cum) { |
99 | foreach ($boxes->mbxs as $cumn_box) { |
100 | if (!empty($cumn_box->unseen)) $boxes->unseen += $cumn_box->unseen; |
101 | if (!empty($cumn_box->total)) $boxes->total += $cumn_box->total; |
ccc4580f |
102 | } |
48879ef0 |
103 | } |
104 | if (($boxes->unseen !== false) || ($boxes->total !== false)) { |
105 | if ($boxes->unseen !== false) $unseen = $boxes->unseen; |
106 | /* |
107 | * Should only display unseen info if the folder is inbox |
108 | * or you set the option for all folders |
109 | */ |
110 | if ((strtolower($mailbox) == 'inbox') || ($unseen_notify == 3)) { |
111 | $unseen_string = $unseen; |
112 | |
113 | /* If users requests, display message count too */ |
114 | if (isset($unseen_type) && ($unseen_type == 2) && ($boxes->total !== false)) { |
115 | $unseen_string .= '/' . $boxes->total; |
116 | } |
5fefb100 |
117 | if (isset($boxes->recent) && $boxes->recent > 0) { |
118 | $unseen_string = "<span class=\"leftrecent\">($unseen_string)</span>"; |
119 | } else { |
120 | $unseen_string = "<span class=\"leftunseen\">($unseen_string)</span>"; |
121 | } |
48879ef0 |
122 | |
123 | /* |
124 | * Finally allow the script to display the values by setting a boolean. |
125 | * This can only occur if the unseen count is great than 0 (if you have |
126 | * unseen count only), or you have the message count too. |
127 | */ |
128 | if (($unseen > 0) || (isset($unseen_type) && ($unseen_type ==2))) { |
129 | $unseen_found = true; |
130 | } |
6c8fee24 |
131 | } |
ccc4580f |
132 | } |
6c8fee24 |
133 | } |
a6172cd5 |
134 | |
135 | /* If there are unseen message, bold the line. */ |
136 | if ($unseen > 0) { $pre .= '<b>'; } |
137 | |
138 | /* color special boxes */ |
a259636c |
139 | if ($use_special_folder_color && $boxes->is_special) { |
254773f5 |
140 | $pre .= "<span class=\"leftspecial\">"; |
81132de8 |
141 | $end .= '</span>'; |
a6172cd5 |
142 | } |
143 | |
144 | /* If there are unseen message, close bolding. */ |
145 | if ($unseen > 0) { $end .= '</b>'; } |
146 | |
147 | /* Print unseen information. */ |
ccc4580f |
148 | if ($unseen_found) { |
149 | $end .= " $unseen_string"; |
a6172cd5 |
150 | } |
151 | |
152 | if (($move_to_trash) && ($mailbox == $trash_folder)) { |
324ac3c5 |
153 | $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\">" . $pre; |
4bdcd5e0 |
154 | $end .= '</a>'; |
dea5ef88 |
155 | $end .= "\n<small>\n" . |
156 | ' [<a class="mbx_link" href="empty_trash.php">'._("Purge").'</a>]'. |
157 | '</small>'; |
a6172cd5 |
158 | } else { |
159 | if (!$boxes->is_noselect) { /* \Noselect boxes can't be selected */ |
324ac3c5 |
160 | $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\">" . $pre; |
4bdcd5e0 |
161 | $end .= '</a>'; |
a6172cd5 |
162 | } |
163 | } |
164 | |
8fc208f8 |
165 | // let plugins fiddle with end of line |
166 | global $imapConnection; |
167 | $end .= concat_hook_function('left_main_after_each_folder', |
324ac3c5 |
168 | array(isset($numMessages) ? $numMessages : '', |
8fc208f8 |
169 | $boxes->mailboxname_full, $imapConnection)); |
170 | |
29997535 |
171 | $out = ''; |
a6172cd5 |
172 | if (!$boxes->is_root) { |
173 | if ($use_folder_images) { |
ccc4580f |
174 | if ($boxes->is_inbox) { |
175 | $folder_img = '../images/inbox.png'; |
176 | } else if ($boxes->is_sent) { |
177 | $folder_img = '../images/senti.png'; |
178 | } else if ($boxes->is_trash) { |
179 | $folder_img = '../images/delitem.png'; |
180 | } else if ($boxes->is_draft) { |
181 | $folder_img = '../images/draft.png'; |
182 | } else if ($boxes->is_noinferiors) { |
183 | $folder_img = '../images/folder_noinf.png'; |
184 | } else { |
185 | $folder_img = '../images/folder.png'; |
186 | } |
0bcd11eb |
187 | $folder_img = ' <img src="'.$folder_img.'" height="15" /> '; |
ccc4580f |
188 | } else { |
189 | $folder_img = ''; |
190 | } |
a6172cd5 |
191 | if (!isset($boxes->mbxs[0])) { |
29997535 |
192 | $out .= ' ' . html_tag( 'div', |
0bcd11eb |
193 | $pre . $folder_img . |
3cbf882e |
194 | str_replace( array(' ','<','>'), |
195 | array(' ','<','>'), |
196 | $boxes->mailboxname_sub) . |
197 | $end, |
3170c448 |
198 | 'left', '', 'class="mbx_sub" id="' .$j. '"' ) . "\n"; |
ccc4580f |
199 | } else { |
48879ef0 |
200 | |
29997535 |
201 | $out .= ' ' . html_tag( 'div', |
a6172cd5 |
202 | $collapse_link . $pre . $folder_img . ' '. $boxes->mailboxname_sub . $end , |
3170c448 |
203 | 'left', '', 'class="mbx_par" id="' .$j. 'P"' ) . "\n"; |
29997535 |
204 | $out .= ' <input type="hidden" name="mbx['.$j. 'F]" value="'.$collapse.'" id="mbx['.$j.'F]" />'."\n"; |
a6172cd5 |
205 | } |
206 | } |
a6172cd5 |
207 | |
4bdcd5e0 |
208 | $visible = ($collapse ? ' style="display:none"' : ' style="display:block"'); |
209 | if (isset($boxes->mbxs[0]) && !$boxes->is_root) /* mailbox contains childs */ |
29997535 |
210 | $out .= html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n"; |
a6172cd5 |
211 | |
3cbf882e |
212 | if ($j !='ID.0000') { |
4bdcd5e0 |
213 | $j = $j .'.0000'; |
3cbf882e |
214 | } |
4bdcd5e0 |
215 | for ($i = 0; $i <count($boxes->mbxs); $i++) { |
216 | $j++; |
29997535 |
217 | $out .= ListAdvancedBoxes($boxes->mbxs[$i],$mbx,$j); |
f23f6a3a |
218 | } |
3cbf882e |
219 | if (isset($boxes->mbxs[0]) && !$boxes->is_root) { |
29997535 |
220 | $out .= '</div>'."\n\n"; |
3cbf882e |
221 | } |
29997535 |
222 | |
223 | return $out; |
f23f6a3a |
224 | } |
225 | |
226 | |
227 | |
95e93571 |
228 | |
229 | /* -------------------- MAIN ------------------------ */ |
230 | |
f38b7cf0 |
231 | /* get globals */ |
232 | sqgetGlobalVar('username', $username, SQ_SESSION); |
233 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
234 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
235 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
a32985a5 |
236 | |
f38b7cf0 |
237 | sqgetGlobalVar('fold', $fold, SQ_GET); |
238 | sqgetGlobalVar('unfold', $unfold, SQ_GET); |
239 | |
240 | /* end globals */ |
95e93571 |
241 | |
242 | // open a connection on the imap port (143) |
3cbf882e |
243 | // why hide the output? |
244 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, true); |
95e93571 |
245 | |
f43c35f8 |
246 | /** |
3cbf882e |
247 | * Using stristr since very old preferences may contain "None" and "none". |
f43c35f8 |
248 | */ |
3cbf882e |
249 | if (!empty($left_refresh) && |
d68323ff |
250 | !stristr($left_refresh, 'none')){ |
251 | $xtra = "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\" />\n" . |
252 | "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n". |
dcc1cc82 |
253 | "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n"; |
95e93571 |
254 | } else { |
255 | $xtra = ''; |
256 | } |
257 | |
f23f6a3a |
258 | /** |
3cbf882e |
259 | * $advanced_tree and is a boolean var which is default set to default |
a6172cd5 |
260 | * SM behaviour. |
a6172cd5 |
261 | * Setting $advanced tree to true causes SM to display a experimental |
29997535 |
262 | * mailbox-tree with dhtml behaviour. |
263 | * |
264 | * See templates/default/left_main_advanced.tpl |
a6172cd5 |
265 | **/ |
f23f6a3a |
266 | |
78e5377d |
267 | /* set this to true if you want to see a nicer mailboxtree */ |
3cbf882e |
268 | if (empty($advanced_tree)) { |
ccc4580f |
269 | $advanced_tree=false; |
270 | } |
f23f6a3a |
271 | |
a462b928 |
272 | // get mailbox list and cache it |
273 | $mailboxes=sqimap_get_mailboxes($imapConnection,false,$show_only_subscribed_folders); |
274 | |
dcc1cc82 |
275 | displayHtmlHeader( 'SquirrelMail', $xtra ); |
a462b928 |
276 | |
852abae7 |
277 | sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION); |
95e93571 |
278 | /* If requested and not yet complete, attempt to autocreate folders. */ |
279 | if ($auto_create_special && !isset($auto_create_done)) { |
a3439b27 |
280 | $autocreate = array($sent_folder, $trash_folder, $draft_folder); |
3bf08e48 |
281 | $folders_created = false; |
95e93571 |
282 | foreach( $autocreate as $folder ) { |
a3439b27 |
283 | if (($folder != '') && ($folder != 'none')) { |
a462b928 |
284 | // use $mailboxes array for checking if mailbox exists |
285 | if ( !sqimap_mailbox_exists($imapConnection, $folder, $mailboxes)) { |
95e93571 |
286 | sqimap_mailbox_create($imapConnection, $folder, ''); |
3bf08e48 |
287 | $folders_created = true; |
852abae7 |
288 | } else { |
7b1f03c9 |
289 | // check for subscription is useless and expensive, just |
290 | // surpress the NO response. Unless we're on Mecury, which |
291 | // will just subscribe a folder again if it's already |
292 | // subscribed. |
293 | if ( strtolower($imap_server_type) != 'mercury32' || |
294 | !sqimap_mailbox_is_subscribed($imapConnection, $folder) ) { |
295 | sqimap_subscribe($imapConnection, $folder, false); |
3bf08e48 |
296 | $folders_created = true; |
7b1f03c9 |
297 | } |
2d367c68 |
298 | } |
ebf18afa |
299 | } |
2d367c68 |
300 | } |
a6d2e0de |
301 | |
95e93571 |
302 | /* Let the world know that autocreation is complete! Hurrah! */ |
90de1755 |
303 | $auto_create_done = TRUE; |
a32985a5 |
304 | sqsession_register($auto_create_done, 'auto_create_done'); |
3bf08e48 |
305 | // reload mailbox list |
306 | if ($folders_created) |
307 | $mailboxes=sqimap_get_mailboxes($imapConnection,true,$show_only_subscribed_folders); |
95e93571 |
308 | } |
dcc1cc82 |
309 | |
29997535 |
310 | $clock = ''; |
95e93571 |
311 | if ($date_format != 6) { |
312 | /* First, display the clock. */ |
313 | if ($hour_format == 1) { |
3208c2a5 |
314 | $hr = 'H:i'; |
95e93571 |
315 | if ($date_format == 4) { |
316 | $hr .= ':s'; |
a6d2e0de |
317 | } |
95e93571 |
318 | } else { |
319 | if ($date_format == 4) { |
320 | $hr = 'g:i:s a'; |
321 | } else { |
322 | $hr = 'g:i a'; |
2d367c68 |
323 | } |
324 | } |
325 | |
95e93571 |
326 | switch( $date_format ) { |
e4f5158a |
327 | case 0: |
134e4174 |
328 | $clk = date('Y-m-d '.$hr. ' T', time()); |
329 | break; |
95e93571 |
330 | case 1: |
331 | $clk = date('m/d/y '.$hr, time()); |
332 | break; |
333 | case 2: |
334 | $clk = date('d/m/y '.$hr, time()); |
335 | break; |
336 | case 4: |
337 | case 5: |
338 | $clk = date($hr, time()); |
339 | break; |
340 | default: |
67eb95d7 |
341 | $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() ); |
2d367c68 |
342 | } |
95e93571 |
343 | $clk = str_replace(' ',' ',$clk); |
344 | |
29997535 |
345 | $clock = '<small><span style="white-space: nowrap;">' |
f8a1ed5a |
346 | . str_replace(' ', ' ', _("Last Refresh")) |
3cbf882e |
347 | . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />\n"; |
95e93571 |
348 | } |
349 | |
95e93571 |
350 | if ( $collapse_folders ) { |
351 | /* If directed, collapse or uncollapse a folder. */ |
352 | if (isset($fold)) { |
353 | setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED); |
354 | } else if (isset($unfold)) { |
355 | setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED); |
356 | } |
357 | } |
358 | |
c5a52f46 |
359 | /* Get unseen/total display prefs */ |
360 | $unseen_type = getPref( $data_dir , $username , 'unseen_type' ); |
361 | $unseen_notify = getPref( $data_dir , $username , 'unseen_notify' ); |
362 | |
3cbf882e |
363 | if (empty($unseen_type)) { |
364 | if (!empty($default_unseen_type)) { |
c5a52f46 |
365 | $unseen_type = $default_unseen_type; |
366 | } else { |
367 | $unseen_type = 1; |
368 | } |
369 | } |
370 | |
3cbf882e |
371 | if (empty($unseen_notify)) { |
372 | if (!empty($default_unseen_notify)) { |
c5a52f46 |
373 | $unseen_notify = $default_unseen_notify; |
374 | } else { |
375 | $unseen_notify = 0; |
376 | } |
377 | } |
29997535 |
378 | |
a462b928 |
379 | /** |
380 | * pass $mailboxes now instead of $imapconnection - sqimap_get_mailboxes() has been separated from |
381 | * sqimap_mailbox_tree() so that the cached mailbox list can be used elsewhere in left_main and beyond |
382 | */ |
383 | $boxes = sqimap_mailbox_tree($imapConnection,$mailboxes,$show_only_subscribed_folders); |
c5a52f46 |
384 | |
29997535 |
385 | $mailbox_listing = ''; |
3cbf882e |
386 | if (isset($advanced_tree) && $advanced_tree) { |
29997535 |
387 | $mailbox_listing = '<form name="collapse" action="left_main.php" method="post" ' . |
0bcd11eb |
388 | 'enctype="multipart/form-data">'."\n"; |
29997535 |
389 | $mailbox_listing .= '<button type="submit" class="button" onmouseover="buttonover(this,true)" onmouseout="buttonover(this,false)" onmousedown="buttonclick(this,true)" onmouseup="buttonclick(this,false)">'. _("Save folder tree") .'</button><br /><br />'; |
390 | $mailbox_listing .= '<div id="mailboxes" class="mailboxes">'."\n\n"; |
3cbf882e |
391 | sqgetGlobalVar('mbx', $mbx, SQ_POST); |
392 | if (!isset($mbx)) $mbx=NULL; |
29997535 |
393 | $mailbox_listing .=ListAdvancedBoxes($boxes, $mbx); |
394 | $mailbox_listing .= '</div>'; |
395 | $mailbox_listing .= '</form>'."\n"; |
3cbf882e |
396 | } else { |
29997535 |
397 | $mailbox_listing = ListBoxes($boxes); |
95e93571 |
398 | } |
399 | |
29997535 |
400 | $mailbox_structure = getBoxStructure($boxes); |
401 | |
402 | $oTemplate->assign('clock', $clock); |
403 | $oTemplate->assign('mailbox_listing', $mailbox_listing); |
404 | $oTemplate->assign('location_of_bar', $location_of_bar); |
405 | $oTemplate->assign('left_size', $left_size); |
406 | |
407 | $oTemplate->assign('mailboxes', $mailbox_structure); |
408 | $oTemplate->assign('imapConnection', $imapConnection); |
409 | |
410 | $oTemplate->assign('unread_notification_enabled', $unseen_notify!=1); |
411 | $oTemplate->assign('unread_notification_cummulative', $unseen_cum==1); |
412 | $oTemplate->assign('unread_notification_allFolders', $unseen_notify == 3); |
413 | $oTemplate->assign('unread_notification_displayTotal', $unseen_type == 2); |
414 | $oTemplate->assign('collapsable_folders_enabled', $collapse_folders==1); |
415 | $oTemplate->assign('icon_theme_path', $icon_theme_path); |
416 | $oTemplate->assign('use_special_folder_color', $use_special_folder_color); |
417 | $oTemplate->assign('message_recycling_enabled', $move_to_trash); |
29997535 |
418 | |
419 | if (isset($advanced_tree) && $advanced_tree) { |
420 | $oTemplate->display('left_main_advanced.tpl'); |
421 | } else { |
422 | $oTemplate->display('left_main.tpl'); |
423 | } |
dcc1cc82 |
424 | |
29997535 |
425 | sqimap_logout($imapConnection); |
5c4ff7bf |
426 | $oTemplate->display('footer.tpl'); |
427 | ?> |