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