<?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
*/

// Index
// Moregroupware.org

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

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

$smarty->assign("topheight", 67); // 88-21

$width_treeframe = $MGW->settings["wm2_width_treeframe"];
if (is_numeric($width_treeframe) and $width_treeframe > 0) {
  $smarty->assign("width_treeframe", $width_treeframe);
} else {
  $smarty->assign("width_treeframe", 200);
}

$width_mailfolders = $MGW->settings["wm2_width_mailfolders"];
if (is_numeric($width_mailfolders) and $width_mailfolders > 0) {
  $smarty->assign("width_mailfolders", $width_mailfolders);
} else {
  $smarty->assign("width_mailfolders", 100);
}

if ($MGW->settings["wm2_always_hide_sidebar"]) {
  $smarty->assign("width_mailfolders", 0);
}

if (isset($MGW->settings["wm2_show_top_menu"]) and $MGW->settings["wm2_show_top_menu"]) {
  $smarty->assign("wm2_show_top_menu",true);
}

$myvars = array("new","mbox_id","rightframe","todo");
foreach ($myvars as $thevar) {
  ${$thevar} = (isset($_GET[$thevar])) ? $_GET[$thevar] : (isset($_POST[$thevar]) ? $_POST[$thevar] : "");
}
$MGW = $_SESSION["MGW"];
$user_id = $MGW->userid;
$username = $MGW->username;

// #################################################### //
// creating default database mailboxes for POP3 access. //
// #################################################### //

if ($MGW->settings["wm2_enabledownload"]) {
  checkdir(STORE_FOLDER,false);
} else {
  checkdir(STORE_FOLDER,true);
}

checkdir(CACHE_FOLDER."gpg/",true);
checkdir(CACHE_FOLDER."sendmail/",true);
checkdir(CACHE_FOLDER."readmessage/",true);
checkdir(CACHE_FOLDER."attachments/",true);
checkdir(CACHE_FOLDER."img/",false);

checkdir(CACHE_FOLDER."imap/",false);
checkdir(CACHE_FOLDER."imap/tree/",true);
checkdir(CACHE_FOLDER."imap/readmessage/",true);
checkdir(CACHE_FOLDER."imap/attachments/",true);
checkdir(CACHE_FOLDER."imap/img/",false);

error_reporting  (E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// #################################################### //
// creating default database mailboxes for POP3 access. //
// #################################################### //

if (!isset($MGW->settings["wm2_disable_public_folders"]) or !$MGW->settings["wm2_disable_public_folders"]) {
  create_boxes(array(array(ucfirst($username),getboxid("public",0,0),0)));
}

create_boxes(array(array("draft",0,$user_id),array("sent",0,$user_id),array("trash",0,$user_id),array("inbox",0,$user_id)));
create_boxes(array(array("spam",getboxid("trash",0,$user_id),$user_id)));

/*
$tar = new tar();
$tar->addFile("inc/smenu.php");
$tar->addData("test.txt","blabla",time());
$tar->toTar(CACHE_FOLDER."new.tar",false);
unset($tar);

$tar = new tar();
$tar->openTAR(CACHE_FOLDER."new.tar");

print_r($tar->files);

unset($tar);

die;
*/

/*
$box[3] = $user_id;

$msg_id = mgw_genID('mgw__seq_messages');
$uid = "<".date("YmdHi").".".substr(ereg_replace("/","X",md5(mt_rand(1,6000))),0,12)."@".$_SERVER["SERVER_NAME"].">";

// add quoting ??
$sql = "INSERT INTO mgw_webmail2_messages (msg_cache,message_id,account_name,uid,type,mbox_id,user_id,header_from,header_to,header_cc,header_bcc,header_replyto,header_date,header_subject,header_size,header_inreplyto,msg_body,recentbit,readbit,replybit,draftbit,flaggedbit,forwardbit,attachbit) VALUES('9426c311e76888b3b2368150cd05f362',".$msg_id.",'','".$uid."','eml',".getboxid("inbox",0,$box[3]).",".$box[3].",'Thomas Bley <thomas.bley@simple-groupware.de>','MoreGroupWare-User','','','','".time()."','Small Webmail Manual #1',".filesize("docu/docu1.eml").",'','docu/docu1.eml','1','0','0','0','3','0','0')";
if(!$res = $conn->Execute($sql)) die(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
*/

if ($rightframe=="") {$rightframe = "index2.php?new=".$new."&account=0&mbox_id=".$mbox_id."&todo=".$todo."&".SID;}
if ($rightframe=="fetchmail.php") {$rightframe.="?action=indexer&new=yes&".SID;}
$smarty->assign("rightframe", $rightframe."&".SID);


$smarty->assign("myimgpathmaster","templates/default/media");
$smarty->display("index.tpl");
?>
