Subversion Repositories oidplus

Rev

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