Example #1
0
 public function __construct(Site $site, &$session, $post)
 {
     $tasks = new Tasks($site);
     $user = $session[User::SESSION_NAME];
     $root = $site->getRoot();
     if (isset($post['add'])) {
         $day = strip_tags($post['day']);
         $title = strip_tags($post['title']);
         $notes = strip_tags($post['notes']);
         $notes = $notes === null ? '' : $notes;
         $priority = strip_tags($post['priority']);
         $row = array("id" => 0, "day" => $day, "title" => $title, "notes" => $notes, "priority" => $priority);
         $task = new Task($row);
         $tasks->addTask($user->getId(), $task);
         $this->redirect = "/tasks.php";
         return;
     }
     if (isset($post['edit'])) {
         $id = strip_tags($post['id']);
         $day = strip_tags($post['day']);
         $title = strip_tags($post['title']);
         $notes = strip_tags($post['notes']);
         $notes = $notes === null ? '' : $notes;
         $priority = strip_tags($post['priority']);
         $row = array("id" => $id, "day" => $day, "title" => $title, "notes" => $notes, "priority" => $priority);
         $task = new Task($row);
         $tasks->updateTask($user->getId(), $task);
         $this->redirect = "/tasks.php";
         return;
     }
     if (isset($post['delete'])) {
         $id = strip_tags($post['id']);
         $tasks->deleteTask($user->getId(), $id);
         $this->redirect = "/tasks.php";
         return;
     }
 }
if (isset($_REQUEST['id'])) {
    include_once "Tasks.php";
    $obj_task = new Tasks();
    $tid = $_REQUEST['id'];
    $tname = $_REQUEST['taskname'];
    $tdesc = $_REQUEST['description'];
    $start_date = $_REQUEST['sdate'];
    $end_date = $_REQUEST['edate'];
    $loc = $_REQUEST['location'];
    /**
     * A method to check is the task is successfully updated
     *
     *@param string  $tid id of the task
     *@param varchar $name name of the task
     *@param varchar description of task
     *@param date $s_date start date of the job
     *@param date $e_date end date of the job
     *@param string $location location of job
     *@return Task successfully updated or update not successful
     */
    if (!$obj_task->updateTask('$tid', '$tname', '$tdesc', '$start_date', '$end_date', '$loc')) {
        echo "The task was not updated";
    } else {
        echo "A task was successfully updated";
    }
}
?>
	</body>
</html>