<?php
/* $Id: index.php,v 1.90 2003/11/12 13:26:22 k-fish Exp $ */

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

require_once("../../config.inc.php");
require_once(INCLUDEPATH . "container.inc.php");
require_once("inc/todo.class.php");

$todoObj = new Todo();

if(isset($_POST["op"])){
    if ($_POST["op"] == "create"){
	$todoObj->opCreate();
    }

    if ($_POST["op"] == "update"){
	$todoObj->opUpdate();
    }
}

if(isset($_GET["view"])){
    if ($_GET["view"] == "newform") {
	$todoObj->viewNewForm();
	exit();
    }
    
    if ($_GET["view"] == "editform") {
	$todoObj->viewEditForm();
	exit();
    }

    if ($_GET["view"] == "details") {
	$todoObj->viewDetails();
	exit();
    }
}

// =================================================
// Todo delete FIXME var handling, encapsulation
// =================================================
// delete only when user said so
if(isset($_POST["confirmation_yes"])) {
    $sql = "DELETE FROM mgw_todo WHERE id=".(int)$_POST["itemid"];
    if(!$conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
}
if (isset($_GET["view"]) && $_GET["view"] == "delete"){
    $id = (int) $_GET["id"];
    // show confirmation screen if it wasnt there so far
    $sql = "SELECT * FROM mgw_todo WHERE id=".$id;
    if(!$res = $conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
    $row = $res->FetchRow();
    $smarty->assign("itemid", $row["id"]);
    $smarty->assign("deletedetail1", $row["header"]);
    $smarty->assign("deletedetail2", $row["description"]);
	
    $smarty->assign("suclass", "submit");
    $smarty->assign("menuid", "3");
    $smarty->assign("parms", str_replace("view=delete","",$_SERVER["QUERY_STRING"]));
	
    $smarty->display($appconf["gentemplates"] ."/delete_item.tpl");
    exit();
}	

$todoObj->viewList();

?>
