<?php

require_once "../header.php";

$flag = Task::INCOMPLETE;
if ( $_SESSION['showalltasks'] ) $flag = Task::ALLTASKS;
$tasks = Task::getList($flag);
$data = array();
$data["error"] = false;
$data["message"] = "Listing " . (($flag == Task::INCOMPLETE) ? "Incomplete Tasks" : "All Tasks");
$data["tasks"] = $tasks;
$data["showalltasks"] = $_SESSION['showalltasks'];

pushData();

exit();

function pushData($errormsg = null) {
    global $data;

    if ( !is_null($errormsg) ) {
        $data["error"] = true;
        $data["message"] = $errormsg;
    }
    header('Content-Type: application/json');
    echo json_encode($data);
    exit();
}
