Subversion Repositories oidplus

Rev

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

Rev Author Line No. Line
2 daniel-mar 1
<?php
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
 
327 daniel-mar 52
        public static function link($goto, $new_window=false) {
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) : '';
496 daniel-mar 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> ';
362 daniel-mar 80
                }
81
                if ($non_default_languages > 0) {
426 daniel-mar 82
                        foreach ($langbox_entries as $ent) {
83
                                echo "$ent\n\t\t";
84
                        }
362 daniel-mar 85
                }
86
                echo '</div>';
87
        }
366 daniel-mar 88
 
89
        public static function html_exception_handler($exception) {
90
                if ($exception instanceof OIDplusConfigInitializationException) {
463 daniel-mar 91
                        echo '<!DOCTYPE HTML>';
92
                        echo '<html><head><title>'._L('OIDplus initialization error').'</title></head><body>';
366 daniel-mar 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')) {
496 daniel-mar 97
                                echo ' '._L('or run <a href="%1">setup</a> again',OIDplus::webpath().'setup/');
366 daniel-mar 98
                        }
99
                        echo '</p>';
463 daniel-mar 100
                        echo '</body></html>';
366 daniel-mar 101
                } else {
463 daniel-mar 102
                        echo '<!DOCTYPE HTML>';
103
                        echo '<html><head><title>'._L('OIDplus error').'</title></head><body>';
366 daniel-mar 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>';
463 daniel-mar 116
                        echo '</body></html>';
366 daniel-mar 117
                }
118
        }
420 daniel-mar 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
 
366 daniel-mar 144
}