'Malformed URI request.', ]; echo json_encode($response); } function handle_login() { $response = ['log' => []]; if (isset($_POST['user_id']) && isset($_POST['username']) && isset($_POST['role'])) { $response['log'][] = 'Required parameters met. Logging user in.'; $_SESSION['user_id'] = $_POST['user_id']; $_SESSION['username'] = $_POST['username']; $_SESSION['role_id'] = $_POST['role']; $response['redirect'] = 'articles.php?view=list'; } echo json_encode($response); } function handle_todo() { include 'functions/todo_functions.php'; $response = ['log' => []]; if (isset($_POST['todo_id']) && isset($_POST['action_id'])) { $response['log'][] = 'Required parameters met.'; switch ($_POST['action_id']) { case 'status': $response['log'][] = 'Changing status on ' . $_POST['todo_id'] . ' to ' . $_POST['status'] . '.'; change_status($_POST['todo_id'], $_POST['status']); break; case 'create_update_todo': if ($_POST['todo_id'] != -1) { $response['log'][] = 'Updating todo information on ' . $_POST['todo_id'] . '.'; update_todo($_POST['todo_id'], urldecode($_POST['todo'])); } else { $response['log'][] = 'Creating todo information on ' . $_POST['todo_id'] . '.'; create_todo(urldecode($_POST['todo'])); } break; } } echo json_encode($response); }