function removeContact($id)
{
    $d = loadContacts();
    $found = 0;
    foreach ($d as $key => $ds) {
        if ($ds['id'] == $id) {
            unset($d[$key]);
            $found = $found + 1;
        }
    }
    if ($found == 1) {
        saveContacts(array_values($d));
    }
    return $found;
}
        echo "{ \"message\": \" ERROR: no eventType key found\" }";
        return;
    }
    // get the eventNotes
    $eventNotes = "";
    if (!isset($_POST['eventNotes'])) {
        $eventNotes = "";
    } else {
        $eventNotes = urldecode($_POST['eventNotes']);
    }
    // get the event date
    $date = "";
    if (!isset($_POST['date'])) {
        $date = date(DATE_ATOM);
    } else {
        $date = urldecode($_POST['date']);
    }
    // add a new event to the events array
    $ar['events'] = array(array("eventType" => $eventType, "eventNotes" => $eventNotes, "username" => "web", "date" => $date, "serverdate" => date(DATE_ATOM)));
    // add the contact array to the list of contacts
    $d = loadContacts();
    $d[] = $ar;
    saveContacts($d);
    // return ok message
    echo json_encode(array("message" => "contact created", "contactID" => $ar['contactID'], "ok" => 1));
    return;
} else {
    // create error, action is not create
    echo json_encode(array("message" => "Error: action is not create"));
    return;
}
Example #3
0
function delete($contactID)
{
    $d = loadContacts();
    $found = 0;
    foreach ($d as $key => $ds) {
        if ($ds['contactID'] == $contactID) {
            unset($d[$key]);
            $found = $found + 1;
        }
    }
    if ($found == 1) {
        saveContacts(array_values($d));
    }
    return $found;
}