forked from XoopsModules25x/wgsimpleacc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtratemplates.php
217 lines (200 loc) · 9.85 KB
/
tratemplates.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
<?php
/*
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.
*/
/**
* wgSimpleAcc module for xoops
*
* @copyright 2020 XOOPS Project (https://xooops.org)
* @license GPL 2.0 or later
* @package wgsimpleacc
* @since 1.0
* @min_xoops 2.5.10
* @author Goffy - XOOPS Development Team - Email:<webmaster@wedega.com> - Website:<https://xoops.wedega.com>
*/
use Xmf\Request;
use XoopsModules\Wgsimpleacc;
use XoopsModules\Wgsimpleacc\{
Constants,
Common,
Utility
};
require __DIR__ . '/header.php';
require_once \XOOPS_ROOT_PATH . '/header.php';
$GLOBALS['xoopsTpl']->assign('template_sub', 'db:wgsimpleacc_tratemplates.tpl');
require __DIR__ . '/navbar.php';
// Permissions
if (!$permissionsHandler->getPermTratemplatesView()) {
\redirect_header('index.php', 0, '');
}
$op = Request::getCmd('op', 'list');
$start = Request::getInt('start', 0);
$limit = Request::getInt('limit', $helper->getConfig('userpager'));
$tplId = Request::getInt('ttpl_id', 0);
$GLOBALS['xoopsTpl']->assign('xoops_icons32_url', \XOOPS_ICONS32_URL);
$GLOBALS['xoopsTpl']->assign('wgsimpleacc_url', \WGSIMPLEACC_URL);
$GLOBALS['xoopsTpl']->assign('wgsimpleacc_icons_url_32', \WGSIMPLEACC_ICONS_URL . '/32/');
$GLOBALS['xoopsTpl']->assign('showItem', $tplId > 0);
$permSubmit = $permissionsHandler->getPermTratemplatesSubmit();
$keywords = [];
switch ($op) {
case 'show':
case 'list':
default:
$GLOBALS['xoopsTpl']->assign('showList', true);
$GLOBALS['xoopsTpl']->assign('useClients', $helper->getConfig('use_clients'));
$crTratemplates = new \CriteriaCompo();
if ($tplId > 0) {
$crTratemplates->add(new \Criteria('ttpl_id', $tplId));
}
$tratemplatesCount = $tratemplatesHandler->getCount($crTratemplates);
$GLOBALS['xoopsTpl']->assign('tratemplatesCount', $tratemplatesCount);
$crTratemplates->setStart($start);
$crTratemplates->setLimit($limit);
$tratemplatesAll = $tratemplatesHandler->getAll($crTratemplates);
if ($tratemplatesCount > 0) {
$tratemplates = [];
// Get All Tratemplates
foreach (\array_keys($tratemplatesAll) as $i) {
$tratemplates[$i] = $tratemplatesAll[$i]->getValuesTratemplates();
$tratemplates[$i]['edit'] = $permissionsHandler->getPermTratemplatesEdit($tratemplates[$i]['ttpl_submitter']);
$keywords[$i] = $tratemplatesAll[$i]->getVar('ttpl_name');
}
$GLOBALS['xoopsTpl']->assign('tratemplates', $tratemplates);
$GLOBALS['xoopsTpl']->assign('permSubmit', $permSubmit);
unset($tratemplates);
// Display Navigation
if ($tratemplatesCount > $limit) {
include_once \XOOPS_ROOT_PATH . '/class/pagenav.php';
$pagenav = new \XoopsPageNav($tratemplatesCount, $limit, $start, 'start', 'op=list&limit=' . $limit);
$GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4));
}
}
// Breadcrumbs
$xoBreadcrumbs[] = ['title' => \_MA_WGSIMPLEACC_TRATEMPLATES];
break;
case 'save':
// Security Check
if (!$GLOBALS['xoopsSecurity']->check()) {
\redirect_header('tratemplates.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
}
// Check permissions
if (!$permSubmit) {
\redirect_header('tratemplates.php?op=list', 3, \_NOPERM);
}
if ($tplId > 0) {
$tratemplatesObj = $tratemplatesHandler->get($tplId);
} else {
$tratemplatesObj = $tratemplatesHandler->create();
}
$tratemplatesObj->setVar('ttpl_name', Request::getString('ttpl_name', ''));
$tratemplatesObj->setVar('ttpl_desc', Request::getText('ttpl_desc', ''));
$tratemplatesObj->setVar('ttpl_accid', Request::getInt('ttpl_accid', 0));
$tratemplatesObj->setVar('ttpl_allid', Request::getInt('ttpl_allid', 0));
$tratemplatesObj->setVar('ttpl_asid', Request::getInt('ttpl_asid', 0));
$tratemplatesObj->setVar('ttpl_cliid', Request::getInt('ttpl_cliid', 0));
$tratemplatesObj->setVar('ttpl_class', Request::getInt('ttpl_class', 0));
$tplAmountin = Request::getString('ttpl_amountin');
$tratemplatesObj->setVar('ttpl_amountin', Utility::StringToFloat($tplAmountin));
$tplAmountout = Request::getString('ttpl_amountout');
$tratemplatesObj->setVar('ttpl_amountout', Utility::StringToFloat($tplAmountout));
$tratemplatesObj->setVar('ttpl_online', Request::getInt('ttpl_online', 0));
$templateDatecreatedObj = \DateTime::createFromFormat(\_SHORTDATESTRING, Request::getString('ttpl_datecreated'));
$tratemplatesObj->setVar('ttpl_datecreated', $templateDatecreatedObj->getTimestamp());
$tratemplatesObj->setVar('ttpl_submitter', Request::getInt('ttpl_submitter', 0));
// Insert Data
if ($tratemplatesHandler->insert($tratemplatesObj)) {
// redirect after insert
\redirect_header('tratemplates.php', 2, \_MA_WGSIMPLEACC_FORM_OK);
}
// Get Form Error
$GLOBALS['xoopsTpl']->assign('error', $tratemplatesObj->getHtmlErrors());
$form = $tratemplatesObj->getFormTratemplates();
$GLOBALS['xoopsTpl']->assign('form', $form->render());
break;
case 'new':
// Check permissions
if (!$permSubmit) {
\redirect_header('tratemplates.php?op=list', 3, \_NOPERM);
}
$traId = Request::getInt('tra_id', 0);
// Form Create
$tratemplatesObj = $tratemplatesHandler->create();
if ($traId > 0) {
$transactionsObj = $transactionsHandler->get($traId);
$tratemplatesObj->setVar('ttpl_desc', $transactionsObj->getVar('tra_desc', 'n'));
$tratemplatesObj->setVar('ttpl_accid', $transactionsObj->getVar('tra_accid'));
$tratemplatesObj->setVar('ttpl_allid', $transactionsObj->getVar('tra_allid'));
$tratemplatesObj->setVar('ttpl_asid', $transactionsObj->getVar('tra_asid'));
$tratemplatesObj->setVar('ttpl_cliid', $transactionsObj->getVar('tra_cliid'));
$tratemplatesObj->setVar('ttpl_class', $transactionsObj->getVar('tra_class'));
$tratemplatesObj->setVar('ttpl_amountin', $transactionsObj->getVar('tra_amountin'));
$tratemplatesObj->setVar('ttpl_amountout', $transactionsObj->getVar('tra_amountout'));
}
$form = $tratemplatesObj->getFormTratemplates();
$GLOBALS['xoopsTpl']->assign('form', $form->render());
// Breadcrumbs
$xoBreadcrumbs[] = ['title' => \_MA_WGSIMPLEACC_TRATEMPLATES, 'link' => 'tratemplates.php?op=list'];
$xoBreadcrumbs[] = ['title' => \_MA_WGSIMPLEACC_TRATEMPLATE_ADD];
break;
case 'edit':
// Check params
if (0 == $tplId) {
\redirect_header('tratemplates.php?op=list', 3, \_MA_WGSIMPLEACC_INVALID_PARAM);
}
// Get Form
$tratemplatesObj = $tratemplatesHandler->get($tplId);
// Check permissions
if (!$permissionsHandler->getPermTratemplatesEdit($tratemplatesObj->getVar('ttpl_submitter'))) {
\redirect_header('tratemplates.php?op=list', 3, \_NOPERM);
}
$form = $tratemplatesObj->getFormTratemplates();
$GLOBALS['xoopsTpl']->assign('form', $form->render());
// Breadcrumbs
$xoBreadcrumbs[] = ['title' => \_MA_WGSIMPLEACC_TRATEMPLATES, 'link' => 'tratemplates.php?op=list'];
$xoBreadcrumbs[] = ['title' => \_MA_WGSIMPLEACC_TRATEMPLATE_EDIT];
break;
case 'delete':
// Check params
if (0 == $tplId) {
\redirect_header('tratemplates.php?op=list', 3, \_MA_WGSIMPLEACC_INVALID_PARAM);
}
$tratemplatesObj = $tratemplatesHandler->get($tplId);
// Check permissions
if (!$permissionsHandler->getPermTratemplatesEdit($tratemplatesObj->getVar('ttpl_submitter'))) {
\redirect_header('tratemplates.php?op=list', 3, \_NOPERM);
}
$tplName = $tratemplatesObj->getVar('ttpl_name');
if (isset($_REQUEST['ok']) && 1 == $_REQUEST['ok']) {
if (!$GLOBALS['xoopsSecurity']->check()) {
\redirect_header('tratemplates.php', 3, \implode(', ', $GLOBALS['xoopsSecurity']->getErrors()));
}
if ($tratemplatesHandler->delete($tratemplatesObj)) {
\redirect_header('tratemplates.php', 3, \_MA_WGSIMPLEACC_FORM_DELETE_OK);
} else {
$GLOBALS['xoopsTpl']->assign('error', $tratemplatesObj->getHtmlErrors());
}
} else {
$customConfirm = new Common\Confirm(
['ok' => 1, 'ttpl_id' => $tplId, 'op' => 'delete'],
$_SERVER['REQUEST_URI'],
\sprintf(\_MA_WGSIMPLEACC_FORM_SURE_DELETE, $tratemplatesObj->getVar('ttpl_name')));
$form = $customConfirm->getFormConfirm();
$GLOBALS['xoopsTpl']->assign('form', $form->render());
// Breadcrumbs
$xoBreadcrumbs[] = ['title' => \_MA_WGSIMPLEACC_TRATEMPLATES, 'link' => 'tratemplates.php?op=list'];
$xoBreadcrumbs[] = ['title' => \_MA_WGSIMPLEACC_TRATEMPLATE_EDIT];
}
break;
}
// Keywords
wgsimpleaccMetaKeywords($helper->getConfig('keywords') . ', ' . \implode(',', $keywords));
unset($keywords);
$GLOBALS['xoopsTpl']->assign('xoops_mpageurl', \WGSIMPLEACC_URL.'/tratemplates.php');
$GLOBALS['xoopsTpl']->assign('wgsimpleacc_upload_url', \WGSIMPLEACC_UPLOAD_URL);
require __DIR__ . '/footer.php';