-
Notifications
You must be signed in to change notification settings - Fork 136
/
index.php
576 lines (485 loc) · 23.6 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
<?php
/*
* LMS version 1.11-git
*
* (C) Copyright 2001-2022 LMS Developers
*
* Please, see the doc/AUTHORS for more information about authors!
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
* $Id$
*/
// PLEASE DO NOT MODIFY ANYTHING BELOW THIS LINE UNLESS YOU KNOW
// *EXACTLY* WHAT ARE YOU DOING!!!
// *******************************************************************
if (!isset($_SERVER['HTTP_HOST'])) {
$_SERVER['HTTP_HOST'] = '';
}
define('START_TIME', microtime(true));
define('LMS-UI', true);
define('K_TCPDF_EXTERNAL_CONFIG', true);
define('K_TCPDF_CALLS_IN_HTML', true);
ini_set('error_reporting', E_ALL & ~E_NOTICE);
$CONFIG_FILE = DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'lms' . DIRECTORY_SEPARATOR . 'lms.ini';
// find alternative config files:
if (is_readable('lms.ini')) {
$CONFIG_FILE = 'lms.ini';
} elseif (is_readable(DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'lms' . DIRECTORY_SEPARATOR . 'lms-' . $_SERVER['HTTP_HOST'] . ':' . $_SERVER['SERVER_PORT'] . '.ini')) {
$CONFIG_FILE = DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'lms' . DIRECTORY_SEPARATOR . 'lms-' . $_SERVER['HTTP_HOST'] . ':' . $_SERVER['SERVER_PORT'] . '.ini';
} elseif (is_readable(DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'lms' . DIRECTORY_SEPARATOR . 'lms-' . $_SERVER['HTTP_HOST'] . '.ini')) {
$CONFIG_FILE = DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'lms' . DIRECTORY_SEPARATOR . 'lms-' . $_SERVER['HTTP_HOST'] . '.ini';
} elseif (!is_readable($CONFIG_FILE)) {
die('Unable to read configuration file [' . $CONFIG_FILE . ']!');
}
define('CONFIG_FILE', $CONFIG_FILE);
$CONFIG = (array) parse_ini_file(CONFIG_FILE, true);
// Check for configuration vars and set default values
$CONFIG['directories']['sys_dir'] = (!isset($CONFIG['directories']['sys_dir']) ? getcwd() : $CONFIG['directories']['sys_dir']);
$CONFIG['directories']['lib_dir'] = (!isset($CONFIG['directories']['lib_dir']) ? $CONFIG['directories']['sys_dir'] . DIRECTORY_SEPARATOR . 'lib' : $CONFIG['directories']['lib_dir']);
$CONFIG['directories']['doc_dir'] = (!isset($CONFIG['directories']['doc_dir']) ? $CONFIG['directories']['sys_dir'] . DIRECTORY_SEPARATOR . 'documents' : $CONFIG['directories']['doc_dir']);
$CONFIG['directories']['modules_dir'] = (!isset($CONFIG['directories']['modules_dir']) ? $CONFIG['directories']['sys_dir'] . DIRECTORY_SEPARATOR . 'modules' : $CONFIG['directories']['modules_dir']);
$CONFIG['directories']['backup_dir'] = (!isset($CONFIG['directories']['backup_dir']) ? $CONFIG['directories']['sys_dir'] . DIRECTORY_SEPARATOR . 'backups' : $CONFIG['directories']['backup_dir']);
$CONFIG['directories']['storage_dir'] = (!isset($CONFIG['directories']['storage_dir']) ? $CONFIG['directories']['sys_dir'] . DIRECTORY_SEPARATOR . 'storage' : $CONFIG['directories']['storage_dir']);
$CONFIG['directories']['config_templates_dir'] = (!isset($CONFIG['directories']['config_templates_dir']) ? $CONFIG['directories']['sys_dir'] . DIRECTORY_SEPARATOR . 'config_templates' : $CONFIG['directories']['config_templates_dir']);
$CONFIG['directories']['smarty_compile_dir'] = (!isset($CONFIG['directories']['smarty_compile_dir']) ? $CONFIG['directories']['sys_dir'] . DIRECTORY_SEPARATOR . 'templates_c' : $CONFIG['directories']['smarty_compile_dir']);
$CONFIG['directories']['smarty_templates_dir'] = (!isset($CONFIG['directories']['smarty_templates_dir']) ? $CONFIG['directories']['sys_dir'] . DIRECTORY_SEPARATOR . 'templates' : $CONFIG['directories']['smarty_templates_dir']);
$CONFIG['directories']['plugin_dir'] = (!isset($CONFIG['directories']['plugin_dir']) ? $CONFIG['directories']['sys_dir'] . DIRECTORY_SEPARATOR . 'plugins' : $CONFIG['directories']['plugin_dir']);
$CONFIG['directories']['plugins_dir'] = $CONFIG['directories']['plugin_dir'];
$CONFIG['directories']['vendor_dir'] = (!isset($CONFIG['directories']['vendor_dir']) ? $CONFIG['directories']['sys_dir'] . DIRECTORY_SEPARATOR . 'vendor' : $CONFIG['directories']['vendor_dir']);
$CONFIG['directories']['cache_dir'] = (!isset($CONFIG['directories']['cache_dir']) ? $CONFIG['directories']['sys_dir'] . DIRECTORY_SEPARATOR . 'cache' : $CONFIG['directories']['cache_dir']);
define('SYS_DIR', $CONFIG['directories']['sys_dir']);
define('LIB_DIR', $CONFIG['directories']['lib_dir']);
define('DOC_DIR', $CONFIG['directories']['doc_dir']);
define('BACKUP_DIR', $CONFIG['directories']['backup_dir']);
define('STORAGE_DIR', $CONFIG['directories']['storage_dir']);
define('MODULES_DIR', $CONFIG['directories']['modules_dir']);
define('SMARTY_COMPILE_DIR', $CONFIG['directories']['smarty_compile_dir']);
define('SMARTY_TEMPLATES_DIR', $CONFIG['directories']['smarty_templates_dir']);
define('PLUGIN_DIR', $CONFIG['directories']['plugin_dir']);
define('PLUGINS_DIR', $CONFIG['directories']['plugin_dir']);
define('VENDOR_DIR', $CONFIG['directories']['vendor_dir']);
define('CACHE_DIR', $CONFIG['directories']['cache_dir']);
// Load autoloader
$composer_autoload_path = VENDOR_DIR . DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($composer_autoload_path)) {
require_once $composer_autoload_path;
} else {
die("Composer autoload not found. Run 'composer install' command from LMS directory and try again. More information at https://getcomposer.org/");
}
// Do some checks and load config defaults
require_once(LIB_DIR . DIRECTORY_SEPARATOR . 'checkdirs.php');
require_once(LIB_DIR . DIRECTORY_SEPARATOR . 'common.php');
// Init database
$DB = null;
try {
$DB = LMSDB::getInstance();
} catch (Exception $ex) {
trigger_error($ex->getMessage(), E_USER_WARNING);
// can't work without database
die("Fatal error: cannot connect to database!<BR>");
}
$api = isset($_GET['api']);
if (!$api) {
// Call any of upgrade process before anything else
$layout['dbschversion'] = $DB->UpgradeDb();
$db_upgrade_errors = $DB->getUpgradeErrors();
if (!empty($db_upgrade_errors)) {
die(
"Launch 'devel/upgradedb.php' script from your installation directory (recommended)"
. " or add 'database.auto_update' configuration variable with value 'true' to lms.ini file (not recommended)<br>"
);
}
}
// Redirect to SSL
$_FORCE_SSL = ConfigHelper::checkConfig('phpui.force_ssl');
if ($_FORCE_SSL && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit(0);
}
// Include required files (including sequence is important)
$_SERVER['REMOTE_ADDR'] = str_replace("::ffff:", "", $_SERVER['REMOTE_ADDR']);
require_once(LIB_DIR . DIRECTORY_SEPARATOR . 'language.php');
if (!$api) {
// Initialize templates engine (must be before locale settings)
$SMARTY = new LMSSmarty;
// test for proper version of Smarty
if (defined('Smarty::SMARTY_VERSION')) {
$ver_chunks = preg_split('/[- ]/', preg_replace('/^smarty-/i', '', Smarty::SMARTY_VERSION), -1, PREG_SPLIT_NO_EMPTY);
} else {
$ver_chunks = null;
}
if (count($ver_chunks) < 1 || version_compare('3.1', $ver_chunks[0]) > 0) {
die('<B>Wrong version of Smarty engine! We support only Smarty-3.x greater than 3.1.</B>');
}
define('SMARTY_VERSION', $ver_chunks[0]);
$SMARTY->setMergeCompiledIncludes(true);
$SMARTY->setDefaultResourceType('extendsall');
// uncomment this line if you're not gonna change template files no more
//$SMARTY->compile_check = false;
}
require_once(LIB_DIR . DIRECTORY_SEPARATOR . 'definitions.php');
require_once(LIB_DIR . DIRECTORY_SEPARATOR . 'checkip.php');
require_once(LIB_DIR . DIRECTORY_SEPARATOR . 'accesstable.php');
$SYSLOG = SYSLOG::getInstance();
// Initialize Session, Auth and LMS classes
$SESSION = new Session(
$DB,
ConfigHelper::getConfig('phpui.timeout'),
ConfigHelper::getConfig('phpui.settings_timeout')
);
// new browser tab can be opened as hidden or tabid of new tab can be not initialised
// so we have to be careful and handle 'backto' session variable in special way and
// correct this variable when new tab id has been determined before the moment
if (isset($_GET['old_tab_id'], $_GET['tab_id'], $_POST['old_history_entry'], $_POST['history_entry'])
&& preg_match('/^[0-9]+$/', $_GET['old_tab_id'])
&& preg_match('/^[0-9]+$/', $_GET['tab_id'])) {
$SESSION->historyQuirks(array(
'old_tab_id' => $_GET['old_tab_id'],
'old_history_entry' => $_POST['old_history_entry'] ?? null,
'tab_id' => $_GET['tab_id'],
'history_entry' => $_POST['history_entry'] ?? null,
));
//$SESSION->close();
header('Content-Type: application/json');
die('[]');
}
$AUTH = new Auth($DB, $SESSION);
$LMS = new LMS($DB, $AUTH, $SYSLOG);
Localisation::initDefaultCurrency();
$plugin_manager = new LMSPluginManager();
$LMS->setPluginManager($plugin_manager);
if (!$api) {
$SMARTY->setPluginManager($plugin_manager);
// Set some template and layout variables
$SMARTY->setTemplateDir(null);
$custom_templates_dir = ConfigHelper::getConfig('phpui.custom_templates_dir');
if (!empty($custom_templates_dir) && file_exists(SMARTY_TEMPLATES_DIR . DIRECTORY_SEPARATOR . $custom_templates_dir)
&& !is_file(SMARTY_TEMPLATES_DIR . DIRECTORY_SEPARATOR . $custom_templates_dir)) {
$SMARTY->AddTemplateDir(SMARTY_TEMPLATES_DIR . DIRECTORY_SEPARATOR . $custom_templates_dir);
}
$SMARTY->AddTemplateDir(
array(
SMARTY_TEMPLATES_DIR . DIRECTORY_SEPARATOR . 'default',
SMARTY_TEMPLATES_DIR,
)
);
$SMARTY->setCompileDir(SMARTY_COMPILE_DIR);
$SMARTY->debugging = ConfigHelper::checkConfig('phpui.smarty_debug');
$layout['smarty_version'] = SMARTY_VERSION;
}
$layout['logname'] = $AUTH->logname;
$layout['logid'] = Auth::GetCurrentUser();
$layout['lmsdbv'] = $DB->GetVersion();
$layout['hostname'] = hostname();
$layout['lmsv'] = LMS::SOFTWARE_VERSION;
$layout['lmsvr'] = LMS::getSoftwareRevision();
$layout['dberrors'] = &$DB->GetErrors();
$layout['dbdebug'] = $_DBDEBUG ?? false;
$layout['popup'] = isset($_GET['popup']);
$layout['url'] = 'http' . (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '') . '://'
. $_SERVER['HTTP_HOST']
. substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/') + 1);
if (!$api) {
$SMARTY->assignByRef('layout', $layout);
}
$error = null; // initialize error variable needed for (almost) all modules
$warning = null; // initialize warning variable needed for (almost) all modules
// Load menu
if (!$layout['popup'] && !$api) {
require_once(LIB_DIR . DIRECTORY_SEPARATOR . 'menu.php');
$menu = $plugin_manager->executeHook('menu_initialized', $menu);
$SMARTY->assignByRef('newmenu', $menu);
}
header('X-Powered-By: LMS/'.$layout['lmsv']);
$modules_dirs = array(MODULES_DIR);
$modules_dirs = $plugin_manager->executeHook('modules_dir_initialized', $modules_dirs);
$plugin_manager->executeHook('lms_initialized', $LMS);
if (!$api) {
$plugin_manager->executeHook('smarty_initialized', $SMARTY);
}
$documents_dirs = array(DOC_DIR);
$documents_dirs = $plugin_manager->executeHook('documents_dir_initialized', $documents_dirs);
// Check privileges and execute modules
if ($AUTH->islogged) {
if (isset($_GET['clear_login_timeout'])) {
$SESSION->clearLoginTimeout();
header('Content-Type: application/json');
die('[]');
}
$qs_properties = $SESSION->get_persistent_setting('qs-properties');
if (empty($qs_properties)) {
$qs_properties = array();
} else {
foreach ($qs_properties as $mode => $properties) {
$qs_properties[$mode] = strlen($properties) ? array_flip(explode(',', $properties)) : array();
}
}
$user_divisions = $LMS->GetDivisions(array('userid' => Auth::GetCurrentUser()));
$persistentDivisionContext = $SESSION->get_persistent_setting('division_context');
$tabDivisionContext = $SESSION->get('division_context', true);
// check if user has any division
if (!$user_divisions) {
$SESSION->save_persistent_setting('division_context', '');
$tabDivisionContext = '';
$SESSION->save('division_context', $tabDivisionContext, true);
} else {
$user_division = reset($user_divisions);
if (count($user_divisions) > 1) {
if (!isset($persistentDivisionContext)
|| (!isset($user_divisions[$persistentDivisionContext])
&& !empty($persistentDivisionContext))) {
$SESSION->save_persistent_setting('division_context', $user_division['id']);
$persistentDivisionContext = $SESSION->get_persistent_setting('division_context');
}
if (!isset($tabDivisionContext)
|| (!isset($user_divisions[$persistentDivisionContext])
&& !empty($persistentDivisionContext))) {
$tabDivisionContext = $persistentDivisionContext;
$SESSION->save('division_context', $tabDivisionContext, true);
}
} else {
$SESSION->save_persistent_setting('division_context', $user_division['id']);
$SESSION->save('division_context', $user_division['id'], true);
}
}
LMSDivisionManager::setCurrentDivision($tabDivisionContext);
$layout['division'] = $tabDivisionContext;
if (!$api) {
$SMARTY->assign('division_context', $tabDivisionContext);
$SMARTY->assign('main_menu_sortable_order', $SESSION->get_persistent_setting('main-menu-order'));
$SMARTY->assign('qs_properties', $qs_properties);
$qs_fields = $SESSION->get_persistent_setting('qs-fields');
if (empty($qs_fields)) {
$qs_fields = array();
} else {
$qs_fields = array_flip(explode(',', $qs_fields));
}
$SMARTY->assign('qs_fields', $qs_fields);
if (isset($_GET['backid'])) {
$SESSION->save('backid', $_GET['backid']);
}
if ($backid = $SESSION->get('backid')) {
$SMARTY->assign('backid', $backid);
}
}
// Load plugin files and register hook callbacks
$plugins = $plugin_manager->getAllPluginInfo(LMSPluginManager::OLD_STYLE);
if (!empty($plugins)) {
foreach ($plugins as $plugin_name => $plugin) {
if ($plugin['enabled']) {
require(LIB_DIR . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $plugin_name . '.php');
}
}
}
$LMS->ExecHook('access_table_init');
$LMS->executeHook('access_table_initialized');
LMSConfig::getConfig(array(
'force' => true,
'force_user_rights_only' => true,
'user_id' => Auth::GetCurrentUser(),
));
$divisionid = LMSDivisionManager::getCurrentDivision();
ConfigHelper::setFilter($divisionid, Auth::GetCurrentUser());
$LMS->executeHook('division_set_after', array(
'lms' => $LMS,
'divisionid' => $divisionid,
));
Localisation::initDefaultCurrency();
$module = isset($_GET['m']) ? preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['m']) : '';
$deny = $allow = false;
$res = $LMS->ExecHook('module_load_before', array('module' => $module));
if (array_key_exists('abort', $res) && $res['abort']) {
$SESSION->close();
die;
}
$module = $res['module'];
if ($module != 'logout') {
if ($AUTH->requiredPasswordChange()) {
if ($api) {
die;
}
$module = 'chpasswd';
} elseif ($AUTH->requiredTwoFactorAuthChange()) {
if ($api) {
die;
}
$module = 'twofactorauthedit';
}
}
if ($module == '') {
$module = ConfigHelper::getConfig('phpui.default_module');
}
$module_dir = null;
foreach ($modules_dirs as $suspected_module_dir) {
if (file_exists($suspected_module_dir . DIRECTORY_SEPARATOR . $module . '.php')) {
$module_dir = $suspected_module_dir;
break;
}
}
if ($module_dir !== null) {
$global_allow = !Auth::GetCurrentUser() || (!empty($global_access_regexp) && preg_match('/' . $global_access_regexp . '/i', $module));
if (Auth::GetCurrentUser() && ($rights = $LMS->GetUserRights(Auth::GetCurrentUser()))) {
$allow = $access->checkRights($module, $rights, $global_allow);
}
if ($SYSLOG) {
$SYSLOG->NewTransaction($module);
}
// everyone should have access to documentation and authentication configuration
$rights[] = 'documentation';
$rights[] = 'auth';
$access->applyMenuPermissions($menu, $rights);
if ($global_allow || $allow) {
$layout['module'] = $module;
$SESSION->save('module', $module);
if (!$api) {
$SMARTY->assign('url', 'http' . (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '') . '://' . $_SERVER['HTTP_HOST']
. substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/') + 1));
// get all persistent filters
$SMARTY->assign('persistent_filters', $SESSION->getAllPersistentFilters());
// persister filter apply
if (isset($_GET['persistent-filter'])) {
$filterId = $_GET['filter-id'] ?? null;
$filter = $SESSION->getPersistentFilter(
$_GET['persistent-filter'],
null,
$filterId
);
$filter['persistent_filter'] = $_GET['persistent-filter'];
if (isset($filterId)) {
$SESSION->saveFilter($filter, null, null, false, $filterId);
} else {
$SESSION->saveFilter($filter);
}
}
$filter = $SESSION->getFilter($_GET['module-filter'] ?? null);
$SMARTY->assignByRef('filter', $filter);
// restore selected persistent filter info
if (isset($filter['persistent_filter'])) {
$SMARTY->assign('persistent_filter', $filter['persistent_filter']);
}
// tab visibility toggle support
$resource_tabs = $SESSION->get_persistent_setting($layout['module'] . '-resource-tabs');
$SMARTY->assign('serialized_resource_tabs', $resource_tabs);
if (!empty($resource_tabs)) {
$resource_tabs = explode(';', $resource_tabs);
$all_tabs = array();
foreach ($resource_tabs as $resource_tab) {
[$resource_tab_id, $resource_tab_state] = explode(':', $resource_tab);
$all_tabs[$resource_tab_id] = intval($resource_tab_state) != 0;
}
$resource_tabs = $all_tabs;
} else {
$resource_tabs = array();
}
$SMARTY->assign('resource_tabs', $resource_tabs);
// preset error and warning smarty variable
// they can be easily filled later in modules
$SMARTY->assignByRef('error', $error);
$SMARTY->assignByRef('warning', $warning);
// preload warnings from submitted form to $warning variable
if (isset($_GET['warning'])) {
$warnings = $_GET['warning'];
} elseif (isset($_POST['warning'])) {
$warnings = $_POST['warning'];
}
} else {
// persistent filter ajax management
if (isset($_GET['persistent-filter']) && isset($_GET['action'])) {
$filterId = $_POST['filter-id'] ?? null;
switch ($_GET['action']) {
case 'update':
$oldFilter = $SESSION->getFilter(null, $filterId);
if (isset($_GET['savefilter'])) {
$filter = array_merge($_POST, array('persistent_filter' => $_GET['persistent-filter']));
$SESSION->saveFilter($filter, null, null, false, $filterId);
} else {
$filter = $oldFilter;
}
$SESSION->savePersistentFilter($_GET['persistent-filter'], $filter, null, $filterId);
$persistent_filters = $SESSION->getAllPersistentFilters(null, $filterId);
$SESSION->close();
header('Content-type: application/json');
die(json_encode($persistent_filters));
break;
case 'delete':
$SESSION->removePersistentFilter(
$_GET['persistent-filter'],
null,
$filterId
);
$persistent_filters = $SESSION->getAllPersistentFilters(null, $filterId);
$SESSION->close();
header('Content-type: application/json');
die(json_encode($persistent_filters));
break;
}
}
}
$LMS->InitUI();
$LMS->executeHook($module.'_on_load');
$serviceproviders = $LMS->getServiceProviders();
if (!$api) {
$SMARTY->assign('serviceproviders', $serviceproviders);
}
try {
session_write_close();
include($module_dir . DIRECTORY_SEPARATOR . $module . '.php');
} catch (Exception $e) {
if (!$api) {
$SMARTY->display('header.html');
echo '<div class="bold">' . $e->getFile() . '[' . $e->getLine() . ']: <span class="red">'
. str_replace("\n", '<br>', $e->getMessage())
. '</span></div>';
$SMARTY->display('footer.html');
}
die;
}
} else {
if ($SYSLOG) {
$SYSLOG->AddMessage(
SYSLOG::RES_USER,
SYSLOG::OPER_USERNOACCESS,
array(SYSLOG::RES_USER => Auth::GetCurrentUser())
);
}
if (!$api) {
$SMARTY->display('noaccess.html');
}
}
} else {
$layout['module'] = 'notfound';
$layout['pagetitle'] = trans('Error!');
if (!$api) {
$SMARTY->assign('layout', $layout);
$SMARTY->assign('server', $_SERVER);
$SMARTY->display('notfound.html');
}
}
if ($SESSION->get('lastmodule') != $module) {
$SESSION->save('lastmodule', $module);
}
} else {
if (!$api) {
$SMARTY->assign('error', $AUTH->error);
$SMARTY->assign('target', '?'.$_SERVER['QUERY_STRING']);
if ($AUTH->authCodeRequired()) {
$SMARTY->display('twofactorauth/twofactorauthcode.html');
} else {
$SMARTY->display('login.html');
}
}
}
$SESSION->close();