Rev 279 | 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>'; |
281 | daniel-mar | 62 | return; |
63 | } |
||
64 | |||
65 | $output = ''; |
||
66 | $output .= '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
||
67 | $output .= '<table class="table table-bordered table-striped">'; |
||
68 | $output .= ' <tr>'; |
||
69 | $output .= ' <th>Setting</th>'; |
||
70 | $output .= ' <th>Description</th>'; |
||
71 | $output .= ' <th>Value</th>'; |
||
72 | $output .= ' <th>Update</th>'; |
||
73 | $output .= ' </tr>'; |
||
61 | daniel-mar | 74 | |
281 | daniel-mar | 75 | OIDplus::config(); // <-- make sure that the config table is loaded/filled correctly before we do a select |
61 | daniel-mar | 76 | |
281 | daniel-mar | 77 | $result = OIDplus::db()->query("select * from ###config where visible = ? order by name", array(true)); |
78 | while ($row = $result->fetch_object()) { |
||
79 | $output .= '<tr>'; |
||
80 | $output .= ' <td>'.htmlentities($row->name).'</td>'; |
||
81 | $output .= ' <td>'.htmlentities($row->description).'</td>'; |
||
82 | if ($row->protected == 1) { |
||
83 | $desc = $row->value; |
||
84 | if (strlen($desc) > 100) $desc = substr($desc, 0, 100) . '...'; |
||
85 | $output .= ' <td style="word-break: break-all;">'.htmlentities($desc).'</td>'; |
||
86 | $output .= ' <td> </td>'; |
||
87 | } else { |
||
88 | $output .= ' <td><input type="text" id="config_'.$row->name.'" value="'.htmlentities($row->value).'"></td>'; |
||
89 | $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>'; |
||
61 | daniel-mar | 90 | } |
281 | daniel-mar | 91 | $output .= '</tr>'; |
92 | } |
||
61 | daniel-mar | 93 | |
281 | daniel-mar | 94 | $output .= '</table>'; |
95 | $output .= '</div></div>'; |
||
61 | daniel-mar | 96 | |
281 | daniel-mar | 97 | $output .= '<br><p>See also:</p>'; |
98 | $output .= '<ul>'; |
||
99 | $output .= '<li><a href="'.OIDplus::getSystemUrl().'setup/">Setup part 1: Create config.php (contains database settings, ReCAPTCHA, admin password and SSL enforcement)</a></li>'; |
||
100 | if (class_exists('OIDplusPageAdminRegistration')) { |
||
101 | $reflector = new \ReflectionClass('OIDplusPageAdminRegistration'); |
||
102 | $path = dirname($reflector->getFilename()); |
||
103 | $output .= '<li><a href="'.OIDplus::webpath($path).'oobe.php">Setup part 2: Basic settings (they are all available above, too)</a></li>'; |
||
104 | } else { |
||
105 | $output .= '<li>Setup part 2 requires plugin OIDplusPageAdminRegistration (the basic settings are all available above, too)</a></li>'; |
||
61 | daniel-mar | 106 | } |
281 | daniel-mar | 107 | $output .= '</ul>'; |
61 | daniel-mar | 108 | |
281 | daniel-mar | 109 | $out['text'] = $output; |
61 | daniel-mar | 110 | } |
111 | } |
||
112 | |||
106 | daniel-mar | 113 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
281 | daniel-mar | 114 | if (!OIDplus::authUtils()::isAdminLoggedIn()) return false; |
115 | |||
61 | daniel-mar | 116 | if (file_exists(__DIR__.'/treeicon.png')) { |
241 | daniel-mar | 117 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
61 | daniel-mar | 118 | } else { |
119 | $tree_icon = null; // default icon (folder) |
||
120 | } |
||
121 | |||
122 | $json[] = array( |
||
123 | 'id' => 'oidplus:edit_config', |
||
124 | 'icon' => $tree_icon, |
||
125 | 'text' => 'System config' |
||
126 | ); |
||
104 | daniel-mar | 127 | |
128 | return true; |
||
61 | daniel-mar | 129 | } |
108 | daniel-mar | 130 | |
131 | public function tree_search($request) { |
||
132 | return false; |
||
133 | } |
||
61 | daniel-mar | 134 | } |