Subversion Repositories oidplus

Rev

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