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