Completed
Push — master ( 22cdbd...91d359 )
by Michael
01:57
created

functions.php ➔ defineCurrency()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 26
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 22
nc 7
nop 1
dl 0
loc 26
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/************************************************************************/
3
/* Donations - Paypal financial management module for Xoops 2           */
4
/* Copyright (c) 2016 XOOPS Project                                     */
5
/* http://dev.xoops.org/modules/xfmod/project/?group_id=1060            */
6
/* 
7
/************************************************************************/
8
/*                                                                      */
9
/* Based on NukeTreasury for PHP-Nuke - by Dave Lawrence AKA Thrash     */
10
/* NukeTreasury - Financial management for PHP-Nuke                     */
11
/* Copyright (c) 2004 by Dave Lawrence AKA Thrash                       */
12
/*                       [email protected]                         */
13
/*                       [email protected]                          */
14
/*                                                                      */
15
/************************************************************************/
16
/*                                                                      */
17
/* This program is free software; you can redistribute it and/or modify */
18
/* it under the terms of the GNU General Public License as published by */
19
/* the Free Software Foundation; either version 2 of the License.       */
20
/*                                                                      */
21
/* This program is distributed in the hope that it will be useful, but  */
22
/* WITHOUT ANY WARRANTY; without even the implied warranty of           */
23
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU     */
24
/* General Public License for more details.                             */
25
/*                                                                      */
26
/* You should have received a copy of the GNU General Public License    */
27
/* along with this program; if not, write to the Free Software          */
28
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  */
29
/* USA                                                                  */
30
/************************************************************************/
31
32
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
33
34
/**
35
 * Set the Currency Indicator ($, etc...)
36
 *
37
 * @param  string $curr PAYPAL abbreviation for currency
38
 * @return string currency indicator (sign)
39
 *
40
 */
41
function defineCurrency($curr)
42
{
43
    switch ($curr) {
44
        case 'AUD':
45
            $currencySign = _MD_DON_CURR_AUD;
46
            break;
47
        case 'EUR':
48
            $currencySign = _MD_DON_CURR_EUR;
49
            break;
50
        case 'GBP':
51
            $currencySign = _MD_DON_CURR_GBP;
52
            break;
53
        case 'JPY':
54
            $currencySign = _MD_DON_CURR_JPY;
55
            break;
56
        case 'CAD':
57
            $currencySign = _MD_DON_CURR_CAD;
58
            break;
59
        case 'USD':
60
        default:
61
            $currencySign = _MD_DON_CURR_USD;
62
            break;
63
    }
64
65
    return $currencySign;
66
}
67
68
/**
69
 * Get all Config fields from DB
70
 *
71
 * @return array
72
 */
73
function configInfo()
74
{
75
    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...
76
77
    $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE subtype = '' OR subtype = 'array'";
78
    $cfgset    = $xoopsDB->query($query_cfg);
79
    $tr_config = array();
80
    while ($cfgset && $row = $xoopsDB->fetchArray($cfgset)) {
81
        $tr_config[$row['name']] = $row['value'];
82
    }
83
84
    return $tr_config;
85
}
86
87
/**
88
 * Get XOOPS Member Object
89
 *
90
 * @param  int $muser_id
91
 * @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...
92
 */
93
function mgetUserInfo($muser_id)
94
{
95
    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...
96
    $thisUser = false;
97
    if ((int)$muser_id > 0) {
98
        $member_handler = xoops_getHandler('member');
99
        $thisUser       = $member_handler->getUser($muser_id);
100
    }
101
102
    return $thisUser;
103
}
104
105
/**
106
 * Retrieve list of db table's field names
107
 *
108
 * EXAMPLE USAGE:
109
 *
110
 * $list=simple_query($xoopsDB->prefix('donations_transactions'));
111
 *
112
 * @param  string $table_name DB table name
113
 * @param  string $key_col    (optional) table column name
114
 * @param  mixed  $key_val    (optional) table column value
115
 * @param  array  $ignore     (optional) list of values to ignore (clear)
116
 * @return mixed  FALSE - nothing found, SUCCESS - array() of values
117
 */
118
function simple_query($table_name, $key_col = '', $key_val = '', $ignore = array())
119
{
120
    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...
121
    // open the db
122
//    $db_link = mysqli_connect(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS);
123
    $keys    = '';
124
    if ($key_col != '' && $key_val != '') {
125
        $keys = "WHERE $key_col = $key_val";
126
    }
127
    // query table using key col/val
128
    $simple_q   = false;
129
    $db_rs      = $xoopsDB->query("SELECT * FROM $table_name $keys");
130
    $num_fields = $xoopsDB->getFieldsNum($db_rs);
131
    if ($num_fields) {
132
        // first (and only) row
133
        $simple_q = array();
134
        $row      = $xoopsDB->fetchArray($db_rs);
135
        // load up array
136
        if ($key_col != '' && $key_val != '') {
137 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...
138
                $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...
139
                $var            = $xoopsDB->getFieldName($db_rs, $i);
140
                $simple_q[$var] = $row[$var];
141
            }
142
        } else {
143 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...
144
                $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...
145
                $var = $xoopsDB->getFieldName($db_rs, $i);
146
                if (!in_array($var, $ignore)) {
147
                    $simple_q[$var] = '';
148
                }
149
            }
150
        }
151
    }
152
    $xoopsDB->freeRecordSet($db_rs);
153
154
    return $simple_q;
155
}
156
157
/*
158
 * Functions for Administration display
159
 */
160
161
/**
162
 * Display a Config Option html Option Box in a 2 column table row
163
 *
164
 * @param string $name name of config variable in config DB table
165
 * @param string $desc description of option box
166
 */
167
function ShowYNBox($name, $desc)
168
{
169
    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...
170
171
    $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '{$name}'";
172
    $cfgset    = $xoopsDB->query($query_cfg);
173
    if ($cfgset) {
174
        $cfg  = $xoopsDB->fetchArray($cfgset);
175
        $text = htmlentities($cfg['text']);
176
        echo "<tr>\n" . "  <td title=\"{$text}\" style=\"text-align: right;\">{$desc}</td>\n" . "  <td title=\"{$text}\" style=\"text-align: left;\">";
177
        echo "    <select size=\"1\" name=\"var_{$name}\">";
178
        if ($cfg['value']) {
179
            echo "      <option selected value=\"1\">" . _YES . '</option>' . "      <option value=\"0\">" . _NO . '</option>';
180
        } else {
181
            echo "      <option value=\"1\">" . _YES . '</option>' . "      <option selected value=\"0\">" . _NO . '</option>';
182
        }
183
        echo "    </select>\n";
184
        echo "  </td>\n";
185
        echo "</tr>\n";
186
    }
187
}
188
189
/**
190
 * Display a Config option HTML Select Box in 2 column table
191
 *
192
 * @param string $name name of config DB table column
193
 * @param string $desc description of select box to show
194
 */
195
function ShowDropBox($name, $desc)
196
{
197
    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...
198
199
    $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '{$name}'";
200
    $cfgset    = $xoopsDB->query($query_cfg);
201
    if ($cfgset) {
202
        $cfg  = $xoopsDB->fetchArray($cfgset);
203
        $text = htmlentities($cfg['text']);
204
        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";
205
        echo "    <select size=\"1\" name=\"var_{$name}-array\">\n";
206
        if (isset($cfg['value'])) {
207
            $splitArr = explode('|', $cfg['value']);
208
            $i        = 0;
209
            while ($i < count($splitArr)) {
210
                $selected = (0 == $i) ? ' selected' : '';
211
                echo "      <option{$selected} value=\"{$splitArr[$i]}\">{$splitArr[$i]}</option>\n";
212
                ++$i;
213
            }
214
        }
215
        echo "    </select>\n";
216
        echo "  </td>\n";
217
        echo "</tr>\n";
218
    }
219
}
220
221
/**
222
 * Display Config Array Drop Box in HTML 2 column table row
223
 *
224
 * @param string $name    name of DB column in config table
225
 * @param string $desc    description to display for select box
226
 * @param array  $x_array array( array($value1, $attrib1), array(...) )
227
 */
228
function ShowArrayDropBox($name, $desc, $x_array)
229
{
230
    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...
231
    $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '{$name}' LIMIT 1";
232
    $cfgset    = $xoopsDB->query($query_cfg);
233
    if ($cfgset) {
234
        $cfg  = $xoopsDB->fetchArray($cfgset);
235
        $text = htmlentities($cfg['text']);
236
        echo "<tr>\n" . "  <td title=\"{$text}\" style=\"text-align: right;\">{$desc}</td>\n" . "  <td title=\"{$text}\" style=\"text-align: left;\">\n";
237
        echo "    <select size=\"1\" name=\"var_{$name}\">\n";
238
        if (isset($cfg['value'])) {
239
            if (0 == $cfg['value']) {
240
                echo "      <option selected value=\"0\">-------</option>\n";
241
            } else {
242
                echo "      <option value=\"0\">-------</option>\n";
243
            }
244
            $i = 0;
245
            while ($i < count($x_array)) {
246
                $mvar     = $x_array[$i];
247
                $selected = '';
248
                if ($mvar[0] == $cfg['value']) {
249
                    $selected = ' selected';
250
                }
251
                echo "      <option{$selected} value=\"{$mvar[0]}\">{$mvar[1]}</option>\n";
252
                ++$i;
253
            }
254
        }
255
        echo "    </select>\n";
256
        echo "  </td>\n";
257
        echo "</tr>\n";
258
    }
259
}
260
261
/**
262
 * Display Config Option Text Box in a 2 column table row
263
 *
264
 * @param string $name    name of DB column in config table
265
 * @param string $desc    description of text box to display
266
 * @param int    $tdWidth width of description field
267
 * @param int    $inpSize width of text input box
268
 * @param string $extra   extra info included in input box 'string'
269
 */
270
function ShowTextBox($name, $desc, $tdWidth, $inpSize, $extra)
271
{
272
    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...
273
274
    $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '{$name}'";
275
    $cfgset    = $xoopsDB->query($query_cfg);
276
    if ($cfgset) {
277
        $cfg  = $xoopsDB->fetchArray($cfgset);
278
        $text = htmlentities($cfg['text']);
279
        echo "<tr>\n" . "  <td title=\"{$text}\" style=\"text-align: right; width: {$tdWidth};\">{$desc}</td>\n" . "  <td title=\"{$text}\" style=\"text-align: left;\">\n" . "    <input size=\"{$inpSize}\" name=\"var_{$name}\" type=\"text\" value=\"{$cfg['value']}\"  {$extra} />\n" . "  </td>\n" . "</tr>\n";
280
    }
281
}
282
283
/************************************************************************
284
 *
285
 ***********************************************************************
286
 * @param $xnm
287
 * @param $ynm
288
 * @param $desc
289
 * @param $inpSize
290
 * @param $extra
291
 */
292
function ShowImgXYBox($xnm, $ynm, $desc, $inpSize, $extra)
293
{
294
    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...
295
296
    $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '$xnm'";
297
    $cfgset    = $xoopsDB->query($query_cfg);
298
299
    if ($cfgset) {
300
        $cfg = $xoopsDB->fetchArray($cfgset);
301
302
        $text = htmlentities($cfg['text']);
303
        echo "<tr>\n" . "  <td title=\"{$text}\" style=\"text-align: right;\">{$desc}</td>\n" . "  <td title=\"{$text}\" style=\"text-align: left;\">\n";
304
        echo '    &nbsp;' . _AD_DON_WIDTH . "&nbsp;\n" . "    <input size=\"{$inpSize}\" name=\"var_{$cfg['name']}\" type=\"text\" value=\"{$cfg['value']}\" {$extra} />\n";
305
306
        $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '$ynm'";
307
        $cfgset    = $xoopsDB->query($query_cfg);
308
        if ($cfgset) {
309
            $cfg = $xoopsDB->fetchArray($cfgset);
310
            echo '    &nbsp;&nbsp;' . _AD_DON_HEIGHT . "&nbsp;\n" . "    <input size=\"{$inpSize}\" name=\"var_{$cfg['name']}\" type=\"text\" value=\"{$cfg['value']}\" {$extra} />\n";
311
        }
312
        echo "  </td>\n" . "</tr>\n";
313
    }
314
}
315
316
/*
317
 * Functions to save Administration settings
318
 */
319
320
/**
321
 * Update the Config option in the database
322
 *
323
 * @param  string $name config var name in the database
324
 * @param  string $sub  config subtype in the database
325
 * @param  mixed  $val  config var value
326
 * @param  string $txt  configuration text for this var
327
 * @return bool   TRUE value updated, FALSE value not updated
328
 */
329
function updateDb($name, $sub, $val, $txt)
330
{
331
    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...
332
    $insertRecordset = 'UPDATE `' . $xoopsDB->prefix('donations_config') . '`' . " SET `value`='$val', `text`='{$txt}'" . " WHERE `name`='{$name}' AND `subtype`='{$sub}'";
333
    $ilog .= "{$insertRecordset}<br /><br />";
334
    echo "{$insertRecordset}<br /><br />";
335
    echo "<span style=\"color: #FF0000; font-weight: bold;\">";
336
    $rvalue = $xoopsDB->query($insertRecordset);
337
    echo '</span>';
338
    $retVal = $rvalue ? true : false;
339
340
    return $retVal;
341
}
342
343
/************************************************************************
344
 *
345
 ***********************************************************************
346
 * @param $name
347
 * @param $sub
348
 * @param $val
349
 * @param $txt
350
 */
351
function updateDbShort($name, $sub, $val, $txt='')
0 ignored issues
show
Unused Code introduced by
The parameter $txt is not used and could be removed.

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

Loading history...
352
{
353
    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...
354
    if ($sub === 'array') {
355
        $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...
356
        $query_cfg = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '{$name}'";
357
        $cfgset    = $xoopsDB->query($query_cfg);
358
        $cfg       = $xoopsDB->fetchArray($cfgset);
359
        if (isset($cfg['value'])) {
360
            $splitArr = explode('|', $cfg['value']);
361
            $newArr   = $val;
362
            $i        = 0;
363
            while (false != ($singleVar = $splitArr[$i])) {
364
                if ($singleVar != $val) {
365
                    $newArr = $newArr . '|' . $singleVar;
366
                }
367
                ++$i;
368
            }
369
            $val = $newArr;
370
        }
371
    }
372
    $insertRecordset = 'UPDATE `' . $xoopsDB->prefix('donations_config') . '`' . " SET `value`='{$val}'" . " WHERE `name`='{$name}' AND `subtype`='{$sub}'";
373
374
    $ilog .= "{$insertRecordset}<br /><br />\n";
375
    echo "{$insertRecordset}<br /><br /><span style=\"color: #FF0000; font-weight: bold;\">\n";
376
    $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...
377
    echo "</span>\n";
378
}
379
380
/**
381
 * Get Configuration Value
382
 *
383
 * @param  string $name name of configuration variable
384
 * @return mixed  value of config var on success, FALSE on failure
385
 *
386
 */
387
function getLibConfig($name)
388
{
389
    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...
390
391
    $sql       = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = '{$name}'";
392
    $Recordset = $xoopsDB->query($sql);
393
    $row       = $xoopsDB->fetchArray($Recordset);
394
    //  $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...
395
    $text = html_entity_decode($row['text']);
396
397
    return $text;
398
}
399
400
/**
401
 *
402
 * Get All Configuration Values
403
 *
404
 * @return array SUCCESS - array of config values (name as key); FAIL - empty
405
 */
406
function getAllLibConfig()
407
{
408
    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...
409
410
    $sql      = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . ' ORDER BY name, subtype';
411
    $sqlquery = $xoopsDB->query($sql);
412
413
    $t = array();
414
    while (false != ($sqlfetch = $xoopsDB->fetchArray($sqlquery))) {
415
        $text = html_entity_decode($sqlfetch['text']);
416
        $text = str_replace('<br />', "\r\n", $text);
417
        $text = str_replace('<br />', "\r\n", $text);
418
419
        if ($sqlfetch['subtype'] == '') {
420
            $t[$sqlfetch['name']] = $text;
421
        } else {
422
            $t[$sqlfetch['name']][$sqlfetch['subtype']] = $text;
423
        }
424
    }
425
    //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...
426
    return $t;
427
}
428
429
/*******************************************************************
430
 *
431
 ******************************************************************
432
 * @param        $t
433
 * @param string $name
434
 * @param int    $ident
435
 */
436
function displayArray_don($t, $name = '', $ident = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $ident is not used and could be removed.

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

Loading history...
437
{
438
    if (is_array($t)) {
439
        echo '------------------------------------------------<br />';
440
        echo 'displayArray: ' . $name . ' - count = ' . count($t);
441
        //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...
442
        echo "<table>\n";
443
444
        echo '  <tr><td>';
445
        //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...
446
        echo "</td></tr>\n";
447
448
        echo "  <tr><td>\n";
449
        echo '    <pre>';
450
        echo print_r($t);
451
        echo "</pre>\n";
452
        echo "  </td></tr>\n";
453
        echo "</table>\n";
454
    } else {
455
        echo "The variable ---|{$t}|--- is not an array\n";
456
        //        echo "l'indice ---|{$t}|--- n'est pas un tableau\n";
457
    }
458
    //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...
459
}
460
461
/**
462
 * Display main top header table
463
 *
464
 */
465
function adminmain()
466
{
467
    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...
468
469
    echo "<div style=\"text-align: center;\">\n";
470
    echo "<table style='text-align: center; border-width: 1px; padding: 2px; margin: 2px; width: 90%;'>\n";
471
    echo "  <tr>\n";
472
    echo "    <td style='text-align: center; width: 25%;'><a href='index.php?op=Treasury'><img src='../images/admin/business_sm.png' alt='" . _AD_DON_TREASURY . "' />&nbsp;" . _AD_DON_TREASURY . "</a></td>\n";
473
    echo "    <td style='text-align: center; width: 25%;'><a href='index.php?op=ShowLog'><img src='../images/admin/view_text_sm.png' alt='" . _AD_DON_SHOW_LOG . "' />&nbsp;" . _AD_DON_SHOW_LOG . "</a></td>\n";
474
    echo "    <td style='text-align: center; width: 25%;'><a href='transaction.php'><img src='../images/admin/view_detailed_sm.png' alt='" . _AD_DON_SHOW_TXN . "' />&nbsp;" . _AD_DON_SHOW_TXN . "</a></td>\n";
475
    echo "    <td style='text-align: center; width: 25%;'><a href='index.php?op=Config'><img src='../images/admin/configure_sm.png' alt='" . _AD_DON_CONFIGURATION . "' />&nbsp;" . _AD_DON_CONFIGURATION . "</a></td>\n";
476
    echo "  </tr>\n";
477
    echo "</table>\n";
478
    echo "<br /></div>\n";
479
}
480