Subversion Repositories oidplus

Rev

Rev 263 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
104 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 OIDplusPagePublicRaInfo extends OIDplusPagePluginPublic {
104 daniel-mar 21
 
22
        public function priority() {
23
                return 93;
24
        }
25
 
26
        public function action(&$handled) {
27
        }
28
 
29
        public function init($html=true) {
30
        }
31
 
32
        public function gui($id, &$out, &$handled) {
33
                if (explode('$',$id)[0] == 'oidplus:rainfo') {
34
                        $handled = true;
35
 
151 daniel-mar 36
                        $antispam_email = explode('$',$id.'$')[1];
37
                        $ra_email = str_replace('&', '@', $antispam_email);
104 daniel-mar 38
 
241 daniel-mar 39
                        $out['icon'] = OIDplus::webpath(__DIR__).'rainfo_big.png';
104 daniel-mar 40
 
41
                        if (empty($ra_email)) {
151 daniel-mar 42
                                $out['title'] = 'Object roots without RA';
104 daniel-mar 43
                                $out['text'] = '<p>Following object roots have an undefined Registration Authority:</p>';
44
                        } else {
261 daniel-mar 45
                                $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email));
151 daniel-mar 46
                                $out['title'] = '';
236 daniel-mar 47
                                if ($row = $res->fetch_array()) {
151 daniel-mar 48
                                        $out['title'] = $row['ra_name'];
49
                                }
50
                                if (empty($out['title'])) {
51
                                        $out['title'] = $antispam_email;
52
                                }
104 daniel-mar 53
                                $out['text'] = $this->showRAInfo($ra_email);
54
                        }
55
 
56
                        $out['text'] .= '<br><br>';
57
 
58
                        foreach (OIDplusObject::getRaRoots($ra_email) as $loc_root) {
59
                                $ico = $loc_root->getIcon();
241 daniel-mar 60
                                $icon = !is_null($ico) ? $ico : OIDplus::webpath(__DIR__).'treeicon_link.png';
250 daniel-mar 61
                                $out['text'] .= '<p><a '.OIDplus::gui()->link($loc_root->nodeId()).'><img src="'.$icon.'"> Jump to RA root '.$loc_root->objectTypeTitleShort().' '.$loc_root->crudShowId(OIDplusObject::parse($loc_root::root())).'</a></p>';
104 daniel-mar 62
                        }
63
 
117 daniel-mar 64
                        if (!empty($ra_email)) {
261 daniel-mar 65
                                $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email));
236 daniel-mar 66
                                if ($res->num_rows() > 0) {
152 daniel-mar 67
                                        if (OIDplus::authUtils()::isRALoggedIn($ra_email) || OIDplus::authUtils()::isAdminLoggedIn()) {
68
                                                if (class_exists('OIDplusPageRaEditContactData')) {
250 daniel-mar 69
                                                        $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:edit_ra$'.$ra_email).'>Edit contact data</a></p>';
152 daniel-mar 70
                                                }
71
                                        }
104 daniel-mar 72
 
152 daniel-mar 73
                                        if (OIDplus::authUtils()::isAdminLoggedIn()) {
117 daniel-mar 74
                                                if (class_exists("OIDplusPageAdminListRAs")) {
152 daniel-mar 75
                                                        $out['text'] .= '<p><a href="#" onclick="return deleteRa('.js_escape($ra_email).','.js_escape('oidplus:list_ra').')">Delete this RA</a></p>';
117 daniel-mar 76
                                                } else {
152 daniel-mar 77
                                                        $out['text'] .= '<p><a href="#" onclick="return deleteRa('.js_escape($ra_email).','.js_escape('oidplus:system').')">Delete this RA</a></p>';
117 daniel-mar 78
                                                }
196 daniel-mar 79
 
152 daniel-mar 80
                                                if (class_exists('OIDplusPageRaChangePassword')) {
250 daniel-mar 81
                                                        $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:change_ra_password$'.$ra_email).'>Change password of this RA</a>';
152 daniel-mar 82
                                                }
109 daniel-mar 83
                                        }
104 daniel-mar 84
                                }
117 daniel-mar 85
 
86
                                if (OIDplus::authUtils()::isRALoggedIn($ra_email) || OIDplus::authUtils()::isAdminLoggedIn()) {
261 daniel-mar 87
                                        $res = OIDplus::db()->query("select lo.unix_ts, lo.addr, lo.event from ###log lo ".
88
                                                                    "left join ###log_user lu on lu.log_id = lo.id ".
239 daniel-mar 89
                                                                    "where lu.username = ? " .
150 daniel-mar 90
                                                                    "order by lo.unix_ts desc", array($ra_email));
118 daniel-mar 91
                                        $out['text'] .= '<h2>Log messages for RA '.htmlentities($ra_email).'</h2>';
236 daniel-mar 92
                                        if ($res->num_rows() > 0) {
117 daniel-mar 93
                                                $out['text'] .= '<pre>';
236 daniel-mar 94
                                                while ($row = $res->fetch_array()) {
117 daniel-mar 95
                                                        $addr = empty($row['addr']) ? 'no address' : $row['addr'];
96
 
97
                                                        $out['text'] .= date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr) . ")\n";
98
                                                }
99
                                                $out['text'] .= '</pre>';
100
 
101
                                                // TODO: List logs in a table instead of a <pre> text
102
                                                // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down
118 daniel-mar 103
                                        } else {
104
                                                $out['text'] .= '<p>Currently there are no log entries</p>';
117 daniel-mar 105
                                        }
106
                                }
104 daniel-mar 107
                        }
108
                }
109
        }
110
 
106 daniel-mar 111
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
104 daniel-mar 112
                return false;
113
        }
114
 
115
        public static function showRAInfo($email) {
116
                $out = '';
117
 
118
                if (empty($email)) {
119
                        $out = '<p>The superior RA did not define a RA for this OID.</p>';
120
                        return $out;
121
                }
122
 
261 daniel-mar 123
                $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email));
236 daniel-mar 124
                if ($res->num_rows() === 0) {
104 daniel-mar 125
                        $out = '<p>The RA <a href="mailto:'.htmlentities($email).'">'.htmlentities($email).'</a> is not registered in the database.</p>';
126
                } else {
236 daniel-mar 127
                        $row = $res->fetch_array();
151 daniel-mar 128
                        $out = '<b>'.htmlentities($row['ra_name']).'</b><br>'; // TODO: if you are not already at the page "oidplus:rainfo", then link to it now
104 daniel-mar 129
                        $out .= 'E-Mail: <a href="mailto:'.htmlentities($email).'">'.htmlentities($email).'</a><br>';
130
                        if (trim($row['personal_name']) !== '') $out .= htmlentities($row['personal_name']).'<br>';
131
                        if (trim($row['organization']) !== '') $out .= htmlentities($row['organization']).'<br>';
132
                        if (trim($row['office']) !== '') $out .= htmlentities($row['office']).'<br>';
133
                        if ($row['privacy']) {
134
                                // TODO: meldung nur anzeigen, wenn benutzer überhaupt straße, adresse etc hat
135
                                // TODO: aber der admin soll es sehen, und der user selbst (mit anmerkung, dass es privat ist)
136
                                $out .= '<p>The RA does not want to publish their personal information.</p>';
137
                        } else {
138
                                if (trim($row['street']) !== '') $out .= htmlentities($row['street']).'<br>';
139
                                if (trim($row['zip_town']) !== '') $out .= htmlentities($row['zip_town']).'<br>';
140
                                if (trim($row['country']) !== '') $out .= htmlentities($row['country']).'<br>';
141
                                $out .= '<br>';
142
                                if (trim($row['phone']) !== '') $out .= htmlentities($row['phone']).'<br>';
143
                                if (trim($row['fax']) !== '') $out .= htmlentities($row['fax']).'<br>';
144
                                if (trim($row['mobile']) !== '') $out .= htmlentities($row['mobile']).'<br>';
145
                                $out .= '<br>';
146
                        }
147
                }
148
 
149
                return trim_br($out);
150
        }
108 daniel-mar 151
 
152
        public function tree_search($request) {
153
                return false;
154
        }
104 daniel-mar 155
}