Subversion Repositories oidplus

Rev

Rev 1065 | Rev 1068 | 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. namespace ViaThinkSoft\OIDplus;
  21.  
  22. class OIDplusGui extends OIDplusBaseClass {
  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.png';
  38.                                 $out['text'] = $e->getMessage();
  39.                         }
  40.                         if ($handled) break;
  41.                 }
  42.  
  43.                 if (!$handled) {
  44.                         if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box
  45.                                 http_response_code(404);
  46.                         }
  47.                         $out['title'] = _L('Error');
  48.                         $out['icon'] = 'img/error.png';
  49.                         $out['text'] = _L('The resource cannot be found.');
  50.                 }
  51.  
  52.                 return $out;
  53.         }
  54.  
  55.         public static function link($goto, $new_window=false): string {
  56.                 if ($new_window) {
  57.                         return 'href="?goto='.urlencode($goto).'" target="_blank"';
  58.                 } else {
  59.                         if (strpos($goto, '#') !== false) {
  60.                                 list($goto, $anchor) = explode('#', $goto, 2);
  61.                                 return 'href="?goto='.urlencode($goto).'#'.htmlentities($anchor).'" onclick="openOidInPanel('.js_escape($goto).', true, '.js_escape($anchor).'); return false;"';
  62.                         } else {
  63.                                 return 'href="?goto='.urlencode($goto).'" onclick="openOidInPanel('.js_escape($goto).', true); return false;"';
  64.                         }
  65.                 }
  66.         }
  67.  
  68.         public static function getLanguageBox($goto, $useJs) {
  69.                 $out = '';
  70.                 $out .= '<div id="languageBox">';
  71.                 $langbox_entries = array();
  72.                 $non_default_languages = 0;
  73.                 foreach (OIDplus::getAllPluginManifests('language') as $pluginManifest) {
  74.                         $flag = $pluginManifest->getLanguageFlag();
  75.                         $code = $pluginManifest->getLanguageCode();
  76.                         if ($code != OIDplus::getDefaultLang()) $non_default_languages++;
  77.                         if ($code == OIDplus::getCurrentLang()) {
  78.                                 $class = 'lng_flag';
  79.                         } else {
  80.                                 $class = 'lng_flag picture_ghost';
  81.                         }
  82.                         $add = (!is_null($goto)) ? '&amp;goto='.urlencode($goto) : '';
  83.  
  84.                         $dirs = glob(OIDplus::localpath().'plugins/'.'*'.'/language/'.$code.'/');
  85.  
  86.                         if (count($dirs) > 0) {
  87.                                 $dir = substr($dirs[0], strlen(OIDplus::localpath()));
  88.                                 $langbox_entries[$code] = '<span class="lang_flag_bg"><a '.($useJs ? 'onclick="return !setLanguage(\''.$code.'\')" ' : '').'href="?lang='.$code.$add.'"><img src="'.OIDplus::webpath(null,OIDplus::PATH_RELATIVE).$dir.$flag.'" alt="'.$pluginManifest->getName().'" title="'.$pluginManifest->getName().'" class="'.$class.'" id="lng_flag_'.$code.'" height="20"></a></span> ';
  89.                         }
  90.                 }
  91.                 if ($non_default_languages > 0) {
  92.                         foreach ($langbox_entries as $ent) {
  93.                                 $out .= "$ent\n\t\t";
  94.                         }
  95.                 }
  96.                 $out .= '</div>';
  97.                 return $out;
  98.         }
  99.  
  100.         public static function html_exception_handler($exception) {
  101.                 if ($exception instanceof OIDplusConfigInitializationException) {
  102.                         echo '<!DOCTYPE HTML>';
  103.                         echo '<html><head><title>'.htmlentities(_L('OIDplus initialization error')).'</title></head><body>';
  104.                         echo '<h1>'.htmlentities(_L('OIDplus initialization error')).'</h1>';
  105.                         echo '<p>'.htmlentities($exception->getMessage(), ENT_SUBSTITUTE).'</p>';
  106.                         $msg = _L('Please check the file %1','<b>userdata/baseconfig/config.inc.php</b>');
  107.                         if (is_dir(__DIR__ . '/../../setup')) {
  108.                                 $msg .= ' '._L('or run <a href="%1">setup</a> again',OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/');
  109.                         }
  110.                         echo '<p>'.htmlentities($msg).'</p>';
  111.                         echo self::getExceptionTechInfo($exception);
  112.                         echo '</body></html>';
  113.                 } else {
  114.                         echo '<!DOCTYPE HTML>';
  115.                         echo '<html><head><title>'.htmlentities(_L('OIDplus error')).'</title></head><body>';
  116.                         echo '<h1>'.htmlentities(_L('OIDplus error')).'</h1>';
  117.                         // ENT_SUBSTITUTE because ODBC drivers might return ANSI instead of UTF-8 stuff
  118.                         echo '<p>'.htmlentities($exception->getMessage(), ENT_SUBSTITUTE).'</p>';
  119.                         echo self::getExceptionTechInfo($exception);
  120.                         echo '</body></html>';
  121.                 }
  122.         }
  123.  
  124.         private static function getExceptionTechInfo($exception) {
  125.                 $out = '';
  126.                 $out .= '<p><b>'.htmlentities(_L('Technical information about the problem')).':</b></p>';
  127.                 $out .= '<pre>';
  128.                 $out .= get_class($exception)."\n";
  129.                 $out .= _L('at file %1 (line %2)',$exception->getFile(),"".$exception->getLine())."\n\n";
  130.                 $out .= _L('Stacktrace').":\n";
  131.                 $out .= htmlentities($exception->getTraceAsString());
  132.                 $out .= '</pre>';
  133.                 return $out;
  134.         }
  135.  
  136.         public function tabBarStart() {
  137.                 return '<ul class="nav nav-tabs" id="myTab" role="tablist">';
  138.         }
  139.  
  140.         public function tabBarEnd() {
  141.                 return '</ul>';
  142.         }
  143.  
  144.         public function tabBarElement($id, $title, $active) {
  145.                 // data-bs-toggle is for Bootstrap 5
  146.                 // data-toggle is for Bootstrap 4 (InternetExplorer compatibility)
  147.                 return '<li class="nav-item"><a class="nav-link'.($active ? ' active' : '').'" id="'.$id.'-tab" data-bs-toggle="tab" data-toggle="tab" href="#'.$id.'" role="tab" aria-controls="'.$id.'" aria-selected="'.($active ? 'true' : 'false').'">'.$title.'</a></li>';
  148.         }
  149.  
  150.         public function tabContentStart() {
  151.                 return '<div class="tab-content" id="myTabContent">';
  152.         }
  153.  
  154.         public function tabContentEnd() {
  155.                 return '</div>';
  156.         }
  157.  
  158.         public function tabContentPage($id, $content, $active) {
  159.                 return '<div class="tab-pane fade'.($active ? ' show active' : '').'" id="'.$id.'" role="tabpanel" aria-labelledby="'.$id.'-tab">'.$content.'</div>';
  160.         }
  161.  
  162.         public function combine_systemtitle_and_pagetitle($systemtitle, $pagetitle) {
  163.                 // Please also change the function in oidplus_base.js
  164.                 if ($systemtitle == $pagetitle) {
  165.                         return $systemtitle;
  166.                 } else {
  167.                         return $pagetitle . ' - ' . $systemtitle;
  168.                 }
  169.         }
  170.  
  171.         private function getCommonHeadElems($title) {
  172.                 // Get theme color (color of title bar)
  173.                 $design_plugin = OIDplus::getActiveDesignPlugin();
  174.                 $theme_color = is_null($design_plugin) ? '' : $design_plugin->getThemeColor();
  175.  
  176.                 $head_elems = array();
  177.                 $head_elems[] = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
  178.                 if (OIDplus::baseConfig()->getValue('DATABASE_PLUGIN','') !== '') {
  179.                         $head_elems[] = '<meta name="OIDplus-SystemTitle" content="'.htmlentities(OIDplus::config()->getValue('system_title')).'">'; // Do not remove. This meta tag is acessed by oidplus_base.js
  180.                 }
  181.                 if ($theme_color != '') {
  182.                         $head_elems[] = '<meta name="theme-color" content="'.htmlentities($theme_color).'">';
  183.                 }
  184.                 $head_elems[] = '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
  185.                 $head_elems[] = '<title>'.htmlentities($title).'</title>';
  186.                 $head_elems[] = '<script src="'.OIDplus::webpath(null, OIDplus::PATH_RELATIVE).'polyfill.min.js.php"></script>';
  187.                 $head_elems[] = '<script src="'.OIDplus::webpath(null, OIDplus::PATH_RELATIVE).'oidplus.min.js.php?noBaseConfig=1" type="text/javascript"></script>';
  188.                 $head_elems[] = '<link rel="stylesheet" href="'.OIDplus::webpath(null, OIDplus::PATH_RELATIVE).'oidplus.min.css.php?noBaseConfig=1">';
  189.                 $head_elems[] = '<link rel="shortcut icon" type="image/x-icon" href="'.OIDplus::webpath(null, OIDplus::PATH_RELATIVE).'favicon.ico.php">';
  190.                 if (OIDplus::baseConfig()->exists('CANONICAL_SYSTEM_URL')) {
  191.                         $head_elems[] = '<link rel="canonical" href="'.htmlentities(OIDplus::canonicalURL()).OIDplus::webpath(null, OIDplus::PATH_RELATIVE).'">';
  192.                 }
  193.  
  194.                 return $head_elems;
  195.         }
  196.  
  197.         public function showMainPage($page_title_1, $page_title_2, $static_icon, $static_content, $extra_head_tags=array(), $static_node_id='') {
  198.                 $head_elems = $this->getCommonHeadElems($page_title_1);
  199.                 $head_elems = array_merge($head_elems, $extra_head_tags);
  200.  
  201.                 $plugins = OIDplus::getPagePlugins();
  202.                 foreach ($plugins as $plugin) {
  203.                         $plugin->htmlHeaderUpdate($head_elems);
  204.                 }
  205.  
  206.                 # ---
  207.  
  208.                 $out  = "<!DOCTYPE html>\n";
  209.  
  210.                 $out .= "<html lang=\"".substr(OIDplus::getCurrentLang(),0,2)."\">\n";
  211.                 $out .= "<head>\n";
  212.                 $out .= "\t".implode("\n\t",$head_elems)."\n";
  213.                 $out .= "</head>\n";
  214.  
  215.                 $out .= "<body>\n";
  216.  
  217.                 $out .= '<div id="loading" style="display:none">Loading&#8230;</div>';
  218.  
  219.                 $out .= '<div id="frames">';
  220.                 $out .= '<div id="content_window" class="borderbox">';
  221.  
  222.                 $out .= '<h1 id="real_title">';
  223.                 if ($static_icon != '') $out .= '<img src="'.htmlentities($static_icon).'" width="48" height="48" alt=""> ';
  224.                 $out .= htmlentities($page_title_2).'</h1>';
  225.                 $out .= '<div id="real_content">'.$static_content.'</div>';
  226.                 if ((!isset($_SERVER['REQUEST_METHOD'])) || ($_SERVER['REQUEST_METHOD'] == 'GET')) {
  227.                         $out .= '<br><p><img src="img/share.png" width="15" height="15" alt="'._L('Share').'"> <a href="?goto='.htmlentities($static_node_id).'" id="static_link" class="gray_footer_font">'._L('Static link to this page').'</a>';
  228.                         $out .= '</p>';
  229.                 }
  230.                 $out .= '<br>';
  231.  
  232.                 $out .= '</div>';
  233.  
  234.                 $out .= '<div id="system_title_bar">';
  235.  
  236.                 $out .= '<div id="system_title_menu" onclick="mobileNavButtonClick(this)" onmouseenter="mobileNavButtonHover(this)" onmouseleave="mobileNavButtonHover(this)">';
  237.                 $out .= '       <div id="bar1"></div>';
  238.                 $out .= '       <div id="bar2"></div>';
  239.                 $out .= '       <div id="bar3"></div>';
  240.                 $out .= '</div>';
  241.  
  242.                 $out .= '<div id="system_title_text">';
  243.                 $out .= '       <a '.OIDplus::gui()->link('oidplus:system').' id="system_title_a">';
  244.                 $out .= '               <span id="system_title_logo"></span>';
  245.                 $out .= '               <span id="system_title_1">'.htmlentities(OIDplus::getEditionInfo()['vendor'].' OIDplus 2.0').'</span><br>';
  246.                 $out .= '               <span id="system_title_2">'.htmlentities(OIDplus::config()->getValue('system_title')).'</span>';
  247.                 $out .= '       </a>';
  248.                 $out .= '</div>';
  249.  
  250.                 $out .= '</div>';
  251.  
  252.                 $out .= OIDplus::gui()->getLanguageBox($static_node_id, true);
  253.  
  254.                 $out .= '<div id="gotobox">';
  255.                 $out .= '<input type="text" name="goto" id="gotoedit" value="'.htmlentities($static_node_id).'">';
  256.                 $out .= '<input type="button" value="'._L('Go').'" onclick="gotoButtonClicked()" id="gotobutton">';
  257.                 $out .= '</div>';
  258.  
  259.                 $out .= '<div id="oidtree" class="borderbox">';
  260.                 //$out .= '<noscript>';
  261.                 //$out .= '<p><b>'._L('Please enable JavaScript to use all features').'</b></p>';
  262.                 //$out .= '</noscript>';
  263.                 $out .= OIDplus::menuUtils()->nonjs_menu();
  264.                 $out .= '</div>';
  265.  
  266.                 $out .= '</div>';
  267.  
  268.                 $out .= "\n</body>\n";
  269.                 $out .= "</html>\n";
  270.  
  271.                 # ---
  272.  
  273.                 $plugins = OIDplus::getPagePlugins();
  274.                 foreach ($plugins as $plugin) {
  275.                         $plugin->htmlPostprocess($out);
  276.                 }
  277.  
  278.                 return $out;
  279.         }
  280.  
  281.         public function showSimplePage($page_title_1, $page_title_2, $static_icon, $static_content, $extra_head_tags=array()) {
  282.                 $head_elems = $this->getCommonHeadElems($page_title_1);
  283.                 $head_elems = array_merge($head_elems, $extra_head_tags);
  284.  
  285.                 # ---
  286.  
  287.                 $out  = "<!DOCTYPE html>\n";
  288.  
  289.                 $out .= "<html lang=\"".substr(OIDplus::getCurrentLang(),0,2)."\">\n";
  290.                 $out .= "<head>\n";
  291.                 $out .= "\t".implode("\n\t",$head_elems)."\n";
  292.                 $out .= "</head>\n";
  293.  
  294.                 $out .= "<body>\n";
  295.  
  296.                 $out .= '<div id="loading" style="display:none">Loading&#8230;</div>';
  297.  
  298.                 $out .= '<div id="frames">';
  299.                 $out .= '<div id="content_window" class="borderbox">';
  300.  
  301.                 $out .= '<h1 id="real_title">';
  302.                 if ($static_icon != '') $out .= '<img src="'.htmlentities($static_icon).'" width="48" height="48" alt=""> ';
  303.                 $out .= htmlentities($page_title_2).'</h1>';
  304.                 $out .= '<div id="real_content">'.$static_content.'</div>';
  305.                 $out .= '<br>';
  306.  
  307.                 $out .= '</div>';
  308.  
  309.                 $out .= '<div id="system_title_bar">';
  310.  
  311.                 $out .= '<div id="system_title_text">';
  312.                 $out .= '       <span id="system_title_logo"></span>';
  313.                 $out .= '       <span id="system_title_1">'.htmlentities(OIDplus::getEditionInfo()['vendor'].' OIDplus 2.0').'</span><br>';
  314.                 $out .= '       <span id="system_title_2">'.htmlentities($page_title_1).'</span>';
  315.                 $out .= '</div>';
  316.  
  317.                 $out .= '</div>';
  318.  
  319.                 $out .= OIDplus::gui()->getLanguageBox(null, true);
  320.  
  321.                 $out .= '</div>';
  322.  
  323.                 $out .= "\n</body>\n";
  324.                 $out .= "</html>\n";
  325.  
  326.                 # ---
  327.  
  328.                 return $out;
  329.         }
  330.  
  331. }
  332.