a907a73fa1e3bc8f3440203137657ae7a562ddb4
[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/i18n.php");
15 include("../functions/strings.php");
16 include("../config/config.php");
17 include("../functions/array.php");
18 include("../functions/imap.php");
19 include("../functions/page_header.php");
20 include("../functions/plugin.php");
21 include("../src/load_prefs.php");
22
23 // open a connection on the imap port (143)
24 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
25
26 displayHtmlHeader();
27
28 function formatMailboxName($imapConnection, $box_array, $delimeter) {
29 global $folder_prefix, $trash_folder, $sent_folder;
30 global $color, $move_to_sent, $move_to_trash;
31 global $unseen_notify, $unseen_type, $collapse_folders;
32
33 $real_box = $box_array['unformatted'];
34 $mailbox = $box_array['formatted'];
35 $mailboxURL = urlencode($real_box);
36
37 $unseen = 0;
38
39 if (($unseen_notify == 2 && $real_box == "INBOX") ||
40 $unseen_notify == 3) {
41 $unseen = sqimap_unseen_messages($imapConnection, $numUnseen, $real_box);
42 if ($unseen_type == 1 && $unseen > 0) {
43 $unseen_string = "($unseen)";
44 $unseen_found = true;
45 } else if ($unseen_type == 2) {
46 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
47 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
48 $unseen_found = true;
49 }
50 }
51
52 $special_color = false;
53 if ((strtolower($real_box) == "inbox") ||
54 (($real_box == $trash_folder) && ($move_to_trash)) ||
55 (($real_box == $sent_folder) && ($move_to_sent)))
56 $special_color = true;
57
58 $spaces = '';
59 $line = "<NOBR>";
60 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
61 $spaces = $regs[1];
62 $mailbox = $regs[2];
63 }
64
65 if ($unseen > 0)
66 $line .= "<B>";
67 $line .= str_replace(' ', '&nbsp;', $spaces);
68
69 if ($collapse_folders) {
70 if (isset($box_array['parent']))
71 $line .= FoldLink($box_array['unformatted'], $box_array['parent']);
72 else
73 $line .= '<tt>&nbsp;</tt>&nbsp;';
74 }
75
76 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
77 if ($special_color == true)
78 $line .= "<FONT COLOR=\"$color[11]\">";
79 $line .= str_replace(' ', '&nbsp;', $mailbox);
80 if ($special_color == true)
81 $line .= "</font>";
82 $line .= "</a>";
83
84 if ($unseen > 0)
85 $line .= "</B>";
86
87 if (isset($unseen_found) && $unseen_found) {
88 $line .= "&nbsp;<small>$unseen_string</small>";
89 }
90
91 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
92 if (! isset($numMessages))
93 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
94
95 if ($numMessages > 0)
96 {
97 $urlMailbox = urlencode($real_box);
98 $line .= "\n<small>\n";
99 $line .= " &nbsp; (<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)";
100 $line .= "\n</small>\n";
101 }
102 }
103 $line .= "</NOBR>";
104 return $line;
105 }
106
107 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
108 echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n";
109 echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
110 echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
111 }
112
113 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
114
115 do_hook("left_main_before");
116
117 $boxes = sqimap_mailbox_list($imapConnection);
118
119 echo "<CENTER><FONT SIZE=4><B>";
120 echo _("Folders") . "</B><BR></FONT>\n\n";
121
122 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
123 echo _("refresh folder list");
124 echo "</A>)</small></CENTER><BR>";
125 $delimeter = sqimap_get_delimiter($imapConnection);
126
127 if (isset($collapse_folders) && $collapse_folders) {
128 if (isset($fold))
129 setPref($data_dir, $username, 'collapse_folder_' . $fold, 1);
130 if (isset($unfold))
131 setPref($data_dir, $username, 'collapse_folder_' . $unfold, 0);
132 $IAmAParent = array();
133 for ($i = 0; $i < count($boxes); $i ++) {
134 $parts = explode($delimeter, $boxes[$i]['unformatted']);
135 $box_name = array_pop($parts);
136 $box_parent = implode($delimeter, $parts);
137 $hidden = 0;
138 if (isset($box_parent)) {
139 $hidden = getPref($data_dir, $username,
140 'collapse_folder_' . $box_parent);
141 $IAmAParent[$box_parent] = $hidden;
142 }
143 $boxes[$i]['folded'] = $hidden;
144 }
145 }
146
147 for ($i = 0;$i < count($boxes); $i++) {
148 if (! isset($boxes[$i]['folded']) || ! $boxes[$i]['folded'])
149 {
150 $line = "";
151 $mailbox = $boxes[$i]["formatted"];
152
153 if (isset($collapse_folders) && $collapse_folders && isset($IAmAParent[$boxes[$i]['unformatted']])) {
154 $boxes[$i]['parent'] = $IAmAParent[$boxes[$i]['unformatted']];
155 }
156
157 if (in_array('noselect', $boxes[$i]['flags'])) {
158 $line .= "<FONT COLOR=\"$color[10]\">";
159 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
160 $line .= str_replace(' ', '&nbsp;', $mailbox);
161 if (isset($boxes[$i]['parent']))
162 $line .= FoldLink($boxes[$i]['unformatted'], $boxes[$i]['parent']);
163 elseif ($collapse_folders)
164 $line .= '<tt>&nbsp;</tt>&nbsp;';
165 }
166 $line .= '</FONT>';
167 } else {
168 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
169 }
170 echo "$line<BR>\n";
171 }
172 }
173 sqimap_logout($imapConnection);
174 do_hook("left_main_after");
175
176 function FoldLink($mailbox, $folded) {
177 $mailbox = urlencode($mailbox);
178 echo '<tt><a target="left" style="text-decoration:none" ';
179 echo 'href="left_main.php?';
180 if ($folded)
181 echo "unfold=$mailbox\">+";
182 else
183 echo "fold=$mailbox\">-";
184 echo '</a></tt>&nbsp;';
185 }
186
187 ?>
188 </BODY></HTML>