Subversion Repositories oidplus

Rev

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