PHP 8.3 fixes for not defined variables, remove double code on /user/check/ method, add observer flag on /user/check/ method

This commit is contained in:
merelendor 2024-05-14 20:22:56 +03:00
parent d7b22e0b39
commit d87d7fea78

View File

@ -5,10 +5,9 @@ header('Content-Type: application/json; charset=utf-8');
use \Bitrix\Main\Service\GeoIp; use \Bitrix\Main\Service\GeoIp;
$httpClient = new \Bitrix\Main\Web\HttpClient(); $httpClient = new \Bitrix\Main\Web\HttpClient();
$PARAM_1 = $_REQUEST["PARAM_1"]; $PARAM_1 = isset($_REQUEST["PARAM_1"]) ? $_REQUEST["PARAM_1"] : null;
$PARAM_2 = $_REQUEST["PARAM_2"]; $PARAM_2 = isset($_REQUEST["PARAM_2"]) ? $_REQUEST["PARAM_2"] : null;
$PARAM_3 = $_REQUEST["PARAM_3"]; $PARAM_3 = isset($_REQUEST["PARAM_3"]) ? $_REQUEST["PARAM_3"] : null;
$PARAM_4 = $_REQUEST["PARAM_4"];
$HEADERS = apache_request_headers(); $HEADERS = apache_request_headers();
$METHOD = $_SERVER['REQUEST_METHOD']; $METHOD = $_SERVER['REQUEST_METHOD'];
@ -25,12 +24,12 @@ $ORIGINS = [
'https://lk.evoleasing.ru', 'https://lk.evoleasing.ru',
]; ];
$origin = $HEADERS['Origin'] ? $HEADERS['Origin'] : $HEADERS['origin']; $origin = isset($HEADERS['Origin']) ? $HEADERS['Origin'] : (isset($HEADERS['origin']) ? $HEADERS['origin'] : preg_replace(["/([^A-z.]+)/"], [""], isset($HEADERS['Host']) ? $HEADERS['Host'] : $HEADERS['host']));
if($origin == "") if($origin == "")
{ {
foreach($ORIGINS as $ORIGIN) foreach($ORIGINS as $ORIGIN)
{ {
if(strpos($referer, $ORIGIN) !== FALSE) if(strpos($HEADERS['referer'], $ORIGIN) !== FALSE)
{ {
$origin = $ORIGIN; $origin = $ORIGIN;
break; break;
@ -821,112 +820,13 @@ switch($PARAM_1)
"user" => $user_data, "user" => $user_data,
"company" => $company_data, "company" => $company_data,
"companies" => $companies, "companies" => $companies,
"token" => \Bitrix\Main\Web\JWT::encode([ "acc_number" => $auth['acc_number'], "is_admin" => $companies[0]['is_admin'], "login" => $ar_user['LOGIN'], "companies" => $companies ], $secret, 'HS256', null, null), "token" => \Bitrix\Main\Web\JWT::encode([
]); "acc_number" => $auth['acc_number'],
} "is_admin" => $companies[0]['is_admin'],
else "login" => $ar_user['LOGIN'],
{ "observer" => $auth['observer'] ? true : false,
print json_encode([ "companies" => $companies,
"status" => "error", ], $secret, 'HS256', null, null),
"error" => "unknown account",
]);
}
die();
}
catch(\Exception $e)
{
print json_encode([
"status" => "error",
"error" => "wrong_jwt",
"message" => $e->getMessage(),
]);
die();
}
}
else
{
print json_encode([
"status" => "error",
"error" => "wrong_source",
"error" => "Wrong source",
]);
}
}
}
break;
case "check":
{
if(CModule::IncludeModule('iblock'))
{
if(checkRequestIsLocal())
{
try
{
$user_registered = false;
$ar_user;
$existed_accounts = [];
$auth = (array) \Bitrix\Main\Web\JWT::decode($REQ['token'], $secret_crm, ["HS256"]);
$default_admin_id;
$existed_client_as_admin_res = CIBlockElement::GetList([ 'ID' => 'ASC' ], [ 'IBLOCK_ID' => IBLOCK_ID_CLIENTS, 'CODE' => $auth['acc_number'] ], false, []);
while ($existed_client_as_admin_element = $existed_client_as_admin_res->GetNextElement())
{
$existed_client_as_admin_record = $existed_client_as_admin_element->GetFields();
$existed_client_as_admin_record['PROPERTIES'] = $existed_client_as_admin_element->GetProperties();
$default_admin_id = $existed_client_as_admin_record['PROPERTIES']['ADMINS']['VALUE'][0];
$user_registered = true;
}
$existed_users_res = \CUser::GetList(["ID" => "ASC"], false, [ "ID" => $default_admin_id ], []);
while($existed_user = $existed_users_res->Fetch())
{
$rs_user = \CUser::GetByLogin($existed_user['LOGIN']);
$ar_user = $rs_user->Fetch();
array_push($existed_accounts, $existed_user['XML_ID']);
}
if(isset($REQ['filter']))
{
if(!in_array($auth['acc_number'], $existed_accounts))
{
print json_encode([
"status" => "error",
"error" => "access_denied",
]);
die();
}
}
if($user_registered)
{
$user_data = [
"email" => $ar_user['LOGIN'],
"name" => $ar_user['NAME'],
"secondname" => $ar_user['SECOND_NAME'],
"lastname" => $ar_user['LAST_NAME'],
"phone" => $ar_user['UF_PHONE_NUMBER'],
"phone_verified" => $ar_user['UF_PHONE_VERIFIED'],
"valid_email" => $ar_user['UF_IS_VALID_EMAIL'],
];
$companies = getCompaniesForUser($ar_user['ID']);
$company_data = [
"inn" => $companies[0]['inn'],
"kpp" => $companies[0]['kpp'],
"ogrn" => $companies[0]['ogrn'],
"title" => $companies[0]['title'],
];
print json_encode([
"status" => "success",
"user" => $user_data,
"company" => $company_data,
"companies" => $companies,
"token" => \Bitrix\Main\Web\JWT::encode([ "acc_number" => $auth['acc_number'], "is_admin" => $companies[0]['is_admin'], "login" => $ar_user['LOGIN'], "companies" => $companies ], $secret, 'HS256', null, null),
]); ]);
} }
else else
@ -1254,7 +1154,7 @@ switch($PARAM_1)
{ {
if(CModule::IncludeModule('iblock')) if(CModule::IncludeModule('iblock'))
{ {
define("USED", filter_var($REQ['USED'], FILTER_VALIDATE_BOOLEAN)); define("USED", filter_var(isset($REQ['USED']) ? $REQ['USED'] : false, FILTER_VALIDATE_BOOLEAN));
$filter = [ "ACTIVE" => "Y", ]; $filter = [ "ACTIVE" => "Y", ];
if(!empty($REQ['PROGRAM'])) { $filter['PROPERTY_LEASING_PROGRAMS'] = $REQ['PROGRAM']; } if(!empty($REQ['PROGRAM'])) { $filter['PROPERTY_LEASING_PROGRAMS'] = $REQ['PROGRAM']; }
@ -1339,7 +1239,7 @@ switch($PARAM_1)
{ {
if(CModule::IncludeModule('iblock')) if(CModule::IncludeModule('iblock'))
{ {
define("USED", filter_var($REQ['USED'], FILTER_VALIDATE_BOOLEAN)); define("USED", filter_var(isset($REQ['USED']) ? $REQ['USED'] : false, FILTER_VALIDATE_BOOLEAN));
$brands = []; $brands = [];
$brands_res = CIBlockElement::GetList(["NAME" => "ASC"], ["ACTIVE" => "Y", "IBLOCK_ID" => USED ? IBLOCK_ID_BRANDS_USED : IBLOCK_ID_BRANDS ], false, []); $brands_res = CIBlockElement::GetList(["NAME" => "ASC"], ["ACTIVE" => "Y", "IBLOCK_ID" => USED ? IBLOCK_ID_BRANDS_USED : IBLOCK_ID_BRANDS ], false, []);
@ -1367,7 +1267,7 @@ switch($PARAM_1)
{ {
if(CModule::IncludeModule('iblock')) if(CModule::IncludeModule('iblock'))
{ {
define("USED", filter_var($REQ['USED'], FILTER_VALIDATE_BOOLEAN)); define("USED", filter_var(isset($REQ['USED']) ? $REQ['USED'] : false, FILTER_VALIDATE_BOOLEAN));
$models = []; $models = [];
$models_res = CIBlockElement::GetList(["NAME" => "ASC"], ["ACTIVE" => "Y", "IBLOCK_ID" => USED ? IBLOCK_ID_MODELS_USED : IBLOCK_ID_MODELS, "PROPERTY_BRAND_UID" => $REQ['BRAND_UID']], false, []); $models_res = CIBlockElement::GetList(["NAME" => "ASC"], ["ACTIVE" => "Y", "IBLOCK_ID" => USED ? IBLOCK_ID_MODELS_USED : IBLOCK_ID_MODELS, "PROPERTY_BRAND_UID" => $REQ['BRAND_UID']], false, []);
@ -1419,7 +1319,7 @@ switch($PARAM_1)
{ {
if(CModule::IncludeModule('iblock')) if(CModule::IncludeModule('iblock'))
{ {
define("USED", filter_var($REQ['USED'], FILTER_VALIDATE_BOOLEAN)); define("USED", filter_var(isset($REQ['USED']) ? $REQ['USED'] : false, FILTER_VALIDATE_BOOLEAN));
$filter = [ "ACTIVE" => "Y", ]; $filter = [ "ACTIVE" => "Y", ];
if(!empty($REQ['PROGRAM'])) { $filter['PROPERTY_LEASING_PROGRAMS'] = $REQ['PROGRAM']; } if(!empty($REQ['PROGRAM'])) { $filter['PROPERTY_LEASING_PROGRAMS'] = $REQ['PROGRAM']; }
@ -1785,8 +1685,8 @@ switch($PARAM_1)
} }
$volumes = []; $volumes = [];
$min = floor($engine_volumes[0] / 100) * 100; $min = isset($engine_volumes[0]) ? floor($engine_volumes[0] / 100) * 100 : 0;
$max = (floor($engine_volumes[count($engine_volumes)-1] / 100) + 1) * 100; $max = count($engine_volumes) > 0 ? (floor($engine_volumes[count($engine_volumes)-1] / 100) + 1) * 100 : 0;
while($min <= $max) while($min <= $max)
{ {
@ -1815,8 +1715,11 @@ switch($PARAM_1)
$result["cities"] = $cities; $result["cities"] = $cities;
$result["years"] = $years; $result["years"] = $years;
$result["mileages"] = $mileages; $result["mileages"] = $mileages;
$result["bitrix_mileages"] = $bitrix_mileages; if(USED)
$result["bitrix_years"] = $bitrix_years; {
$result["bitrix_mileages"] = $bitrix_mileages;
$result["bitrix_years"] = $bitrix_years;
}
//if(empty($REQ['ENGINE_VOLUME_FROM']) || empty($REQ['ENGINE_VOLUME_TO'])) { //if(empty($REQ['ENGINE_VOLUME_FROM']) || empty($REQ['ENGINE_VOLUME_TO'])) {
$result["engine_volumes"] = $volumes; $result["engine_volumes"] = $volumes;
@ -2056,14 +1959,14 @@ switch($PARAM_1)
if(CModule::IncludeModule('iblock')) if(CModule::IncludeModule('iblock'))
{ {
$cars = []; $cars = [];
$cars_res = CIBlockElement::GetList(["ID" => "ASC"], [ "IBLOCK_ID" => 1 ], false, []); $cars_res = CIBlockElement::GetList(["ID" => "ASC"], [ "IBLOCK_ID" => IBLOCK_ID_CATALOG_CARS_NEW ], false, []);
while ($cars_ob_element = $cars_res->GetNextElement()) while ($cars_ob_element = $cars_res->GetNextElement())
{ {
$cars_ar_res = $cars_ob_element->GetFields(); $cars_ar_res = $cars_ob_element->GetFields();
CIBlockElement::Delete($cars_ar_res['ID']); CIBlockElement::Delete($cars_ar_res['ID']);
} }
$modifications_res = CIBlockElement::GetList(["ID" => "ASC"], [ "IBLOCK_ID" => 10 ], false, []); $modifications_res = CIBlockElement::GetList(["ID" => "ASC"], [ "IBLOCK_ID" => IBLOCK_ID_MODIFICATIONS ], false, []);
while ($modifications_ob_element = $modifications_res->GetNextElement()) while ($modifications_ob_element = $modifications_res->GetNextElement())
{ {
$modifications_ar_res = $modifications_ob_element->GetFields(); $modifications_ar_res = $modifications_ob_element->GetFields();
@ -2100,7 +2003,7 @@ switch($PARAM_1)
{ {
if(CModule::IncludeModule('iblock')) if(CModule::IncludeModule('iblock'))
{ {
define("USED", filter_var($REQ['USED'], FILTER_VALIDATE_BOOLEAN)); define("USED", filter_var(isset($REQ['USED']) ? $REQ['USED'] : false, FILTER_VALIDATE_BOOLEAN));
$filter = [ "ACTIVE" => "Y", ]; $filter = [ "ACTIVE" => "Y", ];
if(!empty($REQ['PROGRAM'])) { $filter['PROPERTY_LEASING_PROGRAMS'] = $REQ['PROGRAM']; } if(!empty($REQ['PROGRAM'])) { $filter['PROPERTY_LEASING_PROGRAMS'] = $REQ['PROGRAM']; }
@ -2140,7 +2043,7 @@ switch($PARAM_1)
{ {
if(CModule::IncludeModule('iblock')) if(CModule::IncludeModule('iblock'))
{ {
define("USED", filter_var($REQ['USED'], FILTER_VALIDATE_BOOLEAN)); define("USED", filter_var(isset($REQ['USED']) ? $REQ['USED'] : false, FILTER_VALIDATE_BOOLEAN));
$filter = [ "ACTIVE" => "Y", "PROPERTY_BRAND" => $REQ['BRAND_ID'] ]; $filter = [ "ACTIVE" => "Y", "PROPERTY_BRAND" => $REQ['BRAND_ID'] ];
if(!empty($REQ['PROGRAM'])) { $filter['PROPERTY_LEASING_PROGRAMS'] = $REQ['PROGRAM']; } if(!empty($REQ['PROGRAM'])) { $filter['PROPERTY_LEASING_PROGRAMS'] = $REQ['PROGRAM']; }