<?php
/*
This file is part of Thomas Bley's moregroupware webmail2/calendar2/admin2 module. (tb-mgw)

More information:
-----------------

Simple Groupware Solutions Thomas Bley
Fichtenstr. 23
Germany, 85640 Putzbrunn

Contact:
--------

info@simple-groupware.de

http://www.simple-groupware.de


Copyright 2002-2003 Thomas Bley
tb-mgw is distributed under the terms of the GNU General Public License 

tb-mgw is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

tb-mgw is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with tb-mgw; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// Myfolders
// Moregroupware.org

$myEnv["module"] = "webmail2";
$myEnv["stdsmenu"] = false;
$myEnv["output"] = "html";

include("../../config.inc.php");
include(INCLUDEPATH . "container.inc.php");
include(WM2_INC_DIR.'accounts_inc.php');

error_reporting  (E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

$myvars = array("error","reload","mode");
foreach ($myvars as $thevar) {
  ${$thevar} = (isset($_GET[$thevar])) ? $_GET[$thevar] : (isset($_POST[$thevar]) ? $_POST[$thevar] : "");
}
$MGW = $_SESSION["MGW"];
$username = $MGW->username;

if ($mode=="my") {
  $user_id = $MGW->userid;
} else {
  $user_id = 0;
}

$messagecount = 0;
$tree = array();
$folders = array();

$sql = "select * from mgw_webmail2_mailboxes where user_id=".(int)$user_id." order by mboxname!='inbox',mboxparent,mbox_protect desc,mboxname";
get_folders2($sql);
  
calc_ebene($tree,0);  
  
$folders2 = array();
treesort($tree);

$folders = $folders2;
unset($folders2);

$errormessage = "";
if ($error=="folderexists") { $errormessage = $hashmap["myfolders_folder_exists"]; }
elseif ($error=="folderprotect2") { $errormessage = $hashmap["myfolders_folder_cant_delete"]; }
elseif ($error=="folderhassubs") { $errormessage = $hashmap["myfolders_folder_has_subfolders"];}

if ($errormessage!="") {$errormessage="<center><font color=\"#ff0000\"><b>".$errormessage."</b></font></center><br>";}

if ($reload=="true") {$reload = 'onload="top.mailfolders.location.reload();"';} else {$reload = "";}

$smarty->assign("mode", $mode);
$smarty->assign("reload", $reload);
$smarty->assign("username", ucfirst($username));
$smarty->assign("messagecount", $messagecount);
$smarty->assign("errormessage", $errormessage);
$smarty->assign("folders", $folders);

$smarty->display("myfolders.tpl");
?>
