Completed
Push — master ( 635f68...66b59e )
by Michael
01:25
created

XdonationsUtility::checkVerXoops()   D

Complexity

Conditions 9
Paths 40

Size

Total Lines 39
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 27
nc 40
nop 2
dl 0
loc 39
rs 4.909
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Class MyalbumUtil
5
 */
6
class XdonationsUtility extends XoopsObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    /**
9
     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
10
     *
11
     * @param string $folder The full path of the directory to check
12
     *
13
     * @return void
14
     */
15
    public static function createFolder($folder)
16
    {
17
        //        try {
18
        //            if (!mkdir($folder) && !is_dir($folder)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
19
        //                throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
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...
20
        //            } else {
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...
21
        //                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
22
        //            }
23
        //        }
24
        //        catch (Exception $e) {
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...
25
        //            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
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...
26
        //        }
27
        try {
28
            if (!file_exists($folder)) {
29
                if (!mkdir($folder) && !is_dir($folder)) {
30
                    throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
31
                }
32
                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
33
            }
34
        } catch (Exception $e) {
35
            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
36
        }
37
    }
38
39
    /**
40
     * @param $file
41
     * @param $folder
42
     * @return bool
43
     */
44
    public static function copyFile($file, $folder)
45
    {
46
        return copy($file, $folder);
47
        //        try {
48
        //            if (!is_dir($folder)) {
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...
49
        //                throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder));
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...
50
        //            } else {
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...
51
        //                return copy($file, $folder);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
52
        //            }
53
        //        } catch (Exception $e) {
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...
54
        //            echo 'Caught exception: ', $e->getMessage(), "\n", "<br>";
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...
55
        //        }
56
        //        return false;
57
    }
58
59
    /**
60
     * @param $src
61
     * @param $dst
62
     */
63
    public static function recurseCopy($src, $dst)
64
    {
65
        $dir = opendir($src);
66
        //    @mkdir($dst);
67
        while (false !== ($file = readdir($dir))) {
68
            if (($file !== '.') && ($file !== '..')) {
69
                if (is_dir($src . '/' . $file)) {
70
                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
71
                } else {
72
                    copy($src . '/' . $file, $dst . '/' . $file);
73
                }
74
            }
75
        }
76
        closedir($dir);
77
    }
78
79
    /**
80
     *
81
     * Verifies XOOPS version meets minimum requirements for this module
82
     * @static
83
     * @param XoopsModule $module
0 ignored issues
show
Documentation introduced by
Should the type for parameter $module not be null|XoopsModule?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
84
     *
85
     * @param null|string $requiredVer
86
     * @return bool true if meets requirements, false if not
87
     */
88
    public static function checkVerXoops(XoopsModule $module = null, $requiredVer = null)
89
    {
90
        $moduleDirName = basename(dirname(__DIR__));
91
        if (null === $module) {
92
            $module = XoopsModule::getByDirname($moduleDirName);
93
        }
94
        xoops_loadLanguage('admin', $moduleDirName);
95
        //check for minimum XOOPS version
96
        $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string
97
        $currArray  = explode('.', $currentVer);
98
        if (null === $requiredVer) {
99
            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
100
        }
101
        $reqArray = explode('.', $requiredVer);
102
        $success  = true;
103
        foreach ($reqArray as $k => $v) {
104
            if (isset($currArray[$k])) {
105
                if ($currArray[$k] > $v) {
106
                    break;
107
                } elseif ($currArray[$k] == $v) {
108
                    continue;
109
                } else {
110
                    $success = false;
111
                    break;
112
                }
113
            } else {
114
                if ((int)$v > 0) { // handles versions like x.x.x.0_RC2
115
                    $success = false;
116
                    break;
117
                }
118
            }
119
        }
120
121
        if (!$success) {
122
            $module->setErrors(sprintf(_AM_XDONATION_ERROR_BAD_XOOPS, $requiredVer, $currentVer));
123
        }
124
125
        return $success;
126
    }
127
128
    /**
129
     *
130
     * Verifies PHP version meets minimum requirements for this module
131
     * @static
132
     * @param XoopsModule $module
133
     *
134
     * @return bool true if meets requirements, false if not
135
     */
136
    public static function checkVerPhp(XoopsModule $module)
137
    {
138
        xoops_loadLanguage('admin', $module->dirname());
139
        // check for minimum PHP version
140
        $success = true;
141
        $verNum  = PHP_VERSION;
142
        $reqVer  = $module->getInfo('min_php');
143
        if (false !== $reqVer && '' !== $reqVer) {
144
            if (version_compare($verNum, $reqVer, '<')) {
145
                $module->setErrors(sprintf(_AM_XDONATION_ERROR_BAD_PHP, $reqVer, $verNum));
146
                $success = false;
147
            }
148
        }
149
150
        return $success;
151
    }
152
153
    /**
154
     * @param $curr
155
     * @return string
156
     */
157
    public static function defineCurrency($curr)
158
    {
159
        switch ($curr) {
160
            case 'AUD':
161
                $currencySign = _MD_XDONATION_CURR_AUD;
162
                break;
163
            case 'EUR':
164
                $currencySign = _MD_XDONATION_CURR_EUR;
165
                break;
166
            case 'GBP':
167
                $currencySign = _MD_XDONATION_CURR_GBP;
168
                break;
169
            case 'JPY':
170
                $currencySign = _MD_XDONATION_CURR_JPY;
171
                break;
172
            case 'CAD':
173
                $currencySign = _MD_XDONATION_CURR_CAD;
174
                break;
175
            case 'USD':
176
            default:
177
                $currencySign = _MD_XDONATION_CURR_USD;
178
                break;
179
        }
180
181
        return $currencySign;
182
    }
183
184
    /**
185
     * Get all Config fields from DB
186
     *
187
     * @return array
188
     */
189
    public static function getConfigInfo()
190
    {
191
        global $xoopsDB;
0 ignored issues
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...
192
193
        $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE subtype = '' OR subtype = 'array'";
194
        $cfgset    = $xoopsDB->query($query_cfg);
195
        $tr_config = array();
196
        while ($cfgset && $row = $xoopsDB->fetchArray($cfgset)) {
197
            $tr_config[$row['name']] = $row['value'];
198
        }
199
200
        return $tr_config;
201
    }
202
203
    /**
204
     * Get XOOPS Member Object
205
     *
206
     * @param  int $muser_id
207
     * @return FALSE - no member info avail for this id, SUCCESS - member object
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
208
     */
209
    public static function getUserInfo($muser_id)
210
    {
211
        global $xoopsDB;
0 ignored issues
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...
212
        $thisUser = false;
213
        if ((int)$muser_id > 0) {
214
            $memberHandler = xoops_getHandler('member');
215
            $thisUser      = $memberHandler->getUser($muser_id);
216
        }
217
218
        return $thisUser;
219
    }
220
221
    /**
222
     * Retrieve list of db table's field names
223
     *
224
     * EXAMPLE USAGE:
225
     *
226
     * $list=XdonationsUtility::runSimpleQuery($xoopsDB->prefix('donations_transactions'));
227
     *
228
     * @param  string $table_name DB table name
229
     * @param  string $key_col    (optional) table column name
230
     * @param  mixed  $key_val    (optional) table column value
231
     * @param  array  $ignore     (optional) list of values to ignore (clear)
232
     * @return mixed  FALSE - nothing found, SUCCESS - array() of values
233
     */
234
    public static function runSimpleQuery($table_name, $key_col = '', $key_val = '', $ignore = array())
235
    {
236
        global $xoopsDB;
0 ignored issues
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...
237
        // open the db
238
        //    $db_link = mysqli_connect(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS);
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
239
        $keys = '';
240
        if ($key_col != '' && $key_val != '') {
241
            $keys = "WHERE $key_col = $key_val";
242
        }
243
        // query table using key col/val
244
        $simple_q   = false;
245
        $db_rs      = $xoopsDB->query("SELECT * FROM $table_name $keys");
246
        $num_fields = $xoopsDB->getFieldsNum($db_rs);
247
        if ($num_fields) {
248
            // first (and only) row
249
            $simple_q = array();
250
            $row      = $xoopsDB->fetchArray($db_rs);
251
            // load up array
252
            if ($key_col != '' && $key_val != '') {
253 View Code Duplication
                for ($i = 0; $i < $num_fields; ++$i) {
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...
254
                    $var            = '';
0 ignored issues
show
Unused Code introduced by
$var 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...
255
                    $var            = $xoopsDB->getFieldName($db_rs, $i);
256
                    $simple_q[$var] = $row[$var];
257
                }
258
            } else {
259 View Code Duplication
                for ($i = 0; $i < $num_fields; ++$i) {
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...
260
                    $var = '';
0 ignored issues
show
Unused Code introduced by
$var 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...
261
                    $var = $xoopsDB->getFieldName($db_rs, $i);
262
                    if (!in_array($var, $ignore)) {
263
                        $simple_q[$var] = '';
264
                    }
265
                }
266
            }
267
        }
268
        $xoopsDB->freeRecordSet($db_rs);
269
270
        return $simple_q;
271
    }
272
273
    /*
274
     * Functions for Administration display
275
     */
276
277
    /**
278
     * Display a Config Option html Option Box in a 2 column table row
279
     *
280
     * @param string $name name of config variable in config DB table
281
     * @param string $desc description of option box
282
     */
283
    public static function showYNBox($name, $desc)
284
    {
285
        global $tr_config, $modversion, $xoopsDB;
0 ignored issues
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...
286
287
        $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '{$name}'";
288
        $cfgset    = $xoopsDB->query($query_cfg);
289
        if ($cfgset) {
290
            $cfg  = $xoopsDB->fetchArray($cfgset);
291
            $text = htmlentities($cfg['text']);
292
            echo "<tr>\n" . "  <td title=\"{$text}\" style=\"text-align: right;\">{$desc}</td>\n" . "  <td title=\"{$text}\" style=\"text-align: left;\">";
293
            echo "    <select size=\"1\" name=\"var_{$name}\">";
294
            if ($cfg['value']) {
295
                echo '      <option selected value="1">' . _YES . '</option>' . '      <option value="0">' . _NO . '</option>';
296
            } else {
297
                echo '      <option value="1">' . _YES . '</option>' . '      <option selected value="0">' . _NO . '</option>';
298
            }
299
            echo "    </select>\n";
300
            echo "  </td>\n";
301
            echo "</tr>\n";
302
        }
303
    }
304
305
    /**
306
     * Display a Config option HTML Select Box in 2 column table
307
     *
308
     * @param string $name name of config DB table column
309
     * @param string $desc description of select box to show
310
     */
311
    public static function showDropBox($name, $desc)
312
    {
313
        global $tr_config, $modversion, $xoopsDB;
0 ignored issues
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...
314
315
        $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '{$name}'";
316
        $cfgset    = $xoopsDB->query($query_cfg);
317
        if ($cfgset) {
318
            $cfg  = $xoopsDB->fetchArray($cfgset);
319
            $text = htmlentities($cfg['text']);
320
            echo "<tr style=\"text-align: center;\">\n" . "  <td title=\"{$text}\" style=\"text-align: right; width: 50%;\">{$desc}</td>\n" . "  <td title=\"{$text}\" style=\"text-align: left;\">\n";
321
            echo "    <select size=\"1\" name=\"var_{$name}-array\">\n";
322
            if (isset($cfg['value'])) {
323
                $splitArr = explode('|', $cfg['value']);
324
                $i        = 0;
325
                while ($i < count($splitArr)) {
326
                    $selected = (0 == $i) ? ' selected' : '';
327
                    echo "      <option{$selected} value=\"{$splitArr[$i]}\">{$splitArr[$i]}</option>\n";
328
                    ++$i;
329
                }
330
            }
331
            echo "    </select>\n";
332
            echo "  </td>\n";
333
            echo "</tr>\n";
334
        }
335
    }
336
337
    /**
338
     * Display Config Array Drop Box in HTML 2 column table row
339
     *
340
     * @param string $name    name of DB column in config table
341
     * @param string $desc    description to display for select box
342
     * @param array  $x_array array( array($value1, $attrib1), array(...) )
343
     */
344
    public static function showArrayDropBox($name, $desc, $x_array)
345
    {
346
        global $tr_config, $modversion, $xoopsDB;
0 ignored issues
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...
347
        $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '{$name}' LIMIT 1";
348
        $cfgset    = $xoopsDB->query($query_cfg);
349
        if ($cfgset) {
350
            $cfg  = $xoopsDB->fetchArray($cfgset);
351
            $text = htmlentities($cfg['text']);
352
            echo "<tr>\n" . "  <td title=\"{$text}\" style=\"text-align: right;\">{$desc}</td>\n" . "  <td title=\"{$text}\" style=\"text-align: left;\">\n";
353
            echo "    <select size=\"1\" name=\"var_{$name}\">\n";
354
            if (isset($cfg['value'])) {
355
                if (0 == $cfg['value']) {
356
                    echo "      <option selected value=\"0\">-------</option>\n";
357
                } else {
358
                    echo "      <option value=\"0\">-------</option>\n";
359
                }
360
                $i = 0;
361
                while ($i < count($x_array)) {
362
                    $mvar     = $x_array[$i];
363
                    $selected = '';
364
                    if ($mvar[0] == $cfg['value']) {
365
                        $selected = ' selected';
366
                    }
367
                    echo "      <option{$selected} value=\"{$mvar[0]}\">{$mvar[1]}</option>\n";
368
                    ++$i;
369
                }
370
            }
371
            echo "    </select>\n";
372
            echo "  </td>\n";
373
            echo "</tr>\n";
374
        }
375
    }
376
377
    /**
378
     * Display Config Option Text Box in a 2 column table row
379
     *
380
     * @param string $name    name of DB column in config table
381
     * @param string $desc    description of text box to display
382
     * @param int    $tdWidth width of description field
383
     * @param int    $inpSize width of text input box
384
     * @param string $extra   extra info included in input box 'string'
385
     */
386
    public static function showTextBox($name, $desc, $tdWidth, $inpSize, $extra)
387
    {
388
        global $tr_config, $modversion, $xoopsDB;
0 ignored issues
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...
389
390
        $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '{$name}'";
391
        $cfgset    = $xoopsDB->query($query_cfg);
392
        if ($cfgset) {
393
            $cfg  = $xoopsDB->fetchArray($cfgset);
394
            $text = htmlentities($cfg['text']);
395
            echo "<tr>\n"
396
                 . "  <td title=\"{$text}\" style=\"text-align: right; width: {$tdWidth};\">{$desc}</td>\n"
397
                 . "  <td title=\"{$text}\" style=\"text-align: left;\">\n"
398
                 . "    <input size=\"{$inpSize}\" name=\"var_{$name}\" type=\"text\" value=\"{$cfg['value']}\"  {$extra}>\n"
399
                 . "  </td>\n"
400
                 . "</tr>\n";
401
        }
402
    }
403
404
    /************************************************************************
405
     *
406
     ***********************************************************************
407
     * @param $xnm
408
     * @param $ynm
409
     * @param $desc
410
     * @param $inpSize
411
     * @param $extra
412
     */
413
    public static function showImgXYBox($xnm, $ynm, $desc, $inpSize, $extra)
414
    {
415
        global $tr_config, $modversion, $xoopsDB;
0 ignored issues
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...
416
417
        $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '$xnm'";
418
        $cfgset    = $xoopsDB->query($query_cfg);
419
420
        if ($cfgset) {
421
            $cfg = $xoopsDB->fetchArray($cfgset);
422
423
            $text = htmlentities($cfg['text']);
424
            echo "<tr>\n" . "  <td title=\"{$text}\" style=\"text-align: right;\">{$desc}</td>\n" . "  <td title=\"{$text}\" style=\"text-align: left;\">\n";
425
            echo '    &nbsp;' . _AD_XDONATION_WIDTH . "&nbsp;\n" . "    <input size=\"{$inpSize}\" name=\"var_{$cfg['name']}\" type=\"text\" value=\"{$cfg['value']}\" {$extra}>\n";
426
427
            $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '$ynm'";
428
            $cfgset    = $xoopsDB->query($query_cfg);
429
            if ($cfgset) {
430
                $cfg = $xoopsDB->fetchArray($cfgset);
431
                echo '    &nbsp;&nbsp;' . _AD_XDONATION_HEIGHT . "&nbsp;\n" . "    <input size=\"{$inpSize}\" name=\"var_{$cfg['name']}\" type=\"text\" value=\"{$cfg['value']}\" {$extra}>\n";
432
            }
433
            echo "  </td>\n" . "</tr>\n";
434
        }
435
    }
436
437
    /*
438
     * Functions to save Administration settings
439
     */
440
441
    /**
442
     * Update the Config option in the database
443
     *
444
     * @param  string $name config var name in the database
445
     * @param  string $sub  config subtype in the database
446
     * @param  mixed  $val  config var value
447
     * @param  string $txt  configuration text for this var
448
     * @return bool   TRUE value updated, FALSE value not updated
449
     */
450
    public static function updateDb($name, $sub, $val, $txt)
451
    {
452
        global $tr_config, $ilog, $xoopsDB;
0 ignored issues
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...
453
        $insertRecordset = 'UPDATE `' . $xoopsDB->prefix('donations_config') . '`' . " SET `value`='$val', `text`='{$txt}'" . " WHERE `name`='{$name}' AND `subtype`='{$sub}'";
454
        $ilog            .= "{$insertRecordset}<br><br>";
455
        echo "{$insertRecordset}<br><br>";
456
        echo '<span style="color: #FF0000; font-weight: bold;">';
457
        $rvalue = $xoopsDB->query($insertRecordset);
458
        echo '</span>';
459
        $retVal = $rvalue ? true : false;
460
461
        return $retVal;
462
    }
463
464
    /************************************************************************
465
     *
466
     ***********************************************************************
467
     * @param $name
468
     * @param $sub
469
     * @param $val
470
     * @param $txt
471
     */
472
    public static function updateDbShort($name, $sub, $val, $txt = '')
473
    {
474
        global $tr_config, $ilog, $xoopsDB;
0 ignored issues
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...
475
        if ($sub === 'array') {
476
            $newArr    = '';
0 ignored issues
show
Unused Code introduced by
$newArr 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...
477
            $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '{$name}'";
478
            $cfgset    = $xoopsDB->query($query_cfg);
479
            $cfg       = $xoopsDB->fetchArray($cfgset);
480
            if (isset($cfg['value'])) {
481
                $splitArr = explode('|', $cfg['value']);
482
                $newArr   = $val;
483
                $i        = 0;
484
                while (false != ($singleVar = $splitArr[$i])) {
485
                    if ($singleVar != $val) {
486
                        $newArr = $newArr . '|' . $singleVar;
487
                    }
488
                    ++$i;
489
                }
490
                $val = $newArr;
491
            }
492
        }
493
        $insertRecordset = 'UPDATE `' . $xoopsDB->prefix('donations_config') . '`' . " SET `value`='{$val}'" . " WHERE `name`='{$name}' AND `subtype`='{$sub}'";
494
495
        $ilog .= "{$insertRecordset}<br><br>\n";
496
        echo "{$insertRecordset}<br><br><span style=\"color: #FF0000; font-weight: bold;\">\n";
497
        $rvalue = $xoopsDB->query($insertRecordset);
0 ignored issues
show
Unused Code introduced by
$rvalue 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...
498
        echo "</span>\n";
499
    }
500
501
    /**
502
     * Get Configuration Value
503
     *
504
     * @param  string $name name of configuration variable
505
     * @return mixed  value of config var on success, FALSE on failure
506
     *
507
     */
508
    public static function getLibConfig($name)
509
    {
510
        global $xoopsDB;
0 ignored issues
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...
511
512
        $sql       = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '{$name}'";
513
        $Recordset = $xoopsDB->query($sql);
514
        $row       = $xoopsDB->fetchArray($Recordset);
515
        //  $text = $b = html_entity_decode($row['text']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
516
        $text = html_entity_decode($row['text']);
517
518
        return $text;
519
    }
520
521
    /**
522
     *
523
     * Get All Configuration Values
524
     *
525
     * @return array SUCCESS - array of config values (name as key); FAIL - empty
526
     */
527
    public static function getAllLibConfig()
528
    {
529
        global $xoopsDB;
0 ignored issues
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...
530
531
        $sql      = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . ' ORDER BY name, subtype';
532
        $sqlQuery = $xoopsDB->query($sql);
533
534
        $t = array();
535
        while (false !== ($sqlfetch = $xoopsDB->fetchArray($sqlQuery))) {
536
            $text = html_entity_decode($sqlfetch['text']);
537
            $text = str_replace('<br>', "\r\n", $text);
538
            $text = str_replace('<br>', "\r\n", $text);
539
540
            if ($sqlfetch['subtype'] == '') {
541
                $t[$sqlfetch['name']] = $text;
542
            } else {
543
                $t[$sqlfetch['name']][$sqlfetch['subtype']] = $text;
544
            }
545
        }
546
547
        //displayArray($t,"------getAllLibConfig-----------");
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
548
        return $t;
549
    }
550
551
    /*******************************************************************
552
     *
553
     ******************************************************************
554
     * @param        $t
555
     * @param string $name
556
     * @param int    $ident
557
     */
558
    public static function displayDonorArray($t, $name = '', $ident = 0)
559
    {
560
        if (is_array($t)) {
561
            echo '------------------------------------------------<br>';
562
            echo 'displayArray: ' . $name . ' - count = ' . count($t);
563
            //echo "<table ".getTblStyle().">";
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
564
            echo "<table>\n";
565
566
            echo '  <tr><td>';
567
            //jjd_echo ("displayArray: ".$name." - count = ".count($t), 255, "-") ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
568
            echo "</td></tr>\n";
569
570
            echo "  <tr><td>\n";
571
            echo '    <pre>';
572
            echo print_r($t);
573
            echo "</pre>\n";
574
            echo "  </td></tr>\n";
575
            echo "</table>\n";
576
        } else {
577
            echo "The variable ---|{$t}|--- is not an array\n";
578
            //        echo "l'indice ---|{$t}|--- n'est pas un tableau\n";
579
        }
580
        //jjd_echo ("Fin - ".$name, 255, "-") ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
581
    }
582
583
    /**
584
     * Display main top header table
585
     *
586
     */
587
    public static function adminmain()
588
    {
589
        global $tr_config, $modversion, $xoopsDB;
0 ignored issues
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...
590
591
        echo "<div style=\"text-align: center;\">\n";
592
        echo "<table style='text-align: center; border-width: 1px; padding: 2px; margin: 2px; width: 90%;'>\n";
593
        echo "  <tr>\n";
594
        echo "    <td style='text-align: center; width: 25%;'><a href='index.php?op=Treasury'><img src='../images/admin/business_sm.png' alt='" . _AD_XDONATION_TREASURY . "'>&nbsp;" . _AD_XDONATION_TREASURY . "</a></td>\n";
595
        echo "    <td style='text-align: center; width: 25%;'><a href='index.php?op=ShowLog'><img src='../images/admin/view_text_sm.png' alt='" . _AD_XDONATION_SHOW_LOG . "'>&nbsp;" . _AD_XDONATION_SHOW_LOG . "</a></td>\n";
596
        echo "    <td style='text-align: center; width: 25%;'><a href='transaction.php'><img src='../images/admin/view_detailed_sm.png' alt='" . _AD_XDONATION_SHOW_TXN . "'>&nbsp;" . _AD_XDONATION_SHOW_TXN . "</a></td>\n";
597
        echo "    <td style='text-align: center; width: 25%;'><a href='index.php?op=Config'><img src='../images/admin/configure_sm.png' alt='" . _AD_XDONATION_CONFIGURATION . "'>&nbsp;" . _AD_XDONATION_CONFIGURATION . "</a></td>\n";
598
        echo "  </tr>\n";
599
        echo "</table>\n";
600
        echo "<br></div>\n";
601
    }
602
}
603