7f0f3268deb4d3350fcec7f1a3d5de708fbdabdd
[mailer.git] / inc / modules / member / what-transfer.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/07/2004 *
4  * ================                             Last change: 10/07/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-transfer.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : Point transfers                                  *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Punktetransfers                                  *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } elseif (!isMember()) {
43         redirectToIndexMemberOnlyModule();
44 }
45
46 // Add description as navigation point
47 addMenuDescription('member', __FILE__);
48
49 if ((!isExtensionActive('transfer')) && (!isAdmin())) {
50         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('transfer'));
51         return;
52 } // END - if
53
54 // Load data
55 $result = SQL_QUERY_ESC("SELECT `opt_in` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
56         array(getUserId()), __FILE__, __LINE__);
57 list($opt_in) = SQL_FETCHROW($result);
58
59 // Free memory
60 SQL_FREERESULT($result);
61
62 // Check for mode in GET
63 $mode = '';
64 if (isGetRequestElementSet('mode')) $mode = getRequestElement('mode');
65
66 // Check for "faker"
67 if (($opt_in != 'Y') && ($mode == 'new')) $mode = '';
68
69 switch ($mode) {
70         case 'new': // Start new transfer
71                 // Get total points and subtract the balance amount from it = maximum transferable points
72                 $total = countSumTotalData(getUserId(), 'user_points', 'points')  - countSumTotalData(getUserId(), 'user_data', 'used_points');
73
74                 // Remember maximum value for template
75                 $content['max_transferable'] = round($total - getConfig('transfer_balance') - 0.5);
76
77                 if (isFormSent()) {
78                         // Add new transfer
79                         if (getConfig('transfer_code') > 0) {
80                                 // Check for code
81                                 $code = generateRandomCode(getConfig('transfer_code'), postRequestElement('code_chk'), getUserId(), $content['max_transferable']);
82                                 $valid_code = ($code == postRequestElement('code'));
83                         } else {
84                                 // Zero length (= disabled) is always valid!
85                                 $valid_code = true;
86                         }
87
88                         // Test password
89                         $valid_pass = ($pass == generateHash(postRequestElement('password'), $pass));
90
91                         // Test transfer amount
92                         $valid_amount = ((isPostRequestElementSet('points')) && (postRequestElement('points') <= $content['max_transferable']));
93
94                         // Test reason for transfer
95                         $valid_reason = (isPostRequestElementSet('reason'));
96
97                         // Test if a recipient is selected
98                         $valid_recipient = (postRequestElement('to_userid') > 0);
99
100                         // Check for nickname extension and set additional data
101                         // @TODO Rewrite this to a filter
102                         $add = '';
103                         if (isExtensionActive('nickname')) {
104                                 $add = ', `nickname`';
105                         } // END - if
106
107                         // Re-check receivers and own personal data
108                         $result = SQL_QUERY_ESC("SELECT `userid`, `gender`, `surname`, `family`, `email`".$add." FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid` IN ('%s','%s') AND `status`='CONFIRMED' LIMIT 2",
109                                 array(
110                                         getUserId(),
111                                         bigintval(postRequestElement('to_userid'))
112                                 ), __FILE__, __LINE__);
113
114                         // Do we have two entries?
115                         $valid_data = (SQL_NUMROWS($result) == 2);
116
117                         // Final check if all is fine
118                         if ($valid_code && $valid_data && $valid_pass && $valid_amount && $valid_reason && $valid_recipient) {
119                                 // Let's start the transfer and load user data
120                                 $content['sender']    = SQL_FETCHARRAY($result);
121                                 $content['recipient'] = SQL_FETCHARRAY($result);
122
123                                 // Is the nickname extension not installed?
124                                 if (!isExtensionActive('nickname')) {
125                                         // Fix empty nicknames
126                                         $content['sender']['nickname']    = '';
127                                         $content['recipient']['nickname'] = '';
128                                 } // END - if
129
130                                 // Translate some data
131                                 $content['sender']['gender']    = translateGender($content['sender']['gender']);
132                                 $content['recipient']['gender'] = translateGender($content['recipient']['gender']);
133
134                                 // Prepare variables for testing
135                                 $TEST_NICK_SENDER = $content['sender']['nickname'];
136                                 $TEST_NICK_REC    = $content['recipient']['nickname'];
137
138                                 // Default is userids for subject line
139                                 $SENDER = getUserId();
140                                 $RECIPIENT = bigintval(postRequestElement('to_userid'));
141
142                                 // If nickname is installed we can set the nickname
143                                 // @TODO Rewrite this to a filter
144                                 if (isExtensionActive('nickname')) {
145                                         if (($TEST_NICK_SENDER != getUserId()) && (!empty($TEST_NICK_SENDER))) {
146                                                 $SENDER = $content['sender']['nickname'];
147                                         }
148
149                                         if (($TEST_NICK_REC != postRequestElement('to_userid')) && (!empty($TEST_NICK_REC))) {
150                                                 $RECIPIENT = $content['recipient']['nickname'];
151                                         }
152                                 } // END - if
153
154                                 // Remember transfer reason and fancy date/time in constants
155                                 $content['reason']  = secureString(postRequestElement('reason'));
156                                 $content['expires'] = createFancyTime(getConfig('transfer_age'));
157
158                                 // Generate tranafer id
159                                 $content['trans_id'] = bigintval(generateRandomCode('10', mt_rand(0, 99999), getUserId(), postRequestElement('reason')));
160
161                                 // Add entries to both tables
162                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_transfers_in` (`userid`, `from_userid`, `points`, `reason`, `time_trans`, `trans_id`) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP(),'%s')",
163                                         array(bigintval(postRequestElement('to_userid')), getUserId(), bigintval(postRequestElement('points')), postRequestElement('reason'), $content['trans_id']), __FILE__, __LINE__);
164                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_transfers_out` (`userid`, `to_userid`, `points`, `reason`, `time_trans`, `trans_id`) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP(),'%s')",
165                                         array(getUserId(), bigintval(postRequestElement('to_userid')), bigintval(postRequestElement('points')), postRequestElement('reason'), $content['trans_id']), __FILE__, __LINE__);
166
167                                 // Add points to account *directly* ...
168                                 addPointsDirectly('member_transfer', bigintval(postRequestElement('to_userid')), bigintval(postRequestElement('points')));
169
170                                 // ... and add it to current user's used points
171                                 subtractPoints('transfer', getUserId(), postRequestElement('points'));
172
173                                 // First send email to recipient
174                                 $message = loadEmailTemplate('member_transfer_recipient', $content, postRequestElement('to_userid'));
175                                 sendEmail($content['recipient']['email'], getMessage('TRANSFER_MEMBER_RECIPIENT_SUBJ') . ': ' . $SENDER, $message);
176
177                                 // Second send email to sender
178                                 $message = loadEmailTemplate('member_transfer_sender', $content, getUserId());
179                                 sendEmail($content['sender']['email'], getMessage('TRANSFER_MEMBER_SENDER_SUBJ') . ': ' . $RECIPIENT, $message);
180
181                                 // At last send admin mail(s)
182                                 $ADMIN_SUBJ = sprintf("%s (%s->%s)", getMessage('TRANSFER_ADMIN_SUBJECT'), $SENDER, $RECIPIENT);
183                                 sendAdminNotification($ADMIN_SUBJ, 'admin_transfer_points', $content);
184
185                                 // Transfer is completed
186                                 loadTemplate('admin_settings_saved', false, getMessage('TRANSFER_COMPLETED') . "<br /><a href=\"{?URL?}/modules.php?module=login&amp;what=transfer\">{--TRANSFER_CONTINUE_OVERVIEW--}</a>");
187                         } elseif ($valid_code === false) {
188                                 // Invalid Touring code!
189                                 loadTemplate('admin_settings_saved', false, "<div class=\"member_note\">{--TRANSFER_INVALID_CODE--}</div>");
190                                 unsetPostRequestElement('ok');
191                         } elseif ($valid_pass === false) {
192                                 // Wrong password entered
193                                 loadTemplate('admin_settings_saved', false, "<div class=\"member_note\">{--TRANSFER_INVALID_PASSWORD--}</div>");
194                                 unsetPostRequestElement('ok');
195                         } elseif ($valid_amount === false) {
196                                 // Too much points entered
197                                 loadTemplate('admin_settings_saved', false, "<div class=\"member_note\">{--TRANSFER_INVALID_POINTS--}</div>");
198                                 unsetPostRequestElement('ok');
199                         } elseif ($valid_reason === false) {
200                                 // No transfer reason entered
201                                 loadTemplate('admin_settings_saved', false, "<div class=\"member_note\">{--TRANSFER_INVALID_REASON--}</div>");
202                                 unsetPostRequestElement('ok');
203                         } elseif ($valid_recipient === false) {
204                                 // No recipient selected
205                                 loadTemplate('admin_settings_saved', false, "<div class=\"member_note\">{--TRANSFER_INVALID_RECIPIENT--}</div>");
206                                 unsetPostRequestElement('ok');
207                         } elseif ($valid_data === false) {
208                                 // No recipient/sender selected
209                                 loadTemplate('admin_settings_saved', false, "<div class=\"member_note\">{--TRANSFER_INVALID_DATA--}</div>");
210                                 unsetPostRequestElement('ok');
211                         }
212
213                         // Free result
214                         SQL_FREERESULT($result);
215                 } // END - if
216
217                 if (!isFormSent()) {
218                         // Load member list
219                         if (isExtensionActive('nickname')) {
220                                 // Load userid and nickname
221                                 $result = SQL_QUERY_ESC("SELECT `userid`, `nickname` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status`='CONFIRMED' AND `opt_in`='Y' AND `userid` != '%s' ORDER BY `userid` ASC",
222                                         array(getUserId()), __FILE__, __LINE__);
223                         } else {
224                                 // Load only userid
225                                 $result = SQL_QUERY_ESC("SELECT `userid`, `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status`='CONFIRMED' AND `opt_in`='Y' AND `userid` != '%s' ORDER BY `userid` ASC",
226                                         array(getUserId()), __FILE__, __LINE__);
227                         }
228
229                         if (SQL_NUMROWS($result) > 0) {
230                                 // Load list
231                                 $OUT  = "<select name=\"to_userid\" size=\"1\" class=\"member_select\">
232         <option value=\"0\">{--SELECT_NONE--}</option>\n";
233                                 // @TODO Try to rewrite his to $content = SQL_FETCHARRAY(), see some lines above for two different queries
234                                 while (list($userid, $nick) = SQL_FETCHROW($result)) {
235                                         $OUT .= "       <option value=\"".$userid."\"";
236                                         if ((isPostRequestElementSet(('to_userid'))) && (postRequestElement('to_userid') == $userid)) $OUT .= ' selected="selected"';
237                                         $OUT .= ">";
238                                         if (($nick != $userid) && (!empty($nick))) {
239                                                 // Output nickname
240                                                 $OUT .= $nick;
241                                         } else {
242                                                 // Output userid
243                                                 $OUT .= $userid;
244                                         }
245                                         $OUT .= "</option>\n";
246                                 }
247                                 $OUT .= "</select>\n";
248                                 $content['to_disabled'] = '';
249
250                                 // Free memory
251                                 SQL_FREERESULT($result);
252                         } else {
253                                 // No one else is opt-in
254                                 $OUT = loadTemplate('admin_settings_saved', true, getMessage('TRANSFER_NO_ONE_ELSE_OPT_IN'));
255                                 $content['to_disabled'] = ' disabled="disabled"';
256                         }
257
258                         // Transfer output to constant for the template
259                         $content['userid_selection'] = $OUT;
260
261                         // Generate Code
262                         if (getConfig('transfer_code') > 0) {
263                                 $rand = mt_rand(0, 99999);
264                                 $code = generateRandomCode(getConfig('transfer_code'), $rand, getUserId(), $content['max_transferable']);
265                                 $img = generateImageOrCode($code, false);
266                                 $content['captcha_code'] = "<input type=\"hidden\" name=\"code_chk\" value=\"".$rand."\" /><input type=\"text\" name=\"code\" class=\"member_normal\" size=\"5\" maxlength=\"7\"".$content['to_disabled']." />&nbsp;" . $img;
267                         } else {
268                                 $code = '00000';
269                                 $content['captcha_code'] = loadTemplate('admin_settings_saved', true, getMessage('TRANSFER_NO_CODE'));
270                         }
271
272                         // Init points/reason
273                         $content['points'] = '';
274                         $content['reason'] = '';
275
276                         // Transfer maybe already entered valued'
277                         if (isGetRequestElementSet('ok')) {
278                                 // Get values from form
279                                 $content['points'] = bigintval(postRequestElement('points'));
280                                 $content['reason'] = secureString(postRequestElement('reason'));
281                         } // END - if
282
283                         // Translate some array elements for template
284                         $content['max_transferable'] = translateComma($content['max_transferable']);
285
286                         // Output form
287                         loadTemplate('member_transfer_new', false, $content);
288                 } // END - if
289                 break;
290
291         case 'list_in': // List only incoming transactions
292         case 'list_out': // List only outgoing transactions
293                 // As you can see I put list_in and list_out together. I now do a switch() again on it for the right SQL command
294                 $nothingMessage = '';
295                 switch ($mode) {
296                         case 'list_in':
297                                 $sql = "SELECT `trans_id`, `from_userid` AS party_userid, `points`, `reason`, `time_trans` FROM `{?_MYSQL_PREFIX?}_user_transfers_in` WHERE `userid`=%s ORDER BY `time_trans` DESC LIMIT ".getConfig('transfer_max');
298                                 $nothingMessage = getMessage('TRANSFER_NO_INCOMING_TRANSFERS');
299                                 $content['balance'] = getMessage('TRANSFER_TOTAL_INCOMING');
300                                 $content['title']   = getMessage('TRANSFER_LIST_INCOMING');
301                                 break;
302
303                         case 'list_out':
304                                 $sql = "SELECT `trans_id`, `to_userid` AS party_userid, `points`, `reason`, `time_trans` FROM `{?_MYSQL_PREFIX?}_user_transfers_out` WHERE `userid`=%s ORDER BY `time_trans` DESC LIMIT ".getConfig('transfer_max');
305                                 $nothingMessage = getMessage('TRANSFER_NO_OUTGOING_TRANSFERS');
306                                 $content['balance'] = getMessage('TRANSFER_TOTAL_OUTGOING');
307                                 $content['title']   = getMessage('TRANSFER_LIST_OUTGOING');
308                                 break;
309                 } // END - switch
310
311                 // Run the SQL command and set total points to zero
312                 $totalPoints = 0;
313                 $result = SQL_QUERY_ESC($sql, array(getUserId()), __FILE__, __LINE__);
314
315                 // Do we have entries?
316                 if (SQL_NUMROWS($result) > 0) {
317                         $OUT = ''; $SW = 2;
318                         // @TODO This should be somehow rewritten to $row = SQL_FETCHARRAY(), see switch() block above for SQL queries
319                         while (list($tid, $userid, $points, $reason, $stamp) = SQL_FETCHROW($result)) {
320                                 // Rewrite points
321                                 if ($type == 'OUT') $points = $points . '-';
322
323                                 // Prepare content for template
324                                 // @TODO Rewrite: tid->trans_id,stamp->time_trans
325                                 $row = array(
326                                         'sw'     => $SW,
327                                         'tid'    => $tid,
328                                         'stamp'  => generateDateTime($stamp, 3),
329                                         'userid' => $userid,
330                                         'reason' => $reason,
331                                         'points' => translateComma($points)
332                                 );
333
334                                 // Load row template
335                                 $OUT .= loadTemplate('member_transfer_row2', true, $row);
336
337                                 // Add points and switch color
338                                 $totalPoints += $points;
339                                 $SW = 3 - $SW;
340                         } // END - while
341
342                         // Free memory
343                         SQL_FREERESULT($result);
344                 } else {
345                         // Nothing for in or out
346                         $OUT = "<tr>
347   <td colspan=\"5\" align=\"center\" class=\"bottom2\" height=\"70\">
348     ".loadTemplate('admin_settings_saved', true, $nothingMessage)."
349   </td>
350 </tr>";
351                 }
352
353                 // ... and add them to a constant for the template
354                 $content['rows'] = $OUT;
355
356                 // Remeber total amount
357                 $content['total'] = translateComma($totalPoints);
358
359                 // Load final template
360                 loadTemplate('member_transfer_list', false, $content);
361                 break;
362
363         case 'list_all': // List all transactions
364                 // We fill a temporary table with data from both tables. This is much easier
365                 // to code and unstand by you as sub-SELECT queries. I know this is not the
366                 // fastest way but it shall be fine for now.
367                 //
368                 // First of all create the temporary table
369                 $result = SQL_QUERY("CREATE TEMPORARY TABLE `{?_MYSQL_PREFIX?}_transfers_tmp` (
370 `trans_id` VARCHAR(12) NOT NULL DEFAULT '',
371 `party_userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
372 `points` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
373 `reason` VARCHAR(255) NOT NULL DEFAULT '',
374 `time_trans` VARCHAR(10) NOT NULL DEFAULT 0,
375 `trans_type` ENUM('IN','OUT') NOT NULL DEFAULT 'IN',
376 KEY (`party_userid`)
377 ) TYPE=HEAP", __FILE__, __LINE__);
378
379                 // Let's begin with the incoming list
380                 $result = SQL_QUERY_ESC("SELECT `trans_id`, `from_userid`, `points`, `reason`, `time_trans` FROM `{?_MYSQL_PREFIX?}_user_transfers_in` WHERE `userid`=%s ORDER BY `id` ASC LIMIT %s",
381                         array(getUserId(), getConfig('transfer_max')), __FILE__, __LINE__);
382                 while ($DATA = SQL_FETCHROW($result)) {
383                         $DATA[] = 'IN';
384                         $DATA = implode("','", $DATA);
385                         $res_temp = SQL_QUERY("INSERT INTO `{?_MYSQL_PREFIX?}_transfers_tmp` (`trans_id`, `party_userid`, `points`, `reason`, `time_trans`, `trans_type`) VALUES ('".$DATA."')", __FILE__, __LINE__);
386                 } // END - while
387
388                 // Free memory
389                 SQL_FREERESULT($result);
390
391                 // As the last table transfer data from outgoing table to temporary
392                 $result = SQL_QUERY_ESC("SELECT `trans_id`, `to_userid`, `points`, `reason`, `time_trans` FROM `{?_MYSQL_PREFIX?}_user_transfers_out` WHERE `userid`=%s ORDER BY `id` LIMIT %s",
393                         array(getUserId(), getConfig('transfer_max')), __FILE__, __LINE__);
394                 while ($DATA = SQL_FETCHROW($result)) {
395                         $DATA[] = 'OUT';
396                         $DATA = implode("','", $DATA);
397                         $res_temp = SQL_QUERY("INSERT INTO `{?_MYSQL_PREFIX?}_transfers_tmp` (`trans_id`, `party_userid`, `points`, `reason`, `time_trans`, `trans_type`) VALUES ('".$DATA."')", __FILE__, __LINE__);
398                 } // END - while
399
400                 // Free memory
401                 SQL_FREERESULT($result);
402
403                 $total = 0;
404                 if (SQL_NUMROWS($result) > 0) {
405                         // Search for entries
406                         $result = SQL_QUERY("SELECT `party_userid`, `trans_id`, `points`, `reason`, `time_trans`, `trans_type` FROM `{?_MYSQL_PREFIX?}_transfers_tmp` ORDER BY `time_trans` DESC",
407                                 __FILE__, __LINE__);
408
409                         // Output rows
410                         $OUT = ''; $SW = 2;
411                         while ($content = SQL_FETCHARRAY($result)) {
412                                 // Rewrite points
413                                 if ($content['trans_type'] == 'OUT') $content['points'] = '-'.$content['points']."";
414
415                                 // Prepare content for template
416                                 $content['sw']     = $SW;
417                                 $content['time']   = generateDateTime($content['time_trans'], 3);
418                                 $content['points'] = translateComma($content['points']);
419
420                                 // Load row template
421                                 $OUT .= loadTemplate('member_transfer_row', true, $content);
422
423                                 // Add points and switch color
424                                 $total += $content['points'];
425                                 $SW = 3 - $SW;
426                         } // END - while
427
428                         // Free memory
429                         SQL_FREERESULT($result);
430                 } else {
431                         // Nothing for in and out
432                         $OUT = "<tr>
433   <td colspan=\"5\" align=\"center\" class=\"bottom2\" height=\"70\">
434     ".loadTemplate('admin_settings_saved', true, getMessage('TRANSFER_NO_INOUT_TRANSFERS'))."
435   </td>
436 </tr>";
437                 }
438
439                 // ... and add them to a constant for the template
440                 $content['rows'] =  $OUT;
441
442                 // Remeber total amount
443                 $content['total'] = translateComma($total);
444
445                 // Set title
446                 $content['title'] = getMessage('TRANSFER_LIST_ALL');
447
448                 // Set "balance" word
449                 $content['balance'] = getMessage('TRANSFER_TOTAL_BALANCE');
450
451                 // At the end we don't need a temporary table in memory
452                 $result = SQL_QUERY("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_transfers_tmp`", __FILE__, __LINE__);
453
454                 // Load final template
455                 loadTemplate('member_transfer_list', false, $content);
456
457                 // Free some memory...
458                 SQL_FREERESULT($result);
459                 break;
460
461         default: // Overview page
462                 // Check incoming transfers
463                 $total = countSumTotalData(getUserId(), 'user_transfers_in', 'id', 'userid', true);
464                 $content['in_link'] = $total;
465                 if ($total > 0) {
466                         $content['in_link'] = "<a href=\"{?URL?}/modules.php?module=login&amp;what=transfer&amp;mode=list_in\">".$total."</a>";
467                 } // END - if
468
469                 // Check outgoing transfers
470                 $dmy = countSumTotalData(getUserId(), 'user_transfers_out', 'id', 'userid', true);
471
472                 // Add to total amount
473                 $total += $dmy;
474
475                 $content['out_link'] = $dmy;
476                 if ($dmy > 0) {
477                         $content['out_link'] = "<a href=\"{?URL?}/modules.php?module=login&amp;what=transfer&amp;mode=list_out\">".$dmy."</a>";
478                 } // END - if
479
480                 // Total transactions
481                 $content['all_link'] = $total;
482                 if ($total > 0) {
483                         $content['all_link'] = "<a href=\"{?URL?}/modules.php?module=login&amp;what=transfer&amp;mode=list_all\">".$total."</a>";
484                 } // END - if
485
486                 if (isFormSent()) {
487                         // Save settings
488                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `opt_in`='%s' WHERE `userid`=%s LIMIT 1",
489                                 array(postRequestElement('opt_in'), getUserId()), __FILE__, __LINE__);
490
491                         // Rember for next switch() command
492                         $opt_in = substr(postRequestElement('opt_in'), 0, 1);
493
494                         // "Settings saved..."
495                         loadTemplate('admin_settings_saved', false, "<div class=\"member_done\">{--SETTINGS_SAVED--}</div>");
496                 } // END - if
497
498                 // Init entries
499                 foreach (array('allow_y','allow_n') as $entry) {
500                         $content[$entry] = '';
501                 } // END - foreach
502
503                 // Set current selection
504                 $content['allow_' . strtolower($opt_in)] = ' checked="checked"';
505
506                 // Set 'new transfer' link according to above option
507                 switch ($opt_in) {
508                         case 'Y':
509                                 $content['new_link'] = "<a href=\"{?URL?}/modules.php?module=login&amp;what=transfer&amp;mode=new\">{--TRANSFER_NOW_LINK--}</a>";
510                                 break;
511
512                         case 'N':
513                                 $content['new_link'] = getMessage('TRANSFER_PLEASE_ALLOW_OPT_IN');
514                                 break;
515                 } // END - switch
516
517                 // Check for latest out-transfers
518                 $result = SQL_QUERY_ESC("SELECT
519         `time_trans`
520 FROM
521         `{?_MYSQL_PREFIX?}_user_transfers_out`
522 WHERE
523         `time_trans` > (UNIX_TIMESTAMP() - %s) AND `userid`=%s
524 ORDER BY
525         `time_trans` DESC
526 LIMIT 1",
527                         array(
528                                 getConfig('transfer_timeout'),
529                                 getUserId()
530                         ), __FILE__, __LINE__);
531
532                 // Do we have an entry?
533                 if (SQL_NUMROWS($result) == 1) {
534                         // Load newest transaction
535                         list($newest) = SQL_FETCHROW($result);
536                         $content['settings'] = sprintf(getMessage('TRANSFER_LATEST_IS'), generateDateTime($newest, 3));
537                 } else {
538                         // Load template
539                         $content['settings'] = loadTemplate('member_transfer_settings', true, $content);
540                 }
541
542                 // Free result
543                 SQL_FREERESULT($result);
544
545                 // Load template
546                 loadTemplate('member_transfer_overview', false, $content);
547                 break;
548 } // END - switch
549
550 // [EOF]
551 ?>