Example #1
0
function restructureQuery($structure, $connection, $sql, $params, $operation, $pdo)
{
    $result = generalQuery($connection, $sql, $params, $operation, $pdo);
    $restructured = $operation === 0 && rightResult($result) ? restructureArray($result, $structure) : $result;
    return $restructured;
}
Example #2
0
function changeQueryIntoJSON($nameJSON, $structure, $connection, $sql, $params, $operation, $pdo)
{
    $result = generalQuery($connection, $sql, $params, $operation, $pdo);
    $restructured = $operation === 0 && rightResult($result) ? restructureArray($result, $structure) : $result;
    return changeArrayIntoJSON($nameJSON, $restructured);
}
Example #3
0
function getTransmision()
{
    $sql = "SELECT *, COUNT(*) AS SEN_Number\r\n            FROM camSeminuevos sen\r\n            GROUP BY SEN_Transmision\r\n            ORDER BY SEN_Id ASC\r\n            ";
    /*$structure = array(
          'id_mdo' => 'MDO_Id',
          'nombre_mdo' => 'MDO_Nombre',
          'id_marc' => 'MAR_Id',
          'nombre_marc' => 'MAR_Nombre',
          'cantidad' => 'MAR_Number',
      );*/
    $structure = array("modelo" => array("transmision" => "SEN_Transmision", "id_sen" => "SEN_Id", "cantidad" => "SEN_Number"));
    $params = array();
    $orderBy = array();
    $result = generalQuery(getConnection(), $sql, $params, 0, PDO::FETCH_ASSOC);
    $detail = array();
    $detail = multiLevelJSON($result, $structure, $orderBy);
    echo changeArrayIntoJSON('campa', $detail);
    //echo changeQueryIntoJSON('campa', $structure, getConnection(), $sql, $params, 0, PDO::FETCH_ASSOC);
}
Example #4
0
function getRental()
{
    $sql_agencias = "SELECT *\r\n                        FROM (\r\n                            SELECT *\r\n                            FROM camAgencias\r\n                            WHERE AGN_Tipo = 3\r\n                        ) agn\r\n                        ";
    $sql_telefonos = "SELECT *\r\n                        FROM camTelefonos\r\n                        WHERE TEL_AGN_Id = :telefonos\r\n                        ";
    $params_agencias = array();
    $structure_agencias = array('agnId' => 'AGN_Id', 'agpid' => 'AGN_AGP_Id', 'agnTipo' => 'AGN_Tipo', 'agnNombre' => 'AGN_Nombre', 'agnDireccion' => 'AGN_Dirección', 'agnSmall' => 'AGN_Small');
    $structure_telefonos = array('telId' => 'TEL_AGN_Id', 'telefono' => 'TEL_Telefono', 'call' => 'TEL_Call');
    $result_agencias = restructureQuery($structure_agencias, getConnection(), $sql_agencias, $params_agencias, 0, PDO::FETCH_ASSOC);
    for ($idx = 0; $idx < count($result_agencias); $idx++) {
        $agnId = $result_agencias[$idx]['agnId'];
        $result_agencias[$idx]['columns'] = $idx % 2 === 0 ? 'col-md-offset-7 col-sm-offset-5' : '';
        $result_agencias[$idx]['textAlign'] = $idx % 2 === 0 ? 'text-left' : 'text-right';
        $result_agencias[$idx]['direction'] = $idx % 2 === 0 ? 'pull-left' : 'pull-right';
        // TELEFONOS
        $params_telefonos = array('telefonos' => $agnId);
        $result_telefonos = generalQuery(getConnection(), $sql_telefonos, $params_telefonos, 0, PDO::FETCH_ASSOC);
        $result_telefonos = count($result_telefonos) > 0 ? restructureRow($result_telefonos[0], $structure_telefonos) : array();
        $result_agencias[$idx]['telefonos'] = $result_telefonos;
    }
    $json = changeArrayIntoJSON('campa', $result_agencias);
    echo $json;
}
Example #5
0
function checkbrute($userId)
{
    //Get timestamp of current time
    $now = time();
    //All login attempts are counted from the past 2 hours.
    $validAttempts = $now - 2 * 60 * 60;
    $sql = "SELECT ATT_Time\r\n            FROM camAttempts\r\n            WHERE ATT_USR_Id = :usr_id\r\n            AND ATT_Time > :valid_attempts";
    $structure = array('password' => 'DIS_Password');
    $params = array('usr_id' => $userId, 'valid_attempts' => $validAttempts);
    $result = generalQuery(getConnection(), $sql, $params, 0, PDO::FETCH_ASSOC);
    if (count($result)) {
        if (rightResult($result)) {
            //If there have been more than 5 failed logins
            if (count($result) > 5) {
                return true;
            } else {
                return false;
            }
        } else {
            //Could not create a prepared statement
            header("Location: ../error.php?err=Database error: cannot prepare statement");
            exit;
        }
    }
    return false;
}