Subversion Repositories oidplus

Rev

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