Completed
Push — master ( 923121...f83415 )
by Michael
02:52
created

modify.php ➔ ModAd()   F

Complexity

Conditions 30
Paths > 20000

Size

Total Lines 222
Code Lines 160

Duplication

Lines 11
Ratio 4.95 %

Importance

Changes 0
Metric Value
cc 30
eloc 160
nc 11943942
nop 1
dl 11
loc 222
rs 2
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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 43 and the first side effect is on line 23.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
-------------------------------------------------------------------------
4
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
23
include_once __DIR__ . '/header.php';
24
$moduleDirName = basename(__DIR__);
25
$main_lang     = '_' . strtoupper($moduleDirName);
26
require_once XOOPS_ROOT_PATH . '/modules/adslight/include/gtickets.php';
27
$myts      = MyTextSanitizer::getInstance();
28
$module_id = $xoopsModule->getVar('mid');
29
30
$groups        = ($xoopsUser instanceof XoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
0 ignored issues
show
Bug introduced by
The class XoopsUser does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
31
$gperm_handler = xoops_getHandler('groupperm');
32
$perm_itemid   = XoopsRequest::getInt('item_id', 0, 'POST');
33
34
//If no access
35 View Code Duplication
if (!$gperm_handler->checkRight('adslight_submit', $perm_itemid, $groups, $module_id)) {
1 ignored issue
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...
36
    redirect_header(XOOPS_URL . '/modules/adslight/index.php', 3, _NOPERM);
37
}
38
39
/**
40
 * @param $lid
41
 * @param $ok
42
 */
43
function ListingDel($lid, $ok)
0 ignored issues
show
Best Practice introduced by
The function ListingDel() has been defined more than once; this definition is ignored, only the first definition in admin/modify_ads.php (L375-410) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
44
{
45
    global $xoopsDB, $xoopsUser, $xoopsConfig, $xoopsTheme, $xoopsLogger, $moduleDirName, $main_lang;
1 ignored issue
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
46
47
    $result = $xoopsDB->query('SELECT usid FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lid) . '');
48
    list($usid) = $xoopsDB->fetchRow($result);
49
50
    $result1 = $xoopsDB->query('SELECT url FROM ' . $xoopsDB->prefix('adslight_pictures') . ' WHERE lid=' . $xoopsDB->escape($lid) . '');
51
52
    if ($xoopsUser) {
53
        $currentid = $xoopsUser->getVar('uid', 'E');
54
        if ($usid == $currentid) {
55
            if ($ok == 1) {
56
                while (list($purl) = $xoopsDB->fetchRow($result1)) {
57
                    if ($purl) {
58
                        $destination = XOOPS_ROOT_PATH . '/uploads/AdsLight';
59
                        if (file_exists("$destination/$purl")) {
60
                            unlink("$destination/$purl");
61
                        }
62
                        $destination2 = XOOPS_ROOT_PATH . '/uploads/AdsLight/thumbs';
63
                        if (file_exists("$destination2/thumb_$purl")) {
64
                            unlink("$destination2/thumb_$purl");
65
                        }
66
                        $destination3 = XOOPS_ROOT_PATH . '/uploads/AdsLight/midsize';
67
                        if (file_exists("$destination3/resized_$purl")) {
68
                            unlink("$destination3/resized_$purl");
69
                        }
70
71
                        $xoopsDB->queryF('DELETE FROM ' . $xoopsDB->prefix('adslight_pictures') . ' WHERE lid=' . $xoopsDB->escape($lid) . '');
72
                    }
73
                }
74
                $xoopsDB->queryF('DELETE FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lid) . '');
75
                redirect_header('index.php', 1, _ADSLIGHT_ANNDEL);
76
            } else {
77
                echo "<table width='100%' border='0' cellspacing='1' cellpadding='8'><tr class='bg4'><td valign='top'>\n";
78
                echo '<br><center>';
79
                echo '<strong>' . _ADSLIGHT_SURDELANN . '</strong><br><br>';
80
            }
81
            echo "[ <a href=\"modify.php?op=ListingDel&amp;lid=" . $lid . "&amp;ok=1\">" . _ADSLIGHT_OUI . "</a> | <a href=\"index.php\">" . _ADSLIGHT_NON . '</a> ]<br><br>';
82
            echo '</td></tr></table>';
83
        }
84
    }
85
}
86
87
/**
88
 * @param $r_lid
89
 * @param $ok
90
 */
91
function DelReply($r_lid, $ok)
92
{
93
    global $xoopsDB, $xoopsUser, $xoopsConfig, $xoopsTheme, $xoopsLogger, $moduleDirName, $main_lang;
1 ignored issue
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
94
95
    $result = $xoopsDB->query('SELECT l.usid, r.r_lid, r.lid, r.title, r.date, r.submitter, r.message, r.tele, r.email, r.r_usid FROM '
96
                              . $xoopsDB->prefix('adslight_listing')
97
                              . ' l LEFT JOIN '
98
                              . $xoopsDB->prefix('adslight_replies')
99
                              . ' r ON l.lid=r.lid  WHERE r.r_lid='
100
                              . $xoopsDB->escape($r_lid)
101
                              . '');
102
    list($usid, $r_lid, $rlid, $title, $date, $submitter, $message, $tele, $email, $r_usid) = $xoopsDB->fetchRow($result);
0 ignored issues
show
Unused Code introduced by
The assignment to $rlid is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $title is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $date is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $submitter is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $message is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $tele is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $email is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $r_usid is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
103
104
    if ($xoopsUser) {
105
        $currentid = $xoopsUser->getVar('uid', 'E');
106
        if ($usid == $currentid) {
107
            if ($ok == 1) {
108
                $xoopsDB->queryF('DELETE FROM ' . $xoopsDB->prefix('adslight_replies') . ' WHERE r_lid=' . $xoopsDB->escape($r_lid) . '');
109
                redirect_header('members.php?usid=' . addslashes($usid) . '', 1, _ADSLIGHT_ANNDEL);
110
            } else {
111
                echo "<table width='100%' border='0' cellspacing='1' cellpadding='8'><tr class='bg4'><td valign='top'>\n";
112
                echo '<br><center>';
113
                echo '<strong>' . _ADSLIGHT_SURDELANN . '</strong><br><br>';
114
            }
115
            echo "[ <a href=\"modify.php?op=DelReply&amp;r_lid="
116
                 . addslashes($r_lid)
117
                 . "&amp;ok=1\">"
118
                 . _ADSLIGHT_OUI
119
                 . "</a> | <a href=\"members.php?usid="
120
                 . addslashes($usid)
121
                 . "\">"
122
                 . _ADSLIGHT_NON
123
                 . '</a> ]<br><br>';
124
            echo '</td></tr></table>';
125
        }
126
    }
127
}
128
129
/**
130
 * @param $lid
131
 */
132
function ModAd($lid)
1 ignored issue
show
Coding Style introduced by
ModAd uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
ModAd uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
133
{
134
    global $xoopsDB, $xoopsModule, $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsTheme, $myts, $xoopsLogger, $moduleDirName, $main_lang;
1 ignored issue
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
135
136
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
137
    include_once XOOPS_ROOT_PATH . '/modules/adslight/include/functions.php';
138
    echo "<script language=\"javascript\">\nfunction CLA(CLA) { var MainWindow = window.open (CLA, \"_blank\",\"width=500,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no\");}\n</script>";
139
140
    include_once XOOPS_ROOT_PATH . '/modules/adslight/class/classifiedstree.php';
141
    $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
142
143
    $result = $xoopsDB->query('SELECT lid, cid, title, status, expire, type, desctext, tel, price, typeprice, typeusure, date, email, submitter, usid, town, country, contactby, premium, valid FROM '
144
                              . $xoopsDB->prefix('adslight_listing')
145
                              . ' WHERE lid='
146
                              . $xoopsDB->escape($lid)
147
                              . '');
148
    list($lid, $cide, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $usid, $town, $country, $contactby, $premium, $valid) = $xoopsDB->fetchRow($result);
0 ignored issues
show
Unused Code introduced by
The assignment to $valid is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
149
150
    $categories = adslight_MygetItemIds('adslight_submit');
151 View Code Duplication
    if (is_array($categories) && count($categories) > 0) {
1 ignored issue
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...
152
        if (!in_array($cide, $categories)) {
153
            redirect_header(XOOPS_URL . '/modules/adslight/index.php', 3, _NOPERM);
154
        }
155
    } else {    // User can't see any category
156
        redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
157
    }
158
159
    if ($xoopsUser) {
160
        $calusern = $xoopsUser->uid();
161
        if ($usid == $calusern) {
162
            echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _ADSLIGHT_MODIFANN . '</legend><br><br>';
163
            $title      = $myts->htmlSpecialChars($title);
164
            $status     = $myts->htmlSpecialChars($status);
165
            $expire     = $myts->htmlSpecialChars($expire);
166
            $type       = $myts->htmlSpecialChars($type);
167
            $desctext   = $myts->displayTarea($desctext, 1);
168
            $tel        = $myts->htmlSpecialChars($tel);
169
            $price      = number_format($price, 2, ',', ' ');
170
            $typeprice  = $myts->htmlSpecialChars($typeprice);
171
            $typeusure  = $myts->htmlSpecialChars($typeusure);
172
            $submitter  = $myts->htmlSpecialChars($submitter);
173
            $town       = $myts->htmlSpecialChars($town);
174
            $country    = $myts->htmlSpecialChars($country);
175
            $contactby  = $myts->htmlSpecialChars($contactby);
176
            $premium    = $myts->htmlSpecialChars($premium);
177
            $useroffset = '';
178 View Code Duplication
            if ($xoopsUser) {
1 ignored issue
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...
179
                $timezone   = $xoopsUser->timezone();
180
                $useroffset = (!empty($timezone)) ? $xoopsUser->timezone() : $xoopsConfig['default_TZ'];
181
            }
182
            $dates = ($useroffset * 3600) + $date;
0 ignored issues
show
Unused Code introduced by
$dates is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
183
            $dates = formatTimestamp($date, 's');
184
185
            echo "<form action=\"modify.php\" method=post enctype=\"multipart/form-data\">
186
    <table><tr class=\"head\" border=\"2\">
187
    <td class=\"head\">" . _ADSLIGHT_NUMANNN . " </td><td class=\"head\" border=\"1\">$lid " . _ADSLIGHT_DU . " $dates</td>
188
    </tr><tr>";
189
190
            if ($xoopsModuleConfig['adslight_diff_name'] == '1') {
191
                echo "<td class=\"head\">" . _ADSLIGHT_SENDBY . " </td><td class=\"head\"><input type=\"text\" name=\"submitter\" size=\"50\" value=\"$submitter\" /></td>";
192
            } else {
193
                echo "<td class=\"head\">" . _ADSLIGHT_SENDBY . " </td><td class=\"head\"><input type=\"hidden\" name=\"submitter\" value=\"$submitter\">$submitter</td>";
194
            }
195
            echo '</tr><tr>';
196
197
            if (1 == $contactby) {
198
                $contactselect = _ADSLIGHT_CONTACT_BY_EMAIL;
199
            }
200
            if (2 == $contactby) {
201
                $contactselect = _ADSLIGHT_CONTACT_BY_PM;
202
            }
203
            if (3 == $contactby) {
204
                $contactselect = _ADSLIGHT_CONTACT_BY_BOTH;
205
            }
206
            if (4 == $contactby) {
207
                $contactselect = _ADSLIGHT_CONTACT_BY_PHONE;
208
            }
209
210
            echo " <td class='head'>" . _ADSLIGHT_CONTACTBY . " </td><td class='head'><select name=\"contactby\">
211
    <option value=\"" . $contactby . "\">" . $contactselect . "</option>
0 ignored issues
show
Bug introduced by
The variable $contactselect does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
212
    <option value=\"1\">" . _ADSLIGHT_CONTACT_BY_EMAIL . "</option>
213
    <option value=\"2\">" . _ADSLIGHT_CONTACT_BY_PM . "</option>
214
    <option value=\"3\">" . _ADSLIGHT_CONTACT_BY_BOTH . "</option>
215
    <option value=\"4\">" . _ADSLIGHT_CONTACT_BY_PHONE . '</option></select></td></tr>';
216
217
            if ($xoopsModuleConfig['adslight_diff_email'] == '1') {
218
                echo "<tr><td class=\"head\">" . _ADSLIGHT_EMAIL . " </td><td class=\"head\"><input type=\"text\" name=\"email\" size=\"50\" value=\"$email\" /></td>";
219
            } else {
220
                echo "<tr><td class=\"head\">" . _ADSLIGHT_EMAIL . " </td><td class=\"head\">$email<input type=\"hidden\" name=\"email\" value=\"$email\" /></td>";
221
            }
222
            echo "</tr><tr>
223
    <td class=\"head\">" . _ADSLIGHT_TEL . " </td><td class=\"head\"><input type=\"text\" name=\"tel\" size=\"50\" value=\"$tel\" /></td>
224
    </tr>";
225
            echo "<tr>
226
    <td class=\"head\">" . _ADSLIGHT_TOWN . " </td><td class=\"head\"><input type=\"text\" name=\"town\" size=\"50\" value=\"$town\" /></td>
227
    </tr>";
228
            if ($xoopsModuleConfig['adslight_use_country'] == '1') {
229
                echo "<tr>
230
    <td class=\"head\">" . _ADSLIGHT_COUNTRY . " </td><td class=\"head\"><input type=\"text\" name=\"country\" size=\"50\" value=\"$country\" /></td>
231
    </tr>";
232
            } else {
233
                echo "<input type=\"hidden\" name=\"country\" value=\"\">";
234
            }
235
236
            echo "<tr><td class='head'>" . _ADSLIGHT_STATUS . "</td><td class='head'><input type=\"radio\" name=\"status\" value=\"0\"";
237
            if ('0' == $status) {
238
                echo 'checked';
239
            }
240
            echo '>' . _ADSLIGHT_ACTIVE . "&nbsp;&nbsp; <input type=\"radio\" name=\"status\" value=\"1\"";
241
            if ('1' == $status) {
242
                echo 'checked';
243
            }
244
            echo '>' . _ADSLIGHT_INACTIVE . "&nbsp;&nbsp; <input type=\"radio\" name=\"status\" value=\"2\"";
245
            if ('2' == $status) {
246
                echo 'checked';
247
            }
248
            echo '>' . _ADSLIGHT_SOLD . '</td></tr>';
249
            echo "<tr>
250
    <td class=\"head\">" . _ADSLIGHT_TITLE2 . " </td><td class=\"head\"><input type=\"text\" name=\"title\" size=\"50\" value=\"$title\" /></td>
251
    </tr>";
252
            echo "<tr><td class=\"head\">" . _ADSLIGHT_PRICE2 . " </td><td class=\"head\"><input type=\"text\" name=\"price\" size=\"20\" value=\"$price\" /> " . $xoopsModuleConfig['adslight_money'];
253
254
            $result3 = $xoopsDB->query('SELECT nom_price, id_price FROM ' . $xoopsDB->prefix('adslight_price') . ' ORDER BY id_price');
255
            echo " <select name=\"typeprice\">";
256
            while (list($nom_price, $id_price) = $xoopsDB->fetchRow($result3)) {
257
                $sel = '';
258
                if ($id_price == $typeprice) {
259
                    $sel = 'selected';
260
                }
261
                echo "<option value=\"$id_price\" $sel>$nom_price</option>";
262
            }
263
            echo '</select></td></tr>';
264
            $module_id = $xoopsModule->getVar('mid');
265
            $groups    = ($xoopsUser instanceof XoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
0 ignored issues
show
Bug introduced by
The class XoopsUser does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
266
267
            $gperm_handler = xoops_getHandler('groupperm');
268
            $perm_itemid   = XoopsRequest::getInt('item_id', 0, 'GET');
269
270
            //If no access
271
            if (!$gperm_handler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id)) {
272
                echo "<tr>
273
    <td width='30%' class='head'>" . _ADSLIGHT_WILL_LAST . " </td><td class='head'>$expire  " . _ADSLIGHT_DAY . '</td>
274
    </tr>';
275
                echo "<input type=\"hidden\" name=\"expire\" value=\"$expire\" />";
276
            } else {
277
                echo "<tr>
278
    <td width='30%' class='head'>" . _ADSLIGHT_HOW_LONG . " </td><td class='head'><input type=\"text\" name=\"expire\" size=\"3\" maxlength=\"3\" value=\"$expire\" />  " . _ADSLIGHT_DAY . '</td>
279
    </tr>';
280
            }
281
282
            /// Type d'annonce
283
            echo "<tr>
284
    <td class=\"head\">" . _ADSLIGHT_TYPE . " </td><td class=\"head\"><select name=\"type\">";
285
286
            $result5 = $xoopsDB->query('SELECT nom_type, id_type FROM ' . $xoopsDB->prefix('adslight_type') . ' ORDER BY nom_type');
287
            while (list($nom_type, $id_type) = $xoopsDB->fetchRow($result5)) {
288
                $sel = '';
289
                if ($id_type == $type) {
290
                    $sel = 'selected';
291
                }
292
                echo "<option value=\"$id_type\" $sel>$nom_type</option>";
293
            }
294
            echo '</select></td></tr>';
295
296
            /// Etat de l'objet
297
            echo "<tr>
298
    <td class=\"head\">" . _ADSLIGHT_TYPE_USURE . " </td><td class=\"head\"><select name=\"typeusure\">";
299
300
            $result6 = $xoopsDB->query('SELECT nom_usure, id_usure FROM ' . $xoopsDB->prefix('adslight_usure') . ' ORDER BY nom_usure');
301
            while (list($nom_usure, $id_usure) = $xoopsDB->fetchRow($result6)) {
302
                $sel = '';
303
                if ($id_usure == $typeusure) {
304
                    $sel = 'selected';
305
                }
306
                echo "<option value=\"$id_usure\" $sel>$nom_usure</option>";
307
            }
308
            echo '</select></td></tr>';
309
310
            echo "<tr>
311
    <td class=\"head\">" . _ADSLIGHT_CAT . " </td><td class=\"head\">";
312
            $mytree->makeMySelBox('title', 'title', $cide, '', 'cid');
313
            echo "</td>
314
    </tr><tr>
315
    <td class=\"head\">" . _ADSLIGHT_DESC . " </td><td class=\"head\">";
316
            $wysiwyg_text_area = adslight_getEditor(_ADSLIGHT_DESC, 'desctext', $desctext, '100%', '200px');
317
            echo $wysiwyg_text_area->render();
318
            echo "</td></tr>
319
    <td colspan=2><br><input type=\"submit\" value=\"" . _ADSLIGHT_MODIFANN . "\" /></td>
320
    </tr></table>";
321
            echo "<input type=\"hidden\" name=\"op\" value=\"ModAdS\" />";
322
323
            $module_id = $xoopsModule->getVar('mid');
324
            if (is_object($xoopsUser)) {
325
                $groups = $xoopsUser->getGroups();
326
            } else {
327
                $groups = XOOPS_GROUP_ANONYMOUS;
328
            }
329
            $gperm_handler = xoops_getHandler('groupperm');
330
            if (isset($_POST['item_id'])) {
331
                $perm_itemid = (int)$_POST['item_id'];
332
            } else {
333
                $perm_itemid = 0;
334
            }
335
            //If no access
336
            if (!$gperm_handler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id)) {
337
                if ($xoopsModuleConfig['adslight_moderated'] == '1') {
338
                    echo "<input type=\"hidden\" name=\"valid\" value=\"No\" />";
339
                    echo '<br>' . _ADSLIGHT_MODIFBEFORE . '<br>';
340
                } else {
341
                    echo "<input type=\"hidden\" name=\"valid\" value=\"Yes\" />";
342
                }
343
            } else {
344
                echo "<input type=\"hidden\" name=\"valid\" value=\"Yes\" />";
345
            }
346
            echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\" />";
347
            echo "<input type=\"hidden\" name=\"premium\" value=\"$premium\" />";
348
            echo "<input type=\"hidden\" name=\"date\" value=\"$date\" />
349
    " . $GLOBALS['xoopsGTicket']->getTicketHtml(__LINE__, 1800, 'token') . '';
350
            echo '</form><br></fieldset><br>';
351
        }
352
    }
353
}
354
355
/**
356
 * @param $lid
357
 * @param $cat
358
 * @param $title
359
 * @param $status
360
 * @param $expire
361
 * @param $type
362
 * @param $desctext
363
 * @param $tel
364
 * @param $price
365
 * @param $typeprice
366
 * @param $typeusure
367
 * @param $date
368
 * @param $email
369
 * @param $submitter
370
 * @param $town
371
 * @param $country
372
 * @param $contactby
373
 * @param $premium
374
 * @param $valid
375
 */
376
function ModAdS(
377
    $lid,
378
    $cat,
379
    $title,
380
    $status,
381
    $expire,
382
    $type,
383
    $desctext,
384
    $tel,
385
    $price,
386
    $typeprice,
387
    $typeusure,
388
    $date,
389
    $email,
390
    $submitter,
391
    $town,
392
    $country,
393
    $contactby,
394
    $premium,
395
    $valid
396
) {
397
    global $xoopsDB, $xoopsConfig, $xoopsModuleConfig, $myts, $xoopsLogger, $moduleDirName, $main_lang, $xoopsGTicket;
1 ignored issue
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
398
399
    if (!$xoopsGTicket->check(true, 'token')) {
400
        redirect_header(XOOPS_URL . '/modules/adslight/index.php', 3, $xoopsGTicket->getErrors());
401
    }
402
    $title     = $myts->addSlashes($title);
403
    $status    = $myts->addSlashes($status);
404
    $expire    = $myts->addSlashes($expire);
405
    $type      = $myts->addSlashes($type);
406
    $desctext  = $myts->displayTarea($desctext, 1, 1, 1, 1, 1);
407
    $tel       = $myts->addSlashes($tel);
408
    $price     = str_replace(array(' '), '', $price);
409
    $typeprice = $myts->addSlashes($typeprice);
410
    $typeusure = $myts->addSlashes($typeusure);
411
    $submitter = $myts->addSlashes($submitter);
412
    $town      = $myts->addSlashes($town);
413
    $country   = $myts->addSlashes($country);
414
    $contactby = $myts->addSlashes($contactby);
415
    $premium   = $myts->addSlashes($premium);
416
417
    $xoopsDB->query('UPDATE '
418
                    . $xoopsDB->prefix('adslight_listing')
419
                    . " SET cid='$cat', title='$title', status='$status',  expire='$expire', type='$type', desctext='$desctext', tel='$tel', price='$price', typeprice='$typeprice', typeusure='$typeusure', email='$email', submitter='$submitter', town='$town', country='$country', contactby='$contactby', premium='$premium', valid='$valid' WHERE lid=$lid");
420
421
    redirect_header('index.php', 1, _ADSLIGHT_ANNMOD2);
422
}
423
424
####################################################
425
foreach ($_POST as $k => $v) {
426
    ${$k} = $v;
427
}
428
$ok = isset($_GET['ok']) ? $_GET['ok'] : '';
429
430
if (!isset($_POST['lid']) && isset($_GET['lid'])) {
431
    $lid = $_GET['lid'];
432
}
433
if (!isset($_POST['r_lid']) && isset($_GET['r_lid'])) {
434
    $r_lid = $_GET['r_lid'];
435
}
436
if (!isset($_POST['op']) && isset($_GET['op'])) {
437
    $op = $_GET['op'];
438
}
439
switch ($op) {
440
441
    case 'ModAd':
442
        include XOOPS_ROOT_PATH . '/header.php';
443
        ModAd($lid);
444
        include XOOPS_ROOT_PATH . '/footer.php';
445
        break;
446
447
    case 'ModAdS':
448
        ModAdS($lid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $town, $country, $contactby, $premium, $valid);
449
        break;
450
451
    case 'ListingDel':
452
        include XOOPS_ROOT_PATH . '/header.php';
453
        ListingDel($lid, $ok);
454
        include XOOPS_ROOT_PATH . '/footer.php';
455
        break;
456
457
    case 'DelReply':
458
        include XOOPS_ROOT_PATH . '/header.php';
459
        DelReply($r_lid, $ok);
460
        include XOOPS_ROOT_PATH . '/footer.php';
461
        break;
462
463
    default:
464
        redirect_header('index.php', 1, '' . _RETURNANN . '');
465
        break;
466
}
467