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