Subversion Repositories oidplus

Rev

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