* Fixed error when logging out
[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');
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");
142499d4 22
99ab0367 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
2a833d72 26 displayHtmlHeader();
21c3249f 27
235a65d5 28 function formatMailboxName($imapConnection, $box_array, $delimeter) {
5bdd7223 29 global $folder_prefix, $trash_folder, $sent_folder;
30 global $color, $move_to_sent, $move_to_trash;
235a65d5 31 global $unseen_notify, $unseen_type, $collapse_folders;
32
33 $real_box = $box_array['unformatted'];
34 $mailbox = $box_array['formatted'];
5c42b0dd 35 $mailboxURL = urlencode($real_box);
0cd84d75 36
235a65d5 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);
24fc5dd2 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 }
5bdd7223 51
7ce342dc 52 $special_color = false;
508ca2d3 53 if ((strtolower($real_box) == "inbox") ||
235a65d5 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 }
5bdd7223 64
235a65d5 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;';
d92b6f31 74 }
235a65d5 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>";
7ce342dc 83
d1941f35 84 if ($unseen > 0)
7ce342dc 85 $line .= "</B>";
235a65d5 86
245a6892 87 if (isset($unseen_found) && $unseen_found) {
24fc5dd2 88 $line .= "&nbsp;<small>$unseen_string</small>";
7ce342dc 89 }
90
1e0628fb 91 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
b4cf620b 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 }
d92b6f31 102 }
1d4fe45e 103 $line .= "</NOBR>";
d92b6f31 104 return $line;
105 }
106
4c34dac5 107 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
1d4fe45e 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";
469eb37b 111 }
813eba2f 112
04632dbc 113 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
f3d17401 114
9d0c7bee 115 do_hook("left_main_before");
116
813eba2f 117 $boxes = sqimap_mailbox_list($imapConnection);
21c3249f 118
1d4fe45e 119 echo "<CENTER><FONT SIZE=4><B>";
120 echo _("Folders") . "</B><BR></FONT>\n\n";
97afcee9 121
9f2215a1 122 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
ad6f805c 123 echo _("refresh folder list");
aae41ae9 124 echo "</A>)</small></CENTER><BR>";
813eba2f 125 $delimeter = sqimap_get_delimiter($imapConnection);
4c34dac5 126
235a65d5 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
7ce342dc 147 for ($i = 0;$i < count($boxes); $i++) {
235a65d5 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;', $regs[1]);
161 if (isset($boxes[$i]['parent']))
162 $line .= FoldLink($boxes[$i]['unformatted'],
163 $boxes[$i]['parent']);
164 elseif ($collapse_folders)
165 $line .= '<tt>&nbsp;</tt>&nbsp;';
166 $line .= str_replace(' ', '&nbsp;', $regs[2]);
167 }
168 $line .= '</FONT>';
169 } else {
170 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
171 }
172 echo "$line<BR>\n";
d92b6f31 173 }
d92b6f31 174 }
1195c340 175 sqimap_logout($imapConnection);
6b638171 176 do_hook("left_main_after");
235a65d5 177
178 function FoldLink($mailbox, $folded) {
179 $mailbox = urlencode($mailbox);
180 echo '<tt><a target="left" style="text-decoration:none" ';
181 echo 'href="left_main.php?';
182 if ($folded)
183 echo "unfold=$mailbox\">+";
184 else
185 echo "fold=$mailbox\">-";
186 echo '</a></tt>&nbsp;';
187 }
188
21c3249f 189?>
aae41ae9 190</BODY></HTML>