Completed
Push — master ( 4a1a1e...7e0534 )
by Michael
02:41
created

functions.php ➔ define_curr()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 27
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 22
c 1
b 0
f 0
nc 7
nop 1
dl 0
loc 27
rs 6.7272
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 41 and the first side effect is on line 32.

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
/* Donations - Paypal financial management module for Xoops 2           */
4
/* Copyright (c) 2004 by Xoops2 Donations Module Dev Team			    */
5
/* http://dev.xoops.org/modules/xfmod/project/?group_id=1060			*/
6
/* $Id: functions.php 8193 2011-11-07 02:42:53Z beckmi $      */
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% 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...
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') or die('Restricted access');
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

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 define_curr($curr)
42
{
43
    switch ($curr)
44
    {
45
        case 'AUD' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
46
            $curr_sign = _MD_DON_CURR_EUR;
47
            break;
48
        case 'EUR' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
49
            $curr_sign = _MD_DON_CURR_EUR;
50
            break;
51
        case 'GBP' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
52
            $curr_sign = _MD_DON_CURR_GBP;
53
            break;
54
        case 'JPY' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
55
            $curr_sign = _MD_DON_CURR_JPY;
56
            break;
57
        case 'CAD' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
58
            $curr_sign = _MD_DON_CURR_CAD;
59
            break;
60
        case 'USD' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
61
        default:
62
            $curr_sign = _MD_DON_CURR_USD;
63
            break;
64
    }
65
66
    return $curr_sign;
67
}
68
69
/**
70
 * Get all Config fields from DB
71
 *
72
 * @return array
73
 */
74
function configInfo()
75
{
76
    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...
77
78
    $query_cfg = "SELECT * FROM ".$xoopsDB->prefix("donations_config")." WHERE subtype = '' OR subtype = 'array'";
79
    $cfgset = $xoopsDB->query($query_cfg);
80
    $tr_config = array();
81
    while ( $cfgset && $row = $xoopsDB->fetchArray($cfgset))
82
    {
83
        $tr_config[$row['name']] = $row['value'];
84
    }
85
86
    return $tr_config;
87
}
88
89
/**
90
 * Get XOOPS Member Object
91
 *
92
 * @param int $muser_id
93
 * @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...
94
 */
95
function mgetusrinfo($muser_id)
96
{
97
    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...
98
    $thisUser = FALSE;
99
    if (intval($muser_id) > 0) {
100
        $member_handler =& xoops_gethandler('member');
101
        $thisUser =& $member_handler->getUser($muser_id);
102
    }
103
104
    return $thisUser;
105
}
106
107
/**
108
 * Retrieve list of db table's field names
109
 *
110
 * EXAMPLE USAGE:
111
 *
112
 * $list=simple_query($xoopsDB->prefix('donations_transactions'));
113
 *
114
 * @param string $table_name DB table name
115
 * @param string $key_col (optional) table column name
116
 * @param mixed $key_val (optional) table column value
117
 * @param array $ignore (optional) list of values to ignore (clear)
118
 * @return mixed FALSE - nothing found, SUCCESS - array() of values
119
 */
120
function simple_query($table_name, $key_col='', $key_val='',$ignore=array())
121
{
122
    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...
123
    // open the db
124
    $db_link = mysql_connect(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS);
125
    $keys='';
126
    if($key_col!=''&&$key_val!=''){
127
        $keys = "WHERE $key_col = $key_val";
128
    }
129
    // query table using key col/val
130
    $simple_q = FALSE;
131
    $db_rs = mysql_query("SELECT * FROM $table_name $keys", $db_link);
132
    $num_fields = mysql_num_fields($db_rs);
133
    if ($num_fields) {
134
        // first (and only) row
135
        $simple_q = array();
136
        $row = mysql_fetch_assoc($db_rs);
137
        // load up array
138
        if($key_col!='' && $key_val!=''){
139 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...
140
                $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...
141
                $var = mysql_field_name($db_rs, $i);
142
                $simple_q[$var] = $row[$var];
143
            }
144
        }else{
145 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...
146
                $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...
147
                $var = mysql_field_name($db_rs, $i);
148
                if(!in_array($var,$ignore)){
149
                    $simple_q[$var] = '';
150
                }
151
            }
152
        }
153
    }
154
    mysql_free_result($db_rs);
155
156
    return $simple_q;
157
}
158
159
/*
160
 * Functions for Administration display
161
 */
162
163
/**
164
 * Display a Config Option html Option Box in a 2 column table row
165
 *
166
 * @param string $name name of config variable in config DB table
167
 * @param string $desc description of option box
168
 */
169
function ShowYNBox($name, $desc)
170
{
171
    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...
172
173
    $query_cfg = "SELECT * FROM " . $xoopsDB->prefix("donations_config")
174
    . " WHERE name = '{$name}'";
175
    $cfgset = $xoopsDB->query($query_cfg);
176
    if( $cfgset ) {
177
        $cfg = $xoopsDB->fetchArray($cfgset);
178
        $text = htmlentities($cfg['text']);
179
        echo "<tr>\n"
180
        . "  <td title=\"{$text}\" style=\"text-align: right;\">{$desc}</td>\n"
181
        . "  <td title=\"{$text}\" style=\"text-align: left\">";
182
        echo "    <select size=\"1\" name=\"var_{$name}\">";
183
        if( $cfg['value'] ) {
184
            echo "      <option selected value=\"1\">" . _YES . "</option>"
185
            . "      <option value=\"0\">" . _NO . "</option>";
186
        } else {
187
            echo "      <option value=\"1\">" . _YES . "</option>"
188
            . "      <option selected value=\"0\">" . _NO . "</option>";
189
        }
190
        echo "    </select>\n";
191
        echo "  </td>\n";
192
        echo "</tr>\n";
193
    }
194
}
195
196
/**
197
 * Display a Config option HTML Select Box in 2 column table
198
 *
199
 * @param string $name name of config DB table column
200
 * @param string $desc description of select box to show
201
 */
202
function ShowDropBox($name, $desc)
203
{
204
    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...
205
206
    $query_cfg = "SELECT * FROM " . $xoopsDB->prefix("donations_config")
207
    . " WHERE name = '{$name}'";
208
    $cfgset = $xoopsDB->query($query_cfg);
209
    if( $cfgset ) {
210
        $cfg = $xoopsDB->fetchArray($cfgset);
211
        $text = htmlentities($cfg['text']);
212
        echo "<tr style=\"text-align: center;\">\n"
213
        . "  <td title=\"{$text}\" style=\"text-align: right; width: 50%;\">{$desc}</td>\n"
214
        . "  <td title=\"{$text}\" style=\"text-align: left;\">\n";
215
        echo "    <select size=\"1\" name=\"var_{$name}-array\">\n";
216
        if( isset($cfg['value']) ) {
217
            $splitArr = explode('|', $cfg['value']);
218
            $i=0;
219
            while($i < count($splitArr)){
220
                $selected = ( 0 == $i ) ? ' selected' : '';
221
                echo "      <option{$selected} value=\"{$splitArr[$i]}\">{$splitArr[$i]}</option>\n";
222
                $i++;
223
            }
224
        }
225
        echo "    </select>\n";
226
        echo "  </td>\n";
227
        echo "</tr>\n";
228
    }
229
}
230
231
/**
232
 * Display Config Array Drop Box in HTML 2 column table row
233
 *
234
 * @param string $name name of DB column in config table
235
 * @param string $desc description to display for select box
236
 * @param array $x_array array( array($value1, $attrib1), array(...) )
237
 */
238
function ShowArrayDropBox($name, $desc, $x_array)
239
{
240
    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...
241
    $query_cfg = "SELECT * FROM ".$xoopsDB->prefix("donations_config")
242
    . " WHERE name = '{$name}' LIMIT 1";
243
    $cfgset = $xoopsDB->query($query_cfg);
244
    if( $cfgset ) {
245
        $cfg = $xoopsDB->fetchArray($cfgset);
246
        $text = htmlentities($cfg['text']);
247
        echo "<tr>\n"
248
        ."  <td title=\"{$text}\" style=\"text-align: right;\">{$desc}</td>\n"
249
        ."  <td title=\"{$text}\" style=\"text-align: left;\">\n";
250
        echo "    <select size=\"1\" name=\"var_{$name}\">\n";
251
        if ( isset($cfg['value']) ) {
252
            if ( 0 == $cfg['value'] ) {
253
                echo "      <option selected value=\"0\">-------</option>\n";
254
            }else{
255
                echo "      <option value=\"0\">-------</option>\n";
256
            }
257
            $i=0;
258
            while( $i < count($x_array) ){
259
                $mvar = $x_array[$i];
260
                $selected = '';
261
                if ( $mvar[0] == $cfg['value'] ) {
262
                    $selected = ' selected';
263
                }
264
                echo "      <option{$selected} value=\"{$mvar[0]}\">{$mvar[1]}</option>\n";
265
                $i++;
266
            }
267
        }
268
        echo "    </select>\n";
269
        echo "  </td>\n";
270
        echo "</tr>\n";
271
    }
272
}
273
274
/**
275
 * Display Config Option Text Box in a 2 column table row
276
 *
277
 * @param string $name name of DB column in config table
278
 * @param string $desc description of text box to display
279
 * @param int $tdWidth width of description field
280
 * @param int $inpSize width of text input box
281
 * @param string $extra extra info included in input box 'string'
282
 */
283
function ShowTextBox($name, $desc, $tdWidth, $inpSize, $extra)
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")
288
    . " WHERE name = '{$name}'";
289
    $cfgset = $xoopsDB->query($query_cfg);
290
    if( $cfgset ) {
291
        $cfg = $xoopsDB->fetchArray($cfgset);
292
        $text = htmlentities($cfg['text']);
293
        echo "<tr>\n"
294
        . "  <td title=\"{$text}\" style=\"text-align: right; width: {$tdWidth}\">{$desc}</td>\n"
295
        . "  <td title=\"{$text}\" style=\"text-align: left;\">\n"
296
        . "    <input size=\"{$inpSize}\" name=\"var_{$name}\" type=\"text\" value=\"{$cfg['value']}\"  {$extra} />\n"
297
        . "  </td>\n"
298
        . "</tr>\n";
299
    }
300
}
301
302
/************************************************************************
303
 *
304
 ************************************************************************/
305
function ShowImgXYBox($xnm, $ynm, $desc, $inpSize, $extra)
306
{
307
    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...
308
309
    $query_cfg = "SELECT * FROM ".$xoopsDB->prefix("donations_config")." WHERE name = '$xnm'";
310
    $cfgset = $xoopsDB->query($query_cfg);
311
312
    if( $cfgset) {
313
        $cfg = $xoopsDB->fetchArray($cfgset);
314
315
        $text = htmlentities($cfg['text']);
316
        echo "<tr>\n"
317
        . "  <td title=\"{$text}\" style=\"text-align: right;\">{$desc}</td>\n"
318
        . "  <td title=\"{$text}\" style=\"text-align: left;\">\n";
319
        echo "    &nbsp;" . _AD_DON_WIDTH . "&nbsp;\n"
320
        . "    <input size=\"{$inpSize}\" name=\"var_{$cfg['name']}\" type=\"text\" value=\"{$cfg['value']}\" {$extra} />\n";
321
322
        $query_cfg = "SELECT * FROM ".$xoopsDB->prefix("donations_config")." WHERE name = '$ynm'";
323
        $cfgset = $xoopsDB->query($query_cfg);
324
        if( $cfgset)
325
        {
326
            $cfg = $xoopsDB->fetchArray($cfgset);
327
            echo "    &nbsp;&nbsp;" . _AD_DON_HEIGHT . "&nbsp;\n"
328
            . "    <input size=\"{$inpSize}\" name=\"var_{$cfg['name']}\" type=\"text\" value=\"{$cfg['value']}\" {$extra} />\n";
329
        }
330
        echo "  </td>\n"
331
        . "</tr>\n";
332
    }
333
}
334
335
/*
336
 * Functions to save Administration settings
337
 */
338
339
/**
340
 * Update the Config option in the database
341
 *
342
 * @param string $name config var name in the database
343
 * @param string $sub  config subtype in the database
344
 * @param mixed $val   config var value
345
 * @param string $txt  configuration text for this var
346
 * @return bool TRUE value updated, FALSE value not updated
347
 */
348
function UpdateDb($name, $sub, $val, $txt)
349
{
350
    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...
351
    $insert_Recordset = "UPDATE `" . $xoopsDB->prefix("donations_config") . "`"
352
    . " SET `value`='$val', `text`='{$txt}'"
353
    . " WHERE `name`='{$name}' AND `subtype`='{$sub}'";
354
    $ilog .= "{$insert_Recordset}<br /><br />";
355
    echo "{$insert_Recordset}<br /><br />";
356
    echo "<span style=\"color: #FF0000; font-weight: bold;\">";
357
    $rvalue = $xoopsDB->query($insert_Recordset);
358
    echo "</span>";
359
    $retVal = ($rvalue) ? TRUE : FALSE;
360
361
    return $retVal;
362
}
363
364
/************************************************************************
365
 *
366
 ************************************************************************/
367
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...
368
{
369
    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...
370
    if($sub=='array'){
371
        $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...
372
        $query_cfg = "SELECT * FROM ".$xoopsDB->prefix("donations_config")
373
        . " WHERE name = '{$name}'";
374
        $cfgset = $xoopsDB->query($query_cfg);
375
        $cfg = $xoopsDB->fetchArray($cfgset);
376
        if( isset($cfg['value']) ) {
377
            $splitArr = explode('|',$cfg['value']);
378
            $newArr = $val;
379
            $i=0;
380
            while($singleVar = $splitArr[$i]) {
381
                if ( $singleVar != $val ) {
382
                    $newArr = $newArr.'|'.$singleVar;
383
                }
384
                $i++;
385
            }
386
            $val = $newArr;
387
        }
388
    }
389
    $insert_Recordset = "UPDATE `" . $xoopsDB->prefix("donations_config") . "`"
390
    . " SET `value`='{$val}'"
391
    . " WHERE `name`='{$name}' AND `subtype`='{$sub}'";
392
393
    $ilog .= "{$insert_Recordset}<br /><br />\n";
394
    echo "{$insert_Recordset}<br /><br /><span style=\"color: #FF0000; font-weight: bold;\">\n";
395
    $rvalue = $xoopsDB->query($insert_Recordset);
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...
396
    echo "</span>\n";
397
}
398
399
/**
400
 * Get Configuration Value
401
 *
402
 * @param string $name name of configuration variable
403
 * @return mixed value of config var on success, FALSE on failure
404
 *
405
 */
406
function getLibConfig($name)
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")
411
    ." WHERE name = '{$name}'";
412
    $Recordset = $xoopsDB->query($sql);
413
    $row = $xoopsDB->fetchArray($Recordset);
414
    //	$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...
415
    $text = html_entity_decode($row['text']);
416
417
    return $text;
418
}
419
420
/**
421
 *
422
 * Get All Configuration Values
423
 *
424
 * @return array SUCCESS - array of config values (name as key); FAIL - empty
425
 */
426
function getAllLibConfig()
427
{
428
    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...
429
430
    $sql = "SELECT * FROM " . $xoopsDB->prefix("donations_config")
431
    . " ORDER BY name, subtype";
432
    $sqlquery = $xoopsDB->query($sql);
433
434
    $t = array();
435
    while ($sqlfetch = $xoopsDB->fetchArray($sqlquery)) {
436
        $text = html_entity_decode($sqlfetch['text']);
437
        $text = str_replace('<br />', "\r\n", $text);
438
        $text = str_replace('<br />', "\r\n", $text);
439
440
        if ($sqlfetch['subtype'] == '') {
441
            $t[$sqlfetch['name']] = $text;
442
        } else {
443
            $t[$sqlfetch['name']][$sqlfetch['subtype']] = $text;
444
        }
445
    }
446
    //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...
447
    return $t;
448
}
449
/*******************************************************************
450
 *
451
 *******************************************************************/
452
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...
453
{
454
    if (is_array($t)) {
455
        echo "------------------------------------------------<br />" ;
456
        echo "displayArray: " . $name . " - count = " . count($t) ;
457
        //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...
458
        echo "<table>\n";
459
460
        echo "  <tr><td>";
461
        //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...
462
        echo "</td></tr>\n";
463
464
        echo "  <tr><td>\n";
465
        echo "    <pre>";
466
        echo print_r($t);
467
        echo "</pre>\n";
468
        echo "  </td></tr>\n";
469
        echo "</table>\n";
470
    } else {
471
        echo "The variable ---|{$t}|--- is not an array\n";
472
        //        echo "l'indice ---|{$t}|--- n'est pas un tableau\n";
473
    }
474
    //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...
475
}
476
/**
477
 * Display main top header table
478
 *
479
 */
480
function adminmain() {
481
    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...
482
483
    echo "<div style=\"text-align: center;\">\n";
484
    echo "<table style='text-align: center; border-width: 1px; padding: 2px; margin: 2px; width: 90%;'>\n";
485
    echo "  <tr>\n";
486
    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";
487
    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";
488
    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";
489
    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";
490
    echo "  </tr>\n";
491
    echo "</table>\n";
492
    echo "<br /></div>\n";
493
}
494