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