Subversion Repositories oidplus

Rev

Rev 717 | Rev 801 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
635 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
6
 *
7
 * Licensed under the Apache License, Version 2.0 (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
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
 
20
if (!defined('INSIDE_OIDPLUS')) die();
21
 
22
class OIDplusPageAdminColors extends OIDplusPagePluginAdmin {
23
 
24
        public function action($actionID, $params) {
25
                if ($actionID == 'color_update') {
26
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
27
                                throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')));
28
                        }
29
 
717 daniel-mar 30
                        _CheckParamExists($params, 'hue_shift');
31
                        _CheckParamExists($params, 'sat_shift');
32
                        _CheckParamExists($params, 'val_shift');
33
                        _CheckParamExists($params, 'invcolors');
34
                        _CheckParamExists($params, 'theme');
635 daniel-mar 35
 
36
                        OIDplus::config()->setValue('color_hue_shift', $params['hue_shift']);
37
                        OIDplus::config()->setValue('color_sat_shift', $params['sat_shift']);
38
                        OIDplus::config()->setValue('color_val_shift', $params['val_shift']);
39
                        OIDplus::config()->setValue('color_invert',    $params['invcolors']);
40
                        OIDplus::config()->setValue('design',          $params['theme']);
41
 
42
                        OIDplus::logger()->log("[OK]A?", "Changed system color theme");
43
 
44
                        return array("status" => 0);
45
                } else {
46
                        throw new OIDplusException(_L('Unknown action ID'));
47
                }
48
        }
49
 
50
        public function init($html=true) {
51
                OIDplus::config()->prepareConfigKey('color_hue_shift', 'HSV Hue shift of CSS colors (-360..360)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
52
                        if (!is_numeric($value) || ($value < -360) || ($value > 360)) {
53
                                throw new OIDplusException(_L('Please enter a valid value.'));
54
                        }
55
                });
56
                OIDplus::config()->prepareConfigKey('color_sat_shift', 'HSV Saturation shift of CSS colors (-100..100)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
57
                        if (!is_numeric($value) || ($value < -100) || ($value > 100)) {
58
                                throw new OIDplusException(_L('Please enter a valid value.'));
59
                        }
60
                });
61
                OIDplus::config()->prepareConfigKey('color_val_shift', 'HSV Value shift of CSS colors (-100..100)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
62
                        if (!is_numeric($value) || ($value < -100) || ($value > 100)) {
63
                                throw new OIDplusException(_L('Please enter a valid value.'));
64
                        }
65
                });
66
                OIDplus::config()->prepareConfigKey('color_invert', 'Invert colors? (0=no, 1=yes)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
67
                        if (!is_numeric($value) || ($value < 0) || ($value > 1)) {
68
                                throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).'));
69
                        }
70
                });
71
                OIDplus::config()->prepareConfigKey('design', 'Which design to use (must exist in plugins/[vendorname]/design/)?', 'default', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
72
                        $good = true;
73
                        if (strpos($value,'/') !== false) $good = false;
74
                        if (strpos($value,'\\') !== false) $good = false;
75
                        if (strpos($value,'..') !== false) $good = false;
76
                        if (!$good) {
77
                                throw new OIDplusException(_L('Invalid design folder name. Do only enter a folder name, not an absolute or relative path'));
78
                        }
79
 
80
                        if (!rec_is_dir(OIDplus::localpath().'plugins/'.'*'.'/design/'.$value)) {
81
                                throw new OIDplusException(_L('The design "%1" does not exist in plugin directory %2',$value,'plugins/[vendorname]/design/'));
82
                        }
83
                });
84
                OIDplus::config()->prepareConfigKey('oobe_colors_done', '"Out Of Box Experience" wizard for OIDplusPageAdminColors done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {});
85
        }
86
 
87
        public function gui($id, &$out, &$handled) {
88
                if ($id === 'oidplus:colors') {
89
                        $handled = true;
90
                        $out['title'] = _L('Design');
800 daniel-mar 91
                        $out['icon']  = OIDplus::webpath(__DIR__,true).'img/main_icon.png';
635 daniel-mar 92
 
93
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
800 daniel-mar 94
                                $out['icon'] = 'img/error.png';
635 daniel-mar 95
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
96
                                return;
97
                        }
98
 
99
                        $out['text']  = '<br><p>';
100
                        $out['text'] .= '  <label for="theme">'._L('Design').':</label>';
101
                        $out['text'] .= '  <select name="theme" id="theme">';
102
                        foreach (OIDplus::getDesignPlugins() as $plugin) {
103
                                $folder = basename($plugin->getPluginDirectory());
104
                                $selected = $folder == OIDplus::config()->getValue('design') ? ' selected="true"' : '';
105
                                $out['text'] .= '<option value="'.htmlentities($folder).'"'.$selected.'>'.htmlentities($plugin->getManifest()->getName()).'</option>';
106
                        }
107
                        $out['text'] .= '  </select>';
108
                        $out['text'] .= '</p>';
109
 
110
                        $out['text'] .= '<br><p>';
111
                        $out['text'] .= '  <label for="amount">'._L('Hue shift').':</label>';
112
                        $out['text'] .= '  <input type="text" id="hshift" readonly style="border:0; background:transparent; font-weight:bold;">';
113
                        $out['text'] .= '</p>';
114
                        $out['text'] .= '<div id="slider-hshift"></div>';
115
 
116
                        $out['text'] .= '<br><p>';
117
                        $out['text'] .= '  <label for="amount">'._L('Saturation shift').':</label>';
118
                        $out['text'] .= '  <input type="text" id="sshift" readonly style="border:0; background:transparent; font-weight:bold;">';
119
                        $out['text'] .= '</p>';
120
                        $out['text'] .= '<div id="slider-sshift"></div>';
121
 
122
                        $out['text'] .= '<br><p>';
123
                        $out['text'] .= '  <label for="amount">'._L('Value shift').':</label>';
124
                        $out['text'] .= '  <input type="text" id="vshift" readonly style="border:0; background:transparent; font-weight:bold;">';
125
                        $out['text'] .= '</p>';
126
                        $out['text'] .= '<div id="slider-vshift"></div>';
127
 
128
                        $out['text'] .= '<br><p>';
129
                        $out['text'] .= '  <label for="amount">'._L('Invert colors').':</label>';
130
                        $out['text'] .= '  <input type="text" id="icolor" readonly style="border:0; background:transparent; font-weight:bold;">'; // TODO: It would be good if that was a checkbox
131
                        $out['text'] .= '</p>';
132
                        $out['text'] .= '<div id="slider-icolor"></div>';
133
 
134
                        $out['text'] .= '<script>';
135
                        $out['text'] .= 'if (OIDplusPageAdminColors.hue_shift == null) OIDplusPageAdminColors.hue_shift = OIDplusPageAdminColors.hue_shift_saved = '.OIDplus::config()->getValue('color_hue_shift').";\n";
136
                        $out['text'] .= 'if (OIDplusPageAdminColors.sat_shift == null) OIDplusPageAdminColors.sat_shift = OIDplusPageAdminColors.sat_shift_saved = '.OIDplus::config()->getValue('color_sat_shift').";\n";
137
                        $out['text'] .= 'if (OIDplusPageAdminColors.val_shift == null) OIDplusPageAdminColors.val_shift = OIDplusPageAdminColors.val_shift_saved = '.OIDplus::config()->getValue('color_val_shift').";\n";
138
                        $out['text'] .= 'if (OIDplusPageAdminColors.invcolors == null) OIDplusPageAdminColors.invcolors = OIDplusPageAdminColors.invcolors_saved = '.OIDplus::config()->getValue('color_invert').";\n";
139
                        $out['text'] .= 'if (OIDplusPageAdminColors.activetheme == null) OIDplusPageAdminColors.activetheme_saved = '.js_escape(OIDplus::config()->getValue('design')).";\n";
140
                        $out['text'] .= 'OIDplusPageAdminColors.setup_color_sliders();';
141
                        $out['text'] .= '</script>';
142
 
143
                        $out['text'] .= '<br>';
144
                        $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.color_reset_sliders_cfg()" value="'._L('Reset to last saved config').'">'.str_repeat('&nbsp;',5);
145
                        $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.color_reset_sliders_factory()" value="'._L('Reset default setting').'">'.str_repeat('&nbsp;',5);
146
                        $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.test_color_theme()" value="'._L('Test').'">'.str_repeat('&nbsp;',5);
147
                        $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.crudActionColorUpdate()" value="'._L('Set permanently').'">';
148
                }
149
        }
150
 
151
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
152
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
153
 
800 daniel-mar 154
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
155
                        $tree_icon = OIDplus::webpath(__DIR__,true).'img/main_icon16.png';
635 daniel-mar 156
                } else {
157
                        $tree_icon = null; // default icon (folder)
158
                }
159
 
160
                $json[] = array(
161
                        'id' => 'oidplus:colors',
162
                        'icon' => $tree_icon,
163
                        'text' => _L('Design')
164
                );
165
 
166
                return true;
167
        }
168
 
169
        public function tree_search($request) {
170
                return false;
171
        }
172
 
173
        public function implementsFeature($id) {
174
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.1') return true; // oobeEntry, oobeRequested
175
                return false;
176
        }
177
 
178
        public function oobeRequested(): bool {
179
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.1
180
 
181
                return OIDplus::config()->getValue('oobe_colors_done') == '0';
182
        }
183
 
184
        public function oobeEntry($step, $do_edits, &$errors_happened)/*: void*/ {
185
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.1
186
 
187
                echo '<p><u>'._L('Step %1: Color Theme',$step).'</u></p>';
188
 
189
                echo '<input type="checkbox" name="color_invert" id="color_invert"';
190
                if (isset($_REQUEST['sent'])) {
191
                        if ($set_value = isset($_REQUEST['color_invert'])) {
192
                                echo ' checked';
193
                        }
194
                } else {
195
                        if ($set_value = (OIDplus::config()->getValue('color_invert') == 1)) {
196
                                echo ' checked';
197
                        }
198
                }
199
                echo '> <label for="color_invert">'._L('Dark Theme (inverted colors)').'</label><br>';
200
 
201
                $msg = '';
202
                if ($do_edits) {
203
                        try {
204
                                OIDplus::config()->setValue('color_invert', $set_value ? 1 : 0);
205
                                OIDplus::config()->setValue('oobe_colors_done', '1');
206
                        } catch (Exception $e) {
207
                                $msg = $e->getMessage();
208
                                $errors_happened = true;
209
                        }
210
                }
211
 
212
                echo ' <font color="red"><b>'.$msg.'</b></font>';
213
        }
214
 
215
}