Issues (273)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

admin/category.php (11 issues)

1
<?php
2
/**
3
 * Module: WF-Links
4
 * Version: v1.0.3
5
 * Release Date: 21 June 2005
6
 * Developer: John N
7
 * Team: WF-Projects
8
 * Licence: GNU
9
 */
10
11
use Xmf\Module\Admin;
12
use Xmf\Request;
13
use XoopsModules\Wflinks;
14
15
require_once __DIR__ . '/admin_header.php';
16
require_once XOOPS_ROOT_PATH . '/class/xoopsform/grouppermform.php';
17
18
/** @var Wflinks\Helper $helper */
19
$helper = Wflinks\Helper::getInstance();
20
21
$op = '';
22
23
if (isset($_POST)) {
24
    foreach ($_POST as $k => $v) {
25
        ${$k} = $v;
26
    }
27
}
28
if (isset($_GET)) {
29
    foreach ($_GET as $k => $v) {
30
        ${$k} = $v;
31
    }
32
}
33
34
/**
35
 * @param int $cid
36
 */
37
function createCat($cid = 0)
38
{
39
    // require_once  dirname(__DIR__) . '/class/wfllists.php';
40
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
41
42
    global $xoopsDB, $myts, $totalcats, $xoopsModule;
43
    /** @var Wflinks\Helper $helper */
44
    $helper = Wflinks\Helper::getInstance();
45
46
    $lid          = 0;
0 ignored issues
show
The assignment to $lid is dead and can be removed.
Loading history...
47
    $title        = '';
48
    $imgurl       = '';
49
    $description  = '';
50
    $pid          = '';
0 ignored issues
show
The assignment to $pid is dead and can be removed.
Loading history...
51
    $weight       = 0;
52
    $nohtml       = 0;
53
    $nosmiley     = 0;
54
    $noxcodes     = 0;
55
    $noimages     = 0;
56
    $nobreak      = 1;
57
    $spotlighttop = 0;
0 ignored issues
show
The assignment to $spotlighttop is dead and can be removed.
Loading history...
58
    $spotlighthis = 0;
0 ignored issues
show
The assignment to $spotlighthis is dead and can be removed.
Loading history...
59
    $client_id    = 0;
60
    $banner_id    = 0;
61
    $heading      = _AM_WFL_CCATEGORY_CREATENEW;
62
    $totalcats    = Wflinks\Utility::getTotalCategory();
63
64
    if ($cid) {
65
        $sql          = 'SELECT * FROM ' . $xoopsDB->prefix('wflinks_cat') . " WHERE cid=$cid";
66
        $cat_arr      = $xoopsDB->fetchArray($xoopsDB->query($sql));
67
        $title        = htmlspecialchars($cat_arr['title'], ENT_QUOTES | ENT_HTML5);
68
        $imgurl       = htmlspecialchars($cat_arr['imgurl'], ENT_QUOTES | ENT_HTML5);
69
        $description  = htmlspecialchars($cat_arr['description'], ENT_QUOTES | ENT_HTML5);
70
        $nohtml       = (int)$cat_arr['nohtml'];
71
        $nosmiley     = (int)$cat_arr['nosmiley'];
72
        $noxcodes     = (int)$cat_arr['noxcodes'];
73
        $noimages     = (int)$cat_arr['noimages'];
74
        $nobreak      = (int)$cat_arr['nobreak'];
75
        $spotlighthis = (int)$cat_arr['spotlighthis'];
76
        $spotlighttop = (int)$cat_arr['spotlighttop'];
77
        $weight       = $cat_arr['weight'];
78
        $client_id    = $cat_arr['client_id'];
79
        $banner_id    = $cat_arr['banner_id'];
80
        $heading      = _AM_WFL_CCATEGORY_MODIFY;
81
82
        /** @var \XoopsGroupPermHandler $grouppermHandler */
83
        $grouppermHandler = xoops_getHandler('groupperm');
84
        $groups           = $grouppermHandler->getGroupIds('WFLinkCatPerm', $cid, $xoopsModule->getVar('mid'));
85
        $groups           = $groups;
0 ignored issues
show
The assignment to $groups is dead and can be removed.
Loading history...
86
    } else {
87
        $groups = true;
88
    }
89
90
    $sform = new \XoopsThemeForm($heading, 'op', xoops_getenv('SCRIPT_NAME'), 'post', true);
91
    $sform->setExtra('enctype="multipart/form-data"');
92
93
    $sform->addElement(new \XoopsFormText(_AM_WFL_FCATEGORY_TITLE, 'title', 50, 80, $title), true);
94
    $sform->addElement(new \XoopsFormText(_AM_WFL_FCATEGORY_WEIGHT, 'weight', 10, 80, $weight), false);
95
96
    if ($totalcats > 0 && $cid) {
97
        $mytreechose = new Wflinks\Tree($xoopsDB->prefix('wflinks_cat'), 'cid', 'pid');
98
        ob_start();
99
        $mytreechose->makeMySelBox('title', 'title', $cat_arr['pid'], 1, 'pid');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $cat_arr does not seem to be defined for all execution paths leading up to this point.
Loading history...
100
        $sform->addElement(new \XoopsFormLabel(_AM_WFL_FCATEGORY_SUBCATEGORY, ob_get_clean()));
101
    } else {
102
        $mytreechose = new Wflinks\Tree($xoopsDB->prefix('wflinks_cat'), 'cid', 'pid');
103
        ob_start();
104
        $mytreechose->makeMySelBox('title', 'title', $cid, 1, 'pid');
105
        $sform->addElement(new \XoopsFormLabel(_AM_WFL_FCATEGORY_SUBCATEGORY, ob_get_clean()));
106
    }
107
108
    $graph_array       = Wflinks\Lists::getListTypeAsArray(XOOPS_ROOT_PATH . '/' . $helper->getConfig('catimage'), $type = 'images');
109
    $indeximage_select = new \XoopsFormSelect('', 'imgurl', $imgurl);
110
    $indeximage_select->addOptionArray($graph_array);
111
    $indeximage_select->setExtra("onchange='showImgSelected(\"image\", \"imgurl\", \"" . $helper->getConfig('catimage') . '", "", "' . XOOPS_URL . "\")'");
112
    $indeximage_tray = new \XoopsFormElementTray(_AM_WFL_FCATEGORY_CIMAGE, '&nbsp;');
113
    $indeximage_tray->addElement($indeximage_select);
114
    if (!empty($imgurl)) {
115
        $indeximage_tray->addElement(new \XoopsFormLabel('', "<br><br><img src='" . XOOPS_URL . '/' . $helper->getConfig('catimage') . '/' . $imgurl . "' name='image' id='image' alt=''>"));
116
    } else {
117
        $indeximage_tray->addElement(new \XoopsFormLabel('', "<br><br><img src='" . XOOPS_URL . "/uploads/blank.gif' name='image' id='image' alt=''>"));
118
    }
119
    $sform->addElement($indeximage_tray);
120
121
    $editor = Wflinks\Utility::getWysiwygForm(_AM_WFL_FCATEGORY_DESCRIPTION, 'description', $description, 15, 60, '');
0 ignored issues
show
The call to XoopsModules\Wflinks\Utility::getWysiwygForm() has too many arguments starting with 15. ( Ignorable by Annotation )

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

121
    /** @scrutinizer ignore-call */ 
122
    $editor = Wflinks\Utility::getWysiwygForm(_AM_WFL_FCATEGORY_DESCRIPTION, 'description', $description, 15, 60, '');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
122
    $sform->addElement($editor, false);
0 ignored issues
show
It seems like $editor can also be of type false; however, parameter $formElement of XoopsForm::addElement() does only seem to accept XoopsFormElement|string, maybe add an additional type check? ( Ignorable by Annotation )

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

122
    $sform->addElement(/** @scrutinizer ignore-type */ $editor, false);
Loading history...
123
124
    // Select Client/Sponsor
125
    $client_select   = new \XoopsFormSelect(_AM_WFL_CATSPONSOR, 'client_id', $client_id, false);
0 ignored issues
show
false of type false is incompatible with the type integer expected by parameter $size of XoopsFormSelect::__construct(). ( Ignorable by Annotation )

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

125
    $client_select   = new \XoopsFormSelect(_AM_WFL_CATSPONSOR, 'client_id', $client_id, /** @scrutinizer ignore-type */ false);
Loading history...
126
    $sql             = 'SELECT cid, name FROM ' . $xoopsDB->prefix('bannerclient') . ' ORDER BY name ASC';
127
    $result          = $xoopsDB->query($sql);
128
    $client_array    = [];
129
    $client_array[0] = '&nbsp;';
130
    while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
131
        $client_array[$myrow['cid']] = $myrow['name'];
132
    }
133
    $client_select->addOptionArray($client_array);
134
    $client_select->setDescription(_AM_WFL_CATSPONSORDSC);
135
    $sform->addElement($client_select);
136
137
    // Select Banner
138
    $banner_select   = new \XoopsFormSelect(_AM_WFL_BANNERID, 'banner_id', $banner_id, false);
139
    $sql             = 'SELECT bid, cid FROM ' . $xoopsDB->prefix('banner') . ' ORDER BY bid ASC';
140
    $result          = $xoopsDB->query($sql);
141
    $banner_array    = [];
142
    $banner_array[0] = '&nbsp;';
143
    while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
144
        $banner_array[$myrow['bid']] = $myrow['bid'];
145
    }
146
    $banner_select->addOptionArray($banner_array);
147
    $banner_select->setDescription(_AM_WFL_BANNERIDDSC);
148
    $sform->addElement($banner_select);
149
150
    $options_tray = new \XoopsFormElementTray(_AM_WFL_TEXTOPTIONS, '<br>');
151
152
    $html_checkbox = new \XoopsFormCheckBox('', 'nohtml', $nohtml);
153
    $html_checkbox->addOption(1, _AM_WFL_DISABLEHTML);
154
    $options_tray->addElement($html_checkbox);
155
156
    $smiley_checkbox = new \XoopsFormCheckBox('', 'nosmiley', $nosmiley);
157
    $smiley_checkbox->addOption(1, _AM_WFL_DISABLESMILEY);
158
    $options_tray->addElement($smiley_checkbox);
159
160
    $xcodes_checkbox = new \XoopsFormCheckBox('', 'noxcodes', $noxcodes);
161
    $xcodes_checkbox->addOption(1, _AM_WFL_DISABLEXCODE);
162
    $options_tray->addElement($xcodes_checkbox);
163
164
    $noimages_checkbox = new \XoopsFormCheckBox('', 'noimages', $noimages);
165
    $noimages_checkbox->addOption(1, _AM_WFL_DISABLEIMAGES);
166
    $options_tray->addElement($noimages_checkbox);
167
168
    $breaks_checkbox = new \XoopsFormCheckBox('', 'nobreak', $nobreak);
169
    $breaks_checkbox->addOption(1, _AM_WFL_DISABLEBREAK);
170
    $options_tray->addElement($breaks_checkbox);
171
    $sform->addElement($options_tray);
172
173
    //    $sform -> addElement(new \XoopsFormSelectGroup(_AM_WFL_FCATEGORY_GROUPPROMPT, "groups", true, $groups, 5, true));
174
175
    $sform->addElement(new \XoopsFormHidden('cid', $cid));
176
177
    $sform->addElement(new \XoopsFormHidden('spotlighttop', $cid));
178
179
    $buttonTray = new \XoopsFormElementTray('', '');
180
    $hidden     = new \XoopsFormHidden('op', 'save');
181
    $buttonTray->addElement($hidden);
182
183
    if ($cid) {
184
        $butt_create = new \XoopsFormButton('', '', _AM_WFL_BMODIFY, 'submit');
185
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addCat\'"');
186
        $buttonTray->addElement($butt_create);
187
188
        $butt_delete = new \XoopsFormButton('', '', _AM_WFL_BDELETE, 'submit');
189
        $butt_delete->setExtra('onclick="this.form.elements.op.value=\'del\'"');
190
        $buttonTray->addElement($butt_delete);
191
192
        $butt_cancel = new \XoopsFormButton('', '', _AM_WFL_BCANCEL, 'button');
193
        $butt_cancel->setExtra('onclick="history.go(-1)"');
194
        $buttonTray->addElement($butt_cancel);
195
    } else {
196
        $butt_create = new \XoopsFormButton('', '', _AM_WFL_BSAVE, 'submit');
197
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addCat\'"');
198
        $buttonTray->addElement($butt_create);
199
200
        $butt_clear = new \XoopsFormButton('', '', _AM_WFL_BRESET, 'reset');
201
        $buttonTray->addElement($butt_clear);
202
203
        $butt_cancel = new \XoopsFormButton('', '', _AM_WFL_BCANCEL, 'button');
204
        $butt_cancel->setExtra('onclick="history.go(-1)"');
205
        $buttonTray->addElement($butt_cancel);
206
    }
207
    $sform->addElement($buttonTray);
208
    $sform->display();
209
210
    $result2 = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('wflinks_cat') . '');
211
    list($numrows) = $xoopsDB->fetchRow($result2);
0 ignored issues
show
Comprehensibility Best Practice introduced by
This list assign is not used and could be removed.
Loading history...
212
}
213
214
$op = \Xmf\Request::getString('op', 'main');
215
216
switch ($op) {
217
    case 'move':
218
        if (isset($_POST['ok'])) {
219
            global $xoopsDB;
220
221
            $source = $_POST['source'];
222
            $target = $_POST['target'];
223
            if ($target == $source) {
224
                redirect_header("category.php?op=move&ok=0&cid=$source", 5, _AM_WFL_CCATEGORY_MODIFY_FAILED);
225
            }
226
            if (!$target) {
227
                redirect_header("category.php?op=move&ok=0&cid=$source", 5, _AM_WFL_CCATEGORY_MODIFY_FAILEDT);
228
            }
229
            $sql    = 'UPDATE ' . $xoopsDB->prefix('wflinks_links') . ' set cid = ' . $target . ' WHERE cid =' . $source;
230
            $result = $xoopsDB->queryF($sql);
231
            $error  = _AM_WFL_DBERROR . ': <br><br>' . $sql;
232
            if (!$result) {
233
                trigger_error($error, E_USER_ERROR);
234
            }
235
            redirect_header('category.php?op=default', 1, _AM_WFL_CCATEGORY_MODIFY_MOVED);
236
        } else {
237
            $cid = $_POST['cid'] ?? $_GET['cid'];
238
239
            xoops_cp_header();
240
241
            require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
242
            $mytree = new Wflinks\Tree($xoopsDB->prefix('wflinks_cat'), 'cid', 'pid');
243
            $sform  = new \XoopsThemeForm(_AM_WFL_CCATEGORY_MOVE, 'move', xoops_getenv('SCRIPT_NAME'), 'post', true);
244
            ob_start();
245
            $mytree->makeMySelBox('title', 'title', 0, 0, 'target');
246
            $sform->addElement(new \XoopsFormLabel(_AM_WFL_BMODIFY, ob_get_contents()));
247
            ob_end_clean();
248
            $create_tray = new \XoopsFormElementTray('', '');
249
            $create_tray->addElement(new \XoopsFormHidden('source', $cid));
250
            $create_tray->addElement(new \XoopsFormHidden('ok', 1));
251
            $create_tray->addElement(new \XoopsFormHidden('op', 'move'));
252
            $butt_save = new \XoopsFormButton('', '', _AM_WFL_BMOVE, 'submit');
253
            $butt_save->setExtra('onclick="this.form.elements.op.value=\'move\'"');
254
            $create_tray->addElement($butt_save);
255
            $butt_cancel = new \XoopsFormButton('', '', _AM_WFL_BCANCEL, 'submit');
256
            $butt_cancel->setExtra('onclick="this.form.elements.op.value=\'cancel\'"');
257
            $create_tray->addElement($butt_cancel);
258
            $sform->addElement($create_tray);
259
            $sform->display();
260
            xoops_cp_footer();
261
        }
262
        break;
263
    case 'addCat':
264
265
        $groups       = Request::getArray('groups', [], 'POST');
266
        $cid          = Request::getInt('cid', 0, 'POST');
267
        $pid          = Request::getInt('pid', 0, 'POST');
268
        $weight       = (isset($_REQUEST['weight']) && $_REQUEST['weight'] > 0) ? $_REQUEST['weight'] : 0;
269
        $spotlighthis = Request::getInt('lid', 0, 'POST');
270
        $spotlighttop = (1 == $_REQUEST['spotlighttop']) ? 1 : 0;
271
        $title        = Request::getText('title', '', 'POST');
272
        $descriptionb = Request::getText('description', '', 'POST');
273
        $imgurl       = ($_REQUEST['imgurl'] && 'blank.gif' !== $_REQUEST['imgurl']) ? Request::getUrl('imgurl', '', 'POST') : '';
274
        $client_id    = Request::getInt('client_id', 0, 'POST');
275
        if ($client_id > 0) {
276
            $banner_id = 0;
277
        } else {
278
            $banner_id = Request::getInt('banner_id', 0, 'POST');
279
        }
280
281
        $nohtml   = Request::getInt('nohtml', 0, 'POST');
282
        $nosmiley = Request::getInt('nosmiley', 0, 'POST');
283
        $noxcodes = Request::getInt('noxcodes', 0, 'POST');
284
        $noimages = Request::getInt('noimages', 0, 'POST');
285
        $nobreak  = Request::getInt('nobreak', 0, 'POST');
286
287
        if ($cid) {
288
            if ($cid == $pid) {
289
                redirect_header('category.php', 1, _AM_WFL_ERROR_CATISCAT);
290
            }
291
            $sql           = 'UPDATE '
292
                             . $xoopsDB->prefix('wflinks_cat')
293
                             . " SET title ='$title', imgurl='$imgurl', pid =$pid, description='$descriptionb', spotlighthis='$spotlighthis' , spotlighttop='$spotlighttop', nohtml='$nohtml', nosmiley='$nosmiley', noxcodes='$noxcodes', noimages='$noimages', nobreak='$nobreak', weight='$weight', client_id='$client_id', banner_id='$banner_id' WHERE cid="
294
                             . $cid;
295
            $database_mess = _AM_WFL_CCATEGORY_MODIFIED;
296
        } else {
297
            $cid = 0;
298
            $sql = 'INSERT INTO '
299
                   . $xoopsDB->prefix('wflinks_cat')
300
                   . " (cid, pid, title, imgurl, description, nohtml, nosmiley, noxcodes, noimages, nobreak, weight, spotlighttop, spotlighthis, client_id, banner_id ) VALUES (0, $pid, '$title', '$imgurl', '$descriptionb', '$nohtml', '$nosmiley', '$noxcodes', '$noimages', '$nobreak', '$weight',  '$spotlighttop', '$spotlighthis', '$client_id', '$banner_id' )";
301
            if (0 == $cid) {
0 ignored issues
show
The condition 0 == $cid is always true.
Loading history...
302
                $newid = $xoopsDB->getInsertId();
303
            }
304
305
            // Notify of new category
306
307
            global $xoopsModule;
308
            $tags                  = [];
309
            $tags['CATEGORY_NAME'] = $title;
310
            $tags['CATEGORY_URL']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewcat.php?cid=' . $newid;
311
            /** @var \XoopsNotificationHandler $notificationHandler */
312
            $notificationHandler = xoops_getHandler('notification');
313
            $notificationHandler->triggerEvent('global', 0, 'new_category', $tags);
314
            $database_mess = _AM_WFL_CCATEGORY_CREATED;
315
        }
316
        if (!$result = $xoopsDB->query($sql)) {
317
            /** @var \XoopsLogger $logger */
318
            $logger = \XoopsLogger::getInstance();
319
            $logger->handleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
320
321
            return false;
322
        }
323
        redirect_header('category.php', 1, $database_mess);
324
        break;
325
    case 'del':
326
327
        global $xoopsDB, $xoopsModule;
328
329
        $cid    = (isset($_POST['cid']) && is_numeric($_POST['cid'])) ? \Xmf\Request::getInt('cid', 0, 'POST') : \Xmf\Request::getInt('cid', 0, 'GET');
330
        $ok     = (isset($_POST['ok']) && 1 == $_POST['ok']) ? \Xmf\Request::getInt('ok', 0, 'POST') : 0;
331
        $mytree = new Wflinks\Tree($xoopsDB->prefix('wflinks_cat'), 'cid', 'pid');
332
333
        if (1 == $ok) {
334
            // get all subcategories under the specified category
335
            $subcategories = $mytree->getAllChildId($cid);
336
            foreach ($subcategories as $subcategory) {
337
                // get all links in each subcategory
338
                $result = $xoopsDB->query('SELECT lid FROM ' . $xoopsDB->prefix('wflinks_links') . ' WHERE cid=' . $subcategory . ' ');
339
                // now for each linkload, delete the text data and vote ata associated with the linkload
340
                while (list($lid) = $xoopsDB->fetchRow($result)) {
341
                    $sql = sprintf('DELETE FROM `%s` WHERE lid = %u', $xoopsDB->prefix('wflinks_votedata'), $lid);
342
                    $xoopsDB->query($sql);
343
                    $sql = sprintf('DELETE FROM `%s` WHERE lid = %u', $xoopsDB->prefix('wflinks_links'), $lid);
344
                    $xoopsDB->query($sql);
345
346
                    // delete comments
347
                    xoops_comment_delete($xoopsModule->getVar('mid'), $lid);
348
                }
349
                // all links for each subcategory are deleted, now delete the subcategory data
350
                $sql = sprintf('DELETE FROM `%s` WHERE cid = %u', $xoopsDB->prefix('wflinks_cat'), $subcategory);
351
                $xoopsDB->query($sql);
352
                // delete altcat entries
353
                $sql = sprintf('DELETE FROM `%s` WHERE cid = %u', $xoopsDB->prefix('wflinks_altcat'), $subcategory);
354
                $xoopsDB->query($sql);
355
            }
356
            // all subcategory and associated data are deleted, now delete category data and its associated data
357
            $result = $xoopsDB->query('SELECT lid FROM ' . $xoopsDB->prefix('wflinks_links') . ' WHERE cid=' . $cid . '');
358
            while (list($lid) = $xoopsDB->fetchRow($result)) {
359
                $sql = sprintf('DELETE FROM `%s` WHERE lid = %u', $xoopsDB->prefix('wflinks_links'), $lid);
360
                $xoopsDB->query($sql);
361
                // delete comments
362
                xoops_comment_delete($xoopsModule->getVar('mid'), $lid);
363
                $sql = sprintf('DELETE FROM `%s` WHERE lid = %u', $xoopsDB->prefix('wflinks_votedata'), $lid);
364
                $xoopsDB->query($sql);
365
            }
366
            // delete altcat entries
367
            $sql = sprintf('DELETE FROM `%s` WHERE cid = %u', $xoopsDB->prefix('wflinks_altcat'), $cid);
368
            $xoopsDB->query($sql);
369
            // delete category
370
            $sql   = sprintf('DELETE FROM `%s` WHERE cid = %u', $xoopsDB->prefix('wflinks_cat'), $cid);
371
            $error = _AM_WFL_DBERROR . ': <br><br>' . $sql;
372
373
            // delete group permissions
374
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'WFLinkCatPerm', $cid);
375
            if (!$result = $xoopsDB->query($sql)) {
376
                trigger_error($error, E_USER_ERROR);
377
            }
378
379
            redirect_header('category.php', 1, _AM_WFL_CCATEGORY_DELETED);
380
        } else {
381
            xoops_cp_header();
382
            xoops_confirm(['op' => 'del', 'cid' => $cid, 'ok' => 1], 'category.php', _AM_WFL_CCATEGORY_AREUSURE);
383
            xoops_cp_footer();
384
        }
385
        break;
386
    case 'modCat':
387
        $cid = \Xmf\Request::getInt('cid', 0, 'POST');
388
        xoops_cp_header();
389
390
        createCat($cid);
391
        xoops_cp_footer();
392
        break;
393
    case 'main':
394
    default:
395
        xoops_cp_header();
396
397
        $adminObject = Admin::getInstance();
398
        $adminObject->displayNavigation(basename(__FILE__));
399
        $adminObject->addItemButton(_MI_WFL_ADD_LINK, 'main.php?op=edit', 'add', '');
400
        $adminObject->addItemButton(_MI_WFL_ADD_CATEGORY, 'category.php', 'add', '');
401
        $adminObject->displayButton('left', '');
402
403
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
404
        $mytree    = new Wflinks\Tree($xoopsDB->prefix('wflinks_cat'), 'cid', 'pid');
405
        $sform     = new \XoopsThemeForm(_AM_WFL_CCATEGORY_MODIFY, 'category', xoops_getenv('SCRIPT_NAME'), 'post', true);
406
        $totalcats = Wflinks\Utility::getTotalCategory();
407
408
        if ($totalcats > 0) {
409
            ob_start();
410
            $mytree->makeMySelBox('title', 'title');
411
            $sform->addElement(new \XoopsFormLabel(_AM_WFL_CCATEGORY_MODIFY_TITLE, ob_get_clean()));
412
            $dup_tray = new \XoopsFormElementTray('', '');
413
            $dup_tray->addElement(new \XoopsFormHidden('op', 'modCat'));
414
            $butt_dup = new \XoopsFormButton('', '', _AM_WFL_BMODIFY, 'submit');
415
            $butt_dup->setExtra('onclick="this.form.elements.op.value=\'modCat\'"');
416
            $dup_tray->addElement($butt_dup);
417
            $butt_move = new \XoopsFormButton('', '', _AM_WFL_BMOVE, 'submit');
418
            $butt_move->setExtra('onclick="this.form.elements.op.value=\'move\'"');
419
            $dup_tray->addElement($butt_move);
420
            $butt_dupct = new \XoopsFormButton('', '', _AM_WFL_BDELETE, 'submit');
421
            $butt_dupct->setExtra('onclick="this.form.elements.op.value=\'del\'"');
422
            $dup_tray->addElement($butt_dupct);
423
            $sform->addElement($dup_tray);
424
            $sform->display();
425
        }
426
        createCat(0);
427
        require_once __DIR__ . '/admin_footer.php';
428
        break;
429
}
430