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