<?php
$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"] ?: array()) + array("_4d707fab93bebb00bbe69e815969" . "7c90" => base64_decode(""), "_d4442ae534959909d9cdb24ef2b1" . "bf68" => base64_decode("d29ya2Zsb3cuZG9jdW1lbnRfaGFzX2JlZW5fYXNzaWduZWRf" . "dG9fdGhlX3N0YXRl"), "_fd4e2f4e1aa450a7626a3bf44" . "f4fa4e1" => base64_decode("ZC5kb2NfaWQsIGQucGFyZW50X" . "2lkLCBkLndmX2lkLCBkLndmX3" . "N0YXRlX2lkLCBkLndmX3Jlc3B" . "vbnNpYmxlX3VpZA=="), "_88c0fe4439" . "f1efb05b37d" . "61d25d02f4f" => base64_decode("LiA" . "="), "_04014b4c4cd7f8beafc06c91213" . "9b979" => base64_decode("aHR0cFJl" . "ZGlyZWN0"), "_6b8bab3518f308b" . "59f0cb06770af10b" . "9" => base64_decode("Z" . "H" . "A" . "="), "_0be6b0fbf9ef1bbe3173ce58ec29b" . "5a4" => base64_decode("ZG9jdW1lbnQgd29ya2Zsb3cgcmVjb3Zlc" . "mVk"), "_5846ddea7ff6d30bd0e7b4a81710776" . "e" => base64_decode("YXJyYXlfc2hpZ" . "nQ="), "_aba44780bfed25b04a" . "1c9a2b044d5f3a" => base64_decode("d2Zfc3R" . "hdGVz"), "_a5b8a957b6bb889a65d0110f7df85f" . "f0" => base64_decode("REVTQw" . "=="), "_8c07175bcc8b38590eb57" . "8536d458420" => base64_decode("ZnJvbV9zdGF0dXMgPSBpbnQ6c3RhdGVfaWQgT1IgdG9fc3RhdHVzID0gaW50OnN0YXRl" . "X2lk"), "_4278f6e1f1e27cc1e96763" . "e4620a4ff5" => base64_decode("Y21fZGl" . "l"), "_3312b0cb5703d1db25d59cc9d10576" . "b5" => base64_decode("YXNzaWduIGRvY3VtZW50" . "IGZhaWxlZA=="), "_ae9ed3fb8f83efe5c2" . "377b2ecc07bc6a" => base64_decode("c3RhdF9kY" . "XRl"), "_0712d458fe37a6259169368d9" . "68c6cb0" => base64_decode("R1JPVVAgQlkgZC5kb2NfaWQsIGQucGFyZW50X2lkLCBkLndmX2lkLCBkLndmX3N0YXRlX2lkLCBkLnd" . "mX3Jlc3BvbnNpYmxlX3VpZA=="), "_08aa8c9631295656e6b3f" . "403b6dcceb3" => base64_decode("d2Zfa" . "WQ9aW" . "50Ond" . "mX2lk"), "_0c5123aa744f69" . "bbc0e8b3ea2f6e8" . "47d" => base64_decode("bG1zZw" . "=="), "_5159b3572969eca" . "46acd1b2e1418459" . "c" => base64_decode("aW1wbG9kZQ" . "=="), "_aa11126" . "de25016e" . "fadd7423" . "305f22ad" . "5" => base64_decode("ZC53Zl9zdGF0Z" . "V9pZCBlcTppbn" . "Q6c3RhdGVfaWQ" . "="));
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["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_aba44780bfed25b04" . "a1c9a2b044d5f3a"];
        $this->id = -1;
        $this->wf_id = $_eb57e3a45673c8e851b42c4eee3742ea;
        $this->name = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_4d707fab93bebb00bbe69e815" . "9697c90"];
        
        
        $this->position = 0;
        $this->color = $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_4d707fab93bebb00bbe6" . "9e8159697c90"];
        $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["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_8c07175bcc8" . "b38590eb5785" . "36d458420"], $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["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_0c5123aa744f69b" . "bc0e8b3ea2f6e847" . "d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_d4442ae534959909" . "d9cdb24ef2b1bf68"]), 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["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_fd4e2f4e1aa450a76" . "26a3bf44f4fa4e1"], array($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_6b8bab3518f308b59f0" . "cb06770af10b9"]), null, null, null, true, $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_0712d458f" . "e37a625916" . "9368d968c6" . "cb0"], 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["__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["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_ae9ed3fb8f83" . "efe5c2377b2ec" . "c07bc6a"] => $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_a5b8a95" . "7b6bb889" . "a65d0110" . "f7df85ff" . "0"]));
        $_9c6efcc5e053323ba2a6eca510b6e7c1 = $_ac4dd3d87712b5121ec69acaf618c2ae->GetSameByDoc(1);
        if (empty($_9c6efcc5e053323ba2a6eca510b6e7c1)) {
            global $db;
            $db->DisableTokenCheck();
            if (!$_fc4ffcaec4dff19ed04cc1c9229222d1->SetWorkflow($this->GetWorkflowId())) {
                $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_4278f6e1f1e27cc1e96763e4620a4ff" . "5"]($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_3312b0cb5703d1db25d59cc9d1" . "0576b5"]);
            }
            $_fc4ffcaec4dff19ed04cc1c9229222d1->Save();
            $db->EnableTokenCheck();
            $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_04014b4c4cd7f8beafc06c912139b9" . "79"]($_fc4ffcaec4dff19ed04cc1c9229222d1->GetDetailsUrl(), $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_0be6b0fbf9ef1bb" . "e3173ce58ec29b5a" . "4"]);
        }
        
        
        
        
        
        
        
        
        
        
        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["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_4d707fab93b" . "ebb00bbe69e8" . "159697c90"];
        
        
    }
    
    
    
    
    
    
    
    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["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "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["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_5159b35729" . "69eca46acd1" . "b2e1418459c"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_88c0fe443" . "9f1efb05b3" . "7d61d25d02" . "f4f"], $_c78f29e7b113c7a4d29fe3c4468181e9));
        }
        return true;
    }
    
    
    
    
    
    
    public function SetNotifyOwner($_ddaadf1c7ecfd539ad81a268b1668f7a)
    {
        $this->owner_notify = (int) $_ddaadf1c7ecfd539ad81a268b1668f7a;
    }
    
    
    
    
    
    
    public function GetNotifyOwner()
    {
        return $this->owner_notify;
    }
}