Subversion Repositories oidplus

Rev

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

Rev Author Line No. Line
635 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 - 2021 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
if (!defined('INSIDE_OIDPLUS')) die();
21
 
22
class OIDplusPageAdminListRAs extends OIDplusPagePluginAdmin {
23
 
24
        public function init($html=true) {
25
                // Nothing
26
        }
27
 
28
        private function get_ralist() {
29
                $tmp = array();
30
                if (OIDplus::db()->getSlang()->id() == 'mysql') {
31
                        $res = OIDplus::db()->query("select distinct BINARY(email) as email from ###ra"); // "binary" because we want to ensure that 'distinct' is case sensitive
32
                } else {
33
                        $res = OIDplus::db()->query("select distinct email as email from ###ra"); // distinct in PGSQL is always case sensitive
34
                }
35
                while ($row = $res->fetch_array()) {
36
                        $tmp[$row['email']] = 1;
37
                }
38
                if (OIDplus::db()->getSlang()->id() == 'mysql') {
39
                        $res = OIDplus::db()->query("select distinct BINARY(ra_email) as ra_email from ###objects");
40
                } else {
41
                        $res = OIDplus::db()->query("select distinct ra_email as ra_email from ###objects");
42
                }
43
                while ($row = $res->fetch_array()) {
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
 
55
        public function gui($id, &$out, &$handled) {
56
                if ($id === 'oidplus:list_ra') {
57
                        $handled = true;
58
                        $out['title'] = _L('RA Listing');
800 daniel-mar 59
                        $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,true).'img/main_icon.png' : '';
635 daniel-mar 60
 
61
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
800 daniel-mar 62
                                $out['icon'] = 'img/error.png';
635 daniel-mar 63
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
64
                                return;
65
                        }
66
 
67
                        $out['text'] = '';
68
 
69
                        $tmp = $this->get_ralist();
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
                        }
75
 
76
                        if (count($tmp) == 0) {
77
                                $out['text'] .= '<p>'._L('Currently there are no Registration Authorities.').'</p>';
78
                        }
79
 
80
                        foreach ($tmp as $ra_email => $registered) {
81
                                if (empty($ra_email)) {
82
                                        $out['text'] .= '<p><b><a '.OIDplus::gui()->link('oidplus:rainfo$').'>'._L('(Objects with undefined RA)').'</a></b></p>';
83
                                } else {
84
                                        if ($registered == 0) {
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>';
86
                                        }
87
                                        if ($registered == 1) {
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>';
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
                                        }
93
                                }
94
                        }
95
                }
96
        }
97
 
98
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
99
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
100
 
800 daniel-mar 101
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
102
                        $tree_icon = OIDplus::webpath(__DIR__,true).'img/main_icon16.png';
635 daniel-mar 103
                } else {
104
                        $tree_icon = null; // default icon (folder)
105
                }
106
 
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,
114
                                        'text' => _L('(Objects with undefined RA)')
115
                                );
116
                        } else {
117
                                if ($registered == 0) {
118
                                        $children[] = array(
119
                                                'id' => 'oidplus:rainfo$'.str_replace('@', '&', $ra_email),
120
                                                'icon' => $tree_icon,
121
                                                'text' => $ra_email.' <i>'._L('(has objects, is not registered)').'</i>'
122
                                        );
123
                                }
124
                                if ($registered == 1) {
125
                                        $children[] = array(
126
                                                'id' => 'oidplus:rainfo$'.$ra_email,
127
                                                'icon' => $tree_icon,
128
                                                'text' => $ra_email.' <i><font color="red">'._L('(has no objects)').'</font></i>'
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
 
141
                $json[] = array(
142
                        'id' => 'oidplus:list_ra',
143
                        'icon' => $tree_icon,
144
                        'text' => _L('List RAs'),
145
                        'children' => $children
146
                );
147
 
148
                return true;
149
        }
150
 
151
        public function tree_search($request) {
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
                /*
155
                if (strpos($request, 'oidplus:rainfo$') === 0) {
156
                        if (OIDplus::authUtils()->isAdminLoggedIn()) {
157
                                return array('oidplus:login', ...dummy..., 'oidplus:list_ra', $request);
158
                        }
159
                }
160
                */
161
                return false;
162
        }
163
}