196 lines
4.8 KiB
PHP
196 lines
4.8 KiB
PHP
<?php
|
|
if (isset($_SERVER['HTTP_PROJECT'])) {
|
|
$project_name = $_SERVER['HTTP_PROJECT'];
|
|
if (isset($project_name)) {
|
|
header('Content-Type:text/html; charset=UTF-8', true, 200);
|
|
} else {
|
|
header('Content-Type:text/html; charset=UTF-8', true, 301);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
ini_set('serialize_precision', -1);
|
|
|
|
function exception_error_handler($severity, $message, $file, $line)
|
|
{
|
|
if (!(error_reporting() & $severity)) {
|
|
return;
|
|
}
|
|
throw new ErrorException($message, 0, $severity, $file, $line);
|
|
}
|
|
set_error_handler('exception_error_handler');
|
|
$sql = array();
|
|
function insert($query)
|
|
{
|
|
global $sql;
|
|
array_push($sql, array(
|
|
'insert' => $query,
|
|
));
|
|
}
|
|
function select($query)
|
|
{
|
|
global $sql;
|
|
array_push($sql, array(
|
|
'select' => $query,
|
|
));
|
|
}
|
|
function select_ru($query)
|
|
{
|
|
global $sql;
|
|
array_push($sql, array(
|
|
'select_ru' => $query,
|
|
));
|
|
}
|
|
function update($query)
|
|
{
|
|
global $sql;
|
|
array_push($sql, array(
|
|
'update' => $query,
|
|
));
|
|
}
|
|
function delete($query)
|
|
{
|
|
global $sql;
|
|
array_push($sql, array(
|
|
'delete' => $query,
|
|
));
|
|
}
|
|
function querySelect_ru($sql_query)
|
|
{
|
|
global $conn;
|
|
global $response;
|
|
global $multiSelect;
|
|
$result = sqlsrv_query($conn, $sql_query);
|
|
$items = array();
|
|
while ($row = sqlsrv_fetch_object($result)) {
|
|
foreach ($row as $key=> &$value) {
|
|
if (is_string($value)) {
|
|
$value = iconv('windows-1251', 'UTF-8', $value);
|
|
}
|
|
if (is_numeric($value)) {
|
|
$value = round($value, 4);
|
|
}
|
|
$key = iconv('windows-1251', 'UTF-8', $key);
|
|
$a[$key]=$value;
|
|
}
|
|
unset($value);
|
|
unset($key);
|
|
array_push($items, $a);
|
|
}
|
|
if (true == $multiSelect) {
|
|
array_push($response, $items);
|
|
} else {
|
|
echo json_encode($items);
|
|
}
|
|
|
|
if (false === $result) {
|
|
if (null != ($errors = sqlsrv_errors())) {
|
|
header('Content-Type:text/html; charset=UTF-8', true, 301);
|
|
}
|
|
}
|
|
}
|
|
|
|
function querySelect($sql_query)
|
|
{
|
|
global $conn;
|
|
global $response;
|
|
global $multiSelect;
|
|
$result = sqlsrv_query($conn, $sql_query);
|
|
$items = array();
|
|
while ($row = sqlsrv_fetch_object($result)) {
|
|
foreach ($row as &$value) {
|
|
if (is_string($value)) {
|
|
$value = iconv('windows-1251', 'UTF-8', $value);
|
|
}
|
|
if (is_numeric($value)) {
|
|
$value = round($value, 4);
|
|
}
|
|
}
|
|
unset($value);
|
|
$items[] = $row;
|
|
}
|
|
if (true == $multiSelect) {
|
|
array_push($response, $items);
|
|
} else {
|
|
echo json_encode($items);
|
|
}
|
|
|
|
if (false === $result) {
|
|
if (null != ($errors = sqlsrv_errors())) {
|
|
header('Content-Type:text/html; charset=UTF-8', true, 301);
|
|
}
|
|
}
|
|
}
|
|
function queryOther($sql_query)
|
|
{
|
|
global $conn;
|
|
$result = sqlsrv_query($conn, $sql_query);
|
|
$rows_affected = sqlsrv_rows_affected($result);
|
|
//if (false === $rows_affected) {
|
|
if ($rows_affected >= 1) {
|
|
header('Content-Type:text/html; charset=UTF-8', true, 200);
|
|
} else {
|
|
header('Content-Type:text/html; charset=UTF-8', true, 301);
|
|
}
|
|
//}
|
|
}
|
|
|
|
// include("libs/hs256.php");
|
|
// include("libs/JWT.php");
|
|
// use \Firebase\JWT\JWT;
|
|
|
|
// try {
|
|
// $JWTdecoded = JWT::decode($jwtToken, $secret, array('HS256'));
|
|
// } catch (\Throwable $th) {
|
|
|
|
// }
|
|
|
|
include_once 'connection.php';
|
|
include_once 'core.php';
|
|
|
|
$multiSelect = false;
|
|
if (isset($params['multiSelect'])) {
|
|
$multiSelect = $params['multiSelect'];
|
|
if (true == $multiSelect) {
|
|
$response = array();
|
|
}
|
|
}
|
|
|
|
try {
|
|
// $query="SELECT id FROM [dbo].[users] where id=$JWTdecoded->id AND is_logged=1";
|
|
// $params = array();
|
|
// $options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
|
|
// $stmt = sqlsrv_query($conn, $query, $params, $options);
|
|
// $row_count = sqlsrv_num_rows($stmt);
|
|
|
|
// if ($row_count === false || $row_count ===0) {
|
|
// header('HTTP/1.0 401 Unauthorized');
|
|
// exit;
|
|
// } else {
|
|
// $verify = verifyJWT('sha256', $jwtToken, $secret);
|
|
// if ($verify) {
|
|
foreach ($sql as $key => $value) {
|
|
$sql_key = array_keys(array_filter($value))[0];
|
|
$sql_query = array_values(array_filter($value))[0];
|
|
if ('select' === $sql_key) {
|
|
querySelect($sql_query);
|
|
} elseif ('select_ru' === $sql_key) {
|
|
querySelect_ru($sql_query);
|
|
} else {
|
|
//if ($JWTdecoded->role===1) {
|
|
queryOther($sql_query);
|
|
// }
|
|
}
|
|
}
|
|
// } else {
|
|
// header('HTTP/1.0 401 Unauthorized');
|
|
// }
|
|
//}
|
|
} catch (Throwable $t) {
|
|
header($t);
|
|
}
|
|
|
|
if (true == $multiSelect) {
|
|
echo json_encode($response);
|
|
}
|