Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / member / what-transaction_fees.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 02/12/2004 *
4  * ===================                          Last change: 01/07/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-                                            *
8  * -------------------------------------------------------------------- *
9  * Short description :                                                  *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  :                                                  *
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 } // END - if
53
54 // Init array
55 $data = array(
56         'current_day'             => generateDateTime(time(), '3'),
57         'next_year'               => generateDateTime(mktime(0, 0, 0, 1, 1, (getCurrentYear() + 1)), '3'),
58         'transaction_holding_fee' => '0.00000'
59 );
60
61 // Get user's open transaction fees
62 $result = sqlQueryEscaped("SELECT
63         COUNT(`transaction_fee_receiver`) AS `transaction_receiver_count`,
64         SUM(`transaction_fee_receiver`) AS `transaction_receiver_fee`
65 FROM
66         `" . $GLOBALS['db_table']['translog'] . "`
67 WHERE
68         `transaction_receiver`=%s AND
69         `transaction_fee_collected`='N' AND
70         `transaction_confirmed`='N' AND
71         `transaction_captcha_failed`='N'
72 LIMIT 1",
73         array(
74                 getCurrentUserId()
75         ), __FILE__, __LINE__
76 );
77
78 // Load entry
79 $data = array_merge($data, sqlFetchArray($result));
80
81 // Free result
82 sqlFreeResult($result);
83
84 // Get user's open transaction fees
85 $result = sqlQueryEscaped("SELECT
86         COUNT(`transaction_fee_sender`) AS `transaction_sender_count`,
87         SUM(`transaction_fee_sender`) AS `transaction_sender_fee`
88 FROM
89         `" . $GLOBALS['db_table']['translog'] . "`
90 WHERE
91         `transaction_sender`=%s AND
92         `transaction_fee_collected`='N' AND
93         `transaction_confirmed`='N' AND
94         `transaction_captcha_failed`='N'
95 LIMIT 1",
96         array(
97                 getCurrentUserId()
98         ), __FILE__, __LINE__
99 );
100
101 // Load entry
102 $data = array_merge($data, sqlFetchArray($result));
103
104 // Free result
105 sqlFreeResult($result);
106
107 // Get user's saved transaction fees
108 $result = sqlQueryEscaped("SELECT
109         COUNT(`transaction_fee_receiver`) AS `transaction_receiver_saved_count`,
110         SUM(`transaction_fee_receiver`) AS `transaction_receiver_saved_fee`
111 FROM
112         `" . $GLOBALS['db_table']['translog'] . "`
113 WHERE
114         `transaction_receiver`=%s AND
115         `transaction_fee_collected`='N' AND
116         (
117                 `transaction_confirmed`='Y' OR
118                 `transaction_captcha_failed`='Y'
119         )
120 LIMIT 1",
121         array(
122                 getCurrentUserId()
123         ), __FILE__, __LINE__
124 );
125
126 // Load entry
127 $data = array_merge($data, sqlFetchArray($result));
128
129 // Free result
130 sqlFreeResult($result);
131
132 // Get user's saved transaction fees
133 $result = sqlQueryEscaped("SELECT
134         COUNT(`transaction_fee_sender`) AS `transaction_sender_saved_count`,
135         SUM(`transaction_fee_sender`) AS `transaction_sender_saved_fee`
136 FROM
137         `" . $GLOBALS['db_table']['translog'] . "`
138 WHERE
139         `transaction_sender`=%s AND
140         `transaction_fee_collected`='N' AND
141         (
142                 `transaction_confirmed`='Y' OR
143                 `transaction_captcha_failed`='Y'
144         )
145 LIMIT 1",
146         array(
147                 getCurrentUserId()
148         ), __FILE__, __LINE__
149 );
150
151 // Load entry
152 $data = array_merge($data, sqlFetchArray($result));
153
154 // Free result
155 sqlFreeResult($result);
156
157 // Total fees from config as it contains all transaction fees
158 $data['total_fee'] = getConfig('transaction_pot');
159
160 // Get total confirmed
161 $result = sqlQuery("SELECT
162         SUM(`transaction_count`) AS `total_transaction_count`
163 FROM
164         `" . $GLOBALS['db_table']['user'] . "`
165 WHERE
166         `locked`='N'
167 LIMIT 1", __FILE__, __LINE__);
168
169 // Load total amount
170 list($data['total_transaction_sum']) = sqlFetchRow($result);
171
172 // Free result
173 sqlFreeResult($result);
174
175 // Add user's count
176 $data['transaction_count_sum'] = getMemberData('transaction_count');
177
178 // Is the user's own count > 0? (This fixes a division by zero)
179 if ($data['total_transaction_sum'] > 0) {
180         // Calulcate how much the user would get if today is 01-01 (new year)
181         $data['transaction_holding_fee'] = $data['total_fee'] / $data['total_transaction_sum'] * $data['transaction_count_sum'];
182 } // END - if
183
184 // "Translate" all fields
185 foreach ($data as $key => $value) {
186         // What suffix has $key?
187         if (substr($key, -6, 6) == '_count') {
188                 // Count
189                 $data[$key] = translateComma($value, TRUE);
190         } elseif ((substr($key, -4, 4) == '_fee') || (substr($key, -4, 4) == '_sum')) {
191                 // Fees/sums
192                 $data[$key] = translateComma($value);
193         }
194 } // END - foreach
195
196 // Get all related config entries
197 // @TODO Make this working
198 $result = sqlGetResultFromLikeColumnsType('config', 'transaction_count_%%', 'decimal(3,1)');
199
200 // Load all fields
201 $data['config_rows'] = ''; $SW = 1;
202 while ($row = sqlFetchArray($result)) {
203         // Prepare content
204         $content = array(
205                 'field' => translateField('data', $row['Field']),
206                 'value' => translateComma(getConfig($row['Field'])),
207                 'sw'    => $SW,
208         );
209
210         // Load row template + switch color
211         $data['config_rows'] .= loadTemplate('member_transaction_fees_config_row', TRUE, $content);
212         $SW = 3 - $SW;
213 } // END - while
214
215 // Free result
216 sqlFreeResult($result);
217
218 // Load template
219 loadTemplate('member_transaction_fees', FALSE, $data);
220
221 // [EOF]
222 ?>