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