Passed
Push — master ( 2ecc51...c1b656 )
by Michael
04:26 queued 02:02
created

getAddressFields()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 38
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 30
nc 6
nop 1
dl 0
loc 38
rs 8.5806
c 0
b 0
f 0
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
 * @param $orderby
20
 * @return string
21
 */
22
23
function convertOrderByIn($orderby)
24
{
25
    switch (trim($orderby)) {
26
        case 'titleA':
27
            $orderby = 'title ASC';
28
            break;
29
        case 'dateA':
30
            $orderby = 'created ASC';
31
            break;
32
        case 'hitsA':
33
            $orderby = 'hits ASC';
34
            break;
35
        case 'ratingA':
36
            $orderby = 'rating ASC';
37
            break;
38
        case 'titleD':
39
            $orderby = 'title DESC';
40
            break;
41
        case 'hitsD':
42
            $orderby = 'hits DESC';
43
            break;
44
        case 'ratingD':
45
            $orderby = 'rating DESC';
46
            break;
47
        case'dateD':
48
        default:
49
            $orderby = 'created DESC';
50
            break;
51
    }
52
53
    return $orderby;
54
}
55
56
/**
57
 * @param $orderby
58
 * @return string
59
 */
60
function convertorderbytrans($orderby)
61
{
62
    $orderbyTrans = '';
63
    if ($orderby === 'hits ASC') {
64
        $orderbyTrans = '' . _MD_POPULARITYLTOM . '';
65
    }
66
    if ($orderby === 'hits DESC') {
67
        $orderbyTrans = '' . _MD_POPULARITYMTOL . '';
68
    }
69
    if ($orderby === 'title ASC') {
70
        $orderbyTrans = '' . _MD_TITLEATOZ . '';
71
    }
72
    if ($orderby === 'title DESC') {
73
        $orderbyTrans = '' . _MD_TITLEZTOA . '';
74
    }
75
    if ($orderby === 'date ASC') {
76
        $orderbyTrans = '' . _MD_DATEOLD . '';
77
    }
78
    if ($orderby === 'date DESC') {
79
        $orderbyTrans = '' . _MD_DATENEW . '';
80
    }
81
    if ($orderby === 'rating ASC') {
82
        $orderbyTrans = '' . _MD_RATINGLTOH . '';
83
    }
84
    if ($orderby === 'rating DESC') {
85
        $orderbyTrans = '' . _MD_RATINGHTOL . '';
86
    }
87
88
    return $orderbyTrans;
89
}
90
91
/**
92
 * @param $orderby
93
 * @return string
94
 */
95
function convertorderbyout($orderby)
96
{
97
    if ($orderby === 'title ASC') {
98
        $orderby = 'titleA';
99
    }
100
    if ($orderby === 'date ASC') {
101
        $orderby = 'dateA';
102
    }
103
    if ($orderby === 'hits ASC') {
104
        $orderby = 'hitsA';
105
    }
106
    if ($orderby === 'rating ASC') {
107
        $orderby = 'ratingA';
108
    }
109
    if ($orderby === 'title DESC') {
110
        $orderby = 'titleD';
111
    }
112
    if ($orderby === 'date DESC') {
113
        $orderby = 'dateD';
114
    }
115
    if ($orderby === 'hits DESC') {
116
        $orderby = 'hitsD';
117
    }
118
    if ($orderby === 'rating DESC') {
119
        $orderby = 'ratingD';
120
    }
121
122
    return $orderby;
123
}
124
125
/**
126
 * @param $time
127
 * @param $status
128
 * @return string
129
 */
130
function newlinkgraphic($time, $status)
131
{
132
    global $moddir;
133
    $count     = 7;
134
    $new       = '';
135
    $startdate = (time() - (86400 * $count));
136
    if ($startdate < $time) {
137
        if ($status == 2) {
138
            $new = '&nbsp;<img src="' . XOOPS_URL . "/modules/$moddir/assets/images/newred.gif\" alt=\"" . _MD_NEWTHISWEEK . '">';
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...
139
        } elseif ($status == 3) {
140
            $new = '&nbsp;<img src="' . XOOPS_URL . "/modules/$moddir/assets/images/update.gif\" alt=\"" . _MD_UPTHISWEEK . '">';
141
        }
142
    }
143
144
    return $new;
145
}
146
147
/**
148
 * @param $hits
149
 * @return string
150
 */
151
function popgraphic($hits)
152
{
153
    global $xoopsModuleConfig, $moddir;
154
    if ($hits >= $xoopsModuleConfig['popular']) {
155
        return '&nbsp;<img src="' . XOOPS_URL . "/modules/$moddir/assets/images/pop.gif\" alt=\"" . _MD_POPULAR . '">';
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...
156
    }
157
158
    return '';
159
}
160
161
/**
162
 * @param     $sel_id
163
 * @param int $status
164
 * @return int
165
 */
166
function getTotalItems($sel_id, $status = 0)
167
{
168
    global $xoopsDB, $mytree;
169
    $count = 0;
170
    $arr   = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $arr is dead and can be removed.
Loading history...
171
    $query = 'SELECT DISTINCT l.itemid FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_items') . ' l, ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_item_x_cat') . ' x WHERE x.itemid=l.itemid AND x.cid=' . $sel_id . '';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
172
    if ($status !== '') {
173
        $query .= " AND l.status>='$status'";
174
    } else {
175
        $query .= '';
176
    }
177
    $query  .= " AND x.active >= '1'";
178
    $result = $xoopsDB->query($query);
179
    //print_r($xoopsDB->fetchArray($result));
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% 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...
180
    if (!$result) {
181
        $count = 0;
182
    } else {
183
        $num_results = $GLOBALS['xoopsDB']->getRowsNum($result);
184
        $count       = $num_results;
185
    }
186
    $arr  = $mytree->getAllChildId($sel_id);
187
    $size = count($arr);
188
    for ($i = 0; $i < $size; ++$i) {
189
        $query2 = 'SELECT DISTINCT l.itemid FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_items') . ' l, ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_item_x_cat') . ' x WHERE l.itemid=x.itemid AND x.cid=' . $arr[$i] . '';
190
        if ($status !== '') {
191
            $query2 .= " AND l.status>='$status'";
192
        } else {
193
            $query2 .= '';
194
        }
195
        $query2       .= " AND x.active >= '1'";
196
        $result2      = $xoopsDB->query($query2);
197
        $num_results2 = $GLOBALS['xoopsDB']->getRowsNum($result2);
198
        $count        += $num_results2;
199
    }
200
201
    return $count;
202
}
203
204
/**
205
 * @param        $sel_id
206
 * @param string $status
207
 * @param        $locdestid
208
 * @return int
209
 */
210
function getTotalItems2($sel_id, $status = '', $locdestid)
211
{
212
    global $xoopsDB, $mytree;
213
    $count = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $count is dead and can be removed.
Loading history...
214
    $arr   = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $arr is dead and can be removed.
Loading history...
215
    $query = 'SELECT count(*) FROM ' . $xoopsDB->prefix('links_links') . ' t, ' . $xoopsDB->prefix('links_x_loc_dest') . ' x  WHERE x.ldestid=t.lid AND x.locdestid=' . $locdestid . ' AND t.cid=' . $sel_id . '';
216
    //  $query = "select DISTINCT count(lid) from ".$xoopsDB->prefix("links_links")." t, ".$xoopsDB->prefix("links_x_loc_dest")." x  where x.ldestid=t.lid AND x.locdestid=".$locdestid." AND t.cid=".$sel_id."";
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
217
    //  $query = "select count(*) from ".$xoopsDB->prefix("links_links")." where cid=".$sel_id."";
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...
218
    if ($status !== '') {
219
        $query .= " and status>=$status";
220
    }
221
    $result = $xoopsDB->query($query);
222
    list($thing) = $xoopsDB->fetchRow($result);
223
    $count = $thing;
224
    $arr   = $mytree->getAllChildId($sel_id);
225
    $size  = count($arr);
226
    for ($i = 0; $i < $size; ++$i) {
227
        $query2 = 'select count(*) ' . $xoopsDB->prefix('links_links') . ' t, ' . $xoopsDB->prefix('links_x_loc_dest') . ' x  where x.ldestid=t.lid AND x.locdestid=' . $locdestid . ' AND t.cid=' . $arr[$i] . '';
228
        if ($status !== '') {
229
            $query2 .= " and status>=$status";
230
        }
231
        $result2 = $xoopsDB->query($query2);
232
        list($thing) = $xoopsDB->fetchRow($result2);
233
        $count += $thing;
234
    }
235
236
    return $count;
237
}
238
239
/**
240
 * @param int $dirid
241
 * @return int
242
 */
243
function getDirNameFromId($dirid = 0)
244
{
245
    global $xoopsDB;
246
    $myts        = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
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...
247
    $result      = $xoopsDB->query('SELECT name FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_dir') . " WHERE dirid = '" . $dirid . '\'');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
248
    $num_results = $GLOBALS['xoopsDB']->getRowsNum($result);
249
    if (!$result) {
250
        return 0;
251
    }
252
    for ($i = 0; $i < $num_results; ++$i) {
253
        $row     = $GLOBALS['xoopsDB']->fetchBoth($result);
254
        $dirname = $row['name'];
255
    }
256
257
    return $dirname;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $dirname does not seem to be defined for all execution paths leading up to this point.
Loading history...
258
}
259
260
/**
261
 * @param int $cid
262
 * @return int
263
 */
264
function getCatTitleFromId($cid = 0)
265
{
266
    global $xoopsDB;
267
    //$block = array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
268
    $myts        = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
269
    $result      = $xoopsDB->query('SELECT title FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_cat') . " WHERE cid = '" . $cid . '\'');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
270
    $num_results = $GLOBALS['xoopsDB']->getRowsNum($result);
271
    if (!$result) {
272
        return 0;
273
    }
274
    for ($i = 0; $i < $num_results; ++$i) {
275
        $row      = $GLOBALS['xoopsDB']->fetchBoth($result);
276
        $cattitle = $row['title'];
277
    }
278
279
    return $cattitle;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $cattitle does not seem to be defined for all execution paths leading up to this point.
Loading history...
280
}
281
282
/**
283
 * @param $get_itemid
284
 * @return int|string
285
 */
286
function getCategoriesPaths($get_itemid)
0 ignored issues
show
Unused Code introduced by
The parameter $get_itemid is not used and could be removed. ( Ignorable by Annotation )

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

286
function getCategoriesPaths(/** @scrutinizer ignore-unused */ $get_itemid)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
287
{
288
    global $efqtree, $xoopsDB, $get_itemid, $get_dirid, $xoopsUser, $xoopsModule;
289 View Code Duplication
    if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
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...
290
        $isadmin = true;
291
    } else {
292
        $isadmin = false;
293
    }
294
    $result      = $xoopsDB->query('SELECT xid, cid, itemid FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_item_x_cat') . ' WHERE itemid = ' . $get_itemid . " AND active='1'");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
295
    $num_results = $GLOBALS['xoopsDB']->getRowsNum($result);
296
    if (!$result) {
297
        return 0;
298
    }
299
    $output = '';
300
    for ($i = 0; $i < $num_results; ++$i) {
301
        $row    = $GLOBALS['xoopsDB']->fetchBoth($result);
302
        $cid    = $row['cid'];
303
        $path   = '';
304
        $path   .= $efqtree->getUnformattedPathFromId($cid, 'title', $path);
305
        $path   .= '<br>';
306
        $output .= $path;
307
    }
308
    if ($isadmin) {
309
        $output .= '<br><a href="admin/categories.php?dirid=' . $get_dirid . '">' . _MD_EDITCATEGORIES . '</a>';
310
    }
311
312
    //$output .= "<br><a href=\"editcategories.php?item=".$get_itemid."\">["._MD_EDIT_CATEGORIES."]</a>";
313
    return $output;
314
}
315
316
/**
317
 * @param int $currentoption
318
 * @param     $breadcrumb
319
 */
320
function adminmenu($currentoption = 0, $breadcrumb)
321
{
322
    global $xoopsModule, $xoopsConfig;
323
    $tblColors                 = array();
324
    $tblColors[0]              = $tblColors[1] = $tblColors[2] = $tblColors[3] = $tblColors[4] = $tblColors[5] = $tblColors[6] = $tblColors[7] = '#DDE';
325
    $tblColors[$currentoption] = 'white';
326
    echo "<table width=100% class='outer'><tr><td align=right>
327
        <font size=2>" . $xoopsModule->name() . ':' . $breadcrumb . '</font>
328
        </td></tr></table><br>';
329
    echo '<div id="navcontainer"><ul style="padding: 3px 0; margin-left:
330
        0;font: bold 12px Verdana, sans-serif; ">';
331
    echo '<li style="list-style: none; margin: 0; display: inline; ">
332
        <a href="index.php" style="padding: 3px 0.5em;
333
        margin-left: 3px;
334
        border: 1px solid #778; background: ' . $tblColors[0] . ';
335
        text-decoration: none; ">' . _MD_A_MODADMIN_HOME . '</a></li>';
336
    echo '<li style="list-style: none; margin: 0; display: inline; ">
337
        <a href="directories.php" style="padding: 3px 0.5em;
338
        margin-left: 3px;
339
        border: 1px solid #778; background: ' . $tblColors[1] . ';
340
        text-decoration: none; ">' . _MD_A_DIRADMIN . '</a></li>';
341
    echo '<li style="list-style: none; margin: 0; display: inline; ">
342
        <a href="fieldtypes.php" style="padding: 3px 0.5em;
343
        margin-left: 3px;
344
        border: 1px solid #778; background: ' . $tblColors[2] . ';
345
        text-decoration: none; ">' . _MD_A_FTYPESADMIN . '</a></li>';
346
    // echo "<li style=\"list-style: none; margin: 0; display: inline; \">
347
    //         <a href=\"addresstypes.php\" style=\"padding: 3px 0.5em;
348
    //         margin-left: 3px;
349
    //         border: 1px solid #778; background: ".$tblColors[3].";
350
    //         text-decoration: none; \">"._MD_A_ATYPESADMIN."</a></li>";
351
    echo '<li style="list-style: none; margin: 0; display: inline; ">
352
        <a href="subscriptions.php" style="padding: 3px 0.5em;
353
        margin-left: 3px;
354
        border: 1px solid #778; background: ' . $tblColors[4] . ';
355
        text-decoration: none; ">' . _MD_A_ASUBSCRIPTIONSADMIN . '</a></li>';
356
    echo '</div></ul>';
357
}
358
359
/**
360
 * @param string $typeid
361
 * @return int|string
362
 */
363 View Code Duplication
function getTypeFromId($typeid = '0')
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...
364
{
365
    global $xoopsDB;
366
    $myts        = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
367
    $result      = $xoopsDB->query('SELECT typename  FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_itemtypes') . " WHERE typeid = '" . $typeid . '\'');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
368
    $num_results = $xoopsDB->getRowsNum($result);
369
    $typename    = '';
370
    if (!$result) {
371
        return 0;
372
    }
373
    for ($i = 0; $i < $num_results; ++$i) {
374
        $row      = $GLOBALS['xoopsDB']->fetchBoth($result);
375
        $typename = $row['typename'];
376
    }
377
378
    return $typename;
379
}
380
381
/**
382
 * @param string $catid
383
 * @return int
384
 */
385 View Code Duplication
function getDirId($catid = '0')
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...
386
{
387
    global $xoopsDB;
388
    $myts        = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
389
    $result      = $xoopsDB->query('SELECT dirid  FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_cat') . " WHERE cid = '" . $catid . '\'');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
390
    $num_results = $xoopsDB->getRowsNum($result);
391
    $dirid       = 0;
392
    if (!$result) {
393
        return 0;
394
    }
395
    for ($i = 0; $i < $num_results; ++$i) {
396
        $row   = $GLOBALS['xoopsDB']->fetchBoth($result);
397
        $dirid = $row['dirid'];
398
    }
399
400
    return $dirid;
401
}
402
403
/**
404
 * @param string $catid
405
 * @return bool
406
 */
407
function checkDescription($catid = '0')
408
{
409
    global $xoopsDB;
410
    $myts        = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
411
    $result      = $xoopsDB->query('SELECT txtid FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_cat_txt') . " WHERE cid = '" . $catid . '\'');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
412
    $num_results = $xoopsDB->getRowsNum($result);
413
    $txtid       = false;
414
    if (!$result) {
415
        return false;
416
    }
417
    for ($i = 0; $i < $num_results; ++$i) {
418
        $row   = $GLOBALS['xoopsDB']->fetchBoth($result);
419
        $txtid = $row['txtid'];
420
    }
421
422
    return $txtid;
423
}
424
425
/**
426
 * @param string $get_catid
427
 * @return int|string
428
 */
429
function getTemplateFromCatid($get_catid = '0')
430
{
431
    global $xoopsDB;
432
    $myts        = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
433
    $result      = $xoopsDB->query('SELECT c.tplid, t.name  FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_cat_tpl') . ' c, ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_tpl') . " t WHERE c.tplid=t.tplid AND c.catid = '" . $get_catid . '\'');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
434
    $num_results = $xoopsDB->getRowsNum($result);
435
    $tplname     = '';
436
    if (!$result) {
437
        return 0;
438
    }
439
    for ($i = 0; $i < $num_results; ++$i) {
440
        $row     = $GLOBALS['xoopsDB']->fetchBoth($result);
441
        $tplname = $row['name'];
442
    }
443
444
    return $tplname;
445
}
446
447
/**
448
 * @param string $item
449
 * @param string $dirid
450
 * @return string
451
 */
452
function getCatSelectArea($item = '0', $dirid = '0')
453
{
454
    global $xoopsDB, $myts, $eh, $mytree, $moddir, $get_itemid;
455
    $sql        = 'SELECT c.cid, c.title, c.pid, c.allowlist, x.active FROM '
456
                  . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_cat')
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
457
                  . ' c LEFT JOIN '
458
                  . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_item_x_cat')
459
                  . ' x ON (c.cid=x.cid AND x.itemid='
460
                  . $item
461
                  . ")  WHERE c.dirid='"
462
                  . $dirid
463
                  . '\' AND c.pid=\'0\' AND c.active=\'1\'';
464
    $mainresult = $xoopsDB->query($sql);
465
    $numrows    = $xoopsDB->getRowsNum($mainresult);
466
    $output     = '<table>';
467
    if ($numrows > 0) {
468
        $cats   = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $cats is dead and can be removed.
Loading history...
469
        $output .= '<tr><td class="categoryHeader" colspan="2"><strong>' . _MD_CATTITLE . '</strong></td><td class="categoryHeader"><strong>' . _MD_SELECT . "</strong></td></tr>\n";
470
        $brench = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $brench is dead and can be removed.
Loading history...
471
        $tab    = '';
472
        while (list($cid, $title, $pid, $allowlist, $active) = $xoopsDB->fetchRow($mainresult)) {
473
            //For each cid, get all 'first children' using getFirstChildId() function
474 View Code Duplication
            if ($allowlist != '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...
475
                if ($active == '1') {
476
                    $checked = ' checked';
477
                } else {
478
                    $checked = '';
479
                }
480
                $checkbox = '<input type="checkbox" name="selected' . $cid . "\"$checked";
481
            } else {
482
                $checkbox = '&nbsp;';
483
            }
484
            $output .= '<tr><td><strong>' . $tab . '' . $title . "</strong></td><td>&nbsp;</td><td>$checkbox</td></tr>\n";
485
            $output .= getCatSelectAreaChildren($cid, 0, $dirid);
0 ignored issues
show
Unused Code introduced by
The call to getCatSelectAreaChildren() has too many arguments starting with $dirid. ( Ignorable by Annotation )

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

485
            $output .= /** @scrutinizer ignore-call */ getCatSelectAreaChildren($cid, 0, $dirid);

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...
486
        }
487
    } else {
488
        $output .= '<tr><td>' . _MD_NORESULTS . '</td></tr>';
489
    }
490
    $output .= '</table>';
491
492
    return $output;
493
}
494
495
/**
496
 * @param string $childid
497
 * @param string $level
498
 * @return string
499
 */
500
function getCatSelectAreaChildren($childid = '0', $level = '0')
501
{
502
    global $xoopsDB, $myts, $eh, $mytree, $get_dirid, $moddir, $get_itemid;
503
    $tab    = '&nbsp;';
504
    $level  = $level;
505
    $output = '';
506
    $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...
507
    for ($i = 0; $i < $level; ++$i) {
508
        $tab .= '&nbsp;&nbsp;&nbsp;&nbsp;';
509
    }
510
    $sql         = 'SELECT DISTINCT c.cid, c.title, c.pid, c.allowlist, x.active FROM '
511
                   . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_cat')
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
512
                   . ' c LEFT JOIN '
513
                   . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_item_x_cat')
514
                   . " x ON (c.cid=x.cid AND x.itemid='"
515
                   . $get_itemid
516
                   . '\')  WHERE c.dirid=\''
517
                   . $get_dirid
518
                   . '\' AND c.pid=\''
519
                   . $childid
520
                   . '\' AND c.active=\'1\'';
521
    $childresult = $xoopsDB->query($sql);
522
    $numrows     = $xoopsDB->getRowsNum($childresult);
523
    if ($numrows > 0) {
524
        while (list($cid, $title, $pid, $allowlist, $active) = $xoopsDB->fetchRow($childresult)) {
525 View Code Duplication
            if ($allowlist != '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...
526
                if ($active == '1') {
527
                    $checked = ' checked';
528
                } else {
529
                    $checked = '';
530
                }
531
                $checkbox = '<input type="checkbox" name="selected' . $cid . "\"$checked";
532
            } else {
533
                $checkbox = '&nbsp;';
534
            }
535
            $output   .= '<tr><td><strong>' . $tab . '' . $plus . '&nbsp;' . $title . "</td><td>&nbsp;</strong></td><td align=\"center\">$checkbox</td></tr>\n";
536
            $newlevel = $level + 1;
537
            $output   .= getCatSelectAreaChildren($cid, $newlevel);
538
        }
539
    }
540
541
    return $output;
542
}
543
544
/**
545
 * @param int $item
546
 * @return int
547
 */
548 View Code Duplication
function getDirIdFromItem($item = 0)
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...
549
{
550
    global $xoopsDB;
551
    $block       = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
552
    $myts        = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
553
    $dirid       = 0;
554
    $result      = $xoopsDB->query('SELECT dirid FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_items') . ' WHERE itemid = ' . $item . '');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
555
    $num_results = $xoopsDB->getRowsNum($result);
556
    if (!$result) {
557
        return 0;
558
    }
559
    for ($i = 0; $i < $num_results; ++$i) {
560
        $row   = $GLOBALS['xoopsDB']->fetchBoth($result);
561
        $dirid = $row['dirid'];
562
    }
563
564
    return $dirid;
565
}
566
567
/**
568
 * @param int $item
569
 * @return int
570
 */
571 View Code Duplication
function getUserIdFromItem($item = 0)
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...
572
{
573
    global $xoopsDB;
574
    $block       = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
575
    $myts        = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
576
    $userid      = 0;
577
    $result      = $xoopsDB->query('SELECT uid FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_items') . ' WHERE itemid = ' . $item . '');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
578
    $num_results = $xoopsDB->getRowsNum($result);
579
    if (!$result) {
580
        return 0;
581
    }
582
    for ($i = 0; $i < $num_results; ++$i) {
583
        $row    = $GLOBALS['xoopsDB']->fetchBoth($result);
584
        $userid = $row['uid'];
585
    }
586
587
    return $userid;
588
}
589
590
//updates rating data in itemtable for a given item
591
/**
592
 * @param $sel_id
593
 */
594
function updaterating($sel_id)
595
{
596
    global $xoopsDB;
597
    $query       = 'SELECT rating FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_votedata') . ' WHERE itemid = ' . $sel_id . '';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
598
    $voteresult  = $xoopsDB->query($query);
599
    $votesDB     = $xoopsDB->getRowsNum($voteresult);
600
    $totalrating = 0;
601
    while (list($rating) = $xoopsDB->fetchRow($voteresult)) {
602
        $totalrating += $rating;
603
    }
604
    $finalrating = $totalrating / $votesDB;
605
    $finalrating = number_format($finalrating, 4);
606
    $query       = 'UPDATE ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_items') . " SET rating=$finalrating, votes=$votesDB WHERE itemid = $sel_id";
607
    $xoopsDB->query($query) or exit();
608
}
609
610
/**
611
 * @param string $typeid
612
 * @return array|int
613
 */
614
function getAddressFields($typeid = '0')
615
{
616
    global $xoopsDB;
617
    $block        = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
618
    $myts         = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
619
    $dirid        = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $dirid is dead and can be removed.
Loading history...
620
    $addressarray = array();
621
    if ($typeid == '0') {
622
        $result = $xoopsDB->query('SELECT typeid, address, address2, zip, postcode, lat, lon, phone, fax, mobile, city, country, typename, uselocyn FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_address_types') . " WHERE defaultyn = '1'");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
623
    } else {
624
        $result = $xoopsDB->query('SELECT typeid, address, address2, zip, postcode, lat, lon, phone, fax, mobile, city, country, typename, uselocyn FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_address_types') . " WHERE typeid = '$typeid'");
625
    }
626
    $num_results = $xoopsDB->getRowsNum($result);
0 ignored issues
show
Unused Code introduced by
The assignment to $num_results is dead and can be removed.
Loading history...
627
    if (!$result) {
628
        return 0;
629
    }
630
    while (list($typeid, $address, $address2, $zip, $postcode, $lat, $lon, $phone, $fax, $mobile, $city, $country, $typename, $uselocyn) = $xoopsDB->fetchRow($result)) {
631
        $addressarray = array(
632
            'typeid'        => $typeid,
633
            'typename'      => $typename,
634
            'uselocyn'      => $uselocyn,
635
            'addressfields' => array(
636
                'address'  => $address,
637
                'address2' => $address2,
638
                'zip'      => $zip,
639
                'postcode' => $postcode,
640
                'lat'      => $lat,
641
                'lon'      => $lon,
642
                'phone'    => $phone,
643
                'fax'      => $fax,
644
                'mobile'   => $mobile,
645
                'city'     => $city,
646
                'country'  => $country
647
            )
648
        );
649
    }
650
651
    return $addressarray;
652
}
653
654
/**
655
 * @param string $addrid
656
 * @return array
657
 */
658
function getAddressValues($addrid = '0')
659
{
660
    global $xoopsDB;
661
    $myts         = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
662
    $addressarray = array();
663
    $result       = $xoopsDB->query('SELECT address, address2, zip, postcode, lat, lon, phone, fax, mobile, city, country FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_addresses') . " WHERE addrid = '$addrid'");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
664
    $num_results  = $xoopsDB->getRowsNum($result);
665
    if ($num_results == 0) {
666
        $addressarray = array('address' => '', 'address2' => '', 'zip' => '', 'postcode' => '', 'lat' => '', 'lon' => '', 'phone' => '', 'fax' => '', 'mobile' => '', 'city' => '', 'country' => '');
667
    }
668
    while (list($address, $address2, $zip, $postcode, $lat, $lon, $phone, $fax, $mobile, $city, $country) = $xoopsDB->fetchRow($result)) {
669
        $addressarray = array(
670
            'address'  => $address,
671
            'address2' => $address2,
672
            'zip'      => $zip,
673
            'postcode' => $postcode,
674
            'lat'      => $lat,
675
            'lon'      => $lon,
676
            'phone'    => $phone,
677
            'fax'      => $fax,
678
            'mobile'   => $mobile,
679
            'city'     => $city,
680
            'country'  => $country
681
        );
682
    }
683
684
    return $addressarray;
685
}
686
687
/**
688
 * @return string
689
 */
690
function getCatSelectArea2()
691
{
692
    global $xoopsDB, $myts, $eh, $mytree, $get_dirid, $moddir, $xoopsUser, $xoopsModule;
693 View Code Duplication
    if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
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...
694
        $isadmin = true;
695
    } else {
696
        $isadmin = false;
697
    }
698
    $sql        = 'SELECT cid, title, pid, allowlist FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_cat') . " WHERE dirid='" . $get_dirid . '\' AND pid=\'0\' AND active=\'1\'';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
699
    $mainresult = $xoopsDB->query($sql);
700
    $numrows    = $xoopsDB->getRowsNum($mainresult);
701
    $output     = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $output is dead and can be removed.
Loading history...
702
    if ($numrows > 0) {
703
        $cats          = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $cats is dead and can be removed.
Loading history...
704
        $output        = '<table class="categoryTable"><tr><td class="categoryHeader" colspan="2"><strong>' . _MD_CATTITLE . '</strong></td><td class="categoryHeader"><strong>' . _MD_SELECT . "</strong></td></tr>\n";
705
        $brench        = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $brench is dead and can be removed.
Loading history...
706
        $tab           = '';
707
        $selectablecat = false;
708
        while (list($cid, $title, $pid, $allowlist) = $xoopsDB->fetchRow($mainresult)) {
709
            //For each cid, get all 'first children' using getFirstChildId() function
710
            if ($allowlist != '0') {
711
                $checkbox      = '<input type="checkbox" name="selected' . $cid . '"';
712
                $selectablecat = true;
713
                //$checked = "";
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...
714
            } else {
715
                //$checked = " checked=checked";
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...
716
                $checkbox = '&nbsp;';
717
            }
718
            //$cats .= $cid."|";
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
719
            $output .= '<tr><td><strong>' . $tab . '' . $title . "</strong></td><td>&nbsp;</td><td align=\"center\">$checkbox</td></tr>\n";
720
            $output .= getCatSelectAreaChildren2($cid);
721
            if ($output !== '') {
722
                $selectablecat = true;
723
            }
724
        }
725
    } else {
726
        redirect_header(XOOPS_URL . "/modules/$moddir/index.php?dirid=$get_dirid", 2, _MD_NOACTIVECATEGORIES);
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...
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

726
        /** @scrutinizer ignore-call */ redirect_header(XOOPS_URL . "/modules/$moddir/index.php?dirid=$get_dirid", 2, _MD_NOACTIVECATEGORIES);
Loading history...
727
        exit();
728
        //$output = ""._MD_NORESULTS."";
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% 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...
729
    }
730
    if ($isadmin) {
731
        $output .= '<tr><td><br><a href="admin/categories.php?dirid=' . $get_dirid . '">' . _MD_EDITCATEGORIES . '</a></td></tr>';
732
    }
733
    $output .= '</table>';
734
    if ($selectablecat === false) {
735
        redirect_header(XOOPS_URL . "/modules/$moddir/index.php?dirid=$get_dirid", 2, _MD_NOACTIVECATEGORIES);
736
        exit();
737
    }
738
739
    return $output;
740
}
741
742
/**
743
 * @param string $childid
744
 * @param string $level
745
 * @return string
746
 */
747
function getCatSelectAreaChildren2($childid = '0', $level = '0')
748
{
749
    global $xoopsDB, $myts, $eh, $mytree, $get_dirid, $moddir;
750
    $tab    = '&nbsp;';
751
    $level  = $level;
752
    $output = '';
753
    $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...
754
    for ($i = 0; $i < $level; ++$i) {
755
        $tab .= '&nbsp;&nbsp;&nbsp;&nbsp;';
756
    }
757
    $sql         = 'SELECT cid, title, pid, allowlist FROM ' . $xoopsDB->prefix($module->getVar('dirname', 'n') . '_cat') . " WHERE dirid='" . (int)$get_dirid . '\' AND pid=\'' . (int)$childid . '\' AND active=\'1\'';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $module seems to be never defined.
Loading history...
758
    $childresult = $xoopsDB->query($sql);
759
    $numrows     = $xoopsDB->getRowsNum($childresult);
760
    if ($numrows > 0) {
761
        while (list($cid, $title, $pid, $allowlist) = $xoopsDB->fetchRow($childresult)) {
762
            if ($allowlist != '0') {
763
                $checkbox = '<input type="checkbox" name="selected' . $cid . '"';
764
            } else {
765
                $checkbox = '&nbsp;';
766
            }
767
            $output   .= '<tr><td><strong>' . $tab . '' . $plus . '&nbsp;' . $title . "</td><td>&nbsp;</strong></td><td align=\"center\">$checkbox</td></tr>\n";
768
            $newlevel = $level + 1;
769
            $output   .= getCatSelectAreaChildren($cid, $newlevel, $get_dirid);
0 ignored issues
show
Unused Code introduced by
The call to getCatSelectAreaChildren() has too many arguments starting with $get_dirid. ( Ignorable by Annotation )

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

769
            $output   .= /** @scrutinizer ignore-call */ getCatSelectAreaChildren($cid, $newlevel, $get_dirid);

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...
770
        }
771
    }
772
773
    return $output;
774
}
775