Subversion Repositories oidplus

Rev

Rev 408 | 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
511 daniel-mar 5
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
61 daniel-mar 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
 
511 daniel-mar 20
if (!defined('INSIDE_OIDPLUS')) die();
21
 
256 daniel-mar 22
class OIDplusPageAdminListRAs extends OIDplusPagePluginAdmin {
23
 
75 daniel-mar 24
        public function init($html=true) {
61 daniel-mar 25
                // Nothing
26
        }
27
 
108 daniel-mar 28
        private function get_ralist() {
29
                $tmp = array();
274 daniel-mar 30
                if (OIDplus::db()->getSlang()::id() == 'mysql') {
261 daniel-mar 31
                        $res = OIDplus::db()->query("select distinct BINARY(email) as email from ###ra"); // "binary" because we want to ensure that 'distinct' is case sensitive
239 daniel-mar 32
                } else {
261 daniel-mar 33
                        $res = OIDplus::db()->query("select distinct email as email from ###ra"); // distinct in PGSQL is always case sensitive
239 daniel-mar 34
                }
236 daniel-mar 35
                while ($row = $res->fetch_array()) {
108 daniel-mar 36
                        $tmp[$row['email']] = 1;
37
                }
274 daniel-mar 38
                if (OIDplus::db()->getSlang()::id() == 'mysql') {
261 daniel-mar 39
                        $res = OIDplus::db()->query("select distinct BINARY(ra_email) as ra_email from ###objects");
239 daniel-mar 40
                } else {
261 daniel-mar 41
                        $res = OIDplus::db()->query("select distinct ra_email as ra_email from ###objects");
239 daniel-mar 42
                }
236 daniel-mar 43
                while ($row = $res->fetch_array()) {
108 daniel-mar 44
                        if (!isset($tmp[$row['ra_email']])) {
45
                                $tmp[$row['ra_email']] = 0;
46
                        } else {
47
                                $tmp[$row['ra_email']] = 2;
48
                        }
49
                }
50
                ksort($tmp);
51
 
52
                return $tmp;
53
        }
54
 
61 daniel-mar 55
        public function gui($id, &$out, &$handled) {
56
                if ($id === 'oidplus:list_ra') {
57
                        $handled = true;
360 daniel-mar 58
                        $out['title'] = _L('RA Listing');
241 daniel-mar 59
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
61 daniel-mar 60
 
61
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
62
                                $out['icon'] = 'img/error_big.png';
360 daniel-mar 63
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login')).'</p>';
281 daniel-mar 64
                                return;
65
                        }
61 daniel-mar 66
 
281 daniel-mar 67
                        $out['text'] = '';
277 daniel-mar 68
 
281 daniel-mar 69
                        $tmp = $this->get_ralist();
408 daniel-mar 70
 
71
                        $raCreatePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.130'); // OIDplusPageAdminCreateRa
72
                        if (!is_null($raCreatePlugin)) {
73
                                $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:create_ra').'>Create a new RA manually</a></p>';
74
                        }
61 daniel-mar 75
 
281 daniel-mar 76
                        if (count($tmp) == 0) {
360 daniel-mar 77
                                $out['text'] .= '<p>'._L('Currently there are no Registration Authorities.').'</p>';
281 daniel-mar 78
                        }
79
 
80
                        foreach ($tmp as $ra_email => $registered) {
81
                                if (empty($ra_email)) {
360 daniel-mar 82
                                        $out['text'] .= '<p><b><a '.OIDplus::gui()->link('oidplus:rainfo$').'>'._L('(Objects with undefined RA)').'</a></b></p>';
281 daniel-mar 83
                                } else {
84
                                        if ($registered == 0) {
360 daniel-mar 85
                                                $out['text'] .= '<p><b><a '.OIDplus::gui()->link('oidplus:rainfo$'.str_replace('@','&',$ra_email)).'>'.htmlentities($ra_email).'</a></b> '._L('(has objects, is not registered)').'</p>';
61 daniel-mar 86
                                        }
281 daniel-mar 87
                                        if ($registered == 1) {
360 daniel-mar 88
                                                $out['text'] .= '<p><b><a '.OIDplus::gui()->link('oidplus:rainfo$'.str_replace('@','&',$ra_email)).'>'.htmlentities($ra_email).'</a></b> '._L('(registered, <font color="red">has no objects</font>)').'</p>';
281 daniel-mar 89
                                        }
90
                                        if ($registered == 2) {
91
                                                $out['text'] .= '<p><b><a '.OIDplus::gui()->link('oidplus:rainfo$'.str_replace('@','&',$ra_email)).'>'.htmlentities($ra_email).'</a></b></p>';
92
                                        }
61 daniel-mar 93
                                }
94
                        }
95
                }
96
        }
97
 
106 daniel-mar 98
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
281 daniel-mar 99
                if (!OIDplus::authUtils()::isAdminLoggedIn()) return false;
360 daniel-mar 100
 
61 daniel-mar 101
                if (file_exists(__DIR__.'/treeicon.png')) {
241 daniel-mar 102
                        $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
61 daniel-mar 103
                } else {
104
                        $tree_icon = null; // default icon (folder)
105
                }
106
 
108 daniel-mar 107
                $children = array();
108
                $tmp = $this->get_ralist();
109
                foreach ($tmp as $ra_email => $registered) {
110
                        if (empty($ra_email)) {
111
                                $children[] = array(
112
                                        'id' => 'oidplus:rainfo$',
113
                                        'icon' => $tree_icon,
360 daniel-mar 114
                                        'text' => _L('(Objects with undefined RA)')
108 daniel-mar 115
                                );
116
                        } else {
117
                                if ($registered == 0) {
118
                                        $children[] = array(
109 daniel-mar 119
                                                'id' => 'oidplus:rainfo$'.str_replace('@', '&', $ra_email),
108 daniel-mar 120
                                                'icon' => $tree_icon,
360 daniel-mar 121
                                                'text' => $ra_email.' <i>'._L('(has objects, is not registered)').'</i>'
108 daniel-mar 122
                                        );
123
                                }
124
                                if ($registered == 1) {
125
                                        $children[] = array(
126
                                                'id' => 'oidplus:rainfo$'.$ra_email,
127
                                                'icon' => $tree_icon,
360 daniel-mar 128
                                                'text' => $ra_email.' <i><font color="red">'._L('(has no objects)').'</font></i>'
108 daniel-mar 129
                                        );
130
                                }
131
                                if ($registered == 2) {
132
                                        $children[] = array(
133
                                                'id' => 'oidplus:rainfo$'.$ra_email,
134
                                                'icon' => $tree_icon,
135
                                                'text' => $ra_email
136
                                        );
137
                                }
138
                        }
139
                }
140
 
61 daniel-mar 141
                $json[] = array(
142
                        'id' => 'oidplus:list_ra',
143
                        'icon' => $tree_icon,
360 daniel-mar 144
                        'text' => _L('List RAs'),
108 daniel-mar 145
                        'children' => $children
61 daniel-mar 146
                );
104 daniel-mar 147
 
148
                return true;
61 daniel-mar 149
        }
108 daniel-mar 150
 
151
        public function tree_search($request) {
109 daniel-mar 152
                // We don't need this, because the list of RAs is loaded without lazy-loading,
153
                // so the node does not need to be searched
154
                /*
108 daniel-mar 155
                if (strpos($request, 'oidplus:rainfo$') === 0) {
156
                        if (OIDplus::authUtils()::isAdminLoggedIn()) {
109 daniel-mar 157
                                return array('oidplus:login', ...dummy..., 'oidplus:list_ra', $request);
108 daniel-mar 158
                        }
159
                }
109 daniel-mar 160
                */
161
                return false;
108 daniel-mar 162
        }
360 daniel-mar 163
}