Rev 279 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
117 | 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 OIDplusPageRaLogEvents extends OIDplusPagePluginRa { |
117 | daniel-mar | 21 | |
22 | public function action(&$handled) { |
||
23 | } |
||
24 | |||
25 | public function init($html=true) { |
||
26 | } |
||
27 | |||
28 | public function gui($id, &$out, &$handled) { |
||
29 | if (explode('$',$id)[0] == 'oidplus:ra_log') { |
||
30 | $handled = true; |
||
31 | |||
32 | $ra_email = explode('$',$id)[1]; |
||
33 | |||
281 | daniel-mar | 34 | if (!OIDplus::authUtils()::isRaLoggedIn($ra_email) && !OIDplus::authUtils()::isAdminLoggedIn()) { |
35 | $out['icon'] = 'img/error_big.png'; |
||
36 | $out['text'] = '<p>You need to <a '.OIDplus::gui()->link('oidplus:login').'>log in</a> as the requested RA <b>'.htmlentities($ra_email).'</b>.</p>'; |
||
37 | return; |
||
38 | } |
||
39 | |||
261 | daniel-mar | 40 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
236 | daniel-mar | 41 | if ($res->num_rows() == 0) { |
117 | daniel-mar | 42 | $out['icon'] = 'img/error_big.png'; |
43 | $out['text'] = 'RA <b>'.htmlentities($ra_email).'</b> does not exist'; |
||
281 | daniel-mar | 44 | return; |
117 | daniel-mar | 45 | } |
46 | |||
47 | $out['title'] = "Log entries for RA $ra_email"; |
||
241 | daniel-mar | 48 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : ''; |
117 | daniel-mar | 49 | |
261 | daniel-mar | 50 | $res = OIDplus::db()->query("select lo.unix_ts, lo.addr, lo.event from ###log lo ". |
51 | "left join ###log_user lu on lu.log_id = lo.id ". |
||
239 | daniel-mar | 52 | "where lu.username = ? " . |
150 | daniel-mar | 53 | "order by lo.unix_ts desc", array($ra_email)); |
236 | daniel-mar | 54 | if ($res->num_rows() > 0) { |
117 | daniel-mar | 55 | $out['text'] = '<pre>'; |
236 | daniel-mar | 56 | while ($row = $res->fetch_array()) { |
117 | daniel-mar | 57 | $addr = empty($row['addr']) ? 'no address' : $row['addr']; |
58 | |||
59 | $out['text'] .= date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr) . ")\n"; |
||
60 | } |
||
61 | $out['text'] .= '</pre>'; |
||
62 | } else { |
||
63 | $out['text'] .= '<p>Currently there are no log entries</p>'; |
||
64 | } |
||
148 | daniel-mar | 65 | |
117 | daniel-mar | 66 | // TODO: List logs in a table instead of a <pre> text |
67 | // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down |
||
68 | } |
||
69 | } |
||
70 | |||
71 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
||
281 | daniel-mar | 72 | if (!$ra_email) return false; |
73 | if (!OIDplus::authUtils()::isRaLoggedIn($ra_email) && !OIDplus::authUtils()::isAdminLoggedIn()) return false; |
||
74 | |||
117 | daniel-mar | 75 | if (file_exists(__DIR__.'/treeicon.png')) { |
241 | daniel-mar | 76 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
117 | daniel-mar | 77 | } else { |
78 | $tree_icon = null; // default icon (folder) |
||
79 | } |
||
80 | |||
81 | $json[] = array( |
||
82 | 'id' => 'oidplus:ra_log$'.$ra_email, |
||
83 | 'icon' => $tree_icon, |
||
84 | 'text' => 'RA log events' |
||
85 | ); |
||
86 | |||
87 | return true; |
||
88 | } |
||
89 | |||
90 | public function tree_search($request) { |
||
91 | return false; |
||
92 | } |
||
93 | } |