Subversion Repositories oidplus

Rev

Rev 1055 | Rev 1060 | 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
 
1050 daniel-mar 20
namespace ViaThinkSoft\OIDplus;
511 daniel-mar 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);
1050 daniel-mar 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) {
936 daniel-mar 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
                        }
360 daniel-mar 47
                        $out['title'] = _L('Error');
800 daniel-mar 48
                        $out['icon'] = 'img/error.png';
360 daniel-mar 49
                        $out['text'] = _L('The resource cannot be found.');
2 daniel-mar 50
                }
51
 
52
                return $out;
53
        }
250 daniel-mar 54
 
595 daniel-mar 55
        public static function link($goto, $new_window=false): string {
327 daniel-mar 56
                if ($new_window) {
57
                        return 'href="?goto='.urlencode($goto).'" target="_blank"';
250 daniel-mar 58
                } else {
327 daniel-mar 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
                        }
250 daniel-mar 65
                }
66
        }
362 daniel-mar 67
 
68
        public static function getLanguageBox($goto, $useJs) {
1056 daniel-mar 69
                $out = '';
70
                $out .= '<div id="languageBox">';
362 daniel-mar 71
                $langbox_entries = array();
72
                $non_default_languages = 0;
73
                foreach (OIDplus::getAllPluginManifests('language') as $pluginManifest) {
389 daniel-mar 74
                        $flag = $pluginManifest->getLanguageFlag();
75
                        $code = $pluginManifest->getLanguageCode();
1041 daniel-mar 76
                        if ($code != OIDplus::getDefaultLang()) $non_default_languages++;
362 daniel-mar 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) : '';
632 daniel-mar 83
 
635 daniel-mar 84
                        $dirs = glob(OIDplus::localpath().'plugins/'.'*'.'/language/'.$code.'/');
632 daniel-mar 85
 
86
                        if (count($dirs) > 0) {
87
                                $dir = substr($dirs[0], strlen(OIDplus::localpath()));
801 daniel-mar 88
                                $langbox_entries[$code] = '<span class="lang_flag_bg"><a '.($useJs ? 'onclick="setLanguage(\''.$code.'\'); return false" ' : '').'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> ';
632 daniel-mar 89
                        }
362 daniel-mar 90
                }
91
                if ($non_default_languages > 0) {
426 daniel-mar 92
                        foreach ($langbox_entries as $ent) {
1056 daniel-mar 93
                                $out .= "$ent\n\t\t";
426 daniel-mar 94
                        }
362 daniel-mar 95
                }
1056 daniel-mar 96
                $out .= '</div>';
97
                return $out;
362 daniel-mar 98
        }
366 daniel-mar 99
 
100
        public static function html_exception_handler($exception) {
101
                if ($exception instanceof OIDplusConfigInitializationException) {
463 daniel-mar 102
                        echo '<!DOCTYPE HTML>';
1056 daniel-mar 103
                        echo '<html><head><title>'.htmlentities(_L('OIDplus initialization error')).'</title></head><body>';
104
                        echo '<h1>'.htmlentities(_L('OIDplus initialization error')).'</h1>';
366 daniel-mar 105
                        echo '<p>'.htmlentities($exception->getMessage(), ENT_SUBSTITUTE).'</p>';
1056 daniel-mar 106
                        $msg = _L('Please check the file %1','<b>userdata/baseconfig/config.inc.php</b>');
366 daniel-mar 107
                        if (is_dir(__DIR__ . '/../../setup')) {
1056 daniel-mar 108
                                $msg .= ' '._L('or run <a href="%1">setup</a> again',OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/');
366 daniel-mar 109
                        }
1056 daniel-mar 110
                        echo '<p>'.htmlentities($msg).'</p>';
780 daniel-mar 111
                        echo self::getExceptionTechInfo($exception);
463 daniel-mar 112
                        echo '</body></html>';
366 daniel-mar 113
                } else {
463 daniel-mar 114
                        echo '<!DOCTYPE HTML>';
1056 daniel-mar 115
                        echo '<html><head><title>'.htmlentities(_L('OIDplus error')).'</title></head><body>';
116
                        echo '<h1>'.htmlentities(_L('OIDplus error')).'</h1>';
366 daniel-mar 117
                        // ENT_SUBSTITUTE because ODBC drivers might return ANSI instead of UTF-8 stuff
118
                        echo '<p>'.htmlentities($exception->getMessage(), ENT_SUBSTITUTE).'</p>';
780 daniel-mar 119
                        echo self::getExceptionTechInfo($exception);
463 daniel-mar 120
                        echo '</body></html>';
366 daniel-mar 121
                }
122
        }
420 daniel-mar 123
 
780 daniel-mar 124
        private static function getExceptionTechInfo($exception) {
125
                $out = '';
1056 daniel-mar 126
                $out .= '<p><b>'.htmlentities(_L('Technical information about the problem')).':</b></p>';
780 daniel-mar 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";
922 daniel-mar 131
                $out .= htmlentities($exception->getTraceAsString());
780 daniel-mar 132
                $out .= '</pre>';
133
                return $out;
134
        }
135
 
420 daniel-mar 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) {
641 daniel-mar 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>';
420 daniel-mar 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
 
1055 daniel-mar 162
        // TODO: Modify this method so that also the real index.php (With menu) can be called here
163
        public function showSimplePage($page_title_1, $page_title_2, $static_icon, $static_content, $extra_head_tags='') {
1056 daniel-mar 164
                $out = '';
1055 daniel-mar 165
 
1056 daniel-mar 166
                $out .= '<!DOCTYPE html>';
167
                $out .= '<html lang="'.substr(OIDplus::getCurrentLang(),0,2).'">';
1055 daniel-mar 168
 
1056 daniel-mar 169
                $out .= '<head>';
170
                $out .= '       <title>'.htmlentities($page_title_1).'</title>';
171
                $out .= '       <meta name="viewport" content="width=device-width, initial-scale=1.0">';
172
                $out .= '       <link rel="stylesheet" href="'.OIDplus::webpath(null, true).'oidplus.min.css.php?noBaseConfig=1">';
173
                $out .= '       <script src="'.OIDplus::webpath(null, true).'oidplus.min.js.php?noBaseConfig=1" type="text/javascript"></script>';
174
                $out .= '       <link rel="shortcut icon" type="image/x-icon" href="'.OIDplus::webpath(null, true).'favicon.ico.php">';
175
                $out .= '       '.implode("\n\t",$extra_head_tags)."\n";
176
                $out .= '</head>';
1055 daniel-mar 177
 
1056 daniel-mar 178
                $out .= '<body>';
1055 daniel-mar 179
 
1056 daniel-mar 180
                $out .= '<div id="loading" style="display:none">Loading&#8230;</div>';
1055 daniel-mar 181
 
1056 daniel-mar 182
                $out .= '<div id="frames">';
183
                $out .= '<div id="content_window" class="borderbox">';
1055 daniel-mar 184
 
1056 daniel-mar 185
                $out .= '<h1 id="real_title">';
186
                if ($static_icon != '') $out .= '<img src="'.htmlentities($static_icon).'" width="48" height="48" alt=""> ';
187
                $out .= htmlentities($page_title_2).'</h1>';
188
                $out .= '<div id="real_content">'.$static_content.'</div>';
189
                $out .= '<br>';
1055 daniel-mar 190
 
1056 daniel-mar 191
                $out .= '</div>';
1055 daniel-mar 192
 
1056 daniel-mar 193
                $out .= '<div id="system_title_bar">';
1055 daniel-mar 194
 
1056 daniel-mar 195
                $out .= '<div id="system_title_text">';
196
                $out .= '       <span id="system_title_logo"></span>';
197
                $out .= '       <span id="system_title_1">'.htmlentities(OIDplus::getEditionInfo()['vendor'].' OIDplus 2.0').'</span><br>';
198
                $out .= '       <span id="system_title_2">'.htmlentities($page_title_1).'</span>';
199
                $out .= '</div>';
1055 daniel-mar 200
 
1056 daniel-mar 201
                $out .= '</div>';
1055 daniel-mar 202
 
1056 daniel-mar 203
                $out .= OIDplus::gui()->getLanguageBox(null, true);
1055 daniel-mar 204
 
1056 daniel-mar 205
                $out .= '</div>';
206
 
207
                $out .= '</body>';
208
                $out .= '</html>';
209
 
210
                return $out;
1055 daniel-mar 211
        }
212
 
366 daniel-mar 213
}