Code Duplication    Length = 22-22 lines in 2 locations

admin/letter.php 1 location

@@ 415-436 (lines=22) @@
412
        break;
413
    case 'delete_letter':
414
        $letterObj = $helper->getHandler('Letter')->get($letterId);
415
        if (true === Request::getBool('ok', false, 'POST')) {
416
            if (!$GLOBALS['xoopsSecurity']->check()) {
417
                redirect_header($currentFile, 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
418
            }
419
            if ($helper->getHandler('Letter')->delete($letterObj)) {
420
                //delete protocols
421
                $sql = 'DELETE';
422
                $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_protocol')}`";
423
                $sql .= " WHERE `protocol_letter_id`={$letterId}";
424
                if (!$result = $xoopsDB->query($sql)) {
425
                    die('MySQL-Error: ' . $GLOBALS['xoopsDB']->error());
426
                }
427
                // delete attachments
428
                $attachmentCriteria = new \Criteria('attachment_letter_id', $letterId);
429
                $helper->getHandler('Attachment')->deleteAll($attachmentCriteria, true, true);
430
                redirect_header($currentFile, 3, _AM_XNEWSLETTER_FORMDELOK);
431
            } else {
432
                $GLOBALS['xoopsTpl']->assign('error', $letterObj->getHtmlErrors());
433
            }
434
        } else {
435
            xoops_confirm(['ok' => true, 'letter_id' => $letterId, 'op' => 'delete_letter'], $_SERVER['REQUEST_URI'], sprintf(_AM_XNEWSLETTER_FORMSUREDEL, $letterObj->getVar('letter_title')));
436
        }
437
        break;
438
}
439
require_once __DIR__ . '/admin_footer.php';

letter.php 1 location

@@ 620-641 (lines=22) @@
617
        // IN PROGRESS FROM HERE
618
619
        $letterObj = $helper->getHandler('Letter')->get($letter_id);
620
        if (true === Request::getBool('ok', false, 'POST')) {
621
            if (!$GLOBALS['xoopsSecurity']->check()) {
622
                redirect_header($currentFile, 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
623
            }
624
            if ($helper->getHandler('Letter')->delete($letterObj)) {
625
                //delete protocols
626
                $sql = 'DELETE';
627
                $sql .= " FROM `{$xoopsDB->prefix('xnewsletter_protocol')}`";
628
                $sql .= " WHERE `protocol_letter_id`={$letter_id}";
629
                if (!$result = $xoopsDB->query($sql)) {
630
                    die('MySQL-Error: ' . $GLOBALS['xoopsDB']->error());
631
                }
632
                // delete attachments
633
                $attachmentCriteria = new \Criteria('attachment_letter_id', $letter_id);
634
                $helper->getHandler('Attachment')->deleteAll($attachmentCriteria, true, true);
635
                redirect_header($currentFile, 3, _AM_XNEWSLETTER_FORMDELOK);
636
            } else {
637
                $GLOBALS['xoopsTpl']->assign('error', $letterObj->getHtmlErrors());
638
            }
639
        } else {
640
            xoops_confirm(['ok' => true, 'letter_id' => $letter_id, 'op' => 'delete_letter'], $_SERVER['REQUEST_URI'], sprintf(_AM_XNEWSLETTER_FORMSUREDEL, $letterObj->getVar('letter_title')));
641
        }
642
        break;
643
}
644