* Added 'other' to the list, since it is a viable option
[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");
f740c049 16 include("../functions/plugin.php");
142499d4 17
99ab0367 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
2a833d72 21 displayHtmlHeader();
21c3249f 22
235a65d5 23 function formatMailboxName($imapConnection, $box_array, $delimeter) {
5bdd7223 24 global $folder_prefix, $trash_folder, $sent_folder;
25 global $color, $move_to_sent, $move_to_trash;
235a65d5 26 global $unseen_notify, $unseen_type, $collapse_folders;
27
28 $real_box = $box_array['unformatted'];
29 $mailbox = $box_array['formatted'];
5c42b0dd 30 $mailboxURL = urlencode($real_box);
0cd84d75 31
235a65d5 32 $unseen = 0;
4d2c01e3 33
235a65d5 34 if (($unseen_notify == 2 && $real_box == "INBOX") ||
35 $unseen_notify == 3) {
4d2c01e3 36 $unseen = sqimap_unseen_messages($imapConnection, $real_box);
24fc5dd2 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 }
5bdd7223 46
7ce342dc 47 $special_color = false;
508ca2d3 48 if ((strtolower($real_box) == "inbox") ||
235a65d5 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 }
5bdd7223 59
235a65d5 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;';
d92b6f31 69 }
235a65d5 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>";
7ce342dc 78
d1941f35 79 if ($unseen > 0)
7ce342dc 80 $line .= "</B>";
235a65d5 81
245a6892 82 if (isset($unseen_found) && $unseen_found) {
24fc5dd2 83 $line .= "&nbsp;<small>$unseen_string</small>";
7ce342dc 84 }
85
1e0628fb 86 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
b4cf620b 87 if (! isset($numMessages))
88 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
89
90 if ($numMessages > 0)
12d61439 91 {
b4cf620b 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";
12d61439 96 }
d92b6f31 97 }
1d4fe45e 98 $line .= "</NOBR>";
d92b6f31 99 return $line;
100 }
101
4c34dac5 102 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
1d4fe45e 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";
469eb37b 106 }
813eba2f 107
04632dbc 108 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
f3d17401 109
9d0c7bee 110 do_hook("left_main_before");
111
813eba2f 112 $boxes = sqimap_mailbox_list($imapConnection);
21c3249f 113
1d4fe45e 114 echo "<CENTER><FONT SIZE=4><B>";
115 echo _("Folders") . "</B><BR></FONT>\n\n";
97afcee9 116
9f2215a1 117 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
ad6f805c 118 echo _("refresh folder list");
aae41ae9 119 echo "</A>)</small></CENTER><BR>";
813eba2f 120 $delimeter = sqimap_get_delimiter($imapConnection);
4c34dac5 121
235a65d5 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
7ce342dc 142 for ($i = 0;$i < count($boxes); $i++) {
235a65d5 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]\">";
12d61439 154 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
155 $line .= str_replace(' ', '&nbsp;', $mailbox);
7161db62 156 if (isset($boxes[$i]['parent']))
12d61439 157 $line .= FoldLink($boxes[$i]['unformatted'], $boxes[$i]['parent']);
7161db62 158 elseif ($collapse_folders)
159 $line .= '<tt>&nbsp;</tt>&nbsp;';
235a65d5 160 }
161 $line .= '</FONT>';
162 } else {
163 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
164 }
165 echo "$line<BR>\n";
d92b6f31 166 }
d92b6f31 167 }
1195c340 168 sqimap_logout($imapConnection);
6b638171 169 do_hook("left_main_after");
235a65d5 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
21c3249f 182?>
aae41ae9 183</BODY></HTML>