8b7ce15d7dcfde16a5b74e56953773c7dff61eb0
[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, $color, $move_to_trash) {
34 global $folder_prefix;
35 require ("../config/config.php");
36
37 $mailboxURL = urlencode($real_box);
38 sqimap_mailbox_select ($imapConnection, $real_box);
39 $unseen = sqimap_unseen_messages($imapConnection, $numUnseen);
40
41 echo "<NOBR>";
42 if ($unseen)
43 $line .= "<B>";
44
45 $special_color = false;
46 for ($i = 0; $i < count($special_folders); $i++) {
47 if ((substr($real_box, strlen($folder_prefix), strlen($special_folders[$i])) == $special_folders[$i]) && ($use_special_folder_color == true))
48 $special_color = true;
49 }
50
51 if ($special_color == true) {
52 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\"><FONT COLOR=\"$color[11]\">";
53 $line .= replace_spaces($mailbox);
54 $line .= "</font></a>";
55 } else {
56 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
57 $line .= replace_spaces($mailbox);
58 $line .= "</font></a>";
59 }
60
61 if ($unseen)
62 $line .= "</B>";
63
64 if ($numUnseen > 0) {
65 $line .= "&nbsp;<small>($numUnseen)</small>";
66 }
67
68 if (($move_to_trash == true) && (trim($real_box) == $trash_folder)) {
69 $urlMailbox = urlencode($real_box);
70 $line .= "<small>";
71 $line .= "&nbsp;&nbsp;&nbsp;&nbsp;(<B><A HREF=\"empty_trash.php?numMessages=$numMessages&mailbox=$urlMailbox\" TARGET=right style=\"text-decoration:none\">"._("purge")."</A></B>)";
72 $line .= "</small></a>\n";
73 }
74
75 echo "</NOBR>";
76 return $line;
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, $color, $move_to_trash);
119 }
120 } else {
121 $line .= formatMailboxName($imapConnection, $mailbox, $boxes[$i]["unformatted"], $delimeter, $color, $move_to_trash);
122 }
123 echo "$line<BR>";
124 }
125
126
127 fclose($imapConnection);
128
129 ?>
130 </BODY></HTML>