Croatian Credits
[squirrelmail.git] / src / left_main.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * left_main.php
5 *
6 * Copyright (c) 1999-2001 The Squirrelmail Development Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This is the code for the left bar. The left bar shows the folders
10 * available, and has cookie information.
11 *
12 * $Id$
13 /
14
15/*****************************************************************/
16/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
17/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
18/*** + Base level indent should begin at left margin, as ***/
19/*** the require_once below looks. ***/
20/*** + All identation should consist of four space blocks ***/
21/*** + Tab characters are evil. ***/
22/*** + all comments should use "slash-star ... star-slash" ***/
23/*** style -- no pound characters, no slash-slash style ***/
24/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
25/*** ALWAYS USE { AND } CHARACTERS!!! ***/
26/*** + Please use ' instead of ", when possible. Note " ***/
27/*** should always be used in _( ) function calls. ***/
28/*** Thank you for your help making the SM code more readable. ***/
29/*****************************************************************/
30
31require_once('../src/validate.php');
32require_once('../functions/array.php');
33require_once('../functions/imap.php');
34require_once('../functions/plugin.php');
35require_once('../functions/page_header.php');
142499d4 36
95e93571 37/* These constants are used for folder stuff. */
38define('SM_BOX_UNCOLLAPSED', 0);
39define('SM_BOX_COLLAPSED', 1);
a6d2e0de 40
2d367c68 41/* --------------------- FUNCTIONS ------------------------- */
525b7ae6 42
95e93571 43function formatMailboxName($imapConnection, $box_array) {
44 global $folder_prefix, $trash_folder, $sent_folder;
45 global $color, $move_to_sent, $move_to_trash;
46 global $unseen_notify, $unseen_type, $collapse_folders;
47 global $draft_folder, $save_as_draft;
48 global $use_special_folder_color;
94f3a73b 49
95e93571 50 $real_box = $box_array['unformatted'];
51 $mailbox = str_replace('&nbsp;','',$box_array['formatted']);
52 $mailboxURL = urlencode($real_box);
21c3249f 53
95e93571 54 /* Strip down the mailbox name. */
55 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
56 $mailbox = $regs[2];
57 }
94f3a73b 58
95e93571 59 $unseen = 0;
60
61 if (($unseen_notify == 2 && $real_box == 'INBOX') ||
62 $unseen_notify == 3) {
63 $unseen = sqimap_unseen_messages($imapConnection, $real_box);
64 if ($unseen_type == 1 && $unseen > 0) {
65 $unseen_string = "($unseen)";
66 $unseen_found = true;
67 } else if ($unseen_type == 2) {
68 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
69 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
70 $unseen_found = true;
94f3a73b 71 }
95e93571 72 }
94f3a73b 73
95e93571 74 $special_color = false;
75 if ($use_special_folder_color) {
76 if ((strtolower($real_box) == 'inbox')
77 || (($real_box == $trash_folder) && ($move_to_trash))
78 || (($real_box == $sent_folder) && ($move_to_sent))
79 || (($real_box == $draft_folder) && ($save_as_draft))) {
80 $special_color = true;
94f3a73b 81 }
95e93571 82 }
f7b1b3b1 83
95e93571 84 /* Start off with a blank line. */
85 $line = '';
235a65d5 86
95e93571 87 /* If there are unseen message, bold the line. */
88 if ($unseen > 0) { $line .= '<B>'; }
a6d2e0de 89
95e93571 90 /* Crate the link for this folder. */
91 $line .= "<A HREF=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" TARGET=\"right\" STYLE=\"text-decoration:none\">";
92 if ($special_color == true)
93 $line .= "<FONT COLOR=\"$color[11]\">";
94 $line .= str_replace(' ','&nbsp;',$mailbox);
95 if ($special_color == true)
96 $line .= "</FONT>";
97 $line .= '</A>';
a6d2e0de 98
95e93571 99 /* If there are unseen message, close bolding. */
100 if ($unseen > 0) { $line .= "</B>"; }
2d367c68 101
95e93571 102 /* Print unseen information. */
103 if (isset($unseen_found) && $unseen_found) {
104 $line .= "&nbsp;<SMALL>$unseen_string</SMALL>";
2016e645 105 }
106
95e93571 107 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
108 if (! isset($numMessages)) {
109 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
a6d2e0de 110 }
a6d2e0de 111
95e93571 112 if ($numMessages > 0) {
113 $urlMailbox = urlencode($real_box);
114 $line .= "\n<small>\n" .
115 "&nbsp;&nbsp;(<A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("empty")."</A>)" .
116 "\n</small>\n";
a6d2e0de 117 }
118 }
a6d2e0de 119
95e93571 120 /* Return the final product. */
121 return ($line);
122}
a6d2e0de 123
95e93571 124/**
125 * Recursive function that computes the collapsed status and parent
126 * (or not parent) status of this box, and the visiblity and collapsed
127 * status and parent (or not parent) status for all children boxes.
128 */
129function compute_folder_children(&$parbox, $boxcount) {
130 global $boxes, $data_dir, $username, $collapse_folders;
131 $nextbox = $parbox + 1;
132
133 /* Retreive the name for the parent box. */
134 $parbox_name = $boxes[$parbox]['unformatted'];
135
136 /* 'Initialize' this parent box to childless. */
137 $boxes[$parbox]['parent'] = false;
138
139 /* Compute the collapse status for this box. */
140 if( isset($collapse_folders) && $collapse_folders ) {
141 $collapse = getPref($data_dir, $username, 'collapse_folder_' . $parbox_name);
142 $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
143 } else {
144 $collapse = SM_BOX_UNCOLLAPSED;
a6d2e0de 145 }
95e93571 146 $boxes[$parbox]['collapse'] = $collapse;
2d367c68 147
95e93571 148 /* Otherwise, get the name of the next box. */
149 if (isset($boxes[$nextbox]['unformatted']))
150 $nextbox_name = $boxes[$nextbox]['unformatted'];
151 else
152 $nextbox_name = '';
a6d2e0de 153
95e93571 154 /* Compute any children boxes for this box. */
155 while (($nextbox < $boxcount) &&
156 (is_parent_box($boxes[$nextbox]['unformatted'], $parbox_name))) {
a6d2e0de 157
95e93571 158 /* Note that this 'parent' box has at least one child. */
159 $boxes[$parbox]['parent'] = true;
a6d2e0de 160
95e93571 161 /* Compute the visiblity of this box. */
162 if ($boxes[$parbox]['visible'] &&
163 ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED)) {
164 $boxes[$nextbox]['visible'] = true;
165 } else {
166 $boxes[$nextbox]['visible'] = false;
167 }
a6d2e0de 168
95e93571 169 /* Compute the visibility of any child boxes. */
170 compute_folder_children($nextbox, $boxcount);
171 }
2d367c68 172
95e93571 173 /* Set the parent box to the current next box. */
174 $parbox = $nextbox;
175}
2d367c68 176
95e93571 177/**
178 * Create the link for a parent folder that will allow that
179 * parent folder to either be collapsed or expaned, as is
180 * currently appropriate.
181 */
182function create_collapse_link($boxnum) {
183 global $boxes;
184 $mailbox = urlencode($boxes[$boxnum]['unformatted']);
185
186 /* Create the link for this collapse link. */
187 $link = '<a target="left" style="text-decoration:none" ';
188 $link .= 'href="left_main.php?';
189 if ($boxes[$boxnum]['collapse'] == SM_BOX_COLLAPSED) {
190 $link .= "unfold=$mailbox\">+";
2d367c68 191 } else {
95e93571 192 $link .= "fold=$mailbox\">-";
2d367c68 193 }
95e93571 194 $link .= '</a>';
2d367c68 195
95e93571 196 /* Return the finished product. */
197 return ($link);
198}
199
200/**
201 * This simple function checks if a box is another box's parent.
202 */
203function is_parent_box($curbox_name, $parbox_name) {
204 global $delimiter;
205
206 /* Extract the name of the parent of the current box. */
207 $curparts = explode($delimiter, $curbox_name);
208 $curname = array_pop($curparts);
209 $actual_parname = implode($delimiter, $curparts);
210 $actual_parname = substr($actual_parname,0,strlen($parbox_name));
211
212 /* Compare the actual with the given parent name. */
213 return ($parbox_name == $actual_parname);
214}
215
216
217/* -------------------- MAIN ------------------------ */
218
219global $delimiter, $default_folder_prefix;
220
221// open a connection on the imap port (143)
222$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
223
224
225if (isset($left_refresh) && ($left_refresh != 'none') && ($left_refresh != '')) {
226 $xtra = "\n<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n" .
227 "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n".
228 "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
229} else {
230 $xtra = '';
231}
232
233displayHtmlHeader( 'SquirrelMail', $xtra );
234
235/* If requested and not yet complete, attempt to autocreate folders. */
236if ($auto_create_special && !isset($auto_create_done)) {
237 $autocreate = array( $sent_folder,
238 $trash_folder,
239 $draft_folder );
240 foreach( $autocreate as $folder ) {
241 if ($folder != '' && $folder != 'none') {
242 if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
243 sqimap_mailbox_create($imapConnection, $folder, '');
244 } elseif ( !sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
245 sqimap_subscribe($imapConnection, $folder);
2d367c68 246 }
ebf18afa 247 }
2d367c68 248 }
a6d2e0de 249
95e93571 250 /* Let the world know that autocreation is complete! Hurrah! */
251 $auto_create_done = true;
252 session_register('auto_create_done');
253}
a6d2e0de 254
95e93571 255echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
a6d2e0de 256
95e93571 257do_hook('left_main_before');
2d367c68 258
95e93571 259$boxes = sqimap_mailbox_list($imapConnection);
2d367c68 260
95e93571 261echo '<CENTER><FONT SIZE=4><B>'. _("Folders") . "</B><BR></FONT>\n\n";
a6d2e0de 262
95e93571 263if ($date_format != 6) {
264 /* First, display the clock. */
265 if ($hour_format == 1) {
266 $hr = 'G:i';
267 if ($date_format == 4) {
268 $hr .= ':s';
a6d2e0de 269 }
95e93571 270 } else {
271 if ($date_format == 4) {
272 $hr = 'g:i:s a';
273 } else {
274 $hr = 'g:i a';
2d367c68 275 }
276 }
277
95e93571 278 switch( $date_format ) {
279 case 1:
280 $clk = date('m/d/y '.$hr, time());
281 break;
282 case 2:
283 $clk = date('d/m/y '.$hr, time());
284 break;
285 case 4:
286 case 5:
287 $clk = date($hr, time());
288 break;
289 default:
290 $clk = date('D, '.$hr, time());
2d367c68 291 }
95e93571 292 $clk = str_replace(' ','&nbsp;',$clk);
293
294 echo '<CENTER><SMALL>' . str_replace(' ','&nbsp;',_("Last Refresh")) .
295 ": $clk</SMALL></CENTER>";
296}
297
298/* Next, display the refresh button. */
299echo '<SMALL>(<A HREF="../src/left_main.php" TARGET="left">'.
300 _("refresh folder list") . '</A>)</SMALL></CENTER><BR>';
301
302/* Lastly, display the folder list. */
303if ( $collapse_folders ) {
304 /* If directed, collapse or uncollapse a folder. */
305 if (isset($fold)) {
306 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
307 } else if (isset($unfold)) {
308 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
309 }
310}
311
312/* Prepare do do out collapsedness and visibility computation. */
313$curbox = 0;
314$boxcount = count($boxes);
315
316/* Compute the collapsedness and visibility of each box. */
317while ($curbox < $boxcount) {
318 $boxes[$curbox]['visible'] = TRUE;
319 compute_folder_children($curbox, $boxcount);
320}
321
322for ($i = 0;$i < count($boxes); $i++) {
323 if ( $boxes[$i]['visible'] ) {
324 $mailbox = $boxes[$i]['formatted'];
325 $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1;
326
327 /* Create the prefix for the folder name and link. */
328 $prefix = str_repeat(' ',$mblevel);
329 if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
330 $prefix = str_replace(' ','&nbsp;',substr($prefix,0,strlen($prefix)-2)).
331 create_collapse_link($i) . '&nbsp;';
332 } else {
333 $prefix = str_replace(' ','&nbsp;',$prefix);
334 }
335 $line = "<NOBR><TT>$prefix</TT>";
336
337 /* Add the folder name and link. */
338 if (in_array('noselect', $boxes[$i]['flags'])) {
339 $line .= "<FONT COLOR=\"$color[10]\">";
340 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
341 $mailbox = str_replace('&nbsp;','',$mailbox);
342 $line .= str_replace(' ', '&nbsp;', $mailbox);
2d367c68 343 }
95e93571 344 $line .= '</FONT>';
345 } else {
346 $line .= formatMailboxName($imapConnection, $boxes[$i]);
347 }
2d367c68 348
95e93571 349 /* Put the final touches on our folder line. */
350 $line .= "</NOBR><BR>\n";
2d367c68 351
95e93571 352 /* Output the line for this folder. */
353 echo $line;
2d367c68 354 }
95e93571 355}
2d367c68 356
95e93571 357sqimap_logout($imapConnection);
358do_hook('left_main_after');
2d367c68 359
95e93571 360echo "</BODY></HTML>\n";
2d367c68 361
95e93571 362?>