Subversion Repositories oidplus

Rev

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