fixed some html errors, added endlines
[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 **/
11
12 session_start();
13
14 if(!isset($username)) {
15 echo "You need a valid user and password to access this page!";
16 exit;
17 }
18
19
20 if (!isset($config_php))
21 include("../config/config.php");
22 if (!isset($array_php))
23 include("../functions/array.php");
24 if (!isset($strings_php))
25 include("../functions/strings.php");
26 if (!isset($imap_php))
27 include("../functions/imap.php");
28 if (!isset($page_header_php))
29 include("../functions/page_header.php");
30 if (!isset($i18n_php))
31 include("../functions/i18n.php");
32 if (!isset($plugin_php))
33 include("../functions/plugin.php");
34
35 // open a connection on the imap port (143)
36 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
37
38 /** If it was a successful login, lets load their preferences **/
39 include("../src/load_prefs.php");
40
41 displayHtmlHeader();
42
43
44 function formatMailboxName($imapConnection, $mailbox, $real_box, $delimeter, $unseen) {
45 global $folder_prefix, $trash_folder, $sent_folder;
46 global $color, $move_to_sent, $move_to_trash;
47 global $unseen_notify, $unseen_type;
48
49 $mailboxURL = urlencode($real_box);
50
51 if ($unseen_notify == 2 && $real_box == "INBOX") {
52 $unseen = sqimap_unseen_messages($imapConnection, $numUnseen, $real_box);
53 if ($unseen_type == 1 && $unseen > 0) {
54 $unseen_string = "($unseen)";
55 $unseen_found = true;
56 } else if ($unseen_type == 2) {
57 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
58 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
59 $unseen_found = true;
60 }
61 } else if ($unseen_notify == 3) {
62 $unseen = sqimap_unseen_messages($imapConnection, $numUnseen, $real_box);
63 if ($unseen_type == 1 && $unseen > 0) {
64 $unseen_string = "($unseen)";
65 $unseen_found = true;
66 } else if ($unseen_type == 2) {
67 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
68 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
69 $unseen_found = true;
70 }
71 }
72
73 $line .= "<NOBR>";
74 if ($unseen > 0)
75 $line .= "<B>";
76
77 $special_color = false;
78 if ((strtolower($real_box) == "inbox") ||
79 (($real_box == $trash_folder) && ($move_to_trash)) ||
80 (($real_box == $sent_folder) && ($move_to_sent)))
81 $special_color = true;
82
83 if ($special_color == true) {
84 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\"><FONT COLOR=\"$color[11]\">";
85 $line .= replace_spaces($mailbox);
86 $line .= "</font></a>";
87 } else {
88 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
89 $line .= replace_spaces($mailbox);
90 $line .= "</a>";
91 }
92
93 if ($unseen > 0)
94 $line .= "</B>";
95
96 if ($unseen_found) {
97 $line .= "&nbsp;<small>$unseen_string</small>";
98 }
99
100 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
101 $urlMailbox = urlencode($real_box);
102 $line .= "\n<small>\n";
103 $line .= " &nbsp;&nbsp;(<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)";
104 $line .= "\n</small>\n";
105 }
106 $line .= "</NOBR>";
107 return $line;
108 }
109
110 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
111 echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n";
112 echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
113 echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
114 }
115
116 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
117
118 do_hook("left_main_before");
119
120 $boxes = sqimap_mailbox_list($imapConnection);
121
122 echo "<CENTER><FONT SIZE=4><B>";
123 echo _("Folders") . "</B><BR></FONT>\n\n";
124
125 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
126 echo _("refresh folder list");
127 echo "</A>)</small></CENTER><BR>";
128 $delimeter = sqimap_get_delimiter($imapConnection);
129
130 for ($i = 0;$i < count($boxes); $i++) {
131 $line = "";
132 $mailbox = $boxes[$i]["formatted"];
133
134 if ($boxes[$i]["flags"]) {
135 $noselect = false;
136 for ($h = 0; $h < count($boxes[$i]["flags"]); $h++) {
137 if (strtolower($boxes[$i]["flags"][$h]) == "noselect")
138 $noselect = true;
139 }
140 if ($noselect == true) {
141 $line .= "<FONT COLOR=\"$color[10]\">";
142 $line .= replace_spaces(readShortMailboxName($mailbox, $delimeter));
143 $line .= "</FONT>";
144 } else {
145 $line .= formatMailboxName($imapConnection, $mailbox, $boxes[$i]["unformatted"], $delimeter, $boxes[$i]["unseen"]);
146 }
147 } else {
148 $line .= formatMailboxName($imapConnection, $mailbox, $boxes[$i]["unformatted"], $delimeter, $boxes[$i]["unseen"]);
149 }
150 echo "$line<BR>\n";
151 }
152 sqimap_logout($imapConnection);
153 do_hook("left_main_after");
154 ?>
155 </BODY></HTML>