<?php
$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"] ?: array()) + array("_e2e360d42f9822dba7a4dd703002afb" . "7" => base64_decode("c3RyOnJlcGV0aXRpb25fc3Rya" . "W5n"), "_947967531816a9ca9bbe90eeb1abd" . "e98" => base64_decode("IFdIRVJF" . "IGlkPWlu" . "dDppZA=="), "_864872f3" . "a7a1fb64f" . "0e4b39d54" . "bd36a6" => base64_decode("U0VMRUNUIGlkIEZST00gcmJfZXZlbn" . "RzIFdIRVJFIGlkPWludDppZCBPUiBw" . "aWQ9aW50OmlkIE9SREVSIEJZIHRtcF" . "9zdGFydCBBU0M="), "_62df08b6ed8667f81" . "74a96d58970883d" => base64_decode("aW50" . "dmFs"), "_f88d69529b1794" . "70c2076e0d0d403" . "f14" => base64_decode("REVMRVRFIEZST00gY2xuX" . "2F0dGVuZGVlcyBXSEVSRS" . "BsaXN0X2lkID0gaW50OmF" . "0dF9saXN0X2lk"), "_5846ddea7ff6d30bd0e7b4a817" . "10776e" => base64_decode("YXJyYXlfc2" . "hpZnQ="), "_ef3a72fcbe857b2afe45cb9d" . "8cafb253" => base64_decode("Z" . "W" . "5" . "k"), "_6438f0b6930a731c657363b00" . "de4c1f5" => base64_decode("cmVwZXRpdGlvb" . "l9zdHJpbmc="), "_69ca75209f57e94fd0bb0d09e2a" . "c260a" => base64_decode("U0VMRUNUIGlkIEZST00gY2xuX2V2ZW50IFdIRVJFIHNlcV9pZCA9" . "IGludDpzZXFfaWQ="), "_43fa09a4d24696009b96d372e" . "df5b5c1" => base64_decode("cmVtX" . "3RpbW" . "U="), "_98352ba2863a6a18384a18629881" . "5408" => base64_decode("U0VMRUNUIHJlbV90aW1lIEZST00gY2xuX3NlcV9yZW1pbmRlciB3aGVyZSB1c2VyX2lkID0gaW50OnVpZCBBTkQgc2" . "VxX2lkID0gaW50OmVpZA=="), "_680336fd6e79305443cf7f46da1" . "735af" => base64_decode("IFdIRV" . "JFIGlk" . "ID0gaW" . "50Omlk"), "_ccd9e402149a4aff4a20" . "de187781aa41" => base64_decode("c3Rhc" . "nQ="), "_710379c26e0ab906" . "b3e255344a8f5d29" => base64_decode("CgkJCVdIRVJFIGljYWxfdWlkPXN0cjp1aWQgQU5EIGNsbl9pZCA9IGludDpjaWQKCQkJT1JERVIgQlkgaWQgREV" . "TQw=="), "_af9bd7d93485f6e2bf3a7436" . "e0cbeed7" => base64_decode("U0VMRUNUIGlkIEZST00gY2xuX2V2ZW50IFdIRVJFIHNlcV9pZCA9IGludDpzZXFfaWQgQU5EIHNlcV9jaGFuZ" . "2VkX2ZsYWcgPSAx"), "_c06c961f393742ec" . "fd52b72263ac9470" => base64_decode("aW50dm" . "Fs"), "_8bac72b3f79f86df50233debc" . "13d03a5" => base64_decode("REVMRVRFIEZST00gY2xuX3NlcV9jb25maXJtIFdIRVJFIHNlcV" . "9pZCA9IGludDppZA=="), "_2c6b4c36d99957cced50" . "cb51f716d423" => base64_decode("RXZlbnQgbm90IGxvYWRl" . "ZCE="), "_63aaf146dd9a5b0ee6a5" . "d691fa5569a7" => base64_decode("REVMRVRFIEZST00gY2xuX3NlcV9yZW1pbmRlciBXSEVSRSBzZXFfaWQgPS" . "BpbnQ6aWQ="), "_f771b8753f763af9d8a9600a" . "0f4b6f67" => base64_decode("REVMRVRFIEZ" . "ST00g"), "_84a9eb3b1aca2c6be317ab94c9cbc" . "1d7" => base64_decode("U0VMRUNUIGlkIEZST00gY2xuX2V2ZW50IFdIRVJFIHNlcV9p" . "ZCA9IGludDpzZXFfaWQgQU5EIGRhdGVfc3RhcnQ+PWludDpz" . "ZCBBTkQgZGF0ZV9zdGFydDxpbnQ6ZWQ="), "_3b03f2d2" . "70ef2d368" . "de828f885" . "8ca740" => base64_decode("U0VMRUNUIGNvbmZpcm1fc3RhdHVzIEZST00gY2xuX3NlcV9jb25maXJtIFdIRVJFIHNlcV9pZCA9IGludDppZCBBTkQgY29udGFjdF9pZCA9IGlud" . "DpjaWQ="), "_38f12d8b8c719a8c" . "e0fc2faefc225f35" => base64_decode("YXJy" . "YXlf" . "bWFw"), "_f628f131769180147" . "75e953a0b1caad3" => base64_decode("U0VMRUNUIGlkLCBuYW1lLCBjbG5faWQsIGNyZWF0b3JfaWQsIHJvb21faWQsIGF0dF9saXN0X2lkLAoJCQlpc19wZXJzb25hbCwgdHosIGRlc2NyaXB0aW9uLCBsb2NhdGlvbiwgZGF0ZV9zdGFydCwgZGF0ZV9lbmQsIGZ1bGxfZGF5LAoJCQlyZXBldGl0aW9uX3N0cmluZywgY2xuX25vX2ljYWwsIGlzX2ltcG9ydGVkLCBpY2FsX3VpZCBGUk" . "9NIA=="));
use Claromentis\Core\Services;






class CalendarEventSequence extends CalendarObject
{
    protected $is_critical_change = false;
    
    
    
    
    protected $table_name = 'cln_sequence';
    public $type = CALENDAR_TYPE_SEQUENCE;
    protected $aggregation = AGGREGATION_CLN_SEQUENCE;
    protected $repetition = '';
    
    
    
    
    
    
    protected $cached_child_event = false;
    protected $create_childs = true;
    public function __construct($_85eea3a16f7026a02992ff95eadc0eb1 = true)
    {
        $this->create_childs = $_85eea3a16f7026a02992ff95eadc0eb1;
        parent::__construct();
    }
    protected function GetLoadQuery()
    {
        return $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_f628f13176918014" . "775e953a0b1caad3"] . $this->table_name . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_947967531816a9ca9bbe9" . "0eeb1abde98"];
    }
    protected function GetLoadByUIDQuery()
    {
        return $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_f628f131769180" . "14775e953a0b1ca" . "ad3"] . $this->table_name . $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_710379c26e0ab" . "906b3e255344a8" . "f5d29"];
    }
    
    
    
    
    
    
    
    
    
    protected function InitParametersByLoadArray($_343a395319323dd7609bcbc465b4d034)
    {
        if (!parent::InitParametersByLoadArray($_343a395319323dd7609bcbc465b4d034)) {
            return false;
        }
        $this->repetition = $_343a395319323dd7609bcbc465b4d034[$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_6438f0b6930a731c65" . "7363b00de4c1f5"]];
        $this->period->LoadFromString($this->repetition);
        return true;
    }
    public function GetRepetition()
    {
        return $this->repetition;
    }
    
    
    
    
    
    
    
    public function CreatePropertiesArray()
    {
        return parent::CreatePropertiesArray() + array($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_e2e360d42" . "f9822dba7a" . "4dd703002a" . "fb7"] => $this->GetPeriod()->CreateSaveString());
    }
    
    
    
    
    
    
    public function Save()
    {
        $this->ValidateDates();
        if ($this->IsError()) {
            return false;
        }
        
        
        if ($this->GetId() > 0 && $this->IsCriticalChange()) {
            CalendarToolKit::DeleteCalendarObject($this, true, false, false, true);
            $this->attended_users = new CalendarEventUsers($this);
            $this->attended_contacts = new CalendarEventContacts($this);
            $this->id = 0;
        }
        return parent::Save();
    }
    protected function Update()
    {
        if (!parent::Update()) {
            return false;
        }
        $_9cee5807b5bab08d25cd4213e63cb764 = $this->GetChildrenIds();
        foreach ($_9cee5807b5bab08d25cd4213e63cb764 as $_0ea4e32b57963ac0cb3057e03e9aef64) {
            $event = new CalendarEvent();
            $event->Load($_0ea4e32b57963ac0cb3057e03e9aef64);
            if (!$event->GetSeqChangedFlag()) {
                $this->InitEventWithSequenceParameters($event);
                $event->Save();
            }
        }
        return true;
    }
    
    
    
    
    
    
    protected function GetBookingsArray()
    {
        global $db;
        return $db->query($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_864872f3a7a1fb64" . "f0e4b39d54bd36a6"], $this->GetBookingID(), $this->GetBookingID())->fetchAllValues();
    }
    protected function Insert()
    {
        $_7c7b8bf0e503161cad423a738d072ddf = array();
        if (!parent::Insert()) {
            return false;
        }
        $_f2a41580dce55e1aa803bb51249e43ca = $this->GetPeriod()->GetDatesArray(true);
        if ($this->GetBookingID() > 0) {
            $_7c7b8bf0e503161cad423a738d072ddf = $this->GetBookingsArray();
        }
        if ($this->create_childs) {
            foreach ((array) $_f2a41580dce55e1aa803bb51249e43ca as $_67a0d624aebcceb0abd5ce56a53ff06f) {
                $event = $this->CreateChildEvent($_67a0d624aebcceb0abd5ce56a53ff06f[$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_ccd9e402" . "149a4aff4" . "a20de1877" . "81aa41"]], $_67a0d624aebcceb0abd5ce56a53ff06f[$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_ef3a72fcbe857b2afe45c" . "b9d8cafb253"]], $this->GetPeriod()->IsFullDay());
                if ($_47f8df6f5aa7de674a0441d749522f0b = $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_5846ddea7ff6d30bd0e7b4a81" . "710776e"]($_7c7b8bf0e503161cad423a738d072ddf)) {
                    $event->SetBookingId($_47f8df6f5aa7de674a0441d749522f0b);
                }
                $event->Save();
            }
        }
        return true;
    }
    
    
    
    
    
    
    
    protected function InitEventWithSequenceParameters(CalendarEvent $event)
    {
        $event->SetName($this->name);
        $event->SetClnId($this->cln_id);
        $event->SetCreatorId($this->creator_id);
        $event->SetDescription($this->description);
        $event->SetLocation($this->location);
        $event->SetPersonalMode($this->GetPersonalMode());
        $event->SetInitialTimezone($this->GetInitialTimezone());
        return $event;
    }
    
    
    
    
    
    
    
    
    
    protected function CreateChildEvent(Date $_ccd9e402149a4aff4a20de187781aa41, Date $_ef3a72fcbe857b2afe45cb9d8cafb253, $_62e32d5a92b034f6515d05dda6d7a62d)
    {
        if (!$this->cached_child_event) {
            $this->cached_child_event = $this->InitEventWithSequenceParameters(new CalendarEvent());
        }
        $event = clone $this->cached_child_event;
        $event->SetStartDate($_ccd9e402149a4aff4a20de187781aa41);
        $event->SetEndDate($_ef3a72fcbe857b2afe45cb9d8cafb253);
        $event->SetFullDay($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_c06c961" . "f393742e" . "cfd52b72" . "263ac947" . "0"]($_62e32d5a92b034f6515d05dda6d7a62d));
        $event->SetListId($this->list_id);
        $event->SetSeqId($this->id);
        $event->SetIsImported($this->is_imported);
        $event->SetICalUID($this->ical_uid);
        return $event;
    }
    public function _delete()
    {
        if (!$this->id) {
            return $this->SetErrMsg($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_2c6b4c36" . "d99957cce" . "d50cb51f7" . "16d423"]);
        }
        $db = Services::I()->GetDb();
        $db->query($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_f88d69529b179470c2076e0d0d" . "403f14"], $this->GetListId());
        $db->query($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_8bac72b3f79f86df50233debc13d03a" . "5"], $this->id);
        $db->query($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_63aaf146dd9a5b0ee6a5d691f" . "a5569a7"], $this->id);
        $db->query($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_f771b8753f763af9d8" . "a9600a0f4b6f67"] . $this->table_name . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_680336f" . "d6e79305" . "443cf7f4" . "6da1735a" . "f"], $this->id);
        return true;
    }
    
    
    
    
    
    
    
    
    public function PrepareChildForDelete(CalendarEvent $event)
    {
        if ($event->GetListId() == $this->GetListId()) {
            $event->SetListId(0);
        }
        return true;
    }
    
    
    
    
    
    
    public function GetChildrenIds() : array
    {
        $_b2eee0013224d2924db36c4231aa5a1a = $this->GetId();
        if (empty($_b2eee0013224d2924db36c4231aa5a1a)) {
            return [];
        }
        $db = Services::I()->GetDb();
        return $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_38f12d8b8c719a8ce0fc" . "2faefc225f35"]($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_62df08b6ed866" . "7f8174a96d5897" . "0883d"], $db->query($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_69ca752" . "09f57e94" . "fd0bb0d0" . "9e2ac260" . "a"], $_b2eee0013224d2924db36c4231aa5a1a)->fetchAllValues());
    }
    public static function GetChildrenByStartDate($_b2eee0013224d2924db36c4231aa5a1a, Date $_91d10773c15d92f509551b22650c8a4e, $_f91e5675e763b68af3f9c9f9702b1d37 = null)
    {
        if (empty($_b2eee0013224d2924db36c4231aa5a1a)) {
            return 0;
        }
        $_2dda4556e52a6eb3aefc6ead58db909d = clone $_91d10773c15d92f509551b22650c8a4e;
        $_2dda4556e52a6eb3aefc6ead58db909d->setHour(0);
        $_2dda4556e52a6eb3aefc6ead58db909d->setMinute(0);
        $_2dda4556e52a6eb3aefc6ead58db909d->setSecond(0);
        $_1593021faad6b6b75f0d0b54a1ce58d3 = clone $_91d10773c15d92f509551b22650c8a4e;
        $_1593021faad6b6b75f0d0b54a1ce58d3->addDays(1);
        $db = Services::I()->GetDb();
        $_189840d11056515e52402d1412a0b6e4 = $db->query($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_84a9eb3b1aca2c6be317a" . "b94c9cbc1d7"], $_b2eee0013224d2924db36c4231aa5a1a, $_2dda4556e52a6eb3aefc6ead58db909d->getDate(), $_1593021faad6b6b75f0d0b54a1ce58d3->getDate());
        $_b8cfc2e06d9d1fec1893ea4a054002bf = $_189840d11056515e52402d1412a0b6e4->fetchRow();
        return isset($_b8cfc2e06d9d1fec1893ea4a054002bf[0]) ? (int) $_b8cfc2e06d9d1fec1893ea4a054002bf[0] : null;
    }
    
    
    
    
    
    
    public function hasModifiedChildren()
    {
        if (empty($this->id)) {
            return false;
        }
        $db = Services::I()->GetDb();
        return $db->query($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_af9bd7d" . "93485f6e" . "2bf3a743" . "6e0cbeed" . "7"], $this->GetId())->hasData();
    }
    public function GetContactConfirmStatus($_29323189a19d68cee9551201fa097a55)
    {
        $_d88b50ddb42db648a9c7ac08065b9409 = $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_3b03f2d270ef2d368de828f8858c" . "a740"];
        return $this->GetContactConfirmStatusByQuery($_29323189a19d68cee9551201fa097a55, $_d88b50ddb42db648a9c7ac08065b9409);
    }
    
    
    
    
    
    
    
    public function SetCriticalChange($_601a171d59986f7c15972b586685671b)
    {
        $this->is_critical_change = $_601a171d59986f7c15972b586685671b;
    }
    
    
    
    
    
    
    
    public function IsCriticalChange()
    {
        return $this->is_critical_change;
    }
    public function GetReminder(?int $user_id = null) : ?int
    {
        if (empty($this->GetId())) {
            return null;
        }
        $db = Services::I()->GetDb();
        $user_id = $user_id ?? CalendarToolKit::Instance()->curr_user_settings->GetUserId();
        $_189840d11056515e52402d1412a0b6e4 = $db->query($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_98352ba28" . "63a6a18384" . "a186298815" . "408"], $user_id, $this->GetId());
        if (!$_189840d11056515e52402d1412a0b6e4->hasData()) {
            return null;
        }
        $_343a395319323dd7609bcbc465b4d034 = $_189840d11056515e52402d1412a0b6e4->fetchArray();
        return $_343a395319323dd7609bcbc465b4d034[$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_43fa09a4d24696009b96d3" . "72edf5b5c1"]];
    }
}