Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / member / what-transactions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/22/2013 *
4  * ===================                          Last change: 06/22/2013 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-transactions.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Confirm transactions of other members            *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Transaktionen anderer Mitglieder bestaetigen     *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         exit();
41 } elseif (!isMember()) {
42         redirectToIndexMemberOnlyModule();
43 }
44
45 // Add description as navigation point
46 addYouAreHereLink('member', __FILE__);
47
48 // Continue only if the proper extension is active (admins can always continue)
49 if ((!isExtensionActive('transaction')) && (!isAdmin())) {
50         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=transaction%}');
51         return;
52 } elseif ((isFormSent()) &&  (ifPostContainsSelections('transaction_id'))) {
53         // Try to confirm transactions
54         if (doTryConfirmTransactions($_POST)) {
55                 // All fine
56                 displayMessage('Best&auml;tigung der CAPTCHA(s) abgeschlossen. Vielen Dank.');
57         } else {
58                 // None confirmed
59                 displayMessage('Es konnten keine CAPTCHA(s) best&auml;tigt werden. Vermutlich weil Sie diese bereits best&auml;tigt haben.');
60         }
61 }
62
63 // Load X most oldest transactions this user is not sender and not receiver
64 $result = sqlQueryEscaped("SELECT
65         `transaction_id`
66 FROM
67         `{?_MYSQL_PREFIX?}_transaction_log`
68 WHERE
69         `transaction_sender` != %s AND
70         `transaction_sender` IS NOT NULL AND
71         `transaction_receiver` != %s AND
72         `transaction_receiver` IS NOT NULL AND
73         `transaction_hash` != 'INVALID' AND
74         `transaction_confirmed`='N' AND
75         `transaction_captcha_failed`='N' AND
76         `transaction_fee_collected`='N' AND
77         `transaction_level` IS NULL AND
78         `transaction_captcha` IS NOT NULL
79 ORDER BY
80         `transaction_hash` ASC
81 LIMIT {?transaction_max_captcha?}",
82         array(
83                 getCurrentUserId(),
84                 getCurrentUserId()
85         ), __FILE__, __LINE__
86 );
87
88 // Init variables
89 $OUT = '';
90
91 // Are there entries?
92 if (sqlNumRows($result) > 0) {
93         // Then load all
94         $row = '';
95         while (list($id) = sqlFetchRow($result)) {
96                 // Load "row" template
97                 $row .= loadTemplate('member_transactions_row', TRUE, $id);
98         } // END - while
99
100         // Load form template
101         $OUT .= loadTemplate('member_transactions_form', TRUE, $row);
102 } else {
103         // Display message
104         $OUT .= returnMessage('Es sind noch keine Transaktionen zum Best&auml;tigen vorhanden. Neu zu best&auml;tigende Transaktionen gibt es durch den &quot;Stundenreset&quot;, der ungef&auml;hr zur vollen Stunde l&auml;uft.');
105 }
106
107 // Free result
108 sqlFreeResult($result);
109
110 // Get summarizations
111 $result = sqlQuery("SELECT
112         SUM(`transaction_fee_sender`) AS `total_sender`,
113         SUM(`transaction_fee_receiver`) AS `total_receiver`
114 FROM
115         `{?_MYSQL_PREFIX?}_transaction_log`
116 WHERE
117         `transaction_fee_collected`='N' AND
118         `transaction_confirmed`='N' AND
119         `transaction_captcha_failed`='N'
120 LIMIT 1", __FILE__, __LINE__);
121
122 // Get values
123 list($totalSenderN, $totalReceiverN) = sqlFetchRow($result);
124
125 // Free result
126 sqlFreeResult($result);
127
128 // Get summarizations
129 $result = sqlQuery("SELECT
130         SUM(`transaction_fee_sender`) AS `total_sender`,
131         SUM(`transaction_fee_receiver`) AS `total_receiver`
132 FROM
133         `{?_MYSQL_PREFIX?}_transaction_log`
134 WHERE
135         `transaction_fee_collected`='Y'
136 LIMIT 1", __FILE__, __LINE__);
137
138 // Get values
139 list($totalSenderY, $totalReceiverY) = sqlFetchRow($result);
140
141 // Free result
142 sqlFreeResult($result);
143
144 // Get summarizations
145 $result = sqlQuery("SELECT
146         COUNT(`transaction_id`) AS `cnt`,
147         (SUM(`transaction_fee_sender`) + SUM(`transaction_fee_receiver`)) AS `total_confirmed`
148 FROM
149         `{?_MYSQL_PREFIX?}_transaction_log`
150 WHERE
151         `transaction_confirmed`='Y'
152 LIMIT 1", __FILE__, __LINE__);
153
154 // Get values
155 list($confirmedCount, $totalConfirmed) = sqlFetchRow($result);
156
157 // Free result
158 sqlFreeResult($result);
159
160 // Prepare content
161 $content = array(
162         'captcha_content'                => $OUT,
163         'transaction_confirmed'          => translateComma(getUserData('transaction_confirmed'), TRUE),
164         'total_sender_uncollected'       => $totalSenderN,
165         'total_receiver_uncollected'     => $totalReceiverN,
166         'total_sender_collected'         => $totalSenderY,
167         'total_receiver_collected'       => $totalReceiverY,
168         'total_confirmed_count'          => translateComma($confirmedCount, TRUE),
169         'total_confirmed'                => $totalConfirmed,
170 );
171
172 // Load main template
173 loadTemplate('member_transactions', FALSE, $content);
174
175 // [EOF]
176 ?>