This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * **************************************************************************** |
||
4 | * - A Project by Developers TEAM For Xoops - ( https://xoops.org ) |
||
5 | * **************************************************************************** |
||
6 | * XNEWSLETTER - MODULE FOR XOOPS |
||
7 | * Copyright (c) 2007 - 2012 |
||
8 | * Goffy ( wedega.com ) |
||
9 | * |
||
10 | * You may not change or alter any portion of this comment or credits |
||
11 | * of supporting developers from this source code or any supporting |
||
12 | * source code which is considered copyrighted (c) material of the |
||
13 | * original comment or credit authors. |
||
14 | * |
||
15 | * This program is distributed in the hope that it will be useful, |
||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
18 | * GNU General Public License for more details. |
||
19 | * --------------------------------------------------------------------------- |
||
20 | * @copyright Goffy ( wedega.com ) |
||
21 | * @license GPL 2.0 |
||
22 | * @package xnewsletter |
||
23 | * @author Goffy ( [email protected] ) |
||
24 | * |
||
25 | * **************************************************************************** |
||
26 | */ |
||
27 | |||
28 | use Xmf\Request; |
||
29 | |||
30 | $currentFile = basename(__FILE__); |
||
31 | require_once __DIR__ . '/admin_header.php'; |
||
32 | xoops_cp_header(); |
||
33 | |||
34 | // set template |
||
35 | $templateMain = 'xnewsletter_admin_maintenance.tpl'; |
||
36 | |||
37 | // We recovered the value of the argument op in the URL$ |
||
38 | $op = \Xmf\Request::getString('op', 'list'); |
||
39 | |||
40 | $GLOBALS['xoopsTpl']->assign('xnewsletter_url', XNEWSLETTER_URL); |
||
41 | $GLOBALS['xoopsTpl']->assign('xnewsletter_icons_url', XNEWSLETTER_ICONS_URL); |
||
42 | |||
43 | switch ($op) { |
||
44 | case 'list': |
||
45 | default: |
||
46 | $adminObject->displayNavigation($currentFile); |
||
47 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
48 | $maintenance = " |
||
49 | <table class='outer width75'> |
||
50 | <tr> |
||
51 | <th>" . _AM_XNEWSLETTER_MAINTENANCE_CAT . '</th> |
||
52 | <th>' . _AM_XNEWSLETTER_MAINTENANCE_DESCR . '</th> |
||
53 | <th>' . _AM_XNEWSLETTER_MAINTENANCE_PARAM . '</th> |
||
54 | <th>' . _AM_XNEWSLETTER_FORMACTION . '</th> |
||
55 | </tr>'; |
||
56 | $class = 'odd'; |
||
57 | |||
58 | // delete protocols |
||
59 | $maintenance .= " <tr class='{$class}'>"; |
||
60 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
61 | $maintenance .= " <form action='{$currentFile}' method='post'>"; |
||
62 | $maintenance .= ' <td>protocol</td>'; |
||
63 | $maintenance .= ' <td>' . _AM_XNEWSLETTER_MAINTENANCE_DELETEPROTOCOL . '</td>'; |
||
64 | $maintenance .= ' <td> </td>'; |
||
65 | $cal_tray = new \XoopsFormElementTray(' ', ' '); |
||
66 | $cal_tray->addElement(new \XoopsFormHidden('op', 'del_oldprotocol')); |
||
67 | $cal_tray->addElement(new \XoopsFormButton('', 'post', _SUBMIT, 'submit')); |
||
68 | $maintenance .= " <td class='center'>" . $cal_tray->render() . '</td>'; |
||
69 | $maintenance .= ' </form>'; |
||
70 | $maintenance .= ' </tr>'; |
||
71 | |||
72 | // delete unconfirmed registrations |
||
73 | $maintenance .= " <tr class='{$class}'>"; |
||
74 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
75 | $maintenance .= " <form action='{$currentFile}' method='post'>"; |
||
76 | $maintenance .= ' <td>subscr</td>'; |
||
77 | $maintenance .= ' <td>' . _AM_XNEWSLETTER_MAINTENANCE_DELETEDATE . '</td>'; |
||
78 | $cal = new \XoopsFormTextDateSelect('', 'del_date', 15, time() - (84600 * 10)); |
||
79 | $maintenance .= ' <td>' . $cal->render() . '</td>'; |
||
80 | $cal_tray = new \XoopsFormElementTray(' ', ' '); |
||
81 | $cal_tray->addElement(new \XoopsFormHidden('op', 'del_oldsubscr')); |
||
82 | $cal_tray->addElement(new \XoopsFormButton('', 'post', _SUBMIT, 'submit')); |
||
83 | $maintenance .= " <td class='center'>" . $cal_tray->render() . '</td>'; |
||
84 | $maintenance .= ' </form>'; |
||
85 | $maintenance .= ' </tr>'; |
||
86 | |||
87 | // delete invalid catsubscr |
||
88 | $maintenance .= " <tr class='{$class}'>"; |
||
89 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
90 | $maintenance .= " <form action='{$currentFile}' method='post'>"; |
||
91 | $maintenance .= ' <td>catsubscr</td>'; |
||
92 | $maintenance .= ' <td>' . _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR . '</td>'; |
||
93 | $maintenance .= ' <td> </td>'; |
||
94 | $maintenance .= " <td class='center'>"; |
||
95 | $cal_tray = new \XoopsFormElementTray(' ', ' '); |
||
96 | $cal_tray->addElement(new \XoopsFormHidden('op', 'del_invalid_catsubscr')); |
||
97 | $cal_tray->addElement(new \XoopsFormButton('', 'post', _SUBMIT, 'submit')); |
||
98 | $maintenance .= $cal_tray->render(); |
||
99 | $maintenance .= ' </td>'; |
||
100 | $maintenance .= ' </form>'; |
||
101 | $maintenance .= ' </tr>'; |
||
102 | |||
103 | // delete invalid catsubscr |
||
104 | $maintenance .= " <tr class='{$class}'>"; |
||
105 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
106 | $maintenance .= " <form action='{$currentFile}' method='post'>"; |
||
107 | $maintenance .= ' <td>catsubscr</td>'; |
||
108 | $maintenance .= ' <td>' . _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR_CATDEL . '</td>'; |
||
109 | $maintenance .= ' <td> </td>'; |
||
110 | $maintenance .= " <td class='center'>"; |
||
111 | $cal_tray = new \XoopsFormElementTray(' ', ' '); |
||
112 | $cal_tray->addElement(new \XoopsFormHidden('op', 'del_invalid_subscr_catdel')); |
||
113 | $cal_tray->addElement(new \XoopsFormButton('', 'post', _SUBMIT, 'submit')); |
||
114 | $maintenance .= $cal_tray->render(); |
||
115 | $maintenance .= ' </td>'; |
||
116 | $maintenance .= ' </form>'; |
||
117 | $maintenance .= ' </tr>'; |
||
118 | |||
119 | // check module preference xn_use_mailinglist with values in cat_mailinglist and check cat_mailinglist versus table mailinglist |
||
120 | |||
121 | if (1 == $helper->getConfig('xn_use_mailinglist')) { |
||
122 | $maintenance .= " <tr class='{$class}'>"; |
||
123 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
124 | $maintenance .= " <form action='{$currentFile}' method='post'>"; |
||
125 | $maintenance .= ' <td>ml</td>'; |
||
126 | $maintenance .= ' <td>' . _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_ML . '</td>'; |
||
127 | $maintenance .= ' <td> </td>'; |
||
128 | $maintenance .= " <td class='center'>"; |
||
129 | $cal_tray = new \XoopsFormElementTray(' ', ' '); |
||
130 | $cal_tray->addElement(new \XoopsFormHidden('op', 'del_invalid_ml')); |
||
131 | $cal_tray->addElement(new \XoopsFormButton('', 'post', _SUBMIT, 'submit')); |
||
132 | $maintenance .= $cal_tray->render(); |
||
133 | $maintenance .= ' </td>'; |
||
134 | $maintenance .= ' </form>'; |
||
135 | $maintenance .= ' </tr>'; |
||
136 | } |
||
137 | |||
138 | // delete invalid cat |
||
139 | $maintenance .= " <tr class='{$class}'>"; |
||
140 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
141 | $maintenance .= " <form action='{$currentFile}' method='post'>"; |
||
142 | $maintenance .= ' <td>cat</td>'; |
||
143 | $maintenance .= ' <td>' . _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_CATNL . '</td>'; |
||
144 | $maintenance .= ' <td> </td>'; |
||
145 | $maintenance .= " <td class='center'>"; |
||
146 | $cal_tray = new \XoopsFormElementTray(' ', ' '); |
||
147 | $cal_tray->addElement(new \XoopsFormHidden('op', 'del_invalid_cat')); |
||
148 | $cal_tray->addElement(new \XoopsFormButton('', 'post', _SUBMIT, 'submit')); |
||
149 | $maintenance .= $cal_tray->render(); |
||
150 | $maintenance .= ' </td>'; |
||
151 | $maintenance .= ' </form>'; |
||
152 | $maintenance .= ' </tr>'; |
||
153 | |||
154 | // delete import |
||
155 | $maintenance .= " <tr class='{$class}'>"; |
||
156 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
157 | $maintenance .= " <form action='{$currentFile}' method='post'>"; |
||
158 | $maintenance .= ' <td>import</td>'; |
||
159 | $maintenance .= ' <td>' . _AM_XNEWSLETTER_MAINTENANCE_DELETE_IMPORT . '</td>'; |
||
160 | $maintenance .= ' <td> </td>'; |
||
161 | $maintenance .= " <td class='center'>"; |
||
162 | $cal_tray = new \XoopsFormElementTray(' ', ' '); |
||
163 | $cal_tray->addElement(new \XoopsFormHidden('op', 'del_import')); |
||
164 | $cal_tray->addElement(new \XoopsFormButton('', 'post', _SUBMIT, 'submit')); |
||
165 | $maintenance .= $cal_tray->render(); |
||
166 | $maintenance .= ' </td>'; |
||
167 | $maintenance .= ' </form>'; |
||
168 | $maintenance .= ' </tr>'; |
||
169 | |||
170 | $maintenance .= '</table>'; |
||
171 | $GLOBALS['xoopsTpl']->assign('maintenance', $maintenance); |
||
172 | break; |
||
173 | View Code Duplication | case 'del_import': |
|
174 | if (true === \Xmf\Request::getBool('ok', false, 'POST')) { |
||
175 | $result = $xoopsDB->queryF("TRUNCATE TABLE `{$xoopsDB->prefix('xnewsletter_import')}`"); |
||
176 | $result = $xoopsDB->queryF("REPAIR TABLE `{$xoopsDB->prefix('xnewsletter_import')}`"); |
||
177 | $result = $xoopsDB->queryF("OPTIMIZE TABLE `{$xoopsDB->prefix('xnewsletter_import')}`"); |
||
178 | $result = $xoopsDB->queryF("ALTER TABLE `{$xoopsDB->prefix('xnewsletter_import')}` AUTO_INCREMENT =1"); |
||
179 | |||
180 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
181 | $protocolObj->setVar('protocol_letter_id', 0); |
||
182 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
183 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' import] ' . _AM_XNEWSLETTER_MAINTENANCE_DELETE_IMPORT_OK); |
||
184 | $protocolObj->setVar('protocol_success', true); |
||
185 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
186 | $protocolObj->setVar('protocol_created', time()); |
||
187 | |||
188 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
189 | // IN PROGRESS |
||
190 | } |
||
191 | redirect_header($currentFile, 3, _AM_XNEWSLETTER_MAINTENANCE_DELETE_IMPORT_OK); |
||
192 | } else { |
||
193 | xoops_confirm(['ok' => true, 'op' => 'del_import'], $currentFile, _AM_XNEWSLETTER_MAINTENANCE_DELETE_IMPORT); |
||
194 | } |
||
195 | break; |
||
196 | case 'del_oldsubscr': |
||
197 | $time = strtotime($_POST['del_date']); |
||
198 | if ($time >= time() || 0 == $time) { |
||
199 | $subscrCount = -1; // for error |
||
200 | } else { |
||
201 | $subscrCriteria = new \CriteriaCompo(); |
||
202 | $subscrCriteria->add(new \Criteria('subscr_activated', 0)); |
||
203 | $subscrCriteria->add(new \Criteria('subscr_created', $time, '<')); |
||
204 | $subscrCount = $helper->getHandler('Subscr')->getCount($subscrCriteria); |
||
205 | } |
||
206 | |||
207 | if (true === Request::getBool('ok', false, 'POST')) { |
||
208 | $deleted = 0; |
||
209 | $errors = []; |
||
210 | $subscrArrays = $helper->getHandler('Subscr')->getAll($subscrCriteria, ['subscr_id'], false, false); |
||
211 | foreach ($subscrArrays as $subscrArray) { |
||
212 | $subscrObj = $helper->getHandler('Subscr')->get((int)$subscrArray['subscr_id']); |
||
213 | $sql = 'DELETE'; |
||
214 | $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_subscr')}`"; |
||
215 | $sql .= " WHERE subscr_id={$subscrArray['subscr_id']}"; |
||
216 | $result = $xoopsDB->queryF($sql); |
||
217 | if ($result) { |
||
218 | // Newsletterlist delete |
||
219 | $sql = 'DELETE'; |
||
220 | $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_catsubscr')}`"; |
||
221 | $sql .= " WHERE catsubscr_subscrid={$subscrArray['subscr_id']}"; |
||
222 | $result = $xoopsDB->queryF($sql); |
||
223 | if (!$result) { |
||
224 | $errors[] = 'Error CAT-Subscr-ID: ' . $subscrArray['subscr_id'] . ' / ' . $result->getHtmlErrors(); |
||
225 | } |
||
226 | ++$deleted; |
||
227 | } else { |
||
228 | $errors[] = 'Error Subscr-ID: ' . $subscrArray['subscr_id'] . ' / ' . $result->getHtmlErrors(); |
||
229 | } |
||
230 | } |
||
231 | |||
232 | View Code Duplication | if (count($errors) > 0) { |
|
233 | foreach ($errors as $error) { |
||
234 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
235 | $protocolObj->setVar('protocol_letter_id', 0); |
||
236 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
237 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' reguser] ' . $error); |
||
238 | $protocolObj->setVar('protocol_success', false); |
||
239 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
240 | $protocolObj->setVar('protocol_created', time()); |
||
241 | $helper->getHandler('Protocol')->insert($protocolObj); |
||
242 | } |
||
243 | } |
||
244 | |||
245 | View Code Duplication | if ($deleted > 0) { |
|
246 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
247 | $protocolObj->setVar('protocol_letter_id', 0); |
||
248 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
249 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' reguser] ' . sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETEUSEROK, $deleted)); |
||
250 | $protocolObj->setVar('protocol_success', true); |
||
251 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
252 | $protocolObj->setVar('protocol_created', time()); |
||
253 | $helper->getHandler('Protocol')->insert($protocolObj); |
||
254 | } |
||
255 | redirect_header($currentFile, 3, sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETEUSEROK, $deleted)); |
||
256 | } else { |
||
257 | if ($subscrCount > 0) { |
||
258 | xoops_confirm(['ok' => true, 'del_date' => $_POST['del_date'], 'op' => 'del_oldsubscr'], $currentFile, sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETEUSER, $subscrCount, $_POST['del_date'])); |
||
259 | } else { |
||
260 | redirect_header($currentFile, 3, _AM_XNEWSLETTER_MAINTENANCE_DELETENOTHING); |
||
261 | } |
||
262 | } |
||
263 | break; |
||
264 | View Code Duplication | case 'del_oldprotocol': |
|
265 | if (true === Request::getBool('ok', false, 'POST')) { |
||
266 | $result = $xoopsDB->queryF("TRUNCATE TABLE `{$xoopsDB->prefix('xnewsletter_protocol')}`"); |
||
267 | $result = $xoopsDB->queryF("REPAIR TABLE `{$xoopsDB->prefix('xnewsletter_protocol')}`"); |
||
268 | $result = $xoopsDB->queryF("OPTIMIZE TABLE `{$xoopsDB->prefix('xnewsletter_protocol')}`"); |
||
269 | $result = $xoopsDB->queryF("ALTER TABLE `{$xoopsDB->prefix('xnewsletter_protocol')}` AUTO_INCREMENT =1"); |
||
270 | |||
271 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
272 | $protocolObj->setVar('protocol_letter_id', 0); |
||
273 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
274 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' prot] ' . _AM_XNEWSLETTER_MAINTENANCE_DELETEPROTOK); |
||
275 | $protocolObj->setVar('protocol_success', true); |
||
276 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
277 | $protocolObj->setVar('protocol_created', time()); |
||
278 | |||
279 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
280 | // IN PROGRESS |
||
281 | } |
||
282 | redirect_header($currentFile, 3, _AM_XNEWSLETTER_MAINTENANCE_DELETEPROTOK); |
||
283 | } else { |
||
284 | xoops_confirm(['ok' => true, 'op' => 'del_oldprotocol'], $currentFile, _AM_XNEWSLETTER_MAINTENANCE_DELETEPROTOCOL); |
||
285 | } |
||
286 | break; |
||
287 | View Code Duplication | case 'del_invalid_catsubscr': |
|
288 | //delete data in table catsubscr, if catsubscr_subscrid is no more existing in table subscr |
||
289 | if (true === Request::getBool('ok', false, 'POST')) { |
||
290 | $number_ids = 0; |
||
291 | $deleted = 0; |
||
292 | $errors = []; |
||
293 | $sql = 'SELECT Count(`catsubscr_id`) AS `nb_ids`'; |
||
294 | $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_catsubscr')}` LEFT JOIN `{$xoopsDB->prefix('xnewsletter_subscr')}` ON `catsubscr_subscrid` = `subscr_id`"; |
||
295 | $sql .= ' WHERE (`subscr_id` Is Null)'; |
||
296 | $result = $xoopsDB->query($sql); |
||
297 | if ($result) { |
||
298 | $row_result = $xoopsDB->fetchRow($result); |
||
299 | $number_ids = $row_result[0]; |
||
300 | } |
||
301 | if ($number_ids > 0) { |
||
302 | $sql = "DELETE `{$xoopsDB->prefix('xnewsletter_catsubscr')}`"; |
||
303 | $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_catsubscr')}` LEFT JOIN `{$xoopsDB->prefix('xnewsletter_subscr')}` ON `catsubscr_subscrid` = `subscr_id`"; |
||
304 | $sql .= ' WHERE (`subscr_id` Is Null)'; |
||
305 | $result = $xoopsDB->query($sql); |
||
306 | if ($result) { |
||
307 | ++$deleted; |
||
308 | } else { |
||
309 | $errors[] = 'Error delete catsubscr: ' . $result->getHtmlErrors(); |
||
310 | } |
||
311 | } |
||
312 | |||
313 | if (count($errors) > 0) { |
||
314 | foreach ($errors as $error) { |
||
315 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
316 | $protocolObj->setVar('protocol_letter_id', 0); |
||
317 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
318 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' catsubscr] ' . $error); |
||
319 | $protocolObj->setVar('protocol_success', false); |
||
320 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
321 | $protocolObj->setVar('protocol_created', time()); |
||
322 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
323 | $GLOBALS['xoopsTpl']->assign('error', _AM_XNEWSLETTER_MAINTENANCE_ERROR); |
||
324 | } |
||
325 | } |
||
326 | } else { |
||
327 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
328 | $protocolObj->setVar('protocol_letter_id', 0); |
||
329 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
330 | $status = 0 == $number_ids ? _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR_NODATA : sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR_OK, $number_ids); |
||
331 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' catsubscr] ' . $status); |
||
332 | $protocolObj->setVar('protocol_success', true); |
||
333 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
334 | $protocolObj->setVar('protocol_created', time()); |
||
335 | |||
336 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
337 | $GLOBALS['xoopsTpl']->assign('error', _AM_XNEWSLETTER_MAINTENANCE_ERROR); |
||
338 | } |
||
339 | redirect_header($currentFile, 3, sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR_OK, $number_ids)); |
||
340 | } |
||
341 | } else { |
||
342 | xoops_confirm(['ok' => true, 'op' => 'del_invalid_catsubscr'], $currentFile, _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR); |
||
343 | } |
||
344 | break; |
||
345 | View Code Duplication | case 'del_invalid_subscr_catdel': |
|
0 ignored issues
–
show
|
|||
346 | //delete data in table catsubscr, if cat is no more existing in table cat |
||
347 | if (true === Request::getBool('ok', false, 'POST')) { |
||
348 | $number_ids = 0; |
||
349 | $deleted = 0; |
||
350 | $errors = []; |
||
351 | $sql = 'SELECT Count(`catsubscr_id`) AS `nb_ids`'; |
||
352 | $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_catsubscr')}` LEFT JOIN `{$xoopsDB->prefix('xnewsletter_cat')}` ON `catsubscr_catid` = `cat_id`"; |
||
353 | $sql .= ' WHERE (`cat_id` Is Null)'; |
||
354 | $result = $xoopsDB->query($sql); |
||
355 | if ($result) { |
||
356 | $row_result = $xoopsDB->fetchRow($result); |
||
357 | $number_ids = $row_result[0]; |
||
358 | } |
||
359 | if ($number_ids > 0) { |
||
360 | $sql = "DELETE `{$xoopsDB->prefix('xnewsletter_catsubscr')}`"; |
||
361 | $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_catsubscr')}` LEFT JOIN `{$xoopsDB->prefix('xnewsletter_cat')}` ON `catsubscr_catid` = `cat_id`"; |
||
362 | $sql .= ' WHERE (`cat_id` Is Null)'; |
||
363 | $result = $xoopsDB->query($sql); |
||
364 | if ($result) { |
||
365 | ++$deleted; |
||
366 | } else { |
||
367 | $errors[] = 'Error delete catsubscr: ' . $result->getHtmlErrors(); |
||
368 | } |
||
369 | } |
||
370 | |||
371 | if (count($errors) > 0) { |
||
372 | foreach ($errors as $error) { |
||
373 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
374 | $protocolObj->setVar('protocol_letter_id', 0); |
||
375 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
376 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' catsubscr] ' . $error); |
||
377 | $protocolObj->setVar('protocol_success', false); |
||
378 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
379 | $protocolObj->setVar('protocol_created', time()); |
||
380 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
381 | $GLOBALS['xoopsTpl']->assign('error', _AM_XNEWSLETTER_MAINTENANCE_ERROR); |
||
382 | } |
||
383 | } |
||
384 | } else { |
||
385 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
386 | $protocolObj->setVar('protocol_letter_id', 0); |
||
387 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
388 | $status = 0 == $number_ids ? _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR_NODATA : sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR_OK, $number_ids); |
||
389 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' catsubscr] ' . $status); |
||
390 | $protocolObj->setVar('protocol_success', true); |
||
391 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
392 | $protocolObj->setVar('protocol_created', time()); |
||
393 | |||
394 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
395 | $GLOBALS['xoopsTpl']->assign('error', _AM_XNEWSLETTER_MAINTENANCE_ERROR); |
||
396 | } |
||
397 | redirect_header($currentFile, 3, sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR_OK, $number_ids)); |
||
398 | } |
||
399 | } else { |
||
400 | xoops_confirm(['ok' => true, 'op' => 'del_invalid_subscr_catdel'], $currentFile, _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR_CATDEL); |
||
401 | } |
||
402 | break; |
||
403 | case 'del_invalid_ml': |
||
404 | if (true === Request::getBool('ok', false, 'POST')) { |
||
405 | $use_mailinglist = $GLOBALS['xoopsModuleConfig']['xn_use_mailinglist']; |
||
406 | $number_ids = 0; |
||
407 | $update = 0; |
||
408 | $errors = []; |
||
409 | if (0 == $use_mailinglist || '0' == $use_mailinglist) { |
||
410 | //set cat_mailinglist = 0, if use mailinglist = false (if someone changed module preferences later) |
||
411 | $sql = 'SELECT Count(`cat_id`) AS `nb_ids`'; |
||
412 | $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_cat')}`"; |
||
413 | $sql .= ' WHERE (`cat_mailinglist` > 0)'; |
||
414 | $result = $xoopsDB->query($sql); |
||
415 | if ($result) { |
||
416 | $row_result = $xoopsDB->fetchRow($result); |
||
417 | $number_ids = $row_result[0]; |
||
418 | } |
||
419 | if ($number_ids > 0) { |
||
420 | $sql = "UPDATE `{$xoopsDB->prefix('xnewsletter_cat')}` SET `cat_mailinglist` = 0"; |
||
421 | $result = $xoopsDB->query($sql); |
||
422 | if ($result) { |
||
423 | ++$update; |
||
424 | } else { |
||
425 | $errors[] = 'Error update cat_mailinglist: ' . $result->getHtmlErrors(); |
||
426 | } |
||
427 | } |
||
428 | } else { |
||
429 | //set cat_mailinglist = 0, if mailinglist_id is no more existing in table mailinglist |
||
430 | $sql = 'SELECT Count(`cat_mailinglist`) AS `nb_ids`'; |
||
431 | $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_cat')}` LEFT JOIN `{$xoopsDB->prefix('xnewsletter_mailinglist')}` ON `cat_mailinglist` = `mailinglist_id`"; |
||
432 | $sql .= ' WHERE (((`mailinglist_id`) Is Null) AND ((`cat_mailinglist`)>0)) HAVING (((Count(`cat_mailinglist`))>0));'; |
||
433 | $result = $xoopsDB->query($sql); |
||
434 | if ($result) { |
||
435 | $row_result = $xoopsDB->fetchRow($result); |
||
436 | $number_ids = $row_result[0]; |
||
437 | } |
||
438 | if ($number_ids > 0) { |
||
439 | $sql = "UPDATE `{$xoopsDB->prefix('xnewsletter_cat')}` LEFT JOIN `{$xoopsDB->prefix('xnewsletter_mailinglist')}` ON `cat_mailinglist` = `mailinglist_id` SET `cat_mailinglist` = 0"; |
||
440 | $sql .= ' WHERE (((`cat_mailinglist`)>0) AND ((`mailinglist_id`) Is Null));'; |
||
441 | $result = $xoopsDB->query($sql); |
||
442 | if ($result) { |
||
443 | ++$update; |
||
444 | } else { |
||
445 | $errors[] = 'Error update cat_mailinglist: ' . $result->getHtmlErrors(); |
||
446 | } |
||
447 | } |
||
448 | } |
||
449 | |||
450 | View Code Duplication | if (count($errors) > 0) { |
|
451 | foreach ($errors as $error) { |
||
452 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
453 | $protocolObj->setVar('protocol_letter_id', 0); |
||
454 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
455 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' ml] ' . $error); |
||
456 | $protocolObj->setVar('protocol_success', false); |
||
457 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
458 | $protocolObj->setVar('protocol_created', time()); |
||
459 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
460 | $GLOBALS['xoopsTpl']->assign('error', _AM_XNEWSLETTER_MAINTENANCE_ERROR); |
||
461 | } |
||
462 | } |
||
463 | } else { |
||
464 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
465 | $protocolObj->setVar('protocol_letter_id', 0); |
||
466 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
467 | $status = 0 == $number_ids ? _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_ML_NODATA : sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_ML_OK, $number_ids); |
||
468 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' ml] ' . $status); |
||
469 | $protocolObj->setVar('protocol_success', true); |
||
470 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
471 | $protocolObj->setVar('protocol_created', time()); |
||
472 | |||
473 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
474 | $GLOBALS['xoopsTpl']->assign('error', _AM_XNEWSLETTER_MAINTENANCE_ERROR); |
||
475 | } |
||
476 | } |
||
477 | redirect_header($currentFile, 3, sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_ML_OK, $number_ids)); |
||
478 | } else { |
||
479 | xoops_confirm(['ok' => true, 'op' => 'del_invalid_ml'], $currentFile, _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_ML); |
||
480 | } |
||
481 | break; |
||
482 | case 'del_invalid_cat': |
||
483 | //remove cat from letter_cats, if cat is missing (if someone deleted cat after creating letter) |
||
484 | if (true === Request::getBool('ok', false, 'POST')) { |
||
485 | $update = 0; |
||
486 | $errors = []; |
||
487 | $number_ids = 0; |
||
488 | |||
489 | $letterObjs = $helper->getHandler('Letter')->getAll(); |
||
490 | foreach ($letterObjs as $letter_id => $letterObj) { |
||
491 | $letter_cats_new = ''; |
||
492 | $letter_cats_old = $letterObj->getVar('letter_cats'); |
||
493 | $letter_cats = []; |
||
494 | $letter_cats = explode('|', $letter_cats_old); |
||
495 | |||
496 | foreach ($letter_cats as $cat_id) { |
||
497 | // check each cat and create new string 'letter_cats' |
||
498 | $catCriteria = new \CriteriaCompo(); |
||
499 | $catCriteria->add(new \Criteria('cat_id', $cat_id)); |
||
500 | $catCount = $helper->getHandler('Cat')->getCount($catCriteria); |
||
501 | if ($catCount > 0) { |
||
502 | $letter_cats_new .= $cat_id . '|'; |
||
503 | } |
||
504 | } |
||
505 | $letter_cats_new = mb_substr($letter_cats_new, 0, -1); |
||
506 | |||
507 | if ($letter_cats_old != $letter_cats_new) { |
||
508 | //update with correct value |
||
509 | $letterObj = $helper->getHandler('Letter')->get($letter_id); |
||
510 | $letterObj->setVar('letter_cats', $letter_cats_new); |
||
511 | if ($helper->getHandler('Letter')->insert($letterObj)) { |
||
512 | ++$update; |
||
513 | } else { |
||
514 | $errors[] = 'Error update cat: ' . $result->getHtmlErrors(); |
||
515 | } |
||
516 | } |
||
517 | } |
||
518 | |||
519 | View Code Duplication | if (count($errors) > 0) { |
|
520 | foreach ($errors as $error) { |
||
521 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
522 | $protocolObj->setVar('protocol_letter_id', 0); |
||
523 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
524 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' cat] ' . $error); |
||
525 | $protocolObj->setVar('protocol_success', false); |
||
526 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
527 | $protocolObj->setVar('protocol_created', time()); |
||
528 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
529 | $GLOBALS['xoopsTpl']->assign('error', _AM_XNEWSLETTER_MAINTENANCE_ERROR); |
||
530 | } |
||
531 | } |
||
532 | } else { |
||
533 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
534 | $protocolObj->setVar('protocol_letter_id', 0); |
||
535 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
536 | $status = 0 == $update ? _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_CATNL_NODATA : sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_CATNL_OK, $update); |
||
537 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' cat] ' . $status); |
||
538 | $protocolObj->setVar('protocol_success', true); |
||
539 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
540 | $protocolObj->setVar('protocol_created', time()); |
||
541 | |||
542 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
543 | $GLOBALS['xoopsTpl']->assign('error', _AM_XNEWSLETTER_MAINTENANCE_ERROR); |
||
544 | } |
||
545 | } |
||
546 | redirect_header($currentFile, 3, sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_CATNL_OK, $number_ids)); |
||
547 | } else { |
||
548 | xoops_confirm(['ok' => true, 'op' => 'del_invalid_cat'], $currentFile, _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_CATNL); |
||
549 | } |
||
550 | break; |
||
551 | } |
||
552 | require_once __DIR__ . '/admin_footer.php'; |
||
553 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.