Subversion Repositories oidplus

Rev

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