forked from Stratusolve/Stratusolve-Exercise-Old
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_task.php
More file actions
47 lines (37 loc) · 1.53 KB
/
update_task.php
File metadata and controls
47 lines (37 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
header('Content-type:application/json;charset=utf-8');
/**
* This script is to be used to receive a POST with the object information and then either updates, creates or deletes the task object
*/
require('Task.class.php');
// Assignment: Implement this script
$message = 'You either tried accessing this directly or submitted an invalid action. Please trying saving the form again';
$success = false;
if (isset($_POST)) {
$action = filter_input(INPUT_POST, 'action', FILTER_SANITIZE_STRING);
$taskId = filter_input(INPUT_POST, 'task_id', FILTER_SANITIZE_NUMBER_INT);
$taskClass = new Task($taskId);
switch ($action) {
case 'save' :
$taskName = filter_input(INPUT_POST, 'task_name', FILTER_SANITIZE_STRING);
$taskDescription = filter_input(INPUT_POST, 'task_description', FILTER_SANITIZE_STRING);
$taskClass->setTaskName($taskName);
$taskClass->setDescription($taskDescription);
$taskClass->Save();
$success = true;
$message = 'Task has been successfully created/updated';
break;
case 'delete' :
$deleted = $taskClass->Delete();
$message = "Something went wrong, couldn't delete task";
if ($deleted) {
$success = true;
$message = "Task has been successfully deleted";
}
break;
default :
$message = 'Unknown action selected';
}
}
echo json_encode(['message' => $message, 'success' => $success]);
exit;