<?php
$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"] ?: array()) + array("_4278f6e1f1e2" . "7cc1e96763e46" . "20a4ff5" => base64_decode("Y21f" . "ZGll"), "_88c0fe4439f1efb05b37d61d25d" . "02f4f" => base64_decode("L" . "i" . "A" . "="), "_5159b3572969e" . "ca46acd1b2e141" . "8459c" => base64_decode("aW1wbG9kZQ" . "=="), "_a5b8a957b6bb889a65d0110f7d" . "f85ff0" => base64_decode("RE" . "VT" . "Qw" . "=="), "_8c07175bcc8b38590eb578536d45" . "8420" => base64_decode("ZnJvbV9zdGF0dXMgPSBpbnQ6c3RhdGVfaWQgT1" . "IgdG9fc3RhdHVzID0gaW50OnN0YXRlX2lk"), "_04014b4c4cd" . "7f8beafc06c9" . "12139b979" => base64_decode("aHR0cFJlZGl" . "yZWN0"), "_d4442ae534959909d9cdb24ef" . "2b1bf68" => base64_decode("d29ya2Zsb3cuZG9jdW1lbnRf" . "aGFzX2JlZW5fYXNzaWduZWRf" . "dG9fdGhlX3N0YXRl"), "_5846ddea7ff6" . "d30bd0e7b4a81" . "710776e" => base64_decode("YXJyYXlfc2h" . "pZnQ="), "_ae9ed3f" . "b8f83efe" . "5c2377b2" . "ecc07bc6" . "a" => base64_decode("c3R" . "hdF" . "9kY" . "XRl"), "_0be6b0fbf9ef1bbe3173ce58ec29b5" . "a4" => base64_decode("ZG9jdW1lbnQgd" . "29ya2Zsb3cgcm" . "Vjb3ZlcmVk"), "_3312b0cb5703d1db25d59cc9d10576b" . "5" => base64_decode("YXNzaWduIGR" . "vY3VtZW50IG" . "ZhaWxlZA=="), "_0c5123aa744f69b" . "bc0e8b3ea2f6e847" . "d" => base64_decode("bG1z" . "Zw=="), "_aa11126de25016efad" . "d7423305f22ad5" => base64_decode("ZC53Zl9zdGF0ZV9pZCBlcTppbnQ6" . "c3RhdGVfaWQ="), "_4d707fab93bebb00bbe69e8159697c9" . "0" => base64_decode(""), "_6b8bab3518f308b59f0cb067" . "70af10b9" => base64_decode("ZHA" . "="), "_aba44780" . "bfed25b04" . "a1c9a2b04" . "4d5f3a" => base64_decode("d2Zf" . "c3Rh" . "dGVz"), "_fd4e2f4e1aa450a7626a3" . "bf44f4fa4e1" => base64_decode("ZC5kb2NfaWQsIGQucGFyZW50X2lkL" . "CBkLndmX2lkLCBkLndmX3N0YXRlX2" . "lkLCBkLndmX3Jlc3BvbnNpYmxlX3V" . "pZA=="), "_08aa8c9" . "63129565" . "6e6b3f40" . "3b6dcceb" . "3" => base64_decode("d2ZfaWQ9aW50Ondm" . "X2lk"), "_0712d458" . "fe37a6259" . "169368d96" . "8c6cb0" => base64_decode("R1JPVVAgQlkgZC5kb2NfaWQsIGQucGFyZW50X2lkLCBkLndmX2lkLCBkLndmX3N0YXRlX2lkLCBkLndmX3Jlc3BvbnNpYmx" . "lX3VpZA=="));
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["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_aba44780bfed25b0" . "4a1c9a2b044d5f3a"];
        $this->id = -1;
        $this->wf_id = $_eb57e3a45673c8e851b42c4eee3742ea;
        $this->name = $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_4d707fab93bebb00bbe69e8" . "159697c90"];
        
        
        $this->position = 0;
        $this->color = $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_4d707fab93bebb00b" . "be69e8159697c90"];
        $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["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_8c07175" . "bcc8b385" . "90eb5785" . "36d45842" . "0"], $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"]["_0c5123aa" . "744f69bbc" . "0e8b3ea2f" . "6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_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["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_fd4e2f4e1aa450a7626a3" . "bf44f4fa4e1"], array($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_6b8bab3518f308b59f0cb067" . "70af10b9"]), null, null, null, true, $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_0712d458fe37a6259169368d968c" . "6cb0"], new DAL\QueryPart($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_aa11126de25016efadd742330" . "5f22ad5"], $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"]["_08aa8c96312956" . "56e6b3f403b6dcc" . "eb3"], $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["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_ae9ed3fb8f83" . "efe5c2377b2ec" . "c07bc6a"] => $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_a5b8a957b6bb889a65d0110f7d" . "f85ff0"]));
        $_9c6efcc5e053323ba2a6eca510b6e7c1 = $_ac4dd3d87712b5121ec69acaf618c2ae->GetSameByDoc(1);
        if (empty($_9c6efcc5e053323ba2a6eca510b6e7c1)) {
            global $db;
            $db->DisableTokenCheck();
            if (!$_fc4ffcaec4dff19ed04cc1c9229222d1->SetWorkflow($this->GetWorkflowId())) {
                $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_4278f6e1f1e27c" . "c1e96763e4620a4" . "ff5"]($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_3312b0cb" . "5703d1db2" . "5d59cc9d1" . "0576b5"]);
            }
            $_fc4ffcaec4dff19ed04cc1c9229222d1->Save();
            $db->EnableTokenCheck();
            $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_04014b4c4cd7f8beafc06c912139b97" . "9"]($_fc4ffcaec4dff19ed04cc1c9229222d1->GetDetailsUrl(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_0be6b0fbf9ef1bbe3173ce58e" . "c29b5a4"]);
        }
        
        
        
        
        
        
        
        
        
        
        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["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_4d707fab93beb" . "b00bbe69e81596" . "97c90"];
        
        
    }
    
    
    
    
    
    
    
    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"]["_5846ddea7ff6d" . "30bd0e7b4a8171" . "0776e"]($_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["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_5159b35" . "72969eca" . "46acd1b2" . "e1418459" . "c"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_88c0fe4439f1efb0" . "5b37d61d25d02f4f"], $_c78f29e7b113c7a4d29fe3c4468181e9));
        }
        return true;
    }
    
    
    
    
    
    
    public function SetNotifyOwner($_ddaadf1c7ecfd539ad81a268b1668f7a)
    {
        $this->owner_notify = (int) $_ddaadf1c7ecfd539ad81a268b1668f7a;
    }
    
    
    
    
    
    
    public function GetNotifyOwner()
    {
        return $this->owner_notify;
    }
}