fix switch of en/decode in mdn, thanks Masato HIGASHIYAMA (#1694687)
[squirrelmail.git] / src / left_main.php
1 <?php
2
3 /**
4 * left_main.php
5 *
6 * This is the code for the left bar. The left bar shows the folders
7 * available, and has cookie information.
8 *
9 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15 /**
16 * Include the SquirrelMail initialization file.
17 */
18 require('../include/init.php');
19
20 /* SquirrelMail required files. */
21 require_once(SM_PATH . 'functions/imap_general.php');
22 require_once(SM_PATH . 'functions/date.php');
23 require_once(SM_PATH . 'functions/template/folder_list_util.php');
24
25 /* These constants are used for folder stuff. */
26 define('SM_BOX_UNCOLLAPSED', 0);
27 define('SM_BOX_COLLAPSED', 1);
28
29 /* get globals */
30 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
31
32 sqgetGlobalVar('fold', $fold, SQ_GET);
33 sqgetGlobalVar('unfold', $unfold, SQ_GET);
34 /* end globals */
35
36 // open a connection on the imap port (143)
37 // why hide the output?
38 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, true);
39
40 /**
41 * Using stristr since very old preferences may contain "None" and "none".
42 */
43 if (!empty($left_refresh) &&
44 !stristr($left_refresh, 'none')){
45 $xtra = "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\" />\n" .
46 "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n".
47 "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
48 } else {
49 $xtra = '';
50 }
51
52 /**
53 * Include extra javascript files needed by template
54 */
55 $js_includes = $oTemplate->get_javascript_includes(TRUE);
56 foreach ($js_includes as $js_file) {
57 $xtra .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
58 }
59
60 // get mailbox list and cache it
61 $mailboxes=sqimap_get_mailboxes($imapConnection,false,$show_only_subscribed_folders);
62
63 displayHtmlHeader( $org_title, $xtra );
64 $oErrorHandler->setDelayedErrors(true);
65
66 sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION);
67 /* If requested and not yet complete, attempt to autocreate folders. */
68 if ($auto_create_special && !isset($auto_create_done)) {
69 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
70 $folders_created = false;
71 foreach( $autocreate as $folder ) {
72 if ($folder != '') {
73 /**
74 * If $show_only_subscribed_folders is true, don't use
75 * $mailboxes array for checking if mailbox exists.
76 * Mailbox list contains only subscribed folders.
77 * sqimap_mailbox_create() will fail, if folder exists.
78 */
79 if ($show_only_subscribed_folders) {
80 $mailbox_cache = false;
81 } else {
82 $mailbox_cache = $mailboxes;
83 }
84 if ( !sqimap_mailbox_exists($imapConnection, $folder, $mailbox_cache)) {
85 sqimap_mailbox_create($imapConnection, $folder, '');
86 $folders_created = true;
87 } else {
88 // check for subscription is useless and expensive, just
89 // surpress the NO response. Unless we're on Mecury, which
90 // will just subscribe a folder again if it's already
91 // subscribed.
92 if ( strtolower($imap_server_type) != 'mercury32' ||
93 !sqimap_mailbox_is_subscribed($imapConnection, $folder) ) {
94 sqimap_subscribe($imapConnection, $folder, false);
95 $folders_created = true;
96 }
97 }
98 }
99 }
100
101 /* Let the world know that autocreation is complete! Hurrah! */
102 $auto_create_done = TRUE;
103 sqsession_register($auto_create_done, 'auto_create_done');
104 // reload mailbox list
105 if ($folders_created)
106 $mailboxes=sqimap_get_mailboxes($imapConnection,true,$show_only_subscribed_folders);
107 }
108
109 $clock = '';
110 if ($date_format != 6) {
111 /* First, display the clock. */
112 if ($hour_format == 1) {
113 $hr = 'H:i';
114 if ($date_format == 4) {
115 $hr .= ':s';
116 }
117 } else {
118 if ($date_format == 4) {
119 $hr = 'g:i:s a';
120 } else {
121 $hr = 'g:i a';
122 }
123 }
124
125 switch( $date_format ) {
126 case 0:
127 $clk = date('Y-m-d '.$hr. ' T', time());
128 break;
129 case 1:
130 $clk = date('m/d/y '.$hr, time());
131 break;
132 case 2:
133 $clk = date('d/m/y '.$hr, time());
134 break;
135 case 4:
136 case 5:
137 $clk = date($hr, time());
138 break;
139 default:
140 $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
141 }
142 $clk = str_replace(' ','&nbsp;',$clk);
143
144 //FIXME don't build HTML here - do it in template
145 $clock = '<small><span style="white-space: nowrap;">'
146 . str_replace(' ', '&nbsp;', _("Last Refresh"))
147 . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />\n";
148 }
149
150 if ( $collapse_folders ) {
151 /* If directed, collapse or uncollapse a folder. */
152 if (isset($fold)) {
153 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
154 } else if (isset($unfold)) {
155 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
156 }
157 }
158
159 /* Get unseen/total display prefs */
160 $unseen_type = getPref( $data_dir , $username , 'unseen_type' );
161 $unseen_notify = getPref( $data_dir , $username , 'unseen_notify' );
162
163 if (empty($unseen_type)) {
164 if (!empty($default_unseen_type)) {
165 $unseen_type = $default_unseen_type;
166 } else {
167 $unseen_type = 1;
168 }
169 }
170
171 if (empty($unseen_notify)) {
172 if (!empty($default_unseen_notify)) {
173 $unseen_notify = $default_unseen_notify;
174 } else {
175 $unseen_notify = 0;
176 }
177 }
178
179 /**
180 * pass $mailboxes now instead of $imapconnection - sqimap_get_mailboxes() has been separated from
181 * sqimap_mailbox_tree() so that the cached mailbox list can be used elsewhere in left_main and beyond
182 */
183 $boxes = sqimap_mailbox_tree($imapConnection,$mailboxes,$show_only_subscribed_folders);
184 $mailbox_structure = getBoxStructure($boxes);
185
186 $oTemplate->assign('clock', $clock);
187 $oTemplate->assign('mailboxes', $mailbox_structure);
188
189 /*
190 * Build an array to pass user prefs to the template in order to avoid using
191 * globals, which are dirty, filthy things in templates. :)
192 */
193 $settings = array();
194 #$settings['imapConnection'] = $imapConnection;
195 $settings['templateID'] = $sTemplateID;
196 $settings['unreadNotificationEnabled'] = $unseen_notify!=1;
197 $settings['unreadNotificationAllFolders'] = $unseen_notify == 3;
198 $settings['unreadNotificationDisplayTotal'] = $unseen_type == 2;
199 $settings['unreadNotificationCummulative'] = $unseen_cum==1;
200 $settings['useSpecialFolderColor'] = $use_special_folder_color;
201 $settings['messageRecyclingEnabled'] = $move_to_trash;
202 $settings['collapsableFoldersEnabled'] = $collapse_folders==1;
203 $oTemplate->assign('settings', $settings);
204
205 $oTemplate->display('left_main.tpl');
206
207 sqimap_logout($imapConnection);
208 $oTemplate->display('footer.tpl');