SHARE
TWEET

Untitled

a guest Dec 2nd, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?
  2. define('AR_FIRST_ORDER_BRANDS', array('Volkswagen','Kia','Toyota','Lexus','Jaguar','Land rover','Mazda','Ford'));
  3. $findded = (!empty($arResult["RESULT_CAR"]) && empty($arResult["RESULT_CAR"]["STATUS_MESSAGE"]));
  4. $result = array(
  5.     "dontHideFormOnSuccess" => true,
  6.     "submitUrl" => $APPLICATION->GetCurPageParam(),
  7.     "buttonText" => $arParams["BUTTON_TEXT"] ?: "",
  8.     "fields" => array(),
  9.     "title" => $arParams["TITLE"] ?: "Узнайте, сколько стоит Ваш автомобиль",
  10.     "fields" => [],
  11.     "currentTab" => 0,
  12.     "tabList" => [],
  13.     "errors" => [],
  14.     "newUserText" => "",
  15.     "existingUserText" => "",
  16.     "needAuthText" => "",
  17.     "requireConfirm" => false,
  18.     "last_price_update" => \Bitrix\Main\Config\Option::get("sh.dblayer", "LAST_TRADEIN_BASE_UPDATE"),
  19.     "user" => [
  20.         "isAdminEdit" => $USER->IsAdmin() && $_SESSION["SESS_INCLUDE_AREAS"],
  21.         "authorized" => $USER->isAuthorized(),
  22.         "name" => $USER->isAuthorized() ? $USER->GetFullName() : ""
  23.     ],
  24.     "phoneFound" => $arResult["FORM"]["PHONE_FOUND"] > 0,
  25.     "phoneCompleted" => $arResult["FORM"]["PHONE_FOUND"] >= 0,
  26.     "carImage" => $arResult["CAR_IMAGE"],
  27.     "self_price_num" => round($arResult["SAVED"]["SELF_PRICE"]) > 0 ? round($arResult["SAVED"]["SELF_PRICE"]) : 0,
  28.     "self_price" => round($arResult["SAVED"]["SELF_PRICE"]) > 0 ? SaleFormatCurrency(round($arResult["SAVED"]["SELF_PRICE"]), "BYN", true) : "",
  29.     "result_car" => [
  30.         "calc_result" => !empty($arResult["RESULT_CAR"]),
  31.         "find" => $findded,
  32.         "self_sell" => $findded && $arResult["RESULT_CAR"]["SELF_SELL"] ? SaleFormatCurrency(round($arResult["RESULT_CAR"]["SELF_SELL"]), "BYN", true) : "",
  33.         "full_sell" => $findded && $arResult["RESULT_CAR"]["FULL_SELL"] ? SaleFormatCurrency(round($arResult["RESULT_CAR"]["FULL_SELL"]), "BYN", true) : "",
  34.         "tradein_sell" => $findded && $arResult["RESULT_CAR"]["TRADEIN_SELL"] ? SaleFormatCurrency(round($arResult["RESULT_CAR"]["TRADEIN_SELL"]), "BYN", true) : "",
  35.         "komission_sell" => $findded && $arResult["RESULT_CAR"]["KOMISSION_SELL"] ? SaleFormatCurrency(round($arResult["RESULT_CAR"]["KOMISSION_SELL"]), "BYN", true) : "",],
  36.     "links" => [
  37.         "getmark" => "/tradein/getmark.php" . ($arResult["SAVED"] ? "?CAR_ID=" . $arResult["SAVED"]["ID"] : ""),
  38.         "tradein" => "/cars/stock/",
  39.         "sellcar" => "/tradein/sellcar.php" . ($arResult["SAVED"] ? "?CAR_ID=" . $arResult["SAVED"]["ID"] : ""),
  40.         "komissioncar" => "/tradein/commissioncar.php" . ($arResult["SAVED"] ? "?CAR_ID=" . $arResult["SAVED"]["ID"] : ""),
  41.     ]
  42. );
  43.  
  44.  
  45. $disabledCount = 0;
  46.  
  47. $prevCode = false;
  48.  
  49. foreach ($arResult["FIELDS"] as &$fieldPrams) {
  50.     if (isset($result["tabList"][$fieldPrams["GROUP_CODE"]])) {
  51.         continue;
  52.     }
  53.  
  54.     if ($fieldPrams["HIDE_AUTH"] && CUser::IsAuthorized()) {
  55.         $fieldPrams["TYPE"] = "hidden";
  56.         continue;
  57.     }
  58.  
  59.     $result["tabList"][$fieldPrams["GROUP_CODE"]] = ["id" => $fieldPrams["GROUP_CODE"], "name" => $fieldPrams["GROUPNAME"], "active" => false, "last" => false, "prev" => !empty($prevCode)];
  60.     $prevCode = $fieldPrams["GROUP_CODE"];
  61. }
  62. unset($fieldPrams);
  63.  
  64. $result["tabList"][$prevCode]["last"] = true;
  65.  
  66.  
  67. $tabError = "";
  68.  
  69. $result["errors"] = array(
  70.     "form" => $arResult["ERRORS"]["FORM"] ? (array) $arResult["ERRORS"]["FORM"] : [],
  71.     "fields" => array()
  72. );
  73.  
  74.  
  75. foreach ($arResult["FIELDS"] as $fieldPrams) {
  76.  
  77.  
  78.     if (empty($tabError) && isset($arResult["ERRORS"][$field["MD5CODE"]])) {
  79.         $tabError = $fieldPrams["GROUP_CODE"];
  80.     }
  81.  
  82.  
  83.     $field = array(
  84.         "groupID" => $fieldPrams["GROUP_CODE"],
  85.         "type" => strtolower($fieldPrams["TYPE"]),
  86.         "code" => $fieldPrams["CODE"],
  87.         "name" => $fieldPrams["MD5CODE"],
  88.         "label" => $fieldPrams["NAME"],
  89.         "value" => $fieldPrams["VALUE"] ?: ( $fieldPrams["MULTIPLE"] == "Y" ? [] : ""),
  90.         "multiple" => $fieldPrams["MULTIPLE"] == "Y",
  91.         "multiplebtn" => $fieldPrams["MULTIPLE"] == "Y" ? ($fieldPrams["MULTIPLE_BTN"] ?: "Добавить") : "",
  92.         "options" => array(),
  93.         "mask" => $fieldPrams["TYPE"] == "PHONE" ? array("mask" => "+375 (99) 999-99-99", "placeholder" => '+375 (__) ___-__-__', "clearMaskOnLostFocus" => false) : null,
  94.         "reload" => $fieldPrams["IS_FILTER"] || $fieldPrams["RELOAD"],
  95.     );
  96.  
  97.  
  98.     if ($fieldPrams["IS_FILTER"] && !in_array(strtolower($fieldPrams["TYPE"]), ["select", "radio", "checkbox", "tumbler", "checkblocks", "radioblocks"])) {
  99.         $fieldPrams["TYPE"] = "select";
  100.     }
  101.  
  102.  
  103.     if (in_array(strtolower($fieldPrams["TYPE"]), ["select", "radio", "checkbox", "tumbler", "checkblocks", "radioblocks"])) {
  104.         $field["searchable"] = $arParams["SEARCHABLE_{$fieldPrams["MD5CODE"]}"] == "Y";
  105.  
  106.         if (empty($field["value"]) && $fieldPrams["SELECT_FIRTS"]) {
  107.             $field["value"] = array_shift(array_values($fieldPrams["VALUES"]));
  108.         }
  109.  
  110.         foreach ($fieldPrams["VALUES"] as $key => $value) {
  111.             if (preg_match("/.+\|[^\|]+$/", $value)) {
  112.                 list($key, $value) = explode("|", $value);
  113.             }
  114.  
  115.             $field["options"][] = array(
  116.                 "value" => $key,
  117.                 "text" => $value,
  118.             );
  119.  
  120.             if (in_array($key, AR_FIRST_ORDER_BRANDS)){
  121.                 $arToStart = array_pop($field["options"]);
  122.                 array_unshift($field["options"], $arToStart);
  123.             }
  124.         }
  125.  
  126.  
  127.  
  128.         if (strtolower($fieldPrams["TYPE"]) == "select" && $fieldPrams["VALUES_OTHER"]) {
  129.             $field["options"][] = array(
  130.                 "value" => "Другое",
  131.                 "text" => "Другое",
  132.                 "showOther" => true
  133.             );
  134.         }
  135.     }
  136.  
  137.     if (in_array(strtolower($fieldPrams["TYPE"]), ["stores"])) {
  138.         $field["options"] = $fieldPrams["OPTIONS"];
  139.     }
  140.  
  141.  
  142.     if (isset($arResult["ERRORS"][$fieldPrams["MD5CODE"]])) {
  143.         $result["errors"]["fields"][$fieldPrams["MD5CODE"]] = $arResult["ERRORS"][$fieldPrams["MD5CODE"]];
  144.     }
  145.  
  146.  
  147.     if (!$USER->isAuthorized() //not authorised
  148.         && $fieldPrams["CODE"] == "PERSONAL_MOBILE" //phone field
  149.         && !empty($field["value"]) //current value set
  150.         && empty($result["errors"]["fields"][$fieldPrams["MD5CODE"]])
  151.     ) {
  152.  
  153.         if ($arResult["FORM"]["PHONE_FOUND"] == 0) {
  154.  
  155.             $field["codeSend"] = true;
  156.  
  157.             if ($_POST["state"]["action"] == "send-verify-code" || $_POST["state"]["action"] == "submit-verify-code") {
  158.                 $result["errors"]["fields"] = [];
  159.                 $result["errors"]["form"] = [];
  160.  
  161.                 if (empty($arResult["ERRORS"]["PHONE_CHECK"]) || !empty($arResult["ERRORS"]["PHONE_CHECK_PIN"])) {
  162.                     $field["type"] = "hidden";
  163.  
  164.                     $result["fields"][] = $field;
  165.                     $userPropCode = $fieldPrams["CODE"] . "_VERIFY";
  166.                     $field = array(
  167.                         "groupID" => $fieldPrams["GROUP_CODE"],
  168.                         "type" => "text",
  169.                         "code" => $userPropCode,
  170.                         "name" => $userPropCode,
  171.                         "label" => "Код подтверждения",
  172.                         "value" => "",
  173.                         "multiple" => false,
  174.                         "multiplebtn" => "",
  175.                         "options" => array(),
  176.                     );
  177.                     $result["errors"]["fields"][$userPropCode] = $arResult["ERRORS"]["PHONE_CHECK_PIN"];
  178.                 } else {
  179.                     $result["errors"]["fields"][$fieldPrams["MD5CODE"]] = $arResult["ERRORS"]["PHONE_CHECK"];
  180.                 }
  181.             }
  182.         }
  183.     }
  184.  
  185.     $result["fields"][] = $field;
  186. }
  187.  
  188. if (empty($tabError)) {
  189.     $tabError = array_shift(array_keys($result["tabList"]));
  190. }
  191. $result["currentTab"] = $tabError;
  192. $result["tabList"][$tabError]["active"] = true;
  193. $result["tabList"] = array_values($result["tabList"]);
  194.  
  195. $requredFields = ["BRAND" => "Volkswagen", "MODEL" => "Polo", "YEAR" => 2013, "MILAGE" => 99999, "STATUS" => 1];
  196. foreach ($requredFields as $code => $def) {
  197.     if (!isset($arResult["FIELDS"][$code])) {
  198.  
  199.         $result["fields"][] = array(
  200.             "type" => "hidden",
  201.             "name" => $code,
  202.             "label" => "",
  203.             "value" => $def,
  204.         );
  205.     }
  206. }
  207.  
  208. if (!empty($_REQUEST["bxajaxid"] && $arParams["AJAX_ID"] == $_REQUEST["bxajaxid"])) {
  209.  
  210.  
  211.     $result["success"] = !empty($arResult['SUCCSESS']);
  212.     $result["reload"] = false;
  213.     $result["redirect"] = "";
  214.     $message = "";
  215.  
  216.     $APPLICATION->RestartBuffer();
  217.     while (ob_get_level()) {
  218.         ob_end_clean();
  219.     }
  220.  
  221.  
  222.     echo json_encode($result);
  223.     die();
  224. }
  225.  
  226. ?>
  227.  
  228. <div class="evaluation-lite form-card">
  229.     <v-trade-in-form template-type="small" :static-data-source="<?= htmlspecialchars(json_encode($result)) ?>" bxajaxid="<?= $arParams["AJAX_ID"] ?>" mode="static"></v-trade-in-form>
  230. </div>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top