Completed
Pull Request — master (#4)
by Michael
02:17
created

blocks/donors.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/************************************************************************/
3
/* Donations - Paypal financial management module for Xoops 2           */
4
/* Copyright (c) 2016 XOOPS Project                                     */
5
/* http://dev.xoops.org/modules/xfmod/project/?group_id=1060            */
6
/* 
7
/************************************************************************/
8
/*                                                                      */
9
/* Based on NukeTreasury for PHP-Nuke - by Dave Lawrence AKA Thrash     */
10
/* NukeTreasury - Financial management for PHP-Nuke                     */
11
/* Copyright (c) 2004 by Dave Lawrence AKA Thrash                       */
12
/*                       [email protected]                         */
13
/*                       [email protected]                          */
14
/*                                                                      */
15
/************************************************************************/
16
/*                                                                      */
17
/* This program is free software; you can redistribute it and/or modify */
18
/* it under the terms of the GNU General Public License as published by */
19
/* the Free Software Foundation; either version 2 of the License.       */
20
/*                                                                      */
21
/* This program is distributed in the hope that it will be useful, but  */
22
/* WITHOUT ANY WARRANTY; without even the implied warranty of           */
23
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU     */
24
/* General Public License for more details.                             */
25
/*                                                                      */
26
/* You should have received a copy of the GNU General Public License    */
27
/* along with this program; if not, write to the Free Software          */
28
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  */
29
/* USA                                                                  */
30
/************************************************************************/
31
32
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
33
34
$moduleDirName = basename(dirname(__DIR__));
35
36
xoops_loadLanguage('main', $moduleDirName);
37
38
include_once XOOPS_ROOT_PATH . "/modules/{$moduleDirName}/include/functions.php";
39
40
/**
41
 * @param $options
42
 * @return array
43
 */
44
function b_donations_donors_show($options)
45
{
46
    global $xoopsDB;
47
48
    $tr_config = configInfo();
49
    //determine the currency
50
    $PP_CURR_CODE = explode('|', $tr_config['pp_curr_code']); // [USD,GBP,JPY,CAD,EUR]
51
    $PP_CURR_CODE = $PP_CURR_CODE[0];
52
    $currencySign    = defineCurrency($PP_CURR_CODE);
53
54
    $dmshowdate = $options[1];
55
    $dmshowamt  = $options[2];
56
    $block      = array();
57
    $swingd     = $tr_config['swing_day'];
58
59
    if (($swingd < 0) or ($swingd > 31)) {
60
        $swingd = 6;
61
    }
62
63
    if (date('d') >= $swingd) {
64
        $query_Recordset1 = "SELECT custom AS muser_id, option_selection1 as showname, DATE_FORMAT(payment_date, '%b %e') AS date, CONCAT('" . $currencySign . "',SUM(mc_gross)) AS amt FROM " . $xoopsDB->prefix('donations_transactions') . " WHERE (payment_date >= DATE_FORMAT(NOW(),'%Y-%m-" . $swingd . "')) GROUP BY txn_id ORDER BY payment_date DESC";
65
    } else {
66
        $query_Recordset1 = "SELECT custom AS muser_id, option_selection1 as showname, DATE_FORMAT(payment_date, '%b-%e') AS date, CONCAT('" . $currencySign . "',SUM(mc_gross)) AS amt FROM " . $xoopsDB->prefix('donations_transactions') . " WHERE (payment_date < DATE_FORMAT(NOW(), '%Y-%m-" . $swingd . "')) AND payment_date > DATE_FORMAT(SUBDATE(NOW(),INTERVAL " . $swingd . " DAY), '%Y-%m-" . $swingd . "') GROUP BY txn_id ORDER BY payment_date DESC";
67
    }
68
69
    $Recordset1           = $xoopsDB->query($query_Recordset1);
70
    $totalRows_Recordset1 = $xoopsDB->getRowsNum($Recordset1);
71
72
    $ROWS_DONATORS = '';
73
    // Fill out the donators table tag
74
    while (false!=($row_Recordset1 = $xoopsDB->fetchArray($Recordset1))) {
75
        if ($row_Recordset1['amt'] > $currencySign . '0') {
76
            $ROWS_DONATORS .= '<tr>';
77
            $ROWS_DONATORS .= "<td style=\"font-weight: bold;\">&nbsp; ";
78
79
            $muser_id = $row_Recordset1['muser_id'];
80 View Code Duplication
            if (strcmp($row_Recordset1['showname'], 'Yes') == 0 && ($userfoin = mgetUserInfo($muser_id))) {
81
                $ROWS_DONATORS .= "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userfoin->getVar('uid') . "'>" . xdshorten($userfoin->getVar('uname')) . "</a>\n";
82
            } else {
83
                $ROWS_DONATORS .= _MB_DON_ANONYMOUS_SHORT;
84
            }
85
86
            $ROWS_DONATORS .= "</td>\n";
87
            if ($dmshowamt) {
88
                $ROWS_DONATORS .= "<td style=\"width: 2px;\">&nbsp;</td>\n";
89
                $ROWS_DONATORS .= "<td style=\"width: 55px; font-weight: bold;\">&nbsp;&nbsp;";
90
                $ROWS_DONATORS .= $row_Recordset1['amt'];
91
                $ROWS_DONATORS .= "</td>\n";
92
            }
93
            if ($dmshowdate) {
94
                $ROWS_DONATORS .= "<td style=\"width: 2px;\">&nbsp;</td>\n";
95
                $ROWS_DONATORS .= "<td style=\"font-weight: bold;\">&nbsp;&nbsp;";
96
                $ROWS_DONATORS .= $row_Recordset1['date'];
97
                $ROWS_DONATORS .= "</td>\n";
98
            }
99
            $ROWS_DONATORS .= "</tr>\n";
100
        }
101
    }
102
103
    // Ok, output the page
104
105
    $block['showamt']  = $dmshowamt;
106
    $block['showdate'] = $dmshowdate;
107
    $block['list']     = $ROWS_DONATORS;
108
    $block['amount']   = _MB_DON_AMOUNT;
109
    $block['date']     = _MB_DON_DATE;
110
    $block['name']     = _MB_DON_NAME;
111
112
    return $block;
113
}
114
115
/**
116
 * @param     $var
117
 * @param int $len
118
 * @return string
119
 */
120
function xdshorten($var, $len = 10)
121
{
122
    $var = trim($var);
123
    if (empty($var)) {
124
        return '';
125
    }
126
    if (strlen($var) < $len) {
127
        return $var;
128
    }
129
130
    if (preg_match("/(.{1,$len})\s/", $var, $match)) {
131
        return $match [1] . '...';
132
    } else {
133
        return substr($var, 0, $len) . '...';
134
    }
135
}
136
137
/**
138
 * @param $options
139
 * @return string
140
 */
141
function b_donations_donors_edit($options)
142
{
143
    $form = _MB_DON_NUM_DONORS . ":&nbsp;<input type='text' name='options[0]' value='" . $options[0] . "'  size='4'/>";
144
    $form .= '<br />' . _MB_DON_REVEAL_DATES . ":&nbsp;<select size='1' name='options[1]'><option value='1'";
145
    if ($options[1] == 1) {
146
        $form .= ' selected';
147
    }
148
    $form .= ' />' . _YES . "</option><option value='0'";
149
    if ($options[1] == 0) {
150
        $form .= ' selected';
151
    }
152
    $form .= ' />' . _NO . '</option></select>';
153
    $form .= '<br />' . _MB_DON_REVEAL_AMOUNTS . ":&nbsp;<select size='1' name='options[2]'><option value='1'";
154
    if ($options[2] == 1) {
155
        $form .= ' selected';
156
    }
157
    $form .= ' />' . _YES . "</option><option value='0'";
158
    if ($options[2] == 0) {
159
        $form .= ' selected';
160
    }
161
    $form .= ' />' . _NO . '</option></select>';
162
163
    return $form;
164
}
165