1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace XoopsModules\Countdown\Form; |
6
|
|
|
|
7
|
|
|
/* |
8
|
|
|
You may not change or alter any portion of this comment or credits |
9
|
|
|
of supporting developers from this source code or any supporting source code |
10
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
11
|
|
|
|
12
|
|
|
This program is distributed in the hope that it will be useful, |
13
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Module: Countdown |
19
|
|
|
* |
20
|
|
|
* @category Module |
21
|
|
|
* @package countdown |
22
|
|
|
* @author XOOPS Development Team <https://xoops.org> |
23
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
24
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
25
|
|
|
* @link https://xoops.org/ |
26
|
|
|
* @since 1.0.0 |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
use Xmf\Request; |
30
|
|
|
use XoopsModules\Countdown; |
31
|
|
|
use XoopsModules\Countdown\Common; |
32
|
|
|
use XoopsFormTextDateSelect; |
33
|
|
|
use XoopsFormSelect; |
34
|
|
|
|
35
|
|
|
require_once dirname(dirname(__DIR__)) . '/include/common.php'; |
36
|
|
|
|
37
|
|
|
$moduleDirName = basename(dirname(dirname(__DIR__))); |
38
|
|
|
$helper = Countdown\Helper::getInstance(); |
39
|
|
|
$permHelper = new \Xmf\Module\Helper\Permission(); |
40
|
|
|
|
41
|
|
|
xoops_load('XoopsFormLoader'); |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Class EventsForm |
45
|
|
|
*/ |
46
|
|
|
class EventsForm extends \XoopsThemeForm |
47
|
|
|
{ |
48
|
|
|
public $targetObject; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Constructor |
52
|
|
|
* |
53
|
|
|
* @param $target |
54
|
|
|
*/ |
55
|
|
|
public function __construct($target) |
56
|
|
|
{ |
57
|
|
|
$helper = \XoopsModules\Countdown\Helper::getInstance(); |
58
|
|
|
|
59
|
|
|
$this->targetObject = $target; |
60
|
|
|
|
61
|
|
|
$title = $this->targetObject->isNew() ? sprintf(_AM_COUNTDOWN_EVENTS_ADD) : sprintf(_AM_COUNTDOWN_EVENTS_EDIT); |
62
|
|
|
parent::__construct($title, 'form', xoops_getenv('PHP_SELF'), 'post', true); |
63
|
|
|
$this->setExtra('enctype="multipart/form-data"'); |
64
|
|
|
|
65
|
|
|
//include ID field, it's needed so the module knows if it is a new form or an edited form |
66
|
|
|
|
67
|
|
|
$hidden = new \XoopsFormHidden('event_id', $this->targetObject->getVar('event_id')); |
68
|
|
|
$this->addElement($hidden); |
69
|
|
|
unset($hidden); |
70
|
|
|
|
71
|
|
|
// Id |
72
|
|
|
$this->addElement(new \XoopsFormLabel(_AM_COUNTDOWN_EVENTS_ID, $this->targetObject->getVar('event_id'), 'event_id')); |
73
|
|
|
//Category |
74
|
|
|
$category_id = 0; |
|
|
|
|
75
|
|
|
if (!$this->targetObject->isNew()) { |
76
|
|
|
$category_id = $this->targetObject->getVar('event_categoryid'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$categoryHandler = $helper->getHandler('category'); |
80
|
|
|
$categories = $categoryHandler->getObjects(); |
81
|
|
|
$category_sel = new XoopsFormSelect(_AM_COUNTDOWN_CATEGORY, 'event_categoryid', $this->targetObject->getVar('event_categoryid')); |
82
|
|
|
$i = 1; |
|
|
|
|
83
|
|
|
|
84
|
|
|
foreach (array_keys($categories) as $i) { |
85
|
|
|
$category_sel->addOption($categories[$i]->getVar('category_id'), $categories[$i]->getVar('category_title')); |
86
|
|
|
} |
87
|
|
|
$this->addElement($category_sel); |
88
|
|
|
|
89
|
|
|
// Name |
90
|
|
|
$this->addElement(new \XoopsFormText(_AM_COUNTDOWN_EVENTS_NAME, 'event_name', 50, 255, $this->targetObject->getVar('event_name')), false); |
91
|
|
|
// Description |
92
|
|
|
if (class_exists('XoopsFormEditor')) { |
93
|
|
|
$editorOptions = []; |
94
|
|
|
$editorOptions['name'] = 'event_description'; |
95
|
|
|
$editorOptions['value'] = $this->targetObject->getVar('event_description', 'e'); |
96
|
|
|
$editorOptions['rows'] = 5; |
97
|
|
|
$editorOptions['cols'] = 40; |
98
|
|
|
$editorOptions['width'] = '100%'; |
99
|
|
|
$editorOptions['height'] = '400px'; |
100
|
|
|
//$editorOptions['editor'] = xoops_getModuleOption('countdown_editor', 'countdown'); |
101
|
|
|
//$this->addElement( new \XoopsFormEditor(_AM_COUNTDOWN_EVENTS_DESCRIPTION, 'description', $editorOptions), false ); |
102
|
|
|
if ($helper->isUserAdmin()) { |
103
|
|
|
$descEditor = new \XoopsFormEditor(_AM_COUNTDOWN_EVENTS_DESCRIPTION, $helper->getConfig('countdownEditorAdmin'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
104
|
|
|
} else { |
105
|
|
|
$descEditor = new \XoopsFormEditor(_AM_COUNTDOWN_EVENTS_DESCRIPTION, $helper->getConfig('countdownEditorUser'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
106
|
|
|
} |
107
|
|
|
} else { |
108
|
|
|
$descEditor = new \XoopsFormDhtmlTextArea(_AM_COUNTDOWN_EVENTS_DESCRIPTION, 'event_description', $this->targetObject->getVar('event_description', 'e'), '100%', '100%'); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
$this->addElement($descEditor); |
111
|
|
|
|
112
|
|
|
// Event Date |
113
|
|
|
$this->addElement(new \XoopsFormDateTime(_AM_COUNTDOWN_EVENTS_DATE, 'event_date', '', strtotime($this->targetObject->getVar('event_date')))); |
|
|
|
|
114
|
|
|
|
115
|
|
|
// Logo |
116
|
|
|
$logo = $this->targetObject->getVar('event_logo') ?: 'blank.png'; |
117
|
|
|
|
118
|
|
|
$uploadDir = '/uploads/countdown/images/'; |
119
|
|
|
$imgtray = new \XoopsFormElementTray(_AM_COUNTDOWN_EVENTS_LOGO, '<br>'); |
120
|
|
|
$imgpath = sprintf(_AM_COUNTDOWN_FORMIMAGE_PATH, $uploadDir); |
121
|
|
|
$imageselect = new \XoopsFormSelect($imgpath, 'event_logo', $logo); |
122
|
|
|
$imageArray = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadDir); |
123
|
|
|
foreach ($imageArray as $image) { |
124
|
|
|
$imageselect->addOption((string)$image, $image); |
125
|
|
|
} |
126
|
|
|
$imageselect->setExtra("onchange='showImgSelected(\"image_logo\", \"logo\", \"" . $uploadDir . '", "", "' . XOOPS_URL . "\")'"); |
127
|
|
|
$imgtray->addElement($imageselect); |
128
|
|
|
$imgtray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $uploadDir . '/' . $logo . "' name='image_logo' id='image_logo' alt=''>")); |
129
|
|
|
$fileseltray = new \XoopsFormElementTray('', '<br>'); |
130
|
|
|
$fileseltray->addElement(new \XoopsFormFile(_AM_COUNTDOWN_FORMUPLOAD, 'event_logo', $helper->getConfig('maxsize'))); |
131
|
|
|
$fileseltray->addElement(new \XoopsFormLabel('')); |
132
|
|
|
$imgtray->addElement($fileseltray); |
133
|
|
|
$this->addElement($imgtray); |
134
|
|
|
|
135
|
|
|
// Submitter |
136
|
|
|
$this->addElement(new \XoopsFormSelectUser(_AM_COUNTDOWN_EVENTS_POSTERNAME, 'event_uid', false, $this->targetObject->getVar('event_uid'), 1, false), false); |
137
|
|
|
|
138
|
|
|
// Data_creation |
139
|
|
|
$this->addElement( |
140
|
|
|
new XoopsFormTextDateSelect( |
141
|
|
|
\_AM_COUNTDOWN_EVENTS_DATE_CREATED, 'date_created', 0, \formatTimestamp($this->targetObject->getVar('date_created'), 's') |
|
|
|
|
142
|
|
|
) |
143
|
|
|
); |
144
|
|
|
// Data_update |
145
|
|
|
$this->addElement( |
146
|
|
|
new XoopsFormTextDateSelect( |
147
|
|
|
\_AM_COUNTDOWN_EVENTS_DATE_UPDATED, 'date_updated', 0, \formatTimestamp($this->targetObject->getVar('date_updated'), 's') |
148
|
|
|
) |
149
|
|
|
); |
150
|
|
|
|
151
|
|
|
$this->addElement(new \XoopsFormHidden('op', 'save')); |
152
|
|
|
$this->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|