Exemple #1
0
<?php

include 'connection.php';
include 'functions.php';
$mode = $_POST['syncMode'];
$user_id = $_POST['user_id'];
if ($mode == "CS") {
    $tableName = $_POST['tableName'];
    $tableRows = $_POST['tableRows'];
    $rowArray = json_decode($tableRows, true);
    $insertCounter = 0;
    $updateCounter = 0;
    add_rows_to_table($tableName, $rowArray, $connection);
} else {
    if ($mode == "SC") {
        echo push_server_changes(false, $user_id);
    } else {
        echo "Invalid Request";
    }
}
    $res = $stmt->execute();
    $count = $stmt->rowCount();
    $response = array();
    if ($count == 0) {
        $response["result"] = "error";
        $response["data"] = "Invalid Credentials";
    } else {
        $row = $stmt->fetch();
        if (strcasecmp($firstName, $row["first_name"]) != 0) {
            $response["result"] = "error";
            $response["data"] = "First name given do not match";
        } else {
            $response["result"] = "success";
            $row = $stmt->fetch();
            $start_date = $row["program_start_date"];
            $cur_date = date("Y-m-d");
            if ($cur_date < $start_date) {
                $response["result"] = "error";
                $response["data"] = "Program hasn't started yet";
            } else {
                $response["data"] = push_server_changes(false, $ID);
            }
        }
    }
    echo json_encode($response);
} catch (Exception $e) {
    $exception_response = array();
    $exception_response["result"] = "server_error";
    $exception_response["data"] = json_encode($e);
    echo json_encode($exception_response);
}