<?php
namespace Claromentis\Orgchart\Controller;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"] = (@$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"] ?: array()) + array("_4d707fab93" . "bebb00bbe69" . "e8159697c90" => base64_decode(""), "_78e464dc81eb33" . "8a3607998820d86" . "b62" => base64_decode("b3JnY2hhcnQuYWRtaW4uY29u" . "ZmlnLnVwZGF0ZWQ="), "_9ed68b6f36b3372642" . "0eb70ac5f8af82" => base64_decode("b3JnY2hhcnQuYWRtaW4uY29uZmlnL" . "nRpdGxl"), "ac" . "ti" . "on" => base64_decode("YW" . "N0" . "aW" . "9u"), "_28cc9c7ccf71b810dd45" . "87d9d76cb622" => base64_decode("b3JnY2hhcnQuY29tbW9uLmRl" . "bGV0ZWQ="), "_0c5123aa744f69bbc0e8b3ea" . "2f6e847d" => base64_decode("bG1" . "zZw" . "=="), "_47cb0be7fd3" . "5c0727eb1f73" . "e321ea1b9" => base64_decode("Y29tbW9uL" . "nBlcm1zLn" . "Blcm1zX3V" . "wZGF0ZWQ="), "_ba5a3d894eac7a600c05551aa4c0" . "3cc3" => base64_decode("b3JnY2hhcnQv" . "YWRtaW4vaW5k" . "ZXguaHRtbA=="), "a" . "c" . "l" => base64_decode("YW" . "Ns"), "_70809333a0f254" . "acf7a1ad0c7dadd" . "46b" => base64_decode("O" . "i" . "A" . "="), "_72649a3d80e7189dc203d0" . "9f55cdc062" => base64_decode("b3JnY2hhcnQuYWRtaW" . "4ucHJvZmlsZV9maWVs" . "ZHMudXBkYXRlZA=="), "_07ccde2e1abe46a6e90" . "b9fa1767bb33a" => base64_decode("ZGVsZXR" . "l"), "_d314fa727a3fc693da3f1a15dae" . "f765e" => base64_decode("Y29uZmlnX3Jvd3NfY3ljbG" . "UuZGF0YXNyYw=="), "_1a2c5ddb4a2bf007" . "c8ec7c2d947a22cf" => base64_decode("b3JnY2hhcnQvYWRtaW4" . "vY29uZmlnLmh0bWw="), "_18ae8370673175f" . "687c8141438892be" . "b" => base64_decode("Y29tbW9uL" . "nBlcm1zLm" . "1hbmFnZQ=" . "="), "i" . "d" => base64_decode("aW" . "Q="), "_5254b5b933003372a6f946933b3" . "17396" => base64_decode("b3JnY2hhcnQvY" . "WRtaW4vcGVybX" . "MuaHRtbA=="), "_1e34f99fa3159cae8fcbe0" . "e4eaedfb7a" => base64_decode("b3JnY2hhcn" . "QuYWRtaW4u" . "cGVybWlzc2" . "lvbnM="), "_86bd78b845" . "ed65863bd10" . "298b532a7d8" => base64_decode("b3JnY2hhcnQuYWRtaW4ucHJvZmls" . "ZV9maWVsZHM="), "_ba44f671f2a1" . "4918205ff55cb" . "f0542d7" => base64_decode("b3JnY2hhcnQ" . "ub3JnY2hhcn" . "RfcmVwb3Npd" . "G9yeQ=="), "_b34dd7ceba9e7677d12561" . "de2fac5426" => base64_decode("b3JnY2hhcnQvYWRtaW4vcHJvZmlsZS1maWVsZHMua" . "HRtbA=="), "_d312f97c814863ce4df29f5db8" . "e665f0" => base64_decode("b3JnY2hhcnQuYWRtaW4ubG" . "lzdGluZw=="), "_e49f2ce698c5556228f0711c3b4" . "3bdbf" => base64_decode("b3JnY2hhcnQuY" . "29tbW9uLm5vdF" . "9mb3VuZA=="));
use Claromentis\Core\Acl\AclRepository;
use Claromentis\Core\Acl\CommonPermsDialog;
use Claromentis\Core\Acl\Exception\AclException;
use Claromentis\Core\Application;
use Claromentis\Core\Config\ConfigDialog;
use Claromentis\Core\Http\gpc;
use Claromentis\Core\Http\RequestData;
use Claromentis\Core\Http\RequestDataTokenException;
use Claromentis\Core\Http\TemplaterCallResponse;
use Claromentis\Orgchart\Config\ConfigOptions;
use Claromentis\Orgchart\Exception\OrgchartNotFoundException;
use Claromentis\Orgchart\OrgchartApplication;
use Claromentis\Orgchart\OrgchartRepository;
use Claromentis\Orgchart\Perm;
use Claromentis\Orgchart\Service\OrgchartProfileFieldService;
use Claromentis\Orgchart\View\ProfileFieldsView;
use Claromentis\People\UserFieldsConfigService;
use Psr\Http\Message\ServerRequestInterface;
class OrgchartAdminController
{
    private UserFieldsConfigService $userFieldsConfigService;
    private OrgchartProfileFieldService $orgchartProfileFieldService;
    public function __construct(UserFieldsConfigService $userFieldsConfigService, OrgchartProfileFieldService $orgchartProfileFieldService)
    {
        $this->userFieldsConfigService = $userFieldsConfigService;
        $this->orgchartProfileFieldService = $orgchartProfileFieldService;
    }
    public function AdminHomepage(Application $app, ServerRequestInterface $request)
    {
        
        
        $_678d945258a520c3df1c42fe4b558f34 = $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_0c5123aa744f69bbc0e8b" . "3ea2f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_d312f97c814863c" . "e4df29f5db8e665f" . "0"]);
        $args = [];
        $message = $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_4d707fab93bebb" . "00bbe69e8159697" . "c90"];
        $is_error_message = false;
        
        
        $_0bb8bac53757cffec6387614650ed2d8 = $app[$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_ba44f671f2a14918205ff55cb" . "f0542d7"]];
        if (gpc::IsSubmit($request) && gpc::GetStringOrNull($request, $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["acti" . "on"]) == $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_07ccde2e1abe46a6e90b9fa176" . "7bb33a"]) {
            try {
                $_08328d03bde61c25f3f3ac2f0b278b96 = $_0bb8bac53757cffec6387614650ed2d8->LoadById(gpc::GetIntOrNull($request, $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["i" . "d"]));
                $_0bb8bac53757cffec6387614650ed2d8->Delete($_08328d03bde61c25f3f3ac2f0b278b96->id);
                $message = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_0c5123aa74" . "4f69bbc0e8b" . "3ea2f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_28cc9c7ccf71b810dd" . "4587d9d76cb622"]);
            } catch (OrgchartNotFoundException $e) {
                $message = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_0c5123aa744f69bbc0e8b" . "3ea2f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_e49f2ce698c5556228f0711c3b4" . "3bdbf"]) . $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_70809333a0f254acf7a1ad0c7dad" . "d46b"] . $e->getMessage();
                $is_error_message = true;
            }
        }
        $template = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_ba5a3d894eac7a600c0555" . "1aa4c03cc3"];
        $response = new TemplaterCallResponse($template, $args, $_678d945258a520c3df1c42fe4b558f34);
        $response->SetMessage($message, $is_error_message);
        return $response;
    }
    public function AdminPermissions(Application $app, ServerRequestInterface $request)
    {
        
        
        $_678d945258a520c3df1c42fe4b558f34 = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_0c5123aa7" . "44f69bbc0e" . "8b3ea2f6e8" . "47d"]($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_1e34f99fa3159c" . "ae8fcbe0e4eaedf" . "b7a"]);
        $args = [];
        
        
        $acl = $app[$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["a" . "c" . "l"]];
        $message = $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_4d707fab93bebb0" . "0bbe69e8159697c9" . "0"];
        $is_error_message = false;
        try {
            $perms = $acl->Get(Perm::CLASS_ORGCHART_ADMIN, 1);
            $_72118176b3ec2f8e909729c620b4069f = new CommonPermsDialog($perms);
            if (gpc::IsSubmit($request)) {
                $_72118176b3ec2f8e909729c620b4069f->Update($request);
                $acl->Save($_72118176b3ec2f8e909729c620b4069f->permissions);
                $message = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_0c5123aa744f69bbc0e8b3ea2f" . "6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_47cb0be7fd35c0727eb1f73e321ea1" . "b9"]);
            }
            $_72118176b3ec2f8e909729c620b4069f->SetAllPermValues(array(Perm::PERM_MANAGE => array($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_0c5123aa" . "744f69bbc" . "0e8b3ea2f" . "6e847d"]($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_18ae8370673175f687c8" . "141438892beb"]), true)));
            $_72118176b3ec2f8e909729c620b4069f->SetShowButtons(true, false, true);
            $_72118176b3ec2f8e909729c620b4069f->Show($args);
        } catch (AclException $e) {
            $is_error_message = true;
            $message = $e->getMessage();
        }
        $template = $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_5254b5b933003372a6f946933b3173" . "96"];
        $response = new TemplaterCallResponse($template, $args, $_678d945258a520c3df1c42fe4b558f34);
        $response->SetMessage($message, $is_error_message);
        return $response;
    }
    public function AdminConfig(Application $app, ServerRequestInterface $request, RequestData $requestData)
    {
        $_678d945258a520c3df1c42fe4b558f34 = $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_0c5123aa744f6" . "9bbc0e8b3ea2f6" . "e847d"]($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_9ed68b6f36b33726420eb70ac5f8a" . "f82"]);
        $args = [];
        $message = $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_4d707fab93bebb00bbe69e8159697" . "c90"];
        $is_error_message = false;
        $options = ConfigOptions::GetAll();
        $config = OrgchartApplication::getConfig();
        $config_dialog = new ConfigDialog($options, $config);
        try {
            if ($requestData->IsSubmit()) {
                $config_dialog->Update($request);
                $config->Save();
                $message = $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_0c5123aa744f69bbc" . "0e8b3ea2f6e847d"]($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_78e464dc81eb338a3607998820d86b" . "62"]);
            }
        } catch (RequestDataTokenException|\Exception $e) {
            $is_error_message = true;
            $message = $e->getMessage();
        }
        $args[$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_d314fa727a3fc693da3f" . "1a15daef765e"]] = $config_dialog->Show();
        $template = $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_1a2c5ddb4a2bf0" . "07c8ec7c2d947a2" . "2cf"];
        $response = new TemplaterCallResponse($template, $args, $_678d945258a520c3df1c42fe4b558f34);
        $response->SetMessage($message, $is_error_message);
        return $response;
    }
    public function AdminProfileFields(Application $app, ServerRequestInterface $request, RequestData $requestData)
    {
        $is_error_message = false;
        $message = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_4d707fab93bebb00bbe69e8" . "159697c90"];
        try {
            if ($requestData->IsSubmit()) {
                $this->orgchartProfileFieldService->UpdateProfileFields($request->getParsedBody());
                $message = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_0c5123aa744f69bbc0e8b3ea2f6e847" . "d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_72649a3d80e71" . "89dc203d09f55c" . "dc062"]);
            }
        } catch (RequestDataTokenException|\Exception $e) {
            $is_error_message = true;
            $message = $e->getMessage();
        }
        
        
        $_678d945258a520c3df1c42fe4b558f34 = $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_0c5123aa744f69bbc0e8b3ea2f6" . "e847d"]($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_86bd78b845e" . "d65863bd1029" . "8b532a7d8"]);
        $_a579fe48d5d666088ef799a735048776 = new ProfileFieldsView($this->userFieldsConfigService);
        $args = $_a579fe48d5d666088ef799a735048776->buildFields(OrgchartApplication::getConfig()->get(OrgchartProfileFieldService::CONFIG_KEY) ?: []);
        $template = $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_b34dd7ce" . "ba9e7677d" . "12561de2f" . "ac5426"];
        $response = new TemplaterCallResponse($template, $args, $_678d945258a520c3df1c42fe4b558f34);
        $response->SetMessage($message, $is_error_message);
        return $response;
    }
}