Subversion Repositories oidplus

Rev

Rev 632 | Rev 641 | 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
 
2 daniel-mar 22
class OIDplusGui {
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');
348 daniel-mar 37
                                $out['icon'] = 'img/error_big.png';
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');
256 daniel-mar 45
                        $out['icon'] = 'img/error_big.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)) ? '&amp;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()));
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> ';
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>';
463 daniel-mar 106
                        echo '</body></html>';
366 daniel-mar 107
                } else {
463 daniel-mar 108
                        echo '<!DOCTYPE HTML>';
109
                        echo '<html><head><title>'._L('OIDplus error').'</title></head><body>';
366 daniel-mar 110
                        echo '<h1>'._L('OIDplus error').'</h1>';
111
                        // ENT_SUBSTITUTE because ODBC drivers might return ANSI instead of UTF-8 stuff
112
                        echo '<p>'.htmlentities($exception->getMessage(), ENT_SUBSTITUTE).'</p>';
113
                        echo '<p><b>'._L('Technical information about the problem').':</b></p>';
114
                        echo '<pre>';
115
                        echo get_class($exception)."\n";
116
                        var_dump($exception->getFile());
117
                        var_dump($exception->getLine());
118
                        echo _L('at file %1 (line %2)',$exception->getFile(),"".$exception->getLine())."\n";
119
                        echo _L('Stacktrace').":\n";
120
                        echo $exception->getTraceAsString();
121
                        echo '</pre>';
463 daniel-mar 122
                        echo '</body></html>';
366 daniel-mar 123
                }
124
        }
420 daniel-mar 125
 
126
        public function tabBarStart() {
127
                return '<ul class="nav nav-tabs" id="myTab" role="tablist">';
128
        }
129
 
130
        public function tabBarEnd() {
131
                return '</ul>';
132
        }
133
 
134
        public function tabBarElement($id, $title, $active) {
597 daniel-mar 135
                return '<li class="nav-item"><a class="nav-link'.($active ? ' active' : '').'" id="'.$id.'-tab" data-bs-toggle="tab" href="#'.$id.'" role="tab" aria-controls="'.$id.'" aria-selected="'.($active ? 'true' : 'false').'">'.$title.'</a></li>';
420 daniel-mar 136
        }
137
 
138
        public function tabContentStart() {
139
                return '<div class="tab-content" id="myTabContent">';
140
        }
141
 
142
        public function tabContentEnd() {
143
                return '</div>';
144
        }
145
 
146
        public function tabContentPage($id, $content, $active) {
147
                return '<div class="tab-pane fade'.($active ? ' show active' : '').'" id="'.$id.'" role="tabpanel" aria-labelledby="'.$id.'-tab">'.$content.'</div>';
148
        }
149
 
366 daniel-mar 150
}