Rev 496 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
142 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
511 | daniel-mar | 5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
142 | daniel-mar | 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 | |||
511 | daniel-mar | 20 | if (!defined('INSIDE_OIDPLUS')) die(); |
21 | |||
256 | daniel-mar | 22 | class OIDplusPageAdminColors extends OIDplusPagePluginAdmin { |
23 | |||
321 | daniel-mar | 24 | public function action($actionID, $params) { |
25 | if ($actionID == 'color_update') { |
||
142 | daniel-mar | 26 | if (!OIDplus::authUtils()::isAdminLoggedIn()) { |
360 | daniel-mar | 27 | throw new OIDplusException(_L('You need to log in as administrator.')); |
142 | daniel-mar | 28 | } |
29 | |||
321 | daniel-mar | 30 | OIDplus::config()->setValue('color_hue_shift', $params['hue_shift']); |
31 | OIDplus::config()->setValue('color_sat_shift', $params['sat_shift']); |
||
32 | OIDplus::config()->setValue('color_val_shift', $params['val_shift']); |
||
33 | OIDplus::config()->setValue('color_invert', $params['invcolors']); |
||
451 | daniel-mar | 34 | OIDplus::config()->setValue('design', $params['theme']); |
142 | daniel-mar | 35 | |
288 | daniel-mar | 36 | OIDplus::logger()->log("[OK]A?", "Changed system color theme"); |
142 | daniel-mar | 37 | |
328 | daniel-mar | 38 | return array("status" => 0); |
321 | daniel-mar | 39 | } else { |
360 | daniel-mar | 40 | throw new OIDplusException(_L('Unknown action ID')); |
142 | daniel-mar | 41 | } |
42 | } |
||
43 | |||
44 | public function init($html=true) { |
||
263 | daniel-mar | 45 | OIDplus::config()->prepareConfigKey('color_hue_shift', 'HSV Hue shift of CSS colors (-360..360)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
142 | daniel-mar | 46 | if (!is_numeric($value) || ($value < -360) || ($value > 360)) { |
360 | daniel-mar | 47 | throw new OIDplusException(_L('Please enter a valid value.')); |
142 | daniel-mar | 48 | } |
263 | daniel-mar | 49 | }); |
50 | OIDplus::config()->prepareConfigKey('color_sat_shift', 'HSV Saturation shift of CSS colors (-100..100)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
||
142 | daniel-mar | 51 | if (!is_numeric($value) || ($value < -100) || ($value > 100)) { |
360 | daniel-mar | 52 | throw new OIDplusException(_L('Please enter a valid value.')); |
142 | daniel-mar | 53 | } |
263 | daniel-mar | 54 | }); |
55 | OIDplus::config()->prepareConfigKey('color_val_shift', 'HSV Value shift of CSS colors (-100..100)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
||
142 | daniel-mar | 56 | if (!is_numeric($value) || ($value < -100) || ($value > 100)) { |
360 | daniel-mar | 57 | throw new OIDplusException(_L('Please enter a valid value.')); |
142 | daniel-mar | 58 | } |
263 | daniel-mar | 59 | }); |
286 | daniel-mar | 60 | OIDplus::config()->prepareConfigKey('color_invert', 'Invert colors? (0=no, 1=yes)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
61 | if (!is_numeric($value) || ($value < 0) || ($value > 1)) { |
||
360 | daniel-mar | 62 | throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).')); |
286 | daniel-mar | 63 | } |
64 | }); |
||
451 | daniel-mar | 65 | OIDplus::config()->prepareConfigKey('design', 'Which design to use (must exist in plugins/design/)?', 'default', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
66 | $good = true; |
||
67 | if (strpos($value,'/') !== false) $good = false; |
||
68 | if (strpos($value,'\\') !== false) $good = false; |
||
69 | if (strpos($value,'..') !== false) $good = false; |
||
70 | if (!$good) { |
||
71 | throw new OIDplusException(_L('Invalid design folder name. Do only enter a folder name, not an absolute or relative path')); |
||
72 | } |
||
73 | |||
496 | daniel-mar | 74 | if (!is_dir(OIDplus::localpath().'plugins/design/'.$value)) { |
451 | daniel-mar | 75 | throw new OIDplusException(_L('The design "%1" does not exist in plugin directory %2',$value,'plugins/design/')); |
76 | } |
||
77 | }); |
||
362 | daniel-mar | 78 | OIDplus::config()->prepareConfigKey('oobe_colors_done', '"Out Of Box Experience" wizard for OIDplusPageAdminColors done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {}); |
142 | daniel-mar | 79 | } |
80 | |||
81 | public function gui($id, &$out, &$handled) { |
||
82 | if ($id === 'oidplus:colors') { |
||
83 | $handled = true; |
||
451 | daniel-mar | 84 | $out['title'] = _L('Design'); |
241 | daniel-mar | 85 | $out['icon'] = OIDplus::webpath(__DIR__).'icon_big.png'; |
142 | daniel-mar | 86 | |
87 | if (!OIDplus::authUtils()::isAdminLoggedIn()) { |
||
88 | $out['icon'] = 'img/error_big.png'; |
||
360 | daniel-mar | 89 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login')).'</p>'; |
281 | daniel-mar | 90 | return; |
142 | daniel-mar | 91 | } |
286 | daniel-mar | 92 | |
93 | $out['text'] = '<br><p>'; |
||
451 | daniel-mar | 94 | $out['text'] .= ' <label for="theme">'._L('Design').':</label>'; |
95 | $out['text'] .= ' <select name="theme" id="theme">'; |
||
96 | foreach (OIDplus::getDesignPlugins() as $plugin) { |
||
97 | $folder = basename($plugin->getPluginDirectory()); |
||
98 | $selected = $folder == OIDplus::config()->getValue('design') ? ' selected="true"' : ''; |
||
99 | $out['text'] .= '<option value="'.htmlentities($folder).'"'.$selected.'>'.htmlentities($plugin->getManifest()->getName()).'</option>'; |
||
100 | } |
||
101 | $out['text'] .= ' </select>'; |
||
102 | $out['text'] .= '</p>'; |
||
103 | |||
104 | $out['text'] .= '<br><p>'; |
||
360 | daniel-mar | 105 | $out['text'] .= ' <label for="amount">'._L('Hue shift').':</label>'; |
281 | daniel-mar | 106 | $out['text'] .= ' <input type="text" id="hshift" readonly style="border:0; background:transparent; font-weight:bold;">'; |
107 | $out['text'] .= '</p>'; |
||
108 | $out['text'] .= '<div id="slider-hshift"></div>'; |
||
286 | daniel-mar | 109 | |
110 | $out['text'] .= '<br><p>'; |
||
360 | daniel-mar | 111 | $out['text'] .= ' <label for="amount">'._L('Saturation shift').':</label>'; |
281 | daniel-mar | 112 | $out['text'] .= ' <input type="text" id="sshift" readonly style="border:0; background:transparent; font-weight:bold;">'; |
113 | $out['text'] .= '</p>'; |
||
114 | $out['text'] .= '<div id="slider-sshift"></div>'; |
||
286 | daniel-mar | 115 | |
116 | $out['text'] .= '<br><p>'; |
||
360 | daniel-mar | 117 | $out['text'] .= ' <label for="amount">'._L('Value shift').':</label>'; |
281 | daniel-mar | 118 | $out['text'] .= ' <input type="text" id="vshift" readonly style="border:0; background:transparent; font-weight:bold;">'; |
119 | $out['text'] .= '</p>'; |
||
120 | $out['text'] .= '<div id="slider-vshift"></div>'; |
||
286 | daniel-mar | 121 | |
122 | $out['text'] .= '<br><p>'; |
||
360 | daniel-mar | 123 | $out['text'] .= ' <label for="amount">'._L('Invert colors').':</label>'; |
409 | daniel-mar | 124 | $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 |
286 | daniel-mar | 125 | $out['text'] .= '</p>'; |
126 | $out['text'] .= '<div id="slider-icolor"></div>'; |
||
127 | |||
281 | daniel-mar | 128 | $out['text'] .= '<script>'; |
129 | $out['text'] .= 'if (g_hue_shift == null) g_hue_shift = g_hue_shift_saved = '.OIDplus::config()->getValue('color_hue_shift').";\n"; |
||
130 | $out['text'] .= 'if (g_sat_shift == null) g_sat_shift = g_sat_shift_saved = '.OIDplus::config()->getValue('color_sat_shift').";\n"; |
||
131 | $out['text'] .= 'if (g_val_shift == null) g_val_shift = g_val_shift_saved = '.OIDplus::config()->getValue('color_val_shift').";\n"; |
||
286 | daniel-mar | 132 | $out['text'] .= 'if (g_invcolors == null) g_invcolors = g_invcolors_saved = '.OIDplus::config()->getValue('color_invert').";\n"; |
451 | daniel-mar | 133 | $out['text'] .= 'if (g_activetheme == null) g_activetheme_saved = '.js_escape(OIDplus::config()->getValue('design')).";\n"; |
281 | daniel-mar | 134 | $out['text'] .= 'setup_color_sliders();'; |
135 | $out['text'] .= '</script>'; |
||
286 | daniel-mar | 136 | |
281 | daniel-mar | 137 | $out['text'] .= '<br>'; |
360 | daniel-mar | 138 | $out['text'] .= '<input type="button" onclick="color_reset_sliders_cfg()" value="'._L('Reset to last saved config').'">'.str_repeat(' ',5); |
139 | $out['text'] .= '<input type="button" onclick="color_reset_sliders_factory()" value="'._L('Reset default setting').'">'.str_repeat(' ',5); |
||
140 | $out['text'] .= '<input type="button" onclick="test_color_theme()" value="'._L('Test').'">'.str_repeat(' ',5); |
||
141 | $out['text'] .= '<input type="button" onclick="crudActionColorUpdate()" value="'._L('Set permanently').'">'; |
||
142 | daniel-mar | 142 | } |
143 | } |
||
144 | |||
145 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
||
281 | daniel-mar | 146 | if (!OIDplus::authUtils()::isAdminLoggedIn()) return false; |
286 | daniel-mar | 147 | |
142 | daniel-mar | 148 | if (file_exists(__DIR__.'/treeicon.png')) { |
241 | daniel-mar | 149 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
142 | daniel-mar | 150 | } else { |
151 | $tree_icon = null; // default icon (folder) |
||
152 | } |
||
153 | |||
154 | $json[] = array( |
||
155 | 'id' => 'oidplus:colors', |
||
156 | 'icon' => $tree_icon, |
||
451 | daniel-mar | 157 | 'text' => _L('Design') |
142 | daniel-mar | 158 | ); |
159 | |||
160 | return true; |
||
161 | } |
||
162 | |||
163 | public function tree_search($request) { |
||
164 | return false; |
||
165 | } |
||
292 | daniel-mar | 166 | |
167 | public function implementsFeature($id) { |
||
362 | daniel-mar | 168 | if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.1') return true; // oobeEntry, oobeRequested |
292 | daniel-mar | 169 | return false; |
170 | } |
||
171 | |||
362 | daniel-mar | 172 | public function oobeRequested(): bool { |
173 | // Interface 1.3.6.1.4.1.37476.2.5.2.3.1 |
||
174 | |||
175 | return OIDplus::config()->getValue('oobe_colors_done') == '0'; |
||
176 | } |
||
177 | |||
292 | daniel-mar | 178 | public function oobeEntry($step, $do_edits, &$errors_happened)/*: void*/ { |
179 | // Interface 1.3.6.1.4.1.37476.2.5.2.3.1 |
||
180 | |||
360 | daniel-mar | 181 | echo '<p><u>'._L('Step %1: Color Theme',$step).'</u></p>'; |
292 | daniel-mar | 182 | |
183 | echo '<input type="checkbox" name="color_invert" id="color_invert"'; |
||
184 | if (isset($_REQUEST['sent'])) { |
||
185 | if ($set_value = isset($_REQUEST['color_invert'])) { |
||
186 | echo ' checked'; |
||
187 | } |
||
188 | } else { |
||
189 | if (OIDplus::config()->getValue('color_invert') == 1) { |
||
190 | echo ' checked'; |
||
191 | } |
||
192 | } |
||
360 | daniel-mar | 193 | echo '> <label for="color_invert">'._L('Dark Theme (inverted colors)').'</label><br>'; |
292 | daniel-mar | 194 | |
195 | $msg = ''; |
||
196 | if ($do_edits) { |
||
197 | try { |
||
198 | OIDplus::config()->setValue('color_invert', $set_value ? 1 : 0); |
||
362 | daniel-mar | 199 | OIDplus::config()->setValue('oobe_colors_done', '1'); |
292 | daniel-mar | 200 | } catch (Exception $e) { |
201 | $msg = $e->getMessage(); |
||
202 | $errors_happened = true; |
||
203 | } |
||
204 | } |
||
205 | |||
206 | echo ' <font color="red"><b>'.$msg.'</b></font>'; |
||
207 | } |
||
208 | |||
360 | daniel-mar | 209 | } |