forked from XoopsModules25x/wgevents
/
log.php
144 lines (136 loc) · 6.16 KB
/
log.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
<?php declare(strict_types=1);
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
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.
*/
/**
* wgEvents module for xoops
*
* @copyright 2021 XOOPS Project (https://xoops.org)
* @license GPL 2.0 or later
* @package wgevents
* @author Goffy - Wedega - Email:webmaster@wedega.com - Website:https://xoops.wedega.com
*/
use Xmf\Request;
use XoopsModules\Wgevents;
use XoopsModules\Wgevents\Constants;
use XoopsModules\Wgevents\Common;
require __DIR__ . '/header.php';
// Get all request values
$op = Request::getCmd('op', 'list');
$logId = Request::getInt('id');
$start = Request::getInt('start');
$limit = Request::getInt('limit', $helper->getConfig('adminpager'));
$GLOBALS['xoopsTpl']->assign('start', $start);
$GLOBALS['xoopsTpl']->assign('limit', $limit);
$moduleDirName = \basename(\dirname(__DIR__));
$GLOBALS['xoopsTpl']->assign('mod_url', XOOPS_URL . '/modules/' . $moduleDirName);
switch ($op) {
case 'list':
default:
// Define Stylesheet
$GLOBALS['xoTheme']->addStylesheet($style, null);
$templateMain = 'wgevents_admin_log.tpl';
$GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('log.php'));
$adminObject->addItemButton(\_AM_WGEVENTS_DELETE_LOGS, 'log.php?op=deleteall', 'delete');
$GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
$logCount = $logHandler->getCountLogs();
$logAll = $logHandler->getAllLogs();
$GLOBALS['xoopsTpl']->assign('logCount', $logCount);
$GLOBALS['xoopsTpl']->assign('wgevents_url', \WGEVENTS_URL);
$GLOBALS['xoopsTpl']->assign('wgevents_upload_url', \WGEVENTS_UPLOAD_URL);
// Table view logs
if ($logCount > 0) {
foreach (\array_keys($logAll) as $i) {
$log = $logAll[$i]->getValuesLogs();
$GLOBALS['xoopsTpl']->append('logs_list', $log);
unset($log);
}
} else {
$GLOBALS['xoopsTpl']->assign('error', \_AM_WGEVENTS_THEREARENT_LOGS);
}
break;
case 'save':
// Security Check
if (!$GLOBALS['xoopsSecurity']->check()) {
\redirect_header('log.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
}
if ($logId > 0) {
$logObj = $logHandler->get($logId);
} else {
$logObj = $logHandler->create();
}
// Set Vars
$logObj->setVar('text', Request::getString('text'));
$logDatecreatedObj = \DateTime::createFromFormat(\_SHORTDATESTRING, Request::getString('datecreated'));
$logObj->setVar('datecreated', $logDatecreatedObj->getTimestamp());
$logObj->setVar('submitter', Request::getInt('submitter'));
// Insert Data
if ($logHandler->insert($logObj)) {
\redirect_header('log.php?op=list&start=' . $start . '&limit=' . $limit, 2, \_AM_WGEVENTS_FORM_OK);
}
// Get Form
$GLOBALS['xoopsTpl']->assign('error', $logObj->getHtmlErrors());
$form = $logObj->getForm();
$GLOBALS['xoopsTpl']->assign('form', $form->render());
break;
case 'edit':
$templateMain = 'wgevents_admin_log.tpl';
$GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('log.php'));
$adminObject->addItemButton(\_AM_WGEVENTS_ADD_LOG, 'log.php?op=new');
$adminObject->addItemButton(\_AM_WGEVENTS_LIST_LOGS, 'log.php', 'list');
$GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
// Get Form
$logObj = $logHandler->get($logId);
$logObj->start = $start;
$logObj->limit = $limit;
$form = $logObj->getForm();
$GLOBALS['xoopsTpl']->assign('form', $form->render());
break;
case 'delete':
$templateMain = 'wgevents_admin_log.tpl';
$GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('log.php'));
$logObj = $logHandler->get($logId);
$logText = $logObj->getVar('text');
if (isset($_REQUEST['ok']) && 1 === (int)$_REQUEST['ok']) {
if (!$GLOBALS['xoopsSecurity']->check()) {
\redirect_header('log.php', 3, \implode(', ', $GLOBALS['xoopsSecurity']->getErrors()));
}
if ($logHandler->delete($logObj)) {
\redirect_header('log.php', 3, \_AM_WGEVENTS_FORM_DELETE_OK);
} else {
$GLOBALS['xoopsTpl']->assign('error', $logObj->getHtmlErrors());
}
} else {
$customConfirm = new Common\Confirm(
['ok' => 1, 'id' => $logId, 'start' => $start, 'limit' => $limit, 'op' => 'delete'],
$_SERVER['REQUEST_URI'],
\sprintf(\_AM_WGEVENTS_FORM_SURE_DELETE, $logObj->getVar('text')));
$form = $customConfirm->getFormConfirm();
$GLOBALS['xoopsTpl']->assign('form', $form->render());
}
break;
case 'deleteall':
$templateMain = 'wgevents_admin_log.tpl';
$GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('log.php'));
if (isset($_REQUEST['ok']) && 1 === (int)$_REQUEST['ok']) {
if (!$GLOBALS['xoopsSecurity']->check()) {
\redirect_header('log.php', 3, \implode(', ', $GLOBALS['xoopsSecurity']->getErrors()));
}
$logHandler->deleteAll();
\redirect_header('log.php', 3, \_MA_WGEVENTS_FORM_DELETE_OK);
} else {
$customConfirm = new Common\Confirm(
['ok' => 1, 'op' => 'deleteall'],
$_SERVER['REQUEST_URI'],
\sprintf(\_AM_WGEVENTS_FORM_SURE_DELETE_ALL, 'Table Log'));
$form = $customConfirm->getFormConfirm();
$GLOBALS['xoopsTpl']->assign('form', $form->render());
}
break;
}
require __DIR__ . '/footer.php';