Ejemplo n.º 1
0
 */
include "messenger.php";
include "dbMessenger.php";
$contacts = $_POST['contacts'];
$user_id = $_POST['id'];
if (!isset($contacts) || !isset($user_id)) {
    echo "Not all required POST parameters are set";
}
if (strlen($contacts) < 4) {
    echo "Invalid JSON : Too short!";
}
$arrayOfContacts = json_decode($contacts, true);
if (isset($arrayOfContacts)) {
    $matchedContacts = compare_contacts($arrayOfContacts, $user_id);
} else {
    echo "Server Error : during JSON decoding  with JSON Error: " . json_last_error() . " and JSON: " . $contacts;
}
$newCreated = false;
$contactsExisting = false;
if (!empty($matchedContacts)) {
    $newCreated = create_contacts($user_id, $matchedContacts);
    $contactsExisting = checkforExistingContacts($matchedContacts);
    header('Content-Type: application/json');
    if ($newCreated || $contactsExisting) {
        echo createJSONResponseForNewContacts($matchedContacts, $user_id);
    } else {
        echo "OK : No new contacts created" . var_dump($matchedContacts);
    }
} else {
    echo "Non of your contacts is using this messenger";
}
Ejemplo n.º 2
0
$JSON = '[ { "number" : "02344232144444441" , "name" :  "hansi" }]';
$arrayOfContacts = json_decode($JSON, true);
$matchedContacts = compare_contacts($arrayOfContacts, $user_id);
if (empty($matchedContacts)) {
    echo "compare_contacts(): unknown number </td><td> <span class='success' style='color:green'>successful</span><br></td>";
} else {
    echo "compare_contacts(): unknown number </td><td> <span class='notsuccess' style='color:red'>not successful</span><br></td>";
}
?>
    </tr>
    <tr>
        <td>Check if a contact can be created with valid data</td>
        <td><?php 
$user_id = 1;
$mobileNumber = generateRandNumber(12);
$password = "******";
create_user($mobileNumber, $password);
$JSON = '[ { "number" : "' . $mobileNumber . '" , "name" :  "Test User" }]';
$arrayOfContacts = json_decode($JSON, true);
$matchedContacts = compare_contacts($arrayOfContacts, $user_id);
if (create_contacts($user_id, $matchedContacts)) {
    echo "create_contacts(): valid data </td><td> <span class='success' style='color:green'>successful</span><br></td>";
} else {
    echo "create_contacts(): valid data </td><td> <span class='notsuccess' style='color:red'>not successful</span><br></td>";
}
?>
    </tr>
</table>
</body>
</html>