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