Subversion Repositories oidplus

Rev

Rev 496 | Rev 595 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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 OIDplusGui {
  23.  
  24.         public static function generateContentPage($id) {
  25.                 $out = array();
  26.  
  27.                 $handled = false;
  28.                 $out['title'] = '';
  29.                 $out['icon'] = '';
  30.                 $out['text'] = '';
  31.  
  32.                 foreach (OIDplus::getPagePlugins() as $plugin) {
  33.                         try {
  34.                                 $plugin->gui($id, $out, $handled);
  35.                         } catch (Exception $e) {
  36.                                 $out['title'] = _L('Error');
  37.                                 $out['icon'] = 'img/error_big.png';
  38.                                 $out['text'] = $e->getMessage();
  39.                         }
  40.                         if ($handled) break;
  41.                 }
  42.  
  43.                 if (!$handled) {
  44.                         $out['title'] = _L('Error');
  45.                         $out['icon'] = 'img/error_big.png';
  46.                         $out['text'] = _L('The resource cannot be found.');
  47.                 }
  48.  
  49.                 return $out;
  50.         }
  51.  
  52.         public static function link($goto, $new_window=false) {
  53.                 if ($new_window) {
  54.                         return 'href="?goto='.urlencode($goto).'" target="_blank"';
  55.                 } else {
  56.                         if (strpos($goto, '#') !== false) {
  57.                                 list($goto, $anchor) = explode('#', $goto, 2);
  58.                                 return 'href="?goto='.urlencode($goto).'#'.htmlentities($anchor).'" onclick="openOidInPanel('.js_escape($goto).', true, '.js_escape($anchor).'); return false;"';
  59.                         } else {
  60.                                 return 'href="?goto='.urlencode($goto).'" onclick="openOidInPanel('.js_escape($goto).', true); return false;"';
  61.                         }
  62.                 }
  63.         }
  64.  
  65.         public static function getLanguageBox($goto, $useJs) {
  66.                 echo '<div id="languageBox">';
  67.                 $langbox_entries = array();
  68.                 $non_default_languages = 0;
  69.                 foreach (OIDplus::getAllPluginManifests('language') as $pluginManifest) {
  70.                         $flag = $pluginManifest->getLanguageFlag();
  71.                         $code = $pluginManifest->getLanguageCode();
  72.                         if ($code != OIDplus::DEFAULT_LANGUAGE) $non_default_languages++;
  73.                         if ($code == OIDplus::getCurrentLang()) {
  74.                                 $class = 'lng_flag';
  75.                         } else {
  76.                                 $class = 'lng_flag picture_ghost';
  77.                         }
  78.                         $add = (!is_null($goto)) ? '&amp;goto='.urlencode($goto) : '';
  79.                         $langbox_entries[$code] = '<span class="lang_flag_bg"><a '.($useJs ? 'onclick="setLanguage(\''.$code.'\'); return false" ' : '').'href="?lang='.$code.$add.'"><img src="'.OIDplus::webpath(null,true).'plugins/language/'.$code.'/'.$flag.'" alt="'.$pluginManifest->getName().'" title="'.$pluginManifest->getName().'" class="'.$class.'" id="lng_flag_'.$code.'" height="20"></a></span> ';
  80.                 }
  81.                 if ($non_default_languages > 0) {
  82.                         foreach ($langbox_entries as $ent) {
  83.                                 echo "$ent\n\t\t";
  84.                         }
  85.                 }
  86.                 echo '</div>';
  87.         }
  88.  
  89.         public static function html_exception_handler($exception) {
  90.                 if ($exception instanceof OIDplusConfigInitializationException) {
  91.                         echo '<!DOCTYPE HTML>';
  92.                         echo '<html><head><title>'._L('OIDplus initialization error').'</title></head><body>';
  93.                         echo '<h1>'._L('OIDplus initialization error').'</h1>';
  94.                         echo '<p>'.htmlentities($exception->getMessage(), ENT_SUBSTITUTE).'</p>';
  95.                         echo '<p>'._L('Please check the file %1','<b>userdata/baseconfig/config.inc.php</b>');
  96.                         if (is_dir(__DIR__ . '/../../setup')) {
  97.                                 echo ' '._L('or run <a href="%1">setup</a> again',OIDplus::webpath().'setup/');
  98.                         }
  99.                         echo '</p>';
  100.                         echo '</body></html>';
  101.                 } else {
  102.                         echo '<!DOCTYPE HTML>';
  103.                         echo '<html><head><title>'._L('OIDplus error').'</title></head><body>';
  104.                         echo '<h1>'._L('OIDplus error').'</h1>';
  105.                         // ENT_SUBSTITUTE because ODBC drivers might return ANSI instead of UTF-8 stuff
  106.                         echo '<p>'.htmlentities($exception->getMessage(), ENT_SUBSTITUTE).'</p>';
  107.                         echo '<p><b>'._L('Technical information about the problem').':</b></p>';
  108.                         echo '<pre>';
  109.                         echo get_class($exception)."\n";
  110.                         var_dump($exception->getFile());
  111.                         var_dump($exception->getLine());
  112.                         echo _L('at file %1 (line %2)',$exception->getFile(),"".$exception->getLine())."\n";
  113.                         echo _L('Stacktrace').":\n";
  114.                         echo $exception->getTraceAsString();
  115.                         echo '</pre>';
  116.                         echo '</body></html>';
  117.                 }
  118.         }
  119.  
  120.         public function tabBarStart() {
  121.                 return '<ul class="nav nav-tabs" id="myTab" role="tablist">';
  122.         }
  123.  
  124.         public function tabBarEnd() {
  125.                 return '</ul>';
  126.         }
  127.  
  128.         public function tabBarElement($id, $title, $active) {
  129.                 return '<li class="nav-item"><a class="nav-link'.($active ? ' active' : '').'" id="'.$id.'-tab" data-toggle="tab" href="#'.$id.'" role="tab" aria-controls="'.$id.'" aria-selected="'.($active ? 'true' : 'false').'">'.$title.'</a></li>';
  130.         }
  131.  
  132.         public function tabContentStart() {
  133.                 return '<div class="tab-content" id="myTabContent">';
  134.         }
  135.  
  136.         public function tabContentEnd() {
  137.                 return '</div>';
  138.         }
  139.  
  140.         public function tabContentPage($id, $content, $active) {
  141.                 return '<div class="tab-pane fade'.($active ? ' show active' : '').'" id="'.$id.'" role="tabpanel" aria-labelledby="'.$id.'-tab">'.$content.'</div>';
  142.         }
  143.  
  144. }
  145.