Issues (371)

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.

extras/newbb_5x/irmtfan/polls.php (11 issues)

Labels
1
<?php declare(strict_types=1);
2
/*
3
 * Newbb module
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * Poll handling for Newbb
15
 *
16
 * @copyright       {@link https://xoops.org/ XOOPS Project}
17
 * @license         {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later}
18
 * @since           4.0
19
 * @author          Taiwen Jiang <[email protected]>
20
 */
21
22
use Xmf\Request;
23
use XoopsModules\Newbb;
24
use XoopsModules\Xoopspoll;
25
use XoopsModules\Xoopspoll\Constants;
26
27
require_once __DIR__ . '/header.php';
28
29
require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
30
require_once $GLOBALS['xoops']->path('class/xoopslists.php');
31
require_once $GLOBALS['xoops']->path('class/xoopsblock.php');
32
33
// irmtfan correct the way and typo=addmor -> addmore
34
$op      = 'add';
35
$goodOps = [
36
    'add',
37
    'save',
38
    'edit',
39
    'update',
40
    'addmore',
41
    'savemore',
42
    'delete',
43
    'delete_ok',
44
    'restart',
45
    'restart_ok',
46
    'log',
47
];
48
$op      = Request::getString('op', 'add');
49
$op      = (!in_array($op, $goodOps, true)) ? 'add' : $op;
50
51
//$poll_id  = (isset($_GET['poll_id']))   ? (int)($_GET['poll_id'])   : 0;
52
//$poll_id  = (isset($_POST['poll_id']))  ? (int)($_POST['poll_id'])  : $poll_id;
53
$poll_id = Request::getInt('poll_id', Request::getInt('poll_id', 0, 'POST'), 'GET');
54
//$topic_id = (isset($_GET['topic_id']))  ? (int)($_GET['topic_id'])  : 0;
55
//$topic_id = (isset($_POST['topic_id'])) ? (int)($_POST['topic_id']) : $topic_id;
56
$topic_id = Request::getInt('topic_id', Request::getInt('topic_id', 0, 'POST'), 'GET');
57
58
/** {@internal $pollmodules is initialized in ./header.php file} */
59
if ('xoopspoll' === $pollmodules) {
60
    xoops_loadLanguage('admin', 'xoopspoll');
61
    $xpPollHandler = Xoopspoll\Helper::getInstance()->getHandler('Poll');
62
} else {
63
    //is this umfrage?
64
    if ('umfrage' === $pollmodules) {
65
        require $GLOBALS['xoops']->path('modules/umfrage/include/constants.php');
66
        require_once $GLOBALS['xoops']->path('modules/umfrage/class/umfrage.php');
67
        require_once $GLOBALS['xoops']->path('modules/umfrage/class/umfrageoption.php');
68
        require_once $GLOBALS['xoops']->path('modules/umfrage/class/umfragelog.php');
69
        require_once $GLOBALS['xoops']->path('modules/umfrage/class/umfragerenderer.php');
70
    } else {
71
        // irmtfan - issue with javascript:history.go(-1)
72
        redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_POLLMODULE_ERROR);
73
    }
74
}
75
/** @var Newbb\TopicHandler $topicHandler */
76
$topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
77
$topic_obj    = $topicHandler->get($topic_id);
78
if ($topic_obj instanceof Newbb\Topic) {
79
    $forum_id = $topic_obj->getVar('forum_id');
80
} else {
81
    redirect_header('index.php', 2, _MD_POLLMODULE_ERROR . ': ' . _MD_FORUMNOEXIST);
82
}
83
84
/** @var Newbb\ForumHandler $forumHandler */
85
$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum');
86
$forum_obj    = $forumHandler->get($forum_id);
87
if (!$forumHandler->getPermission($forum_obj)) {
88
    redirect_header('index.php', 2, _MD_NORIGHTTOACCESS);
89
}
90
91
if (!$topicHandler->getPermission($forum_obj, $topic_obj->getVar('topic_status'), 'view')) {
92
    redirect_header('viewforum.php?forum=' . $forum_obj->getVar('forum_id'), 2, _MD_NORIGHTTOVIEW);
93
}
94
95
require $GLOBALS['xoops']->path('header.php');
96
97
if (!newbb_isAdmin($forum_obj)) {
0 ignored issues
show
The function newbb_isAdmin was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

97
if (!/** @scrutinizer ignore-call */ newbb_isAdmin($forum_obj)) {
Loading history...
98
    $perm = false;
99
    if ($topicHandler->getPermission($forum_obj, $topic_obj->getVar('topic_status'), 'addpoll')//&& $forum_obj->getVar('allow_polls') == 1 {
100
    ) {
101
        //        if (('add' === $op || 'save' === $op || 'update' === $op)
102
        if (($GLOBALS['xoopsUser'] instanceof \XoopsUser)
103
            && in_array($op, ['add', 'save', 'update'], true)
104
            && !$topic_obj->getVar('topic_haspoll')
105
            && ($GLOBALS['xoopsUser']->getVar('uid') === $topic_obj->getVar('topic_poster'))) {
106
            $perm = true;
107
        } elseif (($GLOBALS['xoopsUser'] instanceof \XoopsUser) && !empty($poll_id)) {
108
            if ('xoopspoll' === $pollmodules) {
109
                $poll_obj = $xpPollHandler->get($poll_id);
110
            } else { //Umfrage
111
                $poll_obj = new \Umfrage($poll_id);
0 ignored issues
show
The type Umfrage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
112
            }
113
            if ($GLOBALS['xoopsUser']->getVar('uid') === $poll_obj->getVar('user_id')) {
114
                $perm = true;
115
            }
116
            unset($poll_obj);
117
        }
118
    }
119
    if (!$perm) {
120
        redirect_header("viewtopic.php?topic_id={$topic_id}", 2, _NOPERM);
121
    }
122
}
123
124
switch ($op) {
125
    /*
126
    case "add":
127
        if ("xoopspoll" == $pollmodules) {
128
            echo "<h4>" . _AM_XOOPSPOLL_POLLCONF . "</h4>\n";
129
            $poll_obj = $xpPollHandler->get($poll_id);
130
            $poll_obj->renderForm($_SERVER['SCRIPT_NAME'], 'post', array("topic_id" => $topic_id));
131
        } else { // Umfrage
132
            $poll_form = new \XoopsThemeForm(_MD_POLL_CREATNEWPOLL, "poll_form", "polls.php", "post", true);
133
134
            $question_text = new \XoopsFormText(_MD_POLL_POLLQUESTION, "question", 50, 255);
135
            $poll_form->addElement($question_text, true);
136
137
            $desc_tarea = new \XoopsFormTextarea(_MD_POLL_POLLDESC, "description");
138
            $poll_form->addElement($desc_tarea);
139
140
    //        $currenttime = formatTimestamp(time(), "Y-m-d H:i:s");
141
    //        $endtime = formatTimestamp(time() + 604800, "Y-m-d H:i:s");
142
            $currenttime = formatTimestamp(time(), _DATESTRING);
143
            $endtime = formatTimestamp(time() + (86400 * 10), _DATESTRING);
144
145
            $expire_text = new \XoopsFormText(_MD_POLL_EXPIRATION . "<br><small>" . _MD_POLL_FORMAT . "<br>" . sprintf(_MD_POLL_CURRENTTIME, $currenttime) . "</small>", "end_time", 30, 19, $endtime);
146
            $poll_form->addElement($expire_text);
147
148
            $weight_text = new \XoopsFormText(_MD_POLL_DISPLAYORDER, "weight", 6, 5, 0);
149
            $poll_form->addElement($weight_text);
150
151
            $multi_yn = new \XoopsFormRadioYN(_MD_POLL_ALLOWMULTI, "multiple", 0);
152
            $poll_form->addElement($multi_yn);
153
154
            $notify_yn = new \XoopsFormRadioYN(_MD_POLL_NOTIFY, "notify", 1);
155
            $poll_form->addElement($notify_yn);
156
157
            $option_tray = new \XoopsFormElementTray(_MD_POLL_POLLOPTIONS, "");
158
            $barcolor_array = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . "/modules/{$pollmodules}/assets/images/colorbars/");
159
            for ($i = 0; $i < 10; ++$i) {
160
                $current_bar = ("blank.gif" != current($barcolor_array)) ? current($barcolor_array) : next($barcolor_array);
161
                $option_text = new \XoopsFormText("", "option_text[]", 50, 255);
162
                $option_tray->addElement($option_text);
163
                $color_select = new \XoopsFormSelect("", "option_color[{$i}]", $current_bar);
164
                $color_select->addOptionArray($barcolor_array);
165
                $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/{$pollmodules}/assets/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'");
166
                $color_label = new \XoopsFormLabel("", "<img src='" . XOOPS_URL . "/modules/{$pollmodules}/assets/images/colorbars/{$current_bar}' name='option_color_image[{$i}]' id='option_color_image[{$i}]' width='30' class='alignbottom' height='15' alt=''><br>");
167
                $option_tray->addElement($color_select);
168
                $option_tray->addElement($color_label);
169
                if (!next($barcolor_array)) {
170
                    reset($barcolor_array);
171
                }
172
                unset($color_select, $color_label);
173
            }
174
            $poll_form->addElement($option_tray);
175
            $poll_form->addElement(new \XoopsFormButton("", "poll_submit", _SUBMIT, "submit"));
176
            $poll_form->addElement(new \XoopsFormHidden("op", "save"));
177
            $poll_form->addElement(new \XoopsFormHidden("topic_id", $topic_id));
178
179
            echo "<h4>" . _MD_POLL_POLLCONF . "</h4>\n";
180
            $poll_form->display();
181
        }
182
        break;
183
184
    case "save":
185
        // check security token
186
        if (!$GLOBALS['xoopsSecurity']->check()) {
187
            redirect_header($_SERVER['SCRIPT_NAME'], 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
188
        }
189
190
        // make sure the question isn't empty
191
        if (empty($_POST['question'])) {
192
            redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_ERROROCCURED . ': ' . _MD_POLL_POLLQUESTION . ' !');
193
        }
194
195
        // Check to see if any options are set
196
        $option_text = isset($_POST['option_text']) ? $_POST['option_text'] : "";
197
        $option_string = is_array($option_text) ? implode("", $option_text) : $option_text;
198
        $option_string = trim($option_string);
199
        if (empty($option_string)) {
200
            // irmtfan - issue with javascript:history.go(-1)
201
            redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_ERROROCCURED . ': ' . _MD_POLL_POLLOPTIONS . ' !');
202
        }
203
204
        if ("xoopspoll" == $pollmodules) {
205
    //        $poll_obj = $xpPollHandler->create();
206
            $poll_obj = $xpPollHandler->get($poll_id); // will either get or create poll obj
207
            $default_poll_duration = Constants::DEFAULT_POLL_DURATION;
208
            $poll_not_mailed       = Constants::POLL_NOT_MAILED;
209
            $poll_mailed           = Constants::POLL_MAILED;
210
            $display               = Constants::DO_NOT_DISPLAY_POLL_IN_BLOCK;
211
        } else { // Umfrage
212
    //        $poll_obj = new Umfrage();
213
            if (empty($poll_id)) {  //if creating new poll
214
                $poll_obj = new Umfrage();
215
            } else { // updating current poll
216
                $poll_obj = new Umfrage($poll_id);
217
            }
218
            $default_poll_duration = (86400 * 10);
219
            $poll_not_mailed = POLL_NOT_MAILED;
220
            $poll_mailed     = POLL_MAILED;
221
            $display         = 0;
222
        }
223
224
        $poll_obj->setVar("question", $_POST['question']);
225
        $description = (isset($_POST['description'])) ? htmlspecialchars($_POST['description']) : '';
226
        $poll_obj->setVar("description", $description);
227
228
       if (Request::hasVar('end_time', 'POST')) {
229
            $timezone = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getVar("timezone") : null;
230
            //$poll_obj->setVar("end_time", userTimeToServerTime(strtotime($_POST['end_time']), $timezone));
231
            //Hack by irmtfan
232
            $poll_obj->setVar("end_time", userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($_POST['end_time']) : strtotime($_POST['end_time']), $timezone));
233
        } else {
234
            // if expiration date is not set, set it
235
            $poll_obj->setVar("end_time", time() + $default_poll_duration);
236
        }
237
238
        $weight   = isset($_POST['weight'])    ? (int)($_POST['weight']) : 0;
239
        $multiple = isset($_POST['multiple'])  ? (int)($_POST['multiple']) : 0;
240
        $notify   = (!empty($_POST["notify"])) ? $poll_not_mailed : $poll_mailed;
241
        $uid      = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getVar("uid") : 0;
242
243
        $poll_obj->setVar("display",  $display);
244
        $poll_obj->setVar("weight", $weight);
245
        $poll_obj->setVar("multiple", $multiple);
246
        $poll_obj->setVar("mail_status", $notify);
247
        $poll_obj->setVar("user_id", $uid);
248
249
        if ('xoopspoll' == $pollmodules) {
250
            $poll_obj = $xpPollHandler->insert($poll_obj);
251
            $new_poll_id = ($poll_obj instanceof \Xoopspoll\Poll) ? $poll_obj->getVar('poll_id') : null;
252
        } else { // Umfrage
253
            $new_poll_id = $poll_obj->store();
254
        }
255
        $option_color = Request::getString('option_color', null, 'POST');
256
        if (!empty($new_poll_id)) {
257
            $i = 0;
258
            foreach ($option_text as $optxt) {
259
                $optxt = trim($optxt);
260
                if ("" != $optxt) {
261
                    if ('xoopspoll' == $pollmodules) {
262
                        $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
263
                        $option = $xpOptHandler->create();
264
                        $option->setVar("option_text", $optxt);
265
                        $option->setVar("option_color", $option_color[$i]);
266
                        $option->setVar("poll_id", $new_poll_id);
267
                        $xpOptHandler->insert($option);
268
                    } else { // Umfrage
269
                        $option = new UmfrageOption();
270
                        $option->setVar("option_text", $optxt);
271
                        $option->setVar("option_color", $option_color[$i]);
272
                        $option->setVar("poll_id", $new_poll_id);
273
                        $option->store();
274
                    }
275
                }
276
                ++$i;
277
            }
278
            // update topic to indicate it has a poll
279
            $topic_obj->setVar('topic_haspoll', 1);
280
            $topic_obj->setVar('poll_id', $new_poll_id);
281
            $success = $topicHandler->insert($topic_obj);
282
            if (!$success) {
283
                xoops_error($topicHandler->getHtmlErrors());
284
            }
285
286
    //        $sql = "UPDATE " . $GLOBALS['xoopsDB']->prefix("bb_topics") . " SET topic_haspoll = 1, poll_id = {$new_poll_id} WHERE topic_id = {$topic_id}";
287
    //        if (!$result = $GLOBALS['xoopsDB']->query($sql) ) {
288
    //            xoops_error($GLOBALS['xoopsDB']->error());
289
            }
290
291
            require_once $GLOBALS['xoops']->path("class/template.php");
292
            xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid'));
293
            xoops_template_clear_module_cache($xoopspoll->getVar('mid'));
294
        } else {
295
            xoops_error($poll_obj->getHtmlErrors());
296
            exit();
297
        }
298
        // irmtfan full URL
299
        redirect_header($GLOBALS['xoops']->url("modules/".$xoopsModule->getVar("dirname")."/viewtopic.php?topic_id={$topic_id}"), 1, _MD_POLL_DBUPDATED);
300
        break;
301
    */
302
    case 'add':
303
    case 'edit':
304
        if ('xoopspoll' === $pollmodules) {
305
            echo '<h4>' . _MD_POLL_EDITPOLL . "</h4>\n";
306
            $poll_obj = $xpPollHandler->get($poll_id); // will create poll if poll_id = 0 exist
307
            $poll_obj->renderForm($_SERVER['SCRIPT_NAME'], 'post', ['topic_id' => $topic_id]);
308
        } else { // Umfrage
309
            if (empty($poll_id)) {
310
                $poll_obj = new \Umfrage();
311
            } else {
312
                $poll_obj = new \Umfrage($poll_id);
313
            }
314
            $poll_form    = new \XoopsThemeForm(_MD_POLL_EDITPOLL, 'poll_form', 'polls.php', 'post', true);
315
            $author_label = new \XoopsFormLabel(_MD_POLL_AUTHOR, "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $poll_obj->getVar('user_id') . "'>" . newbb_getUnameFromId($poll_obj->getVar('user_id'), $GLOBALS['xoopsModuleConfig']['show_realname']) . '</a>');
0 ignored issues
show
The function newbb_getUnameFromId was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

315
            $author_label = new \XoopsFormLabel(_MD_POLL_AUTHOR, "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $poll_obj->getVar('user_id') . "'>" . /** @scrutinizer ignore-call */ newbb_getUnameFromId($poll_obj->getVar('user_id'), $GLOBALS['xoopsModuleConfig']['show_realname']) . '</a>');
Loading history...
316
            $poll_form->addElement($author_label);
317
            $question_text = new \XoopsFormText(_MD_POLL_POLLQUESTION, 'question', 50, 255, $poll_obj->getVar('question', 'E'));
318
            $poll_form->addElement($question_text);
319
            $desc_tarea = new \XoopsFormTextarea(_MD_POLL_POLLDESC, 'description', $poll_obj->getVar('description', 'E'));
320
            $poll_form->addElement($desc_tarea);
321
            //        $date = formatTimestamp($poll_obj->getVar("end_time"), "Y-m-d H:i:s");
322
            $date = formatTimestamp($poll_obj->getVar('end_time'), _DATESTRING);
323
            if (!$poll_obj->hasExpired()) {
324
                $expire_text = new \XoopsFormText(_MD_POLL_EXPIRATION . '<br><small>' . _MD_POLL_FORMAT . '<br>' . sprintf(_MD_POLL_CURRENTTIME, formatTimestamp(time(), 'Y-m-d H:i:s')) . '</small>', 'end_time', 20, 19, $date);
325
                $poll_form->addElement($expire_text);
326
            } else {
327
                // irmtfan full URL - add topic_id
328
                $restart_label = new \XoopsFormLabel(_MD_POLL_EXPIRATION, sprintf(_MD_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_POLL_RESTART . '</a>');
329
                $poll_form->addElement($restart_label);
330
            }
331
            $weight_text = new \XoopsFormText(_MD_POLL_DISPLAYORDER, 'weight', 6, 5, $poll_obj->getVar('weight'));
332
            $poll_form->addElement($weight_text);
333
            $multi_yn = new \XoopsFormRadioYN(_MD_POLL_ALLOWMULTI, 'multiple', $poll_obj->getVar('multiple'));
334
            $poll_form->addElement($multi_yn);
335
            $options_arr  = &(new UmfrageOption())->getAllByPollId($poll_id);
0 ignored issues
show
The type UmfrageOption was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
336
            $notify_value = 1;
337
            if (0 !== $poll_obj->getVar('mail_status')) {
338
                $notify_value = 0;
339
            }
340
            $notify_yn = new \XoopsFormRadioYN(_MD_POLL_NOTIFY, 'notify', $notify_value);
341
            $poll_form->addElement($notify_yn);
342
            $option_tray    = new \XoopsFormElementTray(_MD_POLL_POLLOPTIONS, '');
343
            $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path("modules/{$pollmodules}/assets/images/colorbars/"));
344
            $i              = 0;
345
            foreach ($options_arr as $option) {
346
                $option_tray->addElement(new \XoopsFormText('', 'option_text[]', 50, 255, $option->getVar('option_text')));
347
                $option_tray->addElement(new \XoopsFormHidden('option_id[]', $option->getVar('option_id')));
348
                $color_select = new \XoopsFormSelect('', "option_color[{$i}]", $option->getVar('option_color'));
349
                $color_select->addOptionArray($barcolor_array);
350
                $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[" . $i . "]\", \"modules/{$pollmodules}/assets/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'");
351
                $color_label = new \XoopsFormLabel(
352
                    '',
353
                    "<img src='" . $GLOBALS['xoops']->url("modules/{$pollmodules}/assets/images/colorbars/" . $option->getVar('option_color', 'E')) . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' class='alignbottom' width='30' height='15' alt=''><br>"
354
                );
355
                $option_tray->addElement($color_select);
356
                $option_tray->addElement($color_label);
357
                unset($color_select, $color_label);
358
                ++$i;
359
            }
360
            // irmtfan full URL
361
            $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_POLL_ADDMORE . '</a>');
362
            $option_tray->addElement($more_label);
363
            $poll_form->addElement($option_tray);
364
            $poll_form->addElement(new \XoopsFormHidden('op', 'update'));
365
            $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
366
            $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
367
            //        $poll_form->addElement(new \XoopsFormButton("", "poll_submit", _SUBMIT, "submit"));
368
            $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit'));
369
370
            echo '<h4>' . _MD_POLL_POLLCONF . "</h4>\n";
371
            $poll_form->display();
372
        }
373
        break;
374
    case 'save':
375
    case 'update':
376
        // check security token
377
        if (!$GLOBALS['xoopsSecurity']->check()) {
378
            redirect_header($_SERVER['SCRIPT_NAME'], 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
379
        }
380
381
        /* make sure there's at least one option */
382
        $option_text   = Request::getString('option_text', '', 'POST');
383
        $option_string = trim(is_array($option_text) ? implode('', $option_text) : $option_text);
0 ignored issues
show
The condition is_array($option_text) is always false.
Loading history...
384
        if (empty($option_string)) {
385
            // irmtfan - issue with javascript:history.go(-1)
386
            redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_ERROROCCURED . ': ' . _MD_POLL_POLLOPTIONS . ' !');
387
        }
388
389
        if ('xoopspoll' === $pollmodules) {
390
            $poll_obj     = $xpPollHandler->get($poll_id);
391
            $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
392
            $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log');
393
394
            $notify = Request::getInt('notify', Constants::NOTIFICATION_ENABLED, 'POST');
395
396
            $currentTimestamp = time();
397
            $xuEndTimestamp   = strtotime(Request::getString('xu_end_time', null, 'POST'));
398
            $endTimestamp     = empty($xuEndTimestamp) ? ($currentTimestamp + Constants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuEndTimestamp);
399
            $xuStartTimestamp = strtotime(Request::getString('xu_start_time', null, 'POST'));
400
            $startTimestamp   = empty($xuStartTimestamp) ? ($endTimestamp - Constants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuStartTimestamp);
401
402
            //  don't allow changing start time if there are votes in the log
403
            if (($startTimestamp < $poll_obj->getVar('start_time'))
404
                && ($xpLogHandler->getTotalVotesByPollId($poll_id) > 0)) {
405
                $startTimestamp = $poll_obj->getVar('start_time'); //don't change start time
406
            }
407
408
            $poll_vars = [
409
                'user_id'     => Request::getInt('user_id', $GLOBALS['xoopsUser']->uid(), 'POST'),
410
                'question'    => Request::getString('question', null, 'POST'),
411
                'description' => Request::getText('description', null, 'POST'),
412
                'mail_status' => (Constants::NOTIFICATION_ENABLED === $notify) ? Constants::POLL_NOT_MAILED : Constants::POLL_MAILED,
413
                'mail_voter'  => Request::getInt('mail_voter', Constants::NOT_MAIL_POLL_TO_VOTER, 'POST'),
414
                'start_time'  => $startTimestamp,
415
                'end_time'    => $endTimestamp,
416
                'display'     => Request::getInt('display', Constants::DO_NOT_DISPLAY_POLL_IN_BLOCK, 'POST'),
417
                'visibility'  => Request::getInt('visibility', Constants::HIDE_NEVER, 'POST'),
418
                'weight'      => Request::getInt('weight', Constants::DEFAULT_WEIGHT, 'POST'),
419
                'multiple'    => Request::getInt('multiple', Constants::NOT_MULTIPLE_SELECT_POLL, 'POST'),
420
                'multilimit'  => Request::getInt('multilimit', Constants::MULTIPLE_SELECT_LIMITLESS, 'POST'),
421
                'anonymous'   => Request::getInt('anonymous', Constants::ANONYMOUS_VOTING_DISALLOWED, 'POST'),
422
            ];
423
            $poll_obj->setVars($poll_vars);
424
            $poll_id = $xpPollHandler->insert($poll_obj);
425
            if (!$poll_id) {
426
                $err = $poll_obj->getHtmlErrors();
427
                exit($err);
428
            }
429
430
            // now get the options
431
            $optionIdArray    = Request::getArray('option_id', [], 'POST');
432
            $optionIdArray    = array_map('\intval', $optionIdArray);
433
            $optionTextArray  = Request::getArray('option_text', [], 'POST');
434
            $optionColorArray = Request::getArray('option_color', [], 'POST');
435
436
            foreach ($optionIdArray as $key => $oId) {
437
                if (!empty($oId) && ($option_obj = $xpOptHandler->get($oId))) {
438
                    // existing option object so need to update it
439
                    $optionTextArray[$key] = trim($optionTextArray[$key]);
440
                    if ('' === $optionTextArray[$key]) {
441
                        // want to delete this option
442
                        if (false !== $xpOptHandler->delete($option_obj)) {
443
                            // now remove it from the log
444
                            $xpLogHandler->deleteByOptionId($option_obj->getVar('option_id'));
445
                            //update vote count in poll
446
                            $xpPollHandler->updateCount($poll_obj);
447
                        } else {
448
                            xoops_error($xpLogHandler->getHtmlErrors());
0 ignored issues
show
The method getHtmlErrors() does not exist on XoopsModules\Xoopspoll\LogHandler. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

448
                            xoops_error($xpLogHandler->/** @scrutinizer ignore-call */ getHtmlErrors());
Loading history...
449
                            break;
450
                        }
451
                    } else {
452
                        $option_obj->setVar('option_text', $optionTextArray[$key]);
453
                        $option_obj->setVar('option_color', $optionColorArray[$key]);
454
                        $option_obj->setVar('poll_id', $poll_id);
455
                        $xpOptHandler->insert($option_obj);
456
                    }
457
                } else {
458
                    // new option object
459
                    $option_obj            = $xpOptHandler->create();
460
                    $optionTextArray[$key] = trim($optionTextArray[$key]);
461
                    if ('' !== $optionTextArray[$key]) { // ignore if text is empty
462
                        $option_obj->setVar('option_text', $optionTextArray[$key]);
463
                        $option_obj->setVar('option_color', $optionColorArray[$key]);
464
                        $option_obj->setVar('poll_id', $poll_id);
465
                        $xpOptHandler->insert($option_obj);
466
                    }
467
                    unset($option_obj);
468
                }
469
            }
470
471
            // clear the template cache so changes take effect immediately
472
            //        require_once $GLOBALS['xoops']->path("class" . "/template.php");
473
            //        xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid'));
474
            //        xoops_template_clear_module_cache($xoopspoll->getVar('mid'));
475
            //        redirect_header("viewtopic.php?topic_id={$topic_id}", Constants::REDIRECT_DELAY_SHORT, _MD_POLL_DBUPDATED);
476
        } else { // Umfrage
477
            $poll_obj = new \Umfrage($poll_id);
478
            $poll_obj->setVar('question', @$_POST['question']);
479
            $poll_obj->setVar('description', @$_POST['description']);
480
            $end_time = Request::getString('end_time', '', 'POST');
481
            if (!empty($end_time)) {
482
                $timezone = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getVar('timezone') : null;
483
                //            $poll_obj->setVar("end_time", userTimeToServerTime(strtotime($end_time), $timezone));
484
                //Hack by Irmtfan
485
                $poll_obj->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($end_time) : strtotime($end_time), $timezone));
0 ignored issues
show
The method strtotime() does not exist on XoopsLocal. ( Ignorable by Annotation )

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

485
                $poll_obj->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::/** @scrutinizer ignore-call */ strtotime($end_time) : strtotime($end_time), $timezone));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
486
            }
487
            $poll_obj->setVar('display', 0);
488
            $poll_obj->setVar('weight', (int)(@$_POST['weight']));
489
            $poll_obj->setVar('multiple', (int)(@$_POST['multiple']));
490
            if (!empty($_POST['notify']) && $end_time > time()) {
491
                // if notify, set mail status to 'not mailed'
492
                $poll_obj->setVar('mail_status', Constants::POLL_NOT_MAILED);
493
            } else {
494
                // if not notify, set mail status to already "mailed"
495
                $poll_obj->setVar('mail_status', Constants::POLL_MAILED);
496
            }
497
498
            if (!$poll_obj->store()) {
499
                xoops_error($poll_obj->getHtmlErrors);
500
                break;
501
            }
502
            $i            = 0;
503
            $option_id    = Request::getString('option_id', null, 'POST');
504
            $option_color = Request::getString('option_color', null, 'POST');
505
            foreach ($option_id as $opid) {
0 ignored issues
show
The expression $option_id of type string is not traversable.
Loading history...
506
                $option_obj      = new \UmfrageOption($opid);
507
                $option_text[$i] = trim($option_text[$i]);
508
                if ('' !== $option_text[$i]) {
509
                    $option_obj->setVar('option_text', $option_text[$i]);
510
                    $option_obj->setVar('option_color', $option_color[$i]);
511
                    $option_obj->store();
512
                } else {
513
                    if (false !== $option_obj->delete()) {
514
                        (new UmfrageLog())->deleteByOptionId($option->getVar('option_id'));
0 ignored issues
show
The type UmfrageLog was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
515
                    }
516
                }
517
                ++$i;
518
            }
519
            $poll_obj->updateCount();
520
            //        require_once $GLOBALS['xoops']->path("class" . "/template.php");
521
            //        xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid'));
522
            //        redirect_header("viewtopic.php?topic_id={$topic_id}", 1, _MD_POLL_DBUPDATED);
523
        }
524
525
        // clear the template cache so changes take effect immediately
526
        require_once $GLOBALS['xoops']->path('class/template.php');
527
        xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid'));
528
        xoops_template_clear_module_cache($xoopspoll->getVar('mid'));
529
530
        // update topic to indicate it has a poll
531
        $topic_obj->setVar('topic_haspoll', 1);
532
        $topic_obj->setVar('poll_id', $poll_obj->getVar('poll_id'));
533
        $success = $topicHandler->insert($topic_obj);
534
        if (!$success) {
535
            xoops_error($topicHandler->getHtmlErrors());
536
        } else {
537
            redirect_header("viewtopic.php?topic_id={$topic_id}", 2, _MD_POLL_DBUPDATED);
538
        }
539
        break;
540
    case 'addmore':
541
        if ('xoopspoll' === $pollmodules) {
542
            $poll_obj     = $xpPollHandler->get($poll_id);
543
            $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
544
        } else { // Umfrage
545
            $poll_obj = new \Umfrage($poll_id);
546
        }
547
        $question = $poll_obj->getVar('question');
548
        unset($poll_obj);
549
        $poll_form = new \XoopsThemeForm(_MD_POLL_ADDMORE, 'poll_form', 'polls.php', 'post', true);
550
        $poll_form->addElement(new \XoopsFormLabel(_MD_POLL_POLLQUESTION, $question));
551
        if ('xoopspoll' === $pollmodules) {
552
            $option_tray = $xpOptHandler->renderOptionFormTray($poll_id);
553
        } else {
554
            $option_tray    = new \XoopsFormElementTray(_MD_POLL_POLLOPTIONS, '');
555
            $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path("modules/{$pollmodules}/assets/images/colorbars/"));
556
            for ($i = 0; $i < 10; ++$i) {
557
                $current_bar = ('blank.gif' !== current($barcolor_array)) ? current($barcolor_array) : next($barcolor_array);
558
                $option_text = new \XoopsFormText('', 'option_text[]', 50, 255);
559
                $option_tray->addElement($option_text);
560
                $color_select = new \XoopsFormSelect('', "option_color[{$i}]", $current_bar);
561
                $color_select->addOptionArray($barcolor_array);
562
                $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/{$pollmodules}/assets/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'");
563
                $color_label = new \XoopsFormLabel('', "<img src='" . $GLOBALS['xoops']->url("modules/{$pollmodules}/assets/images/colorbars/{$current_bar}") . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' class='alignbottom' width='30' height='15' alt=''><br>");
564
                $option_tray->addElement($color_select);
565
                $option_tray->addElement($color_label);
566
                unset($color_select, $color_label, $option_text);
567
                if (!next($barcolor_array)) {
568
                    reset($barcolor_array);
569
                }
570
            }
571
        }
572
        $poll_form->addElement($option_tray);
573
        $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit'));
574
        //    $poll_form->addElement(new \XoopsFormButton('', 'poll_submit', _SUBMIT, 'submit'));
575
        $poll_form->addElement(new \XoopsFormHidden('op', 'savemore'));
576
        $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
577
        $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
578
579
        echo '<h4>' . _MD_POLL_POLLCONF . "</h4>\n";
580
        $poll_form->display();
581
        break;
582
    case 'savemore':
583
        // check security token
584
        if (!$GLOBALS['xoopsSecurity']->check()) {
585
            redirect_header($_SERVER['SCRIPT_NAME'], 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
586
        }
587
588
        $option_text   = Request::getString('option_text', '', 'POST');
589
        $option_string = trim(is_array($option_text) ? implode('', $option_text) : $option_text);
0 ignored issues
show
The condition is_array($option_text) is always false.
Loading history...
590
        if (empty($option_string)) {
591
            // irmtfan - issue with javascript:history.go(-1)
592
            redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_ERROROCCURED . ': ' . _MD_POLL_POLLOPTIONS . ' !');
593
        }
594
595
        if ('xoopspoll' === $pollmodules) {
596
            $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
597
        }
598
        $i            = 0;
599
        $option_color = Request::getString('option_color', null, 'POST');
600
        foreach ($option_text as $optxt) {
0 ignored issues
show
The expression $option_text of type string is not traversable.
Loading history...
601
            $optxt = trim($optxt);
602
            if ('' !== $optxt) {
603
                if ('xoopspoll' === $pollmodules) {
604
                    $option_obj = $xpOptHandler->create();
605
                    $option_obj->setVar('option_text', $optxt);
606
                    $option_obj->setVar('poll_id', $poll_id);
607
                    $option_obj->setVar('option_color', $option_color[$i]);
608
                    $xpOptHandler->insert($option_obj);
609
                } else { // Umfrage
610
                    $option_obj = new \UmfrageOption();
611
                    $option_obj->setVar('option_text', $optxt);
612
                    $option_obj->setVar('poll_id', $poll_id);
613
                    $option_obj->setVar('option_color', $option_color[$i]);
614
                    $option_obj->store();
615
                }
616
                unset($option_obj);
617
            }
618
            ++$i;
619
        }
620
        require_once $GLOBALS['xoops']->path('class/template.php');
621
        xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid'));
622
        xoops_template_clear_module_cache($xoopspoll->getVar('mid'));
623
        redirect_header("polls.php?op=edit&amp;poll_id={$poll_id}&amp;topic_id={$topic_id}", 2, _MD_POLL_DBUPDATED);
624
        break;
625
    case 'delete':
626
        echo '<h4>' . _MD_POLL_POLLCONF . "</h4>\n";
627
        if ('xoopspoll' === $pollmodules) {
628
            $poll_obj = $xpPollHandler->get($poll_id);
629
        } else {
630
            $poll_obj = new \Umfrage($poll_id);
631
        }
632
        xoops_confirm(['op' => 'delete_ok', 'topic_id' => $topic_id, 'poll_id' => $poll_id], 'polls.php', sprintf(_MD_POLL_RUSUREDEL, $poll_obj->getVar('question')));
633
        break;
634
    case 'delete_ok':
635
        // check security token
636
        if (!$GLOBALS['xoopsSecurity']->check()) {
637
            redirect_header($_SERVER['SCRIPT_NAME'], 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
638
        }
639
        //try and delete the poll
640
        if ('xoopspoll' === $pollmodules) {
641
            $poll_obj = $xpPollHandler->get($poll_id);
642
            $status   = $xpPollHandler->delete($poll_obj);
643
            if (false !== $status) {
644
                $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
645
                $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log');
646
                $xpOptHandler->deleteByPollId($poll_id);
647
                $xpLogHandler->deleteByPollId($poll_id);
648
            } else {
649
                $msg = $xpPollHandler->getHtmlErrors();
650
            }
651
        } else {
652
            $poll_obj = new \Umfrage($poll_id);
653
            $status   = $poll_obj->delete();
654
            if (false !== $status) {
655
                (new UmfrageOption())->deleteByPollId($poll_id);
656
                (new UmfrageLog())->deleteByPollId($poll_id);
657
            } else {
658
                $msg = $poll_obj->getHtmlErrors();
659
            }
660
        }
661
        if (false !== $status) {
662
            require_once $GLOBALS['xoops']->path('class/template.php');
663
            xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
664
            xoops_template_clear_module_cache($xoopspoll->getVar('mid'));
665
            // delete comments for this poll
666
            xoops_comment_delete($xoopsModule->getVar('mid'), $poll_id);
667
668
            $topic_obj->setVar('votes', 0); // not sure why we want to clear votes too... but I left it alone
669
            $topic_obj->setVar('topic_haspoll', 0);
670
            $topic_obj->setVar('poll_id', 0);
671
            $success = $topicHandler->insert($topic_obj);
672
            if (!$success) {
673
                xoops_error($topicHandler->getHtmlErrors());
674
                break;
675
            }
676
            /*
677
                    $sql = "UPDATE " . $xoopsDB->prefix("bb_topics") . " SET votes = 0, topic_haspoll = 0, poll_id = 0 WHERE topic_id = {$topic_id}";
678
                    if ( !$result = $xoopsDB->query($sql) ) {
679
                        //xoops_error($xoopsDB->error());
680
                    }
681
            */
682
        } else {
683
            xoops_error($msg);
684
            break;
685
        }
686
        redirect_header("viewtopic.php?topic_id={$topic_id}", 1, _MD_POLL_DBUPDATED);
687
        break;
688
    case 'restart':
689
        if ('xoopspoll' === $pollmodules) {
690
            $default_poll_duration = Constants::DEFAULT_POLL_DURATION;
691
        } else { // Umfrage
692
            $default_poll_duration = (86400 * 10);
693
        }
694
        $poll_form = new \XoopsThemeForm(_MD_POLL_RESTARTPOLL, 'poll_form', 'polls.php', 'post', true);
695
        //    $expire_text = new \XoopsFormText(_MD_POLL_EXPIRATION . "<br><small>" . _MD_POLL_FORMAT . "<br>" . sprintf(_MD_POLL_CURRENTTIME, formatTimestamp(time(), "Y-m-d H:i:s")) . "</small>", "end_time", 20, 19, formatTimestamp(time() + 604800, "Y-m-d H:i:s"));
696
        $expire_text = new \XoopsFormText(_MD_POLL_EXPIRATION . '<br><small>' . _MD_POLL_FORMAT . '<br>' . sprintf(_MD_POLL_CURRENTTIME, formatTimestamp(time(), _DATESTRING)) . '</small>', 'end_time', 20, 19, formatTimestamp(time() + $default_poll_duration, _DATESTRING));
697
        $poll_form->addElement($expire_text);
698
        $poll_form->addElement(new \XoopsFormRadioYN(_MD_POLL_NOTIFY, 'notify', 1));
699
        $poll_form->addElement(new \XoopsFormRadioYN(_MD_POLL_RESET, 'reset', 0));
700
        $poll_form->addElement(new \XoopsFormHidden('op', 'restart_ok'));
701
        $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
702
        $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
703
        $poll_form->addElement(new \XoopsFormButton('', 'poll_submit', _MD_POLL_RESTART, 'submit'));
704
705
        echo '<h4>' . _MD_POLL_POLLCONF . "</h4>\n";
706
        $poll_form->display();
707
708
        break;
709
    case 'restart_ok':
710
        // check security token
711
        if (!$GLOBALS['xoopsSecurity']->check()) {
712
            redirect_header($_SERVER['SCRIPT_NAME'], 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
713
        }
714
715
        if ('xoopspoll' === $pollmodules) {
716
            $poll_obj              = $xpPollHandler->get($poll_id);
717
            $default_poll_duration = Constants::DEFAULT_POLL_DURATION;
718
            $poll_mailed           = Constants::POLL_MAILED;
719
            $poll_not_mailed       = Constants::POLL_NOT_MAILED;
720
        } else { // Umfrage
721
            $poll_obj              = new \Umfrage($poll_id);
722
            $default_poll_duration = (86400 * 10);
723
            $poll_not_mailed       = Constants::POLL_NOT_MAILED;
724
            $poll_mailed           = Constants::POLL_MAILED;
725
        }
726
727
        $end_time = Request::getInt('end_time', 0, 'POST');
728
        if (!empty($end_time)) {
729
            $timezone = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getVar('timezone') : null;
730
            //        $poll_obj->setVar("end_time", userTimeToServerTime(strtotime($end_time), $timezone));
731
            //Hack by irmtfan
732
            $poll_obj->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($end_time) : strtotime($end_time), $timezone));
733
        } else {
734
            $poll_obj->setVar('end_time', time() + $default_poll_duration);
735
        }
736
        if (!empty($_POST['notify']) && ($end_time > time())) {
737
            // if notify, set mail status to "not mailed"
738
            $poll_obj->setVar('mail_status', $poll_not_mailed);
739
        } else {
740
            // if not notify, set mail status to already "mailed"
741
            $poll_obj->setVar('mail_status', $poll_mailed);
742
        }
743
744
        if ('xoopspoll' === $pollmodules) {
745
            if (!$xpPollHandler->insert($poll_obj)) {  // update the poll
746
                xoops_error($poll_obj->getHtmlErrors());
747
                exit();
748
            }
749
            if (Request::hasVar('reset', 'POST')) { // reset all vote/voter counters
750
                $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log');
751
                $xpLogHandler->deleteByPollId($poll_id);
752
                $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
753
                $xpOptHandler->resetCountByPollId($poll_id);
754
                $xpPollHandler->updateCount($poll_obj);
755
            }
756
        } else {
757
            if (!$poll_obj->store()) { // update the poll
758
                xoops_error($poll_obj->getHtmlErrors());
759
                exit();
760
            }
761
            if (Request::hasVar('reset', 'POST')) { // reset all logs
762
                (new UmfrageLog())->deleteByPollId($poll_id);
763
                (new UmfrageOption())->resetCountByPollId($poll_id);
764
                $poll_obj->updateCount();
765
            }
766
        }
767
768
        // clear the topic votes
769
        /*
770
            $topic_obj->setVar('votes', 0);
771
            $success = $topicHandler->insert($topic_obj);
772
            if (!$success) {
773
                xoops_error($topicHandler->getHtmlErrors());
774
                break;
775
            }
776
        */
777
        require_once $GLOBALS['xoops']->path('class/template.php');
778
        xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
779
        xoops_template_clear_module_cache($xoopspoll->getVar('mid'));
780
        redirect_header("viewtopic.php?topic_id={$topic_id}", 1, _MD_POLL_DBUPDATED);
781
        break;
782
    case 'log':
783
        if ('xoopspoll' === $pollmodules) {
784
            redirect_header($GLOBALS['xoops']->url("modules/xoopspoll/admin/main.php?op=log&amp;poll_id={$poll_id}"), 2, _MD_LOG_XOOPSPOLL_ADMIN_REDIRECT);
785
        } else {
786
            echo '<h4>' . _MD_POLL_POLLCONF . "</h4>\n" . '<br>' . _MD_VIEW_LOG . "\n" . '<br>' . _MD_LOG_NOT_IMPLEMENTED . "\n";
787
        }
788
        break;
789
}
790
791
// irmtfan move to footer.php
792
require_once __DIR__ . '/footer.php';
793
require $GLOBALS['xoops']->path('footer.php');
794