Rev 61 | 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 | |||
20 | class OIDplusPageAdminSystemConfig extends OIDplusPagePlugin { |
||
21 | public function type() { |
||
22 | return 'admin'; |
||
23 | } |
||
24 | |||
25 | public function priority() { |
||
26 | return 110; |
||
27 | } |
||
28 | |||
29 | public function action(&$handled) { |
||
30 | if ($_POST["action"] == "config_update") { |
||
31 | $handled = true; |
||
32 | |||
33 | if (!OIDplus::authUtils()::isAdminLoggedIn()) { |
||
34 | die('You need to log in as administrator.'); |
||
35 | } |
||
36 | |||
37 | $name = $_POST['name']; |
||
38 | $value = $_POST['value']; |
||
39 | |||
40 | OIDplus::config()->setValue($name, $value); |
||
41 | |||
64 | daniel-mar | 42 | $res = OIDplus::db()->query("select protected from ".OIDPLUS_TABLENAME_PREFIX."config where name = '".OIDplus::db()->real_escape_string($name)."';"); |
43 | $row = OIDplus::db()->fetch_array($res); |
||
44 | if ($row['protected'] == 1) { |
||
45 | die('Setting is write protected'); |
||
46 | } |
||
47 | |||
61 | daniel-mar | 48 | echo "OK"; |
49 | } |
||
50 | } |
||
51 | |||
52 | public function cfgLoadConfig() { |
||
53 | // Nothing |
||
54 | } |
||
55 | |||
56 | public function cfgSetValue($name, $value) { |
||
57 | // Nothing |
||
58 | } |
||
59 | |||
60 | public function gui($id, &$out, &$handled) { |
||
61 | if (explode('$',$id)[0] == 'oidplus:edit_config') { |
||
62 | $handled = true; |
||
63 | $out['title'] = 'System configuration'; |
||
64 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? 'plugins/adminPages/'.basename(__DIR__).'/icon_big.png' : ''; |
||
65 | |||
66 | if (!OIDplus::authUtils()::isAdminLoggedIn()) { |
||
67 | $out['icon'] = 'img/error_big.png'; |
||
68 | $out['text'] .= '<p>You need to <a href="?goto=oidplus:login">log in</a> as administrator.</p>'; |
||
69 | } else { |
||
70 | $output = ''; |
||
71 | $output .= '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
||
72 | $output .= '<table class="table table-bordered table-striped">'; |
||
73 | $output .= ' <tr>'; |
||
74 | $output .= ' <th>Setting</th>'; |
||
75 | $output .= ' <th>Description</th>'; |
||
76 | $output .= ' <th>Value</th>'; |
||
77 | $output .= ' <th>Update</th>'; |
||
78 | $output .= ' </tr>'; |
||
79 | |||
80 | OIDplus::config(); // <-- make sure that the config table is loaded/filled correctly before we do a select |
||
81 | |||
64 | daniel-mar | 82 | $result = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."config where `visible` = 1 order by name"); |
61 | daniel-mar | 83 | while ($row = OIDplus::db()->fetch_object($result)) { |
84 | $output .= '<tr>'; |
||
85 | $output .= ' <td>'.htmlentities($row->name).'</td>'; |
||
86 | $output .= ' <td>'.htmlentities($row->description).'</td>'; |
||
64 | daniel-mar | 87 | if ($row->protected == 1) { |
88 | $output .= ' <td>'.htmlentities($row->value).'</td>'; |
||
89 | $output .= ' <td> </td>'; |
||
90 | } else { |
||
91 | $output .= ' <td><input type="text" id="config_'.$row->name.'" value="'.htmlentities($row->value).'"></td>'; |
||
92 | $output .= ' <td><button type="button" name="config_update_'.$row->name.'" id="config_update_'.$row->name.'" class="btn btn-success btn-xs update" onclick="javascript:crudActionConfigUpdate('.js_escape($row->name).')">Update</button></td>'; |
||
93 | } |
||
61 | daniel-mar | 94 | $output .= '</tr>'; |
95 | } |
||
96 | |||
97 | $output .= '</table>'; |
||
98 | $output .= '</div></div>'; |
||
99 | |||
100 | $out['text'] = $output; |
||
101 | } |
||
102 | |||
103 | return $out; |
||
104 | } |
||
105 | } |
||
106 | |||
107 | public function tree(&$json, $ra_email=null) { |
||
108 | if (file_exists(__DIR__.'/treeicon.png')) { |
||
109 | $tree_icon = 'plugins/adminPages/'.basename(__DIR__).'/treeicon.png'; |
||
110 | } else { |
||
111 | $tree_icon = null; // default icon (folder) |
||
112 | } |
||
113 | |||
114 | $json[] = array( |
||
115 | 'id' => 'oidplus:edit_config', |
||
116 | 'icon' => $tree_icon, |
||
117 | 'text' => 'System config' |
||
118 | ); |
||
119 | } |
||
120 | } |
||
121 | |||
122 | OIDplus::registerPagePlugin(new OIDplusPageAdminSystemConfig()); |