<?php
namespace Claromentis\Blog\Controller;

$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"] ?: array()) + array("_c4d674abe9291be143" . "b224c411958fcf" => base64_decode("b3duZX" . "I="), "_70c63623a" . "9e0fe4bf31" . "018c3e9f9b" . "983" => base64_decode("YmxvZy9hZG1pbi9hZG1pbl9jaGF" . "ubmVscy5odG1s"), "_678d945258" . "a520c3df1c4" . "2fe4b558f34" => base64_decode("cGFnZV90aX" . "RsZQ=="), "_faae81f2e" . "21f08c17e7" . "678d146e44" . "845" => base64_decode("YmxvZy9hZG1pbi9" . "hZG1pbl9jaGFubm" . "VsX2RlbGV0ZS5od" . "G1s"), "_2c45e6b3bf9117450ca7e834" . "7bbda4ad" => base64_decode("YmxvZy5jaGFub" . "mVsX2VkaXQubm" . "9fb3duZXI="), "_51a8c40dff7fe90899907177" . "8bf1a672" => base64_decode("YmxvZy9hZG1pbi9hZG1pbl9j" . "aGFubmVsX2VkaXQuaHRtbA=="), "_07ccde2e1abe46a6" . "e90b9fa1767bb33a" => base64_decode("ZGVsZ" . "XRl"), "_0c5123aa" . "744f69bbc" . "0e8b3ea2f" . "6e847d" => base64_decode("bG1zZw=" . "="), "_89ae09001bba57f" . "e3ed7b106b8fc84c" . "c" => base64_decode("aGF" . "zX2" . "93b" . "mVy"), "_e05e0022a2e5a" . "d344b9c4a0d3f6" . "4e1a5" => base64_decode("bWVzc2FnZ" . "Q=="), "_8df4fa2d5c" . "8d8c2e6de45" . "77a36506bb1" => base64_decode("aXNfZX" . "Jyb3Jf" . "bWVzc2" . "FnZQ=="), "_87d793fb0c87299bd43f418405" . "815498" => base64_decode("YmxvZy5jaGFubmVsX2VkaXQudXBkYXRlZ" . "A=="), "_0ea4e32b5" . "7963ac0cb3" . "057e03e9ae" . "f64" => base64_decode("aW" . "Q="), "_e1f397b7c2d69b7a7831" . "fae03f3f5e94" => base64_decode("YmxvZy5jaGFubmVsX2VkaXQuY3JlYXRl" . "ZA=="), "_8c090977da1a3dd4e737f40bd6ee2" . "9e3" => base64_decode("bW92Z" . "V90bw" . "=="), "_453428a48cd825683c" . "5593aa2a5c3b15" => base64_decode("L2Jsb2cvYWR" . "taW4vY2hhbm" . "5lbHM="), "_169371a8b8b80416e0109e2" . "17a6255b0" => base64_decode("YmxvZy5jaGFubmVsX2" . "VkaXQuZGVsZXRlZA=="), "_0c38283cc2a07ab442bd16754415a" . "84f" => base64_decode("ZGVsZXRlX29wdGlv" . "bg=="), "_8e7f4b5c8440c0" . "a24fb1b632eee28" . "538" => base64_decode("YWN0aW" . "9u"), "arg" . "s" => base64_decode("YXJ" . "ncw" . "=="));
use BlogChannel;
use Claromentis\Blog\Exception\ControllerException;
use Claromentis\Core\Application;
use Claromentis\Core\Http\gpc;
use Claromentis\Core\Http\RedirectResponse;
use Claromentis\Core\Http\RequestData;
use Claromentis\Core\Http\RequestDataException;
use Claromentis\Core\Http\RequestDataTokenException;
use Claromentis\Core\Http\TemplaterCallResponse;
use Claromentis\Core\Security\SecurityContext;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ServerRequestInterface;
use TokenException;






class AdminChannelsEditController extends AbstractChannelsEditController
{
    public function OnShowList(SecurityContext $context) : TemplaterCallResponse
    {
        $_189840d11056515e52402d1412a0b6e4 = $this->ShowChannelsList(BlogChannel::GetAll(), $context);
        $template = $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_70c63623a9e0f" . "e4bf31018c3e9f" . "9b983"];
        return new TemplaterCallResponse($template, $_189840d11056515e52402d1412a0b6e4[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["a" . "r" . "g" . "s"]], $_189840d11056515e52402d1412a0b6e4[$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_678d945" . "258a520c" . "3df1c42f" . "e4b558f3" . "4"]]);
    }
    
    
    
    
    public function OnShowChannelEdit(ServerRequestInterface $_b791059c94b285cdf1c90ca6f3a8f2a6, $channel = null) : TemplaterCallResponse
    {
        $blog_channel = $this->GetBlogChannel($channel);
        $_1f24efd4735b7a11b391147435e7d35d = $this->ShowEditChannelForm($blog_channel);
        $template = $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_51a8c40dff7fe9089990717" . "78bf1a672"];
        $_fd5a3a643834299cbdadfc3540ba0bcb = new TemplaterCallResponse($template, $_1f24efd4735b7a11b391147435e7d35d[$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["ar" . "gs"]], $_1f24efd4735b7a11b391147435e7d35d[$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_678d945258a520c3df1c42fe4b558f3" . "4"]]);
        if (gpc::get($_b791059c94b285cdf1c90ca6f3a8f2a6, $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_e05e0022a2e5a" . "d344b9c4a0d3f6" . "4e1a5"]) !== null) {
            $_fd5a3a643834299cbdadfc3540ba0bcb->SetMessage(gpc::get($_b791059c94b285cdf1c90ca6f3a8f2a6, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_e05e0022a2e5ad344b9c4a0d3f64e1a" . "5"]), gpc::get($_b791059c94b285cdf1c90ca6f3a8f2a6, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_8df4fa2" . "d5c8d8c2" . "e6de4577" . "a36506bb" . "1"]));
        }
        return $_fd5a3a643834299cbdadfc3540ba0bcb;
    }
    public function OnSaveChannel(ServerRequestInterface $_b791059c94b285cdf1c90ca6f3a8f2a6, SecurityContext $context, $channel)
    {
        try {
            $blog_channel = $this->GetBlogChannel($channel);
            $_2bd573592d12126d3aa08c722788c86a = $blog_channel->id > 0;
            if (!$blog_channel->UserCanCreateChannel($context) && !$_2bd573592d12126d3aa08c722788c86a) {
                throw new ControllerException($blog_channel->GetErrMsg());
            }
            $this->ReadChannelFormData($_b791059c94b285cdf1c90ca6f3a8f2a6, $blog_channel);
            if (!$blog_channel->Save()) {
                throw new ControllerException($blog_channel->GetErrMsg());
            }
            $_a18f3f2e515f9b634cee4e5fbdcdb572 = $blog_channel->GetPermissions();
            if (!$_a18f3f2e515f9b634cee4e5fbdcdb572->Save()) {
                throw new ControllerException($_a18f3f2e515f9b634cee4e5fbdcdb572->GetErrMsg());
            }
            $_e05e0022a2e5ad344b9c4a0d3f64e1a5 = $_2bd573592d12126d3aa08c722788c86a ? $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_0c5123aa744f69bbc0e8" . "b3ea2f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_87d793fb0c87299bd43f41840581" . "5498"]) : $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_0c5123aa744f69bbc0e8b3ea2f6e847" . "d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_e1f397b7c2d69b7a7" . "831fae03f3f5e94"]);
            return RedirectResponse::httpRedirect($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_453428a48cd825683c5" . "593aa2a5c3b15"], $_e05e0022a2e5ad344b9c4a0d3f64e1a5);
        } catch (ControllerException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $_e05e0022a2e5ad344b9c4a0d3f64e1a5 = $_fe441aa3ef350bfb1a1a1ad8520dd530->getMessage();
            $_b791059c94b285cdf1c90ca6f3a8f2a6 = $_b791059c94b285cdf1c90ca6f3a8f2a6->withQueryParams([$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_e05e0022a2e5a" . "d344b9c4a0d3f6" . "4e1a5"] => $_e05e0022a2e5ad344b9c4a0d3f64e1a5, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_8df4fa2d5c8d8c2e6de4577a365" . "06bb1"] => 1] + $_b791059c94b285cdf1c90ca6f3a8f2a6->getQueryParams());
            return $this->OnShowChannelEdit($_b791059c94b285cdf1c90ca6f3a8f2a6, $channel);
        }
    }
    public function OnPreDelete(Application $app, $channel) : TemplaterCallResponse
    {
        $_1f24efd4735b7a11b391147435e7d35d = $this->ShowPreDeleteform($app, $channel);
        $template = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_faae81f2e21f08c17e7678d" . "146e44845"];
        return new TemplaterCallResponse($template, $_1f24efd4735b7a11b391147435e7d35d[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["a" . "r" . "g" . "s"]], $_1f24efd4735b7a11b391147435e7d35d[$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_678d945258a5" . "20c3df1c42fe4" . "b558f34"]]);
    }
    
    
    
    
    public function OnConfirmDelete(Request $_b791059c94b285cdf1c90ca6f3a8f2a6, $channel) : RedirectResponse
    {
        $blog_channel = $this->GetBlogChannel($channel);
        $_8c090977da1a3dd4e737f40bd6ee29e3 = gpc::get($_b791059c94b285cdf1c90ca6f3a8f2a6, $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_0c38283cc2a07ab442bd16754415a8" . "4f"]) == $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_07ccde2e1abe46a6e9" . "0b9fa1767bb33a"] ? 0 : gpc::get($_b791059c94b285cdf1c90ca6f3a8f2a6, $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_8c090977da1a3" . "dd4e737f40bd6e" . "e29e3"]);
        $blog_channel->Delete($_8c090977da1a3dd4e737f40bd6ee29e3);
        return RedirectResponse::httpRedirect($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_453428a48c" . "d825683c559" . "3aa2a5c3b15"], $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_0c5123aa" . "744f69bbc" . "0e8b3ea2f" . "6e847d"]($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_169371a8b8b80416e0109e217" . "a6255b0"]));
    }
    
    
    
    
    
    
    
    protected function ReadChannelFormData(Request $_b791059c94b285cdf1c90ca6f3a8f2a6, BlogChannel $blog_channel)
    {
        $blog_channel->owner_id = gpc::getPostVar($_b791059c94b285cdf1c90ca6f3a8f2a6, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_c4d674abe9291be143b" . "224c411958fcf"]);
        parent::ReadChannelFormData($_b791059c94b285cdf1c90ca6f3a8f2a6, $blog_channel);
        if (gpc::getPostVar($_b791059c94b285cdf1c90ca6f3a8f2a6, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_89ae09001bba5" . "7fe3ed7b106b8f" . "c84cc"]) && !$blog_channel->owner_id) {
            throw new ControllerException($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_0c5123aa7" . "44f69bbc0e" . "8b3ea2f6e8" . "47d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_2c45e6b3b" . "f9117450ca" . "7e8347bbda" . "4ad"]));
        }
    }
    
    
    
    
    
    
    public function OnAdminChannelEdit(Application $app, SecurityContext $context, RequestData $request_data, Request $_b791059c94b285cdf1c90ca6f3a8f2a6)
    {
        if ($request_data->IsSubmit()) {
            if ($request_data->Get($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_8e7f4b5c8440c0a" . "24fb1b632eee2853" . "8"]) == $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_07ccde2e1abe46a6e90b9fa176" . "7bb33a"]) {
                return $this->OnConfirmDelete($_b791059c94b285cdf1c90ca6f3a8f2a6, $request_data->Get($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_0ea4e32b57963ac0cb30" . "57e03e9aef64"]));
            }
            return $this->OnSaveChannel($_b791059c94b285cdf1c90ca6f3a8f2a6, $context, $request_data->Get($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_0ea4e32b57963ac0cb3" . "057e03e9aef64"]));
        } elseif ($request_data->Get($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_8e7f4b5c8440c0a24fb1b632" . "eee28538"]) == $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_07ccde2e1abe4" . "6a6e90b9fa1767" . "bb33a"]) {
            return $this->OnPreDelete($app, $request_data->Get($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_0ea4e32b57963ac0cb3057e03e9" . "aef64"]));
        } else {
            return $this->OnShowChannelEdit($_b791059c94b285cdf1c90ca6f3a8f2a6, $request_data->Get($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_0ea4e32b57963ac0cb3057e03e9aef6" . "4"]));
        }
    }
}