@@ -109,213 +109,377 @@ discard block |
||
109 | 109 | } |
110 | 110 | } |
111 | 111 | switch ($op) { |
112 | - case 'add': |
|
113 | - // new xoopspoll module |
|
114 | - if ($pollModuleHandler->getVar('version') >= 140) { |
|
115 | - echo '<h4>' . _MD_NEWBB_POLL_CREATNEWPOLL . "</h4>\n"; |
|
116 | - $pollObject->renderForm(Request::getString('PHP_SELF', '', 'SERVER'), 'post', ['topic_id' => $topic_id]); |
|
117 | - // old xoopspoll or umfrage or any clone from them |
|
118 | - } else { |
|
119 | - $classOption = $classPoll . 'Option'; |
|
120 | - $poll_form = new \XoopsThemeForm(_MD_NEWBB_POLL_CREATNEWPOLL, 'poll_form', 'polls.php', 'post', true); |
|
121 | - $author_label = new \XoopsFormLabel(_MD_NEWBB_POLL_AUTHOR, is_object($GLOBALS['xoopsUser']) ? ("<a href='" |
|
122 | - . XOOPS_URL |
|
123 | - . '/userinfo.php?uid=' |
|
124 | - . $GLOBALS['xoopsUser']->getVar('uid') |
|
125 | - . "'>" |
|
126 | - . newbbGetUnameFromId($GLOBALS['xoopsUser']->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname']) |
|
127 | - . '</a>') : $GLOBALS['xoopsConfig']['anonymous']); |
|
128 | - $poll_form->addElement($author_label); |
|
129 | - $question_text = new \XoopsFormText(_MD_NEWBB_POLL_POLLQUESTION, 'question', 50, 255); |
|
130 | - $poll_form->addElement($question_text); |
|
131 | - $desc_tarea = new \XoopsFormTextarea(_MD_NEWBB_POLL_POLLDESC, 'description'); |
|
132 | - $poll_form->addElement($desc_tarea); |
|
133 | - $currenttime = formatTimestamp(time(), 'Y-m-d H:i:s'); |
|
134 | - $endtime = formatTimestamp(time() + 604800, 'Y-m-d H:i:s'); |
|
135 | - $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); |
|
136 | - $poll_form->addElement($expire_text); |
|
112 | + case 'add': |
|
113 | + // new xoopspoll module |
|
114 | + if ($pollModuleHandler->getVar('version') >= 140) { |
|
115 | + echo '<h4>' . _MD_NEWBB_POLL_CREATNEWPOLL . "</h4>\n"; |
|
116 | + $pollObject->renderForm(Request::getString('PHP_SELF', '', 'SERVER'), 'post', ['topic_id' => $topic_id]); |
|
117 | + // old xoopspoll or umfrage or any clone from them |
|
118 | + } else { |
|
119 | + $classOption = $classPoll . 'Option'; |
|
120 | + $poll_form = new \XoopsThemeForm(_MD_NEWBB_POLL_CREATNEWPOLL, 'poll_form', 'polls.php', 'post', true); |
|
121 | + $author_label = new \XoopsFormLabel(_MD_NEWBB_POLL_AUTHOR, is_object($GLOBALS['xoopsUser']) ? ("<a href='" |
|
122 | + . XOOPS_URL |
|
123 | + . '/userinfo.php?uid=' |
|
124 | + . $GLOBALS['xoopsUser']->getVar('uid') |
|
125 | + . "'>" |
|
126 | + . newbbGetUnameFromId($GLOBALS['xoopsUser']->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname']) |
|
127 | + . '</a>') : $GLOBALS['xoopsConfig']['anonymous']); |
|
128 | + $poll_form->addElement($author_label); |
|
129 | + $question_text = new \XoopsFormText(_MD_NEWBB_POLL_POLLQUESTION, 'question', 50, 255); |
|
130 | + $poll_form->addElement($question_text); |
|
131 | + $desc_tarea = new \XoopsFormTextarea(_MD_NEWBB_POLL_POLLDESC, 'description'); |
|
132 | + $poll_form->addElement($desc_tarea); |
|
133 | + $currenttime = formatTimestamp(time(), 'Y-m-d H:i:s'); |
|
134 | + $endtime = formatTimestamp(time() + 604800, 'Y-m-d H:i:s'); |
|
135 | + $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); |
|
136 | + $poll_form->addElement($expire_text); |
|
137 | 137 | |
138 | - $weight_text = new \XoopsFormText(_MD_NEWBB_POLL_DISPLAYORDER, 'weight', 6, 5, 0); |
|
139 | - $poll_form->addElement($weight_text); |
|
140 | - |
|
141 | - $multi_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_ALLOWMULTI, 'multiple', 0); |
|
142 | - $poll_form->addElement($multi_yn); |
|
143 | - |
|
144 | - $notify_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', 1); |
|
145 | - $poll_form->addElement($notify_yn); |
|
146 | - |
|
147 | - $option_tray = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, ''); |
|
148 | - $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars/')); |
|
149 | - for ($i = 0; $i < 10; ++$i) { |
|
150 | - $current_bar = ('blank.gif' !== current($barcolor_array)) ? current($barcolor_array) : next($barcolor_array); |
|
151 | - $option_text = new \XoopsFormText('', 'option_text[]', 50, 255); |
|
152 | - $option_tray->addElement($option_text); |
|
153 | - $color_select = new \XoopsFormSelect('', "option_color[{$i}]", $current_bar); |
|
154 | - $color_select->addOptionArray($barcolor_array); |
|
155 | - $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/" . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars", "", "' . XOOPS_URL . "\")'"); |
|
156 | - $color_label = new \XoopsFormLabel('', "<img src='" |
|
157 | - . XOOPS_URL |
|
158 | - . '/modules/' |
|
159 | - . $GLOBALS['xoopsModuleConfig']['poll_module'] |
|
160 | - . '/assets/images/colorbars/' |
|
161 | - . $current_bar |
|
162 | - . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' width='30' align='bottom' height='15' alt='' /><br>"); |
|
163 | - $option_tray->addElement($color_select); |
|
164 | - $option_tray->addElement($color_label); |
|
165 | - if (!next($barcolor_array)) { |
|
166 | - reset($barcolor_array); |
|
138 | + $weight_text = new \XoopsFormText(_MD_NEWBB_POLL_DISPLAYORDER, 'weight', 6, 5, 0); |
|
139 | + $poll_form->addElement($weight_text); |
|
140 | + |
|
141 | + $multi_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_ALLOWMULTI, 'multiple', 0); |
|
142 | + $poll_form->addElement($multi_yn); |
|
143 | + |
|
144 | + $notify_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', 1); |
|
145 | + $poll_form->addElement($notify_yn); |
|
146 | + |
|
147 | + $option_tray = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, ''); |
|
148 | + $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars/')); |
|
149 | + for ($i = 0; $i < 10; ++$i) { |
|
150 | + $current_bar = ('blank.gif' !== current($barcolor_array)) ? current($barcolor_array) : next($barcolor_array); |
|
151 | + $option_text = new \XoopsFormText('', 'option_text[]', 50, 255); |
|
152 | + $option_tray->addElement($option_text); |
|
153 | + $color_select = new \XoopsFormSelect('', "option_color[{$i}]", $current_bar); |
|
154 | + $color_select->addOptionArray($barcolor_array); |
|
155 | + $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/" . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars", "", "' . XOOPS_URL . "\")'"); |
|
156 | + $color_label = new \XoopsFormLabel('', "<img src='" |
|
157 | + . XOOPS_URL |
|
158 | + . '/modules/' |
|
159 | + . $GLOBALS['xoopsModuleConfig']['poll_module'] |
|
160 | + . '/assets/images/colorbars/' |
|
161 | + . $current_bar |
|
162 | + . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' width='30' align='bottom' height='15' alt='' /><br>"); |
|
163 | + $option_tray->addElement($color_select); |
|
164 | + $option_tray->addElement($color_label); |
|
165 | + if (!next($barcolor_array)) { |
|
166 | + reset($barcolor_array); |
|
167 | + } |
|
168 | + unset($color_select, $color_label); |
|
167 | 169 | } |
168 | - unset($color_select, $color_label); |
|
170 | + $poll_form->addElement($option_tray); |
|
171 | + |
|
172 | + $poll_form->addElement(new \XoopsFormHidden('op', 'save')); |
|
173 | + $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id)); |
|
174 | + $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id)); |
|
175 | + $poll_form->addElement(new \XoopsFormHidden('user_id', is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0)); |
|
176 | + $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit')); |
|
177 | + echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . '</h4>'; |
|
178 | + $poll_form->display(); |
|
169 | 179 | } |
170 | - $poll_form->addElement($option_tray); |
|
171 | - |
|
172 | - $poll_form->addElement(new \XoopsFormHidden('op', 'save')); |
|
173 | - $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id)); |
|
174 | - $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id)); |
|
175 | - $poll_form->addElement(new \XoopsFormHidden('user_id', is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0)); |
|
176 | - $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit')); |
|
177 | - echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . '</h4>'; |
|
178 | - $poll_form->display(); |
|
179 | - } |
|
180 | - break; // op: add |
|
180 | + break; // op: add |
|
181 | 181 | |
182 | - case 'edit': |
|
183 | - // new xoopspoll module |
|
184 | - if ($pollModuleHandler->getVar('version') >= 140) { |
|
185 | - echo '<h4>' . _MD_NEWBB_POLL_EDITPOLL . "</h4>\n"; |
|
186 | - $pollObject->renderForm(Request::getString('PHP_SELF', '', 'SERVER'), 'post', ['topic_id' => $topic_id]); |
|
187 | - // old xoopspoll or umfrage or any clone from them |
|
188 | - } else { |
|
189 | - $classOption = $classPoll . 'Option'; |
|
190 | - $poll_form = new \XoopsThemeForm(_MD_NEWBB_POLL_EDITPOLL, 'poll_form', 'polls.php', 'post', true); |
|
191 | - $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>'); |
|
192 | - $poll_form->addElement($author_label); |
|
193 | - $question_text = new \XoopsFormText(_MD_NEWBB_POLL_POLLQUESTION, 'question', 50, 255, $pollObject->getVar('question', 'E')); |
|
194 | - $poll_form->addElement($question_text); |
|
195 | - $desc_tarea = new \XoopsFormTextarea(_MD_NEWBB_POLL_POLLDESC, 'description', $pollObject->getVar('description', 'E')); |
|
196 | - $poll_form->addElement($desc_tarea); |
|
197 | - $date = formatTimestamp($pollObject->getVar('end_time'), 'Y-m-d H:i:s'); // important "Y-m-d H:i:s" use in jdf function |
|
198 | - if (!$pollObject->hasExpired()) { |
|
199 | - $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); |
|
200 | - $poll_form->addElement($expire_text); |
|
182 | + case 'edit': |
|
183 | + // new xoopspoll module |
|
184 | + if ($pollModuleHandler->getVar('version') >= 140) { |
|
185 | + echo '<h4>' . _MD_NEWBB_POLL_EDITPOLL . "</h4>\n"; |
|
186 | + $pollObject->renderForm(Request::getString('PHP_SELF', '', 'SERVER'), 'post', ['topic_id' => $topic_id]); |
|
187 | + // old xoopspoll or umfrage or any clone from them |
|
201 | 188 | } else { |
202 | - // irmtfan full URL - add topic_id |
|
203 | - $restart_label = new \XoopsFormLabel( |
|
204 | - _MD_NEWBB_POLL_EXPIRATION, |
|
205 | - sprintf(_MD_NEWBB_POLL_EXPIREDAT, $date) . "<br><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/polls.php?op=restart&poll_id={$poll_id}&topic_id={$topic_id}'>" . _MD_NEWBB_POLL_RESTART . '</a>' |
|
206 | - ); |
|
207 | - $poll_form->addElement($restart_label); |
|
208 | - } |
|
209 | - $weight_text = new \XoopsFormText(_MD_NEWBB_POLL_DISPLAYORDER, 'weight', 6, 5, $pollObject->getVar('weight')); |
|
210 | - $poll_form->addElement($weight_text); |
|
211 | - $multi_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_ALLOWMULTI, 'multiple', $pollObject->getVar('multiple')); |
|
212 | - $poll_form->addElement($multi_yn); |
|
213 | - $options_arr =& $classOption::getAllByPollId($poll_id); |
|
214 | - $notify_value = 1; |
|
215 | - if (0 !== $pollObject->getVar('mail_status')) { |
|
216 | - $notify_value = 0; |
|
217 | - } |
|
218 | - $notify_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', $notify_value); |
|
219 | - $poll_form->addElement($notify_yn); |
|
220 | - $option_tray = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, ''); |
|
221 | - $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/")); |
|
222 | - $i = 0; |
|
223 | - foreach ($options_arr as $option) { |
|
224 | - /** @var \XoopsPoll $option */ |
|
225 | - $option_tray->addElement(new \XoopsFormText('', 'option_text[]', 50, 255, $option->getVar('option_text'))); |
|
226 | - $option_tray->addElement(new \XoopsFormHidden('option_id[]', $option->getVar('option_id'))); |
|
227 | - $color_select = new \XoopsFormSelect('', 'option_color[{$i}]', $option->getVar('option_color')); |
|
228 | - $color_select->addOptionArray($barcolor_array); |
|
229 | - $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[" . $i . "]\", \"modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'"); |
|
230 | - $color_label = new \XoopsFormLabel('', "<img src='" |
|
231 | - . $GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/" . $option->getVar('option_color', 'E')) |
|
232 | - . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' class='alignbottom' width='30' height='15' alt='' /><br>"); |
|
233 | - $option_tray->addElement($color_select); |
|
234 | - $option_tray->addElement($color_label); |
|
235 | - unset($color_select, $color_label); |
|
236 | - ++$i; |
|
189 | + $classOption = $classPoll . 'Option'; |
|
190 | + $poll_form = new \XoopsThemeForm(_MD_NEWBB_POLL_EDITPOLL, 'poll_form', 'polls.php', 'post', true); |
|
191 | + $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>'); |
|
192 | + $poll_form->addElement($author_label); |
|
193 | + $question_text = new \XoopsFormText(_MD_NEWBB_POLL_POLLQUESTION, 'question', 50, 255, $pollObject->getVar('question', 'E')); |
|
194 | + $poll_form->addElement($question_text); |
|
195 | + $desc_tarea = new \XoopsFormTextarea(_MD_NEWBB_POLL_POLLDESC, 'description', $pollObject->getVar('description', 'E')); |
|
196 | + $poll_form->addElement($desc_tarea); |
|
197 | + $date = formatTimestamp($pollObject->getVar('end_time'), 'Y-m-d H:i:s'); // important "Y-m-d H:i:s" use in jdf function |
|
198 | + if (!$pollObject->hasExpired()) { |
|
199 | + $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); |
|
200 | + $poll_form->addElement($expire_text); |
|
201 | + } else { |
|
202 | + // irmtfan full URL - add topic_id |
|
203 | + $restart_label = new \XoopsFormLabel( |
|
204 | + _MD_NEWBB_POLL_EXPIRATION, |
|
205 | + sprintf(_MD_NEWBB_POLL_EXPIREDAT, $date) . "<br><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/polls.php?op=restart&poll_id={$poll_id}&topic_id={$topic_id}'>" . _MD_NEWBB_POLL_RESTART . '</a>' |
|
206 | + ); |
|
207 | + $poll_form->addElement($restart_label); |
|
208 | + } |
|
209 | + $weight_text = new \XoopsFormText(_MD_NEWBB_POLL_DISPLAYORDER, 'weight', 6, 5, $pollObject->getVar('weight')); |
|
210 | + $poll_form->addElement($weight_text); |
|
211 | + $multi_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_ALLOWMULTI, 'multiple', $pollObject->getVar('multiple')); |
|
212 | + $poll_form->addElement($multi_yn); |
|
213 | + $options_arr =& $classOption::getAllByPollId($poll_id); |
|
214 | + $notify_value = 1; |
|
215 | + if (0 !== $pollObject->getVar('mail_status')) { |
|
216 | + $notify_value = 0; |
|
217 | + } |
|
218 | + $notify_yn = new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', $notify_value); |
|
219 | + $poll_form->addElement($notify_yn); |
|
220 | + $option_tray = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, ''); |
|
221 | + $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/")); |
|
222 | + $i = 0; |
|
223 | + foreach ($options_arr as $option) { |
|
224 | + /** @var \XoopsPoll $option */ |
|
225 | + $option_tray->addElement(new \XoopsFormText('', 'option_text[]', 50, 255, $option->getVar('option_text'))); |
|
226 | + $option_tray->addElement(new \XoopsFormHidden('option_id[]', $option->getVar('option_id'))); |
|
227 | + $color_select = new \XoopsFormSelect('', 'option_color[{$i}]', $option->getVar('option_color')); |
|
228 | + $color_select->addOptionArray($barcolor_array); |
|
229 | + $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[" . $i . "]\", \"modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'"); |
|
230 | + $color_label = new \XoopsFormLabel('', "<img src='" |
|
231 | + . $GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/" . $option->getVar('option_color', 'E')) |
|
232 | + . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' class='alignbottom' width='30' height='15' alt='' /><br>"); |
|
233 | + $option_tray->addElement($color_select); |
|
234 | + $option_tray->addElement($color_label); |
|
235 | + unset($color_select, $color_label); |
|
236 | + ++$i; |
|
237 | + } |
|
238 | + // irmtfan full URL |
|
239 | + $more_label = new \XoopsFormLabel('', "<br><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/polls.php?op=addmore&poll_id={$poll_id}&topic_id={$topic_id}'>" . _MD_NEWBB_POLL_ADDMORE . '</a>'); |
|
240 | + $option_tray->addElement($more_label); |
|
241 | + $poll_form->addElement($option_tray); |
|
242 | + $poll_form->addElement(new \XoopsFormHidden('op', 'update')); |
|
243 | + $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id)); |
|
244 | + $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id)); |
|
245 | + $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit')); |
|
246 | + |
|
247 | + echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n"; |
|
248 | + $poll_form->display(); |
|
237 | 249 | } |
238 | - // irmtfan full URL |
|
239 | - $more_label = new \XoopsFormLabel('', "<br><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/polls.php?op=addmore&poll_id={$poll_id}&topic_id={$topic_id}'>" . _MD_NEWBB_POLL_ADDMORE . '</a>'); |
|
240 | - $option_tray->addElement($more_label); |
|
241 | - $poll_form->addElement($option_tray); |
|
242 | - $poll_form->addElement(new \XoopsFormHidden('op', 'update')); |
|
243 | - $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id)); |
|
244 | - $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id)); |
|
245 | - $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit')); |
|
250 | + break; // op: edit |
|
246 | 251 | |
247 | - echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n"; |
|
248 | - $poll_form->display(); |
|
249 | - } |
|
250 | - break; // op: edit |
|
252 | + case 'save': |
|
253 | + // old xoopspoll or umfrage or any clone from them |
|
254 | + if ($pollModuleHandler->getVar('version') < 140) { |
|
255 | + // check security token |
|
256 | + if (!$GLOBALS['xoopsSecurity']->check()) { |
|
257 | + redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
|
258 | + } |
|
259 | + /* |
|
260 | + * The option check should be done before submitting |
|
261 | + */ |
|
262 | + $option_empty = true; |
|
263 | + if (!Request::getString('option_text', '', 'POST')) { |
|
264 | + // irmtfan - issue with javascript:history.go(-1) |
|
265 | + redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !'); |
|
266 | + } |
|
267 | + $option_text = Request::getArray('option_text', '', 'POST'); |
|
268 | + foreach ($option_text as $optxt) { |
|
269 | + if ('' !== trim($optxt)) { |
|
270 | + $option_empty = false; |
|
271 | + break; |
|
272 | + } |
|
273 | + } |
|
274 | + if ($option_empty) { |
|
275 | + // irmtfan - issue with javascript:history.go(-1) |
|
276 | + redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !'); |
|
277 | + } |
|
278 | + $pollObject->setVar('question', Request::getString('question', '', 'POST')); |
|
279 | + $pollObject->setVar('description', Request::getString('description', '', 'POST')); |
|
280 | + $end_time = Request::getString('end_time', '', 'POST'); // (empty($_POST['end_time'])) ? "" : $_POST['end_time']; |
|
281 | + if ('' !== $end_time) { |
|
282 | + $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null; |
|
283 | + $pollObject->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($end_time) : strtotime($end_time), $timezone)); |
|
284 | + } else { |
|
285 | + // if expiration date is not set, set it to 10 days from now |
|
286 | + $pollObject->setVar('end_time', time() + (86400 * 10)); |
|
287 | + } |
|
251 | 288 | |
252 | - case 'save': |
|
253 | - // old xoopspoll or umfrage or any clone from them |
|
254 | - if ($pollModuleHandler->getVar('version') < 140) { |
|
289 | + $pollObject->setVar('display', 0); |
|
290 | + $pollObject->setVar('weight', Request::getInt('weight', 0, 'POST')); |
|
291 | + $pollObject->setVar('multiple', Request::getInt('multiple', 0, 'POST')); |
|
292 | + $pollObject->setVar('user_id', Request::getInt('user_id', 0, 'POST')); |
|
293 | + if (Request::getInt('notify', 0, 'POST') && $end_time > time()) { |
|
294 | + // if notify, set mail status to "not mailed" |
|
295 | + $pollObject->setVar('mail_status', POLL_NOTMAILED); |
|
296 | + } else { |
|
297 | + // if not notify, set mail status to already "mailed" |
|
298 | + $pollObject->setVar('mail_status', POLL_MAILED); |
|
299 | + } |
|
300 | + $new_poll_id = $pollObject->store(); |
|
301 | + if (empty($new_poll_id)) { |
|
302 | + xoops_error($pollObject->getHtmlErrors); |
|
303 | + break; |
|
304 | + } |
|
305 | + $i = 0; |
|
306 | + $option_color = Request::getArray('option_color', null, 'POST'); |
|
307 | + $classOption = $classPoll . 'Option'; |
|
308 | + foreach ($option_text as $optxt) { |
|
309 | + $optxt = trim($optxt); |
|
310 | + /** @var XoopspollOption $optionObject */ |
|
311 | + $optionObject = new $classOption(); |
|
312 | + if ('' !== $optxt) { |
|
313 | + $optionObject->setVar('option_text', $optxt); |
|
314 | + $optionObject->setVar('option_color', $option_color[$i]); |
|
315 | + $optionObject->setVar('poll_id', $new_poll_id); |
|
316 | + $optionObject->store(); |
|
317 | + } |
|
318 | + ++$i; |
|
319 | + } |
|
320 | + // clear the template cache so changes take effect immediately |
|
321 | + require_once $GLOBALS['xoops']->path('class/template.php'); |
|
322 | + xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid')); |
|
323 | + xoops_template_clear_module_cache($pollModuleHandler->getVar('mid')); |
|
324 | + |
|
325 | + // update topic to indicate it has a poll |
|
326 | + $topicObject->setVar('topic_haspoll', 1); |
|
327 | + $topicObject->setVar('poll_id', $new_poll_id); |
|
328 | + $success = $topicHandler->insert($topicObject); |
|
329 | + if (!$success) { |
|
330 | + xoops_error($topicHandler->getHtmlErrors()); |
|
331 | + } else { |
|
332 | + redirect_header("viewtopic.php?topic_id={$topic_id}", 2, _MD_NEWBB_POLL_DBUPDATED); |
|
333 | + } |
|
334 | + break;// op: save |
|
335 | + } |
|
336 | + // no break |
|
337 | + case 'update': |
|
255 | 338 | // check security token |
256 | 339 | if (!$GLOBALS['xoopsSecurity']->check()) { |
257 | 340 | redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
258 | 341 | } |
259 | - /* |
|
260 | - * The option check should be done before submitting |
|
261 | - */ |
|
262 | - $option_empty = true; |
|
263 | - if (!Request::getString('option_text', '', 'POST')) { |
|
264 | - // irmtfan - issue with javascript:history.go(-1) |
|
342 | + /* make sure there's at least one option */ |
|
343 | + $option_text = Request::getString('option_text', '', 'POST'); |
|
344 | + $option_string = is_array($option_text) ? implode('', $option_text) : $option_text; |
|
345 | + $option_string = trim($option_string); |
|
346 | + if ('' === $option_string) { |
|
265 | 347 | redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !'); |
266 | 348 | } |
267 | - $option_text = Request::getArray('option_text', '', 'POST'); |
|
268 | - foreach ($option_text as $optxt) { |
|
269 | - if ('' !== trim($optxt)) { |
|
270 | - $option_empty = false; |
|
271 | - break; |
|
349 | + |
|
350 | + // new xoopspoll module |
|
351 | + if ($pollModuleHandler->getVar('version') >= 140) { |
|
352 | + /** @var \XoopspollOptionHandler $xpOptHandler */ |
|
353 | + $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option'); |
|
354 | + /** @var \XoopspollLogHandler $xpLogHandler */ |
|
355 | + $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log'); |
|
356 | + // $classRequest = ucfirst($GLOBALS['xoopsModuleConfig']["poll_module"]) . "Request"; |
|
357 | + $classConstants = ucfirst($GLOBALS['xoopsModuleConfig']['poll_module']) . 'Constants'; |
|
358 | + $notify = Request::getInt('notify', $classConstants::NOTIFICATION_ENABLED, 'POST'); |
|
359 | + $currentTimestamp = time(); |
|
360 | + //$xuEndTimestamp = method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime(Request::getString('xu_end_time', null, 'POST')) |
|
361 | + // : strtotime(Request::getString('xu_end_time', null, 'POST')); |
|
362 | + $xuEndTimestamp = strtotime(Request::getString('xu_end_time', null, 'POST')); |
|
363 | + $endTimestamp = (!Request::getString('xu_end_time', null, 'POST')) ? ($currentTimestamp + $classConstants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuEndTimestamp); |
|
364 | + //$xuStartTimestamp = method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime(Request::getString('xu_start_time', null, 'POST')) |
|
365 | + // : strtotime(Request::getString('xu_start_time', null, 'POST')); |
|
366 | + $xuStartTimestamp = strtotime(Request::getString('xu_start_time', null, 'POST')); |
|
367 | + $startTimestamp = (!Request::getString('xu_start_time', null, 'POST')) ? ($endTimestamp - $classConstants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuStartTimestamp); |
|
368 | + |
|
369 | + // don't allow changing start time if there are votes in the log |
|
370 | + if (($startTimestamp < $pollObject->getVar('start_time')) |
|
371 | + && ($xpLogHandler->getTotalVotesByPollId($poll_id) > 0)) { |
|
372 | + $startTimestamp = $pollObject->getVar('start_time'); //don't change start time |
|
272 | 373 | } |
273 | - } |
|
274 | - if ($option_empty) { |
|
275 | - // irmtfan - issue with javascript:history.go(-1) |
|
276 | - redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !'); |
|
277 | - } |
|
278 | - $pollObject->setVar('question', Request::getString('question', '', 'POST')); |
|
279 | - $pollObject->setVar('description', Request::getString('description', '', 'POST')); |
|
280 | - $end_time = Request::getString('end_time', '', 'POST'); // (empty($_POST['end_time'])) ? "" : $_POST['end_time']; |
|
281 | - if ('' !== $end_time) { |
|
282 | - $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null; |
|
283 | - $pollObject->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($end_time) : strtotime($end_time), $timezone)); |
|
284 | - } else { |
|
285 | - // if expiration date is not set, set it to 10 days from now |
|
286 | - $pollObject->setVar('end_time', time() + (86400 * 10)); |
|
287 | - } |
|
288 | 374 | |
289 | - $pollObject->setVar('display', 0); |
|
290 | - $pollObject->setVar('weight', Request::getInt('weight', 0, 'POST')); |
|
291 | - $pollObject->setVar('multiple', Request::getInt('multiple', 0, 'POST')); |
|
292 | - $pollObject->setVar('user_id', Request::getInt('user_id', 0, 'POST')); |
|
293 | - if (Request::getInt('notify', 0, 'POST') && $end_time > time()) { |
|
294 | - // if notify, set mail status to "not mailed" |
|
295 | - $pollObject->setVar('mail_status', POLL_NOTMAILED); |
|
375 | + $poll_vars = [ |
|
376 | + 'user_id' => Request::getInt('user_id', $GLOBALS['xoopsUser']->uid(), 'POST'), |
|
377 | + 'question' => Request::getString('question', null, 'POST'), |
|
378 | + 'description' => Request::getText('description', null, 'POST'), |
|
379 | + 'mail_status' => ($classConstants::NOTIFICATION_ENABLED == $notify) ? $classConstants::POLL_NOT_MAILED : $classConstants::POLL_MAILED, |
|
380 | + 'mail_voter' => Request::getInt('mail_voter', $classConstants::NOT_MAIL_POLL_TO_VOTER, 'POST'), |
|
381 | + 'start_time' => $startTimestamp, |
|
382 | + 'end_time' => $endTimestamp, |
|
383 | + 'display' => Request::getInt('display', $classConstants::DO_NOT_DISPLAY_POLL_IN_BLOCK, 'POST'), |
|
384 | + 'visibility' => Request::getInt('visibility', $classConstants::HIDE_NEVER, 'POST'), |
|
385 | + 'weight' => Request::getInt('weight', $classConstants::DEFAULT_WEIGHT, 'POST'), |
|
386 | + 'multiple' => Request::getInt('multiple', $classConstants::NOT_MULTIPLE_SELECT_POLL, 'POST'), |
|
387 | + 'multilimit' => Request::getInt('multilimit', $classConstants::MULTIPLE_SELECT_LIMITLESS, 'POST'), |
|
388 | + 'anonymous' => Request::getInt('anonymous', $classConstants::ANONYMOUS_VOTING_DISALLOWED, 'POST') |
|
389 | + ]; |
|
390 | + $pollObject->setVars($poll_vars); |
|
391 | + $poll_id = $xpPollHandler->insert($pollObject); |
|
392 | + if (!$poll_id) { |
|
393 | + $err = $pollObject->getHtmlErrors(); |
|
394 | + exit($err); |
|
395 | + } |
|
396 | + |
|
397 | + // now get the options |
|
398 | + $optionIdArray = Request::getArray('option_id', [], 'POST'); |
|
399 | + $optionIdArray = array_map('intval', $optionIdArray); |
|
400 | + $optionTextArray = Request::getArray('option_text', [], 'POST'); |
|
401 | + $optionColorArray = Request::getArray('option_color', [], 'POST'); |
|
402 | + |
|
403 | + foreach ($optionIdArray as $key => $oId) { |
|
404 | + if (!empty($oId) && ($optionObject = $xpOptHandler->get($oId))) { |
|
405 | + // existing option object so need to update it |
|
406 | + $optionTextArray[$key] = trim($optionTextArray[$key]); |
|
407 | + if ('' === $optionTextArray[$key]) { |
|
408 | + // want to delete this option |
|
409 | + if (false !== $xpOptHandler->delete($optionObject)) { |
|
410 | + // now remove it from the log |
|
411 | + $xpLogHandler->deleteByOptionId($optionObject->getVar('option_id')); |
|
412 | + //update vote count in poll |
|
413 | + $xpPollHandler->updateCount($pollObject); |
|
414 | + } else { |
|
415 | + xoops_error($xpLogHandler->getHtmlErrors()); |
|
416 | + break; |
|
417 | + } |
|
418 | + } else { |
|
419 | + $optionObject->setVar('option_text', $optionTextArray[$key]); |
|
420 | + $optionObject->setVar('option_color', $optionColorArray[$key]); |
|
421 | + $optionObject->setVar('poll_id', $poll_id); |
|
422 | + $xpOptHandler->insert($optionObject); |
|
423 | + } |
|
424 | + } else { |
|
425 | + // new option object |
|
426 | + $optionObject = $xpOptHandler->create(); |
|
427 | + $optionTextArray[$key] = trim($optionTextArray[$key]); |
|
428 | + if ('' !== $optionTextArray[$key]) { // ignore if text is empty |
|
429 | + $optionObject->setVar('option_text', $optionTextArray[$key]); |
|
430 | + $optionObject->setVar('option_color', $optionColorArray[$key]); |
|
431 | + $optionObject->setVar('poll_id', $poll_id); |
|
432 | + $xpOptHandler->insert($optionObject); |
|
433 | + } |
|
434 | + unset($optionObject); |
|
435 | + } |
|
436 | + } |
|
437 | + // old xoopspoll or umfrage or any clone from them |
|
296 | 438 | } else { |
297 | - // if not notify, set mail status to already "mailed" |
|
298 | - $pollObject->setVar('mail_status', POLL_MAILED); |
|
299 | - } |
|
300 | - $new_poll_id = $pollObject->store(); |
|
301 | - if (empty($new_poll_id)) { |
|
302 | - xoops_error($pollObject->getHtmlErrors); |
|
303 | - break; |
|
304 | - } |
|
305 | - $i = 0; |
|
306 | - $option_color = Request::getArray('option_color', null, 'POST'); |
|
307 | - $classOption = $classPoll . 'Option'; |
|
308 | - foreach ($option_text as $optxt) { |
|
309 | - $optxt = trim($optxt); |
|
310 | - /** @var XoopspollOption $optionObject */ |
|
311 | - $optionObject = new $classOption(); |
|
312 | - if ('' !== $optxt) { |
|
313 | - $optionObject->setVar('option_text', $optxt); |
|
314 | - $optionObject->setVar('option_color', $option_color[$i]); |
|
315 | - $optionObject->setVar('poll_id', $new_poll_id); |
|
316 | - $optionObject->store(); |
|
439 | + $pollObject->setVar('question', Request::getString('question', '', 'POST')); |
|
440 | + $pollObject->setVar('description', Request::getString('description', '', 'POST')); |
|
441 | + |
|
442 | + $end_time = Request::getString('end_time', '', 'POST'); |
|
443 | + if ('' !== $end_time) { |
|
444 | + $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null; |
|
445 | + $pollObject->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($end_time) : strtotime($end_time), $timezone)); |
|
317 | 446 | } |
318 | - ++$i; |
|
447 | + $pollObject->setVar('display', 0); |
|
448 | + $pollObject->setVar('weight', Request::getInt('weight', 0, 'POST')); |
|
449 | + $pollObject->setVar('multiple', Request::getInt('multiple', 0, 'POST')); |
|
450 | + $pollObject->setVar('user_id', Request::getInt('user_id', 0, 'POST')); |
|
451 | + if (Request::getInt('notify', 0, 'POST') && $end_time > time()) { |
|
452 | + // if notify, set mail status to "not mailed" |
|
453 | + $pollObject->setVar('mail_status', POLL_NOTMAILED); |
|
454 | + } else { |
|
455 | + // if not notify, set mail status to already "mailed" |
|
456 | + $pollObject->setVar('mail_status', POLL_MAILED); |
|
457 | + } |
|
458 | + |
|
459 | + if (!$pollObject->store()) { |
|
460 | + xoops_error($pollObject->getHtmlErrors); |
|
461 | + break; |
|
462 | + } |
|
463 | + $i = 0; |
|
464 | + $option_id = Request::getArray('option_id', null, 'POST'); |
|
465 | + $option_color = Request::getArray('option_color', null, 'POST'); |
|
466 | + $classOption = $classPoll . 'Option'; |
|
467 | + $classLog = $classPoll . 'Log'; |
|
468 | + foreach ($option_id as $opid) { |
|
469 | + $optionObject = new $classOption($opid); |
|
470 | + $option_text[$i] = trim($option_text[$i]); |
|
471 | + if ('' !== $option_text[$i]) { |
|
472 | + $optionObject->setVar('option_text', $option_text[$i]); |
|
473 | + $optionObject->setVar('option_color', $option_color[$i]); |
|
474 | + $optionObject->store(); |
|
475 | + } else { |
|
476 | + if (false !== $optionObject->delete()) { |
|
477 | + $classLog::deleteByOptionId($option->getVar('option_id')); |
|
478 | + } |
|
479 | + } |
|
480 | + ++$i; |
|
481 | + } |
|
482 | + $pollObject->updateCount(); |
|
319 | 483 | } |
320 | 484 | // clear the template cache so changes take effect immediately |
321 | 485 | require_once $GLOBALS['xoops']->path('class/template.php'); |
@@ -324,433 +488,269 @@ discard block |
||
324 | 488 | |
325 | 489 | // update topic to indicate it has a poll |
326 | 490 | $topicObject->setVar('topic_haspoll', 1); |
327 | - $topicObject->setVar('poll_id', $new_poll_id); |
|
491 | + $topicObject->setVar('poll_id', $pollObject->getVar('poll_id')); |
|
328 | 492 | $success = $topicHandler->insert($topicObject); |
329 | 493 | if (!$success) { |
330 | 494 | xoops_error($topicHandler->getHtmlErrors()); |
331 | 495 | } else { |
332 | 496 | redirect_header("viewtopic.php?topic_id={$topic_id}", 2, _MD_NEWBB_POLL_DBUPDATED); |
333 | 497 | } |
334 | - break;// op: save |
|
335 | - } |
|
336 | - // no break |
|
337 | - case 'update': |
|
338 | - // check security token |
|
339 | - if (!$GLOBALS['xoopsSecurity']->check()) { |
|
340 | - redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
|
341 | - } |
|
342 | - /* make sure there's at least one option */ |
|
343 | - $option_text = Request::getString('option_text', '', 'POST'); |
|
344 | - $option_string = is_array($option_text) ? implode('', $option_text) : $option_text; |
|
345 | - $option_string = trim($option_string); |
|
346 | - if ('' === $option_string) { |
|
347 | - redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !'); |
|
348 | - } |
|
349 | - |
|
350 | - // new xoopspoll module |
|
351 | - if ($pollModuleHandler->getVar('version') >= 140) { |
|
352 | - /** @var \XoopspollOptionHandler $xpOptHandler */ |
|
353 | - $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option'); |
|
354 | - /** @var \XoopspollLogHandler $xpLogHandler */ |
|
355 | - $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log'); |
|
356 | - // $classRequest = ucfirst($GLOBALS['xoopsModuleConfig']["poll_module"]) . "Request"; |
|
357 | - $classConstants = ucfirst($GLOBALS['xoopsModuleConfig']['poll_module']) . 'Constants'; |
|
358 | - $notify = Request::getInt('notify', $classConstants::NOTIFICATION_ENABLED, 'POST'); |
|
359 | - $currentTimestamp = time(); |
|
360 | - //$xuEndTimestamp = method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime(Request::getString('xu_end_time', null, 'POST')) |
|
361 | - // : strtotime(Request::getString('xu_end_time', null, 'POST')); |
|
362 | - $xuEndTimestamp = strtotime(Request::getString('xu_end_time', null, 'POST')); |
|
363 | - $endTimestamp = (!Request::getString('xu_end_time', null, 'POST')) ? ($currentTimestamp + $classConstants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuEndTimestamp); |
|
364 | - //$xuStartTimestamp = method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime(Request::getString('xu_start_time', null, 'POST')) |
|
365 | - // : strtotime(Request::getString('xu_start_time', null, 'POST')); |
|
366 | - $xuStartTimestamp = strtotime(Request::getString('xu_start_time', null, 'POST')); |
|
367 | - $startTimestamp = (!Request::getString('xu_start_time', null, 'POST')) ? ($endTimestamp - $classConstants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuStartTimestamp); |
|
368 | - |
|
369 | - // don't allow changing start time if there are votes in the log |
|
370 | - if (($startTimestamp < $pollObject->getVar('start_time')) |
|
371 | - && ($xpLogHandler->getTotalVotesByPollId($poll_id) > 0)) { |
|
372 | - $startTimestamp = $pollObject->getVar('start_time'); //don't change start time |
|
498 | + break;// op: save | update |
|
499 | + |
|
500 | + case 'addmore': |
|
501 | + $question = $pollObject->getVar('question'); |
|
502 | + unset($pollObject); |
|
503 | + $poll_form = new \XoopsThemeForm(_MD_NEWBB_POLL_ADDMORE, 'poll_form', 'polls.php', 'post', true); |
|
504 | + $poll_form->addElement(new \XoopsFormLabel(_MD_NEWBB_POLL_POLLQUESTION, $question)); |
|
505 | + // new xoopspoll module |
|
506 | + if ($pollModuleHandler->getVar('version') >= 140) { |
|
507 | + $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option'); |
|
508 | + $option_tray = $xpOptHandler->renderOptionFormTray($poll_id); |
|
509 | + // old xoopspoll or umfrage or any clone from them |
|
510 | + } else { |
|
511 | + $option_tray = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, ''); |
|
512 | + $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars/')); |
|
513 | + for ($i = 0; $i < 10; ++$i) { |
|
514 | + $current_bar = ('blank.gif' !== current($barcolor_array)) ? current($barcolor_array) : next($barcolor_array); |
|
515 | + $option_text = new \XoopsFormText('', 'option_text[]', 50, 255); |
|
516 | + $option_tray->addElement($option_text); |
|
517 | + $color_select = new \XoopsFormSelect('', "option_color[{$i}]", $current_bar); |
|
518 | + $color_select->addOptionArray($barcolor_array); |
|
519 | + $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'"); |
|
520 | + $color_label = new \XoopsFormLabel('', "<img src='" |
|
521 | + . $GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/{$current_bar}") |
|
522 | + . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' class='alignbottom' width='30' height='15' alt='' /><br>"); |
|
523 | + $option_tray->addElement($color_select); |
|
524 | + $option_tray->addElement($color_label); |
|
525 | + unset($color_select, $color_label, $option_text); |
|
526 | + if (!next($barcolor_array)) { |
|
527 | + reset($barcolor_array); |
|
528 | + } |
|
529 | + } |
|
373 | 530 | } |
531 | + $poll_form->addElement($option_tray); |
|
532 | + $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit')); |
|
533 | + $poll_form->addElement(new \XoopsFormHidden('op', 'savemore')); |
|
534 | + $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id)); |
|
535 | + $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id)); |
|
374 | 536 | |
375 | - $poll_vars = [ |
|
376 | - 'user_id' => Request::getInt('user_id', $GLOBALS['xoopsUser']->uid(), 'POST'), |
|
377 | - 'question' => Request::getString('question', null, 'POST'), |
|
378 | - 'description' => Request::getText('description', null, 'POST'), |
|
379 | - 'mail_status' => ($classConstants::NOTIFICATION_ENABLED == $notify) ? $classConstants::POLL_NOT_MAILED : $classConstants::POLL_MAILED, |
|
380 | - 'mail_voter' => Request::getInt('mail_voter', $classConstants::NOT_MAIL_POLL_TO_VOTER, 'POST'), |
|
381 | - 'start_time' => $startTimestamp, |
|
382 | - 'end_time' => $endTimestamp, |
|
383 | - 'display' => Request::getInt('display', $classConstants::DO_NOT_DISPLAY_POLL_IN_BLOCK, 'POST'), |
|
384 | - 'visibility' => Request::getInt('visibility', $classConstants::HIDE_NEVER, 'POST'), |
|
385 | - 'weight' => Request::getInt('weight', $classConstants::DEFAULT_WEIGHT, 'POST'), |
|
386 | - 'multiple' => Request::getInt('multiple', $classConstants::NOT_MULTIPLE_SELECT_POLL, 'POST'), |
|
387 | - 'multilimit' => Request::getInt('multilimit', $classConstants::MULTIPLE_SELECT_LIMITLESS, 'POST'), |
|
388 | - 'anonymous' => Request::getInt('anonymous', $classConstants::ANONYMOUS_VOTING_DISALLOWED, 'POST') |
|
389 | - ]; |
|
390 | - $pollObject->setVars($poll_vars); |
|
391 | - $poll_id = $xpPollHandler->insert($pollObject); |
|
392 | - if (!$poll_id) { |
|
393 | - $err = $pollObject->getHtmlErrors(); |
|
394 | - exit($err); |
|
537 | + echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n"; |
|
538 | + $poll_form->display(); |
|
539 | + break; |
|
540 | + |
|
541 | + case 'savemore': |
|
542 | + // check security token |
|
543 | + if (!$GLOBALS['xoopsSecurity']->check()) { |
|
544 | + redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
|
395 | 545 | } |
396 | 546 | |
397 | - // now get the options |
|
398 | - $optionIdArray = Request::getArray('option_id', [], 'POST'); |
|
399 | - $optionIdArray = array_map('intval', $optionIdArray); |
|
400 | - $optionTextArray = Request::getArray('option_text', [], 'POST'); |
|
401 | - $optionColorArray = Request::getArray('option_color', [], 'POST'); |
|
402 | - |
|
403 | - foreach ($optionIdArray as $key => $oId) { |
|
404 | - if (!empty($oId) && ($optionObject = $xpOptHandler->get($oId))) { |
|
405 | - // existing option object so need to update it |
|
406 | - $optionTextArray[$key] = trim($optionTextArray[$key]); |
|
407 | - if ('' === $optionTextArray[$key]) { |
|
408 | - // want to delete this option |
|
409 | - if (false !== $xpOptHandler->delete($optionObject)) { |
|
410 | - // now remove it from the log |
|
411 | - $xpLogHandler->deleteByOptionId($optionObject->getVar('option_id')); |
|
412 | - //update vote count in poll |
|
413 | - $xpPollHandler->updateCount($pollObject); |
|
414 | - } else { |
|
415 | - xoops_error($xpLogHandler->getHtmlErrors()); |
|
416 | - break; |
|
417 | - } |
|
418 | - } else { |
|
419 | - $optionObject->setVar('option_text', $optionTextArray[$key]); |
|
420 | - $optionObject->setVar('option_color', $optionColorArray[$key]); |
|
547 | + $option_text = Request::getString('option_text', '', 'POST'); |
|
548 | + $option_string = is_array($option_text) ? implode('', $option_text) : $option_text; |
|
549 | + $option_string = trim($option_string); |
|
550 | + if ('' === $option_string) { |
|
551 | + // irmtfan - issue with javascript:history.go(-1) |
|
552 | + redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !'); |
|
553 | + } |
|
554 | + $i = 0; |
|
555 | + $option_color = Request::getArray('option_color', null, 'POST'); |
|
556 | + foreach ($option_text as $optxt) { |
|
557 | + $optxt = trim($optxt); |
|
558 | + if ('' !== $optxt) { |
|
559 | + // new xoopspoll module |
|
560 | + if ($pollModuleHandler->getVar('version') >= 140) { |
|
561 | + $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option'); |
|
562 | + $optionObject = $xpOptHandler->create(); |
|
563 | + $optionObject->setVar('option_text', $optxt); |
|
421 | 564 | $optionObject->setVar('poll_id', $poll_id); |
565 | + $optionObject->setVar('option_color', $option_color[$i]); |
|
422 | 566 | $xpOptHandler->insert($optionObject); |
423 | - } |
|
424 | - } else { |
|
425 | - // new option object |
|
426 | - $optionObject = $xpOptHandler->create(); |
|
427 | - $optionTextArray[$key] = trim($optionTextArray[$key]); |
|
428 | - if ('' !== $optionTextArray[$key]) { // ignore if text is empty |
|
429 | - $optionObject->setVar('option_text', $optionTextArray[$key]); |
|
430 | - $optionObject->setVar('option_color', $optionColorArray[$key]); |
|
567 | + // old xoopspoll or umfrage or any clone from them |
|
568 | + } else { |
|
569 | + $classOption = $classPoll . 'Option'; |
|
570 | + $optionObject = new $classOption(); |
|
571 | + $optionObject->setVar('option_text', $optxt); |
|
431 | 572 | $optionObject->setVar('poll_id', $poll_id); |
432 | - $xpOptHandler->insert($optionObject); |
|
573 | + $optionObject->setVar('option_color', $option_color[$i]); |
|
574 | + $optionObject->store(); |
|
433 | 575 | } |
434 | 576 | unset($optionObject); |
435 | 577 | } |
578 | + ++$i; |
|
436 | 579 | } |
437 | - // old xoopspoll or umfrage or any clone from them |
|
438 | - } else { |
|
439 | - $pollObject->setVar('question', Request::getString('question', '', 'POST')); |
|
440 | - $pollObject->setVar('description', Request::getString('description', '', 'POST')); |
|
580 | + require_once $GLOBALS['xoops']->path('class/template.php'); |
|
581 | + xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid')); |
|
582 | + xoops_template_clear_module_cache($pollModuleHandler->getVar('mid')); |
|
583 | + redirect_header("polls.php?op=edit&poll_id={$poll_id}&topic_id={$topic_id}", 2, _MD_NEWBB_POLL_DBUPDATED); |
|
584 | + break; |
|
441 | 585 | |
442 | - $end_time = Request::getString('end_time', '', 'POST'); |
|
443 | - if ('' !== $end_time) { |
|
444 | - $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null; |
|
445 | - $pollObject->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($end_time) : strtotime($end_time), $timezone)); |
|
446 | - } |
|
447 | - $pollObject->setVar('display', 0); |
|
448 | - $pollObject->setVar('weight', Request::getInt('weight', 0, 'POST')); |
|
449 | - $pollObject->setVar('multiple', Request::getInt('multiple', 0, 'POST')); |
|
450 | - $pollObject->setVar('user_id', Request::getInt('user_id', 0, 'POST')); |
|
451 | - if (Request::getInt('notify', 0, 'POST') && $end_time > time()) { |
|
452 | - // if notify, set mail status to "not mailed" |
|
453 | - $pollObject->setVar('mail_status', POLL_NOTMAILED); |
|
454 | - } else { |
|
455 | - // if not notify, set mail status to already "mailed" |
|
456 | - $pollObject->setVar('mail_status', POLL_MAILED); |
|
457 | - } |
|
586 | + case 'delete': |
|
587 | + echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n"; |
|
588 | + xoops_confirm(['op' => 'delete_ok', 'topic_id' => $topic_id, 'poll_id' => $poll_id], 'polls.php', sprintf(_MD_NEWBB_POLL_RUSUREDEL, $pollObject->getVar('question'))); |
|
589 | + break; |
|
458 | 590 | |
459 | - if (!$pollObject->store()) { |
|
460 | - xoops_error($pollObject->getHtmlErrors); |
|
461 | - break; |
|
591 | + case 'delete_ok': |
|
592 | + // check security token |
|
593 | + if (!$GLOBALS['xoopsSecurity']->check()) { |
|
594 | + redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
|
462 | 595 | } |
463 | - $i = 0; |
|
464 | - $option_id = Request::getArray('option_id', null, 'POST'); |
|
465 | - $option_color = Request::getArray('option_color', null, 'POST'); |
|
466 | - $classOption = $classPoll . 'Option'; |
|
467 | - $classLog = $classPoll . 'Log'; |
|
468 | - foreach ($option_id as $opid) { |
|
469 | - $optionObject = new $classOption($opid); |
|
470 | - $option_text[$i] = trim($option_text[$i]); |
|
471 | - if ('' !== $option_text[$i]) { |
|
472 | - $optionObject->setVar('option_text', $option_text[$i]); |
|
473 | - $optionObject->setVar('option_color', $option_color[$i]); |
|
474 | - $optionObject->store(); |
|
596 | + //try and delete the poll |
|
597 | + // new xoopspoll module |
|
598 | + if ($pollModuleHandler->getVar('version') >= 140) { |
|
599 | + $status = $xpPollHandler->delete($pollObject); |
|
600 | + if (false !== $status) { |
|
601 | + $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option'); |
|
602 | + $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log'); |
|
603 | + $xpOptHandler->deleteByPollId($poll_id); |
|
604 | + $xpLogHandler->deleteByPollId($poll_id); |
|
475 | 605 | } else { |
476 | - if (false !== $optionObject->delete()) { |
|
477 | - $classLog::deleteByOptionId($option->getVar('option_id')); |
|
478 | - } |
|
479 | - } |
|
480 | - ++$i; |
|
481 | - } |
|
482 | - $pollObject->updateCount(); |
|
483 | - } |
|
484 | - // clear the template cache so changes take effect immediately |
|
485 | - require_once $GLOBALS['xoops']->path('class/template.php'); |
|
486 | - xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid')); |
|
487 | - xoops_template_clear_module_cache($pollModuleHandler->getVar('mid')); |
|
488 | - |
|
489 | - // update topic to indicate it has a poll |
|
490 | - $topicObject->setVar('topic_haspoll', 1); |
|
491 | - $topicObject->setVar('poll_id', $pollObject->getVar('poll_id')); |
|
492 | - $success = $topicHandler->insert($topicObject); |
|
493 | - if (!$success) { |
|
494 | - xoops_error($topicHandler->getHtmlErrors()); |
|
495 | - } else { |
|
496 | - redirect_header("viewtopic.php?topic_id={$topic_id}", 2, _MD_NEWBB_POLL_DBUPDATED); |
|
497 | - } |
|
498 | - break;// op: save | update |
|
499 | - |
|
500 | - case 'addmore': |
|
501 | - $question = $pollObject->getVar('question'); |
|
502 | - unset($pollObject); |
|
503 | - $poll_form = new \XoopsThemeForm(_MD_NEWBB_POLL_ADDMORE, 'poll_form', 'polls.php', 'post', true); |
|
504 | - $poll_form->addElement(new \XoopsFormLabel(_MD_NEWBB_POLL_POLLQUESTION, $question)); |
|
505 | - // new xoopspoll module |
|
506 | - if ($pollModuleHandler->getVar('version') >= 140) { |
|
507 | - $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option'); |
|
508 | - $option_tray = $xpOptHandler->renderOptionFormTray($poll_id); |
|
509 | - // old xoopspoll or umfrage or any clone from them |
|
510 | - } else { |
|
511 | - $option_tray = new \XoopsFormElementTray(_MD_NEWBB_POLL_POLLOPTIONS, ''); |
|
512 | - $barcolor_array = \XoopsLists::getImgListAsArray($GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/assets/images/colorbars/')); |
|
513 | - for ($i = 0; $i < 10; ++$i) { |
|
514 | - $current_bar = ('blank.gif' !== current($barcolor_array)) ? current($barcolor_array) : next($barcolor_array); |
|
515 | - $option_text = new \XoopsFormText('', 'option_text[]', 50, 255); |
|
516 | - $option_tray->addElement($option_text); |
|
517 | - $color_select = new \XoopsFormSelect('', "option_color[{$i}]", $current_bar); |
|
518 | - $color_select->addOptionArray($barcolor_array); |
|
519 | - $color_select->setExtra("onchange='showImgSelected(\"option_color_image[{$i}]\", \"option_color[{$i}]\", \"modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars\", \"\", \"" . XOOPS_URL . "\")'"); |
|
520 | - $color_label = new \XoopsFormLabel('', "<img src='" |
|
521 | - . $GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/assets/images/colorbars/{$current_bar}") |
|
522 | - . "' name='option_color_image[{$i}]' id='option_color_image[{$i}]' class='alignbottom' width='30' height='15' alt='' /><br>"); |
|
523 | - $option_tray->addElement($color_select); |
|
524 | - $option_tray->addElement($color_label); |
|
525 | - unset($color_select, $color_label, $option_text); |
|
526 | - if (!next($barcolor_array)) { |
|
527 | - reset($barcolor_array); |
|
606 | + $msg = $xpPollHandler->getHtmlErrors(); |
|
528 | 607 | } |
529 | - } |
|
530 | - } |
|
531 | - $poll_form->addElement($option_tray); |
|
532 | - $poll_form->addElement(new \XoopsFormButtonTray('poll_submit', _SUBMIT, 'submit')); |
|
533 | - $poll_form->addElement(new \XoopsFormHidden('op', 'savemore')); |
|
534 | - $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id)); |
|
535 | - $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id)); |
|
536 | - |
|
537 | - echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n"; |
|
538 | - $poll_form->display(); |
|
539 | - break; |
|
540 | - |
|
541 | - case 'savemore': |
|
542 | - // check security token |
|
543 | - if (!$GLOBALS['xoopsSecurity']->check()) { |
|
544 | - redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
|
545 | - } |
|
546 | - |
|
547 | - $option_text = Request::getString('option_text', '', 'POST'); |
|
548 | - $option_string = is_array($option_text) ? implode('', $option_text) : $option_text; |
|
549 | - $option_string = trim($option_string); |
|
550 | - if ('' === $option_string) { |
|
551 | - // irmtfan - issue with javascript:history.go(-1) |
|
552 | - redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_ERROROCCURED . ': ' . _MD_NEWBB_POLL_POLLOPTIONS . ' !'); |
|
553 | - } |
|
554 | - $i = 0; |
|
555 | - $option_color = Request::getArray('option_color', null, 'POST'); |
|
556 | - foreach ($option_text as $optxt) { |
|
557 | - $optxt = trim($optxt); |
|
558 | - if ('' !== $optxt) { |
|
559 | - // new xoopspoll module |
|
560 | - if ($pollModuleHandler->getVar('version') >= 140) { |
|
561 | - $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option'); |
|
562 | - $optionObject = $xpOptHandler->create(); |
|
563 | - $optionObject->setVar('option_text', $optxt); |
|
564 | - $optionObject->setVar('poll_id', $poll_id); |
|
565 | - $optionObject->setVar('option_color', $option_color[$i]); |
|
566 | - $xpOptHandler->insert($optionObject); |
|
567 | 608 | // old xoopspoll or umfrage or any clone from them |
609 | + } else { |
|
610 | + $status = $pollObject->delete(); |
|
611 | + $classOption = $classPoll . 'Option'; |
|
612 | + $classLog = $classPoll . 'Log'; |
|
613 | + if (false !== $status) { |
|
614 | + $classOption::deleteByPollId($poll_id); |
|
615 | + $classLog::deleteByPollId($poll_id); |
|
568 | 616 | } else { |
569 | - $classOption = $classPoll . 'Option'; |
|
570 | - $optionObject = new $classOption(); |
|
571 | - $optionObject->setVar('option_text', $optxt); |
|
572 | - $optionObject->setVar('poll_id', $poll_id); |
|
573 | - $optionObject->setVar('option_color', $option_color[$i]); |
|
574 | - $optionObject->store(); |
|
617 | + $msg = $pollObject->getHtmlErrors(); |
|
575 | 618 | } |
576 | - unset($optionObject); |
|
577 | 619 | } |
578 | - ++$i; |
|
579 | - } |
|
580 | - require_once $GLOBALS['xoops']->path('class/template.php'); |
|
581 | - xoops_template_clear_module_cache($GLOBALS['xoopsModule']->getVar('mid')); |
|
582 | - xoops_template_clear_module_cache($pollModuleHandler->getVar('mid')); |
|
583 | - redirect_header("polls.php?op=edit&poll_id={$poll_id}&topic_id={$topic_id}", 2, _MD_NEWBB_POLL_DBUPDATED); |
|
584 | - break; |
|
585 | - |
|
586 | - case 'delete': |
|
587 | - echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n"; |
|
588 | - xoops_confirm(['op' => 'delete_ok', 'topic_id' => $topic_id, 'poll_id' => $poll_id], 'polls.php', sprintf(_MD_NEWBB_POLL_RUSUREDEL, $pollObject->getVar('question'))); |
|
589 | - break; |
|
590 | - |
|
591 | - case 'delete_ok': |
|
592 | - // check security token |
|
593 | - if (!$GLOBALS['xoopsSecurity']->check()) { |
|
594 | - redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
|
595 | - } |
|
596 | - //try and delete the poll |
|
597 | - // new xoopspoll module |
|
598 | - if ($pollModuleHandler->getVar('version') >= 140) { |
|
599 | - $status = $xpPollHandler->delete($pollObject); |
|
600 | 620 | if (false !== $status) { |
601 | - $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option'); |
|
602 | - $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log'); |
|
603 | - $xpOptHandler->deleteByPollId($poll_id); |
|
604 | - $xpLogHandler->deleteByPollId($poll_id); |
|
621 | + require_once $GLOBALS['xoops']->path('class/template.php'); |
|
622 | + xoops_template_clear_module_cache($xoopsModule->getVar('mid')); |
|
623 | + xoops_template_clear_module_cache($pollModuleHandler->getVar('mid')); |
|
624 | + // delete comments for this poll |
|
625 | + xoops_comment_delete($xoopsModule->getVar('mid'), $poll_id); |
|
626 | + |
|
627 | + $topicObject->setVar('votes', 0); // not sure why we want to clear votes too... but I left it alone |
|
628 | + $topicObject->setVar('topic_haspoll', 0); |
|
629 | + $topicObject->setVar('poll_id', 0); |
|
630 | + $success = $topicHandler->insert($topicObject); |
|
631 | + if (!$success) { |
|
632 | + xoops_error($topicHandler->getHtmlErrors()); |
|
633 | + break; |
|
634 | + } |
|
605 | 635 | } else { |
606 | - $msg = $xpPollHandler->getHtmlErrors(); |
|
636 | + xoops_error($msg); |
|
637 | + break; |
|
607 | 638 | } |
639 | + redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id={$topic_id}", 1, _MD_NEWBB_POLL_DBUPDATED); |
|
640 | + break; |
|
641 | + |
|
642 | + case 'restart': |
|
643 | + // new xoopspoll module |
|
644 | + if ($pollModuleHandler->getVar('version') >= 140) { |
|
645 | + $classConstants = ucfirst($GLOBALS['xoopsModuleConfig']['poll_module']) . 'Constants'; |
|
646 | + $default_poll_duration = $classConstants::DEFAULT_POLL_DURATION; |
|
608 | 647 | // old xoopspoll or umfrage or any clone from them |
609 | - } else { |
|
610 | - $status = $pollObject->delete(); |
|
611 | - $classOption = $classPoll . 'Option'; |
|
612 | - $classLog = $classPoll . 'Log'; |
|
613 | - if (false !== $status) { |
|
614 | - $classOption::deleteByPollId($poll_id); |
|
615 | - $classLog::deleteByPollId($poll_id); |
|
616 | 648 | } else { |
617 | - $msg = $pollObject->getHtmlErrors(); |
|
649 | + $default_poll_duration = (86400 * 10); |
|
618 | 650 | } |
619 | - } |
|
620 | - if (false !== $status) { |
|
621 | - require_once $GLOBALS['xoops']->path('class/template.php'); |
|
622 | - xoops_template_clear_module_cache($xoopsModule->getVar('mid')); |
|
623 | - xoops_template_clear_module_cache($pollModuleHandler->getVar('mid')); |
|
624 | - // delete comments for this poll |
|
625 | - xoops_comment_delete($xoopsModule->getVar('mid'), $poll_id); |
|
651 | + $poll_form = new \XoopsThemeForm(_MD_NEWBB_POLL_RESTARTPOLL, 'poll_form', 'polls.php', 'post', true); |
|
652 | + $expire_text = new \XoopsFormText( |
|
653 | + _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( |
|
654 | + _MD_NEWBB_POLL_EXPIREDAT, |
|
655 | + formatTimestamp($pollObject->getVar('end_time'), 'Y-m-d H:i:s') |
|
656 | + ) . '</small>', |
|
657 | + 'end_time', |
|
658 | + 20, |
|
659 | + 19, |
|
660 | + formatTimestamp(time() + $default_poll_duration, 'Y-m-d H:i:s') |
|
661 | + ); |
|
662 | + $poll_form->addElement($expire_text); |
|
663 | + $poll_form->addElement(new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', 1)); |
|
664 | + $poll_form->addElement(new \XoopsFormRadioYN(_MD_NEWBB_POLL_RESET, 'reset', 0)); |
|
665 | + $poll_form->addElement(new \XoopsFormHidden('op', 'restart_ok')); |
|
666 | + $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id)); |
|
667 | + $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id)); |
|
668 | + $poll_form->addElement(new \XoopsFormButton('', 'poll_submit', _MD_NEWBB_POLL_RESTART, 'submit')); |
|
626 | 669 | |
627 | - $topicObject->setVar('votes', 0); // not sure why we want to clear votes too... but I left it alone |
|
628 | - $topicObject->setVar('topic_haspoll', 0); |
|
629 | - $topicObject->setVar('poll_id', 0); |
|
630 | - $success = $topicHandler->insert($topicObject); |
|
631 | - if (!$success) { |
|
632 | - xoops_error($topicHandler->getHtmlErrors()); |
|
633 | - break; |
|
634 | - } |
|
635 | - } else { |
|
636 | - xoops_error($msg); |
|
670 | + echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n"; |
|
671 | + $poll_form->display(); |
|
637 | 672 | break; |
638 | - } |
|
639 | - redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id={$topic_id}", 1, _MD_NEWBB_POLL_DBUPDATED); |
|
640 | - break; |
|
641 | - |
|
642 | - case 'restart': |
|
643 | - // new xoopspoll module |
|
644 | - if ($pollModuleHandler->getVar('version') >= 140) { |
|
645 | - $classConstants = ucfirst($GLOBALS['xoopsModuleConfig']['poll_module']) . 'Constants'; |
|
646 | - $default_poll_duration = $classConstants::DEFAULT_POLL_DURATION; |
|
647 | - // old xoopspoll or umfrage or any clone from them |
|
648 | - } else { |
|
649 | - $default_poll_duration = (86400 * 10); |
|
650 | - } |
|
651 | - $poll_form = new \XoopsThemeForm(_MD_NEWBB_POLL_RESTARTPOLL, 'poll_form', 'polls.php', 'post', true); |
|
652 | - $expire_text = new \XoopsFormText( |
|
653 | - _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( |
|
654 | - _MD_NEWBB_POLL_EXPIREDAT, |
|
655 | - formatTimestamp($pollObject->getVar('end_time'), 'Y-m-d H:i:s') |
|
656 | - ) . '</small>', |
|
657 | - 'end_time', |
|
658 | - 20, |
|
659 | - 19, |
|
660 | - formatTimestamp(time() + $default_poll_duration, 'Y-m-d H:i:s') |
|
661 | - ); |
|
662 | - $poll_form->addElement($expire_text); |
|
663 | - $poll_form->addElement(new \XoopsFormRadioYN(_MD_NEWBB_POLL_NOTIFY, 'notify', 1)); |
|
664 | - $poll_form->addElement(new \XoopsFormRadioYN(_MD_NEWBB_POLL_RESET, 'reset', 0)); |
|
665 | - $poll_form->addElement(new \XoopsFormHidden('op', 'restart_ok')); |
|
666 | - $poll_form->addElement(new \XoopsFormHidden('topic_id', $topic_id)); |
|
667 | - $poll_form->addElement(new \XoopsFormHidden('poll_id', $poll_id)); |
|
668 | - $poll_form->addElement(new \XoopsFormButton('', 'poll_submit', _MD_NEWBB_POLL_RESTART, 'submit')); |
|
669 | - |
|
670 | - echo '<h4>' . _MD_NEWBB_POLL_POLLCONF . "</h4>\n"; |
|
671 | - $poll_form->display(); |
|
672 | - break; |
|
673 | - |
|
674 | - case 'restart_ok': |
|
675 | - // check security token |
|
676 | - if (!$GLOBALS['xoopsSecurity']->check()) { |
|
677 | - redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
|
678 | - } |
|
679 | 673 | |
680 | - // new xoopspoll module |
|
681 | - if ($pollModuleHandler->getVar('version') >= 140) { |
|
682 | - $classConstants = ucfirst($GLOBALS['xoopsModuleConfig']['poll_module']) . 'Constants'; |
|
683 | - $default_poll_duration = $classConstants::DEFAULT_POLL_DURATION; |
|
684 | - $poll_not_mailed = $classConstants::POLL_NOT_MAILED; |
|
685 | - $poll_mailed = $classConstants::POLL_MAILED; |
|
686 | - // old xoopspoll or umfrage or any clone from them |
|
687 | - } else { |
|
688 | - $default_poll_duration = (86400 * 10); |
|
689 | - $poll_not_mailed = POLL_NOTMAILED; |
|
690 | - $poll_mailed = POLL_MAILED; |
|
691 | - } |
|
674 | + case 'restart_ok': |
|
675 | + // check security token |
|
676 | + if (!$GLOBALS['xoopsSecurity']->check()) { |
|
677 | + redirect_header(Request::getString('PHP_SELF', '', 'SERVER'), 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
|
678 | + } |
|
692 | 679 | |
693 | - $end_time = !Request::getInt('end_time', 0, 'POST'); |
|
694 | - if (0 !== $end_time) { |
|
695 | - $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null; |
|
696 | - $pollObject->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($end_time) : strtotime($end_time), $timezone)); |
|
697 | - } else { |
|
698 | - $pollObject->setVar('end_time', time() + $default_poll_duration); |
|
699 | - } |
|
680 | + // new xoopspoll module |
|
681 | + if ($pollModuleHandler->getVar('version') >= 140) { |
|
682 | + $classConstants = ucfirst($GLOBALS['xoopsModuleConfig']['poll_module']) . 'Constants'; |
|
683 | + $default_poll_duration = $classConstants::DEFAULT_POLL_DURATION; |
|
684 | + $poll_not_mailed = $classConstants::POLL_NOT_MAILED; |
|
685 | + $poll_mailed = $classConstants::POLL_MAILED; |
|
686 | + // old xoopspoll or umfrage or any clone from them |
|
687 | + } else { |
|
688 | + $default_poll_duration = (86400 * 10); |
|
689 | + $poll_not_mailed = POLL_NOTMAILED; |
|
690 | + $poll_mailed = POLL_MAILED; |
|
691 | + } |
|
700 | 692 | |
701 | - $isNotify = Request::getInt('notify', 0, 'POST'); |
|
702 | - if (!empty($isNotify) && ($end_time > time())) { |
|
703 | - // if notify, set mail status to "not mailed" |
|
704 | - $pollObject->setVar('mail_status', $poll_not_mailed); |
|
705 | - } else { |
|
706 | - // if not notify, set mail status to already "mailed" |
|
707 | - $pollObject->setVar('mail_status', $poll_mailed); |
|
708 | - } |
|
693 | + $end_time = !Request::getInt('end_time', 0, 'POST'); |
|
694 | + if (0 !== $end_time) { |
|
695 | + $timezone = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('timezone') : null; |
|
696 | + $pollObject->setVar('end_time', userTimeToServerTime(method_exists('XoopsLocal', 'strtotime') ? XoopsLocal::strtotime($end_time) : strtotime($end_time), $timezone)); |
|
697 | + } else { |
|
698 | + $pollObject->setVar('end_time', time() + $default_poll_duration); |
|
699 | + } |
|
709 | 700 | |
710 | - // new xoopspoll module |
|
711 | - if ($pollModuleHandler->getVar('version') >= 140) { |
|
712 | - if (!$xpPollHandler->insert($pollObject)) { // update the poll |
|
713 | - xoops_error($pollObject->getHtmlErrors()); |
|
714 | - exit(); |
|
701 | + $isNotify = Request::getInt('notify', 0, 'POST'); |
|
702 | + if (!empty($isNotify) && ($end_time > time())) { |
|
703 | + // if notify, set mail status to "not mailed" |
|
704 | + $pollObject->setVar('mail_status', $poll_not_mailed); |
|
705 | + } else { |
|
706 | + // if not notify, set mail status to already "mailed" |
|
707 | + $pollObject->setVar('mail_status', $poll_mailed); |
|
715 | 708 | } |
716 | - if (Request::getInt('reset', 0, 'POST')) { // reset all vote/voter counters |
|
717 | - /** @var \XoopspollOptionHandler $xpOptHandler */ |
|
718 | - $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option'); |
|
719 | - /** @var \XoopspollLogHandler $xpLogHandler */ |
|
720 | - $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log'); |
|
721 | - $xpLogHandler->deleteByPollId($poll_id); |
|
722 | - $xpOptHandler->resetCountByPollId($poll_id); |
|
723 | - $xpPollHandler->updateCount($pollObject); |
|
709 | + |
|
710 | + // new xoopspoll module |
|
711 | + if ($pollModuleHandler->getVar('version') >= 140) { |
|
712 | + if (!$xpPollHandler->insert($pollObject)) { // update the poll |
|
713 | + xoops_error($pollObject->getHtmlErrors()); |
|
714 | + exit(); |
|
715 | + } |
|
716 | + if (Request::getInt('reset', 0, 'POST')) { // reset all vote/voter counters |
|
717 | + /** @var \XoopspollOptionHandler $xpOptHandler */ |
|
718 | + $xpOptHandler = Xoopspoll\Helper::getInstance()->getHandler('Option'); |
|
719 | + /** @var \XoopspollLogHandler $xpLogHandler */ |
|
720 | + $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log'); |
|
721 | + $xpLogHandler->deleteByPollId($poll_id); |
|
722 | + $xpOptHandler->resetCountByPollId($poll_id); |
|
723 | + $xpPollHandler->updateCount($pollObject); |
|
724 | + } |
|
725 | + // old xoopspoll or umfrage or any clone from them |
|
726 | + } else { |
|
727 | + if (!$pollObject->store()) { // update the poll |
|
728 | + xoops_error($pollObject->getHtmlErrors()); |
|
729 | + exit(); |
|
730 | + } |
|
731 | + if (Request::getInt('reset', 0, 'POST')) { // reset all logs |
|
732 | + $classOption = $classPoll . 'Option'; |
|
733 | + $classLog = $classPoll . 'Log'; |
|
734 | + $classLog::deleteByPollId($poll_id); |
|
735 | + $classOption::resetCountByPollId($poll_id); |
|
736 | + $pollObject->updateCount(); |
|
737 | + } |
|
724 | 738 | } |
739 | + require_once $GLOBALS['xoops']->path('class/template.php'); |
|
740 | + xoops_template_clear_module_cache($xoopsModule->getVar('mid')); |
|
741 | + xoops_template_clear_module_cache($pollModuleHandler->getVar('mid')); |
|
742 | + redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id={$topic_id}", 1, _MD_NEWBB_POLL_DBUPDATED); |
|
743 | + break; |
|
744 | + |
|
745 | + case 'log': |
|
746 | + // new xoopspoll module |
|
747 | + if ($pollModuleHandler->getVar('version') >= 140) { |
|
748 | + redirect_header($GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/admin/main.php?op=log&poll_id={$poll_id}"), 2, _MD_NEWBB_POLL_VIEWLOG); |
|
725 | 749 | // old xoopspoll or umfrage or any clone from them |
726 | - } else { |
|
727 | - if (!$pollObject->store()) { // update the poll |
|
728 | - xoops_error($pollObject->getHtmlErrors()); |
|
729 | - exit(); |
|
730 | - } |
|
731 | - if (Request::getInt('reset', 0, 'POST')) { // reset all logs |
|
732 | - $classOption = $classPoll . 'Option'; |
|
733 | - $classLog = $classPoll . 'Log'; |
|
734 | - $classLog::deleteByPollId($poll_id); |
|
735 | - $classOption::resetCountByPollId($poll_id); |
|
736 | - $pollObject->updateCount(); |
|
750 | + } else { |
|
751 | + redirect_header($GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/admin/index.php?op=log&poll_id={$poll_id}"), 2, _MD_NEWBB_POLL_VIEWLOG); |
|
737 | 752 | } |
738 | - } |
|
739 | - require_once $GLOBALS['xoops']->path('class/template.php'); |
|
740 | - xoops_template_clear_module_cache($xoopsModule->getVar('mid')); |
|
741 | - xoops_template_clear_module_cache($pollModuleHandler->getVar('mid')); |
|
742 | - redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id={$topic_id}", 1, _MD_NEWBB_POLL_DBUPDATED); |
|
743 | - break; |
|
744 | - |
|
745 | - case 'log': |
|
746 | - // new xoopspoll module |
|
747 | - if ($pollModuleHandler->getVar('version') >= 140) { |
|
748 | - redirect_header($GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/admin/main.php?op=log&poll_id={$poll_id}"), 2, _MD_NEWBB_POLL_VIEWLOG); |
|
749 | - // old xoopspoll or umfrage or any clone from them |
|
750 | - } else { |
|
751 | - redirect_header($GLOBALS['xoops']->url("modules/{$GLOBALS['xoopsModuleConfig']['poll_module']}/admin/index.php?op=log&poll_id={$poll_id}"), 2, _MD_NEWBB_POLL_VIEWLOG); |
|
752 | - } |
|
753 | - break; |
|
753 | + break; |
|
754 | 754 | } // switch |
755 | 755 | |
756 | 756 | // irmtfan move to footer.php |
@@ -46,179 +46,179 @@ |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | switch ($op) { |
49 | - case 'restore': |
|
50 | - $post_id = array_values($post_id); |
|
51 | - sort($post_id); |
|
52 | - $topics = []; |
|
53 | - $forums = []; |
|
54 | - foreach ($post_id as $post) { |
|
55 | - $postObject = $postHandler->get($post); |
|
56 | - if ($postObject->getVar('topic_id') < 1) { |
|
57 | - continue; |
|
49 | + case 'restore': |
|
50 | + $post_id = array_values($post_id); |
|
51 | + sort($post_id); |
|
52 | + $topics = []; |
|
53 | + $forums = []; |
|
54 | + foreach ($post_id as $post) { |
|
55 | + $postObject = $postHandler->get($post); |
|
56 | + if ($postObject->getVar('topic_id') < 1) { |
|
57 | + continue; |
|
58 | + } |
|
59 | + |
|
60 | + $postHandler->approve($postObject, true); |
|
61 | + $topics[$postObject->getVar('topic_id')] = 1; |
|
62 | + $forums[$postObject->getVar('forum_id')] = 1; |
|
63 | + unset($postObject); |
|
64 | + } |
|
65 | + foreach (array_keys($topics) as $topic) { |
|
66 | + $topicHandler->synchronization($topic); |
|
67 | + } |
|
68 | + foreach (array_keys($forums) as $forum) { |
|
69 | + $forumHandler->synchronization($forum); |
|
70 | + } |
|
71 | + break; |
|
72 | + case 'approve': |
|
73 | + $post_id = array_values($post_id); |
|
74 | + sort($post_id); |
|
75 | + $topics = []; |
|
76 | + $forums = []; |
|
77 | + $criteria = new \Criteria('post_id', '(' . implode(',', $post_id) . ')', 'IN'); |
|
78 | + $postsObject = $postHandler->getObjects($criteria, true); |
|
79 | + foreach ($post_id as $post) { |
|
80 | + /** @var Newbb\Post $postObject */ |
|
81 | + $postObject = $postsObject[$post]; |
|
82 | + if (!empty($topic_id) && $topic_id !== $postObject->getVar('topic_id')) { |
|
83 | + continue; |
|
84 | + } |
|
85 | + $postHandler->approve($postObject); |
|
86 | + $topics[$postObject->getVar('topic_id')] = $post; |
|
87 | + $forums[$postObject->getVar('forum_id')] = 1; |
|
88 | + } |
|
89 | + foreach (array_keys($topics) as $topic) { |
|
90 | + $topicHandler->synchronization($topic); |
|
91 | + } |
|
92 | + foreach (array_keys($forums) as $forum) { |
|
93 | + $forumHandler->synchronization($forum); |
|
58 | 94 | } |
59 | 95 | |
60 | - $postHandler->approve($postObject, true); |
|
61 | - $topics[$postObject->getVar('topic_id')] = 1; |
|
62 | - $forums[$postObject->getVar('forum_id')] = 1; |
|
63 | - unset($postObject); |
|
64 | - } |
|
65 | - foreach (array_keys($topics) as $topic) { |
|
66 | - $topicHandler->synchronization($topic); |
|
67 | - } |
|
68 | - foreach (array_keys($forums) as $forum) { |
|
69 | - $forumHandler->synchronization($forum); |
|
70 | - } |
|
71 | - break; |
|
72 | - case 'approve': |
|
73 | - $post_id = array_values($post_id); |
|
74 | - sort($post_id); |
|
75 | - $topics = []; |
|
76 | - $forums = []; |
|
77 | - $criteria = new \Criteria('post_id', '(' . implode(',', $post_id) . ')', 'IN'); |
|
78 | - $postsObject = $postHandler->getObjects($criteria, true); |
|
79 | - foreach ($post_id as $post) { |
|
80 | - /** @var Newbb\Post $postObject */ |
|
81 | - $postObject = $postsObject[$post]; |
|
82 | - if (!empty($topic_id) && $topic_id !== $postObject->getVar('topic_id')) { |
|
83 | - continue; |
|
96 | + if (empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) { |
|
97 | + break; |
|
98 | + } |
|
99 | + |
|
100 | + $criteria_topic = new \Criteria('topic_id', '(' . implode(',', array_keys($topics)) . ')', 'IN'); |
|
101 | + $topic_list = $topicHandler->getList($criteria_topic, true); |
|
102 | + |
|
103 | + $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN'); |
|
104 | + $forum_list = $forumHandler->getList($criteria_forum); |
|
105 | + |
|
106 | + require_once __DIR__ . '/include/notification.inc.php'; |
|
107 | + /** @var \XoopsNotificationHandler $notificationHandler */ |
|
108 | + $notificationHandler = xoops_getHandler('notification'); |
|
109 | + foreach ($post_id as $post) { |
|
110 | + $tags = []; |
|
111 | + /** @var Newbb\Post[] $postsObject [$post] */ |
|
112 | + $tags['THREAD_NAME'] = $topic_list[$postsObject[$post]->getVar('topic_id')]; |
|
113 | + $tags['THREAD_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?topic_id=' . $postsObject[$post]->getVar('topic_id') . '&forum=' . $postsObject[$post]->getVar('forum_id'); |
|
114 | + $tags['FORUM_NAME'] = $forum_list[$postsObject[$post]->getVar('forum_id')]; |
|
115 | + $tags['FORUM_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewforum.php?forum=' . $postsObject[$post]->getVar('forum_id'); |
|
116 | + $tags['POST_URL'] = $tags['THREAD_URL'] . '#forumpost' . $post; |
|
117 | + $notificationHandler->triggerEvent('thread', $postsObject[$post]->getVar('topic_id'), 'new_post', $tags); |
|
118 | + $notificationHandler->triggerEvent('forum', $postsObject[$post]->getVar('forum_id'), 'new_post', $tags); |
|
119 | + $notificationHandler->triggerEvent('global', 0, 'new_post', $tags); |
|
120 | + $tags['POST_CONTENT'] = $postsObject[$post]->getVar('post_text'); |
|
121 | + $tags['POST_NAME'] = $postsObject[$post]->getVar('subject'); |
|
122 | + $notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags); |
|
123 | + $notificationHandler->triggerEvent('forum', $postsObject[$post]->getVar('forum_id'), 'new_fullpost', $tags); |
|
84 | 124 | } |
85 | - $postHandler->approve($postObject); |
|
86 | - $topics[$postObject->getVar('topic_id')] = $post; |
|
87 | - $forums[$postObject->getVar('forum_id')] = 1; |
|
88 | - } |
|
89 | - foreach (array_keys($topics) as $topic) { |
|
90 | - $topicHandler->synchronization($topic); |
|
91 | - } |
|
92 | - foreach (array_keys($forums) as $forum) { |
|
93 | - $forumHandler->synchronization($forum); |
|
94 | - } |
|
95 | - |
|
96 | - if (empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) { |
|
97 | 125 | break; |
98 | - } |
|
99 | - |
|
100 | - $criteria_topic = new \Criteria('topic_id', '(' . implode(',', array_keys($topics)) . ')', 'IN'); |
|
101 | - $topic_list = $topicHandler->getList($criteria_topic, true); |
|
102 | - |
|
103 | - $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN'); |
|
104 | - $forum_list = $forumHandler->getList($criteria_forum); |
|
105 | - |
|
106 | - require_once __DIR__ . '/include/notification.inc.php'; |
|
107 | - /** @var \XoopsNotificationHandler $notificationHandler */ |
|
108 | - $notificationHandler = xoops_getHandler('notification'); |
|
109 | - foreach ($post_id as $post) { |
|
110 | - $tags = []; |
|
111 | - /** @var Newbb\Post[] $postsObject [$post] */ |
|
112 | - $tags['THREAD_NAME'] = $topic_list[$postsObject[$post]->getVar('topic_id')]; |
|
113 | - $tags['THREAD_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?topic_id=' . $postsObject[$post]->getVar('topic_id') . '&forum=' . $postsObject[$post]->getVar('forum_id'); |
|
114 | - $tags['FORUM_NAME'] = $forum_list[$postsObject[$post]->getVar('forum_id')]; |
|
115 | - $tags['FORUM_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewforum.php?forum=' . $postsObject[$post]->getVar('forum_id'); |
|
116 | - $tags['POST_URL'] = $tags['THREAD_URL'] . '#forumpost' . $post; |
|
117 | - $notificationHandler->triggerEvent('thread', $postsObject[$post]->getVar('topic_id'), 'new_post', $tags); |
|
118 | - $notificationHandler->triggerEvent('forum', $postsObject[$post]->getVar('forum_id'), 'new_post', $tags); |
|
119 | - $notificationHandler->triggerEvent('global', 0, 'new_post', $tags); |
|
120 | - $tags['POST_CONTENT'] = $postsObject[$post]->getVar('post_text'); |
|
121 | - $tags['POST_NAME'] = $postsObject[$post]->getVar('subject'); |
|
122 | - $notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags); |
|
123 | - $notificationHandler->triggerEvent('forum', $postsObject[$post]->getVar('forum_id'), 'new_fullpost', $tags); |
|
124 | - } |
|
125 | - break; |
|
126 | - case 'delete': |
|
127 | - $post_id = array_values($post_id); |
|
128 | - rsort($post_id); |
|
129 | - $topics = []; |
|
130 | - $forums = []; |
|
131 | - foreach ($post_id as $post) { |
|
132 | - $postObject = $postHandler->get($post); |
|
133 | - if (!empty($topic_id) && $topic_id !== $postObject->getVar('topic_id')) { |
|
134 | - continue; |
|
126 | + case 'delete': |
|
127 | + $post_id = array_values($post_id); |
|
128 | + rsort($post_id); |
|
129 | + $topics = []; |
|
130 | + $forums = []; |
|
131 | + foreach ($post_id as $post) { |
|
132 | + $postObject = $postHandler->get($post); |
|
133 | + if (!empty($topic_id) && $topic_id !== $postObject->getVar('topic_id')) { |
|
134 | + continue; |
|
135 | + } |
|
136 | + $topics[$postObject->getVar('topic_id')] = 1; |
|
137 | + $forums[$postObject->getVar('forum_id')] = 1; |
|
138 | + $postHandler->delete($postObject, true); |
|
139 | + unset($postObject); |
|
140 | + } |
|
141 | + foreach (array_keys($topics) as $topic) { |
|
142 | + $topicHandler->synchronization($topic); |
|
143 | + } |
|
144 | + foreach (array_keys($forums) as $forum) { |
|
145 | + $forumHandler->synchronization($forum); |
|
135 | 146 | } |
136 | - $topics[$postObject->getVar('topic_id')] = 1; |
|
137 | - $forums[$postObject->getVar('forum_id')] = 1; |
|
138 | - $postHandler->delete($postObject, true); |
|
139 | - unset($postObject); |
|
140 | - } |
|
141 | - foreach (array_keys($topics) as $topic) { |
|
142 | - $topicHandler->synchronization($topic); |
|
143 | - } |
|
144 | - foreach (array_keys($forums) as $forum) { |
|
145 | - $forumHandler->synchronization($forum); |
|
146 | - } |
|
147 | - break; |
|
148 | - case 'split': |
|
149 | - /** @var Newbb\Post $postObject */ |
|
150 | - $postObject = $postHandler->get($post_id); |
|
151 | - if (0 === count($post_id) || $postObject->isTopic()) { |
|
152 | 147 | break; |
153 | - } |
|
154 | - $topic_id = $postObject->getVar('topic_id'); |
|
155 | - |
|
156 | - $newtopic = $topicHandler->create(); |
|
157 | - $newtopic->setVar('topic_title', $postObject->getVar('subject'), true); |
|
158 | - $newtopic->setVar('topic_poster', $postObject->getVar('uid'), true); |
|
159 | - $newtopic->setVar('forum_id', $postObject->getVar('forum_id'), true); |
|
160 | - $newtopic->setVar('topic_time', $postObject->getVar('post_time'), true); |
|
161 | - $newtopic->setVar('poster_name', $postObject->getVar('poster_name'), true); |
|
162 | - $newtopic->setVar('approved', 1, true); |
|
163 | - $topicHandler->insert($newtopic, true); |
|
164 | - $new_topic_id = $newtopic->getVar('topic_id'); |
|
165 | - |
|
166 | - $pid = $postObject->getVar('pid'); |
|
167 | - |
|
168 | - $postObject->setVar('topic_id', $new_topic_id, true); |
|
169 | - $postObject->setVar('pid', 0, true); |
|
170 | - $postHandler->insert($postObject); |
|
171 | - |
|
172 | - /* split a single post */ |
|
173 | - if (1 === $mode) { |
|
174 | - $criteria = new \CriteriaCompo(new \Criteria('topic_id', $topic_id)); |
|
175 | - $criteria->add(new \Criteria('pid', $post_id)); |
|
176 | - $postHandler->updateAll('pid', $pid, $criteria, true); |
|
177 | - /* split a post and its children posts */ |
|
178 | - } elseif (2 === $mode) { |
|
179 | - require_once $GLOBALS['xoops']->path('class/xoopstree.php'); |
|
180 | - $mytree = new \XoopsTree($GLOBALS['xoopsDB']->prefix('newbb_posts'), 'post_id', 'pid'); |
|
181 | - $posts = $mytree->getAllChildId($post_id); |
|
182 | - if (count($posts) > 0) { |
|
183 | - $criteria = new \Criteria('post_id', '(' . implode(',', $posts) . ')', 'IN'); |
|
184 | - $postHandler->updateAll('topic_id', $new_topic_id, $criteria, true); |
|
148 | + case 'split': |
|
149 | + /** @var Newbb\Post $postObject */ |
|
150 | + $postObject = $postHandler->get($post_id); |
|
151 | + if (0 === count($post_id) || $postObject->isTopic()) { |
|
152 | + break; |
|
185 | 153 | } |
186 | - /* split a post and all posts coming after */ |
|
187 | - } elseif (3 === $mode) { |
|
188 | - $criteria = new \CriteriaCompo(new \Criteria('topic_id', $topic_id)); |
|
189 | - $criteria->add(new \Criteria('post_id', $post_id, '>')); |
|
190 | - $postHandler->updateAll('topic_id', $new_topic_id, $criteria, true); |
|
191 | - |
|
192 | - unset($criteria); |
|
193 | - $criteria = new \CriteriaCompo(new \Criteria('topic_id', $new_topic_id)); |
|
194 | - $criteria->add(new \Criteria('post_id', $post_id, '>')); |
|
195 | - $postHandler->identifierName = 'pid'; |
|
196 | - $posts = $postHandler->getList($criteria); |
|
197 | - |
|
198 | - unset($criteria); |
|
199 | - $post_update = []; |
|
200 | - foreach ($posts as $postid => $pid) { |
|
201 | - // if (!in_array($pid, array_keys($posts))) { |
|
202 | - if (!array_key_exists($pid, $posts)) { |
|
203 | - $post_update[] = $pid; |
|
154 | + $topic_id = $postObject->getVar('topic_id'); |
|
155 | + |
|
156 | + $newtopic = $topicHandler->create(); |
|
157 | + $newtopic->setVar('topic_title', $postObject->getVar('subject'), true); |
|
158 | + $newtopic->setVar('topic_poster', $postObject->getVar('uid'), true); |
|
159 | + $newtopic->setVar('forum_id', $postObject->getVar('forum_id'), true); |
|
160 | + $newtopic->setVar('topic_time', $postObject->getVar('post_time'), true); |
|
161 | + $newtopic->setVar('poster_name', $postObject->getVar('poster_name'), true); |
|
162 | + $newtopic->setVar('approved', 1, true); |
|
163 | + $topicHandler->insert($newtopic, true); |
|
164 | + $new_topic_id = $newtopic->getVar('topic_id'); |
|
165 | + |
|
166 | + $pid = $postObject->getVar('pid'); |
|
167 | + |
|
168 | + $postObject->setVar('topic_id', $new_topic_id, true); |
|
169 | + $postObject->setVar('pid', 0, true); |
|
170 | + $postHandler->insert($postObject); |
|
171 | + |
|
172 | + /* split a single post */ |
|
173 | + if (1 === $mode) { |
|
174 | + $criteria = new \CriteriaCompo(new \Criteria('topic_id', $topic_id)); |
|
175 | + $criteria->add(new \Criteria('pid', $post_id)); |
|
176 | + $postHandler->updateAll('pid', $pid, $criteria, true); |
|
177 | + /* split a post and its children posts */ |
|
178 | + } elseif (2 === $mode) { |
|
179 | + require_once $GLOBALS['xoops']->path('class/xoopstree.php'); |
|
180 | + $mytree = new \XoopsTree($GLOBALS['xoopsDB']->prefix('newbb_posts'), 'post_id', 'pid'); |
|
181 | + $posts = $mytree->getAllChildId($post_id); |
|
182 | + if (count($posts) > 0) { |
|
183 | + $criteria = new \Criteria('post_id', '(' . implode(',', $posts) . ')', 'IN'); |
|
184 | + $postHandler->updateAll('topic_id', $new_topic_id, $criteria, true); |
|
204 | 185 | } |
205 | - if (!array_key_exists($pid, $posts)) { |
|
206 | - $post_update2[] = $pid; |
|
186 | + /* split a post and all posts coming after */ |
|
187 | + } elseif (3 === $mode) { |
|
188 | + $criteria = new \CriteriaCompo(new \Criteria('topic_id', $topic_id)); |
|
189 | + $criteria->add(new \Criteria('post_id', $post_id, '>')); |
|
190 | + $postHandler->updateAll('topic_id', $new_topic_id, $criteria, true); |
|
191 | + |
|
192 | + unset($criteria); |
|
193 | + $criteria = new \CriteriaCompo(new \Criteria('topic_id', $new_topic_id)); |
|
194 | + $criteria->add(new \Criteria('post_id', $post_id, '>')); |
|
195 | + $postHandler->identifierName = 'pid'; |
|
196 | + $posts = $postHandler->getList($criteria); |
|
197 | + |
|
198 | + unset($criteria); |
|
199 | + $post_update = []; |
|
200 | + foreach ($posts as $postid => $pid) { |
|
201 | + // if (!in_array($pid, array_keys($posts))) { |
|
202 | + if (!array_key_exists($pid, $posts)) { |
|
203 | + $post_update[] = $pid; |
|
204 | + } |
|
205 | + if (!array_key_exists($pid, $posts)) { |
|
206 | + $post_update2[] = $pid; |
|
207 | + } |
|
208 | + } |
|
209 | + if (count($post_update)) { |
|
210 | + $criteria = new \Criteria('post_id', '(' . implode(',', $post_update) . ')', 'IN'); |
|
211 | + $postHandler->updateAll('pid', $post_id, $criteria, true); |
|
207 | 212 | } |
208 | 213 | } |
209 | - if (count($post_update)) { |
|
210 | - $criteria = new \Criteria('post_id', '(' . implode(',', $post_update) . ')', 'IN'); |
|
211 | - $postHandler->updateAll('pid', $post_id, $criteria, true); |
|
212 | - } |
|
213 | - } |
|
214 | 214 | |
215 | - $forum_id = $postObject->getVar('forum_id'); |
|
216 | - $topicHandler->synchronization($topic_id); |
|
217 | - $topicHandler->synchronization($new_topic_id); |
|
218 | - $sql = sprintf('UPDATE "%s" SET forum_topics = forum_topics+1 WHERE forum_id = "%u"', $GLOBALS['xoopsDB']->prefix('newbb_forums'), $forum_id); |
|
219 | - $result = $GLOBALS['xoopsDB']->queryF($sql); |
|
215 | + $forum_id = $postObject->getVar('forum_id'); |
|
216 | + $topicHandler->synchronization($topic_id); |
|
217 | + $topicHandler->synchronization($new_topic_id); |
|
218 | + $sql = sprintf('UPDATE "%s" SET forum_topics = forum_topics+1 WHERE forum_id = "%u"', $GLOBALS['xoopsDB']->prefix('newbb_forums'), $forum_id); |
|
219 | + $result = $GLOBALS['xoopsDB']->queryF($sql); |
|
220 | 220 | |
221 | - break; |
|
221 | + break; |
|
222 | 222 | } |
223 | 223 | if (!empty($topic_id)) { |
224 | 224 | redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=$topic_id", 2, _MD_NEWBB_DBUPDATED); |
@@ -37,150 +37,150 @@ |
||
37 | 37 | redirect_header(XOOPS_URL . '/index.php', 2, _MD_NEWBB_NORIGHTTOACCESS); |
38 | 38 | } |
39 | 39 | switch ($op) { |
40 | - case 'restore': |
|
41 | - $forums = []; |
|
42 | - $topicsObject = $topicHandler->getAll(new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN')); |
|
43 | - foreach (array_keys($topicsObject) as $id) { |
|
44 | - /** @var Newbb\Topic $topicObject */ |
|
45 | - $topicObject = $topicsObject[$id]; |
|
46 | - $topicHandler->approve($topicObject); |
|
47 | - $topicHandler->synchronization($topicObject); |
|
48 | - $forums[$topicObject->getVar('forum_id')] = 1; |
|
49 | - } |
|
50 | - $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN'); |
|
51 | - $forumsObject = $forumHandler->getAll($criteria_forum); |
|
52 | - foreach (array_keys($forumsObject) as $id) { |
|
53 | - $forumHandler->synchronization($forumsObject[$id]); |
|
54 | - } |
|
55 | - unset($topicsObject, $forumsObject); |
|
56 | - break; |
|
57 | - case 'approve': |
|
58 | - $forums = []; |
|
59 | - $topicsObject = $topicHandler->getAll(new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN')); |
|
60 | - foreach (array_keys($topicsObject) as $id) { |
|
61 | - /** @var Newbb\Topic $topicObject */ |
|
62 | - $topicObject = $topicsObject[$id]; |
|
63 | - $topicHandler->approve($topicObject); |
|
64 | - $topicHandler->synchronization($topicObject); |
|
65 | - $forums[$topicObject->getVar('forum_id')] = 1; |
|
66 | - } |
|
40 | + case 'restore': |
|
41 | + $forums = []; |
|
42 | + $topicsObject = $topicHandler->getAll(new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN')); |
|
43 | + foreach (array_keys($topicsObject) as $id) { |
|
44 | + /** @var Newbb\Topic $topicObject */ |
|
45 | + $topicObject = $topicsObject[$id]; |
|
46 | + $topicHandler->approve($topicObject); |
|
47 | + $topicHandler->synchronization($topicObject); |
|
48 | + $forums[$topicObject->getVar('forum_id')] = 1; |
|
49 | + } |
|
50 | + $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN'); |
|
51 | + $forumsObject = $forumHandler->getAll($criteria_forum); |
|
52 | + foreach (array_keys($forumsObject) as $id) { |
|
53 | + $forumHandler->synchronization($forumsObject[$id]); |
|
54 | + } |
|
55 | + unset($topicsObject, $forumsObject); |
|
56 | + break; |
|
57 | + case 'approve': |
|
58 | + $forums = []; |
|
59 | + $topicsObject = $topicHandler->getAll(new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN')); |
|
60 | + foreach (array_keys($topicsObject) as $id) { |
|
61 | + /** @var Newbb\Topic $topicObject */ |
|
62 | + $topicObject = $topicsObject[$id]; |
|
63 | + $topicHandler->approve($topicObject); |
|
64 | + $topicHandler->synchronization($topicObject); |
|
65 | + $forums[$topicObject->getVar('forum_id')] = 1; |
|
66 | + } |
|
67 | 67 | |
68 | - $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN'); |
|
69 | - $forumsObject = $forumHandler->getAll($criteria_forum); |
|
70 | - foreach (array_keys($forumsObject) as $id) { |
|
71 | - $forumHandler->synchronization($forumsObject[$id]); |
|
72 | - } |
|
68 | + $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN'); |
|
69 | + $forumsObject = $forumHandler->getAll($criteria_forum); |
|
70 | + foreach (array_keys($forumsObject) as $id) { |
|
71 | + $forumHandler->synchronization($forumsObject[$id]); |
|
72 | + } |
|
73 | 73 | |
74 | - if (empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) { |
|
75 | - break; |
|
76 | - } |
|
74 | + if (empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) { |
|
75 | + break; |
|
76 | + } |
|
77 | 77 | |
78 | - require_once __DIR__ . '/include/notification.inc.php'; |
|
79 | - /** @var \XoopsNotificationHandler $notificationHandler */ |
|
80 | - $notificationHandler = xoops_getHandler('notification'); |
|
81 | - foreach (array_keys($topicsObject) as $id) { |
|
82 | - $topicObject = $topicsObject[$id]; |
|
83 | - $tags = []; |
|
84 | - $tags['THREAD_NAME'] = $topicObject->getVar('topic_title'); |
|
85 | - $tags['THREAD_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewtopic.php?topic_id=' . $id . '&forum=' . $topicObject->getVar('forum_id'); |
|
86 | - /** @var Newbb\Forum[] $forumsObject */ |
|
87 | - $tags['FORUM_NAME'] = $forumsObject[$topicObject->getVar('forum_id')]->getVar('forum_name'); |
|
88 | - $tags['FORUM_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewforum.php?forum=' . $topicObject->getVar('forum_id'); |
|
89 | - $notificationHandler->triggerEvent('global', 0, 'new_thread', $tags); |
|
90 | - $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_thread', $tags); |
|
91 | - $postObject = $topicHandler->getTopPost($id); |
|
92 | - $tags['POST_URL'] = $tags['THREAD_URL'] . '#forumpost' . $postObject->getVar('post_id'); |
|
93 | - $notificationHandler->triggerEvent('thread', $id, 'new_post', $tags); |
|
94 | - $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_post', $tags); |
|
95 | - $notificationHandler->triggerEvent('global', 0, 'new_post', $tags); |
|
96 | - $tags['POST_CONTENT'] = $postObject->getVar('post_text'); |
|
97 | - $tags['POST_NAME'] = $postObject->getVar('subject'); |
|
98 | - $notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags); |
|
99 | - $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_fullpost', $tags); |
|
100 | - unset($postObject); |
|
101 | - } |
|
102 | - unset($topicsObject, $forumsObject); |
|
103 | - break; |
|
104 | - case 'delete': |
|
105 | - $forums = []; |
|
106 | - /** @var Newbb\TopicHandler|\XoopsPersistableObjectHandler $topicHandler */ |
|
107 | - $topicsObject = $topicHandler->getAll(new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN')); |
|
108 | - foreach (array_keys($topicsObject) as $id) { |
|
109 | - /** @var Newbb\Topic $topicObject */ |
|
110 | - $topicObject = $topicsObject[$id]; |
|
111 | - // irmtfan should be set to false to not delete topic from database |
|
112 | - $topicHandler->delete($topicObject, false); |
|
113 | - $topicHandler->synchronization($topicObject); |
|
114 | - $forums[$topicObject->getVar('forum_id')] = 1; |
|
115 | - } |
|
78 | + require_once __DIR__ . '/include/notification.inc.php'; |
|
79 | + /** @var \XoopsNotificationHandler $notificationHandler */ |
|
80 | + $notificationHandler = xoops_getHandler('notification'); |
|
81 | + foreach (array_keys($topicsObject) as $id) { |
|
82 | + $topicObject = $topicsObject[$id]; |
|
83 | + $tags = []; |
|
84 | + $tags['THREAD_NAME'] = $topicObject->getVar('topic_title'); |
|
85 | + $tags['THREAD_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewtopic.php?topic_id=' . $id . '&forum=' . $topicObject->getVar('forum_id'); |
|
86 | + /** @var Newbb\Forum[] $forumsObject */ |
|
87 | + $tags['FORUM_NAME'] = $forumsObject[$topicObject->getVar('forum_id')]->getVar('forum_name'); |
|
88 | + $tags['FORUM_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewforum.php?forum=' . $topicObject->getVar('forum_id'); |
|
89 | + $notificationHandler->triggerEvent('global', 0, 'new_thread', $tags); |
|
90 | + $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_thread', $tags); |
|
91 | + $postObject = $topicHandler->getTopPost($id); |
|
92 | + $tags['POST_URL'] = $tags['THREAD_URL'] . '#forumpost' . $postObject->getVar('post_id'); |
|
93 | + $notificationHandler->triggerEvent('thread', $id, 'new_post', $tags); |
|
94 | + $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_post', $tags); |
|
95 | + $notificationHandler->triggerEvent('global', 0, 'new_post', $tags); |
|
96 | + $tags['POST_CONTENT'] = $postObject->getVar('post_text'); |
|
97 | + $tags['POST_NAME'] = $postObject->getVar('subject'); |
|
98 | + $notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags); |
|
99 | + $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_fullpost', $tags); |
|
100 | + unset($postObject); |
|
101 | + } |
|
102 | + unset($topicsObject, $forumsObject); |
|
103 | + break; |
|
104 | + case 'delete': |
|
105 | + $forums = []; |
|
106 | + /** @var Newbb\TopicHandler|\XoopsPersistableObjectHandler $topicHandler */ |
|
107 | + $topicsObject = $topicHandler->getAll(new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN')); |
|
108 | + foreach (array_keys($topicsObject) as $id) { |
|
109 | + /** @var Newbb\Topic $topicObject */ |
|
110 | + $topicObject = $topicsObject[$id]; |
|
111 | + // irmtfan should be set to false to not delete topic from database |
|
112 | + $topicHandler->delete($topicObject, false); |
|
113 | + $topicHandler->synchronization($topicObject); |
|
114 | + $forums[$topicObject->getVar('forum_id')] = 1; |
|
115 | + } |
|
116 | 116 | |
117 | - $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN'); |
|
118 | - $forumsObject = $forumHandler->getAll($criteria_forum); |
|
119 | - foreach (array_keys($forumsObject) as $id) { |
|
120 | - $forumHandler->synchronization($forumsObject[$id]); |
|
121 | - } |
|
122 | - unset($topicsObject, $forumsObject); |
|
123 | - break; |
|
124 | - case 'move': |
|
125 | - if (Request::getInt('newforum', 0, 'POST') |
|
126 | - && Request::getInt('newforum', 0, 'POST') !== $forum_id |
|
127 | - && $forumHandler->getPermission(Request::getInt('newforum', 0, 'POST'), 'post')) { |
|
128 | - $criteria = new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN'); |
|
129 | - // /** @var Newbb\PostHandler $postHandler */ |
|
130 | - // $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
131 | - $postHandler->updateAll('forum_id', Request::getInt('newforum', 0, 'POST'), $criteria, true); |
|
132 | - $topicHandler->updateAll('forum_id', Request::getInt('newforum', 0, 'POST'), $criteria, true); |
|
133 | - $forumHandler->synchronization(Request::getInt('newforum', 0, 'POST')); |
|
134 | - $forumHandler->synchronization($forum_id); |
|
135 | - } else { |
|
136 | - include $GLOBALS['xoops']->path('header.php'); |
|
137 | - // /** @var Newbb\CategoryHandler $categoryHandler */ |
|
138 | - // $categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
|
139 | - $categories = $categoryHandler->getByPermission('access'); |
|
140 | - $forums = $forumHandler->getForumsByCategory(array_keys($categories), 'post', false); |
|
117 | + $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN'); |
|
118 | + $forumsObject = $forumHandler->getAll($criteria_forum); |
|
119 | + foreach (array_keys($forumsObject) as $id) { |
|
120 | + $forumHandler->synchronization($forumsObject[$id]); |
|
121 | + } |
|
122 | + unset($topicsObject, $forumsObject); |
|
123 | + break; |
|
124 | + case 'move': |
|
125 | + if (Request::getInt('newforum', 0, 'POST') |
|
126 | + && Request::getInt('newforum', 0, 'POST') !== $forum_id |
|
127 | + && $forumHandler->getPermission(Request::getInt('newforum', 0, 'POST'), 'post')) { |
|
128 | + $criteria = new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN'); |
|
129 | + // /** @var Newbb\PostHandler $postHandler */ |
|
130 | + // $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
131 | + $postHandler->updateAll('forum_id', Request::getInt('newforum', 0, 'POST'), $criteria, true); |
|
132 | + $topicHandler->updateAll('forum_id', Request::getInt('newforum', 0, 'POST'), $criteria, true); |
|
133 | + $forumHandler->synchronization(Request::getInt('newforum', 0, 'POST')); |
|
134 | + $forumHandler->synchronization($forum_id); |
|
135 | + } else { |
|
136 | + include $GLOBALS['xoops']->path('header.php'); |
|
137 | + // /** @var Newbb\CategoryHandler $categoryHandler */ |
|
138 | + // $categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
|
139 | + $categories = $categoryHandler->getByPermission('access'); |
|
140 | + $forums = $forumHandler->getForumsByCategory(array_keys($categories), 'post', false); |
|
141 | 141 | |
142 | - $box = '<select name="newforum" size="1">'; |
|
143 | - if (count($categories) > 0 && count($forums) > 0) { |
|
144 | - foreach (array_keys($forums) as $key) { |
|
142 | + $box = '<select name="newforum" size="1">'; |
|
143 | + if (count($categories) > 0 && count($forums) > 0) { |
|
144 | + foreach (array_keys($forums) as $key) { |
|
145 | 145 | |
146 | - /** @var Newbb\Category[] $categories */ |
|
147 | - $box .= "<option value='-1'>[" . $categories[$key]->getVar('cat_title') . ']</option>'; |
|
148 | - foreach ($forums[$key] as $forumid => $_forum) { |
|
149 | - $box .= "<option value='" . $forumid . "'>-- " . $_forum['title'] . '</option>'; |
|
150 | - if (!isset($_forum['sub'])) { |
|
151 | - continue; |
|
152 | - } |
|
153 | - foreach (array_keys($_forum['sub']) as $fid) { |
|
154 | - $box .= "<option value='" . $fid . "'>---- " . $_forum['sub'][$fid]['title'] . '</option>'; |
|
146 | + /** @var Newbb\Category[] $categories */ |
|
147 | + $box .= "<option value='-1'>[" . $categories[$key]->getVar('cat_title') . ']</option>'; |
|
148 | + foreach ($forums[$key] as $forumid => $_forum) { |
|
149 | + $box .= "<option value='" . $forumid . "'>-- " . $_forum['title'] . '</option>'; |
|
150 | + if (!isset($_forum['sub'])) { |
|
151 | + continue; |
|
152 | + } |
|
153 | + foreach (array_keys($_forum['sub']) as $fid) { |
|
154 | + $box .= "<option value='" . $fid . "'>---- " . $_forum['sub'][$fid]['title'] . '</option>'; |
|
155 | + } |
|
155 | 156 | } |
156 | 157 | } |
158 | + } else { |
|
159 | + $box .= "<option value='-1'>" . _MD_NEWBB_NOFORUMINDB . '</option>'; |
|
157 | 160 | } |
158 | - } else { |
|
159 | - $box .= "<option value='-1'>" . _MD_NEWBB_NOFORUMINDB . '</option>'; |
|
160 | - } |
|
161 | - $box .= '</select>'; |
|
162 | - unset($forums, $categories); |
|
161 | + $box .= '</select>'; |
|
162 | + unset($forums, $categories); |
|
163 | 163 | |
164 | - echo "<form action='" . Request::getString('PHP_SELF', '', 'SERVER') . "' method='post'>"; |
|
165 | - echo "<table border='0' cellpadding='1' cellspacing='0' align='center' width='95%'>"; |
|
166 | - echo "<tr><td class='bg2'>"; |
|
167 | - echo "<table border='0' cellpadding='1' cellspacing='1' width='100%'>"; |
|
168 | - echo '<tr><td class="bg3">' . _MD_NEWBB_MOVETOPICTO . '</td><td class="bg1">'; |
|
169 | - echo $box; |
|
170 | - echo '</td></tr>'; |
|
171 | - echo '<tr class="bg3"><td colspan="2" align="center">'; |
|
172 | - echo "<input type='hidden' name='op' value='move' />"; |
|
173 | - echo "<input type='hidden' name='forum_id' value='{$forum_id}' />"; |
|
174 | - foreach ($topic_id as $id) { |
|
175 | - echo "<input type='hidden' name='topic_id[]' value='" . $id . "' />"; |
|
164 | + echo "<form action='" . Request::getString('PHP_SELF', '', 'SERVER') . "' method='post'>"; |
|
165 | + echo "<table border='0' cellpadding='1' cellspacing='0' align='center' width='95%'>"; |
|
166 | + echo "<tr><td class='bg2'>"; |
|
167 | + echo "<table border='0' cellpadding='1' cellspacing='1' width='100%'>"; |
|
168 | + echo '<tr><td class="bg3">' . _MD_NEWBB_MOVETOPICTO . '</td><td class="bg1">'; |
|
169 | + echo $box; |
|
170 | + echo '</td></tr>'; |
|
171 | + echo '<tr class="bg3"><td colspan="2" align="center">'; |
|
172 | + echo "<input type='hidden' name='op' value='move' />"; |
|
173 | + echo "<input type='hidden' name='forum_id' value='{$forum_id}' />"; |
|
174 | + foreach ($topic_id as $id) { |
|
175 | + echo "<input type='hidden' name='topic_id[]' value='" . $id . "' />"; |
|
176 | + } |
|
177 | + echo "<input type='submit' name='submit' value='" . _SUBMIT . "' />"; |
|
178 | + echo '</td></tr></table></td></tr></table>'; |
|
179 | + echo '</form>'; |
|
180 | + include $GLOBALS['xoops']->path('footer.php'); |
|
181 | + exit(); |
|
176 | 182 | } |
177 | - echo "<input type='submit' name='submit' value='" . _SUBMIT . "' />"; |
|
178 | - echo '</td></tr></table></td></tr></table>'; |
|
179 | - echo '</form>'; |
|
180 | - include $GLOBALS['xoops']->path('footer.php'); |
|
181 | - exit(); |
|
182 | - } |
|
183 | - break; |
|
183 | + break; |
|
184 | 184 | } |
185 | 185 | ///** @var Newbb\StatsHandler $statsHandler */ |
186 | 186 | //$statsHandler = Newbb\Helper::getInstance()->getHandler('Stats'); |