<?php
$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"] = (@$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"] ?: array()) + array("agg" . "reg" . "ati" . "on" => base64_decode("YWdn" . "cmVn" . "YXRp" . "b24="), "_70de52cd3ca093409ee739c" . "adeb45bc3" => base64_decode("ZW9zLmFn" . "Z3JlZ2F0" . "aW9uPQ=="), "_c06c961f3937" . "42ecfd52b7226" . "3ac9470" => base64_decode("aW50" . "dmFs"), "_19e451e44a43b536" . "c233116d6cf88e95" => base64_decode("IEFORCBlb3Mub2J" . "qZWN0X2lkPWQuaW" . "QgQU5EIGVvcy5zY" . "2hlZHVsZV9pZD0="), "_318b5e840613de040409f" . "8e6dc83e592" => base64_decode("LCBkLmlkLCBkLnBhcmVudF9pZCwgaW50OmluaF9mcm9tLCBpbnQ6aW5oX2Zyb21fYWdncgoJCQkJCUZST00gRVJNU19kYXRhIGQsIEVSTVNfb2JqZWN0c19zY2hlZHVsZXMgZW9zIFdIRVJFCgkJCQkJCWQucGFyZW50X2lkPWludDpwYXJlbnRfaWQgQ" . "U5EIGVvcy5zY2hlZHVsZV9pZCBJUyBOVUxM"), "_332f55211312ac14495b564e0c9dfd" . "5e" => base64_decode("U0VMRUNUIGFnZ3JlZ2F0aW9uLCBvYmplY3RfaWQsIHBhcmVudF9pZCBGUk9NIEVSTVNfb2JqZWN0c19zY2hlZHVsZXMgV0hFUkUKCQkJCQkJcGFyZW50X2lkPWlu" . "dDpwYXJlbnQgQU5EIHNjaGVkdWxlX2lkPWludDpzY2hlZF9pZCBBTkQgaW5oZXJpdGVkX2Zyb209aW50OmluaF9mcm9tIEFORCBpbmhlcml0ZWRfZnJvbV9hZ2dy" . "ZWdhdGlvbj1pbnQ6aW5oX2Zyb21fYWdncg=="), "_0c5123aa744f69bbc0e8b3ea" . "2f6e847d" => base64_decode("bG1zZw" . "=="), "_7402ad9" . "d719c850" . "d6b2b0e1" . "7168eadc" . "2" => base64_decode("T2JqZWN0IHBhc3NlZCB0byBFUk1TU2N" . "oZWR1bGVBc3NpZ25lcjo6QXNzaWduU2" . "NoZWR1bGUgaXMgbm90IEVSTVNPYmplY" . "3Qgb3IgRVJNU1JlY29yZFR5cGU="), "_5691545210e0e1524daa7" . "908168b3b59" => base64_decode("ZW9" . "z"), "_5368c2db7ec" . "701e3b2b6250" . "00d9265bc" => base64_decode("Z" . "n" . "A" . "="), "_7a773cf918ee6f985" . "4dec0b2aafacb72" => base64_decode("U0VMRUNUIGVvcy5vYmplY3RfaWQgRlJPTSBFUk1TX29iamVjdHNfc2NoZWR1bGVzIGVvcyBXSEVSRQoJCQllb3Muc2NoZWR1bGVfaWQ9aW50OnNjaGVkX2lkIEFORCBlb3MuYWdncmVnYXRpb249aW50OmZvbGRlcl9hZ2dyIEFORCBlb3MucGFyZW50X2lkPWludDpwYXJlbnRfaWQgQU5EIGVv" . "cy5pbmhlcml0ZWRfZnJvbT1pbnQ6aW5oX2Zyb20="), "_eea19a3ce059ab2" . "3108125e5f397e26" . "c" => base64_decode("ZG9jdW1lbnRzLnNjaGVkdWxlcy5ub3RfYXNzaWduZWRfdG9fcGFyZW5" . "0"), "_1ccfde87769c6f002817b" . "b00883c199d" => base64_decode("SU5TRVJUIElOVE8gRVJNU19vYmplY3RzX3NjaGVkdWxlcyAoc2NoZWR1bGVfaWQsIGFnZ3JlZ2F0aW9uLCBvYmplY3RfaWQsIHBhcmVudF9pZCwgaW5oZXJpdGVkX2" . "Zyb20sIGluaGVyaXRlZF9mcm9tX2FnZ3JlZ2F0aW9uKQoJCQkJU0VMRUNUIGludDpzY2hlZF9pZCwg"), "_07af7964f5" . "1512e67eca7" . "0b67f086fce" => base64_decode("Z" . "A" . "=" . "="), "_135a358d0" . "c370824c0c" . "51094a8d13" . "a29" => base64_decode("SU5TRVJUIElOVE8gRVJNU19vYmplY3RzX3NjaGVkdWxlcyAoc2NoZWR1bGVfaWQsIGFnZ3JlZ2F0aW9uLCBvYmplY3RfaWQsIHBhcmVudF9pZCwgaW5oZXJpdGVkX2Zyb20sIGluaGVyaXRlZF9mcm9tX2FnZ3JlZ2F0aW9uKQoJCQlTRUxFQ1QgaW50OnNjaGVkX2lkLCBmcC5hZ2dyZWdhdGlvbiwgZnAuaWQsIGZwLnBhcmVudF9pZCwgaW50OmluaF9mcm9tLCBpbnQ6aW5oX2Zyb21fYWdnciBGUk9NIEVSTVNfZmlsZV9wbGFuIGZwLCBFUk1TX29iamVjdHNfc2NoZWR1bGVzIGVvcyBXSE" . "VSRQoJCQkJZnAucGFyZW50X2lkPWludDpwYXJlbnRfaWQgQU5EIGVvcy5zY2hlZHVsZV9pZCBJUyBOVUxM"), "_06216914a358a55e60" . "c25590bb9f833e" => base64_decode("Q2FuJ3QgYXNzaWduIGEgc2No" . "ZWR1bGUgdG8gYW4gb2JqZWN0" . "IGJlZm9yZSBpdCdzIHNhdmVk"), "_93f2fad2c6fef3" . "051b3305a3afdbf" . "851" => base64_decode("ZG9jdW1lbnRzLnNjaGVkdWxlcy5ub" . "3RfYXNzaWduZWRfdG9fb2Jq"), "_22b7d732a6d9f24f292" . "44ae984219663" => base64_decode("ZW9zLmFnZ3JlZ2F0aW9uPWZwLmFnZ3JlZ2F0aW9uIEFORCBlb3Mub2JqZWN0X2lkP" . "WZwLmlkIEFORCBlb3Muc2NoZWR1bGVfaWQ9"), "object_i" . "d" => base64_decode("b2JqZW" . "N0X2lk"));
use Claromentis\Core\DAL;





class ERMSScheduleAssigner extends ErrorHandler
{
    
    
    
    
    
    
    
    
    
    
    
    
    public function AssignSchedule($_b15aac3aa29c10ea6d1228f58cb9a7e8, $_99f9a102bb8767e290f5ecd80214d3fc, $_2e0f4d4a5cf7c25a94855deecde531ad, $_b3302652694c176a655f7d351a286a1e = 0, $_2ef64163b681ba81d7a7ab44fb09cc2d = 0)
    {
        if (!$_b15aac3aa29c10ea6d1228f58cb9a7e8 instanceof ERMSObject && !$_b15aac3aa29c10ea6d1228f58cb9a7e8 instanceof ERMSRecordType) {
            return $this->SetErrMsg($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_7402ad9d719c850d6b2b0e17168e" . "adc2"]);
        }
        $object_id = $_b15aac3aa29c10ea6d1228f58cb9a7e8->GetId();
        $aggregation = $_b15aac3aa29c10ea6d1228f58cb9a7e8->GetAggregation();
        $_6e38cb9e043a07cd69a1711a6704c62a = $_b15aac3aa29c10ea6d1228f58cb9a7e8->GetParentId();
        if (!$object_id) {
            return $this->SetErrMsg($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_06216914a358a55" . "e60c25590bb9f833" . "e"]);
        }
        try {
            ERMSObjectSchedule::Create($_99f9a102bb8767e290f5ecd80214d3fc, $aggregation, $object_id, $_6e38cb9e043a07cd69a1711a6704c62a, $_b3302652694c176a655f7d351a286a1e, $_2ef64163b681ba81d7a7ab44fb09cc2d);
        } catch (Exception $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            return $this->SetErrMsg($_fe441aa3ef350bfb1a1a1ad8520dd530->getMessage());
        }
        if ($_2e0f4d4a5cf7c25a94855deecde531ad && $_b15aac3aa29c10ea6d1228f58cb9a7e8 instanceof ERMSFolder) {
            $_4fffa41fd07d7711ccb4f280f7c20054 = $_2ef64163b681ba81d7a7ab44fb09cc2d ? $_2ef64163b681ba81d7a7ab44fb09cc2d : $object_id;
            $this->AssignRecursive($_b15aac3aa29c10ea6d1228f58cb9a7e8->GetId(), $_99f9a102bb8767e290f5ecd80214d3fc->GetId(), $_4fffa41fd07d7711ccb4f280f7c20054, $_99f9a102bb8767e290f5ecd80214d3fc->IsApplicableForAggregation(AGGREGATION_DATA));
        }
        return true;
    }
    protected function AssignRecursive($folder_id, $_7f5451fd1c322af95ddc76b4299d7f07, $_2ef64163b681ba81d7a7ab44fb09cc2d, $_2a2cf87523c3e4311f23020dd01bbe84)
    {
        $db = Claromentis\Core\Services::I()->GetDb();
        $_7f5aa4e96d4b415a86ed72ebff677cbe = new DAL\Query($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_135a358d0c370824c0c510" . "94a8d13a29"], $_7f5451fd1c322af95ddc76b4299d7f07, $_2ef64163b681ba81d7a7ab44fb09cc2d, AGGREGATION_FOLDER, $folder_id);
        $_7f5aa4e96d4b415a86ed72ebff677cbe->addJoinCondition($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_5368c2db7ec701e3" . "b2b625000d9265bc"], $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_5691545210e0e1" . "524daa7908168b3" . "b59"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_22b7d732a6d9f24f29" . "244ae984219663"] . $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_c06c961f393742ecfd52" . "b72263ac9470"]($_7f5451fd1c322af95ddc76b4299d7f07));
        $db->query($_7f5aa4e96d4b415a86ed72ebff677cbe);
        if ($_2a2cf87523c3e4311f23020dd01bbe84) {
            $_7f5aa4e96d4b415a86ed72ebff677cbe = new DAL\Query($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_1ccfde87769c6f002817bb008" . "83c199d"] . AGGREGATION_DATA . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_318b5e840613de04040" . "9f8e6dc83e592"], $_7f5451fd1c322af95ddc76b4299d7f07, $_2ef64163b681ba81d7a7ab44fb09cc2d, AGGREGATION_FOLDER, $folder_id);
            $_7f5aa4e96d4b415a86ed72ebff677cbe->addJoinCondition($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_07af7964f51512e" . "67eca70b67f086fc" . "e"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_5691545210e0e1524daa" . "7908168b3b59"], $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_70de52cd3ca093409ee739cadeb4" . "5bc3"] . AGGREGATION_DATA . $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_19e451e44a43b536c23" . "3116d6cf88e95"] . $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_c06c961" . "f393742e" . "cfd52b72" . "263ac947" . "0"]($_7f5451fd1c322af95ddc76b4299d7f07));
            $db->query($_7f5aa4e96d4b415a86ed72ebff677cbe);
        }
        $_189840d11056515e52402d1412a0b6e4 = $db->query($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_7a773cf918" . "ee6f9854dec" . "0b2aafacb72"], $_7f5451fd1c322af95ddc76b4299d7f07, AGGREGATION_FOLDER, $folder_id, $_2ef64163b681ba81d7a7ab44fb09cc2d);
        $_301ec1d34f5bec31e7d0d668413fb337 = $_189840d11056515e52402d1412a0b6e4->fetchAllValues();
        $_189840d11056515e52402d1412a0b6e4->free();
        foreach ($_301ec1d34f5bec31e7d0d668413fb337 as $_b2d4d566b44561685bcf07822f537041) {
            $this->AssignRecursive($_b2d4d566b44561685bcf07822f537041, $_7f5451fd1c322af95ddc76b4299d7f07, $_2ef64163b681ba81d7a7ab44fb09cc2d, $_2a2cf87523c3e4311f23020dd01bbe84);
        }
    }
    
    
    
    
    
    
    
    
    
    
    public function InheritSchedules($_b15aac3aa29c10ea6d1228f58cb9a7e8, $_2e0f4d4a5cf7c25a94855deecde531ad, $_7f5451fd1c322af95ddc76b4299d7f07 = 0)
    {
        $_6e38cb9e043a07cd69a1711a6704c62a = $_b15aac3aa29c10ea6d1228f58cb9a7e8->GetParentId();
        if ($_7f5451fd1c322af95ddc76b4299d7f07 > 0) {
            $_b2fcd799df8a72cf8ad6901ec2916a41 = ERMSObjectSchedule::Get($_7f5451fd1c322af95ddc76b4299d7f07, AGGREGATION_FOLDER, $_6e38cb9e043a07cd69a1711a6704c62a);
            if (!$_b2fcd799df8a72cf8ad6901ec2916a41) {
                return $this->SetErrMsg($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_0c5123aa744f" . "69bbc0e8b3ea2" . "f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_eea19a3ce0" . "59ab2310812" . "5e5f397e26c"]));
            }
            $_f4821cb1c25e022855bb2dbf6c325b85 = array($_b2fcd799df8a72cf8ad6901ec2916a41);
        } else {
            $_f4821cb1c25e022855bb2dbf6c325b85 = ERMSObjectSchedule::GetAllSchedulesByObject(AGGREGATION_FOLDER, $_6e38cb9e043a07cd69a1711a6704c62a);
        }
        foreach ($_f4821cb1c25e022855bb2dbf6c325b85 as $_b2fcd799df8a72cf8ad6901ec2916a41) {
            
            
            $this->AssignSchedule($_b15aac3aa29c10ea6d1228f58cb9a7e8, $_b2fcd799df8a72cf8ad6901ec2916a41->GetSchedule(), $_2e0f4d4a5cf7c25a94855deecde531ad, AGGREGATION_FOLDER, $_b2fcd799df8a72cf8ad6901ec2916a41->GetInheritedFrom() ? $_b2fcd799df8a72cf8ad6901ec2916a41->GetInheritedFrom() : $_6e38cb9e043a07cd69a1711a6704c62a);
        }
        return !$this->IsError();
        
        
    }
    
    
    
    
    
    
    
    
    
    public function RemoveSchedule($_b15aac3aa29c10ea6d1228f58cb9a7e8, $_7f5451fd1c322af95ddc76b4299d7f07)
    {
        $_b2fcd799df8a72cf8ad6901ec2916a41 = ERMSObjectSchedule::Get($_7f5451fd1c322af95ddc76b4299d7f07, $_b15aac3aa29c10ea6d1228f58cb9a7e8);
        if (!$_b2fcd799df8a72cf8ad6901ec2916a41) {
            return $this->SetErrMsg($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_0c5123aa744f69b" . "bc0e8b3ea2f6e847" . "d"]($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_93f2fad2c6fef3051b33" . "05a3afdbf851"], $_7f5451fd1c322af95ddc76b4299d7f07));
        }
        $_2ef64163b681ba81d7a7ab44fb09cc2d = $_b2fcd799df8a72cf8ad6901ec2916a41->GetInheritedFrom();
        $_b2fcd799df8a72cf8ad6901ec2916a41->Delete();
        if ($_b15aac3aa29c10ea6d1228f58cb9a7e8 instanceof ERMSFolder) {
            
            
            $this->RemoveRecursive($_b15aac3aa29c10ea6d1228f58cb9a7e8->GetId(), $_7f5451fd1c322af95ddc76b4299d7f07, $_2ef64163b681ba81d7a7ab44fb09cc2d ? $_2ef64163b681ba81d7a7ab44fb09cc2d : $_b15aac3aa29c10ea6d1228f58cb9a7e8->GetId());
        }
        return true;
    }
    
    
    
    
    
    
    
    
    protected function RemoveRecursive($folder_id, $_7f5451fd1c322af95ddc76b4299d7f07, $_2ef64163b681ba81d7a7ab44fb09cc2d)
    {
        $db = Claromentis\Core\Services::I()->GetDb();
        $_189840d11056515e52402d1412a0b6e4 = $db->query($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_332f552" . "11312ac1" . "4495b564" . "e0c9dfd5" . "e"], $folder_id, $_7f5451fd1c322af95ddc76b4299d7f07, $_2ef64163b681ba81d7a7ab44fb09cc2d, AGGREGATION_FOLDER);
        $_e2e991fb67f11620b04d550af5259a58 = array();
        while ($_343a395319323dd7609bcbc465b4d034 = $_189840d11056515e52402d1412a0b6e4->fetchArray()) {
            $_b2fcd799df8a72cf8ad6901ec2916a41 = ERMSObjectSchedule::Get($_7f5451fd1c322af95ddc76b4299d7f07, $_343a395319323dd7609bcbc465b4d034[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["agg" . "reg" . "ati" . "on"]], $_343a395319323dd7609bcbc465b4d034[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["ob" . "je" . "ct" . "_i" . "d"]]);
            $_b2fcd799df8a72cf8ad6901ec2916a41->Delete();
            if ($_343a395319323dd7609bcbc465b4d034[$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["aggregati" . "on"]] == AGGREGATION_FOLDER) {
                $_e2e991fb67f11620b04d550af5259a58[] = $_343a395319323dd7609bcbc465b4d034[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["obj" . "ect" . "_id"]];
            }
        }
        $_189840d11056515e52402d1412a0b6e4->free();
        foreach ($_e2e991fb67f11620b04d550af5259a58 as $_b2d4d566b44561685bcf07822f537041) {
            $this->RemoveRecursive($_b2d4d566b44561685bcf07822f537041, $_7f5451fd1c322af95ddc76b4299d7f07, $_2ef64163b681ba81d7a7ab44fb09cc2d);
        }
    }
    
    
    
}