Code Duplication    Length = 25-25 lines in 2 locations

admin/main.php 1 location

@@ 540-564 (lines=25) @@
537
538
            $numrows = $xoopsDB->getRowsNum($allcatsresult);
539
            $count   = 0;
540
            if ($numrows > 0) {
541
                while (list($cid) = $xoopsDB->fetchRow($allcatsresult)) {
542
                    if (isset($_POST['selected' . $cid . ''])) {
543
                        if (!in_array($cid, $linkedcats)) {
544
                            $newid = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_item_x_cat') . '_xid_seq');
545
                            $sql   = sprintf("INSERT INTO %s (xid, cid, itemid, active, created) VALUES (%u, %u, %u, '%s', '%s')", $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_item_x_cat'), $newid, $cid, $post_itemid, 1, time());
546
                            $xoopsDB->query($sql) or $eh->show('0013');
547
                        }
548
549
                        ++$count;
550
                    } else {
551
                        if (in_array($cid, $linkedcats)) {
552
                            $sql = sprintf('DELETE FROM %s WHERE cid=%u AND itemid=%u', $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_item_x_cat'), $cid, $post_itemid);
553
                            $xoopsDB->query($sql) or $eh->show('0013');
554
                        }
555
                    }
556
                }
557
                if ($count == 0) {
558
                    redirect_header(XOOPS_URL . "/modules/$moddir/admin/main.php?op=edit&item=" . $post_itemid . '', 2, _MD_NOCATEGORYMATCH);
559
                    exit();
560
                }
561
            } else {
562
                redirect_header(XOOPS_URL . "/modules/$moddir/admin/main.php?op=edit&item=" . $post_itemid . '', 2, _MD_NOCATEGORIESAVAILABLE);
563
                exit();
564
            }
565
566
            redirect_header("main.php?op=edit&item=$post_itemid", 2, _MD_ITEM_UPDATED);
567
            exit();

edit.php 1 location

@@ 159-183 (lines=25) @@
156
    $allcatsresult = $xoopsDB->query('SELECT cid FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_cat') . " WHERE dirid='" . $post_dirid . '\' AND active=\'1\'');
157
    $numrows       = $xoopsDB->getRowsNum($allcatsresult);
158
    $count         = 0;
159
    if ($numrows > 0) {
160
        while (list($cid) = $xoopsDB->fetchRow($allcatsresult)) {
161
            if (isset($_POST['selected' . $cid . ''])) {
162
                if (!in_array($cid, $linkedcats)) {
163
                    $newid = $xoopsDB->genId($xoopsDB->prefix($module->getVar('dirname', 'n') . '_item_x_cat') . '_xid_seq');
164
                    $sql   = sprintf("INSERT INTO %s (xid, cid, itemid, active, created) VALUES (%u, %u, %u, '%s', '%s')", $xoopsDB->prefix($module->getVar('dirname', 'n') . '_item_x_cat'), $newid, $cid, $post_itemid, 1, time());
165
                    $xoopsDB->query($sql) or $eh->show('0013');
166
                }
167
168
                ++$count;
169
            } else {
170
                if (in_array($cid, $linkedcats)) {
171
                    $sql = sprintf('DELETE FROM %s WHERE cid=%u AND itemid=%u', $xoopsDB->prefix($module->getVar('dirname', 'n') . '_item_x_cat'), $cid, $post_itemid);
172
                    $xoopsDB->query($sql) or $eh->show('0013');
173
                }
174
            }
175
        }
176
        if ($count == 0) {
177
            redirect_header(XOOPS_URL . "/modules/$moddir/submit.php?dirid=" . $post_dirid . '', 2, _MD_NOCATEGORYMATCH);
178
            exit();
179
        }
180
    } else {
181
        redirect_header(XOOPS_URL . "/modules/$moddir/submit.php?dirid=" . $post_dirid . '', 2, _MD_NOCATEGORIESAVAILABLE);
182
        exit();
183
    }
184
185
    // Get all datatypes that can be associated with this listing.
186
    $sql         = 'SELECT DISTINCT t.dtypeid, t.title, t.section, f.typeid, f.fieldtype, f.ext, t.options, d.itemid, d.value, t.custom ';