<?php
$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"] ?: array()) + array("_8c07175bcc" . "8b38590eb57" . "8536d458420" => base64_decode("ZnJvbV9zdGF0dXMgPSBpbnQ6c3RhdGVfaWQgT1IgdG9fc3RhdHVzID0gaW50OnN" . "0YXRlX2lk"), "_ae9ed3fb8f83efe5c2377b" . "2ecc07bc6a" => base64_decode("c3RhdF9k" . "YXRl"), "_d4442ae534959909d9cdb24" . "ef2b1bf68" => base64_decode("d29ya2Zsb3cuZG9jdW1lbnRfaGFzX2JlZW5fY" . "XNzaWduZWRfdG9fdGhlX3N0YXRl"), "_08aa8c963129" . "5656e6b3f403b" . "6dcceb3" => base64_decode("d2ZfaWQ9a" . "W50OndmX2" . "lk"), "_a5b8a957b6bb889a65d" . "0110f7df85ff0" => base64_decode("REV" . "TQw" . "=="), "_6b8bab3518f308b59f" . "0cb06770af10b9" => base64_decode("ZH" . "A="), "_aba44780bfed25b04a1c9a2b044" . "d5f3a" => base64_decode("d2Zf" . "c3Rh" . "dGVz"), "_4278f6e1f1e27cc1e96763e" . "4620a4ff5" => base64_decode("Y21f" . "ZGll"), "_88c0fe4439f1efb05b37d61d25d0" . "2f4f" => base64_decode("Li" . "A="), "_5159b3572969eca46acd1b2e" . "1418459c" => base64_decode("aW1wbG9k" . "ZQ=="), "_5846ddea7ff6d30bd0e7" . "b4a81710776e" => base64_decode("YXJyYXlfc2hp" . "ZnQ="), "_4d707fab93bebb00bbe69e815969" . "7c90" => base64_decode(""), "_3312b0cb5703d1d" . "b25d59cc9d10576b" . "5" => base64_decode("YXNzaWduIGRvY3V" . "tZW50IGZhaWxlZA" . "=="), "_0c5123aa744f" . "69bbc0e8b3ea2" . "f6e847d" => base64_decode("bG1zZw=" . "="), "_aa11126de25016" . "efadd7423305f22" . "ad5" => base64_decode("ZC53Zl9zdGF0ZV9pZCBlcTppbn" . "Q6c3RhdGVfaWQ="), "_0be6b0f" . "bf9ef1bb" . "e3173ce5" . "8ec29b5a" . "4" => base64_decode("ZG9jdW1lbnQgd29ya2" . "Zsb3cgcmVjb3ZlcmVk"), "_0712d458fe37a6259169368d968c" . "6cb0" => base64_decode("R1JPVVAgQlkgZC5kb2NfaWQsIGQucGFyZW50X2lkLCBkLndmX2lkLCBkLndmX3N0Y" . "XRlX2lkLCBkLndmX3Jlc3BvbnNpYmxlX3VpZA=="), "_04014b4c4cd7" . "f8beafc06c912" . "139b979" => base64_decode("aHR0" . "cFJl" . "ZGly" . "ZWN0"), "_fd4e2f4e1aa450a7626a3bf44f4fa4e" . "1" => base64_decode("ZC5kb2NfaWQsIGQucGFyZW50X2lkLCBkLndmX2lkLCBkLndmX3N0YXRlX2" . "lkLCBkLndmX3Jlc3BvbnNpYmxlX3VpZA=="));
use Claromentis\Core\DAL;
class WFState extends DBObject
{
    protected $id;
    protected $wf_id;
    protected $name;
    
    
    protected $position;
    protected $color;
    protected $owner_notify;
    protected $readonly;
    
    
    protected $resp_notify;
    
    
    
    
    
    
    public function __construct($_eb57e3a45673c8e851b42c4eee3742ea = 0)
    {
        $this->TABLE_NAME = $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_aba44780bfed25" . "b04a1c9a2b044d5" . "f3a"];
        $this->id = -1;
        $this->wf_id = $_eb57e3a45673c8e851b42c4eee3742ea;
        $this->name = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_4d707fab93bebb00bbe69e815" . "9697c90"];
        
        
        $this->position = 0;
        $this->color = $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_4d707fab93bebb00bbe69e" . "8159697c90"];
        $this->readonly = 0;
        $this->resp_notify = 0;
    }
    
    
    
    
    
    
    public function Delete()
    {
        $_f403cc31b288afbea692958ed6d9a3ce = $this->GetAllActions();
        foreach ($_f403cc31b288afbea692958ed6d9a3ce as $action) {
            
            
            $action->Delete();
        }
        $_c4c0f15c5891a8ac349f1b56352500b5 = new WFTransition();
        $_714e1da7f6235557a4490c30b448e1ad = $_c4c0f15c5891a8ac349f1b56352500b5->GenerateSelect();
        $_714e1da7f6235557a4490c30b448e1ad->AddWhereAndClause($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_8c07175bcc8b3" . "8590eb578536d4" . "58420"], $this->id, $this->id);
        $_206c9a2f1b7a74e0c0cae00c29eb4fce = $_c4c0f15c5891a8ac349f1b56352500b5->GetAll($_714e1da7f6235557a4490c30b448e1ad);
        foreach ($_206c9a2f1b7a74e0c0cae00c29eb4fce as $_07e41711580f2279161feffa9f744876) {
            
            
            $_07e41711580f2279161feffa9f744876->Delete();
        }
        $_3c541b3f26f65571e2515210f1d54101 = $this->GetWorkflow();
        $_ff99444b7fb172efeb317c75f9a524a2 = null;
        foreach ($_3c541b3f26f65571e2515210f1d54101->GetAllStates() as $_a45ac832b3d5b2da25e8966454169ba3) {
            if ($_a45ac832b3d5b2da25e8966454169ba3->GetId() != $this->GetId()) {
                $_ff99444b7fb172efeb317c75f9a524a2 = $_a45ac832b3d5b2da25e8966454169ba3;
                break;
            }
        }
        foreach ($this->GetDocsByState() as $_09f61d3133f39f8e5aff0eb6a7d185a1) {
            if ($_ff99444b7fb172efeb317c75f9a524a2) {
                $this->Cancel($_09f61d3133f39f8e5aff0eb6a7d185a1);
                $_47e20395bf8bd04eea83c346c5cc868b = new WFStateRecord($_09f61d3133f39f8e5aff0eb6a7d185a1->GetDocId(), 0, $_ff99444b7fb172efeb317c75f9a524a2->GetId(), $_ff99444b7fb172efeb317c75f9a524a2->GetId(), $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_0c5123aa744f" . "69bbc0e8b3ea2" . "f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_d4442ae534959909d" . "9cdb24ef2b1bf68"]), AuthUser::I()->GetId());
                $_47e20395bf8bd04eea83c346c5cc868b->Save();
                $_09f61d3133f39f8e5aff0eb6a7d185a1->SetWorkflowState($_ff99444b7fb172efeb317c75f9a524a2->GetId());
                $this->PassError($_09f61d3133f39f8e5aff0eb6a7d185a1->IsError(), $_09f61d3133f39f8e5aff0eb6a7d185a1);
                $_09f61d3133f39f8e5aff0eb6a7d185a1->Save();
            } else {
                $_09f61d3133f39f8e5aff0eb6a7d185a1->SetWorkflow(0);
                $_09f61d3133f39f8e5aff0eb6a7d185a1->Save();
            }
        }
        parent::Delete();
        $_3c541b3f26f65571e2515210f1d54101->ReArrangeStatePositions();
        return true;
    }
    
    
    
    
    
    
    public function GetWorkflow()
    {
        $_2e26bc188caaec4fd575623eb70ac697 = new WFWorkflow();
        $_2e26bc188caaec4fd575623eb70ac697->Load($this->GetWorkflowId());
        return $_2e26bc188caaec4fd575623eb70ac697;
    }
    public function GetDocsByState()
    {
        global $g_erms_browser;
        $_06b2342427d8c7b377fbadac8d48171e = new DocsListProvider();
        $_548c946eac8c11a4bab9434c87e0ecc8 = $_06b2342427d8c7b377fbadac8d48171e->GetSQLForDocuments($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_fd4e2f4e1aa450a7626a3bf4" . "4f4fa4e1"], array($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_6b8bab3518f30" . "8b59f0cb06770a" . "f10b9"]), null, null, null, true, $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_0712d458fe37a62591" . "69368d968c6cb0"], new DAL\QueryPart($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_aa11126de25016efad" . "d7423305f22ad5"], $this->GetId()));
        global $db;
        $_4385bb538c05d2da58ef73ce400a2a58 = $db->query($_548c946eac8c11a4bab9434c87e0ecc8);
        $_f274035cf280fb57c0c9ef54d849a83d = array();
        while (list($id, $_6e38cb9e043a07cd69a1711a6704c62a) = $_4385bb538c05d2da58ef73ce400a2a58->fetchRow()) {
            $_f274035cf280fb57c0c9ef54d849a83d[] = $g_erms_browser->GetDataByDocId($id, $_6e38cb9e043a07cd69a1711a6704c62a);
        }
        return $_f274035cf280fb57c0c9ef54d849a83d;
    }
    
    
    
    
    
    
    
    public function Cancel($_fc4ffcaec4dff19ed04cc1c9229222d1)
    {
        $_6d531f6dc9e331a0e9b18556f51742ea = true;
        $_e3be37b466da96cb55bbca1e9a810ff0 = new WFStateRecord($_fc4ffcaec4dff19ed04cc1c9229222d1->GetDocId());
        $_c456c6b3886ed2803349248752fedd14 = $_e3be37b466da96cb55bbca1e9a810ff0->GetSameByDoc();
        if ($_c456c6b3886ed2803349248752fedd14) {
            foreach ((array) $_c456c6b3886ed2803349248752fedd14 as $_47e20395bf8bd04eea83c346c5cc868b) {
                
                
                $_f403cc31b288afbea692958ed6d9a3ce = $this->GetAllActions();
                foreach ($_f403cc31b288afbea692958ed6d9a3ce as $action) {
                    
                    
                    if (!$action->Cancel($_fc4ffcaec4dff19ed04cc1c9229222d1, $_47e20395bf8bd04eea83c346c5cc868b->GetId())) {
                        $_6d531f6dc9e331a0e9b18556f51742ea = false;
                    }
                }
                $_206c9a2f1b7a74e0c0cae00c29eb4fce = $this->GetAllTransitions();
                foreach ($_206c9a2f1b7a74e0c0cae00c29eb4fce as $_07e41711580f2279161feffa9f744876) {
                    
                    
                    if (!$_07e41711580f2279161feffa9f744876->Cancel($_fc4ffcaec4dff19ed04cc1c9229222d1, $_47e20395bf8bd04eea83c346c5cc868b->GetId())) {
                        $_6d531f6dc9e331a0e9b18556f51742ea = false;
                    }
                }
                $_47e20395bf8bd04eea83c346c5cc868b->Delete();
            }
        }
        return $_6d531f6dc9e331a0e9b18556f51742ea;
    }
    
    
    
    
    
    
    public function GetAllActions()
    {
        return WFActionFactory::GetAllInstancesByState($this->id);
    }
    
    
    
    
    
    
    public function GetAllTransitions()
    {
        return WFTransitionFactory::GetAllInstancesByState($this->id);
    }
    
    
    
    
    
    
    public function GetSameByWF()
    {
        if ($this->wf_id <= 0) {
            return array();
        }
        $_03e9164d0a343b742df4793268b80767 = $this->GenerateSelect();
        $_03e9164d0a343b742df4793268b80767->AddWhereAndClause($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_08aa8c9" . "63129565" . "6e6b3f40" . "3b6dcceb" . "3"], $this->wf_id);
        return parent::GetAll($_03e9164d0a343b742df4793268b80767);
    }
    
    
    
    
    
    
    
    public function GetCurrentStateRecord($_fc4ffcaec4dff19ed04cc1c9229222d1)
    {
        $_ac4dd3d87712b5121ec69acaf618c2ae = new WFStateRecord($_fc4ffcaec4dff19ed04cc1c9229222d1->GetDocId(), 0, $this->GetId(), $this->GetId());
        $_ac4dd3d87712b5121ec69acaf618c2ae->SetOrderFields(array($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_ae9ed3fb8f" . "83efe5c2377" . "b2ecc07bc6a"] => $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_a5b8a957b6bb889a6" . "5d0110f7df85ff0"]));
        $_9c6efcc5e053323ba2a6eca510b6e7c1 = $_ac4dd3d87712b5121ec69acaf618c2ae->GetSameByDoc(1);
        if (empty($_9c6efcc5e053323ba2a6eca510b6e7c1)) {
            global $db;
            $db->DisableTokenCheck();
            if (!$_fc4ffcaec4dff19ed04cc1c9229222d1->SetWorkflow($this->GetWorkflowId())) {
                $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_4278f6e1" . "f1e27cc1e" . "96763e462" . "0a4ff5"]($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_3312b0cb5703d1db25d59cc9d10576" . "b5"]);
            }
            $_fc4ffcaec4dff19ed04cc1c9229222d1->Save();
            $db->EnableTokenCheck();
            $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_04014b4c4cd7f8beafc0" . "6c912139b979"]($_fc4ffcaec4dff19ed04cc1c9229222d1->GetDetailsUrl(), $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_0be6b0fbf9ef1bbe3173ce58ec29b5" . "a4"]);
        }
        
        
        
        
        
        
        
        
        
        
        return $_9c6efcc5e053323ba2a6eca510b6e7c1[0];
    }
    
    
    
    
    
    
    
    
    
    public function GetId()
    {
        return $this->id;
    }
    
    
    
    
    
    
    public function GetWorkflowId()
    {
        return $this->wf_id;
    }
    
    
    
    
    
    
    public function SetWorkflowId($_eb57e3a45673c8e851b42c4eee3742ea)
    {
        $this->wf_id = $_eb57e3a45673c8e851b42c4eee3742ea;
    }
    
    
    
    
    
    
    public function GetName()
    {
        return $this->name;
    }
    
    
    
    
    
    
    
    public function SetName($name)
    {
        $this->name = $name;
        return true;
    }
    
    
    
    
    
    
    public function GetDescription()
    {
        return $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_4d707fab93bebb00bb" . "e69e8159697c90"];
        
        
    }
    
    
    
    
    
    
    
    public function SetDescription($_28fd57f750dbb5ffb3ffad3a888358a9)
    {
        
        
        return true;
    }
    
    
    
    
    
    
    public function GetPosition()
    {
        return $this->position;
    }
    
    
    
    
    
    
    
    public function SetPosition($_2cc1b85bbc9f36a91e2f3d508cf9bf8d)
    {
        $this->position = $_2cc1b85bbc9f36a91e2f3d508cf9bf8d;
        return true;
    }
    
    
    
    
    
    
    
    
    public function InterchangePosition($_939c6a45ff74323dbef487ed15753a7c)
    {
        $_162aeb4711aa43fb3fe1174135bf392b = $this->GetPosition();
        if (!$this->SetPosition($_939c6a45ff74323dbef487ed15753a7c->GetPosition())) {
            return false;
        }
        if (!$_939c6a45ff74323dbef487ed15753a7c->SetPosition($_162aeb4711aa43fb3fe1174135bf392b)) {
            return $this->SetErrMsg($_939c6a45ff74323dbef487ed15753a7c->GetErrMsg());
        }
        return true;
    }
    
    
    
    
    
    
    public function GetColor()
    {
        return $this->color;
    }
    
    
    
    
    
    
    
    public function SetColor($_84929763267bc12007295ccd54f62914)
    {
        $this->color = $_84929763267bc12007295ccd54f62914;
        return true;
    }
    
    
    
    
    
    
    
    public function IsDocReadOnly($_8c9249e463d11409b79e6388da984746)
    {
        if ($this->readonly == 0) {
            return false;
        }
        if ($this->readonly == 1 && $_8c9249e463d11409b79e6388da984746) {
            return false;
        }
        return true;
    }
    
    
    
    
    
    
    
    
    public function SetDocReadOnly($_180ea657011c448f11aaebc69876d1e8, $_65e3b1a9bda3bc3df3903495b175f348 = false)
    {
        if ($_180ea657011c448f11aaebc69876d1e8 && $_65e3b1a9bda3bc3df3903495b175f348) {
            $this->readonly = 1;
        }
        if ($_180ea657011c448f11aaebc69876d1e8 && !$_65e3b1a9bda3bc3df3903495b175f348) {
            $this->readonly = 2;
        }
        if (!$_180ea657011c448f11aaebc69876d1e8) {
            $this->readonly = 0;
        }
        return true;
    }
    
    
    
    
    
    
    public function IsImportantForManagers()
    {
        return $this->resp_notify != 0;
    }
    
    
    
    
    
    
    
    public function SetImportantForManagers($_79ceeeb0539ecf8ac5fda27f7c869adc)
    {
        $this->resp_notify = $_79ceeeb0539ecf8ac5fda27f7c869adc ? 1 : 0;
        return true;
    }
    
    
    
    
    
    
    public function GetAction()
    {
        $_c60d997eb275f45e26bd9fb6327091c8 = $this->GetAllActions();
        if (!$_c60d997eb275f45e26bd9fb6327091c8) {
            return null;
        }
        $action = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_5846ddea7ff6d30bd0e7b4" . "a81710776e"]($_c60d997eb275f45e26bd9fb6327091c8);
        $action->Load();
        return $action;
    }
    
    
    
    
    
    
    
    
    public function InitState($_fc4ffcaec4dff19ed04cc1c9229222d1)
    {
        
        
        $_c78f29e7b113c7a4d29fe3c4468181e9 = array();
        foreach ($this->GetAllActions() as $action) {
            if (!$action->InitAction($_fc4ffcaec4dff19ed04cc1c9229222d1)) {
                $_c78f29e7b113c7a4d29fe3c4468181e9[] = $action->GetErrMsg();
            }
        }
        
        
        foreach ($this->GetAllTransitions() as $_07e41711580f2279161feffa9f744876) {
            $_07e41711580f2279161feffa9f744876->InitTransition($_fc4ffcaec4dff19ed04cc1c9229222d1);
        }
        if (!empty($_c78f29e7b113c7a4d29fe3c4468181e9)) {
            $this->SetErrMsg($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_5159b3572969" . "eca46acd1b2e1" . "418459c"]($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_88c0fe4439f1efb05b37d" . "61d25d02f4f"], $_c78f29e7b113c7a4d29fe3c4468181e9));
        }
        return true;
    }
    
    
    
    
    
    
    public function SetNotifyOwner($_ddaadf1c7ecfd539ad81a268b1668f7a)
    {
        $this->owner_notify = (int) $_ddaadf1c7ecfd539ad81a268b1668f7a;
    }
    
    
    
    
    
    
    public function GetNotifyOwner()
    {
        return $this->owner_notify;
    }
}