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