Rev 224 | 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 | |||
20 | if (!defined('IN_OIDPLUS')) die(); |
||
21 | |||
22 | class OIDplusPageAdminColors extends OIDplusPagePlugin { |
||
222 | daniel-mar | 23 | public static function getPluginInformation() { |
24 | $out = array(); |
||
25 | $out['name'] = 'Colors'; |
||
26 | $out['author'] = 'ViaThinkSoft'; |
||
27 | $out['version'] = null; |
||
28 | $out['descriptionHTML'] = null; |
||
29 | return $out; |
||
30 | } |
||
31 | |||
142 | daniel-mar | 32 | public function type() { |
33 | return 'admin'; |
||
34 | } |
||
35 | |||
36 | public function priority() { |
||
37 | return 700; |
||
38 | } |
||
39 | |||
40 | public function action(&$handled) { |
||
41 | if (isset($_POST["action"]) && ($_POST["action"] == "color_update")) { |
||
42 | $handled = true; |
||
43 | |||
44 | if (!OIDplus::authUtils()::isAdminLoggedIn()) { |
||
237 | daniel-mar | 45 | throw new Exception('You need to log in as administrator.'); |
142 | daniel-mar | 46 | } |
47 | |||
48 | OIDplus::config()->setValue('color_hue_shift', $_POST['hue_shift']); |
||
49 | OIDplus::config()->setValue('color_sat_shift', $_POST['sat_shift']); |
||
50 | OIDplus::config()->setValue('color_val_shift', $_POST['val_shift']); |
||
51 | |||
52 | OIDplus::logger()->log("A?", "Changed system color theme"); |
||
53 | |||
54 | echo json_encode(array("status" => 0)); |
||
55 | } |
||
56 | } |
||
57 | |||
58 | public function init($html=true) { |
||
59 | OIDplus::config()->prepareConfigKey('color_hue_shift', 'HSV Hue shift of CSS colors (-360..360)', '0', 0, 1); |
||
60 | OIDplus::config()->prepareConfigKey('color_sat_shift', 'HSV Saturation shift of CSS colors (-100..100)', '0', 0, 1); |
||
61 | OIDplus::config()->prepareConfigKey('color_val_shift', 'HSV Value shift of CSS colors (-100..100)', '0', 0, 1); |
||
62 | } |
||
63 | |||
64 | public function cfgSetValue($name, $value) { |
||
65 | if ($name == 'color_hue_shift') { |
||
66 | if (!is_numeric($value) || ($value < -360) || ($value > 360)) { |
||
67 | throw new Exception("Please enter a valid value."); |
||
68 | } |
||
69 | } |
||
70 | if ($name == 'color_sat_shift') { |
||
71 | if (!is_numeric($value) || ($value < -100) || ($value > 100)) { |
||
72 | throw new Exception("Please enter a valid value."); |
||
73 | } |
||
74 | } |
||
75 | if ($name == 'color_val_shift') { |
||
76 | if (!is_numeric($value) || ($value < -100) || ($value > 100)) { |
||
77 | throw new Exception("Please enter a valid value."); |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | |||
82 | public function gui($id, &$out, &$handled) { |
||
83 | if ($id === 'oidplus:colors') { |
||
84 | $handled = true; |
||
85 | $out['title'] = 'Colors'; |
||
148 | daniel-mar | 86 | $out['icon'] = 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/icon_big.png'; |
142 | daniel-mar | 87 | |
88 | if (!OIDplus::authUtils()::isAdminLoggedIn()) { |
||
89 | $out['icon'] = 'img/error_big.png'; |
||
153 | daniel-mar | 90 | $out['text'] = '<p>You need to <a '.oidplus_link('oidplus:login').'>log in</a> as administrator.</p>'; |
142 | daniel-mar | 91 | } else { |
92 | $out['text'] = '<p>'; |
||
93 | $out['text'] .= ' <label for="amount">Hue shift:</label>'; |
||
143 | daniel-mar | 94 | $out['text'] .= ' <input type="text" id="hshift" readonly style="border:0; background:transparent; font-weight:bold;">'; |
142 | daniel-mar | 95 | $out['text'] .= '</p>'; |
96 | $out['text'] .= '<div id="slider-hshift"></div>'; |
||
97 | $out['text'] .= '<p>'; |
||
98 | $out['text'] .= ' <label for="amount">Saturation shift:</label>'; |
||
143 | daniel-mar | 99 | $out['text'] .= ' <input type="text" id="sshift" readonly style="border:0; background:transparent; font-weight:bold;">'; |
142 | daniel-mar | 100 | $out['text'] .= '</p>'; |
101 | $out['text'] .= '<div id="slider-sshift"></div>'; |
||
102 | $out['text'] .= '<p>'; |
||
103 | $out['text'] .= ' <label for="amount">Value shift:</label>'; |
||
143 | daniel-mar | 104 | $out['text'] .= ' <input type="text" id="vshift" readonly style="border:0; background:transparent; font-weight:bold;">'; |
142 | daniel-mar | 105 | $out['text'] .= '</p>'; |
106 | $out['text'] .= '<div id="slider-vshift"></div>'; |
||
107 | $out['text'] .= '<script>'; |
||
144 | daniel-mar | 108 | $out['text'] .= 'if (g_hue_shift == null) g_hue_shift = g_hue_shift_saved = '.OIDplus::config()->getValue('color_hue_shift').";\n"; |
109 | $out['text'] .= 'if (g_sat_shift == null) g_sat_shift = g_sat_shift_saved = '.OIDplus::config()->getValue('color_sat_shift').";\n"; |
||
110 | $out['text'] .= 'if (g_val_shift == null) g_val_shift = g_val_shift_saved = '.OIDplus::config()->getValue('color_val_shift').";\n"; |
||
142 | daniel-mar | 111 | $out['text'] .= 'setup_color_sliders();'; |
112 | $out['text'] .= '</script>'; |
||
144 | daniel-mar | 113 | $out['text'] .= '<br>'; |
114 | $out['text'] .= '<input type="button" onclick="color_reset_sliders_cfg()" value="Reset to last saved config">'.str_repeat(' ',5); |
||
115 | $out['text'] .= '<input type="button" onclick="color_reset_sliders_factory()" value="Reset default setting">'.str_repeat(' ',5); |
||
143 | daniel-mar | 116 | $out['text'] .= '<input type="button" onclick="test_color_theme()" value="Test">'.str_repeat(' ',5); |
142 | daniel-mar | 117 | $out['text'] .= '<input type="button" onclick="crudActionColorUpdate()" value="Set permanently">'; |
118 | } |
||
119 | } |
||
120 | } |
||
121 | |||
122 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
||
123 | if (file_exists(__DIR__.'/treeicon.png')) { |
||
148 | daniel-mar | 124 | $tree_icon = 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/treeicon.png'; |
142 | daniel-mar | 125 | } else { |
126 | $tree_icon = null; // default icon (folder) |
||
127 | } |
||
128 | |||
129 | $json[] = array( |
||
130 | 'id' => 'oidplus:colors', |
||
131 | 'icon' => $tree_icon, |
||
132 | 'text' => 'Colors' |
||
133 | ); |
||
134 | |||
135 | return true; |
||
136 | } |
||
137 | |||
138 | public function tree_search($request) { |
||
139 | return false; |
||
140 | } |
||
141 | } |