Viewing file: folderpane.inc.php (19.87 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
/*
############################################################################
# DWmail
# - version 4.0
# - Copyright (c) 2003-2006 Dominion Web Design
# - http://www.dominion-web.com/products/dwmail/
############################################################################
#
# The contents of this file are subject to the DWmail License version
# 2.2 ('License'). You may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.dominion-web.com/products/dwmail/license.php
# Software distributed under the License is distributed on an "AS IS" basis,
# without warranty of any kind, either express or implied.
#
# This code is Copyright (c) 2003-2006 Dominion Web Design.
# All rights reserved.
#
# This software may not be redistributed outside the terms of the
# license agreement.
#
############################################################################
*/
// This include sets the contents of the folder pane to $PageFolderPane
//
// This include must be called after an IMAP connection has been made
// and before $PageHeader is echo'd
// If for some reason the folder tree is messing up and producing unexpected
// results, simply set $fancyfolders, below, to 0 to use a non-indented method
// of displaying folders
// Debug variable
// echo microtime() . "<br />";
$fancyfolders = 1;
if ($_SESSION['servertype'] == "imap" || $_SESSION['servertype'] == "imapssl") {
$IMAPConnection->_folderdelimiter = $DefaultDelimiter;
$IMAPConnection->_IMAPSentMailFolder = $IMAPSentMail;
$IMAPConnection->_IMAPTrashFolder = $IMAPTrash;
$IMAPConnection->_IMAPDraftsFolder = $IMAPDrafts;
$folderget = $IMAPConnection->WM_IMAPFolders($IMAPSubscriptions);
$folders = $IMAPConnection->_folders;
// If you want to FORCE the folder delimiter to be something other than that auto-detected uncomment the following line and change the delimiter value
// $IMAPConnection->_folderdelimiter = '.';
$refreshfolderlist = 0;
if ($IMAPSubscriptions == 1 && $initiallogin == 1) {
// Search to see if INBOX is subscribed to... if not, subscribe to it
if ($IMAPConnection->_inboxfolderexist == 0) {
$subscribeinbox = $IMAPConnection->WM_IMAPFolderSubscribe("INBOX", '');
if ($subscribeinbox == TRUE) {
$refreshfolderlist = 1;
}
}
if ($IMAPConnection->_sentfolderexist == 0) {
$createsent = $IMAPConnection->WM_IMAPFolderCreate($IMAPConnection->_IMAPSentMailFolder, '');
$subscribesent = $IMAPConnection->WM_IMAPFolderSubscribe($IMAPConnection->_IMAPSentMailFolder, '');
if ($subscribesent == TRUE) {
$refreshfolderlist = 1;
}
}
if ($IMAPConnection->_trashfolderexist == 0) {
$createtrash = $IMAPConnection->WM_IMAPFolderCreate($IMAPConnection->_IMAPTrashFolder, '');
$subscribetrash = $IMAPConnection->WM_IMAPFolderSubscribe($IMAPConnection->_IMAPTrashFolder, '');
if ($subscribetrash == TRUE) {
$refreshfolderlist = 1;
}
}
if ($IMAPConnection->_draftsfolderexist == 0) {
$createdrafts = $IMAPConnection->WM_IMAPFolderCreate($IMAPConnection->_IMAPDraftsFolder, '');
$subscribedrafts = $IMAPConnection->WM_IMAPFolderSubscribe($IMAPConnection->_IMAPDraftsFolder, '');
if ($subscribedrafts == TRUE) {
$refreshfolderlist = 1;
}
}
}
elseif ($IMAPSubscriptions == 0 && $initiallogin == 1) {
// Create special folders if they don't exist but don't subscribe
if ($IMAPConnection->_sentfolderexist == 0) {
$createsent = $IMAPConnection->WM_IMAPFolderCreate($IMAPConnection->_IMAPSentMailFolder, '');
if ($createsent == TRUE) {
$refreshfolderlist = 1;
}
}
if ($IMAPConnection->_trashfolderexist == 0) {
$createtrash = $IMAPConnection->WM_IMAPFolderCreate($IMAPConnection->_IMAPTrashFolder, '');
if ($createtrash == TRUE) {
$refreshfolderlist = 1;
}
}
if ($IMAPConnection->_draftsfolderexist == 0) {
$createdrafts = $IMAPConnection->WM_IMAPFolderCreate($IMAPConnection->_IMAPDraftsFolder, '');
if ($createdrafts == TRUE) {
$refreshfolderlist = 1;
}
}
}
if ($refreshfolderlist == 1) {
// We have now updated this list so we need to update the folder list again
$folderget = $IMAPConnection->WM_IMAPFolders($IMAPSubscriptions);
$folders = $IMAPConnection->_folders;
}
sort($folders);
$oldfolder = $_SESSION['folder'];
$PageFolderPane = $getFile->fileRead('folderpane_imap');
$PageFolderLinks = $getFile->fileRead('folderlinks');
if ($_SESSION['fs'] == 1) {
$PageFolderLinks = str_replace("[ifframeset]", "", $PageFolderLinks);
$PageFolderLinks = str_replace("[/ifframeset]", "", $PageFolderLinks);
}
else {
$PageFolderLinks = preg_replace("/(\[)(ifframeset)(])(\r\n)*(.*)(\[\/ifframeset\])/siU", "", $PageFolderLinks);
}
if ($PreviewPane == 1) {
$PageFolderLinks = str_replace("[ifpreviewpane]", "", $PageFolderLinks);
$PageFolderLinks = str_replace("[/ifpreviewpane]", "", $PageFolderLinks);
}
else {
$PageFolderLinks = preg_replace("/(\[)(ifpreviewpane)(])(\r\n)*(.*)(\[\/ifpreviewpane\])/siU", "", $PageFolderLinks);
}
if ($fancyfolders == 1) {
$PageFolderPane = str_replace ("[iffancyfolders]", '', $PageFolderPane);
$PageFolderPane = str_replace ("[/iffancyfolders]", '', $PageFolderPane);
}
else {
$PageFolderPane = preg_replace("/(\[)(iffancyfolders)(])(\r\n)*(.*)(\[\/iffancyfolders\])/siU", "", $PageFolderPane);
}
// We used to close the connection here and re-open a half open connection. We are now using the imap_reopen function instead
// $mailbox = $IMAPConnection->WM_IMAPClose();
// $mailbox = $IMAPConnection->WM_IMAPHalfConnect();
$newfolder = $IMAPConnection->WM_IMAPReOpen('', 1);
$currentindent = 0;
for($i=0; $i<count($folders); $i++) {
$foldertemp = $PageFolderLinks;
$imapstatus = $IMAPConnection->WM_IMAPStatus($folders[$i]['id']);
$numberofmessages = $imapstatus->messages;
$numberofnewmessages = $imapstatus->unseen;
if ($numberofnewmessages > 0) {
$numberofmessages .= " <span class=\"messagecountnew\">($numberofnewmessages)</span>";
$foldertemp = str_replace ("[folderclass]", "folderpanenew", $foldertemp);
}
else {
$foldertemp = str_replace ("[folderclass]", "folderpane", $foldertemp);
}
$foldertemp = str_replace ("[folderid]", "?f=" . urlencode($folders[$i]['id']), $foldertemp);
$foldertemp = str_replace ("[folderidencode]", urlencode($folders[$i]['id']), $foldertemp);
$foldertemp = str_replace ("[folderlocation]", "mailbox.php", $foldertemp);
$foldertemp = str_replace ("[foldertotal]", $numberofmessages, $foldertemp);
$folderid_arry[] = $folders[$i]['id'];
$indentwidth = 17;
$indentgraphics = '';
if ($fancyfolders == 1) {
$folderindent = substr_count($folders[$i]['id'], $IMAPConnection->_folderdelimiter);
$isparent = is_array($IMAPConnection->_foldertree[$folders[$i]['id']]);
if ($folderindent >= 1) {
for ($j=1; $j<=$folderindent; $j++) {
if ($j == $folderindent && $isparent == true) {
if ($folderindent >= 2) {
$indentgraphics .= "<a href=\"JavaScript:childDisplay('el" . $i . "', 'im" . $i . "');\"><img src=\"templates/" . $_SESSION['tpl'] . "/images/folders/folder_collapsed.gif\" name=\"im" . $i . "\" border=\"0\" alt=\"\" /></a>";
$BuildExpand .= "childExpand('el" . $i . "', 'im" . $i . "');\r\n";
$BuildCollapse .= "childCollapse('el" . $i . "', 'im" . $i . "');\r\n";
}
else {
$indentgraphics .= "<a href=\"JavaScript:childDisplay('el" . $i . "', 'im" . $i . "');\"><img src=\"templates/" . $_SESSION['tpl'] . "/images/folders/folder_expanded.gif\" name=\"im" . $i . "\" border=\"0\" alt=\"\" /></a>";
$BuildExpand .= "childExpand('el" . $i . "', 'im" . $i . "');\r\n";
$BuildCollapse .= "childCollapse('el" . $i . "', 'im" . $i . "');\r\n";
}
}
else {
$indentgraphics .= "<img src=\"images/spacer.gif\" width=\"16\" border=\"0\" alt=\"\" />";
}
// $indentgraphics .= "<img src=\"images/spacer.gif\" width=\"16\" border=\"0\" alt=\"\" />";
}
$indentwidth = (17 * $folderindent) + 17;
}
if ($currentindent < $folderindent && $folderindent >= 1) {
$currentindent = $folderindent;
if ($folderindent >= 3) {
$foldertemp = "<div id=\"el" . ($i-1) . "\" style=\"display:none;\">" . $foldertemp;
}
else {
$foldertemp = "<div id=\"el" . ($i-1) . "\" style=\"display:block;\">" . $foldertemp;
}
}
if ($folderindent == 0) {
$condition = 0;
$condition2 = 1;
}
else {
$condition = 1;
$condition2 = 1;
}
if ($currentindent > $folderindent && $folderindent >= $condition) {
$indentdifference = $currentindent - $folderindent;
$currentindent = $folderindent;
for ($j=$indentdifference; $j>=$condition2; $j--) {
$foldertemp = "</div>" . $foldertemp;
}
}
if ($i == (count(folders) - 1) && $currentindent > 1) {
for ($j=$currentindent; $j>=1; $j--) {
$foldertemp = "</div>" . $foldertemp;
}
}
}
$currentnamearry = explode($IMAPConnection->_folderdelimiter, $folders[$i]['name']);
$currentname = $currentnamearry[(sizeof($currentnamearry)-1)];
$foldername_arry[] = str_replace("INBOX" . $IMAPConnection->_folderdelimiter, "", $folders[$i]['name']);
$foldertemp = str_replace ("[foldername]", str_replace("INBOX" . $IMAPConnection->_folderdelimiter, "", $currentname), $foldertemp);
$foldertemp = str_replace ("[indentwidth]", $indentwidth, $foldertemp);
$foldertemp = str_replace ("[previewmode]", "RestorePreview", $foldertemp);
// If Trash folder display an empty link
if ($folders[$i]['name'] == $IMAPTrash) {
$folderpurgetmp = '<span class="smalltext">[<a class="purge" href="deleteall.php?action=purge' . $MainSettings->SessAppend_noecho($TransIDEnabled, 0) . '"';
if ($_SESSION['fs'] == 1) {
$folderpurgetmp .= ' target="mailbox"';
}
$folderpurgetmp .= '>' . $lang['SFolderPane']['EmptyTrash'] . '</a>]</span>';
$foldertemp = str_replace ("[folderpurge]", $folderpurgetmp, $foldertemp);
unset ($folderpurgetmp);
$foldertemp = str_replace ("[icon]", $indentgraphics . "<img src=\"templates/" . $_SESSION['tpl'] . "/images/folders/folder_trash.gif\" border=\"0\" alt=\"" . $currentname . "\" />", $foldertemp);
}
elseif ($folders[$i]['name'] == "INBOX") {
if (!isset($_SESSION['IT']) && $newmail > 0) {
$_SESSION['IT'] = $numberofnewmessages;
}
$foldertemp = str_replace ("[folderpurge]", "", $foldertemp);
$foldertemp = str_replace ("[icon]", $indentgraphics . "<img src=\"templates/" . $_SESSION['tpl'] . "/images/folders/folder_inbox.gif\" border=\"0\" alt=\"Inbox\" />", $foldertemp);
}
elseif ($folders[$i]['name'] == urldecode($IMAPSentMail)) {
$foldertemp = str_replace ("[folderpurge]", "", $foldertemp);
$foldertemp = str_replace ("[icon]", $indentgraphics . "<img src=\"templates/" . $_SESSION['tpl'] . "/images/folders/folder_sent.gif\" border=\"0\" alt=\"" . $currentname . "\" />", $foldertemp);
}
elseif ($folders[$i]['name'] == urldecode($IMAPDrafts)) {
$foldertemp = str_replace ("[folderpurge]", "", $foldertemp);
$foldertemp = str_replace ("[icon]", $indentgraphics . "<img src=\"templates/" . $_SESSION['tpl'] . "/images/folders/folder_drafts.gif\" border=\"0\" alt=\"" . $currentname . "\" />", $foldertemp);
}
else {
$foldertemp = str_replace ("[folderpurge]", "", $foldertemp);
$foldertemp = str_replace ("[icon]", $indentgraphics . "<img src=\"templates/" . $_SESSION['tpl'] . "/images/folders/folder_blank.gif\" border=\"0\" alt=\"" . $currentname . "\" />", $foldertemp);
}
$folderlist .= $foldertemp;
unset ($folderindent);
unset ($isparent);
unset ($indentgraphics);
unset ($foldertemp);
}
// Close any remaining indent divs
if ($currentindent > 1) {
for ($j=$currentindent; $j>=1; $j--) {
$folderlist .= "</div>";
}
}
if ($UseDatabase == 1) {
if ($EnableContacts == 1) {
$folderaddressbook = $PageFolderLinks;
$folderaddressbook = str_replace ("[folderlocation]", "addressbook.php?mode=view", $folderaddressbook);
$folderaddressbook = str_replace ("[folderid]", "", $folderaddressbook);
$folderaddressbook = str_replace ("[foldername]", $lang['Contacts'], $folderaddressbook);
$folderaddressbook = str_replace ("[foldertotal]", "", $folderaddressbook);
$folderaddressbook = str_replace ("[folderpurge]", "", $folderaddressbook);
$folderaddressbook = str_replace ("[indentwidth]", "17", $folderaddressbook);
$folderaddressbook = str_replace ("[icon]", "<img src=\"templates/" . $_SESSION['tpl'] . "/images/folders/folder_addressbook.gif\" border=\"0\" alt=\"" . $lang['Contacts'] . "\" />", $folderaddressbook);
$folderaddressbook = str_replace("[previewmode]", "HidePreview", $folderaddressbook);
$folderlist .= $folderaddressbook;
}
if ($EnableCalendar == 1) {
$foldercalendar = $PageFolderLinks;
$foldercalendar = str_replace ("[folderlocation]", "calendar.php?mode=view", $foldercalendar);
$foldercalendar = str_replace ("[folderid]", "", $foldercalendar);
$foldercalendar = str_replace ("[foldername]", $lang['Calendar'], $foldercalendar);
$foldercalendar = str_replace ("[foldertotal]", "", $foldercalendar);
$foldercalendar = str_replace ("[folderpurge]", "", $foldercalendar);
$foldercalendar = str_replace ("[indentwidth]", "17", $foldercalendar);
$foldercalendar = str_replace ("[icon]", "<img src=\"templates/" . $_SESSION['tpl'] . "/images/folders/folder_calendar.gif\" border=\"0\" alt=\"" . $lang['Calendar'] . "\" />", $foldercalendar);
$foldercalendar = str_replace("[previewmode]", "HidePreview", $foldercalendar);
$folderlist .= $foldercalendar;
}
}
for($i=0; $i<count($folderid_arry); $i++) {
$folderoptions .= "<option value=\"" . $folderid_arry[$i] . "\"";
if ($folderid_arry[$i] == "INBOX") {
$folderoptions .= " selected=\"selected\"";
}
$folderoptions .= ">" . $foldername_arry[$i] . "</option>\n";
}
$PageFolderPane = str_replace ("[expandallfolders]", $BuildExpand, $PageFolderPane);
$PageFolderPane = str_replace ("[collapseallfolders]", $BuildCollapse, $PageFolderPane);
unset ($BuildExpand);
unset ($BuildCollapse);
$PageFolderPane = str_replace ("[folderlinks]", $folderlist, $PageFolderPane);
$PageFolderPane = str_replace ("[folderoptions]", $folderoptions, $PageFolderPane);
if ($AllowExternal == 1 && $UseDatabase == 1) {
$PageFolderPane = str_replace("[ifexternal]", "", $PageFolderPane);
$PageFolderPane = str_replace("[/ifexternal]", "", $PageFolderPane);
}
else {
$PageFolderPane = preg_replace("/(\[)(ifexternal)(])(\r\n)*(.*)(\[\/ifexternal\])/siU", "", $PageFolderPane);
}
// Switch back to current folder
$newfolder = $IMAPConnection->WM_IMAPReOpen($_SESSION['folder'], 0);
}
else {
$PageFolderPane = $getFile->fileRead('folderpane_pop3');
$PageFolderLinks = $getFile->fileRead('folderlinks');
$foldertemp_inbox = $PageFolderLinks;
$foldertemp_inbox = str_replace ("[folderlocation]", "mailbox.php", $foldertemp_inbox);
$foldertemp_inbox = str_replace ("[folderid]", "?f=INBOX", $foldertemp_inbox);
$foldertemp_inbox = str_replace ("[foldername]", "INBOX", $foldertemp_inbox);
$foldertemp_inbox = str_replace ("[foldertotal]", "", $foldertemp_inbox);
$foldertemp_inbox = str_replace ("[folderpurge]", "", $foldertemp_inbox);
$foldertemp_inbox = str_replace ("[icon]", "<img src=\"templates/" . $_SESSION['tpl'] . "/images/folders/folder_inbox.gif\" border=\"0\" alt=\"Inbox\" />", $foldertemp_inbox);
$foldertemp_inbox = str_replace("[previewmode]", "RestorePreview", $foldertemp_inbox);
$imapstatus = $IMAPConnection->WM_IMAPStatus('INBOX');
$numberofmessages = $imapstatus->messages;
if (!isset($_SESSION['IT']) && $newmail > 0) {
$_SESSION['IT'] = $numberofmessages;
}
$foldertemp_inbox = str_replace ("[indentwidth]", '17', $foldertemp_inbox);
$folderlist = $foldertemp_inbox;
if ($UseDatabase == 1) {
if ($EnableContacts == 1) {
$folderaddressbook = $PageFolderLinks;
$folderaddressbook = str_replace ("[folderlocation]", "addressbook.php?mode=view", $folderaddressbook);
$folderaddressbook = str_replace ("[folderid]", "", $folderaddressbook);
$folderaddressbook = str_replace ("[foldername]", $lang['Contacts'], $folderaddressbook);
$folderaddressbook = str_replace ("[foldertotal]", "", $folderaddressbook);
$folderaddressbook = str_replace ("[folderpurge]", "", $folderaddressbook);
$folderaddressbook = str_replace ("[indentwidth]", "17", $folderaddressbook);
$folderaddressbook = str_replace ("[icon]", "<img src=\"templates/" . $_SESSION['tpl'] . "/images/folders/folder_addressbook.gif\" border=\"0\" alt=\"" . $lang['Contacts'] . "\" />", $folderaddressbook);
$folderaddressbook = str_replace("[previewmode]", "HidePreview", $folderaddressbook);
$folderlist .= $folderaddressbook;
}
if ($EnableCalendar == 1) {
$foldercalendar = $PageFolderLinks;
$foldercalendar = str_replace ("[folderlocation]", "calendar.php?mode=view", $foldercalendar);
$foldercalendar = str_replace ("[folderid]", "", $foldercalendar);
$foldercalendar = str_replace ("[foldername]", $lang['Calendar'], $foldercalendar);
$foldercalendar = str_replace ("[foldertotal]", "", $foldercalendar);
$foldercalendar = str_replace ("[folderpurge]", "", $foldercalendar);
$foldercalendar = str_replace ("[indentwidth]", "17", $foldercalendar);
$foldercalendar = str_replace ("[icon]", "<img src=\"templates/" . $_SESSION['tpl'] . "/images/folders/folder_calendar.gif\" border=\"0\" alt=\"" . $lang['Calendar'] . "\" />", $foldercalendar);
$foldercalendar = str_replace("[previewmode]", "HidePreview", $foldercalendar);
$folderlist .= $foldercalendar;
}
}
$PageFolderPane = str_replace ("[folderlinks]", $folderlist, $PageFolderPane);
$PageFolderPane = str_replace ("[folderoptions]", "<option value=\"INBOX\" selected=\"selected\">INBOX</option>", $PageFolderPane);
}
if ($newmail > 0) {
if (!isset($newmailmode) || $newmailmode == 1) {
$PageFolderPane = preg_replace("/(\[)(ifajax)(])(\r\n)*(.*)(\[\/ifajax\])/siU", "", $PageFolderPane);
$PageFolderPane = str_replace("[ifchecknewmail]", "", $PageFolderPane);
$PageFolderPane = str_replace("[/ifchecknewmail]", "", $PageFolderPane);
}
elseif ($newmailmode == 2) {
$PageFolderPane = preg_replace("/(\[)(ifchecknewmail)(])(\r\n)*(.*)(\[\/ifchecknewmail\])/siU", "", $PageFolderPane);
$PageFolderPane = str_replace("[ifajax]", "", $PageFolderPane);
$PageFolderPane = str_replace("[/ifajax]", "", $PageFolderPane);
}
else {
$PageFolderPane = preg_replace("/(\[)(ifchecknewmail)(])(\r\n)*(.*)(\[\/ifchecknewmail\])/siU", "", $PageFolderPane);
$PageFolderPane = preg_replace("/(\[)(ifajax)(])(\r\n)*(.*)(\[\/ifajax\])/siU", "", $PageFolderPane);
}
}
else {
$PageFolderPane = preg_replace("/(\[)(ifchecknewmail)(])(\r\n)*(.*)(\[\/ifchecknewmail\])/siU", "", $PageFolderPane);
$PageFolderPane = preg_replace("/(\[)(ifajax)(])(\r\n)*(.*)(\[\/ifajax\])/siU", "", $PageFolderPane);
}
// Legacy replace for old templates check new mail routine
$checknewmail = "<iframe src=\"checknew.php?" . strip_tags(SID) . "\" allowtransparency=\"true\" scrolling=\"no\" width=\"1\" height=\"1\" frameborder=\"0\" border=\"0\"></iframe>";
$PageFolderPane = str_replace ("[checknewmail]", $checknewmail, $PageFolderPane);
$checktime = $newmail * 1000;
$PageFolderPane = str_replace ("[checkrefresh]", $checktime, $PageFolderPane);
$PageFolderPane = str_replace ("[session_append]", $MainSettings->SessAppend_noecho($TransIDEnabled, 0), $PageFolderPane);
$PageFolderPane = str_replace ("[session_form]", $MainSettings->SessAppend_form($TransIDEnabled), $PageFolderPane);
$PageFolderPane = str_replace ("[session_force]", strip_tags(SID), $PageFolderPane);
$PageFolderPane = str_replace ("[session]", $MainSettings->SessAppend_noecho($TransIDEnabled, 1), $PageFolderPane);
// Debug variable
// echo microtime() . "<br />";
?>
|