Subversion Repositories oidplus

Rev

Rev 321 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  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.  
  20. class OIDplusPageAdminListRAs extends OIDplusPagePluginAdmin {
  21.  
  22.         public function init($html=true) {
  23.                 // Nothing
  24.         }
  25.  
  26.         private function get_ralist() {
  27.                 $tmp = array();
  28.                 if (OIDplus::db()->getSlang()::id() == 'mysql') {
  29.                         $res = OIDplus::db()->query("select distinct BINARY(email) as email from ###ra"); // "binary" because we want to ensure that 'distinct' is case sensitive
  30.                 } else {
  31.                         $res = OIDplus::db()->query("select distinct email as email from ###ra"); // distinct in PGSQL is always case sensitive
  32.                 }
  33.                 while ($row = $res->fetch_array()) {
  34.                         $tmp[$row['email']] = 1;
  35.                 }
  36.                 if (OIDplus::db()->getSlang()::id() == 'mysql') {
  37.                         $res = OIDplus::db()->query("select distinct BINARY(ra_email) as ra_email from ###objects");
  38.                 } else {
  39.                         $res = OIDplus::db()->query("select distinct ra_email as ra_email from ###objects");
  40.                 }
  41.                 while ($row = $res->fetch_array()) {
  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.  
  53.         public function gui($id, &$out, &$handled) {
  54.                 if ($id === 'oidplus:list_ra') {
  55.                         $handled = true;
  56.                         $out['title'] = _L('RA Listing');
  57.                         $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
  58.  
  59.                         if (!OIDplus::authUtils()::isAdminLoggedIn()) {
  60.                                 $out['icon'] = 'img/error_big.png';
  61.                                 $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login')).'</p>';
  62.                                 return;
  63.                         }
  64.  
  65.                         $out['text'] = '';
  66.  
  67.                         $tmp = $this->get_ralist();
  68.  
  69.                         if (count($tmp) == 0) {
  70.                                 $out['text'] .= '<p>'._L('Currently there are no Registration Authorities.').'</p>';
  71.                         }
  72.  
  73.                         foreach ($tmp as $ra_email => $registered) {
  74.                                 if (empty($ra_email)) {
  75.                                         $out['text'] .= '<p><b><a '.OIDplus::gui()->link('oidplus:rainfo$').'>'._L('(Objects with undefined RA)').'</a></b></p>';
  76.                                 } else {
  77.                                         if ($registered == 0) {
  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>';
  79.                                         }
  80.                                         if ($registered == 1) {
  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>';
  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.                                         }
  86.                                 }
  87.                         }
  88.                 }
  89.         }
  90.  
  91.         public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
  92.                 if (!OIDplus::authUtils()::isAdminLoggedIn()) return false;
  93.  
  94.                 if (file_exists(__DIR__.'/treeicon.png')) {
  95.                         $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
  96.                 } else {
  97.                         $tree_icon = null; // default icon (folder)
  98.                 }
  99.  
  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,
  107.                                         'text' => _L('(Objects with undefined RA)')
  108.                                 );
  109.                         } else {
  110.                                 if ($registered == 0) {
  111.                                         $children[] = array(
  112.                                                 'id' => 'oidplus:rainfo$'.str_replace('@', '&', $ra_email),
  113.                                                 'icon' => $tree_icon,
  114.                                                 'text' => $ra_email.' <i>'._L('(has objects, is not registered)').'</i>'
  115.                                         );
  116.                                 }
  117.                                 if ($registered == 1) {
  118.                                         $children[] = array(
  119.                                                 'id' => 'oidplus:rainfo$'.$ra_email,
  120.                                                 'icon' => $tree_icon,
  121.                                                 'text' => $ra_email.' <i><font color="red">'._L('(has no objects)').'</font></i>'
  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.  
  134.                 $json[] = array(
  135.                         'id' => 'oidplus:list_ra',
  136.                         'icon' => $tree_icon,
  137.                         'text' => _L('List RAs'),
  138.                         'children' => $children
  139.                 );
  140.  
  141.                 return true;
  142.         }
  143.  
  144.         public function tree_search($request) {
  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.                 /*
  148.                 if (strpos($request, 'oidplus:rainfo$') === 0) {
  149.                         if (OIDplus::authUtils()::isAdminLoggedIn()) {
  150.                                 return array('oidplus:login', ...dummy..., 'oidplus:list_ra', $request);
  151.                         }
  152.                 }
  153.                 */
  154.                 return false;
  155.         }
  156. }