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

donations.php ➔ Config()   D

Complexity

Conditions 13
Paths 192

Size

Total Lines 374
Code Lines 214

Duplication

Lines 15
Ratio 4.01 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 13
eloc 214
c 1
b 0
f 0
nc 192
nop 0
dl 15
loc 374
rs 4.6605

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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) 2004 by Xoops2 Donations Module Dev Team			    */
5
/* http://dev.xoops.org/modules/xfmod/project/?group_id=1060			*/
6
/* $Id: donations.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
include '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'cp_header.php';
33
34
xoops_loadLanguage('main', $xoopsModule->getVar('dirname'));
35
include '..' . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'functions.php';
36
include_once '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
$curr_sign = define_curr($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, $curr_sign, $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 . DIRECTORY_SEPARATOR . 'class'   . DIRECTORY_SEPARATOR . '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'])) ? intval($_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( $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"
117
    . "<tr><td>\n";
118
    echo "<table style=\"border-width: 0px; padding: 0px; margin: 0px; text-align: center;\">\n";
119
    echo "  <tr><td style=\"width: 100%; text-align: center; font-weight: bold;\">";
120
    echo "<font class=\"option\"><h3>" . _AD_DON_TREASURY_F_REGISTER . "</h3></font></td></tr>\n";
121
    echo "  <tr><td style=\"width: 100%;\">" . _AD_DON_NEW_IPN_COUNT . " {$num_ipn} - " . _AD_DON_TOTALING . " {$curr_sign}{$ipn_tot}";
122
    echo "</td></tr>\n";
123
    echo "<tr><td style=\"width: 100%; text-align: center;\">\n";
124
    echo "  <form action=\"donations.php?op=IpnRec#AdminTop\" method=\"post\">\n";
125
    echo "    <input type=\"hidden\" name=\"op\" value=\"IpnRec\" />\n"
126
    ."    <input type=\"submit\" value=\""._AD_DON_SYNCHRONISE_IPN."\" onClick=\"return confirm('"._AD_DON_CONFIRM_TOTAL_UP."')\" />\n"
127
    ."  </form>\n";
128
    echo "</td></tr></table>\n";
129
130
    if( $pageNum_Recordset1 > 0 ) {
131
        echo "<table style=\"border-width: 0px; text-align: center;\">\n"
132
        . "  <tr>\n";
133
        echo "    <td><form action=\"donations.php#AdminTop\" method=\"post\">\n"
134
        . "<input type=\"hidden\" name=\"op\" value=\"Treasury\" />\n"
135
        . "<input type=\"hidden\" name=\"pageNum_Recordset1\" value=\"0\" />\n"
136
        . "<input type=\"hidden\" name=\"totalRows_Recordset1\" value=\"{$totalRows_Recordset1}\" />\n"
137
        . "<input type=\"submit\" name=\"navig\" value=\"|&lt;\" title=\"" . _AD_DON_CURRENT . "\" /></form></td>\n";
138
        echo "<td><form action=\"donations.php#AdminTop\" method=\"post\">\n"
139
        . "<input type=\"hidden\" name=\"op\" value=\"Treasury\" />\n"
140
        . "<input type=\"hidden\" name=\"pageNum_Recordset1\" value=\"" . max(0, $pageNum_Recordset1 - 1) . "\" />\n"
141
        . "<input type=\"hidden\" name=\"totalRows_Recordset1\" value=\"{$totalRows_Recordset1}\" />\n"
142
        . "<input type=\"submit\" name=\"navig\" value=\"&lt;\" title=\"" . _AD_DON_NEXT_NEWEST . "\" /></form></td>\n";
143
        if( $pageNum_Recordset1 < $totalPages_Recordset1 ) {
144
            echo "<td><form action=\"donations.php#AdminTop\" method=\"post\">\n"
145
            . "<input type=\"hidden\" name=\"op\" value=\"Treasury\" />\n"
146
            . "<input type=\"hidden\" name=\"pageNum_Recordset1\" value=\"" . min($totalPages_Recordset1, $pageNum_Recordset1 + 1) . "\" />\n"
147
            . "<input type=\"hidden\" name=\"totalRows_Recordset1\" value=\"{$totalRows_Recordset1}\" />\n"
148
            . "<input type=\"submit\" name=\"navig\" value=\"&gt;\" title=\"" . _AD_DON_NEXT_OLDEST ."\" /></form></td>\n";
149
            echo "<td><form action=\"donations.php#AdminTop\" method=\"post\">\n"
150
            . "<input type=\"hidden\" name=\"op\" value=\"Treasury\" />\n"
151
            . "<input type=\"hidden\" name=\"pageNum_Recordset1\" value=\"{$totalPages_Recordset1}\" />\n"
152
            . "<input type=\"hidden\" name=\"totalRows_Recordset1\" value=\"{$totalRows_Recordset1}\" />\n"
153
            . "<input type=\"submit\" name=\"navig\" value=\"&gt;|\" title=\"" . _AD_DON_OLDEST . "\" /></form></td>\n";
154
        }
155
        echo "</tr></table>\n";
156
    }
157
158
        echo "<table class='outer' width='100%' border='0' cellpadding='0' cellspacing='0'>"
159
        . "<th align='center'>" . _AD_DON_DATE
160
        . "</th><th align='center'>". _AD_DON_NUM
161
        . "</th><th align='center'>" . _AD_DON_NAME
162
        . "</th><th align='center'>" . _AD_DON_DESCRIPTION
163
        . "</th><th align='center'>" . _AD_DON_AMOUNT
164
        . "</th><th align='center'>" . _AD_DON_ACTION
165
        . "</th></tr>\n";
166
//		$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...
167
168
        $row=0;
169
    do {
170
        $row += 1;
171
        echo "<tr>\n";
172
        echo "</td>\n"
173
        ."<td style=\"text-align: center;\">$row_Recordset1[fdate]</td>\n"
174
        ."<td style=\"text-align: center; width: 8px;\">$row_Recordset1[num]</td>\n"
175
        ."<td style=\"text-align: center;\">$row_Recordset1[name]</td>\n"
176
        ."<td style=\"text-align: center;\">$row_Recordset1[descr]</td>\n"
177
        ."<td style=\"text-align: right;\"><span ";
178
        $amt =  sprintf("%10.2f",$row_Recordset1['amount']);
179
        if( $amt < 0 ) {
180
            echo "style=\"color: #FF0000;\"";
181
        }
182
        echo ">{$curr_sign}{$amt}</span></td>\n";
183
        
184
        if ( $numRec!=0 ) {
185
        echo "<td style=\"text-align: center;\">";
186
        $jscriptCmd = "<a href=\"javascript: void 0\" onclick=\""
187
            ."document.recedit.id.value = '$row_Recordset1[id]'; "
188
            ."document.recedit.StartDate.value = '$row_Recordset1[fdate]'; ";
189
            $jscriptCmd .= "document.recedit.Num.value = '$row_Recordset1[num]'; "
190
            ."document.recedit.Name.value = '$row_Recordset1[name]'; "
191
            ."document.recedit.Descr.value = '$row_Recordset1[descr]'; "
192
            ."document.recedit.Amount.value = '$row_Recordset1[amount]'; "
193
            ."document.recedit.Submit.value = 'Modify'; "
194
            ."document.recedit.op.value = 'FinRegEdit'; "
195
            ."return false;\">"
196
            ."<img style=\"border-width: 0px; width: 16px; height: 16px;\" src=". $pathIcon16 .'/edit.png'." alt='" . _EDIT . "' title='" . _EDIT . "' /></a>&nbsp;"
197
            ."<a href=\"donations.php?op=FinRegDel&id=$row_Recordset1[id]\">"
198
            ."<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 . "')\""
199
            ." /></a>"
200
            ."</td>\n"
201
            ;
202
            echo $jscriptCmd;
203
       }
204
            
205
206
    } while ($row_Recordset1 = $xoopsDB->fetchArray($Recordset1));
207
208
    echo "</table>\n"  . "<table style=\"width: 100%; text-align: center;\"><br/>\n";
209
    echo "<tr><td style=\"text-align: right; font-weight: bold;\" colspan=\"5\"><h4>" . _AD_DON_NETBAL . ":&nbsp;&nbsp;{$curr_sign}";
210
    echo sprintf("%0.2f", $total) . "&nbsp;</h4></td></tr>\n";
211
    echo "</table><br/>\n";
212
213
    echo "<table style=\"text-align: center;\">\n"
214
    . "<tr><td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_DATE . "</td>\n"
215
    . "<td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_NUM . "</td>\n"
216
    . "<td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_NAME . "</td>\n"
217
    . "<td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_DESCRIPTION . "</td>\n"
218
    . "<td style=\"text-align: right; font-weight: bold;\">" . _AD_DON_AMOUNT . "</td></tr>\n"
219
    . "<tr>\n"
220
    . "<td style=\"text-align: center;\">\n"
221
    . "<form action=\"donations.php\" method=\"post\" name=\"recedit\">\n"
222
    . "<input name=\"id\" type=\"hidden\" />\n";
223
    $newDate = new XoopsFormTextDateSelect('Date', 'StartDate', $size = 15, NULL);
224
    $showDate = $newDate->render();
225
    echo $showDate . "</td>\n";
226
    echo "<td style=\"text-align: center; width: 8px;\"><input name=\"Num\" type=\"text\" size=\"8\" /></td>\n"
227
    . "<td style=\"text-align: center;\"><input name=\"Name\" type=\"text\" /></td>\n"
228
    . "<td style=\"text-align: center;\"><input name=\"Descr\" type=\"text\" /></td>\n"
229
    . "<td style=\"text-align: right;\"><input name=\"Amount\" type=\"text\" size=\"8\" /></td>\n";
230
    echo "</tr>\n";
231
    echo "<tr><td style=\"text-align: right;\" colspan=\"5\">\n"
232
    . "<input name=\"\" type=\"reset\" value=\"" . _RESET . "\" onclick=\""
233
    . "document.recedit.Submit.value = '"._ADD."'; "
234
    . "document.recedit.op.value = 'FinRegAdd'; "
235
    . "return true;\" />&nbsp;\n"
236
    . "<input type=\"hidden\" name=\"op\" value=\"FinRegAdd\" /><input name=\"Submit\" type=\"submit\" value=\"" . _AD_DON_ADD . "\" />\n"
237
    . "</form>\n";
238
    echo "</td></tr>\n";
239
    echo "</table>\n";
240
    echo "</td></tr></table>\n";
241
}
242
243
function FinancialRegAdd()
0 ignored issues
show
Coding Style introduced by
FinancialRegAdd 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...
244
{
245
    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...
246
247
    $time = date("h:i:s");
248
    //	$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...
249
    //	$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...
250
    $nTime = strtotime("{$_POST['StartDate']} {$time}");
251
    if($nTime == -1) {
252
        echo _AD_DON_ERR_BAD_DATE_FORMAT . "<br />\n";
253
    } else {
254
        if ( strlen($_POST['Name']) == 0) {
255
            echo _AD_DON_ERR_BAD_NAME_FORMAT . "<br />\n";
256
        } else {
257
            if( !is_numeric($_POST['Amount'])) {
258
                echo _AD_DON_INVALID_AMOUNT."<br />";
259
            } else {
260
                echo _AD_DON_FIELD_PASSED."<br />";
261
                echo strftime("%Y-%m-%d", $nTime) . " $_POST[Num] $_POST[Name] $_POST[Descr] $_POST[Amount]<br /><br />";
262
263
                $insert_Recordset = "INSERT INTO `".$xoopsDB->prefix("donations_financial")."` VALUES "
264
                . "(NULL, '" . strftime("%Y-%m-%d %H:%M:%S", $nTime) . "','" . addslashes($_POST['Num']) . "','" . addslashes($_POST['Name'])
265
                . "','" . addslashes($_POST['Descr']) . "','" . addslashes($_POST['Amount']) . "')";
266
267
                $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...
268
                echo "$insert_Recordset";
269
                echo strftime("%Y-%m-%d", $nTime) . " $_POST[Num] $_POST[Name] $_POST[Descr] $_POST[Amount]<br /><br />$insert_Recordset";
270
                Header("Location: donations.php?op=Treasury#AdminTop");
271
            }
272
        }
273
    }
274
}
275
276
function FinancialRegDel()
0 ignored issues
show
Coding Style introduced by
FinancialRegDel 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...
277
{
278
    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...
279
280
    echo _AD_DON_FIELD_PASSED . "<br />\n";
281
282
    if( is_numeric($_GET['id']) && ($_GET['id'] > 0) ) {
283
        $del_Recordset = "DELETE FROM `" . $xoopsDB->prefix("donations_financial") . "`"
284
        . " WHERE `id`='" . intval($_GET[id]) . "' LIMIT 1";
285
        $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...
286
        header("Location: donations.php?op=Treasury#AdminTop");
287
    } else {
288
        echo "<br />" . _AD_DON_ERR_INVALID_RECORD_ID . "<br />\n";
289
    }
290
}
291
292
function FinancialRegEdit()
0 ignored issues
show
Coding Style introduced by
FinancialRegEdit 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...
293
{
294
    global $tr_config, $modversion, $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
295
296
    $time = date("h:i:s");
297
    //    $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...
298
    $nTime = $_POST['StartDate'] . ' ' . $time;
299
    $nTime = strtotime($nTime);
300
301
    if($nTime == -1) {
302
        echo _AD_DON_ERR_BAD_DATE_FORMAT . "<br />\n";
303
    } else {
304
        if( strlen($_POST['Name']) == 0) {
305
            echo _AD_DON_ERR_BAD_NAME_FORMAT . "<br />\n";
306
        } else {
307
            if( !is_numeric($_POST['Amount'])) {
308
                echo _AD_DON_INVALID_AMOUNT2 . '<br />\n';
309
            } else {
310
                echo _AD_DON_FIELD_PASSED . "<br />\n";
311
312
                echo strftime("%Y-%m-%d", $nTime) . " $_POST[Num] $_POST[Name] $_POST[Descr] $_POST[Amount]<br /><br />\n";
313
314
                $insert_Recordset = "UPDATE `".$xoopsDB->prefix("donations_financial")."` SET date='". strftime("%Y-%m-%d %H:%M:%S", $nTime) . "', num='$_POST[Num]', Name='$_POST[Name]', "
315
                . "descr='$_POST[Descr]', amount='$_POST[Amount]' WHERE id='$_POST[id]' LIMIT 1";
316
317
                echo "$insert_Recordset";
318
                $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...
319
320
                echo "$_POST[id]" . strftime("%Y-%m-%d", $nTime) . " $_POST[Num] $_POST[Name] $_POST[Descr] $_POST[Amount]<br /><br />$insert_Recordset";
321
322
                Header("Location: donations.php?op=Treasury#AdminTop");
323
324
            }
325
        }
326
    }
327
}
328
329
/*********************************************************************
330
 *
331
 *********************************************************************/
332
function Config()
333
{
334
    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...
335
    //------------------------------------------------------------------------
336
    $indexAdmin = new ModuleAdmin();
337
    echo $indexAdmin->addNavigation('donations.php?op=Config');
338
    ?>
339
<script Language="JavaScript">
340
function isEmailAddr(email)
341
{
342
  var result = false;
343
  var theStr = new String(email);
344
  var index = theStr.indexOf("@");
345
  if (index > 0)
346
  {
347
    var pindex = theStr.indexOf(".",index);
348
    if ((pindex > index+1) && (theStr.length > pindex+1))
349
    result = true;
350
  }
351
  return result;
352
}
353
354
function validRequired(formField,fieldLabel,message)
355
{
356
    var result = true;
357
358
    if (formField.value == "")
359
    {
360
        alert(message.replace("%1\$s", field));
361
362
        formField.focus();
363
        result = false;
364
    }
365
366
    return result;
367
}
368
369
function allDigits(str)
370
{
371
    return inValidCharSet(str,"0123456789");
372
}
373
374
function inValidCharSet(str,charset)
375
{
376
    var result = true;
377
378
    // Note: doesn't use regular expressions to avoid early Mac browser bugs
379
    for (var i=0;i<str.length;i++)
380
        if (charset.indexOf(str.substr(i,1))<0)
381
        {
382
            result = false;
383
            break;
384
        }
385
386
    return result;
387
}
388
389
function validInt(formField,fieldLabel,required,message)
390
{
391
    var result = true;
392
393
    if (required && !validRequired(formField,fieldLabel,message))
394
        result = false;
395
396
    if (result)
397
    {
398
// 		var num = parseInt(formField.value,10);
399
        if (!allDigits(formField.value))
400
        {
401
            if(required)
402
            {
403
                //alert('Please enter a number for the "' + fieldLabel +'" field.');
404
                alert(message.replace("%1\$s",fieldLabel));
405
                formField.focus();
406
                result = false;
407
            }
408
            else if ( formField.value == "" )
409
            {
410
                return true;
411
            }
412
            else
413
            {
414
                //alert('Please enter a number or a blank for the "' + fieldLabel +'" field.');
415
                alert(message.replace("%1\$s",fieldLabel));
416
                formField.focus();
417
                result = false;
418
            }
419
        }
420
    }
421
422
    return result;
423
}
424
425
426
function validdateURL(formField, value, secure)
427
{
428
429
    var match = /https/i.test(value);
430
431
    if( value != "" && !/^http/i.test(value) )
432
    {
433
        alert('The URL must start with http://');
434
        formField.focus();
435
        return false;
436
    }
437
438
    if( secure && value != "" && !/^https/i.test(value) )
439
    {
440
//		alert('This should reside on a HTTPS server.  Users will be warned about viewing secure and non-secure data on the same page');
441
442
        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?');
443
    }
444
445
    return true;
446
}
447
448
449
function checkCancelledURL()
450
{
451
    if( document.tr_configs.var_pp_image_url.value == "")
452
        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.');
453
    return true;
454
}
455
</script>
456
    <?php
457
    //-------------------------------------------------------------------------------
458
    echo "<form name=\"tr_configs\" action=\"donations.php\" method=\"post\">\n"
459
    . "<input type=\"hidden\" name=\"op\" value=\"ConfigUpdate\" />\n";
460
    echo "<table style=\"border-width: 1px; width: 90%; text-align: center;\"><tr>\n";
461
    echo "<td style=\"text-align: center; font-weight: bold;\" class=\"title\">\n";
462
    echo "<h3>" . _AD_DON_CONFIG_MODULE . "</h3>\n";
463
    echo "<table style=\"border-width: 1px; text-align: center;\">\n";
464
465
    ShowTextBox('don_button_top', "<span style=\"font-weight: bold;\">" . _AD_DON_IMG_BUTTON_TOP . "</span>", '', '70', 'onChange="return validdateURL(this,this.value);"');
466
    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."\");'");
467
    ShowTextBox('don_button_submit', "<span style=\"font-weight: bold;\">" . _AD_DON_IMG_BUTTON_URL . "</span>", '', '70', 'onChange="return validdateURL(this,this.value);"');
468
    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."\");'");
469
    //"onChange='return validInt(this,"._AD_DON_IMAGE_SIZE.")'"
470
    ShowTextBox('don_name_prompt', "<span style=\"font-weight: bold;\">" . _AD_DON_USERNAME_REQUEST . "</span>", '', '70', '');
471
    ShowTextBox('don_name_yes', "<span style=\"font-weight: bold;\">" . _AD_DON_USERNAME_REQUEST_YES . "</span>", '', '50', '');
472
    ShowTextBox('don_name_no', "<span style=\"font-weight: bold;\">" . _AD_DON_USERNAME_REQUEST_NO . "</span>", '', '50', '');
473
474
    $desc = 'This is where you can appeal to your'
475
          . 'users and your community for donations.'
476
        . 'Suggestion: Explain why you need donations,'
477
          . 'what you do with the money and how you'
478
          . 'manage it. Make them comfortable that'
479
        . 'they are not throwing their money away.';
480
481
    $sql = "SELECT * FROM " . $xoopsDB->prefix("donations_config") . " WHERE name = 'don_text'";
482
    $Recordset = $xoopsDB->query($sql);
483
    $row = $xoopsDB->fetchArray($Recordset);
484
    $donText = $row['text'];
485
    echo "<tr>\n"
486
    ."  <td title=\"{$desc}\" style=\"text-align: right; font-weight: bold;\">" . _AD_DON_INTRODUCE_TEXT . "</td>\n"
487
    ."  <td title=\"{$desc}\" style=\"text-align: left;\">"
488
    ."<textarea name=\"var_don_text-rawtext-txt\" cols=\"100\" rows=\"20\">{$donText}</textarea></td>\n";
489
    echo "</tr>\n";
490
491
//    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...
492
493
    echo "</table>\n";
494
    echo "<br />\n";
495
496
    $query_Recordset1 = "SELECT * FROM ".$xoopsDB->prefix("donations_config")." WHERE name = 'don_amount' ORDER BY subtype";
497
    $Recordset1 = $xoopsDB->query($query_Recordset1);
498
    $row_Recordset1 = $xoopsDB->fetchArray($Recordset1);
499
    $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...
500
    $desc = htmlentities($row_Recordset1['text']);
501
502
    echo "<table style=\"border-width: 1px; width: 100px; text-align: center;\">\n";
503
    echo "  <tr><td style=\"text-align: center; width: 100%; font-weight: bold;\" colspan=\"8\">" . _AD_DON_SUGGESTED_AMOUNT . "<br /></td></tr>\n";
504
    $row1 = "  <tr><td title=\"{$desc}\" style=\"text-align: center;\"></td>\n";
505
    $row2 = "  <tr><td title=\"{$desc}\" style=\"text-align: center; font-weight: bold;\">" . _AD_DON_AMOUNT . "</td>\n";
506
    do {
507
        $row1 .= "    <td title=\"{$desc}\" style=\"text-align: center;\">{$row_Recordset1['subtype']}</td>\n";
508
        $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";
509
    } while ($row_Recordset1 = $xoopsDB->fetchArray($Recordset1));
510
511
    $row1 .= "</tr>\n";
512
    $row2 .= "</tr>\n";
513
    echo "{$row1} {$row2}\n";
514
515
    // display default option
516
    $query_cfg = "SELECT * FROM ".$xoopsDB->prefix("donations_config")
517
               . " WHERE name = 'don_amt_checked' LIMIT 1";
518
    $cfgResult = $xoopsDB->query($query_cfg);
519
    $amt = $xoopsDB->fetchArray($cfgResult);
520
    $amt_checked = intval($amt['value']);
521
    echo "<tr><td>" . _AD_DON_DEFAULT . "</td>\n";
522
    for ($i=1; $i<8; $i++) {
523
        $checked = ($i == $amt_checked) ? ' checked' : '';
524
        echo "<td><input type=\"radio\" name=\"var_don_amt_checked\"{$checked} value=\"{$i}\"></td>\n";
525
    }
526
    echo "</tr>\n";
527
    echo "</table>\n";
528
529
    echo "</td></tr>\n";
530
    echo "<tr><td style=\"text-align: center; width: 100%;\"><br /><input type=\"submit\" value=\"" . _AD_DON_SUBMIT ."\" /></td></tr>";
531
    echo "</table><br /><br />\n";
532
    echo $indexAdmin->addNavigation('donations.php?op=Config');
533
    echo "<table style=\"border-width: 1px; width: 90%; text-align: center;\"><tr>\n";
534
    echo "<td class=\"title\" style=\"font-weight: bold; text-align: center;\"><h3>" . _AD_DON_CONFIG_PAYPAL_HEADER . "</h3><br />\n";
535
    echo "<table style=\"border-width: 1px; text-align: center;\">\n";
536
537
    $rsql = "SELECT rank_id, rank_title FROM " . $xoopsDB->prefix('ranks') . "";
538
    $rresult = $xoopsDB->query($rsql);
539
    $r_array = array();
540
    while( $r_row = $xoopsDB->fetchRow($rresult) ){
541
        $r_array[] = $r_row;
542
    }
543
    ShowDropBox('paypal_url', '<span style=\'font-weight: bold;\'>'._AD_DON_IPN_URL.'</span>');
544
    ShowTextBox('receiver_email', '<span style=\'font-weight: bold;\'>'._AD_DON_IPN_EMAIL_RECEIVER.'</span>', '', '40', '');
545
    ShowTextBox('ty_url', '<span style=\'font-weight: bold;\'>' . _AD_DON_IPN_URL_SUCCESS . '</span>', '', '80', 'onChange="checkCancelledURL(); return validdateURL(this,this.value);"');
546
    ShowTextBox('pp_cancel_url', '<span style=\'font-weight: bold;\'>'._AD_DON_IPN_URL_CANCELED.'</span>', '', '80', 'onChange="return validdateURL(this,this.value);"');
547
    ShowTextBox('pp_itemname', '<span style=\'font-weight: bold;\'>'._AD_DON_PP_ITEM_NAME.'</span>', '', '20', '');
548
    ShowTextBox('pp_item_num', '<span style=\'font-weight: bold;\'>'._AD_DON_PP_ITEM_NUMBER.'</span>', '', '20', '');
549
    ShowTextBox('pp_image_url', '<span style=\'font-weight: bold;\'>'._AD_DON_PP_IMG.'</span>', '', '60', '');
550
    ShowYNBox('pp_get_addr', '<span style=\'font-weight: bold;\'>'._AD_DON_PP_ASK_CP_ADRESS.'</span>');
551
    ShowDropBox('pp_curr_code', '<span style=\'font-weight: bold;\'>'._AD_DON_PP_MONEY.'</span>');
552
    $gsql = "SELECT groupid, name FROM ".$xoopsDB->prefix('groups')." WHERE groupid>3";
553
    $gresult = $xoopsDB->query($gsql);
554
    $g_array = array();
555
    while( $g_row = $xoopsDB->fetchRow($gresult) ){
556
        $g_array[] = $g_row;
557
    }
558
    ShowArrayDropBox('assign_group', '<span style=\'font-weight: bold;\'>'._AD_DON_PP_GROUP.'</span>', $g_array);
559
    $rsql = "SELECT rank_id, rank_title FROM " . $xoopsDB->prefix('ranks') . "";
560
    $rresult = $xoopsDB->query($rsql);
561
    $r_array = array();
562
    while( $r_row = $xoopsDB->fetchRow($rresult) ){
563
        $r_array[] = $r_row;
564
    }
565
    ShowArrayDropBox('assign_rank', '<span style=\'font-weight: bold;\'>'._AD_DON_PP_RANK.'</span>', $r_array);
566
    ShowYNBox('don_forceadd', '<span style=\'font-weight: bold;\'>'._AD_DON_ADD_ANYWAY.'</span>');
567
568
    echo "</table><br />\n";
569
570
    echo "<table style=\"border-width: 1px; width: 100px; text-align: center;\">\n";
571
    echo "  <tr><td style=\"text-align: center; width: 100%; font-weight: bold;\" colspan=\"2\">" . _AD_DON_IPN_LOGGING . "<br /></td></tr>\n";
572
    echo "  <tr>\n"
573
    . "    <td style=\"text-align: right; font-weight: bold;\">" . _AD_DON_IPN_LOGGING_LEVEL . "</td>\n"
574
    . "    <td style=\"text-align: left;\">\n"
575
    . "      <select size=\"1\" name=\"var_ipn_dbg_lvl\">\n";
576
    echo "        <option ";
577
    if ( 0 == $tr_config['ipn_dbg_lvl'] ) {
578
        echo "selected ";
579
    }
580
    echo "value=\"0\">" . _AD_DON_LOG_OFF . "</option>\n";
581
    echo "        <option ";
582
    if ( $tr_config['ipn_dbg_lvl'] == 1 ) {
583
        echo "selected ";
584
    }
585
    echo "value=\"1\">" . _AD_DON_LOG_ONLY_ERRORS . "</option>\n";
586
    echo "        <option ";
587
    if ( $tr_config['ipn_dbg_lvl'] == 2 ) {
588
        echo "selected ";
589
    }
590
    echo "value=\"2\">" . _AD_DON_LOG_EVERYTHING . "</option>\n";
591
    echo "      </select>\n"
592
    . "    </td>\n"
593
    . "  </tr>\n";
594
595
    ShowTextBox('ipn_log_entries', '<nobr><span style=\'font-weight: bold;\'>'._AD_DON_LOG_ENTRY.'</span></nobr>', '', '4', '');
596
597
    $desc = 'This box shows the link to the IPN recorder.
598
    This link must be pasted EXACTLY as it is
599
    into your PayPal IPN profile.  You can click
600
    on the "test" link to the right to verify
601
    that the IPN recorder is functioning correctly.';
602
    $desc = htmlentities($desc);
603
    echo "<tr>\n"
604
    . "  <td title =\"$desc\" style=\"text-align: right; font-weight: bold;\">" . _AD_DON_IPN_LINK . "</td>\n"
605
    . "  <td title =\"$desc\" style=\"text-align: center;\">&nbsp;" . XOOPS_URL . "/modules/" . $xoopsModule->getVar('dirname') . "/ipnppd.php&nbsp;&nbsp;\n"
606
    . "    <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=\"../images/admin/info.png\" style=\"height: 16px; width: 16px;\" alt=\"\">&nbsp;". _AD_DON_TEST_IPN . "</span></a>\n"
607
    . "  </td>\n"
608
    . "</tr>\n";
609
    echo "</table><br />\n";
610
    echo "</td></tr>\n";
611
    echo "<tr><td style=\"text-align: center; width: 100%;\"><input type=\"submit\" value=\"" . _AD_DON_SUBMIT . "\" />\n";
612
    echo "</td></tr></table><br /><br />";
613
    echo $indexAdmin->addNavigation('donations.php?op=Config');
614
    echo "<table style=\"border-width: 1px; width: 90%; text-align: center;\">\n"
615
    . "  <tr>\n";
616
    echo "    <td style=\"text-align: center; font-weight: bold;\" class=\"title\">\n"
617
    . "      <h3>" . _AD_DON_GOAL_PREFERENCES . "</h3>\n";
618
    echo "      <table style=\"border-width: 1px; text-align: center;\">\n"
619
    . "        <tr><td style=\"text-align: center;\">\n";
620
    echo "          <table style=\"border-width: 1px; text-align: center;\">\n";
621
    ShowDropBox('use_goal', '<span style=\'font-weight: bold;\'>'._AD_DON_GOAL_TYPE.'.</span>');
622
    echo "          </table>\n";
623
624
    $query_Recordset1 = "SELECT * FROM ".$xoopsDB->prefix("donations_config")." WHERE name = 'week_goal' AND subtype<>'Default'";
625
    $Recordset1 = $xoopsDB->query($query_Recordset1);
626
    $row_Recordset1 = $xoopsDB->fetchArray($Recordset1);
627
    $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...
628
    $desc = htmlentities($row_Recordset1['text']);
629
630
    echo "          <table style=\"border-width: 1px; width: 100px; text-align: center;\">\n"
631
    . "            <tr><td style=\"text-align: center; width: 100%; font-weight: bold;\" colspan=\"5\">" . _AD_DON_GOAL_HEBDO . "<br /></td></tr>\n";
632
    $row1 = "  <tr>\n"
633
    . "    <td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_WEEK . "</td>\n";
634
    $row2 = "  <tr>\n"
635
    . "    <td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_GOAL . "</td>\n";
636
    //-------------------------------------------------------------
637
    $shortMonth = explode('|', _AD_DON_SHORT_MONTH);
638
    $ordinaux   = explode('|', _AD_DON_NUMBER_ORDINAUX);
639
    //-------------------------------------------------------------
640
    $h = 0;
641 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...
642
        $ord = $ordinaux[$h++];
643
        $row1 .= "    <td title=\"{$desc}\" style=\"text-align: center;\">{$ord}</td>\n";
644
        $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";
645
    } while ($row_Recordset1 = $xoopsDB->fetchArray($Recordset1));
646
    $row1 .= "  </tr>\n";
647
    $row2 .= "  </tr>\n";
648
    echo "{$row1} {$row2}";
649
650
    echo "</table>\n";
651
652
    $query_Recordset1 = "SELECT * FROM ".$xoopsDB->prefix("donations_config")." WHERE name = 'month_goal' AND subtype<>'Default'";
653
    $Recordset1 = $xoopsDB->query($query_Recordset1);
654
    $row_Recordset1 = $xoopsDB->fetchArray($Recordset1);
655
    $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...
656
    $desc = htmlentities($row_Recordset1['text']);
657
658
    $h = 0;
659
    echo "<table style=\"border-width: 1px; width: 100px; text-align: center;\">\n";
660
    echo "  <tr><td style=\"text-align: center; width: 100%; font-weight: bold;\" colspan=\"13\">" . _AD_DON_GOAL_MENSUEL . "</td></tr><br />\n";
661
    $row1 = "  <tr>\n"
662
    . "    <td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_MONTH . "</td>\n";
663
    $row2 = "  <tr>\n"
664
    . "    <td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_GOAL . "</td>\n";
665 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...
666
        $month = $shortMonth[$h++];
667
        $row1 .= "    <td title=\"{$desc}\" style=\"text-align: center;\">{$month}</td>\n";
668
        $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";
669
    } while ($row_Recordset1 = $xoopsDB->fetchArray($Recordset1));
670
    $row1 .= "  </tr>\n";
671
    $row2 .= "  </tr>\n";
672
    echo "{$row1}{$row2}";
673
674
    echo "</table>\n";
675
    echo "<table style=\"border-width: 1px; width: 100px; text-align: center\">\n";
676
    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."\");'");
677
    echo "</table>\n";
678
679
    $query_Recordset1 = "SELECT * FROM ".$xoopsDB->prefix("donations_config")." WHERE name = 'quarter_goal' AND subtype<>'Default'";
680
    $Recordset1 = $xoopsDB->query($query_Recordset1);
681
    $row_Recordset1 = $xoopsDB->fetchArray($Recordset1);
682
    $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...
683
    $desc = htmlentities($row_Recordset1['text']);
684
685
    echo "<table style=\"border-width: 1px; width: 100px; text-align: center;\">\n";
686
    echo "  <tr><td style=\"text-align: center; width: 100%; font-weight: bold;\" colspan=\"5\">" . _AD_DON_QUARTER . "<br /></td></tr>\n";
687
    $row1 = "  <tr><td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_QUARTER . "</td>\n";
688
    $row2 = "  <tr><td style=\"text-align: center; font-weight: bold;\">" . _AD_DON_GOAL . "</td>\n";
689
    $h = 0;
690 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...
691
        $ord = $ordinaux[$h++];
692
        $row1 .= "    <td title='{$desc}' style='text-align: center;'>{$ord}</td>\n";
693
        $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";
694
    } while ($row_Recordset1 = $xoopsDB->fetchArray($Recordset1));
695
    $row1 .= "  </tr>\n";
696
    $row2 .= "  </tr>\n";
697
    echo "{$row1} {$row2}";
698
699
    echo "</table><br />\n";
700
    echo "</td></tr>\n";
701
    echo "<tr><td style=\"text-align: center; width: 100%;\"><input type=\"submit\" value=\"" . _AD_DON_SUBMIT . "\"></td></tr>\n";
702
    echo "</table><br/>\n";
703
    echo "</td></tr></table>\n";
704
    echo "</form>\n";
705
}
706
707
/**
708
 *
709
 * Update Configuration Settings in the database
710
 */
711
function ConfigUpdate()
0 ignored issues
show
Coding Style introduced by
ConfigUpdate 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...
712
{
713
    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...
714
715
    echo "<br />" . _AD_DON_ERR_SQL_FAILURE . "<br /><br />\n";
716
717
    $error = 1;
718
    $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...
719
720
    foreach( $_POST as $option => $value ) {
721
        /// Look for form variables
722
        if( preg_match("/var_/",$option)) {
723
            $varnm = preg_replace("/var_/","",$option);
724
            // Check for subtype field
725
726
            if( preg_match("/-(.*)/",$varnm,$subtype) ) {
727
                echo "<br />subtype = $subtype[1] <br />\n";
728
                $temp = $varnm;
729
                $varnm = preg_replace("/-.*/","",$temp);
730
                // Is this is a text field?
731
                if( preg_match("/([^-]*)-txt/",$subtype[1], $subtype2) ) {
732
                    if (!get_magic_quotes_gpc()) {
733
                        $textarea = addslashes($value);
734
                    } else {
735
                        $textarea = $value;
736
                    }
737
738
                    echo "$varnm $subtype2[1] text=> " . nl2br(htmlspecialchars($textarea)) . "<br />\n";
739
                    $error &= UpdateDb($varnm, $subtype2[1], "0", $textarea);
740
                } else {
741
                    echo "$varnm $subtype[1] => $value<br />\n";
742
                    $error &= UpdateDbShort($varnm, $subtype[1], $value);
0 ignored issues
show
Bug introduced by
The call to UpdateDbShort() misses a required argument $txt.

This check looks for function calls that miss required arguments.

Loading history...
743
                }
744
            } else {
745
                echo "$varnm => $value<br />\n";
746
                $error &= UpdateDbShort($varnm, "", $value);
0 ignored issues
show
Bug introduced by
The call to UpdateDbShort() misses a required argument $txt.

This check looks for function calls that miss required arguments.

Loading history...
747
            }
748
        }
749
    }
750
751
    // If there were no errors
752
    if( 0 == $error )
753
    Header("Location: donations.php?op=Config#AdminTop");
754
}
755
756
/**
757
 *
758
 * Reconcile the IPN Log
759
 */
760
function IpnRec()
761
{
762
    global $tr_config, $modversion, $xoopsDB, $curr_sign;
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...
763
    $query_Recordset1 = "SELECT `date` AS recdate FROM " . $xoopsDB->prefix("donations_financial")
764
    ." WHERE name='PayPal IPN' ORDER BY date DESC LIMIT 1";
765
    $Recordset1 = $xoopsDB->query($query_Recordset1);
766
    if ($Recordset1) {
767
        $row_Recordset1 = $xoopsDB->fetchArray($Recordset1);
768
        if($row_Recordset1){
769
            $recdate = "payment_date > '" . $row_Recordset1['recdate'] . "' AND";
770
        }else{
771
            $recdate = '';
772
        }
773
    } else {
774
        $recdate = '';
775
    }
776
777
    $query_Recordset1 = "SELECT `payment_date` AS curdate from " . $xoopsDB->prefix("donations_transactions")
778
    ." WHERE payment_status='Completed' AND (txn_type='send_money' OR txn_type='web_accept')"
779
    ." ORDER BY payment_date DESC LIMIT 1";
780
    $Recordset1 = $xoopsDB->query($query_Recordset1);
781
    $row_Recordset1 = $xoopsDB->fetchArray($Recordset1);
782
    $curdate = $row_Recordset1['curdate'];
783
    $query_Recordset1 = "SELECT SUM(mc_gross - mc_fee) AS ipn_total, COUNT(*) AS numrecs"
784
    . " FROM " . $xoopsDB->prefix("donations_transactions")
785
    . " WHERE ({$recdate} payment_date <= '{$curdate}')"
786
    . " AND payment_status = 'Completed' AND (txn_type='send_money' OR txn_type='web_accept')";
787
    $Recordset1 = $xoopsDB->query($query_Recordset1);
788
    $row_Recordset1 = $xoopsDB->fetchArray($Recordset1);
789
790
    echo "<span style='text-align: center; font-weight: bold;' class='title'>" . _AD_DON_UPDATE_REGISTER_IPN . "</span><br /><br />";
791
    if( 0 == $row_Recordset1['numrecs'] ) {
792
        echo _AD_DON_NO_NEW_IPNS;
793
    } else {
794
        $insert_set = "INSERT INTO `" . $xoopsDB->prefix("donations_financial") . "` (`date`,`num`,`name`,`descr`,`amount`) VALUES ('{$curdate}','','PayPal IPN','Auto-Reconcile','{$row_Recordset1['ipn_total']}')";
795
796
        if($xoopsDB->query($insert_set)) {
797
            echo sprintf(_AD_DON_RECORDS_INSERTED, $row_Recordset1[numrecs], $curr_sign, $row_Recordset1['ipn_total']);
798
        } else {
799
            echo sprintf(_AD_DON_ERR_DB_INSERTION, $row_Recordset1[numrecs]);
800
        }
801
    }
802
803
    echo "<br /><br /><form action=\"donations.php?op=Treasury#AdminTop\" method=\"post\">";
804
    echo "<input type=\"hidden\" name=\"op\" value=\"Treasury\" />"
805
    ."<input type=\"submit\" value=\"" . _AD_DON_RETURN . "\" />"
806
    ."</form>";
807
}
808
809
/**
810
 *
811
 * Display the IPN Log
812
 *
813
 */
814
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...
815
    global $tr_config, $modversion, $xoopsDB, $curr_sign;
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...
816
    include_once XOOPS_ROOT_PATH . DIRECTORY_SEPARATOR . 'class'   . DIRECTORY_SEPARATOR . 'xoopsformloader.php';
817
    $indexAdmin = new ModuleAdmin();
818
    echo $indexAdmin->addNavigation('donations.php?op=ShowLog');
819
820
    $query_Recordset1 = "SELECT id, log_date, payment_date, logentry FROM " . $xoopsDB->prefix('donations_translog') . " ORDER BY log_date DESC";
821
    $transRecords = $xoopsDB->query($query_Recordset1);
822
    $numRows = $xoopsDB->getRowsNum($transRecords);
823
    $logForm = new XoopsThemeForm(_AD_DON_SHOW_LOG, 'logform', $_SERVER['PHP_SELF'], 'POST');
824
825
    if ($numRows) {
826
        while( list($rId, $rLdate, $rPdate, $rLentry) = $xoopsDB->fetchRow($transRecords) ) {
827
            $thisTray = 'logTray_' . $rId;
828
            $$thisTray = new XoopsFormElementTray($rId, '<br />');
829
            $$thisTray->addElement(new XoopsFormLabel( _AD_DON_LOG_DATE, $rLdate));
830
            $$thisTray->addElement(new XoopsFormLabel( _AD_DON_PMNT_DATE, $rPdate));
831
            $rLentrySplit = '';
832
            $rLentry = htmlspecialchars($rLentry);
833
            $dispWidth = 110;
834
            do {
835
                //                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...
836
                $pos = strrpos($rLentry, ' ', ($dispWidth - strlen($rLentry)));
837
                if ( !$pos) {
838
                    $pos = strrpos($rLentry, ',', ($dispWidth - strlen($rLentry)));
839
                    if ( !$pos) {
840
                        $rLentrySplit .= '<br />' . substr($rLentry, 0, $dispWidth);
841
                        $rLentry = substr($rLentry, $dispWidth);
842 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...
843
                        $rLentrySplit .= '<br />' . substr($rLentry, 0, $pos+1);
844
                        $rLentry = substr($rLentry, $pos);
845
                    }
846 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...
847
                    $rLentrySplit .= '<br />' . substr($rLentry, 0, $pos+1);
848
                    $rLentry = substr($rLentry, $pos);
849
                }
850
            } while  ( strlen($rLentry) > $dispWidth );
851
            $$thisTray->addElement(new XoopsFormLabel( _AD_DON_LOG_ENTRY_TXT, $rLentrySplit . $rLentry));
852
853
            //            $$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...
854
            $logForm->addElement($$thisTray);
855
        }
856
        $buttonTray = new XoopsFormElementTray('');
857
        $cButton = new XoopsFormButton('', 'op', _AD_DON_CLEAR_LOG, 'submit');
858
        $cButton->setExtra("onclick=\"this.form.elements.op.value='ClearLog'\"", TRUE);
859
        $buttonTray->addElement($cButton);
860
        $logForm->addElement($buttonTray);
861
    } else {
862
        //FIXME: replace this with 'full width' cell
863
        $logForm->addElement(new XoopsFormLabel( '', _AD_DON_LOG_EMPTY));
864
    }
865
    $logForm->display();
866
}
867
868
/**
869
 *
870
 * Clear the IPN log
871
 * @param int $ok =0 ask to verify, !=0 clear the log
872
 */
873
function ClearLog($ok = 0)
874
{
875
    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...
876
    if ($ok > 0) {
877
        $sql = "DELETE FROM " . $xoopsDB->prefix('donations_translog') ;
878
        $success = $xoopsDB->query($sql);
879
        $retMsg = $success ? _AD_DON_LOG_CLEARED : _AD_DON_LOG_NOT_CLEARED ;
880
        echo "<form name=\"ipnlog\" action=\"donations.php\" method=\"get\">";
881
        echo "<table style=\"text-align: center; border-width: 0px; margin: 4px;\"><tr><td>{$retMsg}</td></tr>";
882
        echo "<tr><td><input type=\"submit\" value=\"" . _AD_DON_CONTINUE . "\" /></td></tr></table>";
883
        echo "</form>";
884
        //        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...
885
        //        exit();
886
    } else {
887
        xoops_confirm(array('op' => 'ClearLog', 'ok' => 1), 'index.php', _AD_DON_CLEAR_THIS_LOG, _DELETE );
888
    }
889
}
890
/**
891
 *
892
 * Process incoming operand
893
 *
894
 */
895
896
$op = (isset($_GET['op'])) ? $_GET['op'] : 'Treasury';
897
$op = (isset($_POST['op'])) ?  $_POST['op'] : $op;
898
899
Switch($op)
900
{
901
    case 'FinRegAdd':
902
        FinancialRegAdd();
903
        break;
904
905
    case 'FinRegEdit':
906
        FinancialRegEdit();
907
        break;
908
909
    case 'FinRegDel':
910
        FinancialRegDel();
911
        break;
912
913
    case 'Config':
914
        Config();
915
        break;
916
917
    case 'ConfigUpdate':
918
        ConfigUpdate();
919
        break;
920
921
    case 'IpnRec':
922
        IpnRec();
923
        break;
924
    case 'ShowLog':
925
        ShowLog();
926
        break;
927
928
    case 'ClearLog':
929
        $ok = isset($_GET['ok']) ? intval($_GET['ok']) : 0;
930
        $ok = isset($_POST['ok']) ? intval($_POST['ok']) : $ok;
931
        ClearLog($ok);
932
        break;
933
934
    default:
935
    case 'Treasury':
936
        Treasury();
937
        break;
938
}
939
include "admin_footer.php";
940
?>
941