Exemplo n.º 1
0
// BDD CONNECTION
$mysqli = new mysqli(null, 'root', '', 'home_presence', null, '/cloudsql/home-presence-1138:main');
if ($mysqli->connect_errno) {
    die("Echec lors de la connexion à MySQL");
}
// INCLUDES
require_once 'config/api.key.php';
require_once 'classes/OauthConnection.php';
require_once 'classes/SenseAPI.php';
require_once 'classes/Feed.php';
require_once 'classes/Utils.php';
require_once 'classes/BDD.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $json = json_decode(file_get_contents('php://input'));
    $data = $json->data;
    if ($json->type == "presence") {
        if (strpos($json->profile, "Mother") === FALSE) {
            if ($data->code == 200 || $data->code == 201) {
                BDD::storeCookiePresence($mysqli, $json->nodeUid, TRUE, $json->gatewayNodeUid, $_SERVER['REQUEST_TIME'], json_encode($json));
            } else {
                BDD::storeCookiePresence($mysqli, $json->nodeUid, FALSE, $json->gatewayNodeUid, $_SERVER['REQUEST_TIME'], json_encode($json));
            }
        } else {
            if ($data->code == 200 || $data->code == 201) {
                BDD::storeMotherPresence($mysqli, $json->nodeUid, TRUE, $_SERVER['REQUEST_TIME'], json_encode($json));
            } else {
                BDD::storeMotherPresence($mysqli, $json->nodeUid, FALSE, $_SERVER['REQUEST_TIME'], json_encode($json));
            }
        }
    }
}