Пример #1
0
function deleteFriendship()
{
    global $friendTable, $userTable;
    /* verifica se existe alguma informacao no corpo da mensagem */
    $request = Slim::getInstance()->request();
    $json = readRequestBody($request);
    if (!$json) {
        $response["status"] = 0;
        echo json_encode($response);
        return;
    }
    /* lendo dados do json */
    $appID = $json->appID;
    $crypt_data = $json->data;
    $iv = $json->iv;
    $json = json_decode(decrypt_data($appID, $crypt_data, $iv));
    $id1 = $json->idusuario_a;
    $id2 = $json->idusuario_b;
    $response["status"] = 1;
    $dbh = getConnection();
    $sql = "DELETE FROM {$friendTable} where (idusuario_a = :id1 and\n\t\t\t\tidusuario_b = :id2) or (idusuario_a = :id2 and\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tidusuario_b = :id1)";
    $stmt = $dbh->prepare($sql);
    $stmt->bindParam(":id1", $id1);
    $stmt->bindParam(":id2", $id2);
    $stmt->execute();
    closeConnection($dbh);
    $json = json_encode($response);
    $data = encrypt_data($appID, $json);
    echo json_encode($data);
}
Пример #2
0
function addUserObj()
{
    global $patrimonio;
    /* verifica se existe alguma informacao no corpo da mensagem */
    $request = Slim::getInstance()->request();
    $json = readRequestBody($request);
    if (!$json) {
        $response["status"] = 0;
        echo json_encode($response);
        return;
    }
    /* lendo dados do json */
    $appID = $json->appID;
    $crypt_data = $json->data;
    $iv = $json->iv;
    $json = json_decode(decrypt_data($appID, $crypt_data, $iv));
    $userId = $json->userId;
    $objId = $json->objId;
    $objType = $json->objType;
    /* the objType doesn't exist */
    if (!isset($patrimonio[$objType])) {
        $response["status"] = 0;
        echo json_encode($response);
        return;
    }
    $response["status"] = 1;
    $dbh = getConnection();
    $obj = $patrimonio[$objType][0];
    $possui = $patrimonio[$objType][1];
    try {
        /* if the ids exist in their tables and are not linked, add a new row */
        $sql = "insert into {$possui} select idusuario, id{$obj} from\n\t\t\t\t\tusuario, obj{$obj} where idusuario = :userID and\n\t\t\t\t\t\tid{$obj} = :objID and (select count(*) from {$possui} where\n\t\t\t\t\t\t\tfk_idUser = :userID and fk_id{$obj} = :objID) = 0";
        $stmt = $dbh->prepare($sql);
        $stmt->bindParam(":userID", $userId);
        $stmt->bindParam(":objID", $objId);
        $stmt->execute();
    } catch (PDOException $e) {
        /* couldn't insert */
        $response["status"] = 0;
    }
    closeConnection($dbh);
    $json = json_encode($response);
    $data = encrypt_data($appID, $json);
    echo json_encode($data);
    return;
}
Пример #3
0
function removeObjFilm()
{
    global $filmTable;
    /* verifica se existe alguma informacao no corpo da mensagem */
    $request = Slim::getInstance()->request();
    $json = readRequestBody($request);
    if (!$json) {
        $response["status"] = 0;
        echo json_encode($response);
        return;
    }
    /* lendo dados do json */
    $appID = $json->appID;
    $crypt_data = $json->data;
    $iv = $json->iv;
    $json = json_decode(decrypt_data($appID, $crypt_data, $iv));
    $id = $json->idFilme;
    $response["status"] = 1;
    $dbh = getConnection();
    $sql = "delete from {$filmTable} where idFilme = :id";
    $stmt = $dbh->prepare($sql);
    $stmt->bindParam(":id", $id);
    $stmt->execute();
    closeConnection($dbh);
    $json = json_encode($response);
    $data = encrypt_data($appID, $json);
    echo json_encode($data);
    return;
}
Пример #4
0
function changeEmprestimoStatus()
{
    global $loanTable;
    /* verifica se existe alguma informacao no corpo da mensagem */
    $request = Slim::getInstance()->request();
    $json = readRequestBody($request);
    if (!$json) {
        $response["status"] = 0;
        echo json_encode($response);
        return;
    }
    /* lendo dados do json */
    $appID = $json->appID;
    $crypt_data = $json->data;
    $iv = $json->iv;
    $json = json_decode(decrypt_data($appID, $crypt_data, $iv));
    $idEmp = $json->idemprestimo;
    $status = $json->status;
    $response["status"] = 1;
    $dbh = getConnection();
    $sql = "update {$loanTable} set status = :status where idemprestimo = :idEmp";
    try {
        $stmt = $dbh->prepare($sql);
        $stmt->bindParam(":idEmp", $idEmp);
        $stmt->bindParam(":status", $status);
        $stmt->execute();
    } catch (PDOException $e) {
        $response["status"] = 0;
    }
    closeConnection($dbh);
    $json = json_encode($response);
    $data = encrypt_data($appID, $json);
    echo json_encode($data);
    return;
}
Пример #5
0
function checkUser()
{
    global $userTable;
    /* verifica se existe alguma informacao no corpo da mensagem */
    $request = Slim::getInstance()->request();
    $json = readRequestBody($request);
    if (!$json) {
        $response["status"] = 0;
        echo json_encode($response);
        return;
    }
    /* lendo dados do json */
    $appID = $json->appID;
    $crypt_data = $json->data;
    $iv = $json->iv;
    $json = json_decode(decrypt_data($appID, $crypt_data, $iv));
    $email = $json->email;
    $pwd = $json->senha;
    $response["status"] = 1;
    $dbh = getConnection();
    $sql = "SELECT * from {$userTable} where email = :email and senha = :pwd";
    $stmt = $dbh->prepare($sql);
    $stmt->bindParam(":email", $email);
    $stmt->bindParam(":pwd", $pwd);
    $stmt->execute();
    $res = $stmt->fetchAll(PDO::FETCH_ASSOC);
    if (count($res) == 0) {
        $response["status"] = 0;
    }
    closeConnection($dbh);
    $json = json_encode($response);
    $data = encrypt_data($appID, $json);
    echo json_encode($data);
    return;
}