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

donations.php ➔ updateConfig()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 40
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 24
nc 10
nop 0
dl 0
loc 40
rs 8.439
c 0
b 0
f 0
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 49 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) 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
include dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php';
33
34
xoops_loadLanguage('main', $xoopsModule->getVar('dirname'));
35
include dirname(__DIR__) . '/include/functions.php';
36
include_once __DIR__ . '/admin_header.php';
37
xoops_cp_header();
38
//adminmain();
39
40
$tr_config = configInfo();
41
//determine the currency
42
$PP_CURR_CODE = explode('|', $tr_config['pp_curr_code']); // [USD,GBP,JPY,CAD,EUR,AUD]
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...
43
$PP_CURR_CODE = $PP_CURR_CODE[0];
44
$currencySign    = defineCurrency($PP_CURR_CODE);
45
46
/***************************************************************************
47
 *
48
 ***************************************************************************/
49
function treasury()
0 ignored issues
show
Coding Style introduced by
treasury uses the super-global variable $_POST which is generally not recommended.

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

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

// Better
class Router
{
    private $host;

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

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

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

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
50
{
51
    global $tr_config, $xoopsDB, $xoopsModule, $modversion, $currencySign, $pathIcon16;
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...
52
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
53
    $indexAdmin = new ModuleAdmin();
54
    echo $indexAdmin->addNavigation('donations.php?op=Treasury');
55
56
    // Register paging
57
    $maxRows_Recordset1  = 10;
58
    $pageNum_Recordset1  = isset($_POST['pageNum_Recordset1']) ? (int)$_POST['pageNum_Recordset1'] : 0;
59
    $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
60
61
    //  $query_Recordset1 = "SELECT id, date, DATE_FORMAT(date, '%d-%b-%Y') as fdate, DATE_FORMAT(date, '%d') as day, DATE_FORMAT(date, '%m') as mon, DATE_FORMAT(date, '%Y') as year, num, name, descr, amount FROM ".$xoopsDB->prefix("donations_financial")." order by date DESC";
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
62
    $query_Recordset1       = "SELECT id, date, DATE_FORMAT(date, '%d-%b-%Y') as fdate, num, name, descr, amount FROM " . $xoopsDB->prefix('donations_financial') . ' ORDER BY date DESC';
63
    $query_limit_Recordset1 = "$query_Recordset1 LIMIT $startRow_Recordset1, $maxRows_Recordset1";
64
    $Recordset1             = $xoopsDB->query($query_limit_Recordset1);
65
    $row_Recordset1         = $xoopsDB->fetchArray($Recordset1);
66
67
    if (isset($_POST['totalRows_Recordset1'])) {
68
        $totalRows_Recordset1 = $_POST['totalRows_Recordset1'];
69
    } else {
70
        $all_Recordset1       = $xoopsDB->query($query_Recordset1);
71
        $totalRows_Recordset1 = $xoopsDB->getRowsNum($all_Recordset1);
72
    }
73
    $totalPages_Recordset1  = ceil($totalRows_Recordset1 / $maxRows_Recordset1) - 1;
74
    $queryString_Recordset1 = '&totalRows_Recordset1=' . $totalRows_Recordset1 . '#AdminTop';
0 ignored issues
show
Unused Code introduced by
$queryString_Recordset1 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...
75
76
    // Collect IPN reconcile data
77
    // First, get the date of the last time we reconciled
78
    $query_Recordset2 = 'SELECT `date` AS recdate FROM ' . $xoopsDB->prefix('donations_financial') . " WHERE name = 'PayPal IPN' ORDER BY date DESC LIMIT 1";
79
    $Recordset2       = $xoopsDB->query($query_Recordset2);
80
    $row_Recordset2   = $xoopsDB->fetchArray($Recordset2);
81
    $recdate          = $row_Recordset2['recdate'];
82
83
    // Get the date of the last donation
84
    $query_Recordset2 = 'SELECT `payment_date` AS curdate FROM ' . $xoopsDB->prefix('donations_transactions') . " WHERE payment_status = 'Completed' AND (txn_type = 'send_money' OR txn_type = 'web_accept' ) ORDER BY payment_date DESC LIMIT 1";
85
    $Recordset2       = $xoopsDB->query($query_Recordset2);
86
    $row_Recordset2   = $xoopsDB->fetchArray($Recordset2);
87
    $curdate          = $row_Recordset2['curdate'];
88
89
    // Collect the IPN transactions between recdate and curdate
90
    $query_Recordset2 = 'SELECT custom, SUM(mc_gross) AS gross, SUM(mc_gross - mc_fee) AS net FROM ' . $xoopsDB->prefix('donations_transactions') . " WHERE (payment_date > '{$recdate}' AND payment_date <= '{$curdate}') GROUP BY txn_id";
91
    $Recordset2       = $xoopsDB->query($query_Recordset2);
92
93
    // Iterate over the records skipping the ones that total out to zero(refunds)
94
    $ipn_tot = 0;
95
    $num_ipn = 0;
96
    while (false != ($row_Recordset2 = $xoopsDB->fetchArray($Recordset2))) {
97
        if ($row_Recordset2['gross'] > 0) {
98
            $ipn_tot += $row_Recordset2['net'];
99
            ++$num_ipn;
100
        }
101
    }
102
103
    // Get the register balance & total number of records
104
    $query_Recordset4 = 'SELECT SUM(amount) AS total, COUNT(*) as numRec FROM ' . $xoopsDB->prefix('donations_financial') . '';
105
    $Recordset4       = $xoopsDB->query($query_Recordset4);
106
    list($total, $numRec) = $xoopsDB->fetchRow($Recordset4);
107
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
41% 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...
108
     $row_Recordset4 = $xoopsDB->fetchArray($Recordset4);
109
     $total = $row_Recordset4['total'];
110
111
     // Query to remove the Edit/Delete buttons if no results will be listed.
112
     $queryRec = "SELECT COUNT(*) FROM ".$xoopsDB->prefix("donations_financial")."";
113
     list($numRec) = $xoopsDB->fetchRow($queryRec);
114
     */
115
    // Output the page
116
    echo "<table style=\"border-width: 1px; width: 100%; text-align: center;\">\n" . "<tr><td>\n";
117
    echo "<table style=\"border-width: 0px; padding: 0px; margin: 0px; text-align: center;\">\n";
118
    echo "  <tr><td style=\"width: 100%; text-align: center; font-weight: bold;\">";
119
    echo "<span class=\"option\"><h3>" . _AD_DON_TREASURY_F_REGISTER . "</h3></span></td></tr>\n";
120
    echo "  <tr><td style=\"width: 100%;\">" . _AD_DON_NEW_IPN_COUNT . " {$num_ipn} - " . _AD_DON_TOTALING . " {$currencySign}{$ipn_tot}";
121
    echo "</td></tr>\n";
122
    echo "<tr><td style=\"width: 100%; text-align: center;\">\n";
123
    echo "  <form action=\"donations.php?op=IpnRec#AdminTop\" method=\"post\">\n";
124
    echo "    <input type=\"hidden\" name=\"op\" value=\"IpnRec\" />\n" . "    <input type=\"submit\" value=\"" . _AD_DON_SYNCHRONISE_IPN . "\" onClick=\"return confirm('" . _AD_DON_CONFIRM_TOTAL_UP . "')\" />\n" . "  </form>\n";
125
    echo "</td></tr></table>\n";
126
127
    if ($pageNum_Recordset1 > 0) {
128
        echo "<table style=\"border-width: 0px; text-align: center;\">\n" . "  <tr>\n";
129
        echo "    <td><form action=\"donations.php#AdminTop\" method=\"post\">\n" . "<input type=\"hidden\" name=\"op\" value=\"Treasury\" />\n" . "<input type=\"hidden\" name=\"pageNum_Recordset1\" value=\"0\" />\n" . "<input type=\"hidden\" name=\"totalRows_Recordset1\" value=\"{$totalRows_Recordset1}\" />\n" . "<input type=\"submit\" name=\"navig\" value=\"|&lt;\" title=\"" . _AD_DON_CURRENT . "\" /></form></td>\n";
130
        echo "<td><form action=\"donations.php#AdminTop\" method=\"post\">\n" . "<input type=\"hidden\" name=\"op\" value=\"Treasury\" />\n" . "<input type=\"hidden\" name=\"pageNum_Recordset1\" value=\"" . max(0, $pageNum_Recordset1 - 1) . "\" />\n" . "<input type=\"hidden\" name=\"totalRows_Recordset1\" value=\"{$totalRows_Recordset1}\" />\n" . "<input type=\"submit\" name=\"navig\" value=\"&lt;\" title=\"" . _AD_DON_NEXT_NEWEST . "\" /></form></td>\n";
131
        if ($pageNum_Recordset1 < $totalPages_Recordset1) {
132
            echo "<td><form action=\"donations.php#AdminTop\" method=\"post\">\n" . "<input type=\"hidden\" name=\"op\" value=\"Treasury\" />\n" . "<input type=\"hidden\" name=\"pageNum_Recordset1\" value=\"" . min($totalPages_Recordset1, $pageNum_Recordset1 + 1) . "\" />\n" . "<input type=\"hidden\" name=\"totalRows_Recordset1\" value=\"{$totalRows_Recordset1}\" />\n" . "<input type=\"submit\" name=\"navig\" value=\"&gt;\" title=\"" . _AD_DON_NEXT_OLDEST . "\" /></form></td>\n";
133
            echo "<td><form action=\"donations.php#AdminTop\" method=\"post\">\n" . "<input type=\"hidden\" name=\"op\" value=\"Treasury\" />\n" . "<input type=\"hidden\" name=\"pageNum_Recordset1\" value=\"{$totalPages_Recordset1}\" />\n" . "<input type=\"hidden\" name=\"totalRows_Recordset1\" value=\"{$totalRows_Recordset1}\" />\n" . "<input type=\"submit\" name=\"navig\" value=\"&gt;|\" title=\"" . _AD_DON_OLDEST . "\" /></form></td>\n";
134
        }
135
        echo "</tr></table>\n";
136
    }
137
138
    echo "<table class='outer' width='100%' border='0' cellpadding='0' cellspacing='0'>" . "<th align='center'>" . _AD_DON_DATE . "</th><th align='center'>" . _AD_DON_NUM . "</th><th align='center'>" . _AD_DON_NAME . "</th><th align='center'>" . _AD_DON_DESCRIPTION . "</th><th align='center'>" . _AD_DON_AMOUNT . "</th><th align='center'>" . _AD_DON_ACTION . "</th></tr>\n";
139
    //      $class = 'even';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
140
141
    $row = 0;
142
    do {
143
        ++$row;
144
        echo "<tr>\n";
145
        echo "</td>\n" . "<td style=\"text-align: center;\">$row_Recordset1[fdate]</td>\n" . "<td style=\"text-align: center; width: 8px;\">$row_Recordset1[num]</td>\n" . "<td style=\"text-align: center;\">$row_Recordset1[name]</td>\n" . "<td style=\"text-align: center;\">$row_Recordset1[descr]</td>\n" . "<td style=\"text-align: right;\"><span ";
146
        $amt = sprintf('%10.2f', $row_Recordset1['amount']);
147
        if ($amt < 0) {
148
            echo "style=\"color: #FF0000;\"";
149
        }
150
        echo ">{$currencySign}{$amt}</span></td>\n";
151
152
        if ($numRec != 0) {
153
            echo "<td style=\"text-align: center;\">";
154
            $jscriptCmd = "<a href=\"javascript: void 0\" onclick=\"" . "document.recedit.id.value = '$row_Recordset1[id]'; " . "document.recedit.StartDate.value = '$row_Recordset1[fdate]'; ";
155
            $jscriptCmd .= "document.recedit.Num.value = '$row_Recordset1[num]'; " . "document.recedit.Name.value = '$row_Recordset1[name]'; " . "document.recedit.Descr.value = '$row_Recordset1[descr]'; " . "document.recedit.Amount.value = '$row_Recordset1[amount]'; " . "document.recedit.Submit.value = 'Modify'; " . "document.recedit.op.value = 'FinRegEdit'; " . "return false;\">" . "<img style=\"border-width: 0px; width: 16px; height: 16px;\" src=" . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "' /></a>&nbsp;" . "<a href=\"donations.php?op=FinRegDel&id=$row_Recordset1[id]\">" . "<img style=\"border-width: 0px; width: 16px; height: 16px;\" src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'\" onClick=\"return confirm('" . _AD_DON_CONFIRM_DELETE . '\n\n' . _AD_DON_CONFIRM_ACTION . "')\"" . ' /></a>' . "</td>\n";
156
            echo $jscriptCmd;
157
        }
158
    } while (false != ($row_Recordset1 = $xoopsDB->fetchArray($Recordset1)));
159
160
    echo "</table>\n" . "<table style=\"width: 100%; text-align: center;\"><br/>\n";
161
    echo "<tr><td style=\"text-align: right; font-weight: bold;\" colspan=\"5\"><h4>" . _AD_DON_NETBAL . ":&nbsp;&nbsp;{$currencySign}";
162
    echo sprintf('%0.2f', $total) . "&nbsp;</h4></td></tr>\n";
163
    echo "</table><br/>\n";
164
165
    echo "<table style=\"text-align: center;\">\n" . "<tr><td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_DATE . "</td>\n" . "<td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_NUM . "</td>\n" . "<td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_NAME . "</td>\n" . "<td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_DESCRIPTION . "</td>\n" . "<td style=\"text-align: right; font-weight: bold;\">" . _AD_DON_AMOUNT . "</td></tr>\n" . "<tr>\n" . "<td style=\"text-align: center;\">\n" . "<form action=\"donations.php\" method=\"post\" name=\"recedit\">\n" . "<input name=\"id\" type=\"hidden\" />\n";
166
    $newDate  = new XoopsFormTextDateSelect('Date', 'StartDate', $size = 15, null);
167
    $showDate = $newDate->render();
168
    echo $showDate . "</td>\n";
169
    echo "<td style=\"text-align: center; width: 8px;\"><input name=\"Num\" type=\"text\" size=\"8\" /></td>\n" . "<td style=\"text-align: center;\"><input name=\"Name\" type=\"text\" /></td>\n" . "<td style=\"text-align: center;\"><input name=\"Descr\" type=\"text\" /></td>\n" . "<td style=\"text-align: right;\"><input name=\"Amount\" type=\"text\" size=\"8\" /></td>\n";
170
    echo "</tr>\n";
171
    echo "<tr><td style=\"text-align: right;\" colspan=\"5\">\n" . "<input name=\"\" type=\"reset\" value=\"" . _RESET . "\" onclick=\"" . "document.recedit.Submit.value = '" . _ADD . "'; " . "document.recedit.op.value = 'FinRegAdd'; " . "return true;\" />&nbsp;\n" . "<input type=\"hidden\" name=\"op\" value=\"FinRegAdd\" /><input name=\"Submit\" type=\"submit\" value=\"" . _AD_DON_ADD . "\" />\n" . "</form>\n";
172
    echo "</td></tr>\n";
173
    echo "</table>\n";
174
    echo "</td></tr></table>\n";
175
}
176
177
function addFinancialReg()
0 ignored issues
show
Coding Style introduced by
addFinancialReg uses the super-global variable $_POST which is generally not recommended.

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

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

// Better
class Router
{
    private $host;

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

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

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

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
178
{
179
    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...
180
181
    $time = date('h:i:s');
182
    //  $nTime = $_POST['StartYear'].'-'.$_POST['StartMonth'].'-'.$_POST['StartDay'].' '.$time;
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...
183
    //  $nTime = strtotime($nTime);
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...
184
    $nTime = strtotime("{$_POST['StartDate']} {$time}");
185
    if ($nTime == -1) {
186
        echo _AD_DON_ERR_BAD_DATE_FORMAT . "<br />\n";
187
    } else {
188
        if ('' === $_POST['Name']) {
189
            echo _AD_DON_ERR_BAD_NAME_FORMAT . "<br />\n";
190
        } else {
191
            if (!is_numeric($_POST['Amount'])) {
192
                echo _AD_DON_INVALID_AMOUNT . '<br />';
193
            } else {
194
                echo _AD_DON_FIELD_PASSED . '<br />';
195
                echo strftime('%Y-%m-%d', $nTime) . " $_POST[Num] $_POST[Name] $_POST[Descr] $_POST[Amount]<br /><br />";
196
197
                $insertRecordset = 'INSERT INTO `' . $xoopsDB->prefix('donations_financial') . '` VALUES ' . "(NULL, '" . strftime('%Y-%m-%d %H:%M:%S', $nTime) . "','" . addslashes($_POST['Num']) . "','" . addslashes($_POST['Name']) . "','" . addslashes($_POST['Descr']) . "','" . addslashes($_POST['Amount']) . "')";
198
199
                $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...
200
                echo "$insertRecordset";
201
                echo strftime('%Y-%m-%d', $nTime) . " $_POST[Num] $_POST[Name] $_POST[Descr] $_POST[Amount]<br /><br />$insertRecordset";
202
                header('Location: donations.php?op=Treasury#AdminTop');
203
            }
204
        }
205
    }
206
}
207
208
function deleteFinancialReg()
0 ignored issues
show
Coding Style introduced by
deleteFinancialReg uses the super-global variable $_GET which is generally not recommended.

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

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

// Better
class Router
{
    private $host;

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

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

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

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
209
{
210
    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...
211
212
    echo _AD_DON_FIELD_PASSED . "<br />\n";
213
214
    if (is_numeric($_GET['id']) && ($_GET['id'] > 0)) {
215
        $del_Recordset = 'DELETE FROM `' . $xoopsDB->prefix('donations_financial') . '`' . " WHERE `id`='" . (int)$_GET['id'] . "' LIMIT 1";
216
        $rvalue        = $xoopsDB->queryF($del_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...
217
        header('Location: donations.php?op=Treasury#AdminTop');
218
    } else {
219
        echo '<br />' . _AD_DON_ERR_INVALID_RECORD_ID . "<br />\n";
220
    }
221
}
222
223
function editFinancialReg()
0 ignored issues
show
Coding Style introduced by
editFinancialReg uses the super-global variable $_POST which is generally not recommended.

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

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

// Better
class Router
{
    private $host;

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

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

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

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
224
{
225
    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...
226
227
    $time = date('h:i:s');
228
    //    $nTime = $_POST['StartYear'].'-'.$_POST['StartMonth'].'-'.$_POST['StartDay'].' '.$time;
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...
229
    $nTime = $_POST['StartDate'] . ' ' . $time;
230
    $nTime = strtotime($nTime);
231
232
    if ($nTime == -1) {
233
        echo _AD_DON_ERR_BAD_DATE_FORMAT . "<br />\n";
234
    } else {
235
        if ('' === $_POST['Name']) {
236
            echo _AD_DON_ERR_BAD_NAME_FORMAT . "<br />\n";
237
        } else {
238
            if (!is_numeric($_POST['Amount'])) {
239
                echo _AD_DON_INVALID_AMOUNT2 . '<br />\n';
240
            } else {
241
                echo _AD_DON_FIELD_PASSED . "<br />\n";
242
243
                echo strftime('%Y-%m-%d', $nTime) . " $_POST[Num] $_POST[Name] $_POST[Descr] $_POST[Amount]<br /><br />\n";
244
245
                $insertRecordset = 'UPDATE `' . $xoopsDB->prefix('donations_financial') . "` SET date='" . strftime('%Y-%m-%d %H:%M:%S', $nTime) . "', num='$_POST[Num]', Name='$_POST[Name]', " . "descr='$_POST[Descr]', amount='$_POST[Amount]' WHERE id='$_POST[id]' LIMIT 1";
246
247
                echo "$insertRecordset";
248
                $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...
249
250
                echo "$_POST[id]" . strftime('%Y-%m-%d', $nTime) . " $_POST[Num] $_POST[Name] $_POST[Descr] $_POST[Amount]<br /><br />$insertRecordset";
251
252
                header('Location: donations.php?op=Treasury#AdminTop');
253
            }
254
        }
255
    }
256
}
257
258
/*********************************************************************
259
 *
260
 *********************************************************************/
261
function setConfig()
262
{
263
    global $tr_config, $xoopsModule, $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...
264
    //------------------------------------------------------------------------
265
    $indexAdmin = new ModuleAdmin();
266
    echo $indexAdmin->addNavigation('donations.php?op=Config');
267
    ?>
268
    <script Language="JavaScript">
269
        function isEmailAddr(email) {
270
            var result = false;
271
            var theStr = new String(email);
272
            var index = theStr.indexOf("@");
273
            if (index > 0) {
274
                var pindex = theStr.indexOf(".", index);
275
                if ((pindex > index + 1) && (theStr.length > pindex + 1))
276
                    result = true;
277
            }
278
            return result;
279
        }
280
281
        function validRequired(formField, fieldLabel, message) {
282
            var result = true;
283
284
            if (formField.value == "") {
285
                alert(message.replace("%1\$s", field));
286
287
                formField.focus();
288
                result = false;
289
            }
290
291
            return result;
292
        }
293
294
        function allDigits(str) {
295
            return inValidCharSet(str, "0123456789");
296
        }
297
298
        function inValidCharSet(str, charset) {
299
            var result = true;
300
301
            // Note: doesn't use regular expressions to avoid early Mac browser bugs
302
            for (var i = 0; i < str.length; i++)
303
                if (charset.indexOf(str.substr(i, 1)) < 0) {
304
                    result = false;
305
                    break;
306
                }
307
308
            return result;
309
        }
310
311
        function validInt(formField, fieldLabel, required, message) {
312
            var result = true;
313
314
            if (required && !validRequired(formField, fieldLabel, message))
315
                result = false;
316
317
            if (result) {
318
//      var num = parseInt(formField.value,10);
319
                if (!allDigits(formField.value)) {
320
                    if (required) {
321
                        //alert('Please enter a number for the "' + fieldLabel +'" field.');
322
                        alert(message.replace("%1\$s", fieldLabel));
323
                        formField.focus();
324
                        result = false;
325
                    }
326
                    elseif(formField.value == "")
327
                    {
328
                        return true;
329
                    }
330
                else
331
                    {
332
                        //alert('Please enter a number or a blank for the "' + fieldLabel +'" field.');
333
                        alert(message.replace("%1\$s", fieldLabel));
334
                        formField.focus();
335
                        result = false;
336
                    }
337
                }
338
            }
339
340
            return result;
341
        }
342
343
344
        function validateURL(formField, value, secure) {
345
346
            var match = /https/i.test(value);
347
348
            if (value != "" && !/^http/i.test(value)) {
349
                alert('The URL must start with http://');
350
                formField.focus();
351
352
                return false;
353
            }
354
355
            if (secure && value != "" && !/^https/i.test(value)) {
356
//      alert('This should reside on a HTTPS server.  Users will be warned about viewing secure and non-secure data on the same page');
357
                return confirm('This URL does not begin with https://\nThis image should reside on an HTTPS server.\nIf you use this URL, users will receive a warning\nabout viewing secure and non-secure data on the same page.\n\n  Are you sure you want to continue?');
358
            }
359
360
            return true;
361
        }
362
363
364
        function checkCancelledURL() {
365
            if (document.tr_configs.var_pp_image_url.value == "")
366
                alert('There is no URL for a Cancelled payment.  If you do not enter\na URL for cancelled payments PayPal will also use\nthis URL for cancelled payments.');
367
368
            return true;
369
        }
370
    </script>
371
    <?php
372
    //-------------------------------------------------------------------------------
373
    echo "<form name=\"tr_configs\" action=\"donations.php\" method=\"post\">\n" . "<input type=\"hidden\" name=\"op\" value=\"updateConfig\" />\n";
374
    echo "<table style=\"border-width: 1px; width: 90%; text-align: center;\"><tr>\n";
375
    echo "<td style=\"text-align: center; font-weight: bold;\" class=\"title\">\n";
376
    echo '<h3>' . _AD_DON_CONFIG_MODULE . "</h3>\n";
377
    echo "<table style=\"border-width: 1px; text-align: center;\">\n";
378
379
    ShowTextBox('don_button_top', "<span style=\"font-weight: bold;\">" . _AD_DON_IMG_BUTTON_TOP . '</span>', '', '70', 'onChange="return validateURL(this,this.value);"');
380
    ShowImgXYBox('don_top_img_width', 'don_top_img_height', "<span style=\"font-weight: bold;\">" . _AD_DON_IMAGE_SIZE . '</span>', '4', "onChange='return validInt(this,\"" . _AD_DON_IMAGE_SIZE . "\",0,\"" . _AD_DON_ALERTE_INPUT_NUMBER . "\");'");
381
    ShowTextBox('don_button_submit', "<span style=\"font-weight: bold;\">" . _AD_DON_IMG_BUTTON_URL . '</span>', '', '70', 'onChange="return validateURL(this,this.value);"');
382
    ShowImgXYBox('don_sub_img_width', 'don_sub_img_height', "<span style=\"font-weight: bold;\">" . _AD_DON_IMAGE_SIZE . '</span>', '4', "onChange='return validInt(this,\"" . _AD_DON_IMAGE_SIZE . "\",0,\"" . _AD_DON_ALERTE_INPUT_NUMBER . "\");'");
383
    //"onChange='return validInt(this,"._AD_DON_IMAGE_SIZE.")'"
384
    ShowTextBox('don_name_prompt', "<span style=\"font-weight: bold;\">" . _AD_DON_USERNAME_REQUEST . '</span>', '', '70', '');
385
    ShowTextBox('don_name_yes', "<span style=\"font-weight: bold;\">" . _AD_DON_USERNAME_REQUEST_YES . '</span>', '', '50', '');
386
    ShowTextBox('don_name_no', "<span style=\"font-weight: bold;\">" . _AD_DON_USERNAME_REQUEST_NO . '</span>', '', '50', '');
387
388
    $desc = 'This is where you can appeal to your' . 'users and your community for donations.' . 'Suggestion: Explain why you need donations,' . 'what you do with the money and how you' . 'manage it. Make them comfortable that' . 'they are not throwing their money away.';
389
390
    $sql       = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = 'don_text'";
391
    $Recordset = $xoopsDB->query($sql);
392
    $row       = $xoopsDB->fetchArray($Recordset);
393
    $donText   = $row['text'];
394
    echo "<tr>\n" . "  <td title=\"{$desc}\" style=\"text-align: right; font-weight: bold;\">" . _AD_DON_INTRODUCE_TEXT . "</td>\n" . "  <td title=\"{$desc}\" style=\"text-align: left;\">" . "<textarea name=\"var_don_text-rawtext-txt\" cols=\"100\" rows=\"20\">{$donText}</textarea></td>\n";
395
    echo "</tr>\n";
396
397
    //    ShowTextBox('don_amt_checked', '<span style=\'font-weight: bold;\'>'._AD_DON_AMOUNT_DEFAULT.'</span>', '', '4', "onChange=\"return validInt(this,'"._AD_DON_AMOUNT_DEFAULT."',1,'"._AD_DON_ALERTE_INPUT_NUMBER."');\"");
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
398
399
    echo "</table>\n";
400
    echo "<br />\n";
401
402
    $query_Recordset1     = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = 'don_amount' ORDER BY subtype";
403
    $Recordset1           = $xoopsDB->query($query_Recordset1);
404
    $row_Recordset1       = $xoopsDB->fetchArray($Recordset1);
405
    $totalRows_Recordset1 = $xoopsDB->getRowsNum($Recordset1);
0 ignored issues
show
Unused Code introduced by
$totalRows_Recordset1 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...
406
    $desc                 = htmlentities($row_Recordset1['text']);
407
408
    echo "<table style=\"border-width: 1px; width: 100px; text-align: center;\">\n";
409
    echo "  <tr><td style=\"text-align: center; width: 100%; font-weight: bold;\" colspan=\"8\">" . _AD_DON_SUGGESTED_AMOUNT . "<br /></td></tr>\n";
410
    $row1 = "  <tr><td title=\"{$desc}\" style=\"text-align: center;\"></td>\n";
411
    $row2 = "  <tr><td title=\"{$desc}\" style=\"text-align: center; font-weight: bold;\">" . _AD_DON_AMOUNT . "</td>\n";
412
    do {
413
        $row1 .= "    <td title=\"{$desc}\" style=\"text-align: center;\">{$row_Recordset1['subtype']}</td>\n";
414
        $row2 .= "    <td title=\"{$desc}\" style=\"text-align: center;\"><input size=\"4\" name=\"var_don_amount-{$row_Recordset1['subtype']}\" type=\"text\" value=\"{$row_Recordset1['value']}\" onChange=\"return validInt(this,'" . _AD_DON_SUGGESTED_AMOUNT . " #{$row_Recordset1['subtype']}',1,'" . _AD_DON_ALERTE_INPUT_NUMBER . "');\" /></td>\n";
415
    } while (false != ($row_Recordset1 = $xoopsDB->fetchArray($Recordset1)));
416
417
    $row1 .= "</tr>\n";
418
    $row2 .= "</tr>\n";
419
    echo "{$row1} {$row2}\n";
420
421
    // display default option
422
    $query_cfg   = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = 'don_amt_checked' LIMIT 1";
423
    $cfgResult   = $xoopsDB->query($query_cfg);
424
    $amt         = $xoopsDB->fetchArray($cfgResult);
425
    $amt_checked = (int)$amt['value'];
426
    echo '<tr><td>' . _AD_DON_DEFAULT . "</td>\n";
427
    for ($i = 1; $i < 8; ++$i) {
428
        $checked = ($i == $amt_checked) ? ' checked' : '';
429
        echo "<td><input type=\"radio\" name=\"var_don_amt_checked\"{$checked} value=\"{$i}\"></td>\n";
430
    }
431
    echo "</tr>\n";
432
    echo "</table>\n";
433
434
    echo "</td></tr>\n";
435
    echo "<tr><td style=\"text-align: center; width: 100%;\"><br /><input type=\"submit\" value=\"" . _AD_DON_SUBMIT . "\" /></td></tr>";
436
    echo "</table><br /><br />\n";
437
    echo $indexAdmin->addNavigation('donations.php?op=Config');
438
    echo "<table style=\"border-width: 1px; width: 90%; text-align: center;\"><tr>\n";
439
    echo "<td class=\"title\" style=\"font-weight: bold; text-align: center;\"><h3>" . _AD_DON_CONFIG_PAYPAL_HEADER . "</h3><br />\n";
440
    echo "<table style=\"border-width: 1px; text-align: center;\">\n";
441
442
    $rsql    = 'SELECT rank_id, rank_title FROM ' . $xoopsDB->prefix('ranks') . '';
443
    $rresult = $xoopsDB->query($rsql);
444
    $r_array = array();
445
    while (false != ($r_row = $xoopsDB->fetchRow($rresult))) {
446
        $r_array[] = $r_row;
447
    }
448
    ShowDropBox('paypal_url', '<span style=\'font-weight: bold;\'>' . _AD_DON_IPN_URL . '</span>');
449
    ShowTextBox('receiver_email', '<span style=\'font-weight: bold;\'>' . _AD_DON_IPN_EMAIL_RECEIVER . '</span>', '', '40', '');
450
    ShowTextBox('ty_url', '<span style=\'font-weight: bold;\'>' . _AD_DON_IPN_URL_SUCCESS . '</span>', '', '80', 'onChange="checkCancelledURL(); return validateURL(this,this.value);"');
451
    ShowTextBox('pp_cancel_url', '<span style=\'font-weight: bold;\'>' . _AD_DON_IPN_URL_CANCELED . '</span>', '', '80', 'onChange="return validateURL(this,this.value);"');
452
    ShowTextBox('pp_itemname', '<span style=\'font-weight: bold;\'>' . _AD_DON_PP_ITEM_NAME . '</span>', '', '20', '');
453
    ShowTextBox('pp_item_num', '<span style=\'font-weight: bold;\'>' . _AD_DON_PP_ITEM_NUMBER . '</span>', '', '20', '');
454
    ShowTextBox('pp_image_url', '<span style=\'font-weight: bold;\'>' . _AD_DON_PP_IMG . '</span>', '', '60', '');
455
    ShowYNBox('pp_get_addr', '<span style=\'font-weight: bold;\'>' . _AD_DON_PP_ASK_CP_ADRESS . '</span>');
456
    ShowDropBox('pp_curr_code', '<span style=\'font-weight: bold;\'>' . _AD_DON_PP_MONEY . '</span>');
457
    $gsql    = 'SELECT groupid, name FROM ' . $xoopsDB->prefix('groups') . ' WHERE groupid>3';
458
    $gresult = $xoopsDB->query($gsql);
459
    $g_array = array();
460
    while (false != ($g_row = $xoopsDB->fetchRow($gresult))) {
461
        $g_array[] = $g_row;
462
    }
463
    ShowArrayDropBox('assign_group', '<span style=\'font-weight: bold;\'>' . _AD_DON_PP_GROUP . '</span>', $g_array);
464
    $rsql    = 'SELECT rank_id, rank_title FROM ' . $xoopsDB->prefix('ranks') . '';
465
    $rresult = $xoopsDB->query($rsql);
466
    $r_array = array();
467
    while (false != ($r_row = $xoopsDB->fetchRow($rresult))) {
468
        $r_array[] = $r_row;
469
    }
470
    ShowArrayDropBox('assign_rank', '<span style=\'font-weight: bold;\'>' . _AD_DON_PP_RANK . '</span>', $r_array);
471
    ShowYNBox('don_forceadd', '<span style=\'font-weight: bold;\'>' . _AD_DON_ADD_ANYWAY . '</span>');
472
473
    echo "</table><br />\n";
474
475
    echo "<table style=\"border-width: 1px; width: 100px; text-align: center;\">\n";
476
    echo "  <tr><td style=\"text-align: center; width: 100%; font-weight: bold;\" colspan=\"2\">" . _AD_DON_IPN_LOGGING . "<br /></td></tr>\n";
477
    echo "  <tr>\n" . "    <td style=\"text-align: right; font-weight: bold;\">" . _AD_DON_IPN_LOGGING_LEVEL . "</td>\n" . "    <td style=\"text-align: left;\">\n" . "      <select size=\"1\" name=\"var_ipn_dbg_lvl\">\n";
478
    echo '        <option ';
479
    if (0 == $tr_config['ipn_dbg_lvl']) {
480
        echo 'selected ';
481
    }
482
    echo "value=\"0\">" . _AD_DON_LOG_OFF . "</option>\n";
483
    echo '        <option ';
484
    if ($tr_config['ipn_dbg_lvl'] == 1) {
485
        echo 'selected ';
486
    }
487
    echo "value=\"1\">" . _AD_DON_LOG_ONLY_ERRORS . "</option>\n";
488
    echo '        <option ';
489
    if ($tr_config['ipn_dbg_lvl'] == 2) {
490
        echo 'selected ';
491
    }
492
    echo "value=\"2\">" . _AD_DON_LOG_EVERYTHING . "</option>\n";
493
    echo "      </select>\n" . "    </td>\n" . "  </tr>\n";
494
495
    ShowTextBox('ipn_log_entries', '<nobr><span style=\'font-weight: bold;\'>' . _AD_DON_LOG_ENTRY . '</span></nobr>', '', '4', '');
496
497
    $desc = 'This box shows the link to the IPN recorder.
498
    This link must be pasted EXACTLY as it is
499
    into your PayPal IPN profile.  You can click
500
    on the "test" link to the right to verify
501
    that the IPN recorder is functioning correctly.';
502
    $desc = htmlentities($desc);
503
    echo "<tr>\n" . "  <td title =\"$desc\" style=\"text-align: right; font-weight: bold;\">" . _AD_DON_IPN_LINK . "</td>\n" . "  <td title =\"$desc\" style=\"text-align: center;\">&nbsp;" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/ipnppd.php&nbsp;&nbsp;\n" . "    <br /><a href=\"" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/ipnppd.php?dbg=1\" target=\"_blank\"><span style=\"font-weight: bold; font-style: italic;\"><img src=\"../assets/images/admin/info.png\" style=\"height: 16px; width: 16px;\" alt=\"\">&nbsp;" . _AD_DON_TEST_IPN . "</span></a>\n" . "  </td>\n" . "</tr>\n";
504
    echo "</table><br />\n";
505
    echo "</td></tr>\n";
506
    echo "<tr><td style=\"text-align: center; width: 100%;\"><input type=\"submit\" value=\"" . _AD_DON_SUBMIT . "\" />\n";
507
    echo '</td></tr></table><br /><br />';
508
509
    //Goal Preferences
510
    //===============================
511
    echo $indexAdmin->addNavigation('donations.php?op=Config');
512
    echo "<table style=\"border-width: 1px; width: 90%; text-align: center;\">\n" . "  <tr>\n";
513
    echo "    <td style=\"text-align: center; font-weight: bold;\" class=\"title\">\n" . '      <h3>' . _AD_DON_GOAL_PREFERENCES . "</h3>\n";
514
    echo "      <table style=\"border-width: 1px; text-align: center;\">\n" . "        <tr><td style=\"text-align: center;\">\n";
515
    echo "          <table style=\"border-width: 1px; text-align: center;\">\n";
516
    ShowDropBox('use_goal', '<span style=\'font-weight: bold;\'>' . _AD_DON_GOAL_TYPE . '.</span>');
517
    echo "          </table>\n";
518
519
    $query_Recordset1     = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = 'week_goal' AND subtype<>'Default'";
520
    $Recordset1           = $xoopsDB->query($query_Recordset1);
521
    $row_Recordset1       = $xoopsDB->fetchArray($Recordset1);
522
    $totalRows_Recordset1 = $xoopsDB->getRowsNum($Recordset1);
0 ignored issues
show
Unused Code introduced by
$totalRows_Recordset1 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...
523
    $desc                 = htmlentities($row_Recordset1['text']);
524
525
    echo "          <table style=\"border-width: 1px; width: 100px; text-align: center;\">\n" . "            <tr><td style=\"text-align: center; width: 100%; font-weight: bold;\" colspan=\"5\">" . _AD_DON_GOAL_HEBDO . "<br /></td></tr>\n";
526
    $row1 = "  <tr>\n" . "    <td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_WEEK . "</td>\n";
527
    $row2 = "  <tr>\n" . "    <td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_GOAL . "</td>\n";
528
    //-------------------------------------------------------------
529
    $shortMonth = explode('|', _AD_DON_SHORT_MONTH);
530
    $ordinaux   = explode('|', _AD_DON_NUMBER_ORDINAUX);
531
    //-------------------------------------------------------------
532
    $h = 0;
533 View Code Duplication
    do {
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...
534
        $ord = $ordinaux[$h++];
535
        $row1 .= "    <td title=\"{$desc}\" style=\"text-align: center;\">{$ord}</td>\n";
536
        $row2 .= "    <td title=\"{$desc}\" style=\"text-align: center;\"><input size=\"4\" name=\"var_week_goal-$row_Recordset1[subtype]\" type=\"text\" value=\"$row_Recordset1[value]\" onChange=\"return validInt(this,'$row_Recordset1[subtype] " . _AD_DON_GOAL_DONATION . "',1,'" . _AD_DON_ALERTE_INPUT_NUMBER . "');\" /></td>\n";
537
    } while (false != ($row_Recordset1 = $xoopsDB->fetchArray($Recordset1)));
538
    $row1 .= "  </tr>\n";
539
    $row2 .= "  </tr>\n";
540
    echo "{$row1} {$row2}";
541
542
    echo "</table>\n";
543
544
    $query_Recordset1     = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = 'month_goal' AND subtype<>'Default'";
545
    $Recordset1           = $xoopsDB->query($query_Recordset1);
546
    $row_Recordset1       = $xoopsDB->fetchArray($Recordset1);
547
    $totalRows_Recordset1 = $xoopsDB->getRowsNum($Recordset1);
0 ignored issues
show
Unused Code introduced by
$totalRows_Recordset1 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...
548
    $desc                 = htmlentities($row_Recordset1['text']);
549
550
    $h = 0;
551
    echo "<table style=\"border-width: 1px; width: 100px; text-align: center;\">\n";
552
    echo "  <tr><td style=\"text-align: center; width: 100%; font-weight: bold;\" colspan=\"13\">" . _AD_DON_GOAL_MENSUEL . "</td></tr><br />\n";
553
    $row1 = "  <tr>\n" . "    <td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_MONTH . "</td>\n";
554
    $row2 = "  <tr>\n" . "    <td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_GOAL . "</td>\n";
555 View Code Duplication
    do {
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...
556
        $month = $shortMonth[$h++];
557
        $row1 .= "    <td title=\"{$desc}\" style=\"text-align: center;\">{$month}</td>\n";
558
        $row2 .= "    <td title=\"{$desc}\" style=\"text-align: center;\"><input size=\"4\" name=\"var_month_goal-$row_Recordset1[subtype]\" type=\"text\" value=\"$row_Recordset1[value]\" onChange=\"return validInt(this,'$row_Recordset1[subtype] " . _AD_DON_GOAL_DONATION . "',1,'" . _AD_DON_ALERTE_INPUT_NUMBER . "');\" /></td>\n";
559
    } while (false != ($row_Recordset1 = $xoopsDB->fetchArray($Recordset1)));
560
    $row1 .= "  </tr>\n";
561
    $row2 .= "  </tr>\n";
562
    echo "{$row1}{$row2}";
563
564
    echo "</table>\n";
565
    echo "<table style=\"border-width: 1px; width: 100px; text-align: center;\">\n";
566
    ShowTextBox('swing_day', '<span style=\'font-weight: bold;\'>' . _AD_DON_SWING_DAY . '</span>', '175', '4', "onChange='return validInt(this,\"" . _AD_DON_SWING_DAY . "\",1,\"" . _AD_DON_ALERTE_INPUT_NUMBER . "\");'");
567
    echo "</table>\n";
568
569
    $query_Recordset1     = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name = 'quarter_goal' AND subtype<>'Default'";
570
    $Recordset1           = $xoopsDB->query($query_Recordset1);
571
    $row_Recordset1       = $xoopsDB->fetchArray($Recordset1);
572
    $totalRows_Recordset1 = $xoopsDB->getRowsNum($Recordset1);
0 ignored issues
show
Unused Code introduced by
$totalRows_Recordset1 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...
573
    $desc                 = htmlentities($row_Recordset1['text']);
574
575
    echo "<table style=\"border-width: 1px; width: 100px; text-align: center;\">\n";
576
    echo "  <tr><td style=\"text-align: center; width: 100%; font-weight: bold;\" colspan=\"5\">" . _AD_DON_QUARTER . "<br /></td></tr>\n";
577
    $row1 = "  <tr><td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_QUARTER . "</td>\n";
578
    $row2 = "  <tr><td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_GOAL . "</td>\n";
579
    $h    = 0;
580 View Code Duplication
    do {
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...
581
        $ord = $ordinaux[$h++];
582
        $row1 .= "    <td title='{$desc}' style='text-align: center;'>{$ord}</td>\n";
583
        $row2 .= "    <td title='{$desc}' style='text-align: center;'><input size=\"4\" name=\"var_quarter_goal-$row_Recordset1[subtype]\" type=\"text\" value=\"$row_Recordset1[value]\" onChange=\"return validInt(this,'$row_Recordset1[subtype] " . _AD_DON_GOAL_DONATION . "',1,'" . _AD_DON_ALERTE_INPUT_NUMBER . "');\" /></td>\n";
584
    } while (false != ($row_Recordset1 = $xoopsDB->fetchArray($Recordset1)));
585
    $row1 .= "  </tr>\n";
586
    $row2 .= "  </tr>\n";
587
    echo "{$row1} {$row2}";
588
589
    echo "</table><br />\n";
590
    echo "</td></tr>\n";
591
    echo "<tr><td style=\"text-align: center; width: 100%;\"><input type=\"submit\" value=\"" . _AD_DON_SUBMIT . "\"></td></tr>\n";
592
    echo "</table><br/>\n";
593
    echo "</td></tr></table>\n";
594
    echo "</form>\n";
595
}
596
597
/**
598
 *
599
 * Update Configuration Settings in the database
600
 */
601
function updateConfig()
0 ignored issues
show
Coding Style introduced by
updateConfig uses the super-global variable $_POST which is generally not recommended.

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

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

// Better
class Router
{
    private $host;

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

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

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

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
602
{
603
    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...
604
605
    echo '<br />' . _AD_DON_ERR_SQL_FAILURE . "<br /><br />\n";
606
607
    $error = 1;
608
    $ilog  = "<br />\n";
0 ignored issues
show
Unused Code introduced by
$ilog 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...
609
610
    foreach ($_POST as $option => $value) {
611
        /// Look for form variables
612
        if (preg_match('/var_/', $option)) {
613
            $varnm = preg_replace('/var_/', '', $option);
614
            // Check for subtype field
615
616
            if (preg_match('/-(.*)/', $varnm, $subtype)) {
617
                echo "<br />subtype = $subtype[1] <br />\n";
618
                $temp  = $varnm;
619
                $varnm = preg_replace('/-.*/', '', $temp);
620
                // Is this is a text field?
621
                if (preg_match('/([^-]*)-txt/', $subtype[1], $subtype2)) {
622
                    $textarea = addslashes($value);
623
                    echo "$varnm $subtype2[1] text=> " . nl2br(htmlspecialchars($textarea)) . "<br />\n";
624
                    $error &= updateDb($varnm, $subtype2[1], '0', $textarea);
625
                } else {
626
                    echo "$varnm $subtype[1] => $value<br />\n";
627
                    $error &= updateDbShort($varnm, $subtype[1], $value);
628
                }
629
            } else {
630
                echo "$varnm => $value<br />\n";
631
                $error &= updateDbShort($varnm, '', $value);
632
            }
633
        }
634
    }
635
636
    // If there were no errors
637
    if (0 == $error) {
638
        header('Location: donations.php?op=Config#AdminTop');
639
    }
640
}
641
642
/**
643
 *
644
 * Reconcile the IPN Log
645
 */
646
function reconcileIpn()
647
{
648
    global $tr_config, $modversion, $xoopsDB, $currencySign;
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...
649
    $recdate = '';
650
    $query_Recordset1 = 'SELECT `date` AS recdate FROM ' . $xoopsDB->prefix('donations_financial') . " WHERE name='PayPal IPN' ORDER BY date DESC LIMIT 1";
651
    $Recordset1       = $xoopsDB->query($query_Recordset1);
652
    if ($Recordset1) {
653
        $row_Recordset1 = $xoopsDB->fetchArray($Recordset1);
654
        if ($row_Recordset1) {
655
            $recdate = "payment_date > '" . $row_Recordset1['recdate'] . "' AND";
656
        }
657
    }
658
659
    $query_Recordset1 = 'SELECT `payment_date` AS curdate from ' . $xoopsDB->prefix('donations_transactions') . " WHERE payment_status='Completed' AND (txn_type='send_money' OR txn_type='web_accept')" . ' ORDER BY payment_date DESC LIMIT 1';
660
    $Recordset1       = $xoopsDB->query($query_Recordset1);
661
    $row_Recordset1   = $xoopsDB->fetchArray($Recordset1);
662
    $curdate          = $row_Recordset1['curdate'];
663
    $query_Recordset1 = 'SELECT SUM(mc_gross - mc_fee) AS ipn_total, COUNT(*) AS numrecs' . ' FROM ' . $xoopsDB->prefix('donations_transactions') . " WHERE ({$recdate} payment_date <= '{$curdate}')" . " AND payment_status = 'Completed' AND (txn_type='send_money' OR txn_type='web_accept')";
664
    $Recordset1       = $xoopsDB->query($query_Recordset1);
665
    $row_Recordset1   = $xoopsDB->fetchArray($Recordset1);
666
667
    echo "<span style='text-align: center; font-weight: bold;' class='title'>" . _AD_DON_UPDATE_REGISTER_IPN . '</span><br /><br />';
668
    if (0 == $row_Recordset1['numrecs']) {
669
        echo _AD_DON_NO_NEW_IPNS;
670
    } else {
671
        $insert_set = 'INSERT INTO `' . $xoopsDB->prefix('donations_financial') . "` (`date`,`num`,`name`,`descr`,`amount`) VALUES ('{$curdate}','','PayPal IPN','Auto-Reconcile','{$row_Recordset1['ipn_total']}')";
672
673
        if ($xoopsDB->query($insert_set)) {
674
            echo sprintf(_AD_DON_RECORDS_INSERTED, $row_Recordset1['numrecs'], $currencySign, $row_Recordset1['ipn_total']);
675
        } else {
676
            echo sprintf(_AD_DON_ERR_DB_INSERTION, $row_Recordset1['numrecs']);
677
        }
678
    }
679
680
    echo "<br /><br /><form action=\"donations.php?op=Treasury#AdminTop\" method=\"post\">";
681
    echo "<input type=\"hidden\" name=\"op\" value=\"Treasury\" />" . "<input type=\"submit\" value=\"" . _AD_DON_RETURN . "\" />" . '</form>';
682
}
683
684
/**
685
 *
686
 * Display the IPN Log
687
 *
688
 */
689
function showLog()
0 ignored issues
show
Coding Style introduced by
showLog uses the super-global variable $_SERVER which is generally not recommended.

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

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

// Better
class Router
{
    private $host;

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

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

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

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
690
{
691
    global $tr_config, $modversion, $xoopsDB, $currencySign;
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...
692
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
693
    $indexAdmin = new ModuleAdmin();
694
    echo $indexAdmin->addNavigation('donations.php?op=ShowLog');
695
696
    $query_Recordset1 = 'SELECT id, log_date, payment_date, logentry FROM ' . $xoopsDB->prefix('donations_translog') . ' ORDER BY log_date DESC';
697
    $transRecords     = $xoopsDB->query($query_Recordset1);
698
    $numRows          = $xoopsDB->getRowsNum($transRecords);
699
    $logForm          = new XoopsThemeForm(_AD_DON_SHOW_LOG, 'logform', $_SERVER['PHP_SELF'], 'POST');
700
701
    if ($numRows) {
702
        while (false != (list($rId, $rLdate, $rPdate, $rLentry) = $xoopsDB->fetchRow($transRecords))) {
703
            $thisTray  = 'logTray_' . $rId;
704
            $$thisTray = new XoopsFormElementTray($rId, '<br />');
705
            $$thisTray->addElement(new XoopsFormLabel(_AD_DON_LOG_DATE, $rLdate));
706
            $$thisTray->addElement(new XoopsFormLabel(_AD_DON_PMNT_DATE, $rPdate));
707
            $rLentrySplit = '';
708
            $rLentry      = htmlspecialchars($rLentry);
709
            $dispWidth    = 110;
710
            do {
711
                //                echo '[' . strlen($rLentry) . ']<br />';
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% 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...
712
                $pos = strrpos($rLentry, ' ', $dispWidth - strlen($rLentry));
713
                if (!$pos) {
714
                    $pos = strrpos($rLentry, ',', $dispWidth - strlen($rLentry));
715
                    if (!$pos) {
716
                        $rLentrySplit .= '<br />' . substr($rLentry, 0, $dispWidth);
717
                        $rLentry = substr($rLentry, $dispWidth);
718 View Code Duplication
                    } else {
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...
719
                        $rLentrySplit .= '<br />' . substr($rLentry, 0, $pos + 1);
720
                        $rLentry = substr($rLentry, $pos);
721
                    }
722 View Code Duplication
                } else {
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...
723
                    $rLentrySplit .= '<br />' . substr($rLentry, 0, $pos + 1);
724
                    $rLentry = substr($rLentry, $pos);
725
                }
726
            } while (strlen($rLentry) > $dispWidth);
727
            $$thisTray->addElement(new XoopsFormLabel(_AD_DON_LOG_ENTRY_TXT, $rLentrySplit . $rLentry));
728
729
            //            $$thisTray->addElement(new XoopsFormLabel( _AD_DON_LOGENTRY, $rLentry));
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
730
            $logForm->addElement($$thisTray);
731
        }
732
        $buttonTray = new XoopsFormElementTray('');
733
        $cButton    = new XoopsFormButton('', 'op', _AD_DON_CLEAR_LOG, 'submit');
734
        $cButton->setExtra("onclick=\"this.form.elements.op.value='ClearLog'\"", true);
735
        $buttonTray->addElement($cButton);
736
        $logForm->addElement($buttonTray);
737
    } else {
738
        //FIXME: replace this with 'full width' cell
739
        $logForm->addElement(new XoopsFormLabel('', _AD_DON_LOG_EMPTY));
740
    }
741
    $logForm->display();
742
}
743
744
/**
745
 *
746
 * Clear the IPN log
747
 * @param int $ok =0 ask to verify, !=0 clear the log
748
 */
749
function clearLog($ok = 0)
750
{
751
    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...
752
    if ($ok > 0) {
753
        $sql     = 'DELETE FROM ' . $xoopsDB->prefix('donations_translog');
754
        $success = $xoopsDB->query($sql);
755
        $retMsg  = $success ? _AD_DON_LOG_CLEARED : _AD_DON_LOG_NOT_CLEARED;
756
        echo "<form name=\"ipnlog\" action=\"donations.php\" method=\"get\">";
757
        echo "<table style=\"text-align: center; border-width: 0px; margin: 4px;\"><tr><td>{$retMsg}</td></tr>";
758
        echo "<tr><td><input type=\"submit\" value=\"" . _AD_DON_CONTINUE . "\" /></td></tr></table>";
759
        echo '</form>';
760
        //        redirect_header('./index.php', 2, $retMsg);
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...
761
        //
762
    } else {
763
        xoops_confirm(array('op' => 'ClearLog', 'ok' => 1), 'index.php', _AD_DON_CLEAR_THIS_LOG, _DELETE);
764
    }
765
}
766
767
/**
768
 *
769
 * Process incoming operand
770
 *
771
 */
772
773
$op = isset($_GET['op']) ? $_GET['op'] : 'Treasury';
774
$op = isset($_POST['op']) ? $_POST['op'] : $op;
775
776
switch ($op) {
777
    case 'FinRegAdd':
778
        addFinancialReg();
779
        break;
780
781
    case 'FinRegEdit':
782
        editFinancialReg();
783
        break;
784
785
    case 'FinRegDel':
786
        deleteFinancialReg();
787
        break;
788
789
    case 'Config':
790
        setConfig();
791
        break;
792
793
    case 'updateConfig':
794
        updateConfig();
795
        break;
796
797
    case 'IpnRec':
798
        reconcileIpn();
799
        break;
800
    case 'ShowLog':
801
        showLog();
802
        break;
803
804
    case 'ClearLog':
805
        $ok = isset($_GET['ok']) ? (int)$_GET['ok'] : 0;
806
        $ok = isset($_POST['ok']) ? (int)$_POST['ok'] : $ok;
807
        clearLog($ok);
808
        break;
809
810
    default:
811
    case 'Treasury':
812
        treasury();
813
        break;
814
}
815
include_once __DIR__ . '/admin_footer.php';
816