Rev 780 | Rev 801 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
596 | daniel-mar | 1 | <?php |
2 | daniel-mar | 2 | |
3 | /* |
||
4 | * OIDplus 2.0 |
||
511 | daniel-mar | 5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
2 | daniel-mar | 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 | |||
511 | daniel-mar | 20 | if (!defined('INSIDE_OIDPLUS')) die(); |
21 | |||
730 | daniel-mar | 22 | class OIDplusGui extends OIDplusBaseClass { |
2 | daniel-mar | 23 | |
24 | public static function generateContentPage($id) { |
||
25 | $out = array(); |
||
26 | |||
27 | $handled = false; |
||
28 | $out['title'] = ''; |
||
32 | daniel-mar | 29 | $out['icon'] = ''; |
2 | daniel-mar | 30 | $out['text'] = ''; |
31 | |||
281 | daniel-mar | 32 | foreach (OIDplus::getPagePlugins() as $plugin) { |
348 | daniel-mar | 33 | try { |
34 | $plugin->gui($id, $out, $handled); |
||
35 | } catch (Exception $e) { |
||
360 | daniel-mar | 36 | $out['title'] = _L('Error'); |
800 | daniel-mar | 37 | $out['icon'] = 'img/error.png'; |
348 | daniel-mar | 38 | $out['text'] = $e->getMessage(); |
39 | } |
||
281 | daniel-mar | 40 | if ($handled) break; |
61 | daniel-mar | 41 | } |
2 | daniel-mar | 42 | |
43 | if (!$handled) { |
||
360 | daniel-mar | 44 | $out['title'] = _L('Error'); |
800 | daniel-mar | 45 | $out['icon'] = 'img/error.png'; |
360 | daniel-mar | 46 | $out['text'] = _L('The resource cannot be found.'); |
2 | daniel-mar | 47 | } |
48 | |||
49 | return $out; |
||
50 | } |
||
250 | daniel-mar | 51 | |
595 | daniel-mar | 52 | public static function link($goto, $new_window=false): string { |
327 | daniel-mar | 53 | if ($new_window) { |
54 | return 'href="?goto='.urlencode($goto).'" target="_blank"'; |
||
250 | daniel-mar | 55 | } else { |
327 | daniel-mar | 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 | } |
||
250 | daniel-mar | 62 | } |
63 | } |
||
362 | daniel-mar | 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) { |
||
389 | daniel-mar | 70 | $flag = $pluginManifest->getLanguageFlag(); |
71 | $code = $pluginManifest->getLanguageCode(); |
||
362 | daniel-mar | 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)) ? '&goto='.urlencode($goto) : ''; |
||
632 | daniel-mar | 79 | |
635 | daniel-mar | 80 | $dirs = glob(OIDplus::localpath().'plugins/'.'*'.'/language/'.$code.'/'); |
632 | daniel-mar | 81 | |
82 | if (count($dirs) > 0) { |
||
83 | $dir = substr($dirs[0], strlen(OIDplus::localpath())); |
||
721 | daniel-mar | 84 | $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).$dir.$flag.'" alt="'.$pluginManifest->getName().'" title="'.$pluginManifest->getName().'" class="'.$class.'" id="lng_flag_'.$code.'" height="20"></a></span> '; |
632 | daniel-mar | 85 | } |
362 | daniel-mar | 86 | } |
87 | if ($non_default_languages > 0) { |
||
426 | daniel-mar | 88 | foreach ($langbox_entries as $ent) { |
89 | echo "$ent\n\t\t"; |
||
90 | } |
||
362 | daniel-mar | 91 | } |
92 | echo '</div>'; |
||
93 | } |
||
366 | daniel-mar | 94 | |
95 | public static function html_exception_handler($exception) { |
||
96 | if ($exception instanceof OIDplusConfigInitializationException) { |
||
463 | daniel-mar | 97 | echo '<!DOCTYPE HTML>'; |
98 | echo '<html><head><title>'._L('OIDplus initialization error').'</title></head><body>'; |
||
366 | daniel-mar | 99 | echo '<h1>'._L('OIDplus initialization error').'</h1>'; |
100 | echo '<p>'.htmlentities($exception->getMessage(), ENT_SUBSTITUTE).'</p>'; |
||
101 | echo '<p>'._L('Please check the file %1','<b>userdata/baseconfig/config.inc.php</b>'); |
||
102 | if (is_dir(__DIR__ . '/../../setup')) { |
||
496 | daniel-mar | 103 | echo ' '._L('or run <a href="%1">setup</a> again',OIDplus::webpath().'setup/'); |
366 | daniel-mar | 104 | } |
105 | echo '</p>'; |
||
780 | daniel-mar | 106 | echo self::getExceptionTechInfo($exception); |
463 | daniel-mar | 107 | echo '</body></html>'; |
366 | daniel-mar | 108 | } else { |
463 | daniel-mar | 109 | echo '<!DOCTYPE HTML>'; |
110 | echo '<html><head><title>'._L('OIDplus error').'</title></head><body>'; |
||
366 | daniel-mar | 111 | echo '<h1>'._L('OIDplus error').'</h1>'; |
112 | // ENT_SUBSTITUTE because ODBC drivers might return ANSI instead of UTF-8 stuff |
||
113 | echo '<p>'.htmlentities($exception->getMessage(), ENT_SUBSTITUTE).'</p>'; |
||
780 | daniel-mar | 114 | echo self::getExceptionTechInfo($exception); |
463 | daniel-mar | 115 | echo '</body></html>'; |
366 | daniel-mar | 116 | } |
117 | } |
||
420 | daniel-mar | 118 | |
780 | daniel-mar | 119 | private static function getExceptionTechInfo($exception) { |
120 | $out = ''; |
||
121 | $out .= '<p><b>'._L('Technical information about the problem').':</b></p>'; |
||
122 | $out .= '<pre>'; |
||
123 | $out .= get_class($exception)."\n"; |
||
124 | $out .= _L('at file %1 (line %2)',$exception->getFile(),"".$exception->getLine())."\n\n"; |
||
125 | $out .= _L('Stacktrace').":\n"; |
||
126 | $out .= $exception->getTraceAsString(); |
||
127 | $out .= '</pre>'; |
||
128 | return $out; |
||
129 | } |
||
130 | |||
420 | daniel-mar | 131 | public function tabBarStart() { |
132 | return '<ul class="nav nav-tabs" id="myTab" role="tablist">'; |
||
133 | } |
||
134 | |||
135 | public function tabBarEnd() { |
||
136 | return '</ul>'; |
||
137 | } |
||
138 | |||
139 | public function tabBarElement($id, $title, $active) { |
||
641 | daniel-mar | 140 | // data-bs-toggle is for Bootstrap 5 |
141 | // data-toggle is for Bootstrap 4 (InternetExplorer compatibility) |
||
142 | 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>'; |
||
420 | daniel-mar | 143 | } |
144 | |||
145 | public function tabContentStart() { |
||
146 | return '<div class="tab-content" id="myTabContent">'; |
||
147 | } |
||
148 | |||
149 | public function tabContentEnd() { |
||
150 | return '</div>'; |
||
151 | } |
||
152 | |||
153 | public function tabContentPage($id, $content, $active) { |
||
154 | return '<div class="tab-pane fade'.($active ? ' show active' : '').'" id="'.$id.'" role="tabpanel" aria-labelledby="'.$id.'-tab">'.$content.'</div>'; |
||
155 | } |
||
156 | |||
366 | daniel-mar | 157 | } |