~ubuntu-branches/ubuntu/hardy/squirrelmail/hardy-updates

« back to all changes in this revision

Viewing changes to src/left_main.php

  • Committer: Bazaar Package Importer
  • Author(s): Sam Johnston
  • Date: 2004-02-04 01:42:12 UTC
  • Revision ID: james.westby@ubuntu.com-20040204014212-ek9533qvd2vo1wa1
Tags: upstream-1.5.0
ImportĀ upstreamĀ versionĀ 1.5.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * left_main.php
 
5
 *
 
6
 * Copyright (c) 1999-2003 The SquirrelMail Project 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: left_main.php,v 1.184 2003/12/12 21:14:15 indiri69 Exp $
 
13
 * @package squirrelmail
 
14
 */
 
15
 
 
16
/** Path for SquirrelMail required files. */
 
17
define('SM_PATH','../');
 
18
 
 
19
/* SquirrelMail required files. */
 
20
require_once(SM_PATH . 'include/validate.php');
 
21
require_once(SM_PATH . 'functions/imap.php');
 
22
require_once(SM_PATH . 'functions/plugin.php');
 
23
require_once(SM_PATH . 'functions/page_header.php');
 
24
require_once(SM_PATH . 'functions/html.php');
 
25
require_once(SM_PATH . 'functions/date.php');
 
26
 
 
27
/* These constants are used for folder stuff. */
 
28
define('SM_BOX_UNCOLLAPSED', 0);
 
29
define('SM_BOX_COLLAPSED',   1);
 
30
 
 
31
/* --------------------- FUNCTIONS ------------------------- */
 
32
 
 
33
function formatMailboxName($imapConnection, $box_array) {
 
34
 
 
35
    global $folder_prefix, $trash_folder, $sent_folder,
 
36
           $color, $move_to_sent, $move_to_trash,
 
37
           $unseen_notify, $unseen_type, $collapse_folders,
 
38
           $draft_folder, $save_as_draft,
 
39
           $use_special_folder_color;
 
40
    $real_box = $box_array['unformatted'];
 
41
    $mailbox = str_replace('&nbsp;','',$box_array['formatted']);
 
42
    $mailboxURL = urlencode($real_box);
 
43
 
 
44
    /* Strip down the mailbox name. */
 
45
    if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
 
46
        $mailbox = $regs[2];
 
47
    }
 
48
    $unseen = 0;
 
49
    $status = array('','');
 
50
    if (($unseen_notify == 2 && $real_box == 'INBOX') ||
 
51
        $unseen_notify == 3) {
 
52
    $tmp_status = create_unseen_string($real_box, $box_array, $imapConnection, $unseen_type );
 
53
    if ($status !== false) {
 
54
        $status = $tmp_status;
 
55
    }
 
56
    }
 
57
    list($unseen_string, $unseen) = $status;
 
58
    $special_color = ($use_special_folder_color && isSpecialMailbox($real_box));
 
59
 
 
60
    /* Start off with a blank line. */
 
61
    $line = '';
 
62
 
 
63
    /* If there are unseen message, bold the line. */
 
64
    if ($unseen > 0) { $line .= '<B>'; }
 
65
 
 
66
    /* Create the link for this folder. */
 
67
    if ($status !== false) {
 
68
    $line .= '<a href="right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox='.
 
69
                $mailboxURL.'" TARGET="right" STYLE="text-decoration:none">';
 
70
    }
 
71
    if ($special_color) {
 
72
        $line .= "<font color=\"$color[11]\">";
 
73
    }
 
74
    if ( $mailbox == 'INBOX' ) {
 
75
        $line .= _("INBOX");
 
76
    } else {
 
77
        $line .= str_replace(' ','&nbsp;',$mailbox);
 
78
    }
 
79
    if ($special_color == TRUE)
 
80
        $line .= '</font>';
 
81
    if ($status !== false) {
 
82
    $line .= '</a>';
 
83
    }
 
84
 
 
85
    /* If there are unseen message, close bolding. */
 
86
    if ($unseen > 0) { $line .= "</B>"; }
 
87
 
 
88
    /* Print unseen information. */
 
89
    if ($unseen_string != '') {
 
90
        $line .= "&nbsp;<SMALL>$unseen_string</SMALL>";
 
91
    }
 
92
 
 
93
    /* If it's the trash folder, show a purge link when needed */
 
94
    if (($move_to_trash) && ($real_box == $trash_folder)) {
 
95
        if (! isset($numMessages)) {
 
96
            $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
 
97
        }
 
98
 
 
99
        if (($numMessages > 0) or ($box_array['parent'] == 1)) {
 
100
            $urlMailbox = urlencode($real_box);
 
101
            $line .= "\n<small>\n" .
 
102
                    "&nbsp;&nbsp;(<A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A>)" .
 
103
                    "</small>";
 
104
        } else {
 
105
           $line .= concat_hook_function('left_main_after_each_folder',
 
106
                  array(isset($numMessages) ? $numMessages : '',$real_box,$imapConnection));
 
107
        }
 
108
    }
 
109
 
 
110
    /* Return the final product. */
 
111
    return ($line);
 
112
}
 
113
 
 
114
/**
 
115
 * Recursive function that computes the collapsed status and parent
 
116
 * (or not parent) status of this box, and the visiblity and collapsed
 
117
 * status and parent (or not parent) status for all children boxes.
 
118
 */
 
119
function compute_folder_children(&$parbox, $boxcount) {
 
120
    global $boxes, $data_dir, $username, $collapse_folders;
 
121
    $nextbox = $parbox + 1;
 
122
 
 
123
    /* Retreive the name for the parent box. */
 
124
    $parbox_name = $boxes[$parbox]['unformatted'];
 
125
 
 
126
    /* 'Initialize' this parent box to childless. */
 
127
    $boxes[$parbox]['parent'] = FALSE;
 
128
 
 
129
    /* Compute the collapse status for this box. */
 
130
    if( isset($collapse_folders) && $collapse_folders ) {
 
131
        $collapse = getPref($data_dir, $username, 'collapse_folder_' . $parbox_name);
 
132
        $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
 
133
    } else {
 
134
        $collapse = SM_BOX_UNCOLLAPSED;
 
135
    }
 
136
    $boxes[$parbox]['collapse'] = $collapse;
 
137
 
 
138
    /* Otherwise, get the name of the next box. */
 
139
    if (isset($boxes[$nextbox]['unformatted'])) {
 
140
        $nextbox_name = $boxes[$nextbox]['unformatted'];
 
141
    } else {
 
142
        $nextbox_name = '';
 
143
    }
 
144
 
 
145
    /* Compute any children boxes for this box. */
 
146
    while (($nextbox < $boxcount) &&
 
147
           (is_parent_box($boxes[$nextbox]['unformatted'], $parbox_name))) {
 
148
 
 
149
        /* Note that this 'parent' box has at least one child. */
 
150
        $boxes[$parbox]['parent'] = TRUE;
 
151
 
 
152
        /* Compute the visiblity of this box. */
 
153
        $boxes[$nextbox]['visible'] = ($boxes[$parbox]['visible'] &&
 
154
                                       ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED));
 
155
 
 
156
        /* Compute the visibility of any child boxes. */
 
157
        compute_folder_children($nextbox, $boxcount);
 
158
    }
 
159
 
 
160
    /* Set the parent box to the current next box. */
 
161
    $parbox = $nextbox;
 
162
}
 
163
 
 
164
/**
 
165
 * Create the link for a parent folder that will allow that
 
166
 * parent folder to either be collapsed or expaned, as is
 
167
 * currently appropriate.
 
168
 */
 
169
function create_collapse_link($boxnum) {
 
170
    global $boxes, $imapConnection, $unseen_notify, $color;
 
171
    $mailbox = urlencode($boxes[$boxnum]['unformatted']);
 
172
 
 
173
    /* Create the link for this collapse link. */
 
174
    $link = '<a target="left" style="text-decoration:none" ' .
 
175
            'href="left_main.php?';
 
176
    if ($boxes[$boxnum]['collapse'] == SM_BOX_COLLAPSED) {
 
177
        $link .= "unfold=$mailbox\">+";
 
178
    } else {
 
179
        $link .= "fold=$mailbox\">-";
 
180
    }
 
181
    $link .= '</a>';
 
182
 
 
183
    $hooklink = do_hook_function('create_collapse_link',$link);
 
184
    if ($hooklink != '')
 
185
        $link = $hooklink;
 
186
 
 
187
    /* Return the finished product. */
 
188
    return ($link);
 
189
}
 
190
 
 
191
/**
 
192
 * create_unseen_string:
 
193
 *
 
194
 * Create unseen and total message count for both this folder and
 
195
 * it's subfolders.
 
196
 *
 
197
 * @param string $boxName name of the current mailbox
 
198
 * @param array $boxArray array for the current mailbox
 
199
 * @param $imapConnection current imap connection in use
 
200
 * @return array unseen message string (for display), unseen message count
 
201
 */
 
202
function create_unseen_string($boxName, $boxArray, $imapConnection, $unseen_type) {
 
203
    global $boxes, $unseen_type, $color, $unseen_cum;
 
204
 
 
205
    /* Initialize the return value. */
 
206
    $result = array(0,0);
 
207
 
 
208
    /* Initialize the counts for this folder. */
 
209
    $boxUnseenCount = 0;
 
210
    $boxMessageCount = 0;
 
211
    $totalUnseenCount = 0;
 
212
    $totalMessageCount = 0;
 
213
 
 
214
    /* Collect the counts for this box alone. */
 
215
    $status = sqimap_status_messages($imapConnection, $boxName);
 
216
    $boxUnseenCount = $status['UNSEEN'];
 
217
    if ($boxUnseenCount === false) {
 
218
    return false;
 
219
    }
 
220
    if ($unseen_type == 2) {
 
221
        $boxMessageCount = $status['MESSAGES'];
 
222
    }
 
223
 
 
224
    /* Initialize the total counts. */
 
225
 
 
226
    if ($boxArray['collapse'] == SM_BOX_COLLAPSED && $unseen_cum) {
 
227
        /* Collect the counts for this boxes subfolders. */
 
228
        $curBoxLength = strlen($boxName);
 
229
        $boxCount = count($boxes);
 
230
 
 
231
        for ($i = 0; $i < $boxCount; ++$i) {
 
232
            /* Initialize the counts for this subfolder. */
 
233
            $subUnseenCount = 0;
 
234
            $subMessageCount = 0;
 
235
 
 
236
            /* Collect the counts for this subfolder. */
 
237
            if (($boxName != $boxes[$i]['unformatted'])
 
238
                   && (substr($boxes[$i]['unformatted'], 0, $curBoxLength) == $boxName)
 
239
                   && !in_array('noselect', $boxes[$i]['flags'])) {
 
240
        $status = sqimap_status_messages($imapConnection, $boxes[$i]['unformatted']);
 
241
        $subUnseenCount = $status['UNSEEN'];
 
242
                if ($unseen_type == 2) {
 
243
                    $subMessageCount = $status['MESSAGES'];;
 
244
                }
 
245
                /* Add the counts for this subfolder to the total. */
 
246
                $totalUnseenCount += $subUnseenCount;
 
247
                $totalMessageCount += $subMessageCount;
 
248
            }
 
249
        }
 
250
 
 
251
        /* Add the counts for all subfolders to that of the box. */
 
252
        $boxUnseenCount += $totalUnseenCount;
 
253
        $boxMessageCount += $totalMessageCount;
 
254
    }
 
255
 
 
256
    /* And create the magic unseen count string.     */
 
257
    /* Really a lot more then just the unseen count. */
 
258
    if (($unseen_type == 1) && ($boxUnseenCount > 0)) {
 
259
        $result[0] = "($boxUnseenCount)";
 
260
    } else if ($unseen_type == 2) {
 
261
        $result[0] = "($boxUnseenCount/$boxMessageCount)";
 
262
        $result[0] = "<font color=\"$color[11]\">$result[0]</font>";
 
263
    }
 
264
 
 
265
    /* Set the unseen count to return to the outside world. */
 
266
    $result[1] = $boxUnseenCount;
 
267
 
 
268
    /* Return our happy result. */
 
269
    return ($result);
 
270
}
 
271
 
 
272
/**
 
273
 * This simple function checks if a box is another box's parent.
 
274
 */
 
275
function is_parent_box($curbox_name, $parbox_name) {
 
276
    global $delimiter;
 
277
 
 
278
    /* Extract the name of the parent of the current box. */
 
279
    $curparts = explode($delimiter, $curbox_name);
 
280
    $curname = array_pop($curparts);
 
281
    $actual_parname = implode($delimiter, $curparts);
 
282
    $actual_parname = substr($actual_parname,0,strlen($parbox_name));
 
283
 
 
284
    /* Compare the actual with the given parent name. */
 
285
    return ($parbox_name == $actual_parname);
 
286
}
 
287
 
 
288
function ListBoxes ($boxes, $j=0 ) {
 
289
    global $data_dir, $username, $startmessage, $color, $unseen_notify, $unseen_type,
 
290
           $move_to_trash, $trash_folder, $collapse_folders, $imapConnection;
 
291
 
 
292
    if (!isset($boxes) || empty($boxes))
 
293
        return;
 
294
 
 
295
    $pre = '<nobr>';
 
296
    $end = '';
 
297
    $collapse = false;
 
298
    $unseen_found = false;
 
299
    $unseen = 0;
 
300
 
 
301
    $mailbox = $boxes->mailboxname_full;
 
302
    $leader = '<tt>';
 
303
    $leader .= str_repeat('&nbsp;&nbsp;',$j);
 
304
    $mailboxURL = urlencode($mailbox);
 
305
 
 
306
    /* get unseen/total messages information */
 
307
    /* Only need to display info when option is set */
 
308
    if (isset($unseen_notify) && ($unseen_notify > 1) &&
 
309
        (($boxes->unseen !== false) || ($boxes->total !== false))) {
 
310
 
 
311
        if ($boxes->unseen !== false)
 
312
            $unseen = $boxes->unseen;
 
313
 
 
314
        /*
 
315
            Should only display unseen info if the folder is inbox
 
316
            or you set the option for all folders
 
317
        */
 
318
 
 
319
        if ((strtolower($mailbox) == 'inbox') || ($unseen_notify == 3)) {
 
320
            $unseen_string = $unseen;
 
321
 
 
322
            /* If users requests, display message count too */
 
323
            if (isset($unseen_type) && ($unseen_type == 2) && ($boxes->total !== false)) {
 
324
                $unseen_string .= '/' . $boxes->total;
 
325
            }
 
326
 
 
327
            $unseen_string = "<font color=\"$color[11]\">($unseen_string)</font>";
 
328
 
 
329
            /*
 
330
                Finally allow the script to display the values by setting a boolean.
 
331
                This can only occur if the unseen count is great than 0 (if you have
 
332
                unseen count only), or you have the message count too.
 
333
            */
 
334
            if (($unseen > 0) || (isset($unseen_type) && ($unseen_type ==2))) {
 
335
                $unseen_found = true;
 
336
            }
 
337
        }
 
338
    }
 
339
 
 
340
    if (isset($boxes->mbxs[0]) && $collapse_folders) {
 
341
        $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
 
342
        $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
 
343
 
 
344
        $link = '<a target="left" style="text-decoration:none" ' .'href="left_main.php?';
 
345
        if ($collapse) {
 
346
            $link .= "unfold=$mailboxURL\">$leader+&nbsp;</tt>";
 
347
        } else {
 
348
            $link .= "fold=$mailboxURL\">$leader-&nbsp;</tt>";
 
349
        }
 
350
        $link .= '</a>';
 
351
        $pre .= $link;
 
352
    } else {
 
353
        $pre.= $leader . '&nbsp;&nbsp;</tt>';
 
354
    }
 
355
 
 
356
    /* If there are unseen message, bold the line. */
 
357
    if (($move_to_trash) && ($mailbox == $trash_folder)) {
 
358
        if (! isset($boxes->total)) {
 
359
            $boxes->total = sqimap_status_messages($imapConnection, $mailbox);
 
360
        }
 
361
        if ($unseen > 0) {
 
362
            $pre .= '<b>';
 
363
        }
 
364
        $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;sort=0;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
 
365
        if ($unseen > 0) {
 
366
            $end .= '</b>';
 
367
        }
 
368
        $end .= '</a>';
 
369
        if ($boxes->total > 0) {
 
370
            if ($unseen > 0) {
 
371
                $pre .= '<b>';
 
372
            }
 
373
            $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;sort=0;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
 
374
            if ($unseen > 0) {
 
375
                $end .= '</b>';
 
376
            }
 
377
            /* Print unseen information. */
 
378
            if ($unseen_found) {
 
379
                $end .= "&nbsp;<small>$unseen_string</small>";
 
380
            }
 
381
            $end .= "\n<small>\n" .
 
382
                    "&nbsp;&nbsp;(<a href=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</a>)" .
 
383
                    "</small>";
 
384
        }
 
385
    } else {
 
386
        if (!$boxes->is_noselect) {
 
387
            if ($unseen > 0) {
 
388
                $pre .= '<b>';
 
389
            }
 
390
            $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
 
391
            if ($unseen > 0) {
 
392
                $end .= '</b>';
 
393
            }
 
394
            $end .= '</a>';
 
395
        }
 
396
        /* Print unseen information. */
 
397
        if ($unseen_found) {
 
398
            $end .= "&nbsp;<small>$unseen_string</small>";
 
399
        }
 
400
 
 
401
    }
 
402
 
 
403
    $font = '';
 
404
    $fontend = '';
 
405
    if ($boxes->is_special) {
 
406
        $font = "<font color=\"$color[11]\">";
 
407
        $fontend = "</font>";
 
408
    }
 
409
    $end .= '</nobr>';
 
410
 
 
411
    if (!$boxes->is_root) {
 
412
        echo "" . $pre .$font. $boxes->mailboxname_sub .$fontend . $end. '<br />' . "\n";
 
413
        $j++;
 
414
    }
 
415
 
 
416
    if (!$collapse || $boxes->is_root) {
 
417
        for ($i = 0; $i <count($boxes->mbxs); $i++) {
 
418
            listBoxes($boxes->mbxs[$i],$j);
 
419
        }
 
420
    }
 
421
}
 
422
 
 
423
function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) {
 
424
    global $data_dir, $username, $startmessage, $color, $unseen_notify, $unseen_type,
 
425
           $move_to_trash, $trash_folder, $collapse_folders;
 
426
 
 
427
    if (!isset($boxes) || empty($boxes))
 
428
        return;
 
429
 
 
430
    /* use_folder_images only works if the images exist in ../images */
 
431
    $use_folder_images = true;
 
432
 
 
433
    $pre = '';
 
434
    $end = '';
 
435
    $collapse = false;
 
436
    $unseen_found = false;
 
437
    $unseen = 0;
 
438
 
 
439
    $mailbox = $boxes->mailboxname_full;
 
440
    $mailboxURL = urlencode($mailbox);
 
441
 
 
442
    /* get unseen/total messages information */
 
443
    /* Only need to display info when option is set */
 
444
    if (isset($unseen_notify) && ($unseen_notify > 1) &&
 
445
        (($boxes->unseen !== false) || ($boxes->total !== false))) {
 
446
 
 
447
        if ($boxes->unseen !== false)
 
448
            $unseen = $boxes->unseen;
 
449
 
 
450
        /*
 
451
            Should only display unseen info if the folder is inbox
 
452
            or you set the option for all folders
 
453
        */
 
454
 
 
455
        if ((strtolower($mailbox) == 'inbox') || ($unseen_notify == 3)) {
 
456
            $unseen_string = $unseen;
 
457
 
 
458
            /* If users requests, display message count too */
 
459
            if (isset($unseen_type) && ($unseen_type == 2) && ($boxes->total !== false)) {
 
460
                $unseen_string .= '/' . $boxes->total;
 
461
            }
 
462
 
 
463
            $unseen_string = "<font color=\"$color[11]\">($unseen_string)</font>";
 
464
 
 
465
            /*
 
466
                Finally allow the script to display the values by setting a boolean.
 
467
                This can only occur if the unseen count is great than 0 (if you have
 
468
                unseen count only), or you have the message count too.
 
469
            */
 
470
            if (($unseen > 0) || (isset($unseen_type) && ($unseen_type ==2))) {
 
471
                $unseen_found = true;
 
472
            }
 
473
        }
 
474
    }
 
475
 
 
476
    /* If there are unseen message, bold the line. */
 
477
    if ($unseen > 0) { $pre .= '<b>'; }
 
478
 
 
479
    /* color special boxes */
 
480
    if ($boxes->is_special) {
 
481
        $pre .= "<font color=\"$color[11]\">";
 
482
        $end .= '</font>';
 
483
    }
 
484
 
 
485
    /* If there are unseen message, close bolding. */
 
486
    if ($unseen > 0) { $end .= '</b>'; }
 
487
 
 
488
    /* Print unseen information. */
 
489
    if ($unseen_found) {
 
490
        $end .= "&nbsp;$unseen_string";
 
491
    }
 
492
 
 
493
    if (($move_to_trash) && ($mailbox == $trash_folder)) {
 
494
        if (! isset($numMessages)) {
 
495
            $numMessages = $boxes->total;
 
496
        }
 
497
        $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\">" . $pre;
 
498
        $end .= '</a>';
 
499
        if ($numMessages > 0) {
 
500
            $urlMailbox = urlencode($mailbox);
 
501
            $end .= "\n<small>\n" .
 
502
                    "&nbsp;&nbsp;(<a class=\"mbx_link\" href=\"empty_trash.php\">"._("purge")."</a>)" .
 
503
                    "</small>";
 
504
        }
 
505
    } else {
 
506
        if (!$boxes->is_noselect) { /* \Noselect boxes can't be selected */
 
507
            $pre = "<a class=\"mbx_link\" href=\"right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox=$mailboxURL\" target=\"right\">" . $pre;
 
508
            $end .= '</a>';
 
509
        }
 
510
    }
 
511
 
 
512
    if (!$boxes->is_root) {
 
513
        if ($use_folder_images) {
 
514
            if ($boxes->is_inbox) {
 
515
                $folder_img = '../images/inbox.png';
 
516
            } else if ($boxes->is_sent) {
 
517
                $folder_img = '../images/senti.png';
 
518
            } else if ($boxes->is_trash) {
 
519
                $folder_img = '../images/delitem.png';
 
520
            } else if ($boxes->is_draft) {
 
521
                $folder_img = '../images/draft.png';
 
522
            } else if ($boxes->is_noinferiors) {
 
523
                $folder_img = '../images/folder_noinf.png';
 
524
            } else {
 
525
                $folder_img = '../images/folder.png';
 
526
            }
 
527
            $folder_img = '&nbsp;<img src="'.$folder_img.'" height="15" valign="center" />&nbsp;';
 
528
        } else {
 
529
            $folder_img = '';
 
530
        }
 
531
        if (!isset($boxes->mbxs[0])) {
 
532
            echo '   ' . html_tag( 'div',
 
533
                            '<tt>'. $pre . $folder_img . '</tt>'. $boxes->mailboxname_sub . $end,
 
534
                            'left', '', 'class="mbx_sub" id="' .$j. '"' ) . "\n";
 
535
        } else {
 
536
            /* get collapse information */
 
537
            if ($collapse_folders) {
 
538
                $form_entry = $j.'F';
 
539
                if (isset($mbx) && isset($mbx[$form_entry])) {
 
540
                    $collapse = $mbx[$form_entry];
 
541
                    setPref($data_dir, $username, 'collapse_folder_'.$boxes->mailboxname_full , $collapse ? SM_BOX_COLLAPSED : SM_BOX_UNCOLLAPSED);
 
542
                } else {
 
543
                    $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox);
 
544
                    $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
 
545
                }
 
546
                $img_src = ($collapse ? '../images/plus.png' : '../images/minus.png');
 
547
                $collapse_link = '<a href="javascript:void(0)">'." <img src=\"$img_src\" border=\"1\" id=$j onclick=\"hidechilds(this)\" style=\"cursor:hand\" /></a>";
 
548
            } else {
 
549
                 $collapse_link='';
 
550
            }
 
551
            echo '   ' . html_tag( 'div',
 
552
                            $collapse_link . $pre . $folder_img . '&nbsp;'. $boxes->mailboxname_sub . $end ,
 
553
                            'left', '', 'class="mbx_par" id="' .$j. 'P"' ) . "\n";
 
554
            echo '   <input type="hidden" name="mbx['.$j. 'F]" value="'.$collapse.'" id="mbx['.$j.'F]" />'."\n";
 
555
        }
 
556
    }
 
557
 
 
558
    $visible = ($collapse ? ' style="display:none"' : ' style="display:block"');
 
559
    if (isset($boxes->mbxs[0]) && !$boxes->is_root) /* mailbox contains childs */
 
560
        echo html_tag( 'div', '', 'left', '', 'class="par_area" id='.$j.'.0000 '. $visible ) . "\n";
 
561
 
 
562
    if ($j !='ID.0000')
 
563
       $j = $j .'.0000';
 
564
    for ($i = 0; $i <count($boxes->mbxs); $i++) {
 
565
        $j++;
 
566
        ListAdvancedBoxes($boxes->mbxs[$i],$mbx,$j);
 
567
    }
 
568
    if (isset($boxes->mbxs[0]) && !$boxes->is_root)
 
569
        echo '</div>'."\n\n";
 
570
}
 
571
 
 
572
 
 
573
 
 
574
 
 
575
/* -------------------- MAIN ------------------------ */
 
576
 
 
577
/* get globals */
 
578
sqgetGlobalVar('username', $username, SQ_SESSION);
 
579
sqgetGlobalVar('key', $key, SQ_COOKIE);
 
580
sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
 
581
sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
 
582
 
 
583
sqgetGlobalVar('fold', $fold, SQ_GET);
 
584
sqgetGlobalVar('unfold', $unfold, SQ_GET);
 
585
 
 
586
/* end globals */
 
587
 
 
588
// open a connection on the imap port (143)
 
589
$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
 
590
 
 
591
/**
 
592
 * Using stristr since older preferences may contain "None" and "none".
 
593
 */
 
594
if (isset($left_refresh) && ($left_refresh != '') &&
 
595
    !stristr($left_refresh, 'none')){
 
596
    $xtra =  "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\" />\n" .
 
597
             "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n".
 
598
             "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
 
599
} else {
 
600
    $xtra = '';
 
601
}
 
602
 
 
603
/**
 
604
 * $advanced_tree and $oldway are boolean vars which are default set to default
 
605
 * SM behaviour.
 
606
 * Setting $oldway to false causes left_main.php to use the new experimental
 
607
 * way of getting the mailbox-tree.
 
608
 * Setting $advanced tree to true causes SM to display a experimental
 
609
 * mailbox-tree with dhtml behaviour.
 
610
 * It only works on browsers which supports css and javascript. The used
 
611
 * javascript is experimental and doesn't support all browsers.
 
612
 * It has been tested on IE6 an Konquerer 3.0.0-2.
 
613
 * It is now tested and working on: (please test and update this list)
 
614
 * Windows: IE 5.5 SP2, IE 6 SP1, Gecko based (Mozilla, Firebird) and Opera7
 
615
 * XWindow: ?
 
616
 * Mac: ?
 
617
 * In the function ListAdvancedBoxes there is another var $use_folder_images.
 
618
 * setting this to true is only usefull if the images exists in ../images.
 
619
 *
 
620
 * Feel free to experiment with the code and report bugs and enhancements
 
621
 * to marc@its-projects.nl
 
622
 **/
 
623
 
 
624
/* set this to true if you want to see a nicer mailboxtree */
 
625
if (! isset($advanced_tree) || $advanced_tree=="" ) {
 
626
    $advanced_tree=false;
 
627
}
 
628
/* default SM behaviour */
 
629
if (! isset($oldway) || $oldway=="" ) {
 
630
    $oldway=false;
 
631
}
 
632
 
 
633
if ($advanced_tree) {
 
634
$xtra .= <<<ECHO
 
635
<script language="Javascript" TYPE="text/javascript">
 
636
 
 
637
<!--
 
638
 
 
639
    function preload() {
 
640
      if (document.images) {
 
641
        var treeImages = new Array;
 
642
        var arguments = preload.arguments;
 
643
        for (var i = 0; i<arguments.length; i++) {
 
644
          treeImages[i] = new Image();
 
645
          treeImages[i].src = arguments[i];
 
646
        }
 
647
      }
 
648
    }
 
649
 
 
650
var vTreeImg;
 
651
var vTreeDiv;
 
652
var vTreeSrc;
 
653
 
 
654
    function fTreeTimeout() {
 
655
      if (vTreeDiv.readyState == "complete")
 
656
        vTreeImg.src = vTreeSrc;
 
657
      else
 
658
        setTimeout("fTreeTimeout()", 100);
 
659
    }
 
660
 
 
661
    function hidechilds(img) {
 
662
      id = img.id + ".0000";
 
663
      form_id = "mbx[" + img.id +"F]";
 
664
      if (document.all) {       //IE, Opera7
 
665
        div = document.all[id];
 
666
        if (div) {
 
667
           if (div.style.display == "none") {
 
668
              vTreeSrc = "../images/minus.png";
 
669
              style = "block";
 
670
              value = 0;
 
671
           }
 
672
           else {
 
673
              vTreeSrc = "../images/plus.png";
 
674
              style = "none";
 
675
              value = 1;
 
676
           }
 
677
           vTreeImg = img;
 
678
           vTreeDiv = div;
 
679
           if (typeof vTreeDiv.readyState != "undefined")       //IE
 
680
              setTimeout("fTreeTimeout()",100);
 
681
           else //Non IE
 
682
              vTreeImg.src = vTreeSrc;
 
683
           div.style.display = style;
 
684
           document.all[form_id].value = value;
 
685
        }
 
686
      }
 
687
      else if (document.getElementById) {       //Gecko
 
688
        div = document.getElementById(id);
 
689
        if (div) {
 
690
           if (div.style.display == "none") {
 
691
              src = "../images/minus.png";
 
692
              style = "block";
 
693
              value = 0;
 
694
           }
 
695
           else {
 
696
              src = "../images/plus.png";
 
697
              style = "none";
 
698
              value = 1;
 
699
           }
 
700
           div.style.display = style;
 
701
           img.src = src;
 
702
           document.getElementById(form_id).value = value;
 
703
        }
 
704
      }
 
705
    }
 
706
 
 
707
   function buttonover(el,on) {
 
708
      if (!on) {
 
709
//         el.style.borderColor="$color[9]";}
 
710
         el.style.background="$color[0]";}
 
711
      else {
 
712
         el.style.background="$color[9]";}
 
713
   }
 
714
 
 
715
   function buttonclick(el,on) {
 
716
      if (!on) {
 
717
         el.style.border="groove";}
 
718
      else {
 
719
         el.style.border="ridge";}
 
720
   }
 
721
 
 
722
   function hideframe(hide) {
 
723
 
 
724
ECHO;
 
725
$xtra .= "      left_size = \"$left_size\";\n";
 
726
$xtra .= <<<ECHO
 
727
      if (document.all) {
 
728
        masterf = window.parent.document.all["fs1"];
 
729
    leftf = window.parent.document.all["left"];
 
730
    leftcontent = document.all["leftframe"];
 
731
    leftbutton = document.all["showf"];
 
732
      } else if (document.getElementById) {
 
733
    masterf = window.parent.document.getElementById("fs1");
 
734
    leftf = window.parent.document.getElementById("left");
 
735
    leftcontent = document.getElementById("leftframe");
 
736
    leftbutton = document.getElementById("showf");
 
737
      } else {
 
738
        return false;
 
739
      }
 
740
      if(hide) {
 
741
         new_col = calc_col("20");
 
742
         masterf.cols = new_col;
 
743
     document.body.scrollLeft=0;
 
744
     document.body.style.overflow='hidden';
 
745
     leftcontent.style.display = 'none';
 
746
     leftbutton.style.display='block';
 
747
      } else {
 
748
         masterf.cols = calc_col(left_size);
 
749
     document.body.style.overflow='';
 
750
     leftbutton.style.display='none';
 
751
     leftcontent.style.display='block';
 
752
 
 
753
      }
 
754
   }
 
755
 
 
756
   function calc_col(c_w) {
 
757
 
 
758
ECHO;
 
759
   if ($location_of_bar == 'right') {
 
760
       $xtra .= '     right=true;';
 
761
   } else {
 
762
       $xtra .= '     right=false;';
 
763
   }
 
764
   $xtra .= "\n";
 
765
$xtra .= <<<ECHO
 
766
     if (right) {
 
767
         new_col = '*,'+c_w;
 
768
     } else {
 
769
         new_col = c_w+',*';
 
770
     }
 
771
     return new_col;
 
772
   }
 
773
 
 
774
   function resizeframe(direction) {
 
775
     if (document.all) {
 
776
        masterf = window.parent.document.all["fs1"];
 
777
     } else if (document.getElementById) {
 
778
    window.parent.document.getElementById("fs1");
 
779
     } else {
 
780
        return false;
 
781
     }
 
782
 
 
783
ECHO;
 
784
   if ($location_of_bar == 'right') {
 
785
       $xtra .= '  colPat=/^\*,(\d+)$/;';
 
786
   } else {
 
787
       $xtra .= '  colPat=/^(\d+),.*$/;';
 
788
   }
 
789
   $xtra .= "\n";
 
790
 
 
791
$xtra .= <<<ECHO
 
792
     old_col = masterf.cols;
 
793
     colPat.exec(old_col);
 
794
 
 
795
     if (direction) {
 
796
        new_col_width = parseInt(RegExp.$1) + 25;
 
797
 
 
798
     } else {
 
799
        if (parseInt(RegExp.$1) > 35) {
 
800
           new_col_width = parseInt(RegExp.$1) - 25;
 
801
        }
 
802
     }
 
803
     masterf.cols = calc_col(new_col_width);
 
804
   }
 
805
 
 
806
//-->
 
807
 
 
808
</script>
 
809
 
 
810
ECHO;
 
811
 
 
812
/* style definitions */
 
813
 
 
814
$xtra .= <<<ECHO
 
815
 
 
816
<style type="text/css">
 
817
<!--
 
818
  body {
 
819
     margin: 0px 0px 0px 0px;
 
820
     padding: 5px 5px 5px 5px;
 
821
  }
 
822
 
 
823
  .button {
 
824
     border:outset;
 
825
     border-color: $color[9];
 
826
     background:$color[0];
 
827
     color:$color[6];
 
828
     width:99%;
 
829
     heigth:99%;
 
830
  }
 
831
 
 
832
  .mbx_par {
 
833
     font-size:1.0em;
 
834
     margin-left:4px;
 
835
     margin-right:0px;
 
836
  }
 
837
 
 
838
  a.mbx_link {
 
839
      text-decoration: none;
 
840
      background-color: $color[0];
 
841
      display: inline;
 
842
  }
 
843
 
 
844
  a:hover.mbx_link {
 
845
      background-color: $color[9];
 
846
  }
 
847
 
 
848
  a.mbx_link img {
 
849
      border-style: none;
 
850
  }
 
851
 
 
852
  .mbx_sub {
 
853
     padding-left:5px;
 
854
     padding-right:0px;
 
855
     margin-left:4px;
 
856
     margin-right:0px;
 
857
     font-size:0.9em;
 
858
  }
 
859
 
 
860
  .par_area {
 
861
     margin-top:0px;
 
862
     margin-left:4px;
 
863
     margin-right:0px;
 
864
     padding-left:10px;
 
865
     padding-bottom:5px;
 
866
     border-left: solid;
 
867
     border-left-width:0.1em;
 
868
     border-left-color:$color[9];
 
869
     border-bottom: solid;
 
870
     border-bottom-width:0.1em;
 
871
     border-bottom-color:$color[9];
 
872
     display: block;
 
873
  }
 
874
 
 
875
  .mailboxes {
 
876
     padding-bottom:3px;
 
877
     margin-right:4px;
 
878
     padding-right:4px;
 
879
     margin-left:4px;
 
880
     padding-left:4px;
 
881
     border: groove;
 
882
     border-width:0.1em;
 
883
     border-color:$color[9];
 
884
     background: $color[0];
 
885
  }
 
886
 
 
887
-->
 
888
 
 
889
</style>
 
890
 
 
891
ECHO;
 
892
 
 
893
}
 
894
 
 
895
displayHtmlHeader( 'SquirrelMail', $xtra );
 
896
 
 
897
/* If requested and not yet complete, attempt to autocreate folders. */
 
898
if ($auto_create_special && !isset($auto_create_done)) {
 
899
    $autocreate = array($sent_folder, $trash_folder, $draft_folder);
 
900
    foreach( $autocreate as $folder ) {
 
901
        if (($folder != '') && ($folder != 'none')) {
 
902
            if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
 
903
                sqimap_mailbox_create($imapConnection, $folder, '');
 
904
            } else if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
 
905
                sqimap_subscribe($imapConnection, $folder);
 
906
            }
 
907
        }
 
908
    }
 
909
 
 
910
    /* Let the world know that autocreation is complete! Hurrah! */
 
911
    $auto_create_done = TRUE;
 
912
    sqsession_register($auto_create_done, 'auto_create_done');
 
913
}
 
914
 
 
915
if ($advanced_tree)
 
916
  echo "\n<body" .
 
917
        ' onload="preload(\'../images/minus.png\',\'../images/plus.png\')"' .
 
918
  " bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
 
919
else
 
920
  echo "\n<body bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
 
921
 
 
922
do_hook('left_main_before');
 
923
if ($advanced_tree) {
 
924
   /* nice future feature, needs layout !! volunteers?   */
 
925
   $right_pos = $left_size - 20;
 
926
/*   echo '<div style="position:absolute;top:0;border=solid;border-width:0.1em;border-color:blue;"><div ID="hidef" style="width=20;font-size:12"><A HREF="javascript:hideframe(true)"><b><<</b></a></div>';
 
927
   echo '<div ID="showf" style="width=20;font-size:12;display:none;"><a href="javascript:hideframe(false)"><b>>></b></a></div>';
 
928
   echo '<div ID="incrf" style="width=20;font-size:12"><a href="javascript:resizeframe(true)"><b>></b></a></div>';
 
929
   echo '<div ID="decrf" style="width=20;font-size:12"><a href="javascript:resizeframe(false)"><b><</b></a></div></div>';
 
930
   echo '<div ID="leftframe"><br /><br />';*/
 
931
}
 
932
 
 
933
echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) .
 
934
    html_tag( 'tr' ) .
 
935
    html_tag( 'td', '', 'left' ) .
 
936
    '<center><font size="4"><b>'. _("Folders") . "</b><br /></font>\n\n";
 
937
 
 
938
if ($date_format != 6) {
 
939
    /* First, display the clock. */
 
940
    if ($hour_format == 1) {
 
941
        $hr = 'G:i';
 
942
        if ($date_format == 4) {
 
943
            $hr .= ':s';
 
944
        }
 
945
    } else {
 
946
        if ($date_format == 4) {
 
947
            $hr = 'g:i:s a';
 
948
        } else {
 
949
            $hr = 'g:i a';
 
950
        }
 
951
    }
 
952
 
 
953
    switch( $date_format ) {
 
954
    case 1:
 
955
        $clk = date('m/d/y '.$hr, time());
 
956
        break;
 
957
    case 2:
 
958
        $clk = date('d/m/y '.$hr, time());
 
959
        break;
 
960
    case 4:
 
961
    case 5:
 
962
        $clk = date($hr, time());
 
963
        break;
 
964
    default:
 
965
        $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
 
966
    }
 
967
    $clk = str_replace(' ','&nbsp;',$clk);
 
968
 
 
969
    echo '<center><small>' . str_replace(' ','&nbsp;',_("Last Refresh")) .
 
970
         ": $clk</small></center>";
 
971
}
 
972
 
 
973
/* Next, display the refresh button. */
 
974
echo '<small>(<a href="../src/left_main.php" target="left">'.
 
975
     _("refresh folder list") . '</a>)</small></center><br />';
 
976
 
 
977
/* Lastly, display the folder list. */
 
978
if ( $collapse_folders ) {
 
979
    /* If directed, collapse or uncollapse a folder. */
 
980
    if (isset($fold)) {
 
981
        setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
 
982
    } else if (isset($unfold)) {
 
983
        setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
 
984
    }
 
985
}
 
986
 
 
987
/* Get unseen/total display prefs */
 
988
$unseen_type = getPref( $data_dir , $username , 'unseen_type' );
 
989
$unseen_notify = getPref( $data_dir , $username , 'unseen_notify' );
 
990
 
 
991
if (!isset($unseen_type) || empty($unseen_type)) {
 
992
    if (isset($default_unseen_type) && !empty($default_unseen_type)) {
 
993
        $unseen_type = $default_unseen_type;
 
994
    } else {
 
995
        $unseen_type = 1;
 
996
    }
 
997
}
 
998
 
 
999
if (!isset($unseen_notify) || empty($unseen_notify)) {
 
1000
    if (isset($default_unseen_notify) && !empty($default_unseen_notify)) {
 
1001
        $unseen_notify = $default_unseen_notify;
 
1002
    } else {
 
1003
        $unseen_notify = 0;
 
1004
    }
 
1005
}
 
1006
 
 
1007
if ($oldway) {  /* normal behaviour SM */
 
1008
 
 
1009
$boxes = sqimap_mailbox_list($imapConnection);
 
1010
/* Prepare do do out collapsedness and visibility computation. */
 
1011
$curbox = 0;
 
1012
$boxcount = count($boxes);
 
1013
 
 
1014
/* Compute the collapsedness and visibility of each box. */
 
1015
 
 
1016
while ($curbox < $boxcount) {
 
1017
    $boxes[$curbox]['visible'] = TRUE;
 
1018
    compute_folder_children($curbox, $boxcount);
 
1019
}
 
1020
 
 
1021
for ($i = 0; $i < count($boxes); $i++) {
 
1022
    if ( $boxes[$i]['visible'] ) {
 
1023
        $mailbox = $boxes[$i]['formatted'];
 
1024
        $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1;
 
1025
 
 
1026
        /* Create the prefix for the folder name and link. */
 
1027
        $prefix = str_repeat('  ',$mblevel);
 
1028
        if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
 
1029
            $prefix = str_replace(' ','&nbsp;',substr($prefix,0,strlen($prefix)-2)).
 
1030
                      create_collapse_link($i) . '&nbsp;';
 
1031
        } else {
 
1032
            $prefix = str_replace(' ','&nbsp;',$prefix);
 
1033
        }
 
1034
        $line = "<nobr><tt>$prefix</tt>";
 
1035
 
 
1036
        /* Add the folder name and link. */
 
1037
        if (! isset($color[15])) {
 
1038
            $color[15] = $color[6];
 
1039
        }
 
1040
 
 
1041
        if (in_array('noselect', $boxes[$i]['flags'])) {
 
1042
            if( isSpecialMailbox( $boxes[$i]['unformatted']) ) {
 
1043
                $line .= "<font color=\"$color[11]\">";
 
1044
            } else {
 
1045
                $line .= "<font color=\"$color[15]\">";
 
1046
            }
 
1047
            if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
 
1048
                $mailbox = str_replace('&nbsp;','',$mailbox);
 
1049
                $line .= str_replace(' ', '&nbsp;', $mailbox);
 
1050
            }
 
1051
            $line .= '</font>';
 
1052
        } else {
 
1053
            $line .= formatMailboxName($imapConnection, $boxes[$i]);
 
1054
        }
 
1055
 
 
1056
        /* Put the final touches on our folder line. */
 
1057
        $line .= "</nobr><br>\n";
 
1058
 
 
1059
        /* Output the line for this folder. */
 
1060
        echo $line;
 
1061
    }
 
1062
}
 
1063
} else {  /* expiremental code */
 
1064
    $boxes = sqimap_mailbox_tree($imapConnection);
 
1065
    if (isset($advanced_tree) && $advanced_tree) {
 
1066
        echo '<form name="collapse" action="left_main.php" method="post" ' .
 
1067
             'enctype="multipart/form-data"'."\n";
 
1068
        echo '<small>';
 
1069
        echo '<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 />';
 
1070
        echo '<div id="mailboxes" class="mailboxes">'."\n\n";
 
1071
        sqgetGlobalVar('mbx', $mbx, SQ_POST);
 
1072
        if (!isset($mbx)) $mbx=NULL;
 
1073
        ListAdvancedBoxes($boxes, $mbx);
 
1074
        echo '</div>';
 
1075
        echo '</small>';
 
1076
        echo '</form>'."\n";
 
1077
    } else {
 
1078
        //sqimap_get_status_mbx_tree($imap_stream,$boxes)    
 
1079
        ListBoxes($boxes);
 
1080
    }
 
1081
} /* if ($oldway) else ... */
 
1082
do_hook('left_main_after');
 
1083
sqimap_logout($imapConnection);
 
1084
 
 
1085
echo '</td></tr></table>' . "\n".
 
1086
    "</div></body></html>\n";
 
1087
 
 
1088
?>