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