<?php

use Acms\Services\Facades\Application as App;
use Acms\Services\Form\Authorization;

class ACMS_GET_Admin_Form_Import extends ACMS_GET_Admin
{
    /**
     * インポート画面の認可
     *
     * @return bool
     */
    public function auth()
    {
        $authorization = App::make('form.authorization');
        assert($authorization instanceof Authorization);

        return $authorization->canEdit(SUID, BID);
    }

    /**
     * @return string
     */
    public function get()
    {
        if (!$this->auth()) {
            AcmsLogger::notice('認可されていないページにアクセスしました');
            die403();
        }

        $Tpl = new Template($this->tpl, new ACMS_Corrector());

        if (!$this->Post->isValidAll()) {
            $Tpl->add('msg#error');
        }

        if ($this->Post->get('import') === 'success') {
            $Tpl->add('success');
        }

        foreach ($this->Post->getArray('notice') as $message) {
            if (!is_array($message)) {
                continue;
            }
            $Tpl->add('notice:loop', $message);
        }

        $Tpl->add(null, []);

        return $Tpl->get();
    }
}
