1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* **************************************************************************** |
7
|
|
|
* GBOOK - MODULE FOR XOOPS |
8
|
|
|
* Copyright (c) 2007 - 2012 |
9
|
|
|
* Ingo H. de Boer (http://www.winshell.org) |
10
|
|
|
* |
11
|
|
|
* This program is free software; you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU General Public License as published by |
13
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
14
|
|
|
* (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* You may not change or alter any portion of this comment or credits |
17
|
|
|
* of supporting developers from this source code or any supporting |
18
|
|
|
* source code which is considered copyrighted (c) material of the |
19
|
|
|
* original comment or credit authors. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU General Public License for more details. |
25
|
|
|
* --------------------------------------------------------------------------- |
26
|
|
|
* |
27
|
|
|
* @copyright Ingo H. de Boer (http://www.winshell.org) |
28
|
|
|
* @license GNU General Public License (GPL) |
29
|
|
|
* @package GBook |
30
|
|
|
* @author Ingo H. de Boer ([email protected]) |
31
|
|
|
* |
32
|
|
|
* **************************************************************************** |
33
|
|
|
*/ |
34
|
|
|
|
35
|
|
|
use Xmf\Request; |
36
|
|
|
use XoopsModules\Gbook; |
37
|
|
|
|
38
|
|
|
use Xmf\Module\Admin; |
39
|
|
|
use XoopsModules\Gbook\Helper; |
40
|
|
|
|
41
|
|
|
/** @var Admin $adminObject */ |
42
|
|
|
|
43
|
|
|
require_once __DIR__ . '/admin_header.php'; |
44
|
|
|
xoops_cp_header(); |
45
|
|
|
|
46
|
|
|
$adminObject->displayNavigation(basename(__FILE__)); |
47
|
|
|
$adminObject->displayButton('right', ''); |
48
|
|
|
|
49
|
|
|
$tempId = Request::getInt('id', 0, 'GET'); |
50
|
|
|
$tempOp = Request::getCmd('op', Request::getCmd('op', '', 'POST'), 'GET'); |
51
|
|
|
|
52
|
|
|
$template_main = ''; |
53
|
|
|
$op = '' !== $tempOp ? $tempOp : (0 !== $tempId ? 'edit' : 'list'); |
54
|
|
|
|
55
|
|
|
/** @var Gbook\EntriesHandler $entriesHandler */ |
56
|
|
|
$entriesHandler = Helper::getInstance()->getHandler('Entries'); |
57
|
|
|
|
58
|
|
|
switch ($op) { |
59
|
|
|
default: |
60
|
|
|
case 'list': |
61
|
|
|
$criteria = new \CriteriaCompo(); |
62
|
|
|
$criteria->setSort('id'); |
63
|
|
|
$criteria->setOrder('DESC'); |
64
|
|
|
$GLOBALS['xoopsTpl']->assign('entries', $entriesHandler->getObjects($criteria, true, false)); |
65
|
|
|
$template_main = 'gbook_admin_entries.tpl'; |
66
|
|
|
break; |
67
|
|
|
case 'edit': |
68
|
|
|
$obj = $entriesHandler->get(Request::getInt('id', '', 'GET')); |
|
|
|
|
69
|
|
|
/** @var \XoopsThemeForm $form */ |
70
|
|
|
$form = $obj->getForm(); |
71
|
|
|
$form->display(); |
72
|
|
|
break; |
73
|
|
|
case 'save': |
74
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
75
|
|
|
echo $GLOBALS['xoopsSecurity']->getErrors(); |
76
|
|
|
|
77
|
|
|
redirect_header('entries.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
78
|
|
|
} |
79
|
|
|
$tempId = Request::getInt('id', 0, 'GET'); |
80
|
|
|
if (0 !== $tempId) { |
81
|
|
|
$obj = $entriesHandler->get($tempId); |
82
|
|
|
} else { |
83
|
|
|
$obj = $entriesHandler->create(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$obj->setVar('name', Request::getString('name', '', 'POST')); |
87
|
|
|
$obj->setVar('email', Request::getString('email', '', 'POST')); |
88
|
|
|
$obj->setVar('url', Request::getString('url', '', 'POST')); |
89
|
|
|
$obj->setVar('message', Request::getText('message', '', 'POST')); |
90
|
|
|
$obj->setVar('note', Request::getText('note', '', 'POST')); |
91
|
|
|
if ($entriesHandler->insert($obj)) { |
92
|
|
|
redirect_header('entries.php', 3, _AM_GBOOK_ENTRY_EDITED); |
93
|
|
|
} |
94
|
|
|
require_once \dirname(__DIR__) . '/include/forms.php'; |
95
|
|
|
echo $obj->getHtmlErrors(); |
96
|
|
|
/** @var \XoopsThemeForm $form */ |
97
|
|
|
$form = $obj->getForm(); |
98
|
|
|
$form->display(); |
99
|
|
|
break; |
100
|
|
|
case 'delete': |
101
|
|
|
$tempId = Request::getInt('id', 0, 'GET'); |
102
|
|
|
$tempOk = Request::getInt('ok', 0, 'POST'); |
103
|
|
|
$obj = $entriesHandler->get($tempId); |
104
|
|
|
|
105
|
|
|
if (1 === $tempOk) { |
106
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
107
|
|
|
redirect_header('entries.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
108
|
|
|
} |
109
|
|
|
if ($entriesHandler->delete($obj)) { |
110
|
|
|
redirect_header('entries.php', 3, sprintf(_AM_GBOOK_DELETE_SUCCESS, $obj->getVar('name'))); |
111
|
|
|
} else { |
112
|
|
|
echo $obj->getHtmlErrors(); |
113
|
|
|
} |
114
|
|
|
} else { |
115
|
|
|
xoops_confirm(['ok' => 1, 'id' => Request::getInt('id', 0, 'GET'), 'op' => 'delete'], Request::getString('REQUEST_URI', '', 'SERVER'), sprintf(_AM_GBOOK_DELETE_SURE, $obj->getVar('name'))); |
116
|
|
|
} |
117
|
|
|
break; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
if ('' !== $template_main) { |
121
|
|
|
$GLOBALS['xoopsTpl']->display("db:{$template_main}"); |
122
|
|
|
} |
123
|
|
|
require_once __DIR__ . '/admin_footer.php'; |
124
|
|
|
|