<?php
include("../public/impOpreation.php");

$do = $_GET['do'];
$today = date("Y-m-d H:i:s");
$date = date("Y-m-d");
$userid = $_SESSION['userid'];
if (empty($do)) {  
    
    $smarty->display("header.html");
    $smarty->display("taskstypesview/add.html");
    $smarty->display("footer.html");
} elseif ($do == "show") {
    $taskstypes = R::findAll('taskstypes','del = 0');
    $smarty->assign('taskstypes', $taskstypes);
    $smarty->display("header.html");
    $smarty->display("taskstypesview/show.html");
    $smarty->display("footer.html");
} elseif ($do == "edit") {
    $id = filter_input(INPUT_GET, 'id');
    $tasktype = R::load('taskstypes', $id);
    $smarty->assign('tasktype', $tasktype);
    $smarty->display("header.html");
    $smarty->display("taskstypesview/edit.html");
    $smarty->display("footer.html");   
}else if ($do == 'add') {
    $typename = filter_input(INPUT_POST, 'typename');
    $taskstypes = R::dispense('taskstypes');
    $taskstypes->del = 0;
    $taskstypes->today = $today;          
    $taskstypes->userid = $userid;
    $taskstypes->typename = $typename;
    try {
       R::store($taskstypes);    
       header("location:taskstypes.php?do=show");
    } catch (Exception $e) {
       header("location:taskstypes.php");
    }
}else if ($do == 'update') {
    $id = filter_input(INPUT_POST, 'id');
    $typename = filter_input(INPUT_POST, 'typename');
    $taskstypes = R::load('taskstypes',$id);
    $taskstypes->updatetoday = $today;          
    $taskstypes->updateuserid = $userid;
    $taskstypes->typename = $typename;
    try {
       R::store($taskstypes); 
       header("location:taskstypes.php?do=show");
    } catch (Exception $e) {
       header("location:taskstypes.php?do=edit&id=".$id);
    }
}else if ($do == 'del') {
    $id = filter_input(INPUT_GET, 'id');
    $taskstypes = R::load('taskstypes',$id);
    $taskstypes->del = 1;
    $taskstypes->todaydel = $today;  
    $taskstypes->useriddel = $userid;
    try {
       R::store($taskstypes); 
       header("location:taskstypes.php?do=show");
    } catch (Exception $e) {
       header("location:taskstypes.php?do=show");
    }
}






?>