Subversion Repositories oidplus

Rev

Rev 1131 | Rev 1201 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1131 Rev 1143
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * OIDplus 2.0
4
 * OIDplus 2.0
5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
6
 *
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
9
 * You may obtain a copy of the License at
10
 *
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
17
 * limitations under the License.
18
 */
18
 */
19
 
19
 
20
namespace ViaThinkSoft\OIDplus;
20
namespace ViaThinkSoft\OIDplus;
21
 
21
 
22
// phpcs:disable PSR1.Files.SideEffects
22
// phpcs:disable PSR1.Files.SideEffects
23
\defined('INSIDE_OIDPLUS') or die;
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusPageAdminColors extends OIDplusPagePluginAdmin
26
class OIDplusPageAdminColors extends OIDplusPagePluginAdmin
27
        implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1 /* oobeEntry, oobeRequested */
27
        implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1 /* oobeEntry, oobeRequested */
28
{
28
{
29
 
29
 
30
        /**
30
        /**
31
         * @param array $head_elems
31
         * @param array $head_elems
32
         * @return void
32
         * @return void
33
         * @throws OIDplusException
33
         * @throws OIDplusException
34
         */
34
         */
35
        public function htmlHeaderUpdate(array &$head_elems) {
35
        public function htmlHeaderUpdate(array &$head_elems) {
36
                foreach ($head_elems as &$line) {
36
                foreach ($head_elems as &$line) {
37
                        if (strpos($line,'oidplus.min.css.php') !== false) {
37
                        if (strpos($line,'oidplus.min.css.php') !== false) {
38
                                $add_css_args = array();
38
                                $add_css_args = array();
39
                                $add_css_args[] = 'theme='.urlencode(OIDplus::config()->getValue('design','default'));
39
                                $add_css_args[] = 'theme='.urlencode(OIDplus::config()->getValue('design','default'));
40
                                $add_css_args[] = 'invert='.urlencode(OIDplus::config()->getValue('color_invert',0));
40
                                $add_css_args[] = 'invert='.urlencode(OIDplus::config()->getValue('color_invert',0));
41
                                $add_css_args[] = 'h_shift='.urlencode(number_format(OIDplus::config()->getValue('color_hue_shift',0)/360,5,'.',''));
41
                                $add_css_args[] = 'h_shift='.urlencode(number_format(OIDplus::config()->getValue('color_hue_shift',0)/360,5,'.',''));
42
                                $add_css_args[] = 's_shift='.urlencode(number_format(OIDplus::config()->getValue('color_sat_shift',0)/100,5,'.',''));
42
                                $add_css_args[] = 's_shift='.urlencode(number_format(OIDplus::config()->getValue('color_sat_shift',0)/100,5,'.',''));
43
                                $add_css_args[] = 'v_shift='.urlencode(number_format(OIDplus::config()->getValue('color_val_shift',0)/100,5,'.',''));
43
                                $add_css_args[] = 'v_shift='.urlencode(number_format(OIDplus::config()->getValue('color_val_shift',0)/100,5,'.',''));
44
                                if (count($add_css_args) > 0) {
44
                                if (count($add_css_args) > 0) {
45
                                        $line = str_replace('oidplus.min.css.php?', 'oidplus.min.css.php&', $line);
45
                                        $line = str_replace('oidplus.min.css.php?', 'oidplus.min.css.php&', $line);
46
                                        $line = str_replace('oidplus.min.css.php', 'oidplus.min.css.php?'.htmlentities(implode('&',$add_css_args)), $line);
46
                                        $line = str_replace('oidplus.min.css.php', 'oidplus.min.css.php?'.htmlentities(implode('&',$add_css_args)), $line);
47
                                }
47
                                }
48
                        }
48
                        }
49
 
49
 
50
                        if ((stripos($line,'<meta') !== false) && (stripos($line,'name="theme-color"') !== false)) {
50
                        if ((stripos($line,'<meta') !== false) && (stripos($line,'name="theme-color"') !== false)) {
51
                                if (preg_match('@content="(.+)"@ismU', $line, $m)) {
51
                                if (preg_match('@content="(.+)"@ismU', $line, $m)) {
52
                                        $theme_color = $m[1];
52
                                        $theme_color = $m[1];
53
                                        $hs = OIDplus::config()->getValue('color_hue_shift',0)/360;
53
                                        $hs = OIDplus::config()->getValue('color_hue_shift',0)/360;
54
                                        $ss = OIDplus::config()->getValue('color_sat_shift',0)/100;
54
                                        $ss = OIDplus::config()->getValue('color_sat_shift',0)/100;
55
                                        $vs = OIDplus::config()->getValue('color_val_shift',0)/100;
55
                                        $vs = OIDplus::config()->getValue('color_val_shift',0)/100;
56
                                        $theme_color = changeHueOfCSS($theme_color, $hs, $ss, $vs); // "changeHueOfCSS" can also change a single color value if it has the form #xxyyzz or #xyz
56
                                        $theme_color = changeHueOfCSS($theme_color, $hs, $ss, $vs); // "changeHueOfCSS" can also change a single color value if it has the form #xxyyzz or #xyz
57
                                        if (OIDplus::config()->getValue('color_invert',0)) {
57
                                        if (OIDplus::config()->getValue('color_invert',0)) {
58
                                                $theme_color = invertColorsOfCSS($theme_color);
58
                                                $theme_color = invertColorsOfCSS($theme_color);
59
                                        }
59
                                        }
60
                                        $line = preg_replace('@content="(.+)"@ismU', 'content="'.$theme_color.'"', $line);
60
                                        $line = preg_replace('@content="(.+)"@ismU', 'content="'.$theme_color.'"', $line);
61
 
61
 
62
                                }
62
                                }
63
                        }
63
                        }
64
                }
64
                }
65
        }
65
        }
66
 
66
 
67
        /**
67
        /**
68
         * @param string $actionID
68
         * @param string $actionID
69
         * @param array $params
69
         * @param array $params
70
         * @return int[]
70
         * @return array
71
         * @throws OIDplusException
71
         * @throws OIDplusException
72
         */
72
         */
73
        public function action(string $actionID, array $params): array {
73
        public function action(string $actionID, array $params): array {
74
                if ($actionID == 'color_update') {
74
                if ($actionID == 'color_update') {
75
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
75
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
76
                                throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')));
76
                                throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')));
77
                        }
77
                        }
78
 
78
 
79
                        _CheckParamExists($params, 'hue_shift');
79
                        _CheckParamExists($params, 'hue_shift');
80
                        _CheckParamExists($params, 'sat_shift');
80
                        _CheckParamExists($params, 'sat_shift');
81
                        _CheckParamExists($params, 'val_shift');
81
                        _CheckParamExists($params, 'val_shift');
82
                        _CheckParamExists($params, 'invcolors');
82
                        _CheckParamExists($params, 'invcolors');
83
                        _CheckParamExists($params, 'theme');
83
                        _CheckParamExists($params, 'theme');
84
 
84
 
85
                        OIDplus::config()->setValue('color_hue_shift', $params['hue_shift']);
85
                        OIDplus::config()->setValue('color_hue_shift', $params['hue_shift']);
86
                        OIDplus::config()->setValue('color_sat_shift', $params['sat_shift']);
86
                        OIDplus::config()->setValue('color_sat_shift', $params['sat_shift']);
87
                        OIDplus::config()->setValue('color_val_shift', $params['val_shift']);
87
                        OIDplus::config()->setValue('color_val_shift', $params['val_shift']);
88
                        OIDplus::config()->setValue('color_invert',    $params['invcolors']);
88
                        OIDplus::config()->setValue('color_invert',    $params['invcolors']);
89
                        OIDplus::config()->setValue('design',          $params['theme']);
89
                        OIDplus::config()->setValue('design',          $params['theme']);
90
 
90
 
91
                        OIDplus::logger()->log("[OK]A?", "Changed system color theme");
91
                        OIDplus::logger()->log("[OK]A?", "Changed system color theme");
92
 
92
 
93
                        return array("status" => 0);
93
                        return array("status" => 0);
94
                } else {
94
                } else {
95
                        return parent::action($actionID, $params);
95
                        return parent::action($actionID, $params);
96
                }
96
                }
97
        }
97
        }
98
 
98
 
99
        /**
99
        /**
100
         * @param bool $html
100
         * @param bool $html
101
         * @return void
101
         * @return void
102
         * @throws OIDplusException
102
         * @throws OIDplusException
103
         */
103
         */
104
        public function init(bool $html=true) {
104
        public function init(bool $html=true) {
105
                OIDplus::config()->prepareConfigKey('color_hue_shift', 'HSV Hue shift of CSS colors (-360..360)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
105
                OIDplus::config()->prepareConfigKey('color_hue_shift', 'HSV Hue shift of CSS colors (-360..360)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
106
                        if (!is_numeric($value) || ($value < -360) || ($value > 360)) {
106
                        if (!is_numeric($value) || ($value < -360) || ($value > 360)) {
107
                                throw new OIDplusException(_L('Please enter a valid value.'));
107
                                throw new OIDplusException(_L('Please enter a valid value.'));
108
                        }
108
                        }
109
                });
109
                });
110
                OIDplus::config()->prepareConfigKey('color_sat_shift', 'HSV Saturation shift of CSS colors (-100..100)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
110
                OIDplus::config()->prepareConfigKey('color_sat_shift', 'HSV Saturation shift of CSS colors (-100..100)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
111
                        if (!is_numeric($value) || ($value < -100) || ($value > 100)) {
111
                        if (!is_numeric($value) || ($value < -100) || ($value > 100)) {
112
                                throw new OIDplusException(_L('Please enter a valid value.'));
112
                                throw new OIDplusException(_L('Please enter a valid value.'));
113
                        }
113
                        }
114
                });
114
                });
115
                OIDplus::config()->prepareConfigKey('color_val_shift', 'HSV Value shift of CSS colors (-100..100)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
115
                OIDplus::config()->prepareConfigKey('color_val_shift', 'HSV Value shift of CSS colors (-100..100)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
116
                        if (!is_numeric($value) || ($value < -100) || ($value > 100)) {
116
                        if (!is_numeric($value) || ($value < -100) || ($value > 100)) {
117
                                throw new OIDplusException(_L('Please enter a valid value.'));
117
                                throw new OIDplusException(_L('Please enter a valid value.'));
118
                        }
118
                        }
119
                });
119
                });
120
                OIDplus::config()->prepareConfigKey('color_invert', 'Invert colors? (0=no, 1=yes)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
120
                OIDplus::config()->prepareConfigKey('color_invert', 'Invert colors? (0=no, 1=yes)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
121
                        if (!is_numeric($value) || ($value < 0) || ($value > 1)) {
121
                        if (!is_numeric($value) || ($value < 0) || ($value > 1)) {
122
                                throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).'));
122
                                throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).'));
123
                        }
123
                        }
124
                });
124
                });
125
                OIDplus::config()->prepareConfigKey('design', 'Which design to use (must exist in plugins/[vendorname]/design/)?', 'default', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
125
                OIDplus::config()->prepareConfigKey('design', 'Which design to use (must exist in plugins/[vendorname]/design/)?', 'default', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
126
                        $good = true;
126
                        $good = true;
127
                        if (strpos($value,'/') !== false) $good = false;
127
                        if (strpos($value,'/') !== false) $good = false;
128
                        if (strpos($value,'\\') !== false) $good = false;
128
                        if (strpos($value,'\\') !== false) $good = false;
129
                        if (strpos($value,'..') !== false) $good = false;
129
                        if (strpos($value,'..') !== false) $good = false;
130
                        if (!$good) {
130
                        if (!$good) {
131
                                throw new OIDplusException(_L('Invalid design folder name. Do only enter a folder name, not an absolute or relative path'));
131
                                throw new OIDplusException(_L('Invalid design folder name. Do only enter a folder name, not an absolute or relative path'));
132
                        }
132
                        }
133
 
133
 
134
                        if (!wildcard_is_dir(OIDplus::localpath().'plugins/'.'*'.'/design/'.$value)) {
134
                        if (!wildcard_is_dir(OIDplus::localpath().'plugins/'.'*'.'/design/'.$value)) {
135
                                throw new OIDplusException(_L('The design "%1" does not exist in plugin directory %2',$value,'plugins/[vendorname]/design/'));
135
                                throw new OIDplusException(_L('The design "%1" does not exist in plugin directory %2',$value,'plugins/[vendorname]/design/'));
136
                        }
136
                        }
137
                });
137
                });
138
                OIDplus::config()->prepareConfigKey('oobe_colors_done', '"Out Of Box Experience" wizard for OIDplusPageAdminColors done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {});
138
                OIDplus::config()->prepareConfigKey('oobe_colors_done', '"Out Of Box Experience" wizard for OIDplusPageAdminColors done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {});
139
        }
139
        }
140
 
140
 
141
        /**
141
        /**
142
         * @param string $id
142
         * @param string $id
143
         * @param array $out
143
         * @param array $out
144
         * @param bool $handled
144
         * @param bool $handled
145
         * @return void
145
         * @return void
146
         * @throws OIDplusException
146
         * @throws OIDplusException
147
         */
147
         */
148
        public function gui(string $id, array &$out, bool &$handled) {
148
        public function gui(string $id, array &$out, bool &$handled) {
149
                if ($id === 'oidplus:colors') {
149
                if ($id === 'oidplus:colors') {
150
                        $handled = true;
150
                        $handled = true;
151
                        $out['title'] = _L('Design');
151
                        $out['title'] = _L('Design');
152
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
152
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
153
 
153
 
154
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
154
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
155
                                $out['icon'] = 'img/error.png';
155
                                $out['icon'] = 'img/error.png';
156
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
156
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
157
                                return;
157
                                return;
158
                        }
158
                        }
159
 
159
 
160
                        $out['text']  = '<br><p>';
160
                        $out['text']  = '<br><p>';
161
                        $out['text'] .= '  <label for="theme">'._L('Design').':</label>';
161
                        $out['text'] .= '  <label for="theme">'._L('Design').':</label>';
162
                        $out['text'] .= '  <select name="theme" id="theme">';
162
                        $out['text'] .= '  <select name="theme" id="theme">';
163
                        foreach (OIDplus::getDesignPlugins() as $plugin) {
163
                        foreach (OIDplus::getDesignPlugins() as $plugin) {
164
                                $folder = basename($plugin->getPluginDirectory());
164
                                $folder = basename($plugin->getPluginDirectory());
165
                                $selected = $folder == OIDplus::config()->getValue('design') ? ' selected="true"' : '';
165
                                $selected = $folder == OIDplus::config()->getValue('design') ? ' selected="true"' : '';
166
                                $out['text'] .= '<option value="'.htmlentities($folder).'"'.$selected.'>'.htmlentities($plugin->getManifest()->getName()).'</option>';
166
                                $out['text'] .= '<option value="'.htmlentities($folder).'"'.$selected.'>'.htmlentities($plugin->getManifest()->getName()).'</option>';
167
                        }
167
                        }
168
                        $out['text'] .= '  </select>';
168
                        $out['text'] .= '  </select>';
169
                        $out['text'] .= '</p>';
169
                        $out['text'] .= '</p>';
170
 
170
 
171
                        $out['text'] .= '<br><p>';
171
                        $out['text'] .= '<br><p>';
172
                        $out['text'] .= '  <label for="amount">'._L('Hue shift').':</label>';
172
                        $out['text'] .= '  <label for="amount">'._L('Hue shift').':</label>';
173
                        $out['text'] .= '  <input type="text" id="hshift" readonly style="border:0; background:transparent; font-weight:bold;">';
173
                        $out['text'] .= '  <input type="text" id="hshift" readonly style="border:0; background:transparent; font-weight:bold;">';
174
                        $out['text'] .= '</p>';
174
                        $out['text'] .= '</p>';
175
                        $out['text'] .= '<div id="slider-hshift"></div>';
175
                        $out['text'] .= '<div id="slider-hshift"></div>';
176
 
176
 
177
                        $out['text'] .= '<br><p>';
177
                        $out['text'] .= '<br><p>';
178
                        $out['text'] .= '  <label for="amount">'._L('Saturation shift').':</label>';
178
                        $out['text'] .= '  <label for="amount">'._L('Saturation shift').':</label>';
179
                        $out['text'] .= '  <input type="text" id="sshift" readonly style="border:0; background:transparent; font-weight:bold;">';
179
                        $out['text'] .= '  <input type="text" id="sshift" readonly style="border:0; background:transparent; font-weight:bold;">';
180
                        $out['text'] .= '</p>';
180
                        $out['text'] .= '</p>';
181
                        $out['text'] .= '<div id="slider-sshift"></div>';
181
                        $out['text'] .= '<div id="slider-sshift"></div>';
182
 
182
 
183
                        $out['text'] .= '<br><p>';
183
                        $out['text'] .= '<br><p>';
184
                        $out['text'] .= '  <label for="amount">'._L('Value shift').':</label>';
184
                        $out['text'] .= '  <label for="amount">'._L('Value shift').':</label>';
185
                        $out['text'] .= '  <input type="text" id="vshift" readonly style="border:0; background:transparent; font-weight:bold;">';
185
                        $out['text'] .= '  <input type="text" id="vshift" readonly style="border:0; background:transparent; font-weight:bold;">';
186
                        $out['text'] .= '</p>';
186
                        $out['text'] .= '</p>';
187
                        $out['text'] .= '<div id="slider-vshift"></div>';
187
                        $out['text'] .= '<div id="slider-vshift"></div>';
188
 
188
 
189
                        $out['text'] .= '<p><div><input type="checkbox" id="icolor"> <label for="icolor">'._L('Invert colors').'</label></div></p>';
189
                        $out['text'] .= '<p><div><input type="checkbox" id="icolor"> <label for="icolor">'._L('Invert colors').'</label></div></p>';
190
 
190
 
191
                        $out['text'] .= '<script>';
191
                        $out['text'] .= '<script>';
192
                        $out['text'] .= 'if (OIDplusPageAdminColors.hue_shift == null) OIDplusPageAdminColors.hue_shift = OIDplusPageAdminColors.hue_shift_saved = '.OIDplus::config()->getValue('color_hue_shift').";\n";
192
                        $out['text'] .= 'if (OIDplusPageAdminColors.hue_shift == null) OIDplusPageAdminColors.hue_shift = OIDplusPageAdminColors.hue_shift_saved = '.OIDplus::config()->getValue('color_hue_shift').";\n";
193
                        $out['text'] .= 'if (OIDplusPageAdminColors.sat_shift == null) OIDplusPageAdminColors.sat_shift = OIDplusPageAdminColors.sat_shift_saved = '.OIDplus::config()->getValue('color_sat_shift').";\n";
193
                        $out['text'] .= 'if (OIDplusPageAdminColors.sat_shift == null) OIDplusPageAdminColors.sat_shift = OIDplusPageAdminColors.sat_shift_saved = '.OIDplus::config()->getValue('color_sat_shift').";\n";
194
                        $out['text'] .= 'if (OIDplusPageAdminColors.val_shift == null) OIDplusPageAdminColors.val_shift = OIDplusPageAdminColors.val_shift_saved = '.OIDplus::config()->getValue('color_val_shift').";\n";
194
                        $out['text'] .= 'if (OIDplusPageAdminColors.val_shift == null) OIDplusPageAdminColors.val_shift = OIDplusPageAdminColors.val_shift_saved = '.OIDplus::config()->getValue('color_val_shift').";\n";
195
                        $out['text'] .= 'if (OIDplusPageAdminColors.invcolors == null) OIDplusPageAdminColors.invcolors = OIDplusPageAdminColors.invcolors_saved = '.OIDplus::config()->getValue('color_invert').";\n";
195
                        $out['text'] .= 'if (OIDplusPageAdminColors.invcolors == null) OIDplusPageAdminColors.invcolors = OIDplusPageAdminColors.invcolors_saved = '.OIDplus::config()->getValue('color_invert').";\n";
196
                        $out['text'] .= 'if (OIDplusPageAdminColors.activetheme == null) OIDplusPageAdminColors.activetheme_saved = '.js_escape(OIDplus::config()->getValue('design')).";\n";
196
                        $out['text'] .= 'if (OIDplusPageAdminColors.activetheme == null) OIDplusPageAdminColors.activetheme_saved = '.js_escape(OIDplus::config()->getValue('design')).";\n";
197
                        $out['text'] .= 'OIDplusPageAdminColors.setup_color_sliders();';
197
                        $out['text'] .= 'OIDplusPageAdminColors.setup_color_sliders();';
198
                        $out['text'] .= '</script>';
198
                        $out['text'] .= '</script>';
199
 
199
 
200
                        $out['text'] .= '<br>';
200
                        $out['text'] .= '<br>';
201
                        $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.color_reset_sliders_cfg()" value="'._L('Reset to last saved config').'">'.str_repeat('&nbsp;',5);
201
                        $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.color_reset_sliders_cfg()" value="'._L('Reset to last saved config').'">'.str_repeat('&nbsp;',5);
202
                        $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.color_reset_sliders_factory()" value="'._L('Reset default setting').'">'.str_repeat('&nbsp;',5);
202
                        $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.color_reset_sliders_factory()" value="'._L('Reset default setting').'">'.str_repeat('&nbsp;',5);
203
                        $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.test_color_theme()" value="'._L('Test').'">'.str_repeat('&nbsp;',5);
203
                        $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.test_color_theme()" value="'._L('Test').'">'.str_repeat('&nbsp;',5);
204
                        $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.crudActionColorUpdate()" value="'._L('Set permanently').'">';
204
                        $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.crudActionColorUpdate()" value="'._L('Set permanently').'">';
205
                }
205
                }
206
        }
206
        }
207
 
207
 
208
        /**
208
        /**
209
         * @param array $json
209
         * @param array $json
210
         * @param string|null $ra_email
210
         * @param string|null $ra_email
211
         * @param bool $nonjs
211
         * @param bool $nonjs
212
         * @param string $req_goto
212
         * @param string $req_goto
213
         * @return bool
213
         * @return bool
214
         * @throws OIDplusException
214
         * @throws OIDplusException
215
         */
215
         */
216
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
216
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
217
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
217
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
218
 
218
 
219
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
219
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
220
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
220
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
221
                } else {
221
                } else {
222
                        $tree_icon = null; // default icon (folder)
222
                        $tree_icon = null; // default icon (folder)
223
                }
223
                }
224
 
224
 
225
                $json[] = array(
225
                $json[] = array(
226
                        'id' => 'oidplus:colors',
226
                        'id' => 'oidplus:colors',
227
                        'icon' => $tree_icon,
227
                        'icon' => $tree_icon,
228
                        'text' => _L('Design')
228
                        'text' => _L('Design')
229
                );
229
                );
230
 
230
 
231
                return true;
231
                return true;
232
        }
232
        }
233
 
233
 
234
        /**
234
        /**
235
         * @param string $request
235
         * @param string $request
236
         * @return array|false
236
         * @return array|false
237
         */
237
         */
238
        public function tree_search(string $request) {
238
        public function tree_search(string $request) {
239
                return false;
239
                return false;
240
        }
240
        }
241
 
241
 
242
        /**
242
        /**
243
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
243
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
244
         * @return bool
244
         * @return bool
245
         * @throws OIDplusException
245
         * @throws OIDplusException
246
         */
246
         */
247
        public function oobeRequested(): bool {
247
        public function oobeRequested(): bool {
248
                return OIDplus::config()->getValue('oobe_colors_done') == '0';
248
                return OIDplus::config()->getValue('oobe_colors_done') == '0';
249
        }
249
        }
250
 
250
 
251
        /**
251
        /**
252
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
252
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
253
         * @param int $step
253
         * @param int $step
254
         * @param bool $do_edits
254
         * @param bool $do_edits
255
         * @param bool $errors_happened
255
         * @param bool $errors_happened
256
         * @return void
256
         * @return void
257
         * @throws OIDplusException
257
         * @throws OIDplusException
258
         */
258
         */
259
        public function oobeEntry(int $step, bool $do_edits, bool &$errors_happened)/*: void*/ {
259
        public function oobeEntry(int $step, bool $do_edits, bool &$errors_happened)/*: void*/ {
260
                echo '<h2>'._L('Step %1: Color Theme',$step).'</h2>';
260
                echo '<h2>'._L('Step %1: Color Theme',$step).'</h2>';
261
 
261
 
262
                echo '<input type="checkbox" name="color_invert" id="color_invert"';
262
                echo '<input type="checkbox" name="color_invert" id="color_invert"';
263
                if (isset($_POST['sent'])) {
263
                if (isset($_POST['sent'])) {
264
                        if ($set_value = isset($_POST['color_invert'])) {
264
                        if ($set_value = isset($_POST['color_invert'])) {
265
                                echo ' checked';
265
                                echo ' checked';
266
                        }
266
                        }
267
                } else {
267
                } else {
268
                        if ($set_value = (OIDplus::config()->getValue('color_invert') == 1)) {
268
                        if ($set_value = (OIDplus::config()->getValue('color_invert') == 1)) {
269
                                echo ' checked';
269
                                echo ' checked';
270
                        }
270
                        }
271
                }
271
                }
272
                echo '> <label for="color_invert">'._L('Dark Theme (inverted colors)').'</label><br>';
272
                echo '> <label for="color_invert">'._L('Dark Theme (inverted colors)').'</label><br>';
273
 
273
 
274
                $msg = '';
274
                $msg = '';
275
                if ($do_edits) {
275
                if ($do_edits) {
276
                        try {
276
                        try {
277
                                OIDplus::config()->setValue('color_invert', $set_value ? 1 : 0);
277
                                OIDplus::config()->setValue('color_invert', $set_value ? 1 : 0);
278
                                OIDplus::config()->setValue('oobe_colors_done', '1');
278
                                OIDplus::config()->setValue('oobe_colors_done', '1');
279
                        } catch (\Exception $e) {
279
                        } catch (\Exception $e) {
280
                                $msg = $e->getMessage();
280
                                $msg = $e->getMessage();
281
                                $errors_happened = true;
281
                                $errors_happened = true;
282
                        }
282
                        }
283
                }
283
                }
284
 
284
 
285
                echo ' <font color="red"><b>'.$msg.'</b></font>';
285
                echo ' <font color="red"><b>'.$msg.'</b></font>';
286
        }
286
        }
287
 
287
 
288
}
288
}
289
 
289