saveDatatype()   F
last analyzed

Complexity

Conditions 16
Paths 0

Size

Total Lines 82
Code Lines 66

Duplication

Lines 23
Ratio 28.05 %

Importance

Changes 0
Metric Value
cc 16
eloc 66
nc 0
nop 0
dl 23
loc 82
rs 2.0442
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      efqdirectory
16
 * @since
17
 * @author       Martijn Hertog (aka wtravel)
18
 * @author       XOOPS Development Team,
19
 */
20
21
require_once __DIR__ . '/admin_header.php';
22
//include __DIR__ . '/../../../include/cp_header.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
23
24
include __DIR__ . '/../include/functions.php';
25
require_once XOOPS_ROOT_PATH . '/class/xoopstree.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
26
require_once XOOPS_ROOT_PATH . '/include/xoopscodes.php';
27
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
28
require_once __DIR__ . '/../class/class.formimage.php';
29
require_once XOOPS_ROOT_PATH . '/class/module.errorhandler.php';
30
require_once __DIR__ . '/../class/class.efqtree.php';
31
$efqtree = new EfqTree($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat'), 'cid', 'pid');
32
$myts    = MyTextSanitizer::getInstance();
0 ignored issues
show
Bug introduced by
The type MyTextSanitizer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
$eh      = new ErrorHandler;
0 ignored issues
show
Bug introduced by
The type ErrorHandler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
$mytree  = new XoopsTree($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat'), 'cid', 'pid');
0 ignored issues
show
Bug introduced by
The type XoopsTree was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
$mytree2 = new XoopsTree($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_fieldtypes'), 'typeid', 0);
36
$efqtree = new EfqTree($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat'), 'cid', 'pid');
37
38
$moddir = $xoopsModule->getVar('dirname');
39
if (isset($_GET['dirid'])) {
40
    $get_dirid = (int)$_GET['dirid'];
41
} else {
42
    $get_dirid = 0;
43
}
44
if (isset($_GET['dtypeid'])) {
45
    $get_dtypeid = (int)$_GET['dtypeid'];
46
}
47
if (isset($_GET['catid'])) {
48
    $get_catid = (int)$_GET['catid'];
49
}
50
51
function catConfig($dirid = '0')
52
{
53
    global $xoopsDB, $xoopsModule, $xoopsUser, $mytree, $efqtree;
54
    if ($dirid == '0') {
55
        redirect_header('directories.php', 2, _MD_NOVALIDDIR);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        /** @scrutinizer ignore-call */ redirect_header('directories.php', 2, _MD_NOVALIDDIR);
Loading history...
56
        exit();
57
    }
58
    xoops_cp_header();
0 ignored issues
show
Bug introduced by
The function xoops_cp_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
    /** @scrutinizer ignore-call */ xoops_cp_header();
Loading history...
59
    //adminmenu(-1, _MD_MANAGE_CATS);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
    $dirname = getDirNameFromId($dirid);
61
    echo '<h4>' . _MD_CATCONF . '&nbsp;-&nbsp;' . $dirname . '</h4>';
62
    echo "<table width='100%' border='0' cellspacing='1' class='outer'>";
63
    //Get all main categories for this directory.
64
    $cats = getCatOverview();
65
    echo $cats;
66
    echo '</table>';
67
    echo '<br>';
68
    echo '<h4>' . _MD_CREATE_NEWCAT . '</h4>';
69
    echo "<table width='100%' border='0' cellspacing='1'><tr><td>";
70
    $form = new XoopsThemeForm(_MD_NEWCATFORM, 'submitform', 'categories.php');
0 ignored issues
show
Bug introduced by
The type XoopsThemeForm was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
71
    $form->setExtra('enctype="multipart/form-data"');
72
    $form->addElement(new XoopsFormText(_MD_CATTITLE, 'title', 50, 100, ''), true);
0 ignored issues
show
Bug introduced by
The type XoopsFormText was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
73
    $form_active = new XoopsFormCheckBox(_MD_ACTIVEYN, 'active', '');
0 ignored issues
show
Bug introduced by
The type XoopsFormCheckBox was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
74
    $form_active->addOption(1, _MD_YESNO);
75
    $form->addElement($form_active);
76
    $form_importdtypes = new XoopsFormCheckBox(_MD_IMPORT_DTYPES_YN, 'importdtypes', '');
77
    $form_importdtypes->addOption(1, _MD_YESNO);
78
    $form->addElement($form_importdtypes);
79
    $form_allowlist = new XoopsFormCheckBox(_MD_ALLOWLISTYN, 'allowlist', '');
80
    $form_allowlist->addOption(1, _MD_YESNO);
81
    $form->addElement($form_allowlist);
82
    $form_showpopular = new XoopsFormCheckBox(_MD_SHOWPOPULARYN, 'showpopular', '');
83
    $form_showpopular->addOption(1, _MD_YESNO);
84
    $form->addElement($form_showpopular);
85
    $form->addElement(new XoopsFormDhtmlTextArea(_MD_DESCRIPTION, 'descr', '', 5, 50));
0 ignored issues
show
Bug introduced by
The type XoopsFormDhtmlTextArea was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
86
    //Add parent category select box.
87
    ob_start();
88
    $efqtree->setDir($dirid);
89
    $pcat_selbox = $efqtree->makeMySelBox('title', 'title', '', 1, 'pid');
0 ignored issues
show
Unused Code introduced by
The assignment to $pcat_selbox is dead and can be removed.
Loading history...
90
    $selbox      = ob_get_contents();
91
    ob_end_clean();
92
    $pcat_tray = new XoopsFormElementTray(_MD_PARENTCAT, '<br>');
0 ignored issues
show
Bug introduced by
The type XoopsFormElementTray was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
93
    $pcat_tray->addElement(new XoopsFormLabel('', $selbox));
0 ignored issues
show
Bug introduced by
The type XoopsFormLabel was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
94
    $form->addElement($pcat_tray);
95
    $form->addElement(new XoopsFormFile(_MD_SELECT_PIC, 'img', 30000));
0 ignored issues
show
Bug introduced by
The type XoopsFormFile was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
96
    $form_txtactive = new XoopsFormCheckBox(_MD_CATTEXT_ACTIVE_YN, 'open', 0);
97
    $form_txtactive->addOption(1, _MD_YESNO);
98
    $form->addElement($form_txtactive);
99
    $form->addElement(new XoopsFormButton('', 'submit', _MD_SUBMIT, 'submit'));
0 ignored issues
show
Bug introduced by
The type XoopsFormButton was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
100
    $form->addElement(new XoopsFormHidden('op', 'newcat'));
0 ignored issues
show
Bug introduced by
The type XoopsFormHidden was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
101
    $form->addElement(new XoopsFormHidden('dirid', $dirid));
102
    $form->addElement(new XoopsFormHidden('uid', $xoopsUser->getVar('uid')));
103
    $form->display();
104
    echo '</td></tr></table>';
105
    xoops_cp_footer();
0 ignored issues
show
Bug introduced by
The function xoops_cp_footer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
    /** @scrutinizer ignore-call */ xoops_cp_footer();
Loading history...
106
}
107
108
function editCat($catid = '0')
109
{
110
    global $xoopsDB, $efqtree, $mytree, $mytree2, $xoopsUser, $get_catid, $eh, $myts;
111
    xoops_cp_header();
0 ignored issues
show
Bug introduced by
The function xoops_cp_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

111
    /** @scrutinizer ignore-call */ xoops_cp_header();
Loading history...
112
    $diridfromcatid = getDirId($get_catid);
113
    //adminmenu(-1, _MD_EDITCAT);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
114
    echo '<h4>' . _MD_EDITCAT . '</h4>';
115
    $pathstring = "<a href='categories.php?dirid=$diridfromcatid'>" . _MD_MAIN . '</a>&nbsp;:&nbsp;';
116
    $pathstring .= $efqtree->getNicePathFromId($get_catid, 'title', 'categories.php?op=edit');
117
    echo $pathstring . '<br><br>';
118
119
    $catchildren   = $mytree->getFirstChild($get_catid);
120
    $count_subcats = count($catchildren);
121
    if ($count_subcats != 0) {
122
        $subcategories = '';
123
        echo '<strong>' . _MD_SUBCATEGORIES . '</strong>:<br>';
124
        for ($i = 0; $i < $count_subcats; ++$i) {
125
            $subcategories .= "<a href='categories.php?op=edit&catid=" . $catchildren[$i]['cid'] . '\'>' . $catchildren[$i]['title'] . '</a>';
126
            if ($i + 1 != $count_subcats) {
127
                $subcategories .= ', ';
128
            }
129
        }
130
        echo $subcategories . '<br><br>';
131
    }
132
133
    echo "<table width='100%' border='0' cellspacing='1'><tr><td>";
134
    $result  = $xoopsDB->query('SELECT c.cid, c.dirid, c.title, c.active, c.pid, c.img, c.allowlist, c.showpopular, c.height, c.width, t.text FROM '
135
                               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat')
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
136
                               . ' c LEFT JOIN '
137
                               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n')
138
                                                  . '_cat_txt')
139
                               . " t  ON (c.cid=t.cid) WHERE c.cid='"
140
                               . $catid
141
                               . '\'');
142
    $numrows = $xoopsDB->getRowsNum($result);
143
    if ($numrows > 0) {
144
        while (list($cid, $dirid, $title, $active, $pid, $img, $allowlist, $showpopular, $imgheight, $imgwidth, $descr) = $xoopsDB->fetchRow($result)) {
145
            $title     = $myts->htmlSpecialChars($title);
146
            $parentcat = $pid;
147
            if ($img != '') {
148
                $picture = "../uploads/$img";
149
            } else {
150
                $picture = '../uploads/dummy.png';
151
            }
152
            $form = new XoopsThemeForm(_MD_EDITCATFORM, 'editform', 'categories.php');
153
            $form->setExtra('enctype="multipart/form-data"');
154
            $form->addElement(new XoopsFormText(_MD_CATTITLE, 'title', 50, 100, "$title"), true);
155
            $form_active = new XoopsFormCheckBox(_MD_ACTIVEYN, 'active', $active);
156
            $form_active->addOption(1, _MD_YESNO);
157
            $form->addElement($form_active);
158
            $form_allowlist = new XoopsFormCheckBox(_MD_ALLOWLISTYN, 'allowlist', $allowlist);
159
            $form_allowlist->addOption(1, _MD_YESNO);
160
            $form->addElement($form_allowlist);
161
            $form_showpopular = new XoopsFormCheckBox(_MD_SHOWPOPULARYN, 'showpopular', $showpopular);
162
            $form_showpopular->addOption(1, _MD_YESNO);
163
            $form->addElement($form_showpopular);
164
            //Add parent category select box.
165
            ob_start();
166
            $pcat_selbox = $mytree->makeMySelBox('title', 'title', $pid, 1, 'pid');
0 ignored issues
show
Unused Code introduced by
The assignment to $pcat_selbox is dead and can be removed.
Loading history...
167
            $selbox      = ob_get_contents();
168
            ob_end_clean();
169
            $pcat_tray = new XoopsFormElementTray(_MD_PARENTCAT, '<br>');
170
            $pcat_tray->addElement(new XoopsFormLabel('', $selbox));
171
            $form->addElement($pcat_tray);
172
173
            $form->addElement(new XoopsFormDhtmlTextArea(_MD_DESCRIPTION, 'descr', "$descr", 5, 50));
174
            $form->addElement(new XoopsFormFile(_MD_SELECT_PIC, 'img', 30000));
175
            $form->addElement(new XoopsFormImage(_MD_CURRENT_PIC, 'current_image', null, "$picture", $imgheight, $imgwidth));
176
            $form->addElement(new XoopsFormButton('', 'submit', _MD_UPDATE, 'submit'));
177
            $form->addElement(new XoopsFormHidden('op', 'update'));
178
            $form->addElement(new XoopsFormHidden('catid', $cid));
179
            $form->addElement(new XoopsFormHidden('uid', $xoopsUser->getVar('uid')));
180
            $form->display();
181
        }
182
    }
183
    echo '</td></tr></table>';
184
    $dellink = "<align=\"right\"><a href=\"categories.php?op=deleteCatConfirm&catid=$get_catid\"><img src=\"" . XOOPS_URL . '/images/drop.png">' . _MD_DELETE_CAT . '</a></align>';
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
185
    echo $dellink;
186
    echo '<h4>' . _MD_EDITDTYPES . '</h4>';
187
    echo "<table width='100%' border='0' cellspacing='1'><tr><td>";
188
    echo '<form name="editdtypes" id="editdtypes" action="categories.php" method="post">';
189
    echo '<table width="100%" class="outer" cellspacing="1">';
190
    $result  = $xoopsDB->query('SELECT d.dtypeid, x.cid, d.title, d.section, d.seq, d.icon, f.title, f.typeid, d.defaultyn, d.activeyn, d.options, d.custom FROM '
191
                               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes')
192
                               . ' d, '
193
                               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n')
194
                                                  . '_fieldtypes')
195
                               . ' f, '
196
                               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes_x_cat')
197
                               . " x WHERE d.fieldtypeid=f.typeid AND d.dtypeid=x.dtypeid AND x.cid='"
198
                               . $catid
199
                               . '\' ORDER BY d.section ASC, d.seq ASC')
200
               || $eh->show('0013');
201
    $numrows = $xoopsDB->getRowsNum($result);
202
    echo '<tr><th>' . _MD_DTYPE_ICON . '</th><th>' . _MD_DTYPE_TITLE . '</th><th>' . _MD_FTYPE_NAME . '</th><th>' . _MD_OPTIONS . '</th><th>' . _MD_CUSTOM . '</th><th>' . _MD_ACTIVE . '</th><th>' . _MD_DEFAULT . '</th><th>' . _MD_DTYPE_SEQ . '</th><th>' . _MD_SECTION . '</th></tr>';
203
    if ($numrows > 0) {
204
        $dtypes = '';
205
        $count  = 1;
206
        while (list($dtypeid, $cid, $dtypetitle, $section, $dseq, $picture, $ftypename, $ftypeid, $defaultyn, $activeyn, $options, $dcustom) = $xoopsDB->fetchRow($result)) {
207 View Code Duplication
            if ($defaultyn == '1') {
0 ignored issues
show
Duplication introduced by
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...
208
                $default = _MD_YES;
0 ignored issues
show
Unused Code introduced by
The assignment to $default is dead and can be removed.
Loading history...
209
                $checked = ' checked';
210
            } else {
211
                $default = _MD_NO;
212
                $checked = '';
213
            }
214 View Code Duplication
            if ($activeyn == '1') {
0 ignored issues
show
Duplication introduced by
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...
215
                $default       = _MD_YES;
216
                $activechecked = ' checked';
217
            } else {
218
                $default       = _MD_NO;
219
                $activechecked = '';
220
            }
221
            if ($picture != '') {
222
                $iconurl = "../uploads/$picture";
223
            } else {
224
                $iconurl = '';
225
            }
226
            if ($dcustom == '1') {
227
                $custom = _MD_YES;
228
            } else {
229
                $custom = _MD_NO;
230
            }
231
            //Get the existing fields for this category.
232
            ob_start();
233
            $mytree2->makeMySelBox('title', 'title', $ftypeid, 1, 'fieldtype' . $dtypeid . '');
234
            $ftypebox = ob_get_contents();
0 ignored issues
show
Unused Code introduced by
The assignment to $ftypebox is dead and can be removed.
Loading history...
235
            ob_end_clean();
236
237
            if ($count != 1) {
238
                $dtypes .= '|' . $dtypeid;
239
            } else {
240
                $dtypes = $dtypeid;
241
            }
242
            ++$count;
243
            echo "<tr><td class=\"even\"><img src=\"$iconurl\"></td><td class=\"even\"><a href=\"categories.php?op=editdtype&dtypeid=$dtypeid&amp;catid=$get_catid\">$dtypetitle</a></td><td class=\"even\">"
244
                 . $ftypename
245
                 . "</td><td class=\"even\">$options</td><td class=\"even\">$custom</td><td class=\"even\"><input type=\"checkbox\" name=\"activeyn"
246
                 . $dtypeid
247
                 . "\"$activechecked></input></td><td class=\"even\"><input type=\"checkbox\" name=\"defaultyn"
248
                 . $dtypeid
249
                 . "\"$checked></input></td><td class=\"even\"><input type=\"text\" size=\"5\" maxsize=\"10\" name=\"seq"
250
                 . $dtypeid
251
                 . '" value="'
252
                 . $dseq
253
                 . '"></input></td><td class="even"><input type="text" size="5" maxsize="10" name="section'
254
                 . $dtypeid
255
                 . '" value="'
256
                 . $section
257
                 . '"></input></td></tr>';
258
        }
259
        echo '<tr><td class="even">&nbsp;</td><td class="even" colspan="8"><input type="hidden" name="op" value="editdtypes"><input type="hidden" name="catid" value="'
260
             . $get_catid
261
             . '"><input type="hidden" name="dtypes" value="'
262
             . $dtypes
263
             . '"><input type="submit" class="formButton" name="submit"  id="submit" value="'
264
             . _MD_UPDATE
265
             . '" ></td></tr>';
266
    } else {
267
        echo '<tr><td colspan="7">' . _MD_NORECORDS . '&nbsp;';
268
        if ($parentcat != '0') {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $parentcat does not seem to be defined for all execution paths leading up to this point.
Loading history...
269
            echo '<input type="hidden" name="op" value="importdtypes"><input type="hidden" name="catid" value="'
270
                 . $get_catid
271
                 . '"><input type="hidden" name="pid" value="'
272
                 . $parentcat
273
                 . '"><input type="submit" class="formButton" name="submit"  id="submit" value="'
274
                 . _MD_IMPORT_DTYPES_FROM_PARENTCAT
275
                 . '" >';
276
        }
277
        echo '</td></tr>';
278
    }
279
    echo '</table></form></td></tr></table>';
280
    echo '<h4>' . _MD_ADDDTYPE . '</h4>';
281
    echo "<table width='100%' border='0' cellspacing='1'><tr><td>";
282
283
    $form = new XoopsThemeForm(_MD_ADD_DTYPE_FORM, 'newdatatypeform', 'categories.php');
284
    $form->setExtra('enctype="multipart/form-data"');
285
    $form->addElement(new XoopsFormText(_MD_DTYPE_TITLE, 'title', 50, 100, ''), true);
286
    $form->addElement(new XoopsFormFile(_MD_SELECT_ICON, 'image', 30000));
287
    $fieldtype_tray = new XoopsFormElementTray(_MD_FTYPE_NAME, '', 'typeid');
288
    ob_start();
289
    $mytree2->makeMySelBox('title', 'title', 0, 1);
290
    $selbox = ob_get_contents();
291
    ob_end_clean();
292
    $options_tray     = new XoopsFormElementTray(_MD_OPTIONS, '');
293
    $options_text     = new XoopsFormLabel('', '<br>' . _MD_OPTIONS_EXPL);
294
    $options_textarea = new XoopsFormTextArea('', 'options', '', 6, 50);
0 ignored issues
show
Bug introduced by
The type XoopsFormTextArea was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
295
    $options_tray->addElement($options_textarea);
296
    $options_tray->addElement($options_text);
297
    $fieldtype_tray->addElement(new XoopsFormLabel('', $selbox . ' <a href="fieldtypes.php">' . _MD_EDIT . ''));
298
    $form->addElement($fieldtype_tray, true);
299
    $form->addElement($options_tray);
300
    $form_active = new XoopsFormCheckBox(_MD_DTYPE_ACTIVEYN, 'activeyn', 0);
301
    $form_active->addOption(1, _MD_YESNO);
302
    $form->addElement($form_active);
303
    $form_default = new XoopsFormCheckBox(_MD_DTYPE_DEFAULTYN, 'defaultyn', 0);
304
    $form_default->addOption(1, _MD_YESNO);
305
    $form->addElement($form_default);
306
    $form->addElement(new XoopsFormText(_MD_DTYPE_SEQ, 'seq', 5, 10, 0), true);
307
    $form->addElement(new XoopsFormText(_MD_SECTION, 'section', 5, 10, 0), true);
308
    //$form_custom = new XoopsFormCheckBox(_MD_DTYPE_CUSTOM, "custom", "");
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
309
    //$form_custom->addOption(1, _MD_YESNO);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
310
    //$form->addElement($form_custom);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
311
    $form->addElement(new XoopsFormButton('', 'submit', _MD_SUBMIT, 'submit'));
312
    $form->addElement(new XoopsFormHidden('op', 'newdatatype'));
313
    $form->addElement(new XoopsFormHidden('catid', $get_catid));
314
    $form->addElement(new XoopsFormHidden('uid', $xoopsUser->getVar('uid')));
315
    $form->display();
316
    echo '</td></tr></table>';
317
    echo '<br>';
318
    echo '<h4>' . _MD_CREATE_NEWSUBCAT . '</h4>';
319
    echo "<table width='100%' border='0' cellspacing='1'><tr><td>";
320
    $form = new XoopsThemeForm(_MD_NEWCATFORM, 'submitform', 'categories.php');
321
    $form->setExtra('enctype="multipart/form-data"');
322
    $form->addElement(new XoopsFormText(_MD_CATTITLE, 'title', 50, 100, "$title"), true);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $title does not seem to be defined for all execution paths leading up to this point.
Loading history...
323
    $form_active = new XoopsFormCheckBox(_MD_ACTIVEYN, 'active', '');
324
    $form_active->addOption(1, _MD_YESNO);
325
    $form->addElement($form_active);
326
    $form_importdtypes = new XoopsFormCheckBox(_MD_IMPORT_DTYPES_YN, 'importdtypes', 1);
327
    $form_importdtypes->addOption(1, _MD_YESNO);
328
    $form->addElement($form_importdtypes);
329
    $form_allowlist = new XoopsFormCheckBox(_MD_ALLOWLISTYN, 'allowlist', '');
330
    $form_allowlist->addOption(1, _MD_YESNO);
331
    $form->addElement($form_allowlist);
332
    $form_showpopular = new XoopsFormCheckBox(_MD_SHOWPOPULARYN, 'showpopular', '');
333
    $form_showpopular->addOption(1, _MD_YESNO);
334
    $form->addElement($form_showpopular);
335
    $form->addElement(new XoopsFormDhtmlTextArea(_MD_DESCRIPTION, 'descr', '', 5, 50));
336
    ob_start();
337
    $pcat_selbox = $mytree->makeMySelBox('title', 'title', "$get_catid", 0, 'pid');
338
    $selbox      = ob_get_contents();
339
    ob_end_clean();
340
    $pcat_tray = new XoopsFormElementTray(_MD_PARENTCAT, '<br>');
341
    $pcat_tray->addElement(new XoopsFormLabel('', $selbox));
342
    $form->addElement($pcat_tray);
343
    $form->addElement(new XoopsFormFile(_MD_SELECT_PIC, 'img', 30000));
344
    $form_txtactive = new XoopsFormCheckBox(_MD_CATTEXT_ACTIVE_YN, 'open', 0);
345
    $form_txtactive->addOption(1, _MD_YESNO);
346
    $form->addElement($form_txtactive);
347
    $form->addElement(new XoopsFormButton('', 'submit', _MD_SUBMIT, 'submit'));
348
    $form->addElement(new XoopsFormHidden('op', 'newcat'));
349
    $form->addElement(new XoopsFormHidden('dirid', $diridfromcatid));
350
    $form->addElement(new XoopsFormHidden('uid', $xoopsUser->getVar('uid')));
351
    $form->display();
352
    echo '</td></tr></table>';
353
    xoops_cp_footer();
0 ignored issues
show
Bug introduced by
The function xoops_cp_footer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

353
    /** @scrutinizer ignore-call */ xoops_cp_footer();
Loading history...
354
}
355
356
function editDatatype($dtypeid = '0')
357
{
358
    global $xoopsDB, $mytree, $mytree2, $xoopsUser, $get_catid, $eh;
359
    xoops_cp_header();
0 ignored issues
show
Bug introduced by
The function xoops_cp_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

359
    /** @scrutinizer ignore-call */ xoops_cp_header();
Loading history...
360
    //adminmenu(-1, _MD_EDITCAT);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
361
    echo '<h4>' . _MD_EDITDTYPE . '</h4>';
362
    echo "<table width='100%' border='0' cellspacing='1' class='outer'><tr><td>";
363
364
    $result  = $xoopsDB->query('SELECT d.dtypeid, d.title, d.section, d.seq, d.icon, f.title, f.typeid, d.defaultyn, d.activeyn, d.options, d.custom FROM '
365
                               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes')
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
366
                               . ' d, '
367
                               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n')
368
                                                  . '_fieldtypes')
369
                               . " f WHERE d.fieldtypeid=f.typeid AND d.dtypeid='"
370
                               . $dtypeid
371
                               . '\' ORDER BY d.seq ASC')
372
               || $eh->show('0013');
373
    $numrows = $xoopsDB->getRowsNum($result);
374
    if ($numrows > 0) {
375
        while (list($dtypeid, $dtypetitle, $section, $dseq, $picture, $ftypename, $ftypeid, $defaultyn, $activeyn, $options, $dcustom) = $xoopsDB->fetchRow($result)) {
376 View Code Duplication
            if ($defaultyn == '1') {
0 ignored issues
show
Duplication introduced by
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...
377
                $default = _MD_YES;
0 ignored issues
show
Unused Code introduced by
The assignment to $default is dead and can be removed.
Loading history...
378
                $checked = ' checked';
379
            } else {
380
                $default = _MD_NO;
381
                $checked = '';
382
            }
383 View Code Duplication
            if ($activeyn == '1') {
0 ignored issues
show
Duplication introduced by
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...
384
                $default       = _MD_YES;
385
                $activechecked = ' checked';
386
            } else {
387
                $default       = _MD_NO;
388
                $activechecked = '';
389
            }
390
            if ($picture != '') {
391
                $iconurl = "../uploads/$picture";
392
            } else {
393
                $iconurl = '';
394
            }
395
            if ($dcustom == '1') {
396
                $custom = '1';
397
            } else {
398
                $custom = '0';
399
            }
400
            ob_start();
401
            $mytree2->makeMySelBox('title', 'title', $ftypeid, 1, 'fieldtype' . $dtypeid . '');
402
            $ftypebox = ob_get_contents();
0 ignored issues
show
Unused Code introduced by
The assignment to $ftypebox is dead and can be removed.
Loading history...
403
            ob_end_clean();
404
405
            $form = new XoopsThemeForm(_MD_EDIT_DTYPE_FORM, 'editdatatypeform', 'categories.php');
406
            $form->setExtra('enctype="multipart/form-data"');
407
            //$form_custom = new XoopsFormCheckBox(_MD_DTYPE_CUSTOM, "custom", $custom);
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
408
            //$form_custom->addOption(1, _MD_YESNO);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
409
            //$form->addElement($form_custom);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
410
            $form->addElement(new XoopsFormText(_MD_DTYPE_TITLE, 'title', 50, 100, $dtypetitle), true);
411
            $form->addElement(new XoopsFormFile(_MD_SELECT_ICON, 'image', 30000));
412
            $form->addElement(new XoopsFormImage(_MD_CURRENT_ICON, 'current_image', null, $iconurl, '', ''));
413
            $fieldtype_tray = new XoopsFormElementTray(_MD_FTYPE_NAME, '', 'typeid');
414
            ob_start();
415
            $mytree2->makeMySelBox('title', 'title', $ftypeid, 1);
416
            $selbox = ob_get_contents();
417
            ob_end_clean();
418
            $options_tray     = new XoopsFormElementTray(_MD_OPTIONS, '');
419
            $options_text     = new XoopsFormLabel('', '<br>' . _MD_OPTIONS_EXPL);
420
            $options_textarea = new XoopsFormTextArea('', 'options', $options, 6, 5);
421
            $options_tray->addElement($options_textarea);
422
            $options_tray->addElement($options_text);
423
            $fieldtype_tray->addElement(new XoopsFormLabel('', $selbox . ' <a href="fieldtypes.php">' . _MD_EDIT . ''));
424
            $form->addElement($fieldtype_tray, true);
425
            $form->addElement($options_tray);
426
            $form_active = new XoopsFormCheckBox(_MD_DTYPE_ACTIVEYN, 'activeyn', $activeyn);
427
            $form_active->addOption(1, _MD_YESNO);
428
            $form->addElement($form_active);
429
            $form_default = new XoopsFormCheckBox(_MD_DTYPE_DEFAULTYN, 'defaultyn', $defaultyn);
430
            $form_default->addOption(1, _MD_YESNO);
431
            $form->addElement($form_default);
432
            $form->addElement(new XoopsFormText(_MD_DTYPE_SEQ, 'seq', 5, 10, $dseq), true);
433
            $form->addElement(new XoopsFormText(_MD_SECTION, 'section', 5, 10, $section), true);
434
            $form->addElement(new XoopsFormButton('', 'submit', _MD_SUBMIT, 'submit'));
435
            $form->addElement(new XoopsFormHidden('op', 'savedtype'));
436
            $form->addElement(new XoopsFormHidden('catid', $get_catid));
437
            $form->addElement(new XoopsFormHidden('dtypeid', $dtypeid));
438
            $form->addElement(new XoopsFormHidden('uid', $xoopsUser->getVar('uid')));
439
            $form->display();
440
        }
441
    } else {
442
        echo '<table><tr><td colspan="7">' . _MD_NORECORDS . '&nbsp;';
443
        //  if ($parentcat != '0') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
444
        //   echo "<input type=\"hidden\" name=\"op\" value=\"importdtypes\"><input type=\"hidden\" name=\"catid\" value=\"".$get_catid."\"><input type=\"hidden\" name=\"pid\" value=\"".$parentcat."\"><input type=\"submit\" class=\"formButton\" name=\"submit\"  id=\"submit\" value=\""._MD_IMPORT_DTYPES_FROM_PARENTCAT."\" >";
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
445
        //  }
446
        echo '</td></tr></table>';
447
    }
448
    echo '</td></tr></table>';
449
    xoops_cp_footer();
0 ignored issues
show
Bug introduced by
The function xoops_cp_footer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

449
    /** @scrutinizer ignore-call */ xoops_cp_footer();
Loading history...
450
}
451
452
function saveDatatype()
453
{
454
    global $xoopsDB, $_POST, $myts, $eh, $moddir, $xoopsUser;
455
    $count     = 1;
0 ignored issues
show
Unused Code introduced by
The assignment to $count is dead and can be removed.
Loading history...
456
    $return    = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $return is dead and can be removed.
Loading history...
457
    $p_dtypeid = $_POST['dtypeid'];
458
    $p_catid   = $_POST['catid'];
459
    if (isset($_POST['title'])) {
460
        if (isset($_POST['custom'])) {
461
            $p_custom = $_POST['custom'];
462
        } else {
463
            $p_custom = '0';
464
        }
465
        $p_title     = $myts->makeTboxData4Save($_POST['title']);
466
        $p_fieldtype = $_POST['typeid'];
0 ignored issues
show
Unused Code introduced by
The assignment to $p_fieldtype is dead and can be removed.
Loading history...
467
        $p_section   = $myts->makeTboxData4Save($_POST['section']);
468
        if (isset($_POST['defaultyn'])) {
469
            $p_default = $_POST['defaultyn'];
470
        } else {
471
            $p_default = '0';
472
        }
473
        if (isset($_POST['activeyn'])) {
474
            $p_active = $_POST['activeyn'];
475
        } else {
476
            $p_active = '0';
477
        }
478 View Code Duplication
        if (isset($_POST['options'])) {
0 ignored issues
show
Duplication introduced by
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...
479
            $p_options = $myts->makeTareaData4Save($_POST['options']);
480
        } else {
481
            $p_options = '';
482
        }
483
        $p_fieldtype = $_POST['typeid'];
484
        $p_seq       = $myts->makeTboxData4Save($_POST['seq']);
485
486
        require_once XOOPS_ROOT_PATH . '/class/class.uploader.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
487
        $uploader = new XoopsMediaUploader(XOOPS_ROOT_PATH . "/modules/$moddir/init_uploads", array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/jpg'), 30000, 50, 50);
488
        $uploader->setPrefix('icon');
489
        $err    = array();
490
        $ucount = count($_POST['xoops_upload_file']);
491
        if ($ucount != 0) {
492
            for ($i = 0; $i < $ucount; ++$i) {
493
                if ($_POST['xoops_upload_file'][$i] != '') {
494
                    $medianame = $_POST['xoops_upload_file'][$i];
0 ignored issues
show
Unused Code introduced by
The assignment to $medianame is dead and can be removed.
Loading history...
495
                    if ($uploader->fetchMedia($_POST['xoops_upload_file'][$i])) {
496
                        if (!$uploader->upload()) {
497
                            $err[] = $uploader->getErrors();
498
                        } else {
499
                            $savedfilename = $uploader->getSavedFileName();
500
                            $ticket        = uniqid(mt_rand(), 1);
0 ignored issues
show
Unused Code introduced by
The assignment to $ticket is dead and can be removed.
Loading history...
501
                            //Rename the uploaded file to the same name in a different location that does not have 777 rights or 755.
502
                            rename('' . XOOPS_ROOT_PATH . '/modules/' . $moddir . '/init_uploads/' . $savedfilename . '', '' . XOOPS_ROOT_PATH . '/modules/' . $moddir . '/uploads/' . $savedfilename . '');
503
                            //Delete the uploaded file from the initial upload folder if it is still present in that folder.
504
                            if (file_exists('' . XOOPS_ROOT_PATH . '/modules/' . $moddir . '/init_uploads/' . $savedfilename . '')) {
505
                                unlink('' . XOOPS_ROOT_PATH . '/modules/' . $moddir . '/init_uploads/' . $savedfilename . '');
506
                            }
507
                            $sql = 'UPDATE '
508
                                   . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes')
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
509
                                   . " SET title = '$p_title', section = '$p_section', fieldtypeid = '$p_fieldtype', defaultyn = '$p_default', activeyn='$p_active', seq='$p_seq', options='$p_options', custom='$p_custom', icon='$savedfilename' WHERE dtypeid = $p_dtypeid";
510
                            $xoopsDB->query($sql) or $eh->show('0013');
511
                        }
512 View Code Duplication
                    } else {
0 ignored issues
show
Duplication introduced by
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...
513
                        $sql = 'UPDATE '
514
                               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes')
515
                               . " SET title = '$p_title', section = '$p_section', fieldtypeid = '$p_fieldtype', defaultyn = '$p_default', activeyn='$p_active', seq='$p_seq', options='$p_options', custom='$p_custom' WHERE dtypeid = $p_dtypeid";
516
                        $xoopsDB->query($sql) or $eh->show('0013');
517
                    }
518 View Code Duplication
                } else {
0 ignored issues
show
Duplication introduced by
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...
519
                    $sql = 'UPDATE '
520
                           . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes')
521
                           . " SET title = '$p_title', section = '$p_section', fieldtypeid = '$p_fieldtype', defaultyn = '$p_default', activeyn='$p_active', seq='$p_seq', options='$p_options', custom='$p_custom' WHERE dtypeid = $p_dtypeid";
522
                    $xoopsDB->query($sql) or $eh->show('0013');
523
                }
524
            }
525 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
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...
526
            $sql = 'UPDATE '
527
                   . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes')
528
                   . " SET title = '$p_title', section = '$p_section', fieldtypeid = '$p_fieldtype', defaultyn = '$p_default', activeyn='$p_active', seq='$p_seq', options='$p_options', custom='$p_custom' WHERE dtypeid = $p_dtypeid";
529
            $xoopsDB->query($sql) or $eh->show('0013');
530
        }
531
    }
532
    redirect_header("categories.php?op=edit&catid=$p_catid", 2, _MD_DTYPE_UPDATED);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

532
    /** @scrutinizer ignore-call */ redirect_header("categories.php?op=edit&catid=$p_catid", 2, _MD_DTYPE_UPDATED);
Loading history...
533
    exit();
534
}
535
536
function addDatatype()
537
{
538
    global $xoopsDB, $_POST, $myts, $eh, $xoopsUser, $moddir;
539
    if (isset($_POST['catid'])) {
540
        $p_catid = $_POST['catid'];
541
    } else {
542
        exit();
543
    }
544
    $p_title = $myts->makeTboxData4Save($_POST['title']);
545
    if (isset($_POST['defaultyn'])) {
546
        $p_default = $_POST['defaultyn'];
547
    } else {
548
        $p_default = '0';
549
    }
550
    if (isset($_POST['activeyn'])) {
551
        $p_active = $_POST['activeyn'];
552
    } else {
553
        $p_active = '0';
554
    }
555
    if (isset($_POST['custom'])) {
556
        $p_custom = $_POST['custom'];
557
    } else {
558
        $p_custom = '0';
559
    }
560 View Code Duplication
    if (isset($_POST['options'])) {
0 ignored issues
show
Duplication introduced by
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...
561
        $p_options = $myts->makeTareaData4Save($_POST['options']);
562
    } else {
563
        $p_options = '';
564
    }
565
    $p_fieldtype = (int)$_POST['typeid'];
566
    if ($p_fieldtype == '') {
567
        redirect_header("categories.php?op=edit&catid=$p_catid", 2, _MD_NOFIELDTYPE_SELECTED);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

567
        /** @scrutinizer ignore-call */ redirect_header("categories.php?op=edit&catid=$p_catid", 2, _MD_NOFIELDTYPE_SELECTED);
Loading history...
568
        exit();
569
    }
570
    $p_section = $myts->makeTboxData4Save($_POST['section']);
571
    $uid       = $xoopsUser->getVar('uid');
572
573
    require_once XOOPS_ROOT_PATH . '/class/class.uploader.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
574
    //$uploader = new XoopsMediaUploader(XOOPS_ROOT_PATH.'/modules/'.$moddir.'/init_uploads', array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/jpg'), 30000, 50, 50);
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
575
    $uploader = new XoopsMediaUploader(XOOPS_ROOT_PATH . "/modules/$moddir/init_uploads", array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/jpg'), 30000, 50, 50);
576
    $uploader->setPrefix('icon');
577
    $err           = array();
578
    $ucount        = count($_POST['xoops_upload_file']);
579
    $savedfilename = '';
580
    for ($i = 0; $i < $ucount; ++$i) {
581
        if ($_POST['xoops_upload_file'][$i] != '') {
582
            $medianame = $_POST['xoops_upload_file'][$i];
0 ignored issues
show
Unused Code introduced by
The assignment to $medianame is dead and can be removed.
Loading history...
583
            if ($uploader->fetchMedia($_POST['xoops_upload_file'][$i])) {
584 View Code Duplication
                if (!$uploader->upload()) {
0 ignored issues
show
Duplication introduced by
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...
585
                    $err[] = $uploader->getErrors();
586
                } else {
587
                    $savedfilename = $uploader->getSavedFileName();
588
                    $ticket        = uniqid(mt_rand(), 1);
0 ignored issues
show
Unused Code introduced by
The assignment to $ticket is dead and can be removed.
Loading history...
589
                    //Rename the uploaded file to the same name in a different location that does not have 777 rights or 755.
590
                    rename('' . XOOPS_ROOT_PATH . '/modules/' . $moddir . '/init_uploads/' . $savedfilename . '', '' . XOOPS_ROOT_PATH . '/modules/' . $moddir . '/uploads/' . $savedfilename . '');
591
                    //Delete the uploaded file from the initial upload folder if it is still present in that folder.
592
                    if (file_exists('' . XOOPS_ROOT_PATH . '/modules/' . $moddir . '/init_uploads/' . $savedfilename . '')) {
593
                        unlink('' . XOOPS_ROOT_PATH . '/modules/' . $moddir . '/init_uploads/' . $savedfilename . '');
594
                    }
595
                }
596
            }
597
        }
598
    }
599
    $newid = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes') . '_dtypeid_seq');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
600
    $sql   = sprintf("INSERT INTO %s (dtypeid, title, section, fieldtypeid, uid, defaultyn, created, seq, activeyn, OPTIONS, custom, icon) VALUES (%u, '%s', %u, %u, %u, %u, '%s', '%s', %u, '%s', %u, '%s')", $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes'), $newid, $p_title,
601
                     $p_section, $p_fieldtype, $uid, $p_default, time(), 0, $p_active, $p_options, $p_custom, $savedfilename);
602
    $xoopsDB->query($sql) or $eh->show('0013');
603
    $dtypeid = $xoopsDB->getInsertId();
604
    $newid   = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes_x_cat') . '_xid_seq');
605
    $sql     = sprintf('INSERT INTO %s (xid, cid, dtypeid) VALUES (%u, %u, %u)', $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes_x_cat'), $newid, $p_catid, $dtypeid);
606
    $xoopsDB->query($sql) or $eh->show('0013');
607
    redirect_header("categories.php?op=edit&catid=$p_catid", 2, _MD_CAT_UPDATED);
608
    exit();
609
}
610
611
function editDatatypes()
612
{
613
    global $xoopsDB, $_POST, $myts, $eh, $moddir, $xoopsUser;
614
    $count      = 1;
0 ignored issues
show
Unused Code introduced by
The assignment to $count is dead and can be removed.
Loading history...
615
    $return     = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $return is dead and can be removed.
Loading history...
616
    $dtypes     = $_POST['dtypes'];
617
    $p_catid    = $_POST['catid'];
618
    $dtypes_arr = explode('[|]', $dtypes);
619
    foreach ($dtypes_arr as $dtype) {
620
        $p_section = $myts->makeTboxData4Save($_POST['section' . $dtype . '']);
621
        if (isset($_POST['defaultyn' . $dtype . ''])) {
622
            $p_defaultyn = '1';
623
        } else {
624
            $p_defaultyn = '0';
625
        }
626
        $p_seq = $myts->makeTboxData4Save($_POST['seq' . $dtype . '']);
627
        if (isset($_POST['activeyn' . $dtype . ''])) {
628
            $p_activeyn = '1';
629
        } else {
630
            $p_activeyn = '0';
631
        }
632
        $sql = 'UPDATE ' . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes') . " SET section = '$p_section', defaultyn = '$p_defaultyn', activeyn='$p_activeyn', seq='$p_seq' WHERE dtypeid = $dtype";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
633
        $xoopsDB->query($sql) or $eh->show('0013');
634
    }
635
    redirect_header("categories.php?op=edit&catid=$p_catid", 2, _MD_CAT_UPDATED);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

635
    /** @scrutinizer ignore-call */ redirect_header("categories.php?op=edit&catid=$p_catid", 2, _MD_CAT_UPDATED);
Loading history...
636
    exit();
637
}
638
639
function importDatatypes()
640
{
641
    global $xoopsDB, $_POST, $myts, $eh, $moddir, $xoopsUser;
642
    if (isset($_POST['pid'])) {
643
        $p_pid = $_POST['pid'];
644
    } else {
645
        exit();
646
    }
647
    if (isset($_POST['catid'])) {
648
        $p_catid = $_POST['catid'];
649
    } else {
650
        exit();
651
    }
652 View Code Duplication
    if ($p_pid != 0) {
0 ignored issues
show
Duplication introduced by
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...
653
        $sql = 'INSERT INTO '
654
               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes_x_cat')
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
655
               . ' (cid, dtypeid) SELECT '
656
               . $p_catid
657
               . ', d.dtypeid FROM '
658
               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes')
659
               . ' d, '
660
               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n')
661
                                  . '_dtypes_x_cat')
662
               . ' x  WHERE d.dtypeid=x.dtypeid AND x.cid = '
663
               . $p_pid
664
               . " AND d.defaultyn = '1'";
665
    }
666
    $xoopsDB->query($sql) or $eh->show('0013');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $sql does not seem to be defined for all execution paths leading up to this point.
Loading history...
667
    redirect_header("categories.php?op=edit&catid=$p_catid", 2, _MD_CAT_UPDATED);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

667
    /** @scrutinizer ignore-call */ redirect_header("categories.php?op=edit&catid=$p_catid", 2, _MD_CAT_UPDATED);
Loading history...
668
    exit();
669
}
670
671
function updateCat()
672
{
673
    global $xoopsDB, $_POST, $myts, $eh, $moddir;
674
    if (isset($_POST['catid'])) {
675
        $p_catid = $_POST['catid'];
676
    } else {
677
        exit();
678
    }
679
    $descr_exists = checkDescription($p_catid);
680
681
    if (isset($_POST['pid'])) {
682
        $p_pid = $_POST['pid'];
683
    } else {
684
        $p_pid = '0';
685
    }
686
    $p_title = $myts->makeTboxData4Save($_POST['title']);
687
    if (isset($_POST['active'])) {
688
        $p_active = $_POST['active'];
689
    } else {
690
        $p_active = 0;
691
    }
692
    if (isset($_POST['allowlist'])) {
693
        $p_allowlist = $_POST['allowlist'];
694
    } else {
695
        $p_allowlist = 0;
696
    }
697
    if (isset($_POST['showpopular'])) {
698
        $p_showpopular = $_POST['showpopular'];
699
    } else {
700
        $p_showpopular = 0;
701
    }
702 View Code Duplication
    if (isset($_POST['descr'])) {
0 ignored issues
show
Duplication introduced by
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...
703
        $p_descr = $myts->makeTareaData4Save($_POST['descr']);
704
    } else {
705
        $p_descr = false;
706
    }
707
    if ($_POST['xoops_upload_file'][0] != '') {
708
        require_once XOOPS_ROOT_PATH . "/modules/$moddir/class/class.uploader.php";
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
709
        $uploader = new XoopsMediaUploader(XOOPS_ROOT_PATH . "/modules/$moddir/init_uploads", array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/jpg'), 30000, 250, 250);
710
        if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
711
            $filename = $uploader->getMediaName();
0 ignored issues
show
Unused Code introduced by
The assignment to $filename is dead and can be removed.
Loading history...
712 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
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...
713
            $sql = 'UPDATE ' . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat') . " SET title = '$p_title', active='$p_active', pid='$p_pid', allowlist='$p_allowlist', showpopular='$p_showpopular' WHERE cid = $p_catid";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
714
            $xoopsDB->query($sql) or $eh->show('0013');
715
716
            if ($p_descr) {
717
                if ($descr_exists === true) {
718
                    $sql2 = 'UPDATE ' . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat_txt') . " SET text='$p_descr' WHERE cid = $p_catid";
719
                } else {
720
                    $newid = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat_txt') . '_txtid_seq');
721
                    $sql2  = sprintf("INSERT INTO %s (txtid, cid, TEXT, active, created) VALUES (%u, %u, '%s', %u, '%s')", $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat_txt'), $newid, $p_catid, $p_descr, '1', time());
722
                }
723
                $xoopsDB->query($sql2) or $eh->show('0013');
724
            }
725
            redirect_header("categories.php?op=edit&catid=$p_catid", 2, _MD_CAT_UPDATED);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

725
            /** @scrutinizer ignore-call */ redirect_header("categories.php?op=edit&catid=$p_catid", 2, _MD_CAT_UPDATED);
Loading history...
726
            exit();
727
        }
728
        $uploader->setPrefix('efqdir');
729
        if ($uploader->upload()) {
730
            $savedfilename = $uploader->getSavedFileName();
731
            $width         = $uploader->getWidth();
732
            $height        = $uploader->getHeight();
733
            $imagelocation = $uploader->uploadDir;
0 ignored issues
show
Unused Code introduced by
The assignment to $imagelocation is dead and can be removed.
Loading history...
734
            echo $uploader->getErrors();
735
736
            $sql = 'UPDATE ' . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat') . " SET img = '$savedfilename', width = '$width', height = '$height' WHERE cid = $p_catid";
737
            $xoopsDB->query($sql) or $eh->show('0013');
738
            rename('' . XOOPS_ROOT_PATH . "/modules/$moddir/init_uploads/" . $savedfilename . '', '' . XOOPS_ROOT_PATH . "/modules/$moddir/uploads/" . $savedfilename . '');
739
            //Delete the uploaded file from the initial upload folder if it is still present in that folder.
740 View Code Duplication
            if (file_exists('' . XOOPS_ROOT_PATH . "/modules/$moddir/init_uploads/" . $savedfilename . '')) {
0 ignored issues
show
Duplication introduced by
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...
741
                unlink('' . XOOPS_ROOT_PATH . "/modules/$moddir/init_uploads/" . $savedfilename . '');
742
            }
743
            redirect_header("categories.php?op=edit&catid=$p_catid", 2, _MD_CAT_UPDATED);
744
            exit();
745 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
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...
746
            echo $uploader->getErrors();
747
            $sql = 'UPDATE ' . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat') . " SET title = '$p_title', active='$p_active', pid='$p_pid', allowlist='$p_allowlist', showpopular='$p_showpopular' WHERE cid = $p_catid";
748
            $xoopsDB->query($sql) or $eh->show('0013');
749
            if ($p_descr) {
750
                if ($descr_exists === true) {
751
                    $sql2 = 'UPDATE ' . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat_txt') . " SET text='$p_descr' WHERE cid = $p_catid";
752
                } else {
753
                    $newid = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat_txt') . '_txtid_seq');
754
                    $sql2  = sprintf("INSERT INTO %s (txtid, cid, TEXT, active, created) VALUES (%u, %u, '%s', %u, '%s')", $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat_txt'), $newid, $p_catid, $p_descr, '1', time());
755
                }
756
                $xoopsDB->query($sql2) or $eh->show('0013');
757
            }
758
            redirect_header("categories.php?op=edit&catid=$p_catid", 2, _MD_CAT_UPDATED);
759
            exit();
760
        }
761
    }
762
    redirect_header("categories.php?op=edit&catid=$p_catid", 2, _MD_CAT_NOT_UPDATED);
0 ignored issues
show
Bug introduced by
The constant _MD_CAT_NOT_UPDATED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
763
    exit();
764
}
765
766
function newCat()
767
{
768
    global $xoopsDB, $_POST, $myts, $eh, $moddir;
769
    if (isset($_POST['dirid'])) {
770
        $p_dirid = $_POST['dirid'];
771
    } else {
772
        exit();
773
    }
774
    if (isset($_POST['pid'])) {
775
        $p_pid = $_POST['pid'];
776
    } else {
777
        $p_pid = '0';
778
    }
779
    $p_title = $myts->makeTboxData4Save($_POST['title']);
780
    if (isset($_POST['active'])) {
781
        $p_active = $_POST['active'];
782
    } else {
783
        $p_active = 0;
784
    }
785
    if (isset($_POST['importdtypes'])) {
786
        if ($p_pid != 0) {
787
            $p_import = $_POST['importdtypes'];
788
        } else {
789
            $p_import = 0;
790
        }
791
    } else {
792
        $p_import = 0;
793
    }
794
    if (isset($_POST['txtactive'])) {
795
        $p_txtactive = $_POST['txtactive'];
796
    } else {
797
        $p_txtactive = 0;
798
    }
799
    if (isset($_POST['allowlist'])) {
800
        $p_allowlist = $_POST['allowlist'];
801
    } else {
802
        $p_allowlist = 0;
803
    }
804
    if (isset($_POST['showpopular'])) {
805
        $p_showpopular = $_POST['showpopular'];
806
    } else {
807
        $p_showpopular = 0;
808
    }
809 View Code Duplication
    if (isset($_POST['descr'])) {
0 ignored issues
show
Duplication introduced by
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...
810
        $p_descr = $myts->makeTareaData4Save($_POST['descr']);
811
    } else {
812
        $p_descr = '';
813
    }
814
815
    if ($_POST['xoops_upload_file'][0] != '') {
816
        require_once XOOPS_ROOT_PATH . "/modules/$moddir/class/class.uploader.php";
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
817
        $uploader = new XoopsMediaUploader(XOOPS_ROOT_PATH . "/modules/$moddir/init_uploads", array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/jpg'), 30000, 250, 250);
818
        if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
819
            $filename = $uploader->getMediaName();
0 ignored issues
show
Unused Code introduced by
The assignment to $filename is dead and can be removed.
Loading history...
820
        } else {
821
            $newid = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat') . '_cid_seq');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
822
            $sql   = sprintf("INSERT INTO %s (cid, dirid, title, active, pid, allowlist, showpopular) VALUES (%u, %u, '%s', %u, %u, %u, %u)", $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat'), $newid, $p_dirid, $p_title, $p_active, $p_pid, $p_allowlist, $p_showpopular);
823
            $xoopsDB->query($sql) or $eh->show('0013');
824
            if ($newid == 0) {
825
                $cid = $xoopsDB->getInsertId();
826
            }
827
            if ($p_descr != '') {
828
                $newid = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat_txt') . '_txtid_seq');
829
                $sql2  = sprintf("INSERT INTO %s (txtid, cid, TEXT, active, created) VALUES (%u, %u, '%s', %u, '%s')", $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat_txt'), $newid, $cid, $p_descr, $p_txtactive, time());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $cid does not seem to be defined for all execution paths leading up to this point.
Loading history...
830
                $xoopsDB->query($sql2) or $eh->show('0013');
831
            }
832
            if ($p_import == '1') {
833
                importDtypes($p_pid, $cid);
834
            }
835
            redirect_header("categories.php?op=edit&catid=$cid", 2, _MD_CAT_SAVED);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

835
            /** @scrutinizer ignore-call */ redirect_header("categories.php?op=edit&catid=$cid", 2, _MD_CAT_SAVED);
Loading history...
836
            exit();
837
        }
838
        $uploader->setPrefix('efqdir');
839
        if ($uploader->upload()) {
840
            $savedfilename = $uploader->getSavedFileName();
841
            //echo $savedfilename;
842
            $width         = $uploader->getWidth();
843
            $height        = $uploader->getHeight();
844
            $imagelocation = $uploader->uploadDir;
0 ignored issues
show
Unused Code introduced by
The assignment to $imagelocation is dead and can be removed.
Loading history...
845
            echo $uploader->getErrors();
846
            $newid = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat') . '_cid_seq');
847
            $sql   = sprintf("INSERT INTO %s (cid, dirid, title, active, pid, img, allowlist, showpopular, width, height) VALUES (%u, %u, '%s', %u, %u, '%s', %u, %u, %u, %u)", $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat'), $newid, $p_dirid, $p_title, $p_active, $p_pid,
848
                             $savedfilename, $p_allowlist, $p_showpopular, $width, $height);
849
            $xoopsDB->query($sql) or $eh->show('0013');
850
            if ($newid == 0) {
851
                $cid = $xoopsDB->getInsertId();
852
            }
853
            if ($p_descr != '') {
854
                $newid = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat_txt') . '_txtid_seq');
855
                $sql2  = sprintf("INSERT INTO %s (txtid, cid, TEXT, active, created) VALUES (%u, %u, '%s', %u, '%s')", $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat_txt'), $newid, $cid, $p_descr, $p_txtactive, time());
856
                $xoopsDB->query($sql2) or $eh->show('0013');
857
            }
858
            if ($p_import == '1') {
859
                importDtypes($p_pid, $cid);
860
            }
861
            rename('' . XOOPS_ROOT_PATH . "/modules/$moddir/init_uploads/" . $savedfilename . '', '' . XOOPS_ROOT_PATH . "/modules/$moddir/uploads/" . $savedfilename . '');
862
            //Delete the uploaded file from the initial upload folder if it is still present in that folder.
863 View Code Duplication
            if (file_exists('' . XOOPS_ROOT_PATH . "/modules/$moddir/init_uploads/" . $savedfilename . '')) {
0 ignored issues
show
Duplication introduced by
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...
864
                unlink('' . XOOPS_ROOT_PATH . "/modules/$moddir/init_uploads/" . $savedfilename . '');
865
            }
866
            redirect_header("categories.php?op=edit&catid=$cid", 2, _MD_CAT_SAVED);
867
            exit();
868
        } else {
869
            echo $uploader->getErrors();
870
            $newid = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat') . '_cid_seq');
871
            $sql   = sprintf("INSERT INTO %s (cid, dirid, title, active, pid, img, allowlist, showpopular, width, height) VALUES (%u, %u, '%s', %u, %u, %u, %u, %u, %u, %u)", $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat'), $newid, $p_dirid, $p_title, $p_active, $p_pid, '',
872
                             $p_allowlist, $p_showpopular, '', '');
873
            $xoopsDB->query($sql) or $eh->show('0013');
874
            if ($newid == 0) {
875
                $cid = $xoopsDB->getInsertId();
876
            }
877
            if ($p_descr != '') {
878
                $newid = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat_txt') . '_txtid_seq');
879
                $sql2  = sprintf("INSERT INTO %s (txtid, cid, TEXT, active, created) VALUES (%u, %u, '%s', %u, '%s')", $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat_txt'), $newid, $cid, $p_descr, $p_txtactive, time());
880
                $xoopsDB->query($sql2) or $eh->show('0013');
881
            }
882
            if ($p_import == '1') {
883
                importDtypes($p_pid, $cid);
884
            }
885
            redirect_header("categories.php?op=edit&catid=$cid", 2, _MD_CAT_SAVED);
886
            exit();
887
        }
888
    }
889
890
    redirect_header("categories.php?op=edit&catid=$cid", 2, _MD_CAT_SAVED);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $cid seems to be never defined.
Loading history...
891
    exit();
892
}
893
894 View Code Duplication
function deleteCatConfirm()
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
895
{
896
    global $xoopsDB, $_POST, $eh, $xoopsModule, $get_catid;
897
    xoops_cp_header();
0 ignored issues
show
Bug introduced by
The function xoops_cp_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

897
    /** @scrutinizer ignore-call */ xoops_cp_header();
Loading history...
898
    $form        = new XoopsThemeForm(_MD_CONFIRM_DELETECAT_FORM, 'confirmform', 'categories.php');
899
    $submit_tray = new XoopsFormElementTray(_MD_DELETE_CAT_YN, '', 'cid');
900
    $submit_tray->addElement(new XoopsFormButton('', 'submit', _MD_DELETE, 'submit'));
901
    $submit_tray->addElement(new XoopsFormLabel('', '<input type="button" class="formButton" value="' . _MD_CANCEL . "\" onclick=\"location='categories.php?op=edit&amp;catid=$get_catid'\""));
902
    $form->addElement($submit_tray, true);
903
    //'$form->addElement($form_submit);
904
    $form->addElement(new XoopsFormHidden('op', 'deleteCat'));
905
    $form->addElement(new XoopsFormHidden('catid', $get_catid));
906
    $form->display();
907
    xoops_cp_footer();
0 ignored issues
show
Bug introduced by
The function xoops_cp_footer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

907
    /** @scrutinizer ignore-call */ xoops_cp_footer();
Loading history...
908
}
909
910
function deleteCat()
911
{
912
    global $xoopsDB, $_POST, $eh, $xoopsModule;
913
    if (isset($_POST['catid'])) {
914
        $p_catid = (int)$_POST['catid'];
915
    } else {
916
        redirect_header('directories.php', 2, _MD_INVALID_DIR);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

916
        /** @scrutinizer ignore-call */ redirect_header('directories.php', 2, _MD_INVALID_DIR);
Loading history...
917
        exit();
918
    }
919
    $dirid = getDirId($p_catid);
920
    $sql   = sprintf('DELETE FROM %s WHERE cid = %u', $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_item_x_cat'), $p_catid);
921
    $xoopsDB->queryF($sql) or $eh->show('0013');
922
    $sql = sprintf('DELETE FROM %s WHERE cid = %u', $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat'), $p_catid);
923
    $xoopsDB->queryF($sql) or $eh->show('0013');
924
    $sql = sprintf('DELETE FROM %s WHERE cid = %u', $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat_txt'), $p_catid);
925
    $xoopsDB->queryF($sql) or $eh->show('0013');
926
    $sql = sprintf('DELETE FROM %s WHERE cid = %u', $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes_x_cat'), $p_catid);
927
    $xoopsDB->queryF($sql) or $eh->show('0013');
928
    redirect_header('categories.php?dirid=' . $dirid, 2, _MD_CAT_DELETED);
0 ignored issues
show
Bug introduced by
The constant _MD_CAT_DELETED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
929
    exit();
930
}
931
932 View Code Duplication
if (!isset($_POST['op'])) {
0 ignored issues
show
Duplication introduced by
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...
933
    $op = isset($_GET['op']) ? $_GET['op'] : 'main';
934
} else {
935
    $op = $_POST['op'];
936
}
937
switch ($op) {
938
    case 'newdatatype':
939
        addDatatype();
940
        break;
941
    case 'editdtypes':
942
        editDatatypes();
943
        break;
944
    case 'editdtype':
945
        editDatatype($get_dtypeid);
946
        break;
947
    case 'savedtype':
948
        saveDatatype();
949
        break;
950
    case 'importdtypes':
951
        importDatatypes();
952
        break;
953
    case 'edit':
954
        editCat($get_catid);
955
        break;
956
    case 'update':
957
        updateCat();
958
        break;
959
    case 'newcat':
960
        newCat();
961
        break;
962
    case 'deleteCat':
963
        deleteCat();
964
        break;
965
    case 'deleteCatConfirm':
966
        deleteCatConfirm();
967
        break;
968
    default:
969
        catConfig($get_dirid);
970
        break;
971
}
972
973
function getCatOverview()
974
{
975
    global $xoopsDB, $myts, $eh, $mytree, $get_dirid, $moddir;
976
    $mainresult = $xoopsDB->query('SELECT cid, title, active, pid FROM ' . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat') . " WHERE dirid='" . $get_dirid . '\' AND pid=\'0\'');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
977
    $numrows    = $xoopsDB->getRowsNum($mainresult);
978
    $output     = '';
979
    if ($numrows > 0) {
980
        $output = '<th>' . _MD_CATTITLE . '</th><th>' . _MD_ACTIVE . '</th><th>' . _MD_ACTION . "</th>\n";
981
        $brench = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $brench is dead and can be removed.
Loading history...
982
        $tab    = '';
983
        while (list($cid, $title, $active, $pid) = $xoopsDB->fetchRow($mainresult)) {
984
            //For each cid, get all 'first children' using getFirstChildId() function
985 View Code Duplication
            if ($active != '0') {
0 ignored issues
show
Duplication introduced by
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...
986
                $activeyn = '' . _MD_YES . '';
987
            } else {
988
                $activeyn = '' . _MD_NO . '';
989
            }
990
            $output .= '<tr><td>'
991
                       . $tab
992
                       . ''
993
                       . $title
994
                       . '</td><td>'
995
                       . $activeyn
996
                       . '</td><td><a href="'
997
                       . XOOPS_URL
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
998
                       . "/modules/$moddir/admin/categories.php?op=edit&catid=$cid\"><img src=\""
999
                       . XOOPS_URL
1000
                       . '/modules/'
1001
                       . $moddir
1002
                       . '/assets/images/accessories-text-editor.png" title="'
1003
                       . _MD_MANAGE_CAT
1004
                       . '" alt="'
1005
                       . _MD_MANAGE_CAT
1006
                       . "\"></a></td></tr>\n";
1007
            $output .= getChildrenCategories($cid);
1008
        }
1009
    } else {
1010
        $output = '<p><span style="background-color: #E6E6E6; padding: 5px; border: 1px solid #000000;">' . _MD_NORESULTS_PLEASE_CREATE_CATEGORY . '</span></p>';
1011
    }
1012
1013
    return $output;
1014
}
1015
1016
function getChildrenCategories($childid = '0', $level = '0')
1017
{
1018
    global $xoopsDB, $myts, $eh, $mytree, $get_dirid, $moddir;
1019
    $tab    = '&nbsp;';
1020
    $level  = $level;
1021
    $output = '';
1022
    $plus   = '<img src="' . XOOPS_URL . '/images/arrow.gif">';
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
1023
    for ($i = 0; $i < $level; ++$i) {
1024
        $tab .= '&nbsp;&nbsp;&nbsp;&nbsp;';
1025
    }
1026
    $sql         = 'SELECT cid, title, active, pid FROM ' . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_cat') . " WHERE dirid='" . $get_dirid . '\' AND pid=\'' . $childid . '\'';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
1027
    $childresult = $xoopsDB->query($sql);
1028
    $numrows     = $xoopsDB->getRowsNum($childresult);
1029
    if ($numrows > 0) {
1030
        while (list($cid, $title, $active, $pid) = $xoopsDB->fetchRow($childresult)) {
1031 View Code Duplication
            if ($active != '0') {
0 ignored issues
show
Duplication introduced by
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...
1032
                $activeyn = '' . _MD_YES . '';
1033
            } else {
1034
                $activeyn = '' . _MD_NO . '';
1035
            }
1036
            $output   .= '<tr><td>'
1037
                         . $tab
1038
                         . $plus
1039
                         . $title
1040
                         . '&nbsp;</td><td>'
1041
                         . $activeyn
1042
                         . '</td><td><a href="'
1043
                         . XOOPS_URL
1044
                         . "/modules/$moddir/admin/categories.php?op=edit&catid=$cid\"><img src=\""
1045
                         . XOOPS_URL
1046
                         . '/modules/'
1047
                         . $moddir
1048
                         . '/assets/images/accessories-text-editor.png" title="'
1049
                         . _MD_MANAGE_CAT
1050
                         . '" alt="'
1051
                         . _MD_MANAGE_CAT
1052
                         . "\"></a></td></tr>\n";
1053
            $newlevel = $level + 1;
1054
            $output   .= getChildrenCategories($cid, $newlevel);
1055
        }
1056
    }
1057
1058
    return $output;
1059
}
1060
1061
function importDtypes($pid = '0', $catid = '0')
1062
{
1063
    global $xoopsDB, $_POST, $eh;
1064 View Code Duplication
    if ($pid != 0) {
0 ignored issues
show
Duplication introduced by
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...
1065
        $sql = 'INSERT INTO '
1066
               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes_x_cat')
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
1067
               . ' (cid, dtypeid) SELECT '
1068
               . $catid
1069
               . ', d.dtypeid FROM '
1070
               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_dtypes')
1071
               . ' d, '
1072
               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n')
1073
                                  . '_dtypes_x_cat')
1074
               . ' x  WHERE d.dtypeid=x.dtypeid AND x.cid = '
1075
               . $pid
1076
               . " AND d.defaultyn = '1'";
1077
    }
1078
    $xoopsDB->query($sql) or $eh->show('0013');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $sql does not seem to be defined for all execution paths leading up to this point.
Loading history...
1079
}
1080