<?php
$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"] ?: array()) + array("_4d707fab93bebb00bbe69" . "e8159697c90" => base64_decode(""), "_fd4e2f4e1aa450a7626" . "a3bf44f4fa4e1" => base64_decode("ZC5kb2NfaWQsIGQucGFyZW50X2lkLCB" . "kLndmX2lkLCBkLndmX3N0YXRlX2lkLC" . "BkLndmX3Jlc3BvbnNpYmxlX3VpZA=="), "_5159b3572969eca46acd1b2e" . "1418459c" => base64_decode("aW1" . "wbG" . "9kZ" . "Q=="), "_d4442ae" . "53495990" . "9d9cdb24" . "ef2b1bf6" . "8" => base64_decode("d29ya2Zsb3cuZG9jdW" . "1lbnRfaGFzX2JlZW5f" . "YXNzaWduZWRfdG9fdG" . "hlX3N0YXRl"), "_3312b0c" . "b5703d1d" . "b25d59cc" . "9d10576b" . "5" => base64_decode("YXNzaWduIGRvY" . "3VtZW50IGZhaW" . "xlZA=="), "_ae9ed3fb8f83efe5c2377b2e" . "cc07bc6a" => base64_decode("c3RhdF9kY" . "XRl"), "_6b8bab3518f308b59f0cb06770af10b" . "9" => base64_decode("ZHA" . "="), "_4278f6e1f1e2" . "7cc1e96763e46" . "20a4ff5" => base64_decode("Y2" . "1f" . "ZG" . "ll"), "_88c0fe4439f1efb05b37d61d25d02f" . "4f" => base64_decode("Li" . "A="), "_aba44780bfed2" . "5b04a1c9a2b044" . "d5f3a" => base64_decode("d2Zfc3RhdG" . "Vz"), "_8c07175bcc8b38590eb" . "578536d458420" => base64_decode("ZnJvbV9zdGF0dXMgPSBpbnQ6c3RhdGVfaWQgT1IgdG9f" . "c3RhdHVzID0gaW50OnN0YXRlX2lk"), "_0712d458fe37a62591693" . "68d968c6cb0" => base64_decode("R1JPVVAgQlkgZC5kb2NfaWQsIGQucGFyZW50X2lkLCBkLn" . "dmX2lkLCBkLndmX3N0YXRlX2lkLCBkLndmX3Jlc3BvbnNp" . "YmxlX3VpZA=="), "_08aa8c96312956" . "56e6b3f403b6dcc" . "eb3" => base64_decode("d2ZfaWQ9a" . "W50OndmX2" . "lk"), "_0c5123aa744f6" . "9bbc0e8b3ea2f6" . "e847d" => base64_decode("bG1" . "zZw" . "=="), "_0be6b0fbf9ef1bbe31" . "73ce58ec29b5a4" => base64_decode("ZG9jdW1lbnQgd29ya2Zsb3cgcmVjb" . "3ZlcmVk"), "_aa11126de25016efadd7423" . "305f22ad5" => base64_decode("ZC53Zl9zdGF0ZV9" . "pZCBlcTppbnQ6c3" . "RhdGVfaWQ="), "_5846ddea7ff6d30bd0e7b4a8" . "1710776e" => base64_decode("YXJyYXlfc2hp" . "ZnQ="), "_a5b8a957b6bb889a65d0110f7df85ff" . "0" => base64_decode("REVT" . "Qw=="), "_04014b4c4cd7f8beafc06c912139b9" . "79" => base64_decode("aHR0" . "cFJl" . "ZGly" . "ZWN0"));
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["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_aba44780bfed25b04a1c9a2b044d5f" . "3a"];
        $this->id = -1;
        $this->wf_id = $_eb57e3a45673c8e851b42c4eee3742ea;
        $this->name = $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_4d707fab93bebb00bbe69e8159697c" . "90"];
        
        
        $this->position = 0;
        $this->color = $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_4d707fa" . "b93bebb0" . "0bbe69e8" . "159697c9" . "0"];
        $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["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_8c07175bcc8b38590eb578536d4" . "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["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_0c5123aa744f69bbc0" . "e8b3ea2f6e847d"]($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_d4442ae534959909d9cdb2" . "4ef2b1bf68"]), 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["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_fd4e2f4e1aa450a7626a3bf44f4fa" . "4e1"], array($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_6b8bab35" . "18f308b59" . "f0cb06770" . "af10b9"]), null, null, null, true, $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_0712d458fe37a625916936" . "8d968c6cb0"], new DAL\QueryPart($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_aa11126de25016ef" . "add7423305f22ad5"], $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["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_08aa8c9631295656e6b3f403b6d" . "cceb3"], $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["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_ae9ed3fb8f83efe5c2377b2ecc07" . "bc6a"] => $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_a5b8a957b6bb889a65d0110f" . "7df85ff0"]));
        $_9c6efcc5e053323ba2a6eca510b6e7c1 = $_ac4dd3d87712b5121ec69acaf618c2ae->GetSameByDoc(1);
        if (empty($_9c6efcc5e053323ba2a6eca510b6e7c1)) {
            global $db;
            $db->DisableTokenCheck();
            if (!$_fc4ffcaec4dff19ed04cc1c9229222d1->SetWorkflow($this->GetWorkflowId())) {
                $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_4278f6e1f1e27cc1" . "e96763e4620a4ff5"]($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_3312b0cb5703d1db25d59cc9d10576" . "b5"]);
            }
            $_fc4ffcaec4dff19ed04cc1c9229222d1->Save();
            $db->EnableTokenCheck();
            $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_04014b4c4cd7f8beafc06c91" . "2139b979"]($_fc4ffcaec4dff19ed04cc1c9229222d1->GetDetailsUrl(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_0be6b0fbf9ef1bbe3173" . "ce58ec29b5a4"]);
        }
        
        
        
        
        
        
        
        
        
        
        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["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_4d707fab93bebb00bbe69e815969" . "7c90"];
        
        
    }
    
    
    
    
    
    
    
    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["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_5846ddea7ff6d30bd0" . "e7b4a81710776e"]($_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["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_5159b357296" . "9eca46acd1b2" . "e1418459c"]($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_88c0fe4439f" . "1efb05b37d61" . "d25d02f4f"], $_c78f29e7b113c7a4d29fe3c4468181e9));
        }
        return true;
    }
    
    
    
    
    
    
    public function SetNotifyOwner($_ddaadf1c7ecfd539ad81a268b1668f7a)
    {
        $this->owner_notify = (int) $_ddaadf1c7ecfd539ad81a268b1668f7a;
    }
    
    
    
    
    
    
    public function GetNotifyOwner()
    {
        return $this->owner_notify;
    }
}