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