* To reduce on errors, I moved the includes for config.php and strings.php
[squirrelmail.git] / src / left_main.php
1 <?php
2 /**
3 ** left_main.php
4 ** Copyright (c) 1999-2000 The SquirrelMail development team
5 ** Licensed under the GNU GPL. For full terms see the file COPYING.
6 **
7 ** This is the code for the left bar. The left bar shows the folders
8 ** available, and has cookie information.
9 **
10 ** $Id$
11 **/
12
13 include('../src/validate.php');
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");
19
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
23 displayHtmlHeader();
24
25 function formatMailboxName($imapConnection, $box_array, $delimeter) {
26 global $folder_prefix, $trash_folder, $sent_folder;
27 global $color, $move_to_sent, $move_to_trash;
28 global $unseen_notify, $unseen_type, $collapse_folders;
29
30 $real_box = $box_array['unformatted'];
31 $mailbox = $box_array['formatted'];
32 $mailboxURL = urlencode($real_box);
33
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);
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 }
48
49 $special_color = false;
50 if ((strtolower($real_box) == "inbox") ||
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 }
61
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;';
71 }
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>";
80
81 if ($unseen > 0)
82 $line .= "</B>";
83
84 if (isset($unseen_found) && $unseen_found) {
85 $line .= "&nbsp;<small>$unseen_string</small>";
86 }
87
88 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
89 if (! isset($numMessages))
90 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
91
92 if ($numMessages > 0)
93 {
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";
98 }
99 }
100 $line .= "</NOBR>";
101 return $line;
102 }
103
104 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
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";
108 }
109
110 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
111
112 do_hook("left_main_before");
113
114 $boxes = sqimap_mailbox_list($imapConnection);
115
116 echo "<CENTER><FONT SIZE=4><B>";
117 echo _("Folders") . "</B><BR></FONT>\n\n";
118
119 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
120 echo _("refresh folder list");
121 echo "</A>)</small></CENTER><BR>";
122 $delimeter = sqimap_get_delimiter($imapConnection);
123
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
144 for ($i = 0;$i < count($boxes); $i++) {
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]\">";
156 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
157 $line .= str_replace(' ', '&nbsp;', $mailbox);
158 if (isset($boxes[$i]['parent']))
159 $line .= FoldLink($boxes[$i]['unformatted'], $boxes[$i]['parent']);
160 elseif ($collapse_folders)
161 $line .= '<tt>&nbsp;</tt>&nbsp;';
162 }
163 $line .= '</FONT>';
164 } else {
165 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
166 }
167 echo "$line<BR>\n";
168 }
169 }
170 sqimap_logout($imapConnection);
171 do_hook("left_main_after");
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
184 ?>
185 </BODY></HTML>