Completed
Branch master (71f789)
by Michael
02:35
created

modify_ads.php ➔ modifyAdsS()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 48
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 40
nc 1
nop 20
dl 0
loc 48
rs 9.125
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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 32 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__ . '/admin_header.php';
24
25
$op = XoopsRequest::getCmd('op', 'liste');
26
27
/**
28
 * Main Ad Display
29
 *
30
 * @return void
31
 */
32
function index()
1 ignored issue
show
Best Practice introduced by
The function index() has been defined more than once; this definition is ignored, only the first definition in admin/main.php (L29-287) 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...
Coding Style introduced by
index 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...
33
{
34
    global $xoopsDB, $xoopsConfig, $xoopsModule, $myts, $desctext, $moduleDirName, $admin_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...
35
36
    $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
0 ignored issues
show
Unused Code introduced by
$mytree 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...
37
38
    include_once __DIR__ . '/header.php';
39
    xoops_cp_header();
40
    //    loadModuleAdminMenu(0, "");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
41
42
    // photo dir setting checker
43
    $photo_dir         = $GLOBALS['xoopsModuleConfig']['adslight_path_upload'];
44
    $photo_thumb_dir   = $GLOBALS['xoopsModuleConfig']['adslight_path_upload'] . '/thumbs';
45
    $photo_resized_dir = $GLOBALS['xoopsModuleConfig']['adslight_path_upload'] . '/midsize';
46
    if (!is_dir($photo_dir)) {
47
        mkdir($photo_dir);
48
    }
49
    if (!is_dir($photo_thumb_dir)) {
50
        mkdir($photo_thumb_dir);
51
    }
52
    if (!is_dir($photo_resized_dir)) {
53
        mkdir($photo_resized_dir);
54
    }
55 View Code Duplication
    if (!is_writable($photo_dir) || !is_readable($photo_dir)) {
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...
56
        echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_CHECKER . '</legend><br>';
57
        echo "<span style='color: #FF0000;'><b>" . _AM_ADSLIGHT_DIRPERMS . '' . $photo_dir . "</b></span><br><br>\n";
58
        echo '</fieldset><br>';
59
    }
60
61 View Code Duplication
    if (!is_writable($photo_thumb_dir) || !is_readable($photo_thumb_dir)) {
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...
62
        echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_CHECKER . '</legend><br>';
63
        echo "<span style='color: #FF0000;'><b>" . _AM_ADSLIGHT_DIRPERMS . '' . $photo_thumb_dir . "</b></span><br><br>\n";
64
        echo '</fieldset><br>';
65
    }
66
67 View Code Duplication
    if (!is_writable($photo_resized_dir) || !is_readable($photo_resized_dir)) {
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...
68
        echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_CHECKER . '</legend><br>';
69
        echo "<span style='color: #FF0000;'><b>" . _AM_ADSLIGHT_DIRPERMS . '' . $photo_resized_dir . "</b></span><br><br>\n";
70
        echo '</fieldset><br>';
71
    }
72
73
    $result  = $xoopsDB->query('SELECT lid, cid, title, status, expire, type, desctext, tel, price, typeprice, typeusure, date, email, submitter, town, country, contactby, premium, photo, usid FROM '
74
                               . $xoopsDB->prefix('adslight_listing')
75
                               . " WHERE valid='no' ORDER BY lid");
76
    $numrows = $xoopsDB->getRowsNum($result);
77 View Code Duplication
    if ($numrows > 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...
78
79
        ///////// Il y a [..] Annonces en attente d'être approuvées //////
80
        echo "<table class='outer' border=0 cellspacing=5 cellpadding=0><tr><td width=40>";
81
        echo "<img src='../assets/images/admin/error_button.png' border=0 /></td><td>";
82
        echo "<span style='color:#00B4C4'><b>" . _AM_ADSLIGHT_THEREIS . "</b></span> <b>$numrows</b> <span style='color:#00B4C4'>" . _AM_ADSLIGHT_WAIT . '</b></span>';
83
        echo '</td></tr></table><br>';
84
    } else {
85
        echo "<table class='outer' width='50%' border='0'><tr><td width=40>";
86
        echo "<img src='../assets/images/admin/search_button_green_32.png' border=0 alt=\"._AM_ADSLIGHT_RELEASEOK.\" /></td><td>";
87
        echo "<span style='color: #00B4C4;'><b>" . _AM_ADSLIGHT_NOANNVAL . '</b></span>';
88
        echo '</td></tr></table><br>';
89
    }
90
91
    // Modify Annonces
92
    list($numrows) = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ''));
93 View Code Duplication
    if ($numrows > 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...
94
        echo "<table width='100%' border='0' class='outer'><tr class='bg4'><td valign='top'>";
95
        echo "<form method=\"post\" action=\"modify_ads.php\">"
96
             . '<b>'
97
             . _AM_ADSLIGHT_MODANN
98
             . '</b><br><br>'
99
             . ''
100
             . _AM_ADSLIGHT_NUMANN
101
             . " <input type=\"text\" name=\"lid\" size=\"12\" maxlength=\"11\">&nbsp;&nbsp;"
102
             . "<input type=\"hidden\" name=\"op\" value=\"ModifyAds\">"
103
             . "<input type=\"submit\" value=\""
104
             . _AM_ADSLIGHT_MODIF
105
             . "\">"
106
             . '</form><br>';
107
        echo '</td></tr></table><br>';
108
    }
109
110
    echo "<table width='100%' border='0' cellspacing='1' cellpadding='8' style='border: 2px solid #DFE0E0;'><tr class='bg4'><td valign='top'>";
111
    echo "<a href=\"map.php\">" . _AM_ADSLIGHT_GESTCAT . "</a> | <a href=\"../index.php\">" . _AM_ADSLIGHT_ACCESMYANN . '</a>';
112
    echo '</td></tr></table><br>';
113
114
    xoops_cp_footer();
115
}
116
117
#  function modifyAds
118
#####################################################
119
/**
120
 * @param $lid
121
 */
122 View Code Duplication
function modifyAds($lid)
1 ignored issue
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...
Coding Style introduced by
modifyAds 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...
123
{
124
    global $xoopsDB, $xoopsModule, $xoopsConfig, $myts, $desctext, $moduleDirName, $admin_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...
125
126
    $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
127
128
    include_once __DIR__ . '/header.php';
129
    xoops_cp_header();
130
    //    loadModuleAdminMenu(0, "");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
131
    $id_price  = '';
132
    $nom_price = '';
133
    $lid       = (int)$lid;
134
135
    echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_MODANN . '</legend>';
136
137
    $result = $xoopsDB->query('SELECT lid, cid, title, status, expire, type, desctext, tel, price, typeprice, typeusure, date, email, submitter, town, country, contactby, premium, valid, photo FROM '
138
                              . $xoopsDB->prefix('adslight_listing')
139
                              . " WHERE lid=$lid");
140
141
    while (list($lid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $town, $country, $contactby, $premium, $valid, $photo) = $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...
142
        $title     = $myts->htmlSpecialChars($title);
143
        $status    = $myts->htmlSpecialChars($status);
144
        $expire    = $myts->htmlSpecialChars($expire);
145
        $type      = $myts->htmlSpecialChars($type);
146
        $desctext  = $myts->displayTarea($desctext, 1, 1, 1);
147
        $tel       = $myts->htmlSpecialChars($tel);
148
        $price     = number_format($price, 2, ',', ' ');
149
        $typeprice = $myts->htmlSpecialChars($typeprice);
150
        $typeusure = $myts->htmlSpecialChars($typeusure);
151
        $submitter = $myts->htmlSpecialChars($submitter);
152
        $town      = $myts->htmlSpecialChars($town);
153
        $country   = $myts->htmlSpecialChars($country);
154
        $contactby = $myts->htmlSpecialChars($contactby);
155
        $premium   = $myts->htmlSpecialChars($premium);
156
157
        $date2 = formatTimestamp($date, 's');
158
159
        echo "<form action=\"modify_ads.php\" method=post>
160
            <table border=0><tr class='head' border='1'>
161
            <td>" . _AM_ADSLIGHT_NUMANN . " </td><td>$lid &nbsp;" . _AM_ADSLIGHT_ADDED_ON . "&nbsp; $date2</td>
162
            </tr><tr class='head' border='1'>
163
            <td>" . _AM_ADSLIGHT_SENDBY . " </td><td>$submitter</td>
164
            </tr><tr class='head' border='1'>
165
            <td>" . _AM_ADSLIGHT_EMAIL . " </td><td><input type=\"text\" name=\"email\" size=\"40\" value=\"$email\"></td>
166
            </tr><tr class='head' border='1'>
167
            <td>" . _AM_ADSLIGHT_TEL . " </td><td><input type=\"text\" name=\"tel\" size=\"50\" value=\"$tel\"></td>
168
            </tr><tr class='head' border='1'>
169
            <td>" . _AM_ADSLIGHT_TOWN . " </td><td><input type=\"text\" name=\"town\" size=\"40\" value=\"$town\"></td>
170
            </tr><tr class='head' border='1'>
171
            <td>" . _AM_ADSLIGHT_COUNTRY . " </td><td><input type=\"text\" name=\"country\" size=\"40\" value=\"$country\"></td>
172
            </tr></tr><tr class='head' border='1'>";
173
174
        if ($contactby == 1) {
175
            $contactselect = _AM_ADSLIGHT_CONTACT_BY_EMAIL;
176
        }
177
        if ($contactby == 2) {
178
            $contactselect = _AM_ADSLIGHT_CONTACT_BY_PM;
179
        }
180
        if ($contactby == 3) {
181
            $contactselect = _AM_ADSLIGHT_CONTACT_BY_BOTH;
182
        }
183
        if ($contactby == 4) {
184
            $contactselect = _AM_ADSLIGHT_CONTACT_BY_PHONE;
185
        }
186
187
        echo " <td class='head'>" . _AM_ADSLIGHT_CONTACTBY . " </td><td class='head'><select name=\"contactby\">
188
    <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...
189
    <option value=\"1\">" . _AM_ADSLIGHT_CONTACT_BY_EMAIL . "</option>
190
    <option value=\"2\">" . _AM_ADSLIGHT_CONTACT_BY_PM . "</option>
191
    <option value=\"3\">" . _AM_ADSLIGHT_CONTACT_BY_BOTH . "</option>
192
    <option value=\"4\">" . _AM_ADSLIGHT_CONTACT_BY_PHONE . '</option></select></td></tr>';
193
194
        echo "<tr><td class='head'>" . _AM_ADSLIGHT_STATUS . "</td><td class='head'><input type=\"radio\" name=\"status\" value=\"0\"";
195
        if ($status == '0') {
196
            echo 'checked';
197
        }
198
        echo '>' . _AM_ADSLIGHT_ACTIVE . "&nbsp;&nbsp; <input type=\"radio\" name=\"status\" value=\"1\"";
199
        if ($status == '1') {
200
            echo 'checked';
201
        }
202
        echo '>' . _AM_ADSLIGHT_INACTIVE . "&nbsp;&nbsp; <input type=\"radio\" name=\"status\" value=\"2\"";
203
        if ($status == '2') {
204
            echo 'checked';
205
        }
206
        echo '>' . _AM_ADSLIGHT_SOLD . '</td></tr>';
207
208
        echo "<tr class='head' border='1'>
209
            <td>" . _AM_ADSLIGHT_TITLE2 . " </td><td><input type=\"text\" name=\"title\" size=\"40\" value=\"$title\"></td>
210
            </tr><tr class='head' border='1'>
211
            <td>" . _AM_ADSLIGHT_PREMIUM . " </td><td><input type=\"text\" name=\"premium\" size=\"3\" value=\"$premium\"></td>
212
            </tr><tr class='head' border='1'>
213
            <td>" . _AM_ADSLIGHT_EXPIRE . " </td><td><input type=\"text\" name=\"expire\" size=\"40\" value=\"$expire\"></td>
214
            </tr>";
215
        ////// Type d'annonce
216
        echo "<tr class='head' border='1'>
217
            <td>" . _AM_ADSLIGHT_TYPE . " </td><td><select name=\"type\">";
218
219
        $result5 = $xoopsDB->query('SELECT nom_type, id_type FROM ' . $xoopsDB->prefix('adslight_type') . ' ORDER BY nom_type');
220
        while (list($nom_type, $id_type) = $xoopsDB->fetchRow($result5)) {
221
            $sel = '';
222
            if ($id_type == $type) {
223
                $sel = 'selected';
224
            }
225
            echo "<option value=\"{$id_type}\"{$sel}>{$nom_type}</option>";
226
        }
227
        echo '</select></td></tr>';
228
229
        ////// Etat d'usure
230
        echo "<tr class='head' border='1'>
231
            <td>" . _AM_ADSLIGHT_TYPE_USURE . " </td><td><select name=\"typeusure\">";
232
233
        $result6 = $xoopsDB->query('SELECT nom_usure, id_usure FROM ' . $xoopsDB->prefix('adslight_usure') . ' ORDER BY nom_usure');
234
        while (list($nom_usure, $id_usure) = $xoopsDB->fetchRow($result6)) {
235
            $sel = '';
236
            if ($id_usure == $typeusure) {
237
                $sel = 'selected';
238
            }
239
            echo "<option value=\"{$id_usure}\"{$sel}>{$nom_usure}</option>";
240
        }
241
        echo '</select></td></tr>';
242
243
        /////// Price
244
        echo "<tr class='head' border='1'><td>" . _AM_ADSLIGHT_PRICE2 . " </td><td><input type=\"text\" name=\"price\" size=\"20\" value=\"$price\"> " . $GLOBALS['xoopsModuleConfig']['adslight_money'] . '';
245
246
        //////// Price type
247
248
        $resultx = $xoopsDB->query('SELECT nom_price, id_price FROM ' . $xoopsDB->prefix('adslight_price') . ' ORDER BY nom_price');
249
250
        echo " <select name=\"typeprice\"><option value=\"$id_price\">$nom_price</option>";
251
        while (list($nom_price, $id_price) = $xoopsDB->fetchRow($resultx)) {
252
            $sel = '';
253
            if ($id_price == $typeprice) {
254
                $sel = 'selected';
255
            }
256
            echo "<option value=\"{$id_price}\"{$sel}>{$nom_price}</option>";
257
        }
258
        echo '</select></td>';
259
260
        /////// Category
261
262
        echo "<tr class='head' border='1'>
263
            <td>" . _AM_ADSLIGHT_CAT2 . ' </td><td>';
264
        $mytree->makeMySelBox('title', 'title', $cid);
265
        echo "</td>
266
            </tr><tr class='head' border='1'>
267
            <td>" . _AM_ADSLIGHT_DESC . ' </td><td>';
268
269
        $wysiwyg_text_area = AdslightUtilities::getEditor('', 'desctext', $desctext, '100%', '200px', 'small');
270
        echo $wysiwyg_text_area->render();
271
272
        echo '</td></tr>';
273
274
        echo "<tr class='head' border='1'>
275
            <td>" . _AM_ADSLIGHT_PHOTO1 . " </td><td><input type=\"text\" name=\"photo\" size=\"50\" value=\"$photo\"></td>
276
            </tr><tr>";
277
        $time = time();
278
        echo "</tr><tr class='head' border='1'>
279
            <td>&nbsp;</td><td><select name=\"op\">
280
            <option value=\"ModifyAdsS\"> " . _AM_ADSLIGHT_MODIF . "
281
            <option value=\"ListingDel\"> " . _AM_ADSLIGHT_DEL . "
282
            </select><input type=\"submit\" value=\"" . _AM_ADSLIGHT_GO . "\"></td>
283
            </tr></table>";
284
        echo "<input type=\"hidden\" name=\"valid\" value=\"Yes\">";
285
        echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">";
286
        echo "<input type=\"hidden\" name=\"date\" value=\"$time\">";
287
        echo "<input type=\"hidden\" name=\"submitter\" value=\"$submitter\">
288
        </form><br>";
289
        echo '</fieldset><br>';
290
        xoops_cp_footer();
291
    }
292
}
293
294
#  function modifyAdsS
295
#####################################################
296
297
/**
298
 * @param $lid
299
 * @param $cat
300
 * @param $title
301
 * @param $status
302
 * @param $expire
303
 * @param $type
304
 * @param $desctext
305
 * @param $tel
306
 * @param $price
307
 * @param $typeprice
308
 * @param $typeusure
309
 * @param $date
310
 * @param $email
311
 * @param $submitter
312
 * @param $town
313
 * @param $country
314
 * @param $contactby
315
 * @param $premium
316
 * @param $valid
317
 * @param $photo
318
 */
319
function modifyAdsS(
320
    $lid,
321
    $cat,
322
    $title,
323
    $status,
324
    $expire,
325
    $type,
326
    $desctext,
327
    $tel,
328
    $price,
329
    $typeprice,
330
    $typeusure,
331
    $date,
332
    $email,
333
    $submitter,
334
    $town,
335
    $country,
336
    $contactby,
337
    $premium,
338
    $valid,
339
    $photo
340
) {
341
    global $xoopsDB, $xoopsConfig, $myts, $moduleDirName, $admin_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...
342
343
    $lid   = (int)$lid;
344
    $cat   = (int)$cat;
345
    $title = $myts->htmlSpecialChars($title);
346
    //    $status    = $myts->htmlSpecialChars($status);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
347
    $status    = (int)$status;
348
    $expire    = $myts->htmlSpecialChars($expire);
349
    $type      = $myts->htmlSpecialChars($type);
350
    $desctext  = $myts->displayTarea($desctext, 1, 1, 1);
351
    $tel       = $myts->htmlSpecialChars($tel);
352
    $price     = str_replace(array(' '), '', $price);
353
    $typeprice = $myts->htmlSpecialChars($typeprice);
354
    $typeusure = $myts->htmlSpecialChars($typeusure);
355
    $submitter = $myts->htmlSpecialChars($submitter);
356
    $town      = $myts->htmlSpecialChars($town);
357
    $country   = $myts->htmlSpecialChars($country);
358
    $contactby = $myts->htmlSpecialChars($contactby);
359
    $premium   = $myts->htmlSpecialChars($premium);
360
361
    $xoopsDB->query('UPDATE '
362
                    . $xoopsDB->prefix('adslight_listing')
363
                    . " SET cid='$cat', title='$title', status='$status', expire='$expire', type='$type', desctext='$desctext', tel='$tel', price='$price', typeprice='$typeprice', typeusure='$typeusure', date='$date', email='$email', submitter='$submitter', town='$town', country='$country', contactby='$contactby', premium='$premium', valid='$valid', photo='$photo' WHERE lid=$lid");
364
365
    redirect_header('modify_ads.php', 1, _AM_ADSLIGHT_ANNMOD);
366
}
367
368
/**
369
 * Delete Listing
370
 *
371
 * @param  int    $lid
372
 * @param  string $photo
373
 * @return void
374
 */
375 View Code Duplication
function listingDel($lid, $photo)
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...
376
{
377
    global $xoopsDB, $moduleDirName, $admin_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...
378
379
    $lid = (int)$lid;
380
381
    $result2 = $xoopsDB->query('SELECT p.url FROM '
382
                               . $xoopsDB->prefix('adslight_listing')
383
                               . ' l LEFT JOIN '
384
                               . $xoopsDB->prefix('adslight_pictures')
385
                               . ' p  ON l.lid=p.lid WHERE l.lid='
386
                               . $xoopsDB->escape($lid)
387
                               . '');
388
389
    while (list($purl) = $xoopsDB->fetchRow($result2)) {
390
        if ($purl) {
391
            $destination = XOOPS_ROOT_PATH . '/uploads/AdsLight';
392
            if (file_exists("$destination/$purl")) {
393
                unlink("$destination/$purl");
394
            }
395
            $destination2 = XOOPS_ROOT_PATH . '/uploads/AdsLight/thumbs';
396
            if (file_exists("$destination2/thumb_$purl")) {
397
                unlink("$destination2/thumb_$purl");
398
            }
399
            $destination3 = XOOPS_ROOT_PATH . '/uploads/AdsLight/midsize';
400
            if (file_exists("$destination3/resized_$purl")) {
401
                unlink("$destination3/resized_$purl");
402
            }
403
            $xoopsDB->query('DELETE FROM ' . $xoopsDB->prefix('adslight_pictures') . " WHERE lid={$lid}");
404
        }
405
    }
406
407
    $xoopsDB->query('DELETE FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE lid={$lid}");
408
409
    redirect_header('modify_ads.php', 1, _AM_ADSLIGHT_ANNDEL);
410
}
411
412
#####################################################
413
#####################################################
414
//@todo REMOVE THIS ASAP. This code is extremely unsafe
415
foreach ($_POST as $k => $v) {
416
    ${$k} = $v;
417
}
418
$pa  = XoopsRequest::getString('pa', '', 'GET');
419
$lid = XoopsRequest::getInt('lid', 0);
420
$op  = XoopsRequest::getCmd('op', '');
421
422
switch ($op) {
423
    case 'IndexView':
424
        indexView($lid);
425
        break;
426
427
    case 'ListingDel':
428
        listingDel($lid, $photo);
429
        break;
430
431
    case 'ModifyAds':
432
        modifyAds($lid);
433
        break;
434
435
    case 'ModifyAdsS':
436
        modifyAdsS($lid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $town, $country, $contactby, $premium, $valid, $photo);
437
        break;
438
439
    default:
440
        index();
441
        break;
442
}
443