<?php
namespace Claromentis\Blog\Controller;

$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"] ?: array()) + array("_0c5123aa74" . "4f69bbc0e8b" . "3ea2f6e847d" => base64_decode("bG1" . "zZw" . "=="), "_d5e3acfe493fa211" . "1d22dfb93da33d87" => base64_decode("X18" . "="), "_ba9b6c97c9c752d4" . "b80eab79577a4361" => base64_decode("YmxvZy9jaGFubmVsX2RlbGV0ZS5odG" . "1s"), "_e1f397b7c2" . "d69b7a7831f" . "ae03f3f5e94" => base64_decode("YmxvZy5jaG" . "FubmVsX2Vk" . "aXQuY3JlYX" . "RlZA=="), "_21085f50c670b0762b" . "9848ca2d377a12" => base64_decode("L2R" . "lbG" . "V0Z" . "Q=="), "_0ae3807d8d61b" . "b64354b1bd7c3a" . "20b57" => base64_decode("YmxvZy9jaGFub" . "mVsX2VkaXQuaH" . "RtbA=="), "_0c38283cc2a07" . "ab442bd1675441" . "5a84f" => base64_decode("ZGVsZXRlX29wdGlvb" . "g=="), "_8df4fa2d5c8d8c2e6de4577" . "a36506bb1" => base64_decode("aXNfZXJyb3JfbWVzc2FnZ" . "Q=="), "_e05e0022a2e5ad344b9c4a0d3f64e1" . "a5" => base64_decode("bWVzc2" . "FnZQ=="), "_87d793fb0c" . "87299bd43f4" . "18405815498" => base64_decode("YmxvZy5jaGF" . "ubmVsX2VkaX" . "QudXBkYXRlZ" . "A=="), "_ae4a14ab8049cb004f" . "15102f46849e09" => base64_decode("L2NoYW5u" . "ZWxzLw=="), "a" . "r" . "g" . "s" => base64_decode("YXJnc" . "w=="), "_169371a8" . "b8b80416e" . "0109e217a" . "6255b0" => base64_decode("YmxvZy5jaGFubmVsX2VkaXQuZGVsZXRl" . "ZA=="), "_8c090977da1a3dd" . "4e737f40bd6ee29e" . "3" => base64_decode("bW9" . "2ZV" . "90b" . "w=="), "_07ccde2e" . "1abe46a6e" . "90b9fa176" . "7bb33a" => base64_decode("ZGV" . "sZX" . "Rl"), "_5b507e9f50e79" . "fb69e3fc508d62" . "5da72" => base64_decode("YmxvZy5jaGFubmVscy5ub19jcmVhdGVfcGVybWlzc2" . "lvbg=="), "tem" . "pla" . "te" => base64_decode("dGVt" . "cGxh" . "dGU="), "_87daa84" . "e346f642" . "0a3f3426" . "e05d16a7" . "b" => base64_decode("L" . "w" . "=" . "="), "_106fdbc94bb1ea87" . "caca30b55467bf26" => base64_decode("Tm8gcmlnaHRzIHRvIG1" . "vdmUgdG8gdGhpcyBibG" . "9nIGNoYW5uZWw="), "_aa010f01c5fa75b081f8a35ef25" . "9d278" => base64_decode("YmxvZy5jaGFubmVsX2VkaXQubm9fcmlnaHR" . "z"), "_678d945258a" . "520c3df1c42f" . "e4b558f34" => base64_decode("cGFn" . "ZV90" . "aXRs" . "ZQ=="));
use BlogChannel;
use AuthUser;
use Claromentis\Blog\BlogApplication;
use Claromentis\Blog\Exception\ControllerException;
use Claromentis\Core\Application;
use Claromentis\Core\Http\gpc;
use Claromentis\Core\Http\RedirectResponse;
use Claromentis\Core\Http\TemplaterCallResponse;
use Claromentis\Core\Security\SecurityContext;
use Permissions;
use Psr\Http\Message\ServerRequestInterface;






class UserChannelsEditController extends AbstractChannelsEditController
{
    public function OnShowList(SecurityContext $context) : TemplaterCallResponse
    {
        $_1f24efd4735b7a11b391147435e7d35d = $this->ShowChannelsList(BlogChannel::GetEditable($context), $context);
        return new TemplaterCallResponse($_1f24efd4735b7a11b391147435e7d35d[$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["templa" . "te"]], $_1f24efd4735b7a11b391147435e7d35d[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["a" . "r" . "g" . "s"]], $_1f24efd4735b7a11b391147435e7d35d[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_678d945258a520c3df1c42fe4b55" . "8f34"]]);
    }
    public function OnPreDelete(Application $app, $channel)
    {
        $_1f24efd4735b7a11b391147435e7d35d = $this->ShowPreDeleteform($app, $channel);
        $template = $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_ba9b6c97c9c7" . "52d4b80eab795" . "77a4361"];
        return new TemplaterCallResponse($template, $_1f24efd4735b7a11b391147435e7d35d[$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["arg" . "s"]], $_1f24efd4735b7a11b391147435e7d35d[$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_678d945258a520c3df1c42fe4b558f3" . "4"]]);
    }
    public function OnConfirmDelete(Application $app, ServerRequestInterface $request, $channel)
    {
        $_8c090977da1a3dd4e737f40bd6ee29e3 = gpc::get($request, $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_0c38283cc2a07ab442bd16754415a" . "84f"]) === $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_07ccde2e" . "1abe46a6e" . "90b9fa176" . "7bb33a"] ? 0 : gpc::get($request, $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_8c090977da1a3dd4e737f" . "40bd6ee29e3"]);
        if ($_8c090977da1a3dd4e737f40bd6ee29e3 && !Permissions::HasPermissions(PERM_EDIT_APPROVE, PERM_CLASS_BLOG_CHANNEL, $_8c090977da1a3dd4e737f40bd6ee29e3)) {
            return RedirectResponse::httpRedirect(BlogApplication::BASE_URL . $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_ae4a14ab8049cb004f15102f" . "46849e09"], $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_d5e3acfe493fa2111d22dfb93da33" . "d87"]($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_106fdbc94bb1ea" . "87caca30b55467b" . "f26"]), 1);
        }
        $blog_channel = $this->GetBlogChannel($channel);
        $_8c090977da1a3dd4e737f40bd6ee29e3 = gpc::get($request, $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_0c38283cc2a07ab442" . "bd16754415a84f"]) === $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_07ccde2e1abe46a6e90b9" . "fa1767bb33a"] ? 0 : gpc::get($request, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_8c090977da1a3" . "dd4e737f40bd6e" . "e29e3"]);
        try {
            gpc::CheckToken($request);
        } catch (\TokenException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            return RedirectResponse::httpRedirect(BlogApplication::BASE_URL . $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_87daa84e3" . "46f6420a3f" . "3426e05d16" . "a7b"] . $channel . $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_21085f50c670" . "b0762b9848ca2" . "d377a12"], $_fe441aa3ef350bfb1a1a1ad8520dd530->getMessage(), true);
        }
        $blog_channel->Delete($_8c090977da1a3dd4e737f40bd6ee29e3);
        return RedirectResponse::httpRedirect(BlogApplication::BASE_URL . $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_ae4a14ab8049cb004f15102f46" . "849e09"], $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_0c5123aa74" . "4f69bbc0e8b" . "3ea2f6e847d"]($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_169371a8b8b" . "80416e0109e2" . "17a6255b0"]));
    }
    public function OnShowChannelEdit(Application $app, ServerRequestInterface $request, $channel = null)
    {
        $blog_channel = $this->GetBlogChannel($channel);
        if (!$blog_channel->id && !$blog_channel->UserCanCreateChannel($app->security)) {
            return RedirectResponse::httpRedirect(BlogApplication::BASE_URL . $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_ae4a14ab8049cb004f15102" . "f46849e09"], $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_0c5123aa744f69bbc0e8b3ea2" . "f6e847d"]($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_5b507e9f50e79f" . "b69e3fc508d625d" . "a72"]), true);
        }
        $_1f24efd4735b7a11b391147435e7d35d = $this->ShowEditChannelForm($blog_channel);
        $template = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_0ae3807d8d61b" . "b64354b1bd7c3a" . "20b57"];
        $_fd5a3a643834299cbdadfc3540ba0bcb = new TemplaterCallResponse($template, $_1f24efd4735b7a11b391147435e7d35d[$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["ar" . "gs"]], $_1f24efd4735b7a11b391147435e7d35d[$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_678d945258a520c" . "3df1c42fe4b558f3" . "4"]]);
        $_e05e0022a2e5ad344b9c4a0d3f64e1a5 = gpc::GetStringOrNull($request, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_e05e0022a2e5ad344b9c4a0" . "d3f64e1a5"]);
        if ($_e05e0022a2e5ad344b9c4a0d3f64e1a5 !== null) {
            $_fd5a3a643834299cbdadfc3540ba0bcb->message = $_e05e0022a2e5ad344b9c4a0d3f64e1a5;
            $_fd5a3a643834299cbdadfc3540ba0bcb->is_error_message = gpc::GetInt($request, $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_8df4fa2d5c8d8c2e" . "6de4577a36506bb1"]);
        }
        return $_fd5a3a643834299cbdadfc3540ba0bcb;
    }
    public function OnSaveChannel(Application $app, SecurityContext $context, ServerRequestInterface $request, $channel = null)
    {
        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($request, $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["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_0c5123aa744f6" . "9bbc0e8b3ea2f6" . "e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_87d793fb0c87299bd43f4184058" . "15498"]) : $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_0c5123aa744f69" . "bbc0e8b3ea2f6e8" . "47d"]($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_e1f397b7c2d69b7" . "a7831fae03f3f5e9" . "4"]);
            return RedirectResponse::httpRedirect(BlogApplication::BASE_URL . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_ae4a14ab80" . "49cb004f151" . "02f46849e09"], $_e05e0022a2e5ad344b9c4a0d3f64e1a5);
        } catch (ControllerException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $_e05e0022a2e5ad344b9c4a0d3f64e1a5 = $_fe441aa3ef350bfb1a1a1ad8520dd530->getMessage();
            $request = $request->withQueryParams([$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_e05e0022a2e5ad344b9c4a0d3f64e1a" . "5"] => $_e05e0022a2e5ad344b9c4a0d3f64e1a5, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_8df4fa2d5c8d8c2e6de4577a36506" . "bb1"] => 1] + $request->getQueryParams());
            return $this->OnShowChannelEdit($app, $request, $channel);
        } catch (\TokenException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $_e05e0022a2e5ad344b9c4a0d3f64e1a5 = $_fe441aa3ef350bfb1a1a1ad8520dd530->getMessage();
            $request = $request->withQueryParams([$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_e05e0022" . "a2e5ad344" . "b9c4a0d3f" . "64e1a5"] => $_e05e0022a2e5ad344b9c4a0d3f64e1a5, $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_8df4fa2d5c8d8c2e6de4577" . "a36506bb1"] => 1] + $request->getQueryParams());
            return $this->OnShowChannelEdit($app, $request, $channel);
        }
    }
    protected function GetBlogChannel($channel_id)
    {
        if (!$this->blog_channel) {
            $blog_channel = parent::GetBlogChannel($channel_id);
            if (!$blog_channel->id) {
                $blog_channel->owner_id = AuthUser::I()->GetId();
            }
            if ($blog_channel->owner_id != AuthUser::I()->GetId() && !$blog_channel->UserHasPermission(PERM_EDIT_PERMS)) {
                throw new ControllerException($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_0c5123aa744f69bbc" . "0e8b3ea2f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_aa010f01c5fa75b081f8a35ef2" . "59d278"]));
            }
            $this->blog_channel = $blog_channel;
        }
        return $this->blog_channel;
    }
    
    
    
    
    
    protected function ReadChannelFormData(ServerRequestInterface $request, BlogChannel $blog_channel)
    {
        try {
            gpc::CheckToken($request);
        } catch (\TokenException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            throw $_fe441aa3ef350bfb1a1a1ad8520dd530;
        }
        if (!$blog_channel->owner_id) {
            $blog_channel->owner_id = AuthUser::I()->GetId();
        }
        parent::ReadChannelFormData($request, $blog_channel);
        $_a18f3f2e515f9b634cee4e5fbdcdb572 = $blog_channel->GetPermissions();
        if (!$_a18f3f2e515f9b634cee4e5fbdcdb572->UserHasPermission(PERM_EDIT_PERMS)) {
            $_a18f3f2e515f9b634cee4e5fbdcdb572->Add(PERM_EDIT_PERMS, PERM_OCLASS_INDIVIDUAL, AuthUser::I()->GetId());
        }
    }
}