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