Subversion Repositories oidplus

Rev

Rev 104 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
61 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
class OIDplusPageAdminSystemConfig extends OIDplusPagePlugin {
21
        public function type() {
22
                return 'admin';
23
        }
24
 
25
        public function priority() {
26
                return 110;
27
        }
28
 
29
        public function action(&$handled) {
30
                if ($_POST["action"] == "config_update") {
31
                        $handled = true;
32
 
33
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
34
                                die('You need to log in as administrator.');
35
                        }
36
 
37
                        $name = $_POST['name'];
38
                        $value = $_POST['value'];
39
 
40
                        OIDplus::config()->setValue($name, $value);
41
 
64 daniel-mar 42
                        $res = OIDplus::db()->query("select protected from ".OIDPLUS_TABLENAME_PREFIX."config where name = '".OIDplus::db()->real_escape_string($name)."';");
43
                        $row = OIDplus::db()->fetch_array($res);
44
                        if ($row['protected'] == 1) {
45
                                die('Setting is write protected');
46
                        }
47
 
61 daniel-mar 48
                        echo "OK";
49
                }
50
        }
51
 
75 daniel-mar 52
        public function init($html=true) {
61 daniel-mar 53
                // Nothing
54
        }
55
 
56
        public function cfgSetValue($name, $value) {
57
                // Nothing
58
        }
59
 
60
        public function gui($id, &$out, &$handled) {
61
                if (explode('$',$id)[0] == 'oidplus:edit_config') {
62
                        $handled = true;
63
                        $out['title'] = 'System configuration';
64
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/adminPages/'.basename(__DIR__).'/icon_big.png' : '';
65
 
66
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
67
                                $out['icon'] = 'img/error_big.png';
68
                                $out['text'] .= '<p>You need to <a href="?goto=oidplus:login">log in</a> as administrator.</p>';
69
                        } else {
70
                                $output = '';
71
                                $output .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
72
                                $output .= '<table class="table table-bordered table-striped">';
73
                                $output .= '    <tr>';
74
                                $output .= '         <th>Setting</th>';
75
                                $output .= '         <th>Description</th>';
76
                                $output .= '         <th>Value</th>';
77
                                $output .= '         <th>Update</th>';
78
                                $output .= '    </tr>';
79
 
80
                                OIDplus::config(); // <-- make sure that the config table is loaded/filled correctly before we do a select
81
 
64 daniel-mar 82
                                $result = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."config where `visible` = 1 order by name");
61 daniel-mar 83
                                while ($row = OIDplus::db()->fetch_object($result)) {
84
                                        $output .= '<tr>';
85
                                        $output .= '     <td>'.htmlentities($row->name).'</td>';
86
                                        $output .= '     <td>'.htmlentities($row->description).'</td>';
64 daniel-mar 87
                                        if ($row->protected == 1) {
80 daniel-mar 88
                                                $desc = $row->value;
89
                                                if (strlen($desc) > 100) $desc = substr($desc, 0, 100) . '...';
90
                                                $output .= '     <td>'.htmlentities($desc).'</td>';
64 daniel-mar 91
                                                $output .= '     <td>&nbsp;</td>';
92
                                        } else {
93
                                                $output .= '     <td><input type="text" id="config_'.$row->name.'" value="'.htmlentities($row->value).'"></td>';
104 daniel-mar 94
                                                $output .= '     <td><button type="button" name="config_update_'.$row->name.'" id="config_update_'.$row->name.'" class="btn btn-success btn-xs update" onclick="crudActionConfigUpdate('.js_escape($row->name).')">Update</button></td>';
64 daniel-mar 95
                                        }
61 daniel-mar 96
                                        $output .= '</tr>';
97
                                }
98
 
99
                                $output .= '</table>';
100
                                $output .= '</div></div>';
101
 
80 daniel-mar 102
                                $output .= '<br><p>See also:</p>';
103
                                $output .= '<ul><li><a href="setup/">Setup part 1: Create config.php (contains database settings, ReCAPTCHA, admin password and SSL enforcement)</a></li>';
104
                                $output .= '<li><a href="plugins/system/000_registration/registration.php">Setup part 2: Basic settings (they are all available above, too)</a></li></ul>';
105
 
61 daniel-mar 106
                                $out['text'] = $output;
107
                        }
108
 
109
                        return $out;
110
                }
111
        }
112
 
106 daniel-mar 113
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
61 daniel-mar 114
                if (file_exists(__DIR__.'/treeicon.png')) {
115
                        $tree_icon = 'plugins/adminPages/'.basename(__DIR__).'/treeicon.png';
116
                } else {
117
                        $tree_icon = null; // default icon (folder)
118
                }
119
 
120
                $json[] = array(
121
                        'id' => 'oidplus:edit_config',
122
                        'icon' => $tree_icon,
123
                        'text' => 'System config'
124
                );
104 daniel-mar 125
 
126
                return true;
61 daniel-mar 127
        }
128
}
129
 
130
OIDplus::registerPagePlugin(new OIDplusPageAdminSystemConfig());