Passed
Push — master ( 882d2a...8f67b7 )
by Michael
03:09
created
polls.php 1 patch
Switch Indentation   +574 added lines, -574 removed lines patch added patch discarded remove patch
@@ -111,213 +111,377 @@  discard block
 block discarded – undo
111 111
     }
112 112
 }
113 113
 switch ($op) {
114
-    case 'add':
115
-        // new xoopspoll module
116
-        if ($pollModuleHandler->getVar('version') >= 140) {
117
-            echo '<h4>' . _MD_NEWBB_POLL_CREATNEWPOLL . "</h4>\n";
118
-            $pollObject->renderForm(Request::getString('PHP_SELF', '', 'SERVER'), 'post', ['topic_id' => $topic_id]);
119
-        // old xoopspoll or umfrage or any clone from them
120
-        } else {
121
-            $classOption  = $classPoll . 'Option';
122
-            $poll_form    = new \XoopsThemeForm(_MD_NEWBB_POLL_CREATNEWPOLL, 'poll_form', 'polls.php', 'post', true);
123
-            $author_label = new \XoopsFormLabel(_MD_NEWBB_POLL_AUTHOR, is_object($GLOBALS['xoopsUser']) ? ("<a href='"
124
-                                                                                                          . XOOPS_URL
125
-                                                                                                          . '/userinfo.php?uid='
126
-                                                                                                          . $GLOBALS['xoopsUser']->getVar('uid')
127
-                                                                                                          . "'>"
128
-                                                                                                          . newbbGetUnameFromId($GLOBALS['xoopsUser']->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname'])
129
-                                                                                                          . '</a>') : $GLOBALS['xoopsConfig']['anonymous']);
130
-            $poll_form->addElement($author_label);
131
-            $question_text = new \XoopsFormText(_MD_NEWBB_POLL_POLLQUESTION, 'question', 50, 255);
132
-            $poll_form->addElement($question_text);
133
-            $desc_tarea = new \XoopsFormTextarea(_MD_NEWBB_POLL_POLLDESC, 'description');
134
-            $poll_form->addElement($desc_tarea);
135
-            $currenttime = formatTimestamp(time(), 'Y-m-d H:i:s');
136
-            $endtime     = formatTimestamp(time() + 604800, 'Y-m-d H:i:s');
137
-            $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);
138
-            $poll_form->addElement($expire_text);
114
+        case 'add':
115
+            // new xoopspoll module
116
+            if ($pollModuleHandler->getVar('version') >= 140) {
117
+                echo '<h4>' . _MD_NEWBB_POLL_CREATNEWPOLL . "</h4>\n";
118
+                $pollObject->renderForm(Request::getString('PHP_SELF', '', 'SERVER'), 'post', ['topic_id' => $topic_id]);
119
+            // old xoopspoll or umfrage or any clone from them
120
+            } else {
121
+                $classOption  = $classPoll . 'Option';
122
+                $poll_form    = new \XoopsThemeForm(_MD_NEWBB_POLL_CREATNEWPOLL, 'poll_form', 'polls.php', 'post', true);
123
+                $author_label = new \XoopsFormLabel(_MD_NEWBB_POLL_AUTHOR, is_object($GLOBALS['xoopsUser']) ? ("<a href='"
124
+                                                                                                              . XOOPS_URL
125
+                                                                                                              . '/userinfo.php?uid='
126
+                                                                                                              . $GLOBALS['xoopsUser']->getVar('uid')
127
+                                                                                                              . "'>"
128
+                                                                                                              . newbbGetUnameFromId($GLOBALS['xoopsUser']->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname'])
129
+                                                                                                              . '</a>') : $GLOBALS['xoopsConfig']['anonymous']);
130
+                $poll_form->addElement($author_label);
131
+                $question_text = new \XoopsFormText(_MD_NEWBB_POLL_POLLQUESTION, 'question', 50, 255);
132
+                $poll_form->addElement($question_text);
133
+                $desc_tarea = new \XoopsFormTextarea(_MD_NEWBB_POLL_POLLDESC, 'description');
134
+                $poll_form->addElement($desc_tarea);
135
+                $currenttime = formatTimestamp(time(), 'Y-m-d H:i:s');
136
+                $endtime     = formatTimestamp(time() + 604800, 'Y-m-d H:i:s');
137
+                $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);
138
+                $poll_form->addElement($expire_text);
139 139
 
140
-            $weight_text = new \XoopsFormText(_MD_NEWBB_POLL_DISPLAYORDER, 'weight', 6, 5, 0);
141
-            $poll_form->addElement($weight_text);
142
-
143
-            $multi_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_ALLOWMULTI, 'multiple', 0);
144
-            $poll_form->addElement($multi_yn);
145
-
146
-            $notify_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', 1);
147
-            $poll_form->addElement($notify_yn);
148
-
149
-            $option_tray    = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, '');
150
-            $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars/'));
151
-            for ($i = 0; $i < 10; ++$i) {
152
-                $current_bar = ('blank.gif' !== current($barcolor_array)) ? current($barcolor_array) : next($barcolor_array);
153
-                $option_text = new \XoopsFormText('', 'option_text[]', 50, 255);
154
-                $option_tray->addElement($option_text);
155
-                $color_select = new \XoopsFormSelect('', "option_color[{$i}]", $current_bar);
156
-                $color_select->addOptionArray($barcolor_array);
157
-                $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/" . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars", "", "' . XOOPS_URL . "\")'");
158
-                $color_label = new \XoopsFormLabel('', "<img src='"
159
-                                                      . XOOPS_URL
160
-                                                      . '/modules/'
161
-                                                      . $GLOBALS['xoopsModuleConfig']['poll_module']
162
-                                                      . '/assets/images/colorbars/'
163
-                                                      . $current_bar
164
-                                                      . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' width='30' align='bottom' height='15' alt='' /><br>");
165
-                $option_tray->addElement($color_select);
166
-                $option_tray->addElement($color_label);
167
-                if (!next($barcolor_array)) {
168
-                    reset($barcolor_array);
140
+                $weight_text = new \XoopsFormText(_MD_NEWBB_POLL_DISPLAYORDER, 'weight', 6, 5, 0);
141
+                $poll_form->addElement($weight_text);
142
+
143
+                $multi_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_ALLOWMULTI, 'multiple', 0);
144
+                $poll_form->addElement($multi_yn);
145
+
146
+                $notify_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', 1);
147
+                $poll_form->addElement($notify_yn);
148
+
149
+                $option_tray    = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, '');
150
+                $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars/'));
151
+                for ($i = 0; $i < 10; ++$i) {
152
+                    $current_bar = ('blank.gif' !== current($barcolor_array)) ? current($barcolor_array) : next($barcolor_array);
153
+                    $option_text = new \XoopsFormText('', 'option_text[]', 50, 255);
154
+                    $option_tray->addElement($option_text);
155
+                    $color_select = new \XoopsFormSelect('', "option_color[{$i}]", $current_bar);
156
+                    $color_select->addOptionArray($barcolor_array);
157
+                    $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/" . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars", "", "' . XOOPS_URL . "\")'");
158
+                    $color_label = new \XoopsFormLabel('', "<img src='"
159
+                                                          . XOOPS_URL
160
+                                                          . '/modules/'
161
+                                                          . $GLOBALS['xoopsModuleConfig']['poll_module']
162
+                                                          . '/assets/images/colorbars/'
163
+                                                          . $current_bar
164
+                                                          . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' width='30' align='bottom' height='15' alt='' /><br>");
165
+                    $option_tray->addElement($color_select);
166
+                    $option_tray->addElement($color_label);
167
+                    if (!next($barcolor_array)) {
168
+                        reset($barcolor_array);
169
+                    }
170
+                    unset($color_select, $color_label);
169 171
                 }
170
-                unset($color_select, $color_label);
172
+                $poll_form->addElement($option_tray);
173
+
174
+                $poll_form->addElement(new \XoopsFormHidden('op', 'save'));
175
+                $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
176
+                $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
177
+                $poll_form->addElement(new \XoopsFormHidden('user_id', is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0));
178
+                $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit'));
179
+                echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . '</h4>';
180
+                $poll_form->display();
171 181
             }
172
-            $poll_form->addElement($option_tray);
173
-
174
-            $poll_form->addElement(new \XoopsFormHidden('op', 'save'));
175
-            $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
176
-            $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
177
-            $poll_form->addElement(new \XoopsFormHidden('user_id', is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0));
178
-            $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit'));
179
-            echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . '</h4>';
180
-            $poll_form->display();
181
-        }
182
-        break; // op: add
182
+            break; // op: add
183 183
 
184
-    case 'edit':
185
-        // new xoopspoll module
186
-        if ($pollModuleHandler->getVar('version') >= 140) {
187
-            echo '<h4>' . _MD_NEWBB_POLL_EDITPOLL . "</h4>\n";
188
-            $pollObject->renderForm(Request::getString('PHP_SELF', '', 'SERVER'), 'post', ['topic_id' => $topic_id]);
189
-        // old xoopspoll or umfrage or any clone from them
190
-        } else {
191
-            $classOption  = $classPoll . 'Option';
192
-            $poll_form    = new \XoopsThemeForm(_MD_NEWBB_POLL_EDITPOLL, 'poll_form', 'polls.php', 'post', true);
193
-            $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>');
194
-            $poll_form->addElement($author_label);
195
-            $question_text = new \XoopsFormText(_MD_NEWBB_POLL_POLLQUESTION, 'question', 50, 255, $pollObject->getVar('question', 'E'));
196
-            $poll_form->addElement($question_text);
197
-            $desc_tarea = new \XoopsFormTextarea(_MD_NEWBB_POLL_POLLDESC, 'description', $pollObject->getVar('description', 'E'));
198
-            $poll_form->addElement($desc_tarea);
199
-            $date = formatTimestamp($pollObject->getVar('end_time'), 'Y-m-d H:i:s'); // important "Y-m-d H:i:s" use in jdf function
200
-            if (!$pollObject->hasExpired()) {
201
-                $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);
202
-                $poll_form->addElement($expire_text);
184
+        case 'edit':
185
+            // new xoopspoll module
186
+            if ($pollModuleHandler->getVar('version') >= 140) {
187
+                echo '<h4>' . _MD_NEWBB_POLL_EDITPOLL . "</h4>\n";
188
+                $pollObject->renderForm(Request::getString('PHP_SELF', '', 'SERVER'), 'post', ['topic_id' => $topic_id]);
189
+            // old xoopspoll or umfrage or any clone from them
203 190
             } else {
204
-                // irmtfan full URL - add topic_id
205
-                $restart_label = new \XoopsFormLabel(
206
-                    _MD_NEWBB_POLL_EXPIRATION,
207
-                                                    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>'
208
-                );
209
-                $poll_form->addElement($restart_label);
210
-            }
211
-            $weight_text = new \XoopsFormText(_MD_NEWBB_POLL_DISPLAYORDER, 'weight', 6, 5, $pollObject->getVar('weight'));
212
-            $poll_form->addElement($weight_text);
213
-            $multi_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_ALLOWMULTI, 'multiple', $pollObject->getVar('multiple'));
214
-            $poll_form->addElement($multi_yn);
215
-            $options_arr  =& $classOption::getAllByPollId($poll_id);
216
-            $notify_value = 1;
217
-            if (0 !== $pollObject->getVar('mail_status')) {
218
-                $notify_value = 0;
219
-            }
220
-            $notify_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', $notify_value);
221
-            $poll_form->addElement($notify_yn);
222
-            $option_tray    = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, '');
223
-            $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/"));
224
-            $i              = 0;
225
-            foreach ($options_arr as $option) {
226
-                /** @var \XoopsPoll $option */
227
-                $option_tray->addElement(new \XoopsFormText('', 'option_text[]', 50, 255, $option->getVar('option_text')));
228
-                $option_tray->addElement(new \XoopsFormHidden('option_id[]', $option->getVar('option_id')));
229
-                $color_select = new \XoopsFormSelect('', 'option_color[{$i}]', $option->getVar('option_color'));
230
-                $color_select->addOptionArray($barcolor_array);
231
-                $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[" . $i . "]\", \"modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'");
232
-                $color_label = new \XoopsFormLabel('', "<img src='"
233
-                                                      . $GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/" . $option->getVar('option_color', 'E'))
234
-                                                      . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' class='alignbottom' width='30' height='15' alt='' /><br>");
235
-                $option_tray->addElement($color_select);
236
-                $option_tray->addElement($color_label);
237
-                unset($color_select, $color_label);
238
-                ++$i;
191
+                $classOption  = $classPoll . 'Option';
192
+                $poll_form    = new \XoopsThemeForm(_MD_NEWBB_POLL_EDITPOLL, 'poll_form', 'polls.php', 'post', true);
193
+                $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>');
194
+                $poll_form->addElement($author_label);
195
+                $question_text = new \XoopsFormText(_MD_NEWBB_POLL_POLLQUESTION, 'question', 50, 255, $pollObject->getVar('question', 'E'));
196
+                $poll_form->addElement($question_text);
197
+                $desc_tarea = new \XoopsFormTextarea(_MD_NEWBB_POLL_POLLDESC, 'description', $pollObject->getVar('description', 'E'));
198
+                $poll_form->addElement($desc_tarea);
199
+                $date = formatTimestamp($pollObject->getVar('end_time'), 'Y-m-d H:i:s'); // important "Y-m-d H:i:s" use in jdf function
200
+                if (!$pollObject->hasExpired()) {
201
+                    $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);
202
+                    $poll_form->addElement($expire_text);
203
+                } else {
204
+                    // irmtfan full URL - add topic_id
205
+                    $restart_label = new \XoopsFormLabel(
206
+                        _MD_NEWBB_POLL_EXPIRATION,
207
+                                                        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>'
208
+                    );
209
+                    $poll_form->addElement($restart_label);
210
+                }
211
+                $weight_text = new \XoopsFormText(_MD_NEWBB_POLL_DISPLAYORDER, 'weight', 6, 5, $pollObject->getVar('weight'));
212
+                $poll_form->addElement($weight_text);
213
+                $multi_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_ALLOWMULTI, 'multiple', $pollObject->getVar('multiple'));
214
+                $poll_form->addElement($multi_yn);
215
+                $options_arr  =& $classOption::getAllByPollId($poll_id);
216
+                $notify_value = 1;
217
+                if (0 !== $pollObject->getVar('mail_status')) {
218
+                    $notify_value = 0;
219
+                }
220
+                $notify_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', $notify_value);
221
+                $poll_form->addElement($notify_yn);
222
+                $option_tray    = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, '');
223
+                $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/"));
224
+                $i              = 0;
225
+                foreach ($options_arr as $option) {
226
+                    /** @var \XoopsPoll $option */
227
+                    $option_tray->addElement(new \XoopsFormText('', 'option_text[]', 50, 255, $option->getVar('option_text')));
228
+                    $option_tray->addElement(new \XoopsFormHidden('option_id[]', $option->getVar('option_id')));
229
+                    $color_select = new \XoopsFormSelect('', 'option_color[{$i}]', $option->getVar('option_color'));
230
+                    $color_select->addOptionArray($barcolor_array);
231
+                    $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[" . $i . "]\", \"modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'");
232
+                    $color_label = new \XoopsFormLabel('', "<img src='"
233
+                                                          . $GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/" . $option->getVar('option_color', 'E'))
234
+                                                          . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' class='alignbottom' width='30' height='15' alt='' /><br>");
235
+                    $option_tray->addElement($color_select);
236
+                    $option_tray->addElement($color_label);
237
+                    unset($color_select, $color_label);
238
+                    ++$i;
239
+                }
240
+                // irmtfan full URL
241
+                $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>');
242
+                $option_tray->addElement($more_label);
243
+                $poll_form->addElement($option_tray);
244
+                $poll_form->addElement(new \XoopsFormHidden('op', 'update'));
245
+                $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
246
+                $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
247
+                $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit'));
248
+
249
+                echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n";
250
+                $poll_form->display();
239 251
             }
240
-            // irmtfan full URL
241
-            $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>');
242
-            $option_tray->addElement($more_label);
243
-            $poll_form->addElement($option_tray);
244
-            $poll_form->addElement(new \XoopsFormHidden('op', 'update'));
245
-            $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
246
-            $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
247
-            $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit'));
252
+            break; // op: edit
248 253
 
249
-            echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n";
250
-            $poll_form->display();
251
-        }
252
-        break; // op: edit
254
+        case 'save':
255
+            // old xoopspoll or umfrage or any clone from them
256
+            if ($pollModuleHandler->getVar('version') < 140) {
257
+                // check security token
258
+                if (!$GLOBALS['xoopsSecurity']->check()) {
259
+                    redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
260
+                }
261
+                /*
262
+             * The option check should be done before submitting
263
+             */
264
+                $option_empty = true;
265
+                if (!Request::getString('option_text', '', 'POST')) {
266
+                    // irmtfan - issue with javascript:history.go(-1)
267
+                    redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !');
268
+                }
269
+                $option_text = Request::getArray('option_text', '', 'POST');
270
+                foreach ($option_text as $optxt) {
271
+                    if ('' !== trim($optxt)) {
272
+                        $option_empty = false;
273
+                        break;
274
+                    }
275
+                }
276
+                if ($option_empty) {
277
+                    // irmtfan - issue with javascript:history.go(-1)
278
+                    redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !');
279
+                }
280
+                $pollObject->setVar('question', Request::getString('question', '', 'POST'));
281
+                $pollObject->setVar('description', Request::getString('description', '', 'POST'));
282
+                $end_time = Request::getString('end_time', '', 'POST'); // (empty($_POST['end_time'])) ? "" : $_POST['end_time'];
283
+                if ('' !== $end_time) {
284
+                    $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null;
285
+                    $pollObject->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($end_time) : strtotime($end_time), $timezone));
286
+                } else {
287
+                    // if expiration date is not set, set it to 10 days from now
288
+                    $pollObject->setVar('end_time', time() + (86400 * 10));
289
+                }
253 290
 
254
-    case 'save':
255
-        // old xoopspoll or umfrage or any clone from them
256
-        if ($pollModuleHandler->getVar('version') < 140) {
291
+                $pollObject->setVar('display', 0);
292
+                $pollObject->setVar('weight', Request::getInt('weight', 0, 'POST'));
293
+                $pollObject->setVar('multiple', Request::getInt('multiple', 0, 'POST'));
294
+                $pollObject->setVar('user_id', Request::getInt('user_id', 0, 'POST'));
295
+                if (Request::getInt('notify', 0, 'POST') && $end_time > time()) {
296
+                    // if notify, set mail status to "not mailed"
297
+                    $pollObject->setVar('mail_status', Xoopspoll\Constants::POLL_NOT_MAILED);
298
+                } else {
299
+                    // if not notify, set mail status to already "mailed"
300
+                    $pollObject->setVar('mail_status', Xoopspoll\Constants::POLL_MAILED);
301
+                }
302
+                $new_poll_id = $pollObject->store();
303
+                if (empty($new_poll_id)) {
304
+                    xoops_error($pollObject->getHtmlErrors);
305
+                    break;
306
+                }
307
+                $i            = 0;
308
+                $option_color = Request::getArray('option_color', null, 'POST');
309
+                $classOption  = $classPoll . 'Option';
310
+                foreach ($option_text as $optxt) {
311
+                    $optxt = trim($optxt);
312
+                    /** @var Xoopspoll\Option $optionObject */
313
+                    $optionObject = new $classOption();
314
+                    if ('' !== $optxt) {
315
+                        $optionObject->setVar('option_text', $optxt);
316
+                        $optionObject->setVar('option_color', $option_color[$i]);
317
+                        $optionObject->setVar('poll_id', $new_poll_id);
318
+                        $optionObject->store();
319
+                    }
320
+                    ++$i;
321
+                }
322
+                // clear the template cache so changes take effect immediately
323
+                require_once $GLOBALS['xoops']->path('class/template.php');
324
+                xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid'));
325
+                xoops_template_clear_module_cache($pollModuleHandler->getVar('mid'));
326
+
327
+                // update topic to indicate it has a poll
328
+                $topicObject->setVar('topic_haspoll', 1);
329
+                $topicObject->setVar('poll_id', $new_poll_id);
330
+                $success = $topicHandler->insert($topicObject);
331
+                if (!$success) {
332
+                    xoops_error($topicHandler->getHtmlErrors());
333
+                } else {
334
+                    redirect_header("viewtopic.php?topic_id={$topic_id}", 2, _MD_NEWBB_POLL_DBUPDATED);
335
+                }
336
+                break;// op: save
337
+            }
338
+        // no break
339
+        case 'update':
257 340
             // check security token
258 341
             if (!$GLOBALS['xoopsSecurity']->check()) {
259 342
                 redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
260 343
             }
261
-            /*
262
-             * The option check should be done before submitting
263
-             */
264
-            $option_empty = true;
265
-            if (!Request::getString('option_text', '', 'POST')) {
266
-                // irmtfan - issue with javascript:history.go(-1)
344
+            /* make sure there's at least one option */
345
+            $option_text   = Request::getString('option_text', '', 'POST');
346
+            $option_string = is_array($option_text) ? implode('', $option_text) : $option_text;
347
+            $option_string = trim($option_string);
348
+            if ('' === $option_string) {
267 349
                 redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !');
268 350
             }
269
-            $option_text = Request::getArray('option_text', '', 'POST');
270
-            foreach ($option_text as $optxt) {
271
-                if ('' !== trim($optxt)) {
272
-                    $option_empty = false;
273
-                    break;
351
+
352
+            // new xoopspoll module
353
+            if ($pollModuleHandler->getVar('version') >= 140) {
354
+                /** @var Xoopspoll\OptionHandler $xpOptHandler */
355
+                $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
356
+                /** @var Xoopspoll\LogHandler $xpLogHandler */
357
+                $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log');
358
+                //            $classRequest = ucfirst($GLOBALS['xoopsModuleConfig']["poll_module"]) . "Request";
359
+                $classConstants   = new XoopsModules\Xoopspoll\Constants();
360
+                $notify           = Request::getInt('notify', $classConstants::NOTIFICATION_ENABLED, 'POST');
361
+                $currentTimestamp = time();
362
+                //$xuEndTimestamp   = method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime(Request::getString('xu_end_time', null, 'POST'))
363
+                //                                                             : strtotime(Request::getString('xu_end_time', null, 'POST'));
364
+                $xuEndTimestamp = strtotime(Request::getString('xu_end_time', null, 'POST'));
365
+                $endTimestamp   = (!Request::getString('xu_end_time', null, 'POST')) ? ($currentTimestamp + $classConstants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuEndTimestamp);
366
+                //$xuStartTimestamp = method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime(Request::getString('xu_start_time', null, 'POST'))
367
+                //                                                             : strtotime(Request::getString('xu_start_time', null, 'POST'));
368
+                $xuStartTimestamp = strtotime(Request::getString('xu_start_time', null, 'POST'));
369
+                $startTimestamp   = (!Request::getString('xu_start_time', null, 'POST')) ? ($endTimestamp - $classConstants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuStartTimestamp);
370
+
371
+                //  don't allow changing start time if there are votes in the log
372
+                if (($startTimestamp < $pollObject->getVar('start_time'))
373
+                    && ($xpLogHandler->getTotalVotesByPollId($poll_id) > 0)) {
374
+                    $startTimestamp = $pollObject->getVar('start_time'); //don't change start time
274 375
                 }
275
-            }
276
-            if ($option_empty) {
277
-                // irmtfan - issue with javascript:history.go(-1)
278
-                redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !');
279
-            }
280
-            $pollObject->setVar('question', Request::getString('question', '', 'POST'));
281
-            $pollObject->setVar('description', Request::getString('description', '', 'POST'));
282
-            $end_time = Request::getString('end_time', '', 'POST'); // (empty($_POST['end_time'])) ? "" : $_POST['end_time'];
283
-            if ('' !== $end_time) {
284
-                $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null;
285
-                $pollObject->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($end_time) : strtotime($end_time), $timezone));
286
-            } else {
287
-                // if expiration date is not set, set it to 10 days from now
288
-                $pollObject->setVar('end_time', time() + (86400 * 10));
289
-            }
290 376
 
291
-            $pollObject->setVar('display', 0);
292
-            $pollObject->setVar('weight', Request::getInt('weight', 0, 'POST'));
293
-            $pollObject->setVar('multiple', Request::getInt('multiple', 0, 'POST'));
294
-            $pollObject->setVar('user_id', Request::getInt('user_id', 0, 'POST'));
295
-            if (Request::getInt('notify', 0, 'POST') && $end_time > time()) {
296
-                // if notify, set mail status to "not mailed"
297
-                $pollObject->setVar('mail_status', Xoopspoll\Constants::POLL_NOT_MAILED);
377
+                $poll_vars = [
378
+                    'user_id'     => Request::getInt('user_id', $GLOBALS['xoopsUser']->uid(), 'POST'),
379
+                    'question'    => Request::getString('question', null, 'POST'),
380
+                    'description' => Request::getText('description', null, 'POST'),
381
+                    'mail_status' => ($classConstants::NOTIFICATION_ENABLED == $notify) ? $classConstants::POLL_NOT_MAILED : $classConstants::POLL_MAILED,
382
+                    'mail_voter'  => Request::getInt('mail_voter', $classConstants::NOT_MAIL_POLL_TO_VOTER, 'POST'),
383
+                    'start_time'  => $startTimestamp,
384
+                    'end_time'    => $endTimestamp,
385
+                    'display'     => Request::getInt('display', $classConstants::DO_NOT_DISPLAY_POLL_IN_BLOCK, 'POST'),
386
+                    'visibility'  => Request::getInt('visibility', $classConstants::HIDE_NEVER, 'POST'),
387
+                    'weight'      => Request::getInt('weight', $classConstants::DEFAULT_WEIGHT, 'POST'),
388
+                    'multiple'    => Request::getInt('multiple', $classConstants::NOT_MULTIPLE_SELECT_POLL, 'POST'),
389
+                    'multilimit'  => Request::getInt('multilimit', $classConstants::MULTIPLE_SELECT_LIMITLESS, 'POST'),
390
+                    'anonymous'   => Request::getInt('anonymous', $classConstants::ANONYMOUS_VOTING_DISALLOWED, 'POST')
391
+                ];
392
+                $pollObject->setVars($poll_vars);
393
+                $poll_id = $xpPollHandler->insert($pollObject);
394
+                if (!$poll_id) {
395
+                    $err = $pollObject->getHtmlErrors();
396
+                    exit($err);
397
+                }
398
+
399
+                // now get the options
400
+                $optionIdArray    = Request::getArray('option_id', [], 'POST');
401
+                $optionIdArray    = array_map('intval', $optionIdArray);
402
+                $optionTextArray  = Request::getArray('option_text', [], 'POST');
403
+                $optionColorArray = Request::getArray('option_color', [], 'POST');
404
+
405
+                foreach ($optionIdArray as $key => $oId) {
406
+                    if (!empty($oId) && ($optionObject = $xpOptHandler->get($oId))) {
407
+                        // existing option object so need to update it
408
+                        $optionTextArray[$key] = trim($optionTextArray[$key]);
409
+                        if ('' === $optionTextArray[$key]) {
410
+                            // want to delete this option
411
+                            if (false !== $xpOptHandler->delete($optionObject)) {
412
+                                // now remove it from the log
413
+                                $xpLogHandler->deleteByOptionId($optionObject->getVar('option_id'));
414
+                                //update vote count in poll
415
+                                $xpPollHandler->updateCount($pollObject);
416
+                            } else {
417
+                                xoops_error($xpLogHandler->getHtmlErrors());
418
+                                break;
419
+                            }
420
+                        } else {
421
+                            $optionObject->setVar('option_text', $optionTextArray[$key]);
422
+                            $optionObject->setVar('option_color', $optionColorArray[$key]);
423
+                            $optionObject->setVar('poll_id', $poll_id);
424
+                            $xpOptHandler->insert($optionObject);
425
+                        }
426
+                    } else {
427
+                        // new option object
428
+                        $optionObject          = $xpOptHandler->create();
429
+                        $optionTextArray[$key] = trim($optionTextArray[$key]);
430
+                        if ('' !== $optionTextArray[$key]) { // ignore if text is empty
431
+                            $optionObject->setVar('option_text', $optionTextArray[$key]);
432
+                            $optionObject->setVar('option_color', $optionColorArray[$key]);
433
+                            $optionObject->setVar('poll_id', $poll_id);
434
+                            $xpOptHandler->insert($optionObject);
435
+                        }
436
+                        unset($optionObject);
437
+                    }
438
+                }
439
+                // old xoopspoll or umfrage or any clone from them
298 440
             } else {
299
-                // if not notify, set mail status to already "mailed"
300
-                $pollObject->setVar('mail_status', Xoopspoll\Constants::POLL_MAILED);
301
-            }
302
-            $new_poll_id = $pollObject->store();
303
-            if (empty($new_poll_id)) {
304
-                xoops_error($pollObject->getHtmlErrors);
305
-                break;
306
-            }
307
-            $i            = 0;
308
-            $option_color = Request::getArray('option_color', null, 'POST');
309
-            $classOption  = $classPoll . 'Option';
310
-            foreach ($option_text as $optxt) {
311
-                $optxt = trim($optxt);
312
-                /** @var Xoopspoll\Option $optionObject */
313
-                $optionObject = new $classOption();
314
-                if ('' !== $optxt) {
315
-                    $optionObject->setVar('option_text', $optxt);
316
-                    $optionObject->setVar('option_color', $option_color[$i]);
317
-                    $optionObject->setVar('poll_id', $new_poll_id);
318
-                    $optionObject->store();
441
+                $pollObject->setVar('question', Request::getString('question', '', 'POST'));
442
+                $pollObject->setVar('description', Request::getString('description', '', 'POST'));
443
+
444
+                $end_time = Request::getString('end_time', '', 'POST');
445
+                if ('' !== $end_time) {
446
+                    $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null;
447
+                    $pollObject->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($end_time) : strtotime($end_time), $timezone));
319 448
                 }
320
-                ++$i;
449
+                $pollObject->setVar('display', 0);
450
+                $pollObject->setVar('weight', Request::getInt('weight', 0, 'POST'));
451
+                $pollObject->setVar('multiple', Request::getInt('multiple', 0, 'POST'));
452
+                $pollObject->setVar('user_id', Request::getInt('user_id', 0, 'POST'));
453
+                if (Request::getInt('notify', 0, 'POST') && $end_time > time()) {
454
+                    // if notify, set mail status to "not mailed"
455
+                    $pollObject->setVar('mail_status', $classConstants::POLL_NOT_MAILED);
456
+                } else {
457
+                    // if not notify, set mail status to already "mailed"
458
+                    $pollObject->setVar('mail_status', $classConstants::POLL_MAILED);
459
+                }
460
+
461
+                if (!$pollObject->store()) {
462
+                    xoops_error($pollObject->getHtmlErrors);
463
+                    break;
464
+                }
465
+                $i            = 0;
466
+                $option_id    = Request::getArray('option_id', null, 'POST');
467
+                $option_color = Request::getArray('option_color', null, 'POST');
468
+                $classOption  = $classPoll . 'Option';
469
+                $classLog     = $classPoll . 'Log';
470
+                foreach ($option_id as $opid) {
471
+                    $optionObject    = new $classOption($opid);
472
+                    $option_text[$i] = trim($option_text[$i]);
473
+                    if ('' !== $option_text[$i]) {
474
+                        $optionObject->setVar('option_text', $option_text[$i]);
475
+                        $optionObject->setVar('option_color', $option_color[$i]);
476
+                        $optionObject->store();
477
+                    } else {
478
+                        if (false !== $optionObject->delete()) {
479
+                            $classLog::deleteByOptionId($option->getVar('option_id'));
480
+                        }
481
+                    }
482
+                    ++$i;
483
+                }
484
+                $pollObject->updateCount();
321 485
             }
322 486
             // clear the template cache so changes take effect immediately
323 487
             require_once $GLOBALS['xoops']->path('class/template.php');
@@ -326,433 +490,269 @@  discard block
 block discarded – undo
326 490
 
327 491
             // update topic to indicate it has a poll
328 492
             $topicObject->setVar('topic_haspoll', 1);
329
-            $topicObject->setVar('poll_id', $new_poll_id);
493
+            $topicObject->setVar('poll_id', $pollObject->getVar('poll_id'));
330 494
             $success = $topicHandler->insert($topicObject);
331 495
             if (!$success) {
332 496
                 xoops_error($topicHandler->getHtmlErrors());
333 497
             } else {
334 498
                 redirect_header("viewtopic.php?topic_id={$topic_id}", 2, _MD_NEWBB_POLL_DBUPDATED);
335 499
             }
336
-            break;// op: save
337
-        }
338
-    // no break
339
-    case 'update':
340
-        // check security token
341
-        if (!$GLOBALS['xoopsSecurity']->check()) {
342
-            redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
343
-        }
344
-        /* make sure there's at least one option */
345
-        $option_text   = Request::getString('option_text', '', 'POST');
346
-        $option_string = is_array($option_text) ? implode('', $option_text) : $option_text;
347
-        $option_string = trim($option_string);
348
-        if ('' === $option_string) {
349
-            redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !');
350
-        }
351
-
352
-        // new xoopspoll module
353
-        if ($pollModuleHandler->getVar('version') >= 140) {
354
-            /** @var Xoopspoll\OptionHandler $xpOptHandler */
355
-            $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
356
-            /** @var Xoopspoll\LogHandler $xpLogHandler */
357
-            $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log');
358
-            //            $classRequest = ucfirst($GLOBALS['xoopsModuleConfig']["poll_module"]) . "Request";
359
-            $classConstants   = new XoopsModules\Xoopspoll\Constants();
360
-            $notify           = Request::getInt('notify', $classConstants::NOTIFICATION_ENABLED, 'POST');
361
-            $currentTimestamp = time();
362
-            //$xuEndTimestamp   = method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime(Request::getString('xu_end_time', null, 'POST'))
363
-            //                                                             : strtotime(Request::getString('xu_end_time', null, 'POST'));
364
-            $xuEndTimestamp = strtotime(Request::getString('xu_end_time', null, 'POST'));
365
-            $endTimestamp   = (!Request::getString('xu_end_time', null, 'POST')) ? ($currentTimestamp + $classConstants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuEndTimestamp);
366
-            //$xuStartTimestamp = method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime(Request::getString('xu_start_time', null, 'POST'))
367
-            //                                                             : strtotime(Request::getString('xu_start_time', null, 'POST'));
368
-            $xuStartTimestamp = strtotime(Request::getString('xu_start_time', null, 'POST'));
369
-            $startTimestamp   = (!Request::getString('xu_start_time', null, 'POST')) ? ($endTimestamp - $classConstants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuStartTimestamp);
370
-
371
-            //  don't allow changing start time if there are votes in the log
372
-            if (($startTimestamp < $pollObject->getVar('start_time'))
373
-                && ($xpLogHandler->getTotalVotesByPollId($poll_id) > 0)) {
374
-                $startTimestamp = $pollObject->getVar('start_time'); //don't change start time
500
+            break;// op: save | update
501
+
502
+        case 'addmore':
503
+            $question = $pollObject->getVar('question');
504
+            unset($pollObject);
505
+            $poll_form = new \XoopsThemeForm(_MD_NEWBB_POLL_ADDMORE, 'poll_form', 'polls.php', 'post', true);
506
+            $poll_form->addElement(new \XoopsFormLabel(_MD_NEWBB_POLL_POLLQUESTION, $question));
507
+            // new xoopspoll module
508
+            if ($pollModuleHandler->getVar('version') >= 140) {
509
+                $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
510
+                $option_tray  = $xpOptHandler->renderOptionFormTray($poll_id);
511
+            // old xoopspoll or umfrage or any clone from them
512
+            } else {
513
+                $option_tray    = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, '');
514
+                $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars/'));
515
+                for ($i = 0; $i < 10; ++$i) {
516
+                    $current_bar = ('blank.gif' !== current($barcolor_array)) ? current($barcolor_array) : next($barcolor_array);
517
+                    $option_text = new \XoopsFormText('', 'option_text[]', 50, 255);
518
+                    $option_tray->addElement($option_text);
519
+                    $color_select = new \XoopsFormSelect('', "option_color[{$i}]", $current_bar);
520
+                    $color_select->addOptionArray($barcolor_array);
521
+                    $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'");
522
+                    $color_label = new \XoopsFormLabel('', "<img src='"
523
+                                                          . $GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/{$current_bar}")
524
+                                                          . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' class='alignbottom' width='30' height='15' alt='' /><br>");
525
+                    $option_tray->addElement($color_select);
526
+                    $option_tray->addElement($color_label);
527
+                    unset($color_select, $color_label, $option_text);
528
+                    if (!next($barcolor_array)) {
529
+                        reset($barcolor_array);
530
+                    }
531
+                }
375 532
             }
533
+            $poll_form->addElement($option_tray);
534
+            $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit'));
535
+            $poll_form->addElement(new \XoopsFormHidden('op', 'savemore'));
536
+            $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
537
+            $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
376 538
 
377
-            $poll_vars = [
378
-                'user_id'     => Request::getInt('user_id', $GLOBALS['xoopsUser']->uid(), 'POST'),
379
-                'question'    => Request::getString('question', null, 'POST'),
380
-                'description' => Request::getText('description', null, 'POST'),
381
-                'mail_status' => ($classConstants::NOTIFICATION_ENABLED == $notify) ? $classConstants::POLL_NOT_MAILED : $classConstants::POLL_MAILED,
382
-                'mail_voter'  => Request::getInt('mail_voter', $classConstants::NOT_MAIL_POLL_TO_VOTER, 'POST'),
383
-                'start_time'  => $startTimestamp,
384
-                'end_time'    => $endTimestamp,
385
-                'display'     => Request::getInt('display', $classConstants::DO_NOT_DISPLAY_POLL_IN_BLOCK, 'POST'),
386
-                'visibility'  => Request::getInt('visibility', $classConstants::HIDE_NEVER, 'POST'),
387
-                'weight'      => Request::getInt('weight', $classConstants::DEFAULT_WEIGHT, 'POST'),
388
-                'multiple'    => Request::getInt('multiple', $classConstants::NOT_MULTIPLE_SELECT_POLL, 'POST'),
389
-                'multilimit'  => Request::getInt('multilimit', $classConstants::MULTIPLE_SELECT_LIMITLESS, 'POST'),
390
-                'anonymous'   => Request::getInt('anonymous', $classConstants::ANONYMOUS_VOTING_DISALLOWED, 'POST')
391
-            ];
392
-            $pollObject->setVars($poll_vars);
393
-            $poll_id = $xpPollHandler->insert($pollObject);
394
-            if (!$poll_id) {
395
-                $err = $pollObject->getHtmlErrors();
396
-                exit($err);
539
+            echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n";
540
+            $poll_form->display();
541
+            break;
542
+
543
+        case 'savemore':
544
+            // check security token
545
+            if (!$GLOBALS['xoopsSecurity']->check()) {
546
+                redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
397 547
             }
398 548
 
399
-            // now get the options
400
-            $optionIdArray    = Request::getArray('option_id', [], 'POST');
401
-            $optionIdArray    = array_map('intval', $optionIdArray);
402
-            $optionTextArray  = Request::getArray('option_text', [], 'POST');
403
-            $optionColorArray = Request::getArray('option_color', [], 'POST');
404
-
405
-            foreach ($optionIdArray as $key => $oId) {
406
-                if (!empty($oId) && ($optionObject = $xpOptHandler->get($oId))) {
407
-                    // existing option object so need to update it
408
-                    $optionTextArray[$key] = trim($optionTextArray[$key]);
409
-                    if ('' === $optionTextArray[$key]) {
410
-                        // want to delete this option
411
-                        if (false !== $xpOptHandler->delete($optionObject)) {
412
-                            // now remove it from the log
413
-                            $xpLogHandler->deleteByOptionId($optionObject->getVar('option_id'));
414
-                            //update vote count in poll
415
-                            $xpPollHandler->updateCount($pollObject);
416
-                        } else {
417
-                            xoops_error($xpLogHandler->getHtmlErrors());
418
-                            break;
419
-                        }
420
-                    } else {
421
-                        $optionObject->setVar('option_text', $optionTextArray[$key]);
422
-                        $optionObject->setVar('option_color', $optionColorArray[$key]);
549
+            $option_text   = Request::getString('option_text', '', 'POST');
550
+            $option_string = is_array($option_text) ? implode('', $option_text) : $option_text;
551
+            $option_string = trim($option_string);
552
+            if ('' === $option_string) {
553
+                // irmtfan - issue with javascript:history.go(-1)
554
+                redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !');
555
+            }
556
+            $i            = 0;
557
+            $option_color = Request::getArray('option_color', null, 'POST');
558
+            foreach ($option_text as $optxt) {
559
+                $optxt = trim($optxt);
560
+                if ('' !== $optxt) {
561
+                    // new xoopspoll module
562
+                    if ($pollModuleHandler->getVar('version') >= 140) {
563
+                        $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
564
+                        $optionObject = $xpOptHandler->create();
565
+                        $optionObject->setVar('option_text', $optxt);
423 566
                         $optionObject->setVar('poll_id', $poll_id);
567
+                        $optionObject->setVar('option_color', $option_color[$i]);
424 568
                         $xpOptHandler->insert($optionObject);
425
-                    }
426
-                } else {
427
-                    // new option object
428
-                    $optionObject          = $xpOptHandler->create();
429
-                    $optionTextArray[$key] = trim($optionTextArray[$key]);
430
-                    if ('' !== $optionTextArray[$key]) { // ignore if text is empty
431
-                        $optionObject->setVar('option_text', $optionTextArray[$key]);
432
-                        $optionObject->setVar('option_color', $optionColorArray[$key]);
569
+                    // old xoopspoll or umfrage or any clone from them
570
+                    } else {
571
+                        $classOption  = $classPoll . 'Option';
572
+                        $optionObject = new $classOption();
573
+                        $optionObject->setVar('option_text', $optxt);
433 574
                         $optionObject->setVar('poll_id', $poll_id);
434
-                        $xpOptHandler->insert($optionObject);
575
+                        $optionObject->setVar('option_color', $option_color[$i]);
576
+                        $optionObject->store();
435 577
                     }
436 578
                     unset($optionObject);
437 579
                 }
580
+                ++$i;
438 581
             }
439
-            // old xoopspoll or umfrage or any clone from them
440
-        } else {
441
-            $pollObject->setVar('question', Request::getString('question', '', 'POST'));
442
-            $pollObject->setVar('description', Request::getString('description', '', 'POST'));
582
+            require_once $GLOBALS['xoops']->path('class/template.php');
583
+            xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid'));
584
+            xoops_template_clear_module_cache($pollModuleHandler->getVar('mid'));
585
+            redirect_header("polls.php?op=edit&amp;poll_id={$poll_id}&amp;topic_id={$topic_id}", 2, _MD_NEWBB_POLL_DBUPDATED);
586
+            break;
443 587
 
444
-            $end_time = Request::getString('end_time', '', 'POST');
445
-            if ('' !== $end_time) {
446
-                $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null;
447
-                $pollObject->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($end_time) : strtotime($end_time), $timezone));
448
-            }
449
-            $pollObject->setVar('display', 0);
450
-            $pollObject->setVar('weight', Request::getInt('weight', 0, 'POST'));
451
-            $pollObject->setVar('multiple', Request::getInt('multiple', 0, 'POST'));
452
-            $pollObject->setVar('user_id', Request::getInt('user_id', 0, 'POST'));
453
-            if (Request::getInt('notify', 0, 'POST') && $end_time > time()) {
454
-                // if notify, set mail status to "not mailed"
455
-                $pollObject->setVar('mail_status', $classConstants::POLL_NOT_MAILED);
456
-            } else {
457
-                // if not notify, set mail status to already "mailed"
458
-                $pollObject->setVar('mail_status', $classConstants::POLL_MAILED);
459
-            }
588
+        case 'delete':
589
+            echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n";
590
+            xoops_confirm(['op' => 'delete_ok', 'topic_id' => $topic_id, 'poll_id' => $poll_id], 'polls.php', sprintf(_MD_NEWBB_POLL_RUSUREDEL, $pollObject->getVar('question')));
591
+            break;
460 592
 
461
-            if (!$pollObject->store()) {
462
-                xoops_error($pollObject->getHtmlErrors);
463
-                break;
593
+        case 'delete_ok':
594
+            // check security token
595
+            if (!$GLOBALS['xoopsSecurity']->check()) {
596
+                redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
464 597
             }
465
-            $i            = 0;
466
-            $option_id    = Request::getArray('option_id', null, 'POST');
467
-            $option_color = Request::getArray('option_color', null, 'POST');
468
-            $classOption  = $classPoll . 'Option';
469
-            $classLog     = $classPoll . 'Log';
470
-            foreach ($option_id as $opid) {
471
-                $optionObject    = new $classOption($opid);
472
-                $option_text[$i] = trim($option_text[$i]);
473
-                if ('' !== $option_text[$i]) {
474
-                    $optionObject->setVar('option_text', $option_text[$i]);
475
-                    $optionObject->setVar('option_color', $option_color[$i]);
476
-                    $optionObject->store();
598
+            //try and delete the poll
599
+            // new xoopspoll module
600
+            if ($pollModuleHandler->getVar('version') >= 140) {
601
+                $status = $xpPollHandler->delete($pollObject);
602
+                if (false !== $status) {
603
+                    $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
604
+                    $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log');
605
+                    $xpOptHandler->deleteByPollId($poll_id);
606
+                    $xpLogHandler->deleteByPollId($poll_id);
477 607
                 } else {
478
-                    if (false !== $optionObject->delete()) {
479
-                        $classLog::deleteByOptionId($option->getVar('option_id'));
480
-                    }
481
-                }
482
-                ++$i;
483
-            }
484
-            $pollObject->updateCount();
485
-        }
486
-        // clear the template cache so changes take effect immediately
487
-        require_once $GLOBALS['xoops']->path('class/template.php');
488
-        xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid'));
489
-        xoops_template_clear_module_cache($pollModuleHandler->getVar('mid'));
490
-
491
-        // update topic to indicate it has a poll
492
-        $topicObject->setVar('topic_haspoll', 1);
493
-        $topicObject->setVar('poll_id', $pollObject->getVar('poll_id'));
494
-        $success = $topicHandler->insert($topicObject);
495
-        if (!$success) {
496
-            xoops_error($topicHandler->getHtmlErrors());
497
-        } else {
498
-            redirect_header("viewtopic.php?topic_id={$topic_id}", 2, _MD_NEWBB_POLL_DBUPDATED);
499
-        }
500
-        break;// op: save | update
501
-
502
-    case 'addmore':
503
-        $question = $pollObject->getVar('question');
504
-        unset($pollObject);
505
-        $poll_form = new \XoopsThemeForm(_MD_NEWBB_POLL_ADDMORE, 'poll_form', 'polls.php', 'post', true);
506
-        $poll_form->addElement(new \XoopsFormLabel(_MD_NEWBB_POLL_POLLQUESTION, $question));
507
-        // new xoopspoll module
508
-        if ($pollModuleHandler->getVar('version') >= 140) {
509
-            $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
510
-            $option_tray  = $xpOptHandler->renderOptionFormTray($poll_id);
511
-        // old xoopspoll or umfrage or any clone from them
512
-        } else {
513
-            $option_tray    = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, '');
514
-            $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars/'));
515
-            for ($i = 0; $i < 10; ++$i) {
516
-                $current_bar = ('blank.gif' !== current($barcolor_array)) ? current($barcolor_array) : next($barcolor_array);
517
-                $option_text = new \XoopsFormText('', 'option_text[]', 50, 255);
518
-                $option_tray->addElement($option_text);
519
-                $color_select = new \XoopsFormSelect('', "option_color[{$i}]", $current_bar);
520
-                $color_select->addOptionArray($barcolor_array);
521
-                $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'");
522
-                $color_label = new \XoopsFormLabel('', "<img src='"
523
-                                                      . $GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/{$current_bar}")
524
-                                                      . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' class='alignbottom' width='30' height='15' alt='' /><br>");
525
-                $option_tray->addElement($color_select);
526
-                $option_tray->addElement($color_label);
527
-                unset($color_select, $color_label, $option_text);
528
-                if (!next($barcolor_array)) {
529
-                    reset($barcolor_array);
608
+                    $msg = $xpPollHandler->getHtmlErrors();
530 609
                 }
531
-            }
532
-        }
533
-        $poll_form->addElement($option_tray);
534
-        $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit'));
535
-        $poll_form->addElement(new \XoopsFormHidden('op', 'savemore'));
536
-        $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
537
-        $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
538
-
539
-        echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n";
540
-        $poll_form->display();
541
-        break;
542
-
543
-    case 'savemore':
544
-        // check security token
545
-        if (!$GLOBALS['xoopsSecurity']->check()) {
546
-            redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
547
-        }
548
-
549
-        $option_text   = Request::getString('option_text', '', 'POST');
550
-        $option_string = is_array($option_text) ? implode('', $option_text) : $option_text;
551
-        $option_string = trim($option_string);
552
-        if ('' === $option_string) {
553
-            // irmtfan - issue with javascript:history.go(-1)
554
-            redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !');
555
-        }
556
-        $i            = 0;
557
-        $option_color = Request::getArray('option_color', null, 'POST');
558
-        foreach ($option_text as $optxt) {
559
-            $optxt = trim($optxt);
560
-            if ('' !== $optxt) {
561
-                // new xoopspoll module
562
-                if ($pollModuleHandler->getVar('version') >= 140) {
563
-                    $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
564
-                    $optionObject = $xpOptHandler->create();
565
-                    $optionObject->setVar('option_text', $optxt);
566
-                    $optionObject->setVar('poll_id', $poll_id);
567
-                    $optionObject->setVar('option_color', $option_color[$i]);
568
-                    $xpOptHandler->insert($optionObject);
569 610
                 // old xoopspoll or umfrage or any clone from them
611
+            } else {
612
+                $status      = $pollObject->delete();
613
+                $classOption = $classPoll . 'Option';
614
+                $classLog    = $classPoll . 'Log';
615
+                if (false !== $status) {
616
+                    $classOption::deleteByPollId($poll_id);
617
+                    $classLog::deleteByPollId($poll_id);
570 618
                 } else {
571
-                    $classOption  = $classPoll . 'Option';
572
-                    $optionObject = new $classOption();
573
-                    $optionObject->setVar('option_text', $optxt);
574
-                    $optionObject->setVar('poll_id', $poll_id);
575
-                    $optionObject->setVar('option_color', $option_color[$i]);
576
-                    $optionObject->store();
619
+                    $msg = $pollObject->getHtmlErrors();
577 620
                 }
578
-                unset($optionObject);
579 621
             }
580
-            ++$i;
581
-        }
582
-        require_once $GLOBALS['xoops']->path('class/template.php');
583
-        xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid'));
584
-        xoops_template_clear_module_cache($pollModuleHandler->getVar('mid'));
585
-        redirect_header("polls.php?op=edit&amp;poll_id={$poll_id}&amp;topic_id={$topic_id}", 2, _MD_NEWBB_POLL_DBUPDATED);
586
-        break;
587
-
588
-    case 'delete':
589
-        echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n";
590
-        xoops_confirm(['op' => 'delete_ok', 'topic_id' => $topic_id, 'poll_id' => $poll_id], 'polls.php', sprintf(_MD_NEWBB_POLL_RUSUREDEL, $pollObject->getVar('question')));
591
-        break;
592
-
593
-    case 'delete_ok':
594
-        // check security token
595
-        if (!$GLOBALS['xoopsSecurity']->check()) {
596
-            redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
597
-        }
598
-        //try and delete the poll
599
-        // new xoopspoll module
600
-        if ($pollModuleHandler->getVar('version') >= 140) {
601
-            $status = $xpPollHandler->delete($pollObject);
602 622
             if (false !== $status) {
603
-                $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
604
-                $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log');
605
-                $xpOptHandler->deleteByPollId($poll_id);
606
-                $xpLogHandler->deleteByPollId($poll_id);
623
+                require_once $GLOBALS['xoops']->path('class/template.php');
624
+                xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
625
+                xoops_template_clear_module_cache($pollModuleHandler->getVar('mid'));
626
+                // delete comments for this poll
627
+                xoops_comment_delete($xoopsModule->getVar('mid'), $poll_id);
628
+
629
+                $topicObject->setVar('votes', 0); // not sure why we want to clear votes too... but I left it alone
630
+                $topicObject->setVar('topic_haspoll', 0);
631
+                $topicObject->setVar('poll_id', 0);
632
+                $success = $topicHandler->insert($topicObject);
633
+                if (!$success) {
634
+                    xoops_error($topicHandler->getHtmlErrors());
635
+                    break;
636
+                }
607 637
             } else {
608
-                $msg = $xpPollHandler->getHtmlErrors();
638
+                xoops_error($msg);
639
+                break;
609 640
             }
641
+            redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id={$topic_id}", 1, _MD_NEWBB_POLL_DBUPDATED);
642
+            break;
643
+
644
+        case 'restart':
645
+            // new xoopspoll module
646
+            if ($pollModuleHandler->getVar('version') >= 140) {
647
+                $classConstants   = new XoopsModules\Xoopspoll\Constants();
648
+                $default_poll_duration = $classConstants::DEFAULT_POLL_DURATION;
610 649
             // old xoopspoll or umfrage or any clone from them
611
-        } else {
612
-            $status      = $pollObject->delete();
613
-            $classOption = $classPoll . 'Option';
614
-            $classLog    = $classPoll . 'Log';
615
-            if (false !== $status) {
616
-                $classOption::deleteByPollId($poll_id);
617
-                $classLog::deleteByPollId($poll_id);
618 650
             } else {
619
-                $msg = $pollObject->getHtmlErrors();
651
+                $default_poll_duration = (86400 * 10);
620 652
             }
621
-        }
622
-        if (false !== $status) {
623
-            require_once $GLOBALS['xoops']->path('class/template.php');
624
-            xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
625
-            xoops_template_clear_module_cache($pollModuleHandler->getVar('mid'));
626
-            // delete comments for this poll
627
-            xoops_comment_delete($xoopsModule->getVar('mid'), $poll_id);
653
+            $poll_form   = new \XoopsThemeForm(_MD_NEWBB_POLL_RESTARTPOLL, 'poll_form', 'polls.php', 'post', true);
654
+            $expire_text = new \XoopsFormText(
655
+                _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(
656
+                _MD_NEWBB_POLL_EXPIREDAT,
657
+                                                                                                                                                                                                                         formatTimestamp($pollObject->getVar('end_time'), 'Y-m-d H:i:s')
658
+            ) . '</small>',
659
+                                             'end_time',
660
+                20,
661
+                19,
662
+                formatTimestamp(time() + $default_poll_duration, 'Y-m-d H:i:s')
663
+            );
664
+            $poll_form->addElement($expire_text);
665
+            $poll_form->addElement(new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', 1));
666
+            $poll_form->addElement(new \XoopsFormRadioYN(_MD_NEWBB_POLL_RESET, 'reset', 0));
667
+            $poll_form->addElement(new \XoopsFormHidden('op', 'restart_ok'));
668
+            $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
669
+            $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
670
+            $poll_form->addElement(new \XoopsFormButton('', 'poll_submit', _MD_NEWBB_POLL_RESTART, 'submit'));
628 671
 
629
-            $topicObject->setVar('votes', 0); // not sure why we want to clear votes too... but I left it alone
630
-            $topicObject->setVar('topic_haspoll', 0);
631
-            $topicObject->setVar('poll_id', 0);
632
-            $success = $topicHandler->insert($topicObject);
633
-            if (!$success) {
634
-                xoops_error($topicHandler->getHtmlErrors());
635
-                break;
636
-            }
637
-        } else {
638
-            xoops_error($msg);
672
+            echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n";
673
+            $poll_form->display();
639 674
             break;
640
-        }
641
-        redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id={$topic_id}", 1, _MD_NEWBB_POLL_DBUPDATED);
642
-        break;
643
-
644
-    case 'restart':
645
-        // new xoopspoll module
646
-        if ($pollModuleHandler->getVar('version') >= 140) {
647
-            $classConstants   = new XoopsModules\Xoopspoll\Constants();
648
-            $default_poll_duration = $classConstants::DEFAULT_POLL_DURATION;
649
-        // old xoopspoll or umfrage or any clone from them
650
-        } else {
651
-            $default_poll_duration = (86400 * 10);
652
-        }
653
-        $poll_form   = new \XoopsThemeForm(_MD_NEWBB_POLL_RESTARTPOLL, 'poll_form', 'polls.php', 'post', true);
654
-        $expire_text = new \XoopsFormText(
655
-            _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(
656
-            _MD_NEWBB_POLL_EXPIREDAT,
657
-                                                                                                                                                                                                                     formatTimestamp($pollObject->getVar('end_time'), 'Y-m-d H:i:s')
658
-        ) . '</small>',
659
-                                         'end_time',
660
-            20,
661
-            19,
662
-            formatTimestamp(time() + $default_poll_duration, 'Y-m-d H:i:s')
663
-        );
664
-        $poll_form->addElement($expire_text);
665
-        $poll_form->addElement(new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', 1));
666
-        $poll_form->addElement(new \XoopsFormRadioYN(_MD_NEWBB_POLL_RESET, 'reset', 0));
667
-        $poll_form->addElement(new \XoopsFormHidden('op', 'restart_ok'));
668
-        $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id));
669
-        $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id));
670
-        $poll_form->addElement(new \XoopsFormButton('', 'poll_submit', _MD_NEWBB_POLL_RESTART, 'submit'));
671
-
672
-        echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n";
673
-        $poll_form->display();
674
-        break;
675
-
676
-    case 'restart_ok':
677
-        // check security token
678
-        if (!$GLOBALS['xoopsSecurity']->check()) {
679
-            redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
680
-        }
681 675
 
682
-        // new xoopspoll module
683
-        if ($pollModuleHandler->getVar('version') >= 140) {
684
-            $classConstants   = new XoopsModules\Xoopspoll\Constants();
685
-            $default_poll_duration = $classConstants::DEFAULT_POLL_DURATION;
686
-            $poll_not_mailed       = $classConstants::POLL_NOT_MAILED;
687
-            $poll_mailed           = $classConstants::POLL_MAILED;
688
-        // old xoopspoll or umfrage or any clone from them
689
-        } else {
690
-            $default_poll_duration = (86400 * 10);
691
-            $poll_not_mailed       = Xoopspoll\Constants::POLL_NOT_MAILED;
692
-            $poll_mailed           = Xoopspoll\Constants::POLL_MAILED;
693
-        }
676
+        case 'restart_ok':
677
+            // check security token
678
+            if (!$GLOBALS['xoopsSecurity']->check()) {
679
+                redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
680
+            }
694 681
 
695
-        $end_time = !Request::getInt('end_time', 0, 'POST');
696
-        if (0 !== $end_time) {
697
-            $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null;
698
-            $pollObject->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($end_time) : strtotime($end_time), $timezone));
699
-        } else {
700
-            $pollObject->setVar('end_time', time() + $default_poll_duration);
701
-        }
682
+            // new xoopspoll module
683
+            if ($pollModuleHandler->getVar('version') >= 140) {
684
+                $classConstants   = new XoopsModules\Xoopspoll\Constants();
685
+                $default_poll_duration = $classConstants::DEFAULT_POLL_DURATION;
686
+                $poll_not_mailed       = $classConstants::POLL_NOT_MAILED;
687
+                $poll_mailed           = $classConstants::POLL_MAILED;
688
+            // old xoopspoll or umfrage or any clone from them
689
+            } else {
690
+                $default_poll_duration = (86400 * 10);
691
+                $poll_not_mailed       = Xoopspoll\Constants::POLL_NOT_MAILED;
692
+                $poll_mailed           = Xoopspoll\Constants::POLL_MAILED;
693
+            }
702 694
 
703
-        $isNotify = Request::getInt('notify', 0, 'POST');
704
-        if (!empty($isNotify) && ($end_time > time())) {
705
-            // if notify, set mail status to "not mailed"
706
-            $pollObject->setVar('mail_status', $poll_not_mailed);
707
-        } else {
708
-            // if not notify, set mail status to already "mailed"
709
-            $pollObject->setVar('mail_status', $poll_mailed);
710
-        }
695
+            $end_time = !Request::getInt('end_time', 0, 'POST');
696
+            if (0 !== $end_time) {
697
+                $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null;
698
+                $pollObject->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($end_time) : strtotime($end_time), $timezone));
699
+            } else {
700
+                $pollObject->setVar('end_time', time() + $default_poll_duration);
701
+            }
711 702
 
712
-        // new xoopspoll module
713
-        if ($pollModuleHandler->getVar('version') >= 140) {
714
-            if (!$xpPollHandler->insert($pollObject)) {  // update the poll
715
-                xoops_error($pollObject->getHtmlErrors());
716
-                exit();
703
+            $isNotify = Request::getInt('notify', 0, 'POST');
704
+            if (!empty($isNotify) && ($end_time > time())) {
705
+                // if notify, set mail status to "not mailed"
706
+                $pollObject->setVar('mail_status', $poll_not_mailed);
707
+            } else {
708
+                // if not notify, set mail status to already "mailed"
709
+                $pollObject->setVar('mail_status', $poll_mailed);
717 710
             }
718
-            if (Request::getInt('reset', 0, 'POST')) { // reset all vote/voter counters
719
-                /** @var Xoopspoll\OptionHandler $xpOptHandler */
720
-                $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
721
-                /** @var Xoopspoll\LogHandler $xpLogHandler */
722
-                $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log');
723
-                $xpLogHandler->deleteByPollId($poll_id);
724
-                $xpOptHandler->resetCountByPollId($poll_id);
725
-                $xpPollHandler->updateCount($pollObject);
711
+
712
+            // new xoopspoll module
713
+            if ($pollModuleHandler->getVar('version') >= 140) {
714
+                if (!$xpPollHandler->insert($pollObject)) {  // update the poll
715
+                    xoops_error($pollObject->getHtmlErrors());
716
+                    exit();
717
+                }
718
+                if (Request::getInt('reset', 0, 'POST')) { // reset all vote/voter counters
719
+                    /** @var Xoopspoll\OptionHandler $xpOptHandler */
720
+                    $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
721
+                    /** @var Xoopspoll\LogHandler $xpLogHandler */
722
+                    $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log');
723
+                    $xpLogHandler->deleteByPollId($poll_id);
724
+                    $xpOptHandler->resetCountByPollId($poll_id);
725
+                    $xpPollHandler->updateCount($pollObject);
726
+                }
727
+                // old xoopspoll or umfrage or any clone from them
728
+            } else {
729
+                if (!$pollObject->store()) { // update the poll
730
+                    xoops_error($pollObject->getHtmlErrors());
731
+                    exit();
732
+                }
733
+                if (Request::getInt('reset', 0, 'POST')) { // reset all logs
734
+                    $classOption = $classPoll . 'Option';
735
+                    $classLog    = $classPoll . 'Log';
736
+                    $classLog::deleteByPollId($poll_id);
737
+                    $classOption::resetCountByPollId($poll_id);
738
+                    $pollObject->updateCount();
739
+                }
726 740
             }
741
+            require_once $GLOBALS['xoops']->path('class/template.php');
742
+            xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
743
+            xoops_template_clear_module_cache($pollModuleHandler->getVar('mid'));
744
+            redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id={$topic_id}", 1, _MD_NEWBB_POLL_DBUPDATED);
745
+            break;
746
+
747
+        case 'log':
748
+            // new xoopspoll module
749
+            if ($pollModuleHandler->getVar('version') >= 140) {
750
+                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);
727 751
             // old xoopspoll or umfrage or any clone from them
728
-        } else {
729
-            if (!$pollObject->store()) { // update the poll
730
-                xoops_error($pollObject->getHtmlErrors());
731
-                exit();
732
-            }
733
-            if (Request::getInt('reset', 0, 'POST')) { // reset all logs
734
-                $classOption = $classPoll . 'Option';
735
-                $classLog    = $classPoll . 'Log';
736
-                $classLog::deleteByPollId($poll_id);
737
-                $classOption::resetCountByPollId($poll_id);
738
-                $pollObject->updateCount();
752
+            } else {
753
+                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);
739 754
             }
740
-        }
741
-        require_once $GLOBALS['xoops']->path('class/template.php');
742
-        xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
743
-        xoops_template_clear_module_cache($pollModuleHandler->getVar('mid'));
744
-        redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id={$topic_id}", 1, _MD_NEWBB_POLL_DBUPDATED);
745
-        break;
746
-
747
-    case 'log':
748
-        // new xoopspoll module
749
-        if ($pollModuleHandler->getVar('version') >= 140) {
750
-            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);
751
-        // old xoopspoll or umfrage or any clone from them
752
-        } else {
753
-            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);
754
-        }
755
-        break;
755
+            break;
756 756
 } // switch
757 757
 
758 758
 // irmtfan move to footer.php
Please login to merge, or discard this patch.