Exemple #1
0
    // get id
    $id = isset($_GET['id']) ? $_GET['id'] : '';
    // contact does not exist
    if (!$db->existsContact($id)) {
        // give notice to client
        http_response_code(404);
        exit(json_encode(array('status' => 404, 'message' => 'delete failed: contact not found')));
    }
    // delete it
    $db->deleteContact($id);
    // give notice to client
    exit(json_encode(array('status' => 200, 'message' => 'delete OK')));
}
// sort action
if ($action == 'sort') {
    // get contact ids
    $contactIds = isset($_GET['contact']) ? $_GET['contact'] : array();
    // we have passed in contacts
    if (sizeof($contactIds) > 0) {
        foreach ($contactIds as $i => $contactId) {
            $contact = $db->getContact($contactId);
            $contact->sortorder = $i + 1;
            $db->updateContact($contact);
        }
    }
    // give notice to client
    exit(json_encode(array('status' => 200, 'message' => 'sorting OK')));
}
// invalid action
http_response_code(400);
exit(json_encode(array('status' => 400, 'message' => 'invalid API call')));