Rev 328 | 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 | |||
321 | daniel-mar | 22 | public function action($actionID, $params) { |
23 | if ($actionID == 'config_update') { |
||
61 | daniel-mar | 24 | if (!OIDplus::authUtils()::isAdminLoggedIn()) { |
360 | daniel-mar | 25 | throw new OIDplusException(_L('You need to log in as administrator.')); |
61 | daniel-mar | 26 | } |
27 | |||
321 | daniel-mar | 28 | $name = $params['name']; |
29 | $value = $params['value']; |
||
139 | daniel-mar | 30 | |
263 | daniel-mar | 31 | $res = OIDplus::db()->query("select protected, visible from ###config where name = ?", array($name)); |
251 | daniel-mar | 32 | if ($res->num_rows() == 0) { |
360 | daniel-mar | 33 | throw new OIDplusException(_L('Setting does not exist')); |
251 | daniel-mar | 34 | } |
236 | daniel-mar | 35 | $row = $res->fetch_array(); |
263 | daniel-mar | 36 | if (($row['protected'] == 1) || ($row['visible'] == 0)) { |
360 | daniel-mar | 37 | throw new OIDplusException(_L("Setting %1 is read-only",$name)); |
64 | daniel-mar | 38 | } |
39 | |||
115 | daniel-mar | 40 | OIDplus::config()->setValue($name, $value); |
288 | daniel-mar | 41 | OIDplus::logger()->log("[OK]A?", "Changed system config setting '$name' to '$value'"); |
115 | daniel-mar | 42 | |
328 | daniel-mar | 43 | return array("status" => 0); |
321 | daniel-mar | 44 | } else { |
360 | daniel-mar | 45 | throw new OIDplusException(_L('Unknown action ID')); |
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; |
||
360 | daniel-mar | 56 | $out['title'] = _L('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'; |
||
360 | daniel-mar | 61 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login')).'</p>'; |
281 | daniel-mar | 62 | return; |
63 | } |
||
360 | daniel-mar | 64 | |
281 | daniel-mar | 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>'; |
||
360 | daniel-mar | 69 | $output .= ' <th>'._L('Setting').'</th>'; |
70 | $output .= ' <th>'._L('Description').'</th>'; |
||
71 | $output .= ' <th>'._L('Value').'</th>'; |
||
72 | $output .= ' <th>'._L('Update').'</th>'; |
||
281 | daniel-mar | 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>'; |
||
360 | daniel-mar | 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).')">'._L('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 | |
360 | daniel-mar | 97 | $output .= '<br><p>'._L('See also').':</p>'; |
281 | daniel-mar | 98 | $output .= '<ul>'; |
360 | daniel-mar | 99 | $output .= '<li><a href="'.OIDplus::getSystemUrl().'setup/">'._L('Setup part 1: Create %1 (contains database settings, ReCAPTCHA, admin password and SSL enforcement)','userdata/baseconfig/config.inc.php').'</a></li>'; |
294 | daniel-mar | 100 | if (class_exists('OIDplusPageAdminOOBE')) { |
101 | $reflector = new \ReflectionClass('OIDplusPageAdminOOBE'); |
||
281 | daniel-mar | 102 | $path = dirname($reflector->getFilename()); |
360 | daniel-mar | 103 | $output .= '<li><a href="'.OIDplus::webpath($path).'oobe.php">'._L('Setup part 2: Basic settings (they are all available above, too)').'</a></li>'; |
281 | daniel-mar | 104 | } else { |
360 | daniel-mar | 105 | $output .= '<li>'._L('Setup part 2 requires plugin %1 (the basic settings are all available above, too)','OIDplusPageAdminOOBE').'</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; |
360 | daniel-mar | 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, |
||
360 | daniel-mar | 125 | 'text' => _L('System configuration') |
61 | daniel-mar | 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 | } |
||
360 | daniel-mar | 134 | } |