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
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
 
112 daniel-mar 20
if (!defined('IN_OIDPLUS')) die();
21
 
61 daniel-mar 22
class OIDplusPageAdminSystemConfig extends OIDplusPagePlugin {
222 daniel-mar 23
        public static function getPluginInformation() {
24
                $out = array();
25
                $out['name'] = 'System configuration';
26
                $out['author'] = 'ViaThinkSoft';
27
                $out['version'] = null;
28
                $out['descriptionHTML'] = null;
29
                return $out;
30
        }
31
 
61 daniel-mar 32
        public function type() {
33
                return 'admin';
34
        }
35
 
36
        public function priority() {
37
                return 110;
38
        }
39
 
40
        public function action(&$handled) {
107 daniel-mar 41
                if (isset($_POST["action"]) && ($_POST["action"] == "config_update")) {
61 daniel-mar 42
                        $handled = true;
43
 
44
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
250 daniel-mar 45
                                throw new OIDplusException('You need to log in as administrator.');
61 daniel-mar 46
                        }
47
 
48
                        $name = $_POST['name'];
49
                        $value = $_POST['value'];
139 daniel-mar 50
 
150 daniel-mar 51
                        $res = OIDplus::db()->query("select protected from ".OIDPLUS_TABLENAME_PREFIX."config where name = ?", array($name));
251 daniel-mar 52
                        if ($res->num_rows() == 0) {
53
                                throw new OIDplusException('Setting does not exist');
54
                        }
236 daniel-mar 55
                        $row = $res->fetch_array();
64 daniel-mar 56
                        if ($row['protected'] == 1) {
250 daniel-mar 57
                                throw new OIDplusException('Setting is write protected');
64 daniel-mar 58
                        }
59
 
115 daniel-mar 60
                        OIDplus::config()->setValue($name, $value);
61
                        OIDplus::logger()->log("A?", "Changed system config setting '$name' to '$value'");
62
 
107 daniel-mar 63
                        echo json_encode(array("status" => 0));
61 daniel-mar 64
                }
65
        }
66
 
75 daniel-mar 67
        public function init($html=true) {
61 daniel-mar 68
                // Nothing
69
        }
70
 
71
        public function cfgSetValue($name, $value) {
72
                // Nothing
73
        }
74
 
75
        public function gui($id, &$out, &$handled) {
76
                if (explode('$',$id)[0] == 'oidplus:edit_config') {
77
                        $handled = true;
78
                        $out['title'] = 'System configuration';
241 daniel-mar 79
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
61 daniel-mar 80
 
81
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
82
                                $out['icon'] = 'img/error_big.png';
250 daniel-mar 83
                                $out['text'] = '<p>You need to <a '.OIDplus::gui()->link('oidplus:login').'>log in</a> as administrator.</p>';
61 daniel-mar 84
                        } else {
85
                                $output = '';
86
                                $output .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
87
                                $output .= '<table class="table table-bordered table-striped">';
88
                                $output .= '    <tr>';
89
                                $output .= '         <th>Setting</th>';
90
                                $output .= '         <th>Description</th>';
91
                                $output .= '         <th>Value</th>';
92
                                $output .= '         <th>Update</th>';
93
                                $output .= '    </tr>';
94
 
95
                                OIDplus::config(); // <-- make sure that the config table is loaded/filled correctly before we do a select
96
 
239 daniel-mar 97
                                $result = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."config where visible = ? order by name", array(true));
236 daniel-mar 98
                                while ($row = $result->fetch_object()) {
61 daniel-mar 99
                                        $output .= '<tr>';
100
                                        $output .= '     <td>'.htmlentities($row->name).'</td>';
101
                                        $output .= '     <td>'.htmlentities($row->description).'</td>';
64 daniel-mar 102
                                        if ($row->protected == 1) {
80 daniel-mar 103
                                                $desc = $row->value;
104
                                                if (strlen($desc) > 100) $desc = substr($desc, 0, 100) . '...';
181 daniel-mar 105
                                                $output .= '     <td style="word-break: break-all;">'.htmlentities($desc).'</td>';
64 daniel-mar 106
                                                $output .= '     <td>&nbsp;</td>';
107
                                        } else {
108
                                                $output .= '     <td><input type="text" id="config_'.$row->name.'" value="'.htmlentities($row->value).'"></td>';
104 daniel-mar 109
                                                $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 110
                                        }
61 daniel-mar 111
                                        $output .= '</tr>';
112
                                }
113
 
114
                                $output .= '</table>';
115
                                $output .= '</div></div>';
116
 
80 daniel-mar 117
                                $output .= '<br><p>See also:</p>';
241 daniel-mar 118
                                $output .= '<ul>';
119
                                $output .= '<li><a href="'.OIDplus::getSystemUrl().'setup/">Setup part 1: Create config.php (contains database settings, ReCAPTCHA, admin password and SSL enforcement)</a></li>';
120
                                if (class_exists('OIDplusPageAdminRegistration')) {
121
                                        $reflector = new \ReflectionClass('OIDplusPageAdminRegistration');
122
                                        $path = dirname($reflector->getFilename());
123
                                        $output .= '<li><a href="'.OIDplus::webpath($path).'registration.php">Setup part 2: Basic settings (they are all available above, too)</a></li>';
124
                                } else {
125
                                        $output .= '<li>Setup part 2 requires plugin OIDplusPageAdminRegistration (the basic settings are all available above, too)</a></li>';
126
                                }
127
                                $output .= '</ul>';
80 daniel-mar 128
 
61 daniel-mar 129
                                $out['text'] = $output;
130
                        }
131
 
132
                        return $out;
133
                }
134
        }
135
 
106 daniel-mar 136
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
61 daniel-mar 137
                if (file_exists(__DIR__.'/treeicon.png')) {
241 daniel-mar 138
                        $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
61 daniel-mar 139
                } else {
140
                        $tree_icon = null; // default icon (folder)
141
                }
142
 
143
                $json[] = array(
144
                        'id' => 'oidplus:edit_config',
145
                        'icon' => $tree_icon,
146
                        'text' => 'System config'
147
                );
104 daniel-mar 148
 
149
                return true;
61 daniel-mar 150
        }
108 daniel-mar 151
 
152
        public function tree_search($request) {
153
                return false;
154
        }
61 daniel-mar 155
}