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