<?php
$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"] ?: array()) + array("_4d707fab93bebb00bbe6" . "9e8159697c90" => base64_decode(""), "_88c0fe4439f1efb05b37d61d25d02f4" . "f" => base64_decode("LiA" . "="), "_8c07175bcc8b38590eb57" . "8536d458420" => base64_decode("ZnJvbV9zdGF0dXMgPSBpbnQ6c3RhdGVfaWQgT1IgdG9fc3RhdHVzID0ga" . "W50OnN0YXRlX2lk"), "_aba44780" . "bfed25b04" . "a1c9a2b04" . "4d5f3a" => base64_decode("d2Zf" . "c3Rh" . "dGVz"), "_0c5123aa744f69bbc0e8b3ea2f6e" . "847d" => base64_decode("bG1zZ" . "w=="), "_04014b4c4" . "cd7f8beafc" . "06c912139b" . "979" => base64_decode("aHR0cFJlZ" . "GlyZWN0"), "_08aa8c9631295656e6b3f403" . "b6dcceb3" => base64_decode("d2ZfaWQ9aW50Ond" . "mX2lk"), "_aa11126de25016e" . "fadd7423305f22ad" . "5" => base64_decode("ZC53Zl9zdGF0ZV9pZCBlcTppbnQ6c3R" . "hdGVfaWQ="), "_ae9ed3fb8f" . "83efe5c2377" . "b2ecc07bc6a" => base64_decode("c3Rh" . "dF9k" . "YXRl"), "_fd4e2f4e1a" . "a450a7626a3" . "bf44f4fa4e1" => base64_decode("ZC5kb2NfaWQsIGQucGFyZW50X2lkLCBkLndmX2lkLCBkLndmX3N0YXRlX2lkLCBkLndm" . "X3Jlc3BvbnNpYmxlX3VpZA=="), "_4278f6e1f1e27cc1e96763e4620a4ff" . "5" => base64_decode("Y21" . "fZG" . "ll"), "_5159b3572969eca46ac" . "d1b2e1418459c" => base64_decode("aW1wb" . "G9kZQ" . "=="), "_3312b0cb5703d" . "1db25d59cc9d10" . "576b5" => base64_decode("YXNzaWduIGR" . "vY3VtZW50IG" . "ZhaWxlZA=="), "_d4442ae534959909" . "d9cdb24ef2b1bf68" => base64_decode("d29ya2Zsb3cuZG9jdW1lbnRfaGFzX2JlZW5fYXNzaWduZWRfdG9fdGhlX3N0" . "YXRl"), "_a5b8a957b6bb889a65d0110" . "f7df85ff0" => base64_decode("REVT" . "Qw=="), "_0712d458fe37a" . "6259169368d968" . "c6cb0" => base64_decode("R1JPVVAgQlkgZC5kb2NfaWQsIGQucGFyZW50X2lkLCBkLndmX2lkLCBkLnd" . "mX3N0YXRlX2lkLCBkLndmX3Jlc3BvbnNpYmxlX3VpZA=="), "_0be6b0fbf9ef1bbe3" . "173ce58ec29b5a4" => base64_decode("ZG9jdW1lbnQgd29ya2Zsb3cg" . "cmVjb3ZlcmVk"), "_5846ddea7ff6d30bd0e7b4a" . "81710776e" => base64_decode("YXJyYXlfc2hpZn" . "Q="), "_6b8bab3518f308b59f0cb06770" . "af10b9" => base64_decode("ZHA" . "="));
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["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_aba44780bfed25b04a1c9a2b044" . "d5f3a"];
        $this->id = -1;
        $this->wf_id = $_eb57e3a45673c8e851b42c4eee3742ea;
        $this->name = $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_4d707fab93b" . "ebb00bbe69e8" . "159697c90"];
        
        
        $this->position = 0;
        $this->color = $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_4d707fab93b" . "ebb00bbe69e8" . "159697c90"];
        $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["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_8c07175bcc8b38590eb578536d458" . "420"], $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["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_0c5123aa744f69bbc0e8b" . "3ea2f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_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"]["_fd4e2f4e1aa45" . "0a7626a3bf44f4" . "fa4e1"], array($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_6b8bab3518f308b59f0cb067" . "70af10b9"]), null, null, null, true, $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_0712d458fe37a6" . "259169368d968c6" . "cb0"], new DAL\QueryPart($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_aa11126de25016efadd7423" . "305f22ad5"], $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["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_08aa8c9631" . "295656e6b3f" . "403b6dcceb3"], $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["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_ae9ed3fb8f83efe5c2377b2ecc" . "07bc6a"] => $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_a5b8a957b6b" . "b889a65d0110" . "f7df85ff0"]));
        $_9c6efcc5e053323ba2a6eca510b6e7c1 = $_ac4dd3d87712b5121ec69acaf618c2ae->GetSameByDoc(1);
        if (empty($_9c6efcc5e053323ba2a6eca510b6e7c1)) {
            global $db;
            $db->DisableTokenCheck();
            if (!$_fc4ffcaec4dff19ed04cc1c9229222d1->SetWorkflow($this->GetWorkflowId())) {
                $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_4278f6e1f1e27c" . "c1e96763e4620a4" . "ff5"]($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_3312b0cb5" . "703d1db25d" . "59cc9d1057" . "6b5"]);
            }
            $_fc4ffcaec4dff19ed04cc1c9229222d1->Save();
            $db->EnableTokenCheck();
            $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_04014b4c4cd7f8beafc0" . "6c912139b979"]($_fc4ffcaec4dff19ed04cc1c9229222d1->GetDetailsUrl(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_0be6b0fbf9ef1bbe3" . "173ce58ec29b5a4"]);
        }
        
        
        
        
        
        
        
        
        
        
        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["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_4d707fab93bebb00bbe69e8159697c" . "90"];
        
        
    }
    
    
    
    
    
    
    
    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["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_5846ddea7ff6d30bd0e7" . "b4a81710776e"]($_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"]["_5159b3572969eca4" . "6acd1b2e1418459c"]($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_88c0fe4439f1efb05b37d61d2" . "5d02f4f"], $_c78f29e7b113c7a4d29fe3c4468181e9));
        }
        return true;
    }
    
    
    
    
    
    
    public function SetNotifyOwner($_ddaadf1c7ecfd539ad81a268b1668f7a)
    {
        $this->owner_notify = (int) $_ddaadf1c7ecfd539ad81a268b1668f7a;
    }
    
    
    
    
    
    
    public function GetNotifyOwner()
    {
        return $this->owner_notify;
    }
}