1<?php
2
3/**
4 * Class ConfigManagerAdminShowConfig
5 */
6class ConfigManagerAdminShowConfig implements ConfigManagerAdminAction {
7
8    /**
9     * @var helper_plugin_confmanager
10     */
11    private $helper;
12    private $configId;
13
14    /**
15     * @var ConfigManagerConfigType
16     */
17    private $config;
18
19    /**
20     * Constructor
21     */
22    public function __construct() {
23        $this->helper = plugin_load('helper', 'confmanager');
24    }
25
26    public function handle() {
27        global $INPUT;
28        global $ID;
29        global $JSINFO;
30
31        $this->configId = $INPUT->str('configFile');
32        $this->config = $this->helper->getConfigById($this->configId);
33        if ($this->config === false) {
34            $params = [
35                'do' => 'admin',
36                'page' => 'confmanager'
37            ];
38            send_redirect(wl($ID, $params, false, '&'));
39        }
40
41        if (strtolower($INPUT->server->str('REQUEST_METHOD')) == 'post') {
42            if (!checkSecurityToken()) {
43                msg($this->helper->getLang('invalid request csrf'), -1);
44            }
45
46            $this->config->save();
47            @touch(DOKU_INC . 'conf/local.php');
48
49            $params = [
50                'do' => 'admin',
51                'page' => 'confmanager',
52                'configFile' => $this->configId
53            ];
54            send_redirect(wl($ID, $params, false, '&'));
55        }
56        $JSINFO['configId'] = $this->configId;
57    }
58
59    public function html() {
60        $this->header();
61        $this->displayDescription();
62        $this->displayConfig();
63    }
64
65    private function header() {
66        $configFiles = $this->helper->getConfigFiles();
67        $default = $this->configId;
68        include DOKU_PLUGIN . 'confmanager/tpl/selectConfig.php';
69    }
70
71    public function displayConfig() {
72        $this->formStart();
73        formSecurityToken();
74        $this->config->display();
75        $this->formEnd();
76    }
77
78    private function formStart() {
79        $id = $this->configId;
80        include DOKU_PLUGIN . 'confmanager/tpl/formStart.php';
81    }
82
83    private function formEnd() {
84        include DOKU_PLUGIN . 'confmanager/tpl/formEnd.php';
85    }
86
87    private function displayDescription() {
88        $description = $this->config->getDescription();
89        if (empty($description)) {
90            return;
91        }
92
93
94        $configHeadLine = $this->config->getName();
95        include DOKU_PLUGIN . 'confmanager/tpl/descriptionHeader.php';
96        echo '<div class="description_wrapper" id="description">';
97        echo $this->helper->render_text($description);
98        echo '</div>';
99    }
100}
101