Nuke obsolete function general_info
[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
f43c35f8 203/**
204 * Using stristr since older preferences may contain "None" and "none".
205 */
206if (isset($left_refresh) && ($left_refresh != '') &&
207 !stristr($left_refresh, "none")){
95e93571 208 $xtra = "\n<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n" .
209 "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n".
210 "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
211} else {
212 $xtra = '';
213}
214
215displayHtmlHeader( 'SquirrelMail', $xtra );
216
217/* If requested and not yet complete, attempt to autocreate folders. */
218if ($auto_create_special && !isset($auto_create_done)) {
a3439b27 219 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
95e93571 220 foreach( $autocreate as $folder ) {
a3439b27 221 if (($folder != '') && ($folder != 'none')) {
95e93571 222 if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
223 sqimap_mailbox_create($imapConnection, $folder, '');
a3439b27 224 } else if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
95e93571 225 sqimap_subscribe($imapConnection, $folder);
2d367c68 226 }
ebf18afa 227 }
2d367c68 228 }
a6d2e0de 229
95e93571 230 /* Let the world know that autocreation is complete! Hurrah! */
90de1755 231 $auto_create_done = TRUE;
95e93571 232 session_register('auto_create_done');
233}
a6d2e0de 234
95e93571 235echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
a6d2e0de 236
95e93571 237do_hook('left_main_before');
2d367c68 238
95e93571 239$boxes = sqimap_mailbox_list($imapConnection);
2d367c68 240
95e93571 241echo '<CENTER><FONT SIZE=4><B>'. _("Folders") . "</B><BR></FONT>\n\n";
a6d2e0de 242
95e93571 243if ($date_format != 6) {
244 /* First, display the clock. */
245 if ($hour_format == 1) {
246 $hr = 'G:i';
247 if ($date_format == 4) {
248 $hr .= ':s';
a6d2e0de 249 }
95e93571 250 } else {
251 if ($date_format == 4) {
252 $hr = 'g:i:s a';
253 } else {
254 $hr = 'g:i a';
2d367c68 255 }
256 }
257
95e93571 258 switch( $date_format ) {
259 case 1:
260 $clk = date('m/d/y '.$hr, time());
261 break;
262 case 2:
263 $clk = date('d/m/y '.$hr, time());
264 break;
265 case 4:
266 case 5:
267 $clk = date($hr, time());
268 break;
269 default:
fc6f062a 270 $clk = substr( getDayName( date( 'w', time() ) ), 0, 3 ) . date( ', ' . $hr, time() );
2d367c68 271 }
95e93571 272 $clk = str_replace(' ','&nbsp;',$clk);
273
274 echo '<CENTER><SMALL>' . str_replace(' ','&nbsp;',_("Last Refresh")) .
275 ": $clk</SMALL></CENTER>";
276}
277
278/* Next, display the refresh button. */
279echo '<SMALL>(<A HREF="../src/left_main.php" TARGET="left">'.
280 _("refresh folder list") . '</A>)</SMALL></CENTER><BR>';
281
282/* Lastly, display the folder list. */
283if ( $collapse_folders ) {
284 /* If directed, collapse or uncollapse a folder. */
285 if (isset($fold)) {
286 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
287 } else if (isset($unfold)) {
288 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
289 }
290}
291
292/* Prepare do do out collapsedness and visibility computation. */
293$curbox = 0;
294$boxcount = count($boxes);
295
296/* Compute the collapsedness and visibility of each box. */
90de1755 297
95e93571 298while ($curbox < $boxcount) {
299 $boxes[$curbox]['visible'] = TRUE;
300 compute_folder_children($curbox, $boxcount);
301}
302
90de1755 303
1c52ba77 304for ($i = 0; $i < count($boxes); $i++) {
95e93571 305 if ( $boxes[$i]['visible'] ) {
306 $mailbox = $boxes[$i]['formatted'];
307 $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1;
308
309 /* Create the prefix for the folder name and link. */
310 $prefix = str_repeat(' ',$mblevel);
311 if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
312 $prefix = str_replace(' ','&nbsp;',substr($prefix,0,strlen($prefix)-2)).
313 create_collapse_link($i) . '&nbsp;';
314 } else {
315 $prefix = str_replace(' ','&nbsp;',$prefix);
316 }
317 $line = "<NOBR><TT>$prefix</TT>";
318
319 /* Add the folder name and link. */
1c52ba77 320 if (! isset($color[15])) {
05611cba 321 $color[15] = $color[6];
1c52ba77 322 }
90de1755 323
95e93571 324 if (in_array('noselect', $boxes[$i]['flags'])) {
1c52ba77 325 if( isSpecialMailbox( $boxes[$i]['unformatted']) ) {
326 $line .= "<FONT COLOR=\"$color[11]\">";
327 } else {
328 $line .= "<FONT COLOR=\"$color[15]\">";
329 }
95e93571 330 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
331 $mailbox = str_replace('&nbsp;','',$mailbox);
332 $line .= str_replace(' ', '&nbsp;', $mailbox);
2d367c68 333 }
95e93571 334 $line .= '</FONT>';
335 } else {
336 $line .= formatMailboxName($imapConnection, $boxes[$i]);
337 }
2d367c68 338
95e93571 339 /* Put the final touches on our folder line. */
340 $line .= "</NOBR><BR>\n";
2d367c68 341
95e93571 342 /* Output the line for this folder. */
343 echo $line;
2d367c68 344 }
95e93571 345}
2d367c68 346
95e93571 347do_hook('left_main_after');
76b684a5 348sqimap_logout($imapConnection);
2d367c68 349
95e93571 350echo "</BODY></HTML>\n";
2d367c68 351
7fb54066 352?>