Issues (340)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.
1
<?php declare(strict_types=1);
2
3
/**
4
 * Newbb module
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright       XOOPS Project (https://xoops.org)
14
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @since           4.0
16
 * @author          Taiwen Jiang <[email protected]>
17
 */
18
19
use Xmf\Request;
20
use XoopsModules\Newbb\{
21
    Forum,
22
    Helper,
23
    TopicHandler,
24
    ForumHandler
25
};
26
use XoopsModules\Xoopspoll\{
27
    Constants as PollConstants,
28
    Helper as PollHelper
29
};
30
31
/** @var TopicHandler $topicHandler */
32
/** @var ForumHandler $forumHandler */
33
34
// rewrite by irmtfan and zyspec to accept xoopspoll 1.4 and all old xoopspoll and umfrage versions and all clones
35
36
global $xoopsModule;
37
38
require_once __DIR__ . '/header.php';
39
require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
40
require_once $GLOBALS['xoops']->path('class/xoopslists.php');
41
require_once $GLOBALS['xoops']->path('kernel/block.php');
42
xoops_load('XoopsLocal');
43
44
$pollHelper = PollHelper::getInstance();
45
46
$op      = 'add';
47
$goodOps = [
48
    'add',
49
    'save',
50
    'edit',
51
    'update',
52
    'addmore',
53
    'savemore',
54
    'delete',
55
    'delete_ok',
56
    'restart',
57
    'restart_ok',
58
    'log',
59
];
60
$op      = $_REQUEST['op'] ?? 'add';
61
$op      = (!in_array($op, $goodOps, true)) ? 'add' : $op;
62
63
$poll_id  = Request::getInt('poll_id', Request::getInt('poll_id', 0, 'GET'), 'POST');
64
$topic_id = Request::getInt('topic_id', Request::getInt('topic_id', 0, 'GET'), 'POST');
65
66
// deal with permissions
67
68
$topicHandler = Helper::getInstance()->getHandler('Topic');
69
$topicObject  = $topicHandler->get($topic_id);
70
// topic exist
71
if (is_object($topicObject)) {
72
    $forum_id = $topicObject->getVar('forum_id');
73
} else {
74
    redirect_header(XOOPS_URL . '/index.php', 2, _MD_NEWBB_POLLMODULE_ERROR . ': ' . _MD_NEWBB_FORUMNOEXIST);
75
}
76
// forum access permission
77
$forumHandler = Helper::getInstance()->getHandler('Forum');
78
/** @var Forum $forumObject */
79
$forumObject = $forumHandler->get($forum_id);
80
if (!$forumHandler->getPermission($forumObject)) {
81
    redirect_header(XOOPS_URL . '/index.php', 2, _MD_NEWBB_NORIGHTTOACCESS);
82
}
83
// topic view permission
84
if (!$topicHandler->getPermission($forumObject, $topicObject->getVar('topic_status'), 'view')) {
85
    redirect_header('viewforum.php?forum=' . $forum_id, 2, _MD_NEWBB_NORIGHTTOVIEW);
86
}
87
// poll module
88
/** @var \XoopsModuleHandler $moduleHandler */
89
$moduleHandler     = xoops_getHandler('module');
90
$pollModuleHandler = $moduleHandler->getByDirname($GLOBALS['xoopsModuleConfig']['poll_module']);
91
$classPoll = null;
92
$pollObject = null;
93
$xpPollHandler = null;
94
if (is_object($pollModuleHandler) && $pollModuleHandler->getVar('isactive')) {
95
    // new xoopspoll module
96
    if ($pollModuleHandler->getVar('version') >= 201) {
97
        /** @var \XoopsModules\Xoopspoll\PollHandler $xpPollHandler */
98
        $xpPollHandler = $pollHelper->getHandler('Poll');
99
        /** @var \XoopsModules\Xoopspoll\Poll $pollObject */
100
        $pollObject = $xpPollHandler->get($poll_id); // will create poll if poll_id = 0 exist
101
    } elseif ($pollModuleHandler->getVar('version') >= 140) {
102
        xoops_load('constants', $GLOBALS['xoopsModuleConfig']['poll_module']);
103
        xoops_load('pollUtility', $GLOBALS['xoopsModuleConfig']['poll_module']);
104
        xoops_load('request', $GLOBALS['xoopsModuleConfig']['poll_module']);
105
        xoops_loadLanguage('admin', $GLOBALS['xoopsModuleConfig']['poll_module']);
106
        $xpPollHandler = xoops_getModuleHandler('poll', $GLOBALS['xoopsModuleConfig']['poll_module']);
107
        $poll_obj      = $xpPollHandler->get($poll_id); // will create poll if poll_id = 0 exist
108
        // old xoopspoll or umfrage or any clone from them
109
    } else {
110
        require_once $GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/include/constants.php');
111
        $classPoll  = $topicObject->loadOldPoll();
112
        $pollObject = new $classPoll($poll_id); // will create poll if poll_id = 0 exist
113
    }
114
} else {
115
    // irmtfan - issue with javascript:history.go(-1)
116
    redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_POLLMODULE_ERROR);
117
}
118
// include header
119
require_once $GLOBALS['xoops']->path('header.php');
120
121
// no admin user permission
122
if (is_object($GLOBALS['xoopsUser']) && !newbbIsAdmin($forumObject)) {
123
    $perm = false;
124
    if ($topicHandler->getPermission($forumObject, $topicObject->getVar('topic_status'), 'addpoll')) {
125
        if (in_array($op, ['add', 'save', 'update'], true) && !$topicObject->getVar('topic_haspoll')
126
            && ($GLOBALS['xoopsUser']->getVar('uid') == $topicObject->getVar('topic_poster'))) {
127
            $perm = true;
128
        } elseif (!empty($poll_id) && ($GLOBALS['xoopsUser']->getVar('uid') == $pollObject->getVar('user_id'))) {
129
            $perm = true;
130
        }
131
    }
132
    if (!$perm) {
133
        redirect_header("viewtopic.php?topic_id={$topic_id}", 2, _NOPERM);
134
    }
135
}
136
switch ($op) {
137
    case 'add':
138
        // new xoopspoll module
139
        if ($pollModuleHandler->getVar('version') >= 201) {
140
            echo '<h4>' . _MD_NEWBB_POLL_CREATNEWPOLL . "</h4>\n";
141
            $pollObject->renderForm(Request::getString('SCRIPT_NAME', '', 'SERVER'), 'post', ['topic_id' => $topic_id]);
142
        } elseif ($pollModuleHandler->getVar('version') >= 140) {
143
            echo '<h4>' . _MD_NEWBB_POLL_CREATNEWPOLL . "</h4>\n";
144
            $pollObject->renderForm(Request::getString('SCRIPT_NAME', '', 'SERVER'), 'post', ['topic_id' => $topic_id]);
145
            // old xoopspoll or umfrage or any clone from them
146
        } else {
147
            $classOption  = $classPoll . 'Option';
148
            $poll_form    = new \XoopsThemeForm(_MD_NEWBB_POLL_CREATNEWPOLL, 'poll_form', 'polls.php', 'post', true);
149
            $author_label = new \XoopsFormLabel(
150
                _MD_NEWBB_POLL_AUTHOR,
151
                is_object($GLOBALS['xoopsUser']) ? ("<a href='"
152
                                                    . XOOPS_URL
153
                                                    . '/userinfo.php?uid='
154
                                                    . $GLOBALS['xoopsUser']->getVar('uid')
155
                                                    . "'>"
156
                                                    . newbbGetUnameFromId($GLOBALS['xoopsUser']->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname'])
157
                                                    . '</a>') : $GLOBALS['xoopsConfig']['anonymous']
158
            );
159
            $poll_form->addElement($author_label);
160
            $question_text = new \XoopsFormText(_MD_NEWBB_POLL_POLLQUESTION, 'question', 50, 255);
161
            $poll_form->addElement($question_text);
162
            $desc_tarea = new \XoopsFormTextArea(_MD_NEWBB_POLL_POLLDESC, 'description');
163
            $poll_form->addElement($desc_tarea);
164
            $currenttime = formatTimestamp(time(), 'Y-m-d H:i:s');
165
            $endtime     = formatTimestamp(time() + 604800, 'Y-m-d H:i:s');
166
            $expire_text = new \XoopsFormText(_MD_NEWBB_POLL_EXPIRATION . '<br><small>' . _MD_NEWBB_POLL_FORMAT . '<br>' . sprintf(_MD_NEWBB_POLL_CURRENTTIME, $currenttime) . '</small>', 'end_time', 30, 19, $endtime);
167
            $poll_form->addElement($expire_text);
168
169
            $weight_text = new \XoopsFormText(_MD_NEWBB_POLL_DISPLAYORDER, 'weight', 6, 5, 0);
170
            $poll_form->addElement($weight_text);
171
172
            $multi_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_ALLOWMULTI, 'multiple', 0);
173
            $poll_form->addElement($multi_yn);
174
175
            $notify_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', 1);
176
            $poll_form->addElement($notify_yn);
177
178
            $option_tray    = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, '');
179
            $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars/'));
180
            for ($i = 0; $i < 10; ++$i) {
181
                $current_bar = ('blank.gif' !== current($barcolor_array)) ? current($barcolor_array) : next($barcolor_array);
182
                $option_text = new \XoopsFormText('', 'option_text[]', 50, 255);
183
                $option_tray->addElement($option_text);
184
                $color_select = new \XoopsFormSelect('', "option_color[{$i}]", $current_bar);
185
                $color_select->addOptionArray($barcolor_array);
186
                $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/" . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars", "", "' . XOOPS_URL . "\")'");
187
                $color_label = new \XoopsFormLabel(
188
                    '',
189
                    "<img src='" . XOOPS_URL . '/modules/' . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars/' . $current_bar . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' width='30' align='bottom' height='15' alt='' ><br>"
190
                );
191
                $option_tray->addElement($color_select);
192
                $option_tray->addElement($color_label);
193
                if (!next($barcolor_array)) {
194
                    reset($barcolor_array);
195
                }
196
                unset($color_select, $color_label);
197
            }
198
            $poll_form->addElement($option_tray);
199
200
            $poll_form->addElement(new \XoopsFormHidden('op', 'save'));
201
            $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
202
            $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
203
            $poll_form->addElement(new \XoopsFormHidden('user_id', is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0));
204
            $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit'));
205
            echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . '</h4>';
206
            $poll_form->display();
207
        }
208
        break; // op: add
209
    case 'edit':
210
        // new xoopspoll module
211
        if ($pollModuleHandler->getVar('version') >= 201) {
212
            echo '<h4>' . _MD_NEWBB_POLL_EDITPOLL . "</h4>\n";
213
            $pollObject->renderForm(Request::getString('SCRIPT_NAME', '', 'SERVER'), 'post', ['topic_id' => $topic_id]);
214
        } elseif ($pollModuleHandler->getVar('version') >= 140) {
215
            echo '<h4>' . _MD_NEWBB_POLL_EDITPOLL . "</h4>\n";
216
            $pollObject->renderForm(Request::getString('SCRIPT_NAME', '', 'SERVER'), 'post', ['topic_id' => $topic_id]);
217
            // old xoopspoll or umfrage or any clone from them
218
        } else {
219
            $classOption  = $classPoll . 'Option';
220
            $poll_form    = new \XoopsThemeForm(_MD_NEWBB_POLL_EDITPOLL, 'poll_form', 'polls.php', 'post', true);
221
            $author_label = new \XoopsFormLabel(_MD_NEWBB_POLL_AUTHOR, "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $pollObject->getVar('user_id') . "'>" . newbbGetUnameFromId($pollObject->getVar('user_id'), $GLOBALS['xoopsModuleConfig']['show_realname']) . '</a>');
222
            $poll_form->addElement($author_label);
223
            $question_text = new \XoopsFormText(_MD_NEWBB_POLL_POLLQUESTION, 'question', 50, 255, $pollObject->getVar('question', 'E'));
224
            $poll_form->addElement($question_text);
225
            $desc_tarea = new \XoopsFormTextArea(_MD_NEWBB_POLL_POLLDESC, 'description', $pollObject->getVar('description', 'E'));
226
            $poll_form->addElement($desc_tarea);
227
            $date = formatTimestamp($pollObject->getVar('end_time'), 'Y-m-d H:i:s'); // important "Y-m-d H:i:s" use in jdf function
228
            if ($pollObject->hasExpired()) {
229
                // irmtfan full URL - add topic_id
230
                $restart_label = new \XoopsFormLabel(
231
                    _MD_NEWBB_POLL_EXPIRATION,
232
                    sprintf(_MD_NEWBB_POLL_EXPIREDAT, $date) . "<br><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/polls.php?op=restart&amp;poll_id={$poll_id}&amp;topic_id={$topic_id}'>" . _MD_NEWBB_POLL_RESTART . '</a>'
233
                );
234
                $poll_form->addElement($restart_label);
235
            } else {
236
                $expire_text = new \XoopsFormText(_MD_NEWBB_POLL_EXPIRATION . '<br><small>' . _MD_NEWBB_POLL_FORMAT . '<br>' . sprintf(_MD_NEWBB_POLL_CURRENTTIME, formatTimestamp(time(), 'Y-m-d H:i:s')) . '</small>', 'end_time', 20, 19, $date);
237
                $poll_form->addElement($expire_text);
238
            }
239
            $weight_text = new \XoopsFormText(_MD_NEWBB_POLL_DISPLAYORDER, 'weight', 6, 5, $pollObject->getVar('weight'));
240
            $poll_form->addElement($weight_text);
241
            $multi_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_ALLOWMULTI, 'multiple', $pollObject->getVar('multiple'));
242
            $poll_form->addElement($multi_yn);
243
            $options_arr  = &$classOption::getAllByPollId($poll_id);
244
            $notify_value = 1;
245
            if (0 !== $pollObject->getVar('mail_status')) {
246
                $notify_value = 0;
247
            }
248
            $notify_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', $notify_value);
249
            $poll_form->addElement($notify_yn);
250
            $option_tray    = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, '');
251
            $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/"));
252
            $i              = 0;
253
            foreach ($options_arr as $option) {
254
                /** @var \XoopsPoll $option */
255
                $option_tray->addElement(new \XoopsFormText('', 'option_text[]', 50, 255, $option->getVar('option_text')));
256
                $option_tray->addElement(new \XoopsFormHidden('option_id[]', $option->getVar('option_id')));
257
                $color_select = new \XoopsFormSelect('', 'option_color[{$i}]', $option->getVar('option_color'));
258
                $color_select->addOptionArray($barcolor_array);
259
                $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[" . $i . "]\", \"modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'");
260
                $color_label = new \XoopsFormLabel(
261
                    '',
262
                    "<img src='"
263
                    . $GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/" . $option->getVar('option_color', 'E'))
264
                    . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' class='alignbottom' width='30' height='15' alt='' ><br>"
265
                );
266
                $option_tray->addElement($color_select);
267
                $option_tray->addElement($color_label);
268
                unset($color_select, $color_label);
269
                ++$i;
270
            }
271
            // irmtfan full URL
272
            $more_label = new \XoopsFormLabel('', "<br><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/polls.php?op=addmore&amp;poll_id={$poll_id}&amp;topic_id={$topic_id}'>" . _MD_NEWBB_POLL_ADDMORE . '</a>');
273
            $option_tray->addElement($more_label);
274
            $poll_form->addElement($option_tray);
275
            $poll_form->addElement(new \XoopsFormHidden('op', 'update'));
276
            $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
277
            $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
278
            $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit'));
279
280
            echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n";
281
            $poll_form->display();
282
        }
283
        break; // op: edit
284
    case 'save':
285
        // new xoopspoll module
286
        if ($pollModuleHandler->getVar('version') >= 201) {
287
            $xpPollHandler->insert($pollObject);
288
            // old xoopspoll or umfrage or any clone from them
289
        } elseif ($pollModuleHandler->getVar('version') >= 140) {
290
        } // old xoopspoll or umfrage or any clone from them
291
        elseif ($pollModuleHandler->getVar('version') < 140) {
292
            //        if ($pollModuleHandler->getVar('version') >= 140) {
293
            // check security token
294
            if (!$GLOBALS['xoopsSecurity']->check()) {
295
                redirect_header(Request::getString('SCRIPT_NAME', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
296
            }
297
            /*
298
             * The option check should be done before submitting
299
             */
300
            $option_empty = true;
301
            if (!Request::getString('option_text', '', 'POST')) {
302
                // irmtfan - issue with javascript:history.go(-1)
303
                redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !');
304
            }
305
            $option_text = Request::getArray('option_text', '', 'POST');
306
            foreach ($option_text as $optxt) {
307
                if ('' !== trim((string) $optxt)) {
308
                    $option_empty = false;
309
                    break;
310
                }
311
            }
312
            if ($option_empty) {
313
                // irmtfan - issue with javascript:history.go(-1)
314
                redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !');
315
            }
316
            $pollObject->setVar('question', Request::getString('question', '', 'POST'));
317
            $pollObject->setVar('description', Request::getString('description', '', 'POST'));
318
            $end_time = Request::getString('end_time', '', 'POST'); // (empty($_POST['end_time'])) ? "" : $_POST['end_time'];
319
            if ('' !== $end_time) {
320
                $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null;
321
                $pollObject->setVar('end_time', userTimeToServerTime(strtotime((string) $end_time), $timezone));
322
            } else {
323
                // if expiration date is not set, set it to 10 days from now
324
                $pollObject->setVar('end_time', time() + (86400 * 10));
325
            }
326
327
            $pollObject->setVar('display', 0);
328
            $pollObject->setVar('weight', Request::getInt('weight', 0, 'POST'));
329
            $pollObject->setVar('multiple', Request::getInt('multiple', 0, 'POST'));
330
            $pollObject->setVar('user_id', Request::getInt('user_id', 0, 'POST'));
331
            if (Request::getInt('notify', 0, 'POST') && $end_time > time()) {
332
                // if notify, set mail status to "not mailed"
333
                $pollObject->setVar('mail_status', PollConstants::POLL_NOT_MAILED);
334
            } else {
335
                // if not notify, set mail status to already "mailed"
336
                $pollObject->setVar('mail_status', PollConstants::POLL_MAILED);
337
            }
338
            $new_poll_id = $pollObject->store();
339
            if (empty($new_poll_id)) {
340
                xoops_error($pollObject->getHtmlErrors);
341
                break;
342
            }
343
            $i            = 0;
344
            $option_color = Request::getArray('option_color', null, 'POST');
345
            $classOption  = $classPoll . 'Option';
346
            foreach ($option_text as $optxt) {
347
                $optxt = trim((string) $optxt);
348
                /** @var \XoopsModules\Xoopspoll\Option $optionObject */
349
                $optionObject = new $classOption();
350
                if ('' !== $optxt) {
351
                    $optionObject->setVar('option_text', $optxt);
352
                    $optionObject->setVar('option_color', $option_color[$i]);
353
                    $optionObject->setVar('poll_id', $new_poll_id);
354
                    $optionObject->store();
0 ignored issues
show
Deprecated Code introduced by
The function XoopsModules\Xoopspoll\Option::store() has been deprecated: since Xoopspoll 1.40, please @see XoopspollOptionHandler & @see XoopspollOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

354
                    /** @scrutinizer ignore-deprecated */ $optionObject->store();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
355
                }
356
                ++$i;
357
            }
358
            // clear the template cache so changes take effect immediately
359
            require_once $GLOBALS['xoops']->path('class/template.php');
360
            xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid'));
361
            xoops_template_clear_module_cache($pollModuleHandler->getVar('mid'));
362
363
            // update topic to indicate it has a poll
364
            $topicObject->setVar('topic_haspoll', 1);
365
            $topicObject->setVar('poll_id', $new_poll_id);
366
            $success = $topicHandler->insert($topicObject);
367
            if ($success) {
368
                redirect_header("viewtopic.php?topic_id={$topic_id}", 2, _MD_NEWBB_POLL_DBUPDATED);
369
            } else {
370
                xoops_error($topicHandler->getHtmlErrors());
371
            }
372
            break; // op: save
373
        }
374
    // no break
375
    case 'update':
376
        // check security token
377
        //        if (!$GLOBALS['xoopsSecurity']->check()) {
378
        //            redirect_header(Request::getString('SCRIPT_NAME', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
379
        //        }
380
        /* make sure there's at least one option */
381
382
        $option_text   = Request::getString('option_text', '', 'POST');
383
        $option_string = is_array($option_text) ? implode('', $option_text) : $option_text;
384
        $option_string = trim((string) $option_string);
385
        if ('' === $option_string) {
386
            redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !');
387
        }
388
389
        // new xoopspoll module
390
        if ($pollModuleHandler->getVar('version') >= 201) {
391
            /** @var \XoopsModules\Xoopspoll\OptionHandler $xpOptHandler */
392
            $xpOptHandler = $pollHelper->getHandler('Option');
393
            /** @var \XoopsModules\Xoopspoll\LogHandler $xpLogHandler */
394
            $xpLogHandler = $pollHelper->getHandler('Log');
395
396
            //            $xpOptHandler = xoops_getModuleHandler('option', $GLOBALS['xoopsModuleConfig']['poll_module']);
397
            //            $xpLogHandler = xoops_getModuleHandler('log', $GLOBALS['xoopsModuleConfig']['poll_module']);
398
            //            $classRequest = ucfirst($GLOBALS['xoopsModuleConfig']["poll_module"]) . "Request";
399
            //            $classConstants   = ucfirst($GLOBALS['xoopsModuleConfig']['poll_module']) . 'Constants';
400
            $notify           = Request::getInt('notify', PollConstants::NOTIFICATION_ENABLED, 'POST');
401
            $currentTimestamp = time();
402
403
            //$xuEndTimestamp   = method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime(Request::getString('xu_end_time', null, 'POST'))
404
            //                                                             : strtotime(Request::getString('xu_end_time', null, 'POST'));
405
            $xuEndTimestamp = strtotime((string) Request::getString('xu_end_time', null, 'POST'));
406
            $endTimestamp   = (!Request::getString('xu_end_time', null, 'POST')) ? ($currentTimestamp + PollConstants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuEndTimestamp);
407
            //$xuStartTimestamp = method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime(Request::getString('xu_start_time', null, 'POST'))
408
            //                                                             : strtotime(Request::getString('xu_start_time', null, 'POST'));
409
            $xuStartTimestamp = strtotime((string) Request::getString('xu_start_time', null, 'POST'));
410
            $startTimestamp   = (!Request::getString('xu_start_time', null, 'POST')) ? ($endTimestamp - PollConstants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuStartTimestamp);
411
412
            //  don't allow changing start time if there are votes in the log
413
            if (($startTimestamp < $pollObject->getVar('start_time'))
414
                && ($xpLogHandler->getTotalVotesByPollId($poll_id) > 0)) {
415
                $startTimestamp = $pollObject->getVar('start_time'); //don't change start time
416
            }
417
418
            $poll_vars = [
419
                'user_id'     => Request::getInt('user_id', $GLOBALS['xoopsUser']->uid(), 'POST'),
420
                'question'    => Request::getString('question', null, 'POST'),
421
                'description' => Request::getText('description', null, 'POST'),
422
                'mail_status' => (PollConstants::NOTIFICATION_ENABLED == $notify) ? PollConstants::POLL_NOT_MAILED : PollConstants::POLL_MAILED,
423
                'mail_voter'  => Request::getInt('mail_voter', PollConstants::NOT_MAIL_POLL_TO_VOTER, 'POST'),
424
                'start_time'  => $startTimestamp,
425
                'end_time'    => $endTimestamp,
426
                'display'     => Request::getInt('display', PollConstants::DO_NOT_DISPLAY_POLL_IN_BLOCK, 'POST'),
427
                'visibility'  => Request::getInt('visibility', PollConstants::HIDE_NEVER, 'POST'),
428
                'weight'      => Request::getInt('weight', PollConstants::DEFAULT_WEIGHT, 'POST'),
429
                'multiple'    => Request::getInt('multiple', PollConstants::NOT_MULTIPLE_SELECT_POLL, 'POST'),
430
                'multilimit'  => Request::getInt('multilimit', PollConstants::MULTIPLE_SELECT_LIMITLESS, 'POST'),
431
                'anonymous'   => Request::getInt('anonymous', PollConstants::ANONYMOUS_VOTING_DISALLOWED, 'POST'),
432
            ];
433
            $pollObject->setVars($poll_vars);
434
            $poll_id = $xpPollHandler->insert($pollObject);
435
            if (!$poll_id) {
436
                $err = $pollObject->getHtmlErrors();
437
                exit($err);
438
            }
439
440
            // now get the options
441
            $optionIdArray    = Request::getArray('option_id', [], 'POST');
442
            $optionIdArray    = array_map('\intval', $optionIdArray);
443
            $optionTextArray  = Request::getArray('option_text', [], 'POST');
444
            $optionColorArray = Request::getArray('option_color', [], 'POST');
445
446
            foreach ($optionIdArray as $key => $oId) {
447
                if ($oId !== 0 && ($optionObject = $xpOptHandler->get($oId))) {
448
                    // existing option object so need to update it
449
                    $optionTextArray[$key] = trim((string) $optionTextArray[$key]);
450
                    if ('' === $optionTextArray[$key]) {
451
                        // want to delete this option
452
                        if (false !== $xpOptHandler->delete($optionObject)) {
453
                            // now remove it from the log
454
                            $xpLogHandler->deleteByOptionId($optionObject->getVar('option_id'));
455
                            //update vote count in poll
456
                            $xpPollHandler->updateCount($pollObject);
457
                        } else {
458
                            xoops_error($xpLogHandler->getHtmlErrors());
459
                            break;
460
                        }
461
                    } else {
462
                        $optionObject->setVar('option_text', $optionTextArray[$key]);
463
                        $optionObject->setVar('option_color', $optionColorArray[$key]);
464
                        $optionObject->setVar('poll_id', $poll_id);
465
                        $xpOptHandler->insert($optionObject);
466
                    }
467
                } else {
468
                    // new option object
469
                    $optionObject          = $xpOptHandler->create();
470
                    $optionTextArray[$key] = trim((string) $optionTextArray[$key]);
471
                    if ('' !== $optionTextArray[$key]) { // ignore if text is empty
472
                        $optionObject->setVar('option_text', $optionTextArray[$key]);
473
                        $optionObject->setVar('option_color', $optionColorArray[$key]);
474
                        $optionObject->setVar('poll_id', $poll_id);
475
                        $xpOptHandler->insert($optionObject);
476
                    }
477
                    unset($optionObject);
478
                }
479
            }
480
        } elseif ($pollModuleHandler->getVar('version') >= 140) {
481
            //        if ($pollModuleHandler->getVar('version') >= 140) {
482
            $xpOptHandler = xoops_getModuleHandler('option', $GLOBALS['xoopsModuleConfig']['poll_module']);
483
            $xpLogHandler = xoops_getModuleHandler('log', $GLOBALS['xoopsModuleConfig']['poll_module']);
484
            //            $classRequest = ucfirst($GLOBALS['xoopsModuleConfig']["poll_module"]) . "Request";
485
            $classConstants   = ucfirst((string) $GLOBALS['xoopsModuleConfig']['poll_module']) . 'Constants';
486
            $notify           = XoopsRequest::getInt('notify', $classConstants::NOTIFICATION_ENABLED, 'POST');
487
            $currentTimestamp = time();
488
489
            //$xuEndTimestamp   = method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime(Request::getString('xu_end_time', null, 'POST'))
490
            //                                                             : strtotime(Request::getString('xu_end_time', null, 'POST'));
491
            $xuEndTimestamp = strtotime((string) Request::getString('xu_end_time', null, 'POST'));
492
            $endTimestamp   = (!Request::getString('xu_end_time', null, 'POST')) ? ($currentTimestamp + $classConstants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuEndTimestamp);
493
            //$xuStartTimestamp = method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime(Request::getString('xu_start_time', null, 'POST'))
494
            //                                                             : strtotime(Request::getString('xu_start_time', null, 'POST'));
495
            $xuStartTimestamp = strtotime((string) Request::getString('xu_start_time', null, 'POST'));
496
            $startTimestamp   = (!Request::getString('xu_start_time', null, 'POST')) ? ($endTimestamp - $classConstants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuStartTimestamp);
497
498
            //  don't allow changing start time if there are votes in the log
499
            if (($startTimestamp < $pollObject->getVar('start_time'))
500
                && ($xpLogHandler->getTotalVotesByPollId($poll_id) > 0)) {
501
                $startTimestamp = $pollObject->getVar('start_time'); //don't change start time
502
            }
503
504
            $poll_vars = [
505
                'user_id'     => Request::getInt('user_id', $GLOBALS['xoopsUser']->uid(), 'POST'),
506
                'question'    => Request::getString('question', null, 'POST'),
507
                'description' => Request::getText('description', null, 'POST'),
508
                'mail_status' => ($classConstants::NOTIFICATION_ENABLED == $notify) ? $classConstants::POLL_NOT_MAILED : $classConstants::POLL_MAILED,
509
                'mail_voter'  => Request::getInt('mail_voter', $classConstants::NOT_MAIL_POLL_TO_VOTER, 'POST'),
510
                'start_time'  => $startTimestamp,
511
                'end_time'    => $endTimestamp,
512
                'display'     => Request::getInt('display', $classConstants::DO_NOT_DISPLAY_POLL_IN_BLOCK, 'POST'),
513
                'visibility'  => Request::getInt('visibility', $classConstants::HIDE_NEVER, 'POST'),
514
                'weight'      => Request::getInt('weight', $classConstants::DEFAULT_WEIGHT, 'POST'),
515
                'multiple'    => Request::getInt('multiple', $classConstants::NOT_MULTIPLE_SELECT_POLL, 'POST'),
516
                'multilimit'  => Request::getInt('multilimit', $classConstants::MULTIPLE_SELECT_LIMITLESS, 'POST'),
517
                'anonymous'   => Request::getInt('anonymous', $classConstants::ANONYMOUS_VOTING_DISALLOWED, 'POST'),
518
            ];
519
            $pollObject->setVars($poll_vars);
520
            $poll_id = $xpPollHandler->insert($pollObject);
521
            if (!$poll_id) {
522
                $err = $pollObject->getHtmlErrors();
523
                exit($err);
524
            }
525
526
            // now get the options
527
            $optionIdArray    = Request::getArray('option_id', [], 'POST');
528
            $optionIdArray    = array_map('\intval', $optionIdArray);
529
            $optionTextArray  = Request::getArray('option_text', [], 'POST');
530
            $optionColorArray = Request::getArray('option_color', [], 'POST');
531
532
            foreach ($optionIdArray as $key => $oId) {
533
                if ($oId !== 0 && ($optionObject = $xpOptHandler->get($oId))) {
534
                    // existing option object so need to update it
535
                    $optionTextArray[$key] = trim((string) $optionTextArray[$key]);
536
                    if ('' === $optionTextArray[$key]) {
537
                        // want to delete this option
538
                        if (false !== $xpOptHandler->delete($optionObject)) {
539
                            // now remove it from the log
540
                            $xpLogHandler->deleteByOptionId($optionObject->getVar('option_id'));
541
                            //update vote count in poll
542
                            $xpPollHandler->updateCount($pollObject);
543
                        } else {
544
                            xoops_error($xpLogHandler->getHtmlErrors());
545
                            break;
546
                        }
547
                    } else {
548
                        $optionObject->setVar('option_text', $optionTextArray[$key]);
549
                        $optionObject->setVar('option_color', $optionColorArray[$key]);
550
                        $optionObject->setVar('poll_id', $poll_id);
551
                        $xpOptHandler->insert($optionObject);
552
                    }
553
                } else {
554
                    // new option object
555
                    $optionObject          = $xpOptHandler->create();
556
                    $optionTextArray[$key] = trim((string) $optionTextArray[$key]);
557
                    if ('' !== $optionTextArray[$key]) { // ignore if text is empty
558
                        $optionObject->setVar('option_text', $optionTextArray[$key]);
559
                        $optionObject->setVar('option_color', $optionColorArray[$key]);
560
                        $optionObject->setVar('poll_id', $poll_id);
561
                        $xpOptHandler->insert($optionObject);
562
                    }
563
                    unset($optionObject);
564
                }
565
            }
566
            // old xoopspoll or umfrage or any clone from them
567
        } else {
568
            $pollObject->setVar('question', Request::getString('question', '', 'POST'));
569
            $pollObject->setVar('description', Request::getString('description', '', 'POST'));
570
            $classConstants = ucfirst((string) $GLOBALS['xoopsModuleConfig']['poll_module']) . 'Constants';
571
572
            $end_time = Request::getString('end_time', '', 'POST');
573
            if ('' !== $end_time) {
574
                $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null;
575
                $pollObject->setVar('end_time', userTimeToServerTime(strtotime((string) $end_time), $timezone));
576
            }
577
            $pollObject->setVar('display', 0);
578
            $pollObject->setVar('weight', Request::getInt('weight', 0, 'POST'));
579
            $pollObject->setVar('multiple', Request::getInt('multiple', 0, 'POST'));
580
            $pollObject->setVar('user_id', Request::getInt('user_id', 0, 'POST'));
581
            if (Request::getInt('notify', 0, 'POST') && $end_time > time()) {
582
                // if notify, set mail status to "not mailed"
583
                $pollObject->setVar('mail_status', $classConstants::POLL_NOT_MAILED);
584
            } else {
585
                // if not notify, set mail status to already "mailed"
586
                $pollObject->setVar('mail_status', $classConstants::POLL_MAILED);
587
            }
588
589
            if (!$pollObject->store()) {
590
                xoops_error($pollObject->getHtmlErrors);
591
                break;
592
            }
593
            $i            = 0;
594
            $option_id    = Request::getArray('option_id', null, 'POST');
595
            $option_color = Request::getArray('option_color', null, 'POST');
596
            $classOption  = $classPoll . 'Option';
597
            $classLog     = $classPoll . 'Log';
598
            foreach ($option_id as $opid) {
599
                $optionObject    = new $classOption($opid);
600
                $option_text[$i] = trim((string) $option_text[$i]);
601
                if ('' !== $option_text[$i]) {
602
                    $optionObject->setVar('option_text', $option_text[$i]);
603
                    $optionObject->setVar('option_color', $option_color[$i]);
604
                    $optionObject->store();
605
                } elseif (false !== $optionObject->delete()) {
606
                    $classLog::deleteByOptionId($option->getVar('option_id'));
607
                }
608
                ++$i;
609
            }
610
            $pollObject->updateCount();
611
        }
612
        // clear the template cache so changes take effect immediately
613
        require_once $GLOBALS['xoops']->path('class/template.php');
614
        xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid'));
615
        xoops_template_clear_module_cache($pollModuleHandler->getVar('mid'));
616
617
        // update topic to indicate it has a poll
618
        $topicObject->setVar('topic_haspoll', 1);
619
        $topicObject->setVar('poll_id', $pollObject->getVar('poll_id'));
620
        $success = $topicHandler->insert($topicObject);
621
        if ($success) {
622
            redirect_header("viewtopic.php?topic_id={$topic_id}", 2, _MD_NEWBB_POLL_DBUPDATED);
623
        } else {
624
            xoops_error($topicHandler->getHtmlErrors());
625
        }
626
        break; // op: save | update
627
    case 'addmore':
628
        $question = $pollObject->getVar('question');
629
        unset($pollObject);
630
        $poll_form = new \XoopsThemeForm(_MD_NEWBB_POLL_ADDMORE, 'poll_form', 'polls.php', 'post', true);
631
        $poll_form->addElement(new \XoopsFormLabel(_MD_NEWBB_POLL_POLLQUESTION, $question));
632
        // new xoopspoll module
633
        if ($pollModuleHandler->getVar('version') >= 201) {
634
            $xpOptHandler = $pollHelper->getHandler('Option');
635
            $option_tray  = $xpOptHandler->renderOptionFormTray($poll_id);
636
        } elseif ($pollModuleHandler->getVar('version') >= 140) {
637
            $xpOptHandler = xoops_getModuleHandler('option', $GLOBALS['xoopsModuleConfig']['poll_module']);
638
            $option_tray  = $xpOptHandler->renderOptionFormTray($poll_id);
639
            // old xoopspoll or umfrage or any clone from them
640
        } else {
641
            $option_tray    = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, '');
642
            $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars/'));
643
            for ($i = 0; $i < 10; ++$i) {
644
                $current_bar = ('blank.gif' !== current($barcolor_array)) ? current($barcolor_array) : next($barcolor_array);
645
                $option_text = new \XoopsFormText('', 'option_text[]', 50, 255);
646
                $option_tray->addElement($option_text);
647
                $color_select = new \XoopsFormSelect('', "option_color[{$i}]", $current_bar);
648
                $color_select->addOptionArray($barcolor_array);
649
                $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'");
650
                $color_label = new \XoopsFormLabel(
651
                    '',
652
                    "<img src='" . $GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/{$current_bar}") . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' class='alignbottom' width='30' height='15' alt='' ><br>"
653
                );
654
                $option_tray->addElement($color_select);
655
                $option_tray->addElement($color_label);
656
                unset($color_select, $color_label, $option_text);
657
                if (!next($barcolor_array)) {
658
                    reset($barcolor_array);
659
                }
660
            }
661
        }
662
        $poll_form->addElement($option_tray);
663
        $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit'));
664
        $poll_form->addElement(new \XoopsFormHidden('op', 'savemore'));
665
        $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
666
        $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
667
668
        echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n";
669
        $poll_form->display();
670
        break;
671
    case 'savemore':
672
        // check security token
673
        if (!$GLOBALS['xoopsSecurity']->check()) {
674
            redirect_header(Request::getString('SCRIPT_NAME', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
675
        }
676
677
        $option_text   = Request::getString('option_text', '', 'POST');
678
        $option_string = is_array($option_text) ? implode('', $option_text) : $option_text;
679
        $option_string = trim((string) $option_string);
680
        if ('' === $option_string) {
681
            // irmtfan - issue with javascript:history.go(-1)
682
            redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !');
683
        }
684
        $i            = 0;
685
        $option_color = Request::getArray('option_color', null, 'POST');
686
        foreach ($option_text as $optxt) {
687
            $optxt = trim((string) $optxt);
688
            if ('' !== $optxt) {
689
                // new xoopspoll module
690
                if ($pollModuleHandler->getVar('version') >= 201) {
691
                    $xpOptHandler = $pollHelper->getHandler('Option');
692
                    $optionObject = $xpOptHandler->create();
693
                    $optionObject->setVar('option_text', $optxt);
694
                    $optionObject->setVar('poll_id', $poll_id);
695
                    $optionObject->setVar('option_color', $option_color[$i]);
696
                    $xpOptHandler->insert($optionObject);
697
                } elseif ($pollModuleHandler->getVar('version') >= 140) {
698
                    $xpOptHandler = xoops_getModuleHandler('option', $GLOBALS['xoopsModuleConfig']['poll_module']);
699
                    $optionObject = $xpOptHandler->create();
700
                    $optionObject->setVar('option_text', $optxt);
701
                    $optionObject->setVar('poll_id', $poll_id);
702
                    $optionObject->setVar('option_color', $option_color[$i]);
703
                    $xpOptHandler->insert($optionObject);
704
                    // old xoopspoll or umfrage or any clone from them
705
                } else {
706
                    $classOption  = $classPoll . 'Option';
707
                    $optionObject = new $classOption();
708
                    $optionObject->setVar('option_text', $optxt);
709
                    $optionObject->setVar('poll_id', $poll_id);
710
                    $optionObject->setVar('option_color', $option_color[$i]);
711
                    $optionObject->store();
712
                }
713
                unset($optionObject);
714
            }
715
            ++$i;
716
        }
717
        require_once $GLOBALS['xoops']->path('class/template.php');
718
        xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid'));
719
        xoops_template_clear_module_cache($pollModuleHandler->getVar('mid'));
720
        redirect_header("polls.php?op=edit&amp;poll_id={$poll_id}&amp;topic_id={$topic_id}", 2, _MD_NEWBB_POLL_DBUPDATED);
721
        break;
722
    case 'delete':
723
        echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n";
724
        xoops_confirm(['op' => 'delete_ok', 'topic_id' => $topic_id, 'poll_id' => $poll_id], 'polls.php', sprintf(_MD_NEWBB_POLL_RUSUREDEL, $pollObject->getVar('question')));
725
        break;
726
    case 'delete_ok':
727
        // check security token
728
        if (!$GLOBALS['xoopsSecurity']->check()) {
729
            redirect_header(Request::getString('SCRIPT_NAME', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
730
        }
731
        //try and delete the poll
732
        // new xoopspoll module
733
        if ($pollModuleHandler->getVar('version') >= 201) {
734
            $status = $xpPollHandler->delete($pollObject);
735
            if (false !== $status) {
736
                $xpOptHandler = $pollHelper->getHandler('Option');
737
                $xpLogHandler = $pollHelper->getHandler('Log');
738
                $xpOptHandler->deleteByPollId($poll_id);
739
                $xpLogHandler->deleteByPollId($poll_id);
740
            } else {
741
                $msg = $xpPollHandler->getHtmlErrors();
742
            }
743
        } elseif ($pollModuleHandler->getVar('version') >= 140) {
744
            $status = $xpPollHandler->delete($poll_obj);
745
            if (false !== $status) {
746
                $xpOptHandler = xoops_getModuleHandler('option', $GLOBALS['xoopsModuleConfig']['poll_module']);
747
                $xpLogHandler = xoops_getModuleHandler('log', $GLOBALS['xoopsModuleConfig']['poll_module']);
748
                $xpOptHandler->deleteByPollId($poll_id);
749
                $xpLogHandler->deleteByPollId($poll_id);
750
            } else {
751
                $msg = $xpPollHandler->getHtmlErrors();
752
            }
753
            // old xoopspoll or umfrage or any clone from them
754
        } else {
755
            $status      = $pollObject->delete();
756
            $classOption = $classPoll . 'Option';
757
            $classLog    = $classPoll . 'Log';
758
            if (false !== $status) {
759
                $classOption::deleteByPollId($poll_id);
760
                $classLog::deleteByPollId($poll_id);
761
            } else {
762
                $msg = $pollObject->getHtmlErrors();
763
            }
764
        }
765
        if (false !== $status) {
766
            require_once $GLOBALS['xoops']->path('class/template.php');
767
            xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
768
            xoops_template_clear_module_cache($pollModuleHandler->getVar('mid'));
769
            // delete comments for this poll
770
            xoops_comment_delete($xoopsModule->getVar('mid'), $poll_id);
771
772
            $topicObject->setVar('votes', 0); // not sure why we want to clear votes too... but I left it alone
773
            $topicObject->setVar('topic_haspoll', 0);
774
            $topicObject->setVar('poll_id', 0);
775
            $success = $topicHandler->insert($topicObject);
776
            if (!$success) {
777
                xoops_error($topicHandler->getHtmlErrors());
778
                break;
779
            }
780
        } else {
781
            xoops_error($msg);
782
            break;
783
        }
784
        redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id={$topic_id}", 1, _MD_NEWBB_POLL_DBUPDATED);
785
        break;
786
    case 'restart':
787
        // new xoopspoll module
788
        if ($pollModuleHandler->getVar('version') >= 201) {
789
            $default_poll_duration = PollConstants::DEFAULT_POLL_DURATION;
790
        } elseif ($pollModuleHandler->getVar('version') >= 140) {
791
            $classConstants        = ucfirst((string) $GLOBALS['xoopsModuleConfig']['poll_module']) . 'Constants';
792
            $default_poll_duration = $classConstants::DEFAULT_POLL_DURATION;
793
            // old xoopspoll or umfrage or any clone from them
794
        } else {
795
            $default_poll_duration = (86400 * 10);
796
        }
797
        $poll_form   = new \XoopsThemeForm(_MD_NEWBB_POLL_RESTARTPOLL, 'poll_form', 'polls.php', 'post', true);
798
        $expire_text = new \XoopsFormText(
799
            _MD_NEWBB_POLL_EXPIRATION . '<br><small>' . _MD_NEWBB_POLL_FORMAT . '<br>' . sprintf(_MD_NEWBB_POLL_CURRENTTIME, formatTimestamp(time(), 'Y-m-d H:i:s')) . '<br>' . sprintf(
800
                _MD_NEWBB_POLL_EXPIREDAT,
801
                formatTimestamp($pollObject->getVar('end_time'), 'Y-m-d H:i:s')
802
            ) . '</small>',
803
            'end_time',
804
            20,
805
            19,
806
            formatTimestamp(time() + $default_poll_duration, 'Y-m-d H:i:s')
807
        );
808
        $poll_form->addElement($expire_text);
809
        $poll_form->addElement(new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', 1));
810
        $poll_form->addElement(new \XoopsFormRadioYN(_MD_NEWBB_POLL_RESET, 'reset', 0));
811
        $poll_form->addElement(new \XoopsFormHidden('op', 'restart_ok'));
812
        $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
813
        $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
814
        $poll_form->addElement(new \XoopsFormButton('', 'poll_submit', _MD_NEWBB_POLL_RESTART, 'submit'));
815
816
        echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n";
817
        $poll_form->display();
818
        break;
819
    case 'restart_ok':
820
        // check security token
821
        if (!$GLOBALS['xoopsSecurity']->check()) {
822
            redirect_header(Request::getString('SCRIPT_NAME', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
823
        }
824
825
        // new xoopspoll module
826
        if ($pollModuleHandler->getVar('version') >= 201) {
827
            //            $classConstants        = new XoopsModules\Xoopspoll\Constants();
828
            $default_poll_duration = PollConstants::DEFAULT_POLL_DURATION;
829
            $poll_not_mailed       = PollConstants::POLL_NOT_MAILED;
830
            $poll_mailed           = PollConstants::POLL_MAILED;
831
        } elseif ($pollModuleHandler->getVar('version') >= 140) {
832
            $classConstants        = ucfirst((string) $GLOBALS['xoopsModuleConfig']['poll_module']) . 'Constants';
833
            $default_poll_duration = $classConstants::DEFAULT_POLL_DURATION;
834
            $poll_not_mailed       = $classConstants::POLL_NOT_MAILED;
835
            $poll_mailed           = $classConstants::POLL_MAILED;
836
            // old xoopspoll or umfrage or any clone from them
837
        } else {
838
            $default_poll_duration = (86400 * 10);
839
            $poll_not_mailed       = PollConstants::POLL_NOT_MAILED;
840
            $poll_mailed           = PollConstants::POLL_MAILED;
841
        }
842
843
        $end_time = !Request::getInt('end_time', 0, 'POST');
844
        if (0 !== $end_time) {
845
            $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null;
846
            $pollObject->setVar('end_time', userTimeToServerTime(strtotime($end_time), $timezone));
847
        } else {
848
            $pollObject->setVar('end_time', time() + $default_poll_duration);
849
        }
850
851
        $isNotify = Request::getInt('notify', 0, 'POST');
852
        if (!empty($isNotify) && ($end_time > time())) {
853
            // if notify, set mail status to "not mailed"
854
            $pollObject->setVar('mail_status', $poll_not_mailed);
855
        } else {
856
            // if not notify, set mail status to already "mailed"
857
            $pollObject->setVar('mail_status', $poll_mailed);
858
        }
859
860
        // new xoopspoll module
861
        if ($pollModuleHandler->getVar('version') >= 201) {
862
            if (!$xpPollHandler->insert($pollObject)) {  // update the poll
863
                xoops_error($pollObject->getHtmlErrors());
864
                exit();
865
            }
866
            if (Request::getInt('reset', 0, 'POST')) { // reset all vote/voter counters
867
                /** @var \XoopsModules\Xoopspoll\OptionHandler $xpOptHandler */
868
                $xpOptHandler = $pollHelper->getHandler('Option');
869
                /** @var \XoopsModules\Xoopspoll\LogHandler $xpLogHandler */
870
                $xpLogHandler = $pollHelper->getHandler('Log');
871
                $xpLogHandler->deleteByPollId($poll_id);
872
                $xpOptHandler->resetCountByPollId($poll_id);
873
                $xpPollHandler->updateCount($pollObject);
874
            }
875
        } elseif ($pollModuleHandler->getVar('version') >= 140) {
876
            if (!$xpPollHandler->insert($poll_obj)) {  // update the poll
877
                xoops_error($poll_obj->getHtmlErrors());
878
                exit();
879
            }
880
            if (XoopsRequest::getInt('reset', 0, 'POST')) { // reset all vote/voter counters
881
                $xpOptHandler = xoops_getModuleHandler('option', $GLOBALS['xoopsModuleConfig']['poll_module']);
882
                $xpLogHandler = xoops_getModuleHandler('log', $GLOBALS['xoopsModuleConfig']['poll_module']);
883
                $xpLogHandler->deleteByPollId($poll_id);
884
                $xpOptHandler->resetCountByPollId($poll_id);
885
                $xpPollHandler->updateCount($poll_obj);
886
            }
887
            // old xoopspoll or umfrage or any clone from them
888
        } else {
889
            if (!$pollObject->store()) { // update the poll
890
                xoops_error($pollObject->getHtmlErrors());
891
                exit();
892
            }
893
            if (Request::getInt('reset', 0, 'POST')) { // reset all logs
894
                $classOption = $classPoll . 'Option';
895
                $classLog    = $classPoll . 'Log';
896
                $classLog::deleteByPollId($poll_id);
897
                $classOption::resetCountByPollId($poll_id);
898
                $pollObject->updateCount();
899
            }
900
        }
901
        require_once $GLOBALS['xoops']->path('class/template.php');
902
        xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
903
        xoops_template_clear_module_cache($pollModuleHandler->getVar('mid'));
904
        redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id={$topic_id}", 1, _MD_NEWBB_POLL_DBUPDATED);
905
        break;
906
    case 'log':
907
        // new xoopspoll module
908
        if ($pollModuleHandler->getVar('version') >= 201) {
909
            $pollHelper->redirect('admin/main.php?op=log&amp;poll_id={$poll_id}', 2, _MD_NEWBB_POLL_VIEWLOG);
910
        } elseif ($pollModuleHandler->getVar('version') >= 140) {
911
            redirect_header($GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/admin/main.php?op=log&amp;poll_id={$poll_id}"), 2, _MD_NEWBB_POLL_VIEWLOG);
912
            // old xoopspoll or umfrage or any clone from them
913
        } else {
914
            redirect_header($GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/admin/index.php?op=log&amp;poll_id={$poll_id}"), 2, _MD_NEWBB_POLL_VIEWLOG);
915
        }
916
        break;
917
} // switch
918
919
// irmtfan move to footer.php
920
require_once __DIR__ . '/footer.php';
921
require_once $GLOBALS['xoops']->path('footer.php');
922