Exemplo n.º 1
0
    // read note
    $manager->read_note($arg_id);
    $note = $manager->get($arg_id);
    // return note (or error).
    if (empty($note)) {
        echo '{"error": 302, "message": "Note with id (', $arg_id, ') could not be found."}';
        die;
    } else {
        echo json_encode($note);
    }
    //## Delete a note ##//
} elseif ("delete" == $arg_action) {
    // return error if 'id' is not set
    if (!isset($_POST['id']) || $_POST['id'] == '') {
        echo '{"error": 401, "message": "\'id\' must be set for action (read)."}';
        die;
    } else {
        $arg_id = $_POST['id'];
    }
    // delete the note
    // return id of note if successful or an error otherwise
    if (!$manager->delete_note($arg_id)) {
        echo '{"error": 402, "message": "Could not delete the note."}';
        die;
    }
    echo '{"id": ', $arg_id, '}';
    //## Action not found ##//
} else {
    echo '{"error": 101, "message": "Action not found (', $arg_action, ')"}';
    die;
}