* Looks good to me in Netscape and IE
[squirrelmail.git] / src / left_main.php
CommitLineData
59177427 1<?php
21c3249f 2 /**
a09387f4 3 ** left_main.php
ef870322 4 ** Copyright (c) 1999-2000 The SquirrelMail development team
5 ** Licensed under the GNU GPL. For full terms see the file COPYING.
21c3249f 6 **
7 ** This is the code for the left bar. The left bar shows the folders
8 ** available, and has cookie information.
9 **
245a6892 10 ** $Id$
21c3249f 11 **/
12
f740c049 13 include('../src/validate.php');
f740c049 14 include("../functions/array.php");
15 include("../functions/imap.php");
16 include("../functions/page_header.php");
17 include("../functions/plugin.php");
18 include("../src/load_prefs.php");
142499d4 19
99ab0367 20 // open a connection on the imap port (143)
21 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
22
2a833d72 23 displayHtmlHeader();
21c3249f 24
235a65d5 25 function formatMailboxName($imapConnection, $box_array, $delimeter) {
5bdd7223 26 global $folder_prefix, $trash_folder, $sent_folder;
27 global $color, $move_to_sent, $move_to_trash;
235a65d5 28 global $unseen_notify, $unseen_type, $collapse_folders;
29
30 $real_box = $box_array['unformatted'];
31 $mailbox = $box_array['formatted'];
5c42b0dd 32 $mailboxURL = urlencode($real_box);
0cd84d75 33
235a65d5 34 $unseen = 0;
35
36 if (($unseen_notify == 2 && $real_box == "INBOX") ||
37 $unseen_notify == 3) {
38 $unseen = sqimap_unseen_messages($imapConnection, $numUnseen, $real_box);
24fc5dd2 39 if ($unseen_type == 1 && $unseen > 0) {
40 $unseen_string = "($unseen)";
41 $unseen_found = true;
42 } else if ($unseen_type == 2) {
43 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
44 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
45 $unseen_found = true;
46 }
47 }
5bdd7223 48
7ce342dc 49 $special_color = false;
508ca2d3 50 if ((strtolower($real_box) == "inbox") ||
235a65d5 51 (($real_box == $trash_folder) && ($move_to_trash)) ||
52 (($real_box == $sent_folder) && ($move_to_sent)))
53 $special_color = true;
54
55 $spaces = '';
56 $line = "<NOBR>";
57 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
58 $spaces = $regs[1];
59 $mailbox = $regs[2];
60 }
5bdd7223 61
235a65d5 62 if ($unseen > 0)
63 $line .= "<B>";
64 $line .= str_replace(' ', '&nbsp;', $spaces);
65
66 if ($collapse_folders) {
67 if (isset($box_array['parent']))
68 $line .= FoldLink($box_array['unformatted'], $box_array['parent']);
69 else
70 $line .= '<tt>&nbsp;</tt>&nbsp;';
d92b6f31 71 }
235a65d5 72
73 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
74 if ($special_color == true)
75 $line .= "<FONT COLOR=\"$color[11]\">";
76 $line .= str_replace(' ', '&nbsp;', $mailbox);
77 if ($special_color == true)
78 $line .= "</font>";
79 $line .= "</a>";
7ce342dc 80
d1941f35 81 if ($unseen > 0)
7ce342dc 82 $line .= "</B>";
235a65d5 83
245a6892 84 if (isset($unseen_found) && $unseen_found) {
24fc5dd2 85 $line .= "&nbsp;<small>$unseen_string</small>";
7ce342dc 86 }
87
1e0628fb 88 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
b4cf620b 89 if (! isset($numMessages))
90 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
91
92 if ($numMessages > 0)
12d61439 93 {
b4cf620b 94 $urlMailbox = urlencode($real_box);
95 $line .= "\n<small>\n";
96 $line .= " &nbsp; (<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)";
97 $line .= "\n</small>\n";
12d61439 98 }
d92b6f31 99 }
1d4fe45e 100 $line .= "</NOBR>";
d92b6f31 101 return $line;
102 }
103
4c34dac5 104 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
1d4fe45e 105 echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n";
106 echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
107 echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
469eb37b 108 }
813eba2f 109
04632dbc 110 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
f3d17401 111
9d0c7bee 112 do_hook("left_main_before");
113
813eba2f 114 $boxes = sqimap_mailbox_list($imapConnection);
21c3249f 115
1d4fe45e 116 echo "<CENTER><FONT SIZE=4><B>";
117 echo _("Folders") . "</B><BR></FONT>\n\n";
97afcee9 118
9f2215a1 119 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
ad6f805c 120 echo _("refresh folder list");
aae41ae9 121 echo "</A>)</small></CENTER><BR>";
813eba2f 122 $delimeter = sqimap_get_delimiter($imapConnection);
4c34dac5 123
235a65d5 124 if (isset($collapse_folders) && $collapse_folders) {
125 if (isset($fold))
126 setPref($data_dir, $username, 'collapse_folder_' . $fold, 1);
127 if (isset($unfold))
128 setPref($data_dir, $username, 'collapse_folder_' . $unfold, 0);
129 $IAmAParent = array();
130 for ($i = 0; $i < count($boxes); $i ++) {
131 $parts = explode($delimeter, $boxes[$i]['unformatted']);
132 $box_name = array_pop($parts);
133 $box_parent = implode($delimeter, $parts);
134 $hidden = 0;
135 if (isset($box_parent)) {
136 $hidden = getPref($data_dir, $username,
137 'collapse_folder_' . $box_parent);
138 $IAmAParent[$box_parent] = $hidden;
139 }
140 $boxes[$i]['folded'] = $hidden;
141 }
142 }
143
7ce342dc 144 for ($i = 0;$i < count($boxes); $i++) {
235a65d5 145 if (! isset($boxes[$i]['folded']) || ! $boxes[$i]['folded'])
146 {
147 $line = "";
148 $mailbox = $boxes[$i]["formatted"];
149
150 if (isset($collapse_folders) && $collapse_folders && isset($IAmAParent[$boxes[$i]['unformatted']])) {
151 $boxes[$i]['parent'] = $IAmAParent[$boxes[$i]['unformatted']];
152 }
153
154 if (in_array('noselect', $boxes[$i]['flags'])) {
155 $line .= "<FONT COLOR=\"$color[10]\">";
12d61439 156 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
157 $line .= str_replace(' ', '&nbsp;', $mailbox);
7161db62 158 if (isset($boxes[$i]['parent']))
12d61439 159 $line .= FoldLink($boxes[$i]['unformatted'], $boxes[$i]['parent']);
7161db62 160 elseif ($collapse_folders)
161 $line .= '<tt>&nbsp;</tt>&nbsp;';
235a65d5 162 }
163 $line .= '</FONT>';
164 } else {
165 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
166 }
167 echo "$line<BR>\n";
d92b6f31 168 }
d92b6f31 169 }
1195c340 170 sqimap_logout($imapConnection);
6b638171 171 do_hook("left_main_after");
235a65d5 172
173 function FoldLink($mailbox, $folded) {
174 $mailbox = urlencode($mailbox);
175 echo '<tt><a target="left" style="text-decoration:none" ';
176 echo 'href="left_main.php?';
177 if ($folded)
178 echo "unfold=$mailbox\">+";
179 else
180 echo "fold=$mailbox\">-";
181 echo '</a></tt>&nbsp;';
182 }
183
21c3249f 184?>
aae41ae9 185</BODY></HTML>