XoopsModules25x /
xnewsletter
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 | // We recovered the value of the argument op in the URL$ |
||
| 35 | $op = \Xmf\Request::getString('op', 'list'); |
||
| 36 | |||
| 37 | switch ($op) { |
||
| 38 | case 'list': |
||
| 39 | default: |
||
| 40 | $adminObject->displayNavigation($currentFile); |
||
| 41 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 42 | echo " |
||
| 43 | <table class='outer width75'> |
||
| 44 | <tr> |
||
| 45 | <th>" . _AM_XNEWSLETTER_MAINTENANCE_CAT . '</th> |
||
| 46 | <th>' . _AM_XNEWSLETTER_MAINTENANCE_DESCR . '</th> |
||
| 47 | <th>' . _AM_XNEWSLETTER_MAINTENANCE_PARAM . '</th> |
||
| 48 | <th>' . _AM_XNEWSLETTER_FORMACTION . '</th> |
||
| 49 | </tr>'; |
||
| 50 | $class = 'odd'; |
||
| 51 | |||
| 52 | // delete protocols |
||
| 53 | echo " <tr class='{$class}'>"; |
||
| 54 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
| 55 | echo " <form action='{$currentFile}' method='post'>"; |
||
| 56 | echo ' <td>protocol</td>'; |
||
| 57 | echo ' <td>' . _AM_XNEWSLETTER_MAINTENANCE_DELETEPROTOCOL . '</td>'; |
||
| 58 | echo ' <td> </td>'; |
||
| 59 | $cal_tray = new \XoopsFormElementTray(' ', ' '); |
||
| 60 | $cal_tray->addElement(new \XoopsFormHidden('op', 'del_oldprotocol')); |
||
| 61 | $cal_tray->addElement(new \XoopsFormButton('', 'post', _SUBMIT, 'submit')); |
||
| 62 | echo " <td class='center'>" . $cal_tray->render() . '</td>'; |
||
| 63 | echo ' </form>'; |
||
| 64 | echo ' </tr>'; |
||
| 65 | |||
| 66 | // delete unconfirmed registrations |
||
| 67 | echo " <tr class='{$class}'>"; |
||
| 68 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
| 69 | echo " <form action='{$currentFile}' method='post'>"; |
||
| 70 | echo ' <td>subscr</td>'; |
||
| 71 | echo ' <td>' . _AM_XNEWSLETTER_MAINTENANCE_DELETEDATE . '</td>'; |
||
| 72 | $cal = new \XoopsFormTextDateSelect('', 'del_date', 15, time() - (84600 * 10)); |
||
| 73 | echo ' <td>' . $cal->render() . '</td>'; |
||
| 74 | $cal_tray = new \XoopsFormElementTray(' ', ' '); |
||
| 75 | $cal_tray->addElement(new \XoopsFormHidden('op', 'del_oldsubscr')); |
||
| 76 | $cal_tray->addElement(new \XoopsFormButton('', 'post', _SUBMIT, 'submit')); |
||
| 77 | echo " <td class='center'>" . $cal_tray->render() . '</td>'; |
||
| 78 | echo ' </form>'; |
||
| 79 | echo ' </tr>'; |
||
| 80 | |||
| 81 | // delete invalid catsubscr |
||
| 82 | echo " <tr class='{$class}'>"; |
||
| 83 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
| 84 | echo " <form action='{$currentFile}' method='post'>"; |
||
| 85 | echo ' <td>catsubscr</td>'; |
||
| 86 | echo ' <td>' . _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR . '</td>'; |
||
| 87 | echo ' <td> </td>'; |
||
| 88 | echo " <td class='center'>"; |
||
| 89 | $cal_tray = new \XoopsFormElementTray(' ', ' '); |
||
| 90 | $cal_tray->addElement(new \XoopsFormHidden('op', 'del_invalid_catsubscr')); |
||
| 91 | $cal_tray->addElement(new \XoopsFormButton('', 'post', _SUBMIT, 'submit')); |
||
| 92 | echo $cal_tray->render(); |
||
| 93 | echo ' </td>'; |
||
| 94 | echo ' </form>'; |
||
| 95 | echo ' </tr>'; |
||
| 96 | |||
| 97 | // check module preference xn_use_mailinglist with values in cat_mailinglist and check cat_mailinglist versus table mailinglist |
||
| 98 | |||
| 99 | if (1 == $helper->getConfig('xn_use_mailinglist')) { |
||
| 100 | echo " <tr class='{$class}'>"; |
||
| 101 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
| 102 | echo " <form action='{$currentFile}' method='post'>"; |
||
| 103 | echo ' <td>ml</td>'; |
||
| 104 | echo ' <td>' . _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_ML . '</td>'; |
||
| 105 | echo ' <td> </td>'; |
||
| 106 | echo " <td class='center'>"; |
||
| 107 | $cal_tray = new \XoopsFormElementTray(' ', ' '); |
||
| 108 | $cal_tray->addElement(new \XoopsFormHidden('op', 'del_invalid_ml')); |
||
| 109 | $cal_tray->addElement(new \XoopsFormButton('', 'post', _SUBMIT, 'submit')); |
||
| 110 | echo $cal_tray->render(); |
||
| 111 | echo ' </td>'; |
||
| 112 | echo ' </form>'; |
||
| 113 | echo ' </tr>'; |
||
| 114 | } |
||
| 115 | |||
| 116 | // delete invalid cat |
||
| 117 | echo " <tr class='{$class}'>"; |
||
| 118 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
| 119 | echo " <form action='{$currentFile}' method='post'>"; |
||
| 120 | echo ' <td>cat</td>'; |
||
| 121 | echo ' <td>' . _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_CATNL . '</td>'; |
||
| 122 | echo ' <td> </td>'; |
||
| 123 | echo " <td class='center'>"; |
||
| 124 | $cal_tray = new \XoopsFormElementTray(' ', ' '); |
||
| 125 | $cal_tray->addElement(new \XoopsFormHidden('op', 'del_invalid_cat')); |
||
| 126 | $cal_tray->addElement(new \XoopsFormButton('', 'post', _SUBMIT, 'submit')); |
||
| 127 | echo $cal_tray->render(); |
||
| 128 | echo ' </td>'; |
||
| 129 | echo ' </form>'; |
||
| 130 | echo ' </tr>'; |
||
| 131 | |||
| 132 | // delete import |
||
| 133 | echo " <tr class='{$class}'>"; |
||
| 134 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
| 135 | echo " <form action='{$currentFile}' method='post'>"; |
||
| 136 | echo ' <td>import</td>'; |
||
| 137 | echo ' <td>' . _AM_XNEWSLETTER_MAINTENANCE_DELETE_IMPORT . '</td>'; |
||
| 138 | echo ' <td> </td>'; |
||
| 139 | echo " <td class='center'>"; |
||
| 140 | $cal_tray = new \XoopsFormElementTray(' ', ' '); |
||
| 141 | $cal_tray->addElement(new \XoopsFormHidden('op', 'del_import')); |
||
| 142 | $cal_tray->addElement(new \XoopsFormButton('', 'post', _SUBMIT, 'submit')); |
||
| 143 | echo $cal_tray->render(); |
||
| 144 | echo ' </td>'; |
||
| 145 | echo ' </form>'; |
||
| 146 | echo ' </tr>'; |
||
| 147 | |||
| 148 | echo '</table>'; |
||
| 149 | break; |
||
| 150 | View Code Duplication | case 'del_import': |
|
|
0 ignored issues
–
show
|
|||
| 151 | if (true === \Xmf\Request::getBool('ok', false, 'POST')) { |
||
| 152 | $result = $xoopsDB->queryF("TRUNCATE TABLE `{$xoopsDB->prefix('xnewsletter_import')}`"); |
||
| 153 | $result = $xoopsDB->queryF("REPAIR TABLE `{$xoopsDB->prefix('xnewsletter_import')}`"); |
||
| 154 | $result = $xoopsDB->queryF("OPTIMIZE TABLE `{$xoopsDB->prefix('xnewsletter_import')}`"); |
||
| 155 | $result = $xoopsDB->queryF("ALTER TABLE `{$xoopsDB->prefix('xnewsletter_import')}` AUTO_INCREMENT =1"); |
||
| 156 | |||
| 157 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
| 158 | $protocolObj->setVar('protocol_letter_id', 0); |
||
| 159 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
| 160 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' import] ' . _AM_XNEWSLETTER_MAINTENANCE_DELETE_IMPORT_OK); |
||
| 161 | $protocolObj->setVar('protocol_success', true); |
||
| 162 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
| 163 | $protocolObj->setVar('protocol_created', time()); |
||
| 164 | |||
| 165 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
| 166 | // IN PROGRESS |
||
| 167 | } |
||
| 168 | redirect_header($currentFile, 3, _AM_XNEWSLETTER_MAINTENANCE_DELETE_IMPORT_OK); |
||
| 169 | } else { |
||
| 170 | xoops_confirm(['ok' => true, 'op' => 'del_import'], $currentFile, _AM_XNEWSLETTER_MAINTENANCE_DELETE_IMPORT); |
||
| 171 | } |
||
| 172 | break; |
||
| 173 | case 'del_oldsubscr': |
||
| 174 | $time = strtotime($_POST['del_date']); |
||
| 175 | if ($time >= time() || 0 == $time) { |
||
| 176 | $subscrCount = -1; // for error |
||
| 177 | } else { |
||
| 178 | $subscrCriteria = new \CriteriaCompo(); |
||
| 179 | $subscrCriteria->add(new \Criteria('subscr_activated', 0)); |
||
| 180 | $subscrCriteria->add(new \Criteria('subscr_created', $time, '<')); |
||
| 181 | $subscrCount = $helper->getHandler('Subscr')->getCount($subscrCriteria); |
||
| 182 | } |
||
| 183 | |||
| 184 | if (true === \Xmf\Request::getBool('ok', false, 'POST')) { |
||
| 185 | $deleted = 0; |
||
| 186 | $errors = []; |
||
| 187 | $subscrArrays = $helper->getHandler('Subscr')->getAll($subscrCriteria, ['subscr_id'], false, false); |
||
| 188 | foreach ($subscrArrays as $subscrArray) { |
||
| 189 | $subscrObj = $helper->getHandler('Subscr')->get((int)$subscrArray['subscr_id']); |
||
| 190 | $sql = 'DELETE'; |
||
| 191 | $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_subscr')}`"; |
||
| 192 | $sql .= " WHERE subscr_id={$subscrArray['subscr_id']}"; |
||
| 193 | $result = $xoopsDB->queryF($sql); |
||
| 194 | if ($result) { |
||
| 195 | // Newsletterlist delete |
||
| 196 | $sql = 'DELETE'; |
||
| 197 | $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_catsubscr')}`"; |
||
| 198 | $sql .= " WHERE catsubscr_subscrid={$subscrArray['subscr_id']}"; |
||
| 199 | $result = $xoopsDB->queryF($sql); |
||
| 200 | if (!$result) { |
||
| 201 | $errors[] = 'Error CAT-Subscr-ID: ' . $subscrArray['subscr_id'] . ' / ' . $result->getHtmlErrors(); |
||
| 202 | } |
||
| 203 | ++$deleted; |
||
| 204 | } else { |
||
| 205 | $errors[] = 'Error Subscr-ID: ' . $subscrArray['subscr_id'] . ' / ' . $result->getHtmlErrors(); |
||
| 206 | } |
||
| 207 | } |
||
| 208 | |||
| 209 | View Code Duplication | if (count($errors) > 0) { |
|
| 210 | foreach ($errors as $error) { |
||
| 211 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
| 212 | $protocolObj->setVar('protocol_letter_id', 0); |
||
| 213 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
| 214 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' reguser] ' . $error); |
||
| 215 | $protocolObj->setVar('protocol_success', false); |
||
| 216 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
| 217 | $protocolObj->setVar('protocol_created', time()); |
||
| 218 | $helper->getHandler('Protocol')->insert($protocolObj); |
||
| 219 | } |
||
| 220 | } |
||
| 221 | |||
| 222 | View Code Duplication | if ($deleted > 0) { |
|
| 223 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
| 224 | $protocolObj->setVar('protocol_letter_id', 0); |
||
| 225 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
| 226 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' reguser] ' . sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETEUSEROK, $deleted)); |
||
| 227 | $protocolObj->setVar('protocol_success', true); |
||
| 228 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
| 229 | $protocolObj->setVar('protocol_created', time()); |
||
| 230 | $helper->getHandler('Protocol')->insert($protocolObj); |
||
| 231 | } |
||
| 232 | redirect_header($currentFile, 3, sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETEUSEROK, $deleted)); |
||
| 233 | } else { |
||
| 234 | if ($subscrCount > 0) { |
||
| 235 | xoops_confirm(['ok' => true, 'del_date' => $_POST['del_date'], 'op' => 'del_oldsubscr'], $currentFile, sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETEUSER, $subscrCount, $_POST['del_date'])); |
||
| 236 | } else { |
||
| 237 | redirect_header($currentFile, 3, _AM_XNEWSLETTER_MAINTENANCE_DELETENOTHING); |
||
| 238 | } |
||
| 239 | } |
||
| 240 | break; |
||
| 241 | View Code Duplication | case 'del_oldprotocol': |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. Loading history...
|
|||
| 242 | if (true === \Xmf\Request::getBool('ok', false, 'POST')) { |
||
| 243 | $result = $xoopsDB->queryF("TRUNCATE TABLE `{$xoopsDB->prefix('xnewsletter_protocol')}`"); |
||
| 244 | $result = $xoopsDB->queryF("REPAIR TABLE `{$xoopsDB->prefix('xnewsletter_protocol')}`"); |
||
| 245 | $result = $xoopsDB->queryF("OPTIMIZE TABLE `{$xoopsDB->prefix('xnewsletter_protocol')}`"); |
||
| 246 | $result = $xoopsDB->queryF("ALTER TABLE `{$xoopsDB->prefix('xnewsletter_protocol')}` AUTO_INCREMENT =1"); |
||
| 247 | |||
| 248 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
| 249 | $protocolObj->setVar('protocol_letter_id', 0); |
||
| 250 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
| 251 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' prot] ' . _AM_XNEWSLETTER_MAINTENANCE_DELETEPROTOK); |
||
| 252 | $protocolObj->setVar('protocol_success', true); |
||
| 253 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
| 254 | $protocolObj->setVar('protocol_created', time()); |
||
| 255 | |||
| 256 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
| 257 | // IN PROGRESS |
||
| 258 | } |
||
| 259 | redirect_header($currentFile, 3, _AM_XNEWSLETTER_MAINTENANCE_DELETEPROTOK); |
||
| 260 | } else { |
||
| 261 | xoops_confirm(['ok' => true, 'op' => 'del_oldprotocol'], $currentFile, _AM_XNEWSLETTER_MAINTENANCE_DELETEPROTOCOL); |
||
| 262 | } |
||
| 263 | break; |
||
| 264 | case 'del_invalid_catsubscr': |
||
| 265 | //delete data in table catsubscr, if catsubscr_subscrid is no more existing in table subscr |
||
| 266 | if (true === \Xmf\Request::getBool('ok', false, 'POST')) { |
||
| 267 | $number_ids = 0; |
||
| 268 | $deleted = 0; |
||
| 269 | $errors = []; |
||
| 270 | $sql = 'SELECT Count(`catsubscr_id`) AS `nb_ids`'; |
||
| 271 | $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_catsubscr')}` LEFT JOIN `{$xoopsDB->prefix('xnewsletter_subscr')}` ON `catsubscr_subscrid` = `subscr_id`"; |
||
| 272 | $sql .= ' WHERE (`subscr_id` Is Null)'; |
||
| 273 | View Code Duplication | if ($result = $xoopsDB->query($sql)) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. Loading history...
|
|||
| 274 | $row_result = $xoopsDB->fetchRow($result); |
||
| 275 | $number_ids = $row_result[0]; |
||
| 276 | } |
||
| 277 | if ($number_ids > 0) { |
||
| 278 | $sql = "DELETE `{$xoopsDB->prefix('xnewsletter_catsubscr')}`"; |
||
| 279 | $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_catsubscr')}` LEFT JOIN `{$xoopsDB->prefix('xnewsletter_subscr')}` ON `catsubscr_subscrid` = `subscr_id`"; |
||
| 280 | $sql .= ' WHERE (`subscr_id` Is Null)'; |
||
| 281 | $result = $xoopsDB->query($sql); |
||
| 282 | View Code Duplication | if ($result = $xoopsDB->query($sql)) { |
|
| 283 | ++$deleted; |
||
| 284 | } else { |
||
| 285 | $errors[] = 'Error delete catsubscr: ' . $result->getHtmlErrors(); |
||
| 286 | } |
||
| 287 | } |
||
| 288 | |||
| 289 | if (count($errors) > 0) { |
||
| 290 | foreach ($errors as $error) { |
||
| 291 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
| 292 | $protocolObj->setVar('protocol_letter_id', 0); |
||
| 293 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
| 294 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' catsubscr] ' . $error); |
||
| 295 | $protocolObj->setVar('protocol_success', false); |
||
| 296 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
| 297 | $protocolObj->setVar('protocol_created', time()); |
||
| 298 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
| 299 | echo _AM_XNEWSLETTER_MAINTENANCE_ERROR; |
||
| 300 | } |
||
| 301 | } |
||
| 302 | } else { |
||
| 303 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
| 304 | $protocolObj->setVar('protocol_letter_id', 0); |
||
| 305 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
| 306 | $status = 0 == $number_ids ? _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR_NODATA : sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR_OK, $number_ids); |
||
| 307 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' catsubscr] ' . $status); |
||
| 308 | $protocolObj->setVar('protocol_success', true); |
||
| 309 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
| 310 | $protocolObj->setVar('protocol_created', time()); |
||
| 311 | |||
| 312 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
| 313 | echo _AM_XNEWSLETTER_MAINTENANCE_ERROR; |
||
| 314 | } |
||
| 315 | redirect_header($currentFile, 3, sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR_OK, $number_ids)); |
||
| 316 | } |
||
| 317 | } else { |
||
| 318 | xoops_confirm(['ok' => true, 'op' => 'del_invalid_catsubscr'], $currentFile, _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_SUBCR); |
||
| 319 | } |
||
| 320 | break; |
||
| 321 | case 'del_invalid_ml': |
||
| 322 | if (true === \Xmf\Request::getBool('ok', false, 'POST')) { |
||
| 323 | $use_mailinglist = $GLOBALS['xoopsModuleConfig']['xn_use_mailinglist']; |
||
| 324 | $number_ids = 0; |
||
| 325 | $update = 0; |
||
| 326 | $errors = []; |
||
| 327 | if (0 == $use_mailinglist || '0' == $use_mailinglist) { |
||
| 328 | //set cat_mailinglist = 0, if use mailinglist = false (if someone changed module preferences later) |
||
| 329 | $sql = 'SELECT Count(`cat_id`) AS `nb_ids`'; |
||
| 330 | $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_cat')}`"; |
||
| 331 | $sql .= ' WHERE (`cat_mailinglist` > 0)'; |
||
| 332 | View Code Duplication | if ($result = $xoopsDB->query($sql)) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. Loading history...
|
|||
| 333 | $row_result = $xoopsDB->fetchRow($result); |
||
| 334 | $number_ids = $row_result[0]; |
||
| 335 | } |
||
| 336 | if ($number_ids > 0) { |
||
| 337 | $sql = "UPDATE `{$xoopsDB->prefix('xnewsletter_cat')}` SET `cat_mailinglist` = 0"; |
||
| 338 | View Code Duplication | if ($result = $xoopsDB->query($sql)) { |
|
| 339 | ++$update; |
||
| 340 | } else { |
||
| 341 | $errors[] = 'Error update cat_mailinglist: ' . $result->getHtmlErrors(); |
||
| 342 | } |
||
| 343 | } |
||
| 344 | } else { |
||
| 345 | //set cat_mailinglist = 0, if mailinglist_id is no more existing in table mailinglist |
||
| 346 | $sql = 'SELECT Count(`cat_mailinglist`) AS `nb_ids`'; |
||
| 347 | $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_cat')}` LEFT JOIN `{$xoopsDB->prefix('xnewsletter_mailinglist')}` ON `cat_mailinglist` = `mailinglist_id`"; |
||
| 348 | $sql .= ' WHERE (((`mailinglist_id`) Is Null) AND ((`cat_mailinglist`)>0)) HAVING (((Count(`cat_mailinglist`))>0));'; |
||
| 349 | View Code Duplication | if ($result = $xoopsDB->query($sql)) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. Loading history...
|
|||
| 350 | $row_result = $xoopsDB->fetchRow($result); |
||
| 351 | $number_ids = $row_result[0]; |
||
| 352 | } |
||
| 353 | if ($number_ids > 0) { |
||
| 354 | $sql = "UPDATE `{$xoopsDB->prefix('xnewsletter_cat')}` LEFT JOIN `{$xoopsDB->prefix('xnewsletter_mailinglist')}` ON `cat_mailinglist` = `mailinglist_id` SET `cat_mailinglist` = 0"; |
||
| 355 | $sql .= ' WHERE (((`cat_mailinglist`)>0) AND ((`mailinglist_id`) Is Null));'; |
||
| 356 | View Code Duplication | if ($result = $xoopsDB->query($sql)) { |
|
| 357 | ++$update; |
||
| 358 | } else { |
||
| 359 | $errors[] = 'Error update cat_mailinglist: ' . $result->getHtmlErrors(); |
||
| 360 | } |
||
| 361 | } |
||
| 362 | } |
||
| 363 | |||
| 364 | View Code Duplication | if (count($errors) > 0) { |
|
| 365 | foreach ($errors as $error) { |
||
| 366 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
| 367 | $protocolObj->setVar('protocol_letter_id', 0); |
||
| 368 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
| 369 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' ml] ' . $error); |
||
| 370 | $protocolObj->setVar('protocol_success', false); |
||
| 371 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
| 372 | $protocolObj->setVar('protocol_created', time()); |
||
| 373 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
| 374 | echo _AM_XNEWSLETTER_MAINTENANCE_ERROR; |
||
| 375 | } |
||
| 376 | } |
||
| 377 | } else { |
||
| 378 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
| 379 | $protocolObj->setVar('protocol_letter_id', 0); |
||
| 380 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
| 381 | $status = 0 == $number_ids ? _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_ML_NODATA : sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_ML_OK, $number_ids); |
||
| 382 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' ml] ' . $status); |
||
| 383 | $protocolObj->setVar('protocol_success', true); |
||
| 384 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
| 385 | $protocolObj->setVar('protocol_created', time()); |
||
| 386 | |||
| 387 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
| 388 | echo _AM_XNEWSLETTER_MAINTENANCE_ERROR; |
||
| 389 | } |
||
| 390 | } |
||
| 391 | redirect_header($currentFile, 3, sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_ML_OK, $number_ids)); |
||
| 392 | } else { |
||
| 393 | xoops_confirm(['ok' => true, 'op' => 'del_invalid_ml'], $currentFile, _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_ML); |
||
| 394 | } |
||
| 395 | break; |
||
| 396 | case 'del_invalid_cat': |
||
| 397 | //remove cat from letter_cats, if cat is missing (if someone deleted cat after creating letter) |
||
| 398 | if (true === \Xmf\Request::getBool('ok', false, 'POST')) { |
||
| 399 | $update = 0; |
||
| 400 | $errors = []; |
||
| 401 | $number_ids = 0; |
||
| 402 | |||
| 403 | $letterObjs = $helper->getHandler('Letter')->getAll(); |
||
| 404 | foreach ($letterObjs as $letter_id => $letterObj) { |
||
| 405 | $letter_cats_new = ''; |
||
| 406 | $letter_cats_old = $letterObj->getVar('letter_cats'); |
||
| 407 | $letter_cats = []; |
||
| 408 | $letter_cats = explode('|', $letter_cats_old); |
||
| 409 | |||
| 410 | foreach ($letter_cats as $cat_id) { |
||
| 411 | // check each cat and create new string 'letter_cats' |
||
| 412 | $catCriteria = new \CriteriaCompo(); |
||
| 413 | $catCriteria->add(new \Criteria('cat_id', $cat_id)); |
||
| 414 | $catCount = $helper->getHandler('Cat')->getCount($catCriteria); |
||
| 415 | if ($catCount > 0) { |
||
| 416 | $letter_cats_new .= $cat_id . '|'; |
||
| 417 | } |
||
| 418 | } |
||
| 419 | $letter_cats_new = mb_substr($letter_cats_new, 0, -1); |
||
| 420 | |||
| 421 | if ($letter_cats_old != $letter_cats_new) { |
||
| 422 | //update with correct value |
||
| 423 | $letterObj = $helper->getHandler('Letter')->get($letter_id); |
||
| 424 | $letterObj->setVar('letter_cats', $letter_cats_new); |
||
| 425 | if ($helper->getHandler('Letter')->insert($letterObj)) { |
||
| 426 | ++$update; |
||
| 427 | } else { |
||
| 428 | $errors[] = 'Error update cat: ' . $result->getHtmlErrors(); |
||
| 429 | } |
||
| 430 | } |
||
| 431 | } |
||
| 432 | |||
| 433 | View Code Duplication | if (count($errors) > 0) { |
|
| 434 | foreach ($errors as $error) { |
||
| 435 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
| 436 | $protocolObj->setVar('protocol_letter_id', 0); |
||
| 437 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
| 438 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' cat] ' . $error); |
||
| 439 | $protocolObj->setVar('protocol_success', false); |
||
| 440 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
| 441 | $protocolObj->setVar('protocol_created', time()); |
||
| 442 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
| 443 | echo _AM_XNEWSLETTER_MAINTENANCE_ERROR; |
||
| 444 | } |
||
| 445 | } |
||
| 446 | } else { |
||
| 447 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
| 448 | $protocolObj->setVar('protocol_letter_id', 0); |
||
| 449 | $protocolObj->setVar('protocol_subscriber_id', 0); |
||
| 450 | $status = 0 == $update ? _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_CATNL_NODATA : sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_CATNL_OK, $update); |
||
| 451 | $protocolObj->setVar('protocol_status', '[' . _MI_XNEWSLETTER_ADMENU11 . ' cat] ' . $status); |
||
| 452 | $protocolObj->setVar('protocol_success', true); |
||
| 453 | $protocolObj->setVar('protocol_submitter', $GLOBALS['xoopsUser']->uid()); |
||
| 454 | $protocolObj->setVar('protocol_created', time()); |
||
| 455 | |||
| 456 | if (!$helper->getHandler('Protocol')->insert($protocolObj)) { |
||
| 457 | echo _AM_XNEWSLETTER_MAINTENANCE_ERROR; |
||
| 458 | } |
||
| 459 | } |
||
| 460 | redirect_header($currentFile, 3, sprintf(_AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_CATNL_OK, $number_ids)); |
||
| 461 | } else { |
||
| 462 | xoops_confirm(['ok' => true, 'op' => 'del_invalid_cat'], $currentFile, _AM_XNEWSLETTER_MAINTENANCE_DELETE_INVALID_CATNL); |
||
| 463 | } |
||
| 464 | break; |
||
| 465 | } |
||
| 466 | require_once __DIR__ . '/admin_footer.php'; |
||
| 467 |
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.