Some functions rewritten to hungarian notation, handling of array rewritten
[mailer.git] / inc / modules / member / what-transfer.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/07/2004 *
4  * ================                             Last change: 10/07/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-transfer.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : Point transfers                                  *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Punktetransfers                                  *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif (!IS_MEMBER()) {
39         LOAD_URL("modules.php?module=index");
40 } elseif ((!EXT_IS_ACTIVE("transfer")) && (!IS_ADMIN())) {
41         addFatalMessage(EXTENSION_PROBLEM_EXT_INACTIVE, "transfer");
42         return;
43 }
44
45 // Add description as navigation point
46 ADD_DESCR("member", __FILE__);
47
48 // Load data
49 $result = SQL_QUERY_ESC("SELECT opt_in FROM `"._MYSQL_PREFIX."_user_data` WHERE userid=%s LIMIT 1",
50  array($GLOBALS['userid']), __FILE__, __LINE__);
51 list($opt_in) = SQL_FETCHROW($result);
52
53 // Free memory
54 SQL_FREERESULT($result);
55
56 $MODE = "";
57 if (!empty($_GET['mode'])) $MODE = $_GET['mode'];
58
59 // Check for "faker"
60 if (($opt_in == "N") && ($MODE == "new")) $MODE = "";
61
62 switch ($MODE)
63 {
64 case "new": // Start new transfer
65         // Get total points and subtract the balance amount from it = maximum transferable points
66         $total = GET_TOTAL_DATA($GLOBALS['userid'], "user_points", "points")  - GET_TOTAL_DATA($GLOBALS['userid'], "user_data", "used_points");
67
68         // Remember maximum value for template
69         define('__TRANSFER_MAX_VALUE', round($total - getConfig('transfer_balance') - 0.5));
70
71         if (isset($_POST['ok']))
72         {
73                 // Add new transfer
74                 if (getConfig('transfer_code') > 0)
75                 {
76                         // Check for code
77                         $code = GEN_RANDOM_CODE(getConfig('transfer_code'), $_POST['code_chk'], $GLOBALS['userid'], __TRANSFER_MAX_VALUE);
78                         $valid_code = ($code == $_POST['code']);
79                 }
80                  else
81                 {
82                         // Zero length (= disabled) is always valid!
83                         $valid_code = true;
84                 }
85
86                 // Test password
87                 $valid_pass = ($pass == generateHash($_POST['password'], $pass));
88
89                 // Test transfer amount
90                 $valid_amount = ((!empty($_POST['points'])) && ($_POST['points'] <= __TRANSFER_MAX_VALUE));
91
92                 // Test reason for transfer
93                 $valid_reason = (!empty($_POST['reason']));
94
95                 // Test if a recipient is selected
96                 $valid_recipient = ($_POST['to_uid'] > 0);
97
98                 // Check for nickname extension and set additional data
99                 $nick = false; $ADD = ", userid";
100                 if (EXT_IS_ACTIVE("nickname"))
101                 {
102                         $ADD = ", nickname";
103                         $nick = true;
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' ORDER BY userid LIMIT 2",
107                  array($GLOBALS['userid'], bigintval($_POST['to_uid'])), __FILE__, __LINE__);
108                 $valid_data = (SQL_NUMROWS($result) == 2);
109
110                 if ($valid_code && $valid_pass && $valid_amount && $valid_reason && $valid_recipient)
111                 {
112                         // Let's start the transfer and load user data
113                         list($uid1, $gender1, $sname1, $fname1, $email1, $nick1) = SQL_FETCHROW($result);
114                         list($uid2, $gender2, $sname2, $fname2, $email2, $nick2) = SQL_FETCHROW($result);
115                         SQL_FREERESULT($result);
116                         if ($uid1 == $GLOBALS['userid'])
117                         {
118                                 // Data row 1 is sender's data
119                                 define('__SENDER_GENDER'     , TRANSLATE_GENDER($gender1));
120                                 define('__SENDER_NICK'    , $nick1);
121                                 define('__SENDER_SNAME'   , $sname1);
122                                 define('__SENDER_FNAME'   , $fname1);
123                                 define('__SENDER_EMAIL'   , $email1);
124                                 // Data row 2 is recpient's data
125                                 define('__RECIPIENT_GENDER'  , TRANSLATE_GENDER($gender2));
126                                 define('__RECIPIENT_NICK' , $nick2);
127                                 define('__RECIPIENT_SNAME', $sname2);
128                                 define('__RECIPIENT_FNAME', $fname2);
129                                 define('__RECIPIENT_EMAIL', $email2);
130
131                                 // Prepare variables for testing
132                                 $TEST_NICK_SENDER = $nick1;
133                                 $TEST_NICK_REC = $nick2;
134                         }
135                          else
136                         {
137                                 // Data row 2 is sender's data
138                                 define('__SENDER_GENDER'     , TRANSLATE_GENDER($gender2));
139                                 define('__SENDER_NICK'    , $nick2);
140                                 define('__SENDER_SNAME'   , $sname2);
141                                 define('__SENDER_FNAME'   , $fname2);
142                                 define('__SENDER_EMAIL'   , $email2);
143                                 // Data row 1 is recpient's data
144                                 define('__RECIPIENT_GENDER'  , TRANSLATE_GENDER($gender1));
145                                 define('__RECIPIENT_NICK' , $nick1);
146                                 define('__RECIPIENT_SNAME', $sname1);
147                                 define('__RECIPIENT_FNAME', $fname1);
148                                 define('__RECIPIENT_EMAIL', $email1);
149
150                                 // Prepare variables for testing
151                                 $TEST_NICK_SENDER = $nick2;
152                                 $TEST_NICK_REC = $nick1;
153                         }
154                         // Sender's UID is always currently stored in cookie userid...
155                         define('__SENDER_UID'     , $GLOBALS['userid']);
156                         define('__RECIPIENT_UID'  , $_POST['to_uid']);
157
158                         $SENDER = __SENDER_UID;
159                         $RECIPIENT = __RECIPIENT_UID;
160                         if ($nick)
161                         {
162                                 if (($TEST_NICK_SENDER != __SENDER_UID) && (!empty($TEST_NICK_SENDER)))
163                                 {
164                                         $SENDER = __SENDER_NICK;
165                                 }
166                                 if (($TEST_NICK_REC != __RECIPIENT_UID) && (!empty($TEST_NICK_REC)))
167                                 {
168                                         $RECIPIENT = __RECIPIENT_NICK;
169                                 }
170                         }
171
172                         // Remember transfer reason and fancy date/time in constants
173                         define('__TRANSFER_REASON', $_POST['reason']);
174                         if (function_exists('CREATE_FANCY_TIME'))
175                         {
176                                 define('__TRANSFER_EXPIRES', CREATE_FANCY_TIME(getConfig('transfer_age')));
177                         }
178                          else
179                         {
180                                 define('__TRANSFER_EXPIRES', round(getConfig('transfer_age')/60/60/24)." ".DAYS);
181                         }
182
183                         // Generate tranafer id
184                         define('__TRANS_ID', bigintval(GEN_RANDOM_CODE("10", mt_rand(0, 99999), $GLOBALS['userid'], $_POST['reason'])));
185
186                         // Add entries to both tables
187                         SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_transfers_in (userid, from_uid, points, reason, time_trans, trans_id) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP(),'%s')",
188                                 array(bigintval($_POST['to_uid']), $GLOBALS['userid'], bigintval($_POST['points']), $_POST['reason'], __TRANS_ID),
189                                 __FILE__, __LINE__);
190                         SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_transfers_out (userid, to_uid, points, reason, time_trans, trans_id) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP(),'%s')",
191                                 array($GLOBALS['userid'], bigintval($_POST['to_uid']), bigintval($_POST['points']), $_POST['reason'], __TRANS_ID),
192                                 __FILE__, __LINE__);
193
194                         // Add points to account *directly* ...
195                         ADD_POINTS_REFSYSTEM("member_transfer", bigintval($_POST['to_uid']), bigintval($_POST['points']), false, "0", false, "direct");
196
197                         // ... and add it to current user's used points
198                         SUB_POINTS("transfer", $GLOBALS['userid'], $_POST['points']);
199
200                         // First send email to recipient
201                         $msg = LOAD_EMAIL_TEMPLATE("member_transfer_recipient", "", __RECIPIENT_UID);
202                         SEND_EMAIL(__RECIPIENT_EMAIL, TRANSFER_MEMBER_RECIPIENT_SUBJ.": ".$SENDER, $msg);
203
204                         // Second send email to sender
205                         $msg = LOAD_EMAIL_TEMPLATE("member_transfer_sender", "", __SENDER_UID);
206                         SEND_EMAIL(__SENDER_EMAIL, TRANSFER_MEMBER_SENDER_SUBJ.": ".$RECIPIENT, $msg);
207
208                         // At last send admin mail(s)
209                         $ADMIN_SUBJ = sprintf("%s (%s->%s)", TRANSFER_ADMIN_SUBJECT, $SENDER, $RECIPIENT);
210                         SEND_ADMIN_NOTIFICATION($ADMIN_SUBJ, "admin_transfer_points");
211
212                         // Transfer is completed
213                         LOAD_TEMPLATE("admin_settings_saved", false, TRANSFER_COMPLETED."<br /><A href=\"".URL."/modules.php?module=login&amp;what=transfer\">".TRANSFER_CONTINUE_OVERVIEW."</A>");
214                 }
215                  elseif (!$valid_code)
216                 {
217                         // Invalid Touring code!
218                         OUTPUT_HTML("<P><STRONG class=\"member_note\">".TRANSFER_INVALID_CODE."</STRONG></P>");
219                         unset($_POST['ok']);
220                 }
221                  elseif (!$valid_pass)
222                 {
223                         // Wrong password entered
224                         OUTPUT_HTML("<P><STRONG class=\"member_note\">".TRANSFER_INVALID_PASSWORD."</STRONG></P>");
225                         unset($_POST['ok']);
226                 }
227                  elseif (!$valid_amount)
228                 {
229                         // Too much points entered
230                         OUTPUT_HTML("<P><STRONG class=\"member_note\">".TRANSFER_INVALID_POINTS."</STRONG></P>");
231                         unset($_POST['ok']);
232                 }
233                  elseif (!$valid_reason)
234                 {
235                         // No transfer reason entered
236                         OUTPUT_HTML("<P><STRONG class=\"member_note\">".TRANSFER_INVALID_REASON."</STRONG></P>");
237                         unset($_POST['ok']);
238                 }
239                  elseif (!$valid_recipient)
240                 {
241                         // No recipient selected
242                         OUTPUT_HTML("<P><STRONG class=\"member_note\">".TRANSFER_INVALID_RECIPIENT."</STRONG></P>");
243                         unset($_POST['ok']);
244                 }
245                  elseif (!$valid_data)
246                 {
247                         // No recipient selected
248                         OUTPUT_HTML("<P><STRONG class=\"member_note\">".TRANSFER_INVALID_DATA."</STRONG></P>");
249                         unset($_POST['ok']);
250                 }
251         }
252         if (!isset($_POST['ok']))
253         {
254                 // Load member list
255                 if (EXT_IS_ACTIVE("nickname"))
256                 {
257                         // Load userid and nickname
258                         $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",
259                          array($GLOBALS['userid']), __FILE__, __LINE__);
260                 }
261                  else
262                 {
263                         // Load only userid
264                         $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",
265                          array($GLOBALS['userid']), __FILE__, __LINE__);
266                 }
267                 if (SQL_NUMROWS($result) > 0)
268                 {
269                         // Load list
270                         $OUT  = "<SELECT name=\"to_uid\" size=\"1\" class=\"member_select\">
271   <OPTION value=\"0\">".SELECT_NONE."</OPTION>\n";
272                         while (list($uid, $nick) = SQL_FETCHROW($result))
273                         {
274                                 $OUT .= "<OPTION value=\"".$uid."\"";
275                                 if ((isset($_POST['to_uid'])) && ($_POST['to_uid'] == $uid)) $OUT .= " selected=\"selected\"";
276                                 $OUT .= ">";
277                                 if (($nick != $uid) && (!empty($nick)))
278                                 {
279                                         // Output nickname
280                                         $OUT .= $nick;
281                                 }
282                                  else
283                                 {
284                                         // Output userid
285                                         $OUT .= $uid;
286                                 }
287                                 $OUT .= "</OPTION>\n";
288                         }
289                         $OUT .= "</SELECT>\n";
290                         define('__TRANSFER_TO_DISABLED', "");
291
292                         // Free memory
293                         SQL_FREERESULT($result);
294                 }
295                  else
296                 {
297                         // No one else is opt-in
298                         $OUT = TRANSFER_NO_ONE_ELSE_OPT_IN;
299                         define('__TRANSFER_TO_DISABLED', " disabled");
300                 }
301                 // Transfer output to constant for the template
302                 define('__TRANSFER_USERID_SELECTION', $OUT);
303
304                 // Generate Code
305                 if (getConfig('transfer_code') > 0)
306                 {
307                         $rand = mt_rand(0, 99999);
308                         $code = GEN_RANDOM_CODE(getConfig('transfer_code'), $rand, $GLOBALS['userid'], __TRANSFER_MAX_VALUE);
309                         $img = GENERATE_IMAGE($code, false);
310                         define('__TRANSFER_IMAGE_INPUT', "<INPUT type=\"hidden\" name=\"code_chk\" value=\"".$rand."\"><INPUT type=\"text\" name=\"code\" class=\"member_normal\" size=\"5\" maxlength=\"7\"".__TRANSFER_TO_DISABLED.">&nbsp;".$img);
311                 }
312                  else
313                 {
314                         $code = "00000";
315                         define('__TRANSFER_IMAGE_INPUT', TRANSFER_NO_CODE);
316                 }
317
318                 // Transfer maybe already entered valued'
319                 if (isset($_GET['ok'])) {
320                         // Get values from form
321                         define('__TRANSFER_POINTS_VALUE', bigintval($_POST['points']));
322                         define('__TRANSFER_REASON_VALUE', strip_tags($_POST['reason']));
323                 } else {
324                         // Set empty values
325                         define('__TRANSFER_POINTS_VALUE', "");
326                         define('__TRANSFER_REASON_VALUE', "");
327                 }
328
329                 // Output form
330                 LOAD_TEMPLATE("member_transfer_new");
331         }
332         break;
333
334 case "list_in": // List only incoming transactions
335 case "list_out": // List only outgoing transactions
336         // 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
337         switch ($MODE)
338         {
339         case "list_in":
340                 $SQL = "SELECT trans_id, from_uid, points, reason, time_trans FROM "._MYSQL_PREFIX."_user_transfers_in WHERE userid=%s ORDER BY time_trans DESC LIMIT ".getConfig('transfer_max');
341                 $NOTHING = TRANSFER_NO_INCOMING_TRANSFERS;
342                 define('__TRANSFER_SUM', TRANSFER_TOTAL_INCOMING);
343                 define('__TRANSFER_TITLE', TRANSFER_LIST_INCOMING);
344                 break;
345
346         case "list_out":
347                 $SQL = "SELECT trans_id, to_uid, points, reason, time_trans FROM "._MYSQL_PREFIX."_user_transfers_out WHERE userid=%s ORDER BY time_trans DESC LIMIT ".getConfig('transfer_max');
348                 $NOTHING = TRANSFER_NO_OUTGOING_TRANSFERS;
349                 define('__TRANSFER_SUM', TRANSFER_TOTAL_OUTGOING);
350                 define('__TRANSFER_TITLE', TRANSFER_LIST_OUTGOING);
351                 break;
352         }
353
354         // Run the SQL command
355         $total = 0;
356         $result = SQL_QUERY_ESC($SQL, array($GLOBALS['userid']), __FILE__, __LINE__);
357         if (SQL_NUMROWS($result) > 0)
358         {
359                 $OUT = ""; $SW = 2;
360                 while (list($tid, $uid, $points, $reason, $stamp) = SQL_FETCHROW($result))
361                 {
362                         if ($type == "OUT") $points = "$points-";
363                         $OUT .= "<TR>
364   <TD class=\"transfer_row1 switch_sw".$SW." bottom2 right2\">
365     <FONT class=\"transfer_row1\">".$tid."</FONT>
366   </TD>
367   <TD class=\"transfer_row2 switch_sw".$SW." bottom2 right2\">
368     <FONT class=\"transfer_row2\">".MAKE_DATETIME($stamp, "3")."</FONT>
369   </TD>
370   <TD class=\"transfer_row3 switch_sw".$SW." bottom2 right2\">
371     <FONT class=\"transfer_row3\">".$uid."</FONT>
372   </TD>
373   <TD class=\"transfer_row4 switch_sw".$SW." bottom2 right2\">
374     <FONT class=\"transfer_row4\">".$reason."</FONT>
375   </TD>
376   <TD class=\"transfer_row5 switch_sw".$SW." bottom2\">
377     <FONT class=\"transfer_row5\">".$points."</FONT>
378   </TD>
379 </TR>\n";
380                         $total += $points;
381                         $SW = 3 - $SW;
382                 }
383
384                 // Free memory
385                 SQL_FREERESULT($result);
386         }
387          else
388         {
389                 // Nothing for in or out
390                 $OUT = "<TR>
391   <TD colspan=\"5\" align=\"center\" class=\"bottom2\" height=\"70\">
392     ".LOAD_TEMPLATE("admin_settings_saved", true, $NOTHING)."
393   </TD>
394 </TR>";
395         }
396
397         // ... and add them to a constant for the template
398         define('__TRANSFER_ROWS', $OUT);
399
400         // Remeber total amount
401         define('__TRANSFER_TOTAL_VALUE', $total);
402
403         // Load final template
404         LOAD_TEMPLATE("member_transfer_list");
405         break;
406
407 case "list_all": // List all transactions
408         // We fill a temporary table with data from both tables. This is much easier
409         // to code and unstand by you as sub-SELECT queries. I know this is not the
410         // fastest way but it shall be fine for now.
411         //
412         // First of all create the temporary table
413         $result = SQL_QUERY("CREATE TEMPORARY TABLE "._MYSQL_PREFIX."_transfers_tmp (
414 trans_id VARCHAR(12) NOT NULL DEFAULT '',
415 party_uid BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
416 points BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
417 reason VARCHAR(255) NOT NULL DEFAULT '',
418 time_trans VARCHAR(10) NOT NULL DEFAULT '0',
419 trans_type ENUM('IN','OUT') NOT NULL DEFAULT 'IN',
420 KEY(party_uid)
421 ) TYPE=HEAP", __FILE__, __LINE__);
422
423         // Let's begin with the incoming list
424         $result = SQL_QUERY_ESC("SELECT trans_id, from_uid, points, reason, time_trans FROM "._MYSQL_PREFIX."_user_transfers_in WHERE userid=%s ORDER BY id LIMIT %s",
425 array($GLOBALS['userid'], getConfig('transfer_max')), __FILE__, __LINE__);
426         while ($DATA = SQL_FETCHROW($result))
427         {
428                 $DATA[] = "IN";
429                 $DATA = implode("','", $DATA);
430                 $res_temp = SQL_QUERY("INSERT INTO "._MYSQL_PREFIX."_transfers_tmp (trans_id, party_uid, points, reason, time_trans, trans_type) VALUES ('".$DATA."')", __FILE__, __LINE__);
431         }
432
433         // Free memory
434         SQL_FREERESULT($result);
435
436         // As the last table transfer data from outgoing table to temporary
437         $result = SQL_QUERY_ESC("SELECT trans_id, to_uid, points, reason, time_trans FROM "._MYSQL_PREFIX."_user_transfers_out WHERE userid=%s ORDER BY id LIMIT %s",
438 array($GLOBALS['userid'], getConfig('transfer_max')), __FILE__, __LINE__);
439         while ($DATA = SQL_FETCHROW($result))
440         {
441                 $DATA[] = "OUT";
442                 $DATA = implode("','", $DATA);
443                 $res_temp = SQL_QUERY("INSERT INTO "._MYSQL_PREFIX."_transfers_tmp (trans_id, party_uid, points, reason, time_trans, trans_type) VALUES ('".$DATA."')", __FILE__, __LINE__);
444         }
445
446         // Free memory
447         SQL_FREERESULT($result);
448
449         $total = 0;
450         if (SQL_NUMROWS($result) > 0)
451         {
452                 // Output rows
453                 $OUT = ""; $SW = 2;
454                 $result = SQL_QUERY("SELECT party_uid, trans_id, points, reason, time_trans, trans_type FROM "._MYSQL_PREFIX."_transfers_tmp ORDER BY time_trans DESC", __FILE__, __LINE__);
455                 while(list($uid, $idx, $points, $reason, $stamp, $type) = SQL_FETCHROW($result))
456                 {
457                         if ($type == "OUT") $points = "-$points";
458                         $OUT .= "<TR>
459   <TD class=\"transfer_row1 switch_sw".$SW." bottom2 right2\">
460     <FONT class=\"transfer_row1\">".$idx."</FONT>
461   </TD>
462   <TD class=\"transfer_row2 switch_sw".$SW." bottom2 right2\">
463     <FONT class=\"transfer_row2\">".MAKE_DATETIME($stamp, "3")."</FONT>
464   </TD>
465   <TD class=\"transfer_row3 switch_sw".$SW." bottom2 right2\">
466     <FONT class=\"transfer_row3\">".$uid."</FONT>
467   </TD>
468   <TD class=\"transfer_row4 switch_sw".$SW." bottom2 right2\">
469     <FONT class=\"transfer_row4\">".$reason."</FONT>
470   </TD>
471   <TD class=\"transfer_row5 switch_sw".$SW." bottom2\">
472     <FONT class=\"transfer_row5\">".$points."</FONT>
473   </TD>
474 </TR>\n";
475                         $total += $points;
476                         $SW = 3 - $SW;
477                 }
478
479                 // Free memory
480                 SQL_FREERESULT($result);
481         }
482          else
483         {
484                 // Nothing for in and out
485                 $OUT = "<TR>
486   <TD colspan=\"5\" align=\"center\" class=\"bottom2\" height=\"70\">
487     ".LOAD_TEMPLATE("admin_settings_saved", true, TRANSFER_NO_INOUT_TRANSFERS)."
488   </TD>
489 </TR>";
490         }
491
492         // ... and add them to a constant for the template
493         define('__TRANSFER_ROWS', $OUT);
494
495         // Remeber total amount
496         define('__TRANSFER_TOTAL_VALUE', $total);
497
498         // Set title
499         define('__TRANSFER_TITLE', TRANSFER_LIST_ALL);
500
501         // Set "balance" word
502         define('__TRANSFER_SUM', TRANSFER_TOTAL_BALANCE);
503
504         // Load final template
505         LOAD_TEMPLATE("member_transfer_list");
506
507         // At the end we don't need a temporary table in memory
508         $result = SQL_QUERY("DROP TABLE IF EXISTS "._MYSQL_PREFIX."_transfers_tmp", __FILE__, __LINE__);
509
510         // Free some memory...
511         SQL_FREERESULT($result);
512         break;
513
514 case "": // Overview page
515         // Check incoming transfers
516         $result = SQL_QUERY_ESC("SELECT COUNT(id) FROM "._MYSQL_PREFIX."_user_transfers_in WHERE userid=%s", array($GLOBALS['userid']), __FILE__, __LINE__);
517         list($dmy) = SQL_FETCHROW($result);
518         SQL_FREERESULT($result);
519
520         $total=$dmy;
521         if ($dmy > 0)
522         {
523                 define('__TRANSFER_IN_LINK', "<A href=\"".URL."/modules.php?module=login&amp;what=transfer&amp;mode=list_in\">".$dmy."</A>");
524         }
525          else
526         {
527                 define('__TRANSFER_IN_LINK', $dmy);
528         }
529
530         // Check outgoing transfers
531         $result = SQL_QUERY_ESC("SELECT COUNT(id) FROM "._MYSQL_PREFIX."_user_transfers_out WHERE userid=%s", array($GLOBALS['userid']), __FILE__, __LINE__);
532         list($dmy) = SQL_FETCHROW($result);
533         SQL_FREERESULT($result);
534
535         $total+=$dmy;
536         if ($dmy > 0)
537         {
538                 define('__TRANSFER_OUT_LINK', "<A href=\"".URL."/modules.php?module=login&amp;what=transfer&amp;mode=list_out\">".$dmy."</A>");
539         }
540          else
541         {
542                 define('__TRANSFER_OUT_LINK', $dmy);
543         }
544
545         // Total transactions
546         if ($total > 0)
547         {
548                 define('__TRANSFER_ALL_LINK', "<A href=\"".URL."/modules.php?module=login&amp;what=transfer&amp;mode=list_all\">".$total."</A>");
549         }
550          else
551         {
552                 define('__TRANSFER_ALL_LINK', $total);
553         }
554
555         if (isset($_POST['ok'])) {
556                 // Save settings
557                 SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET opt_in='%s' WHERE userid=%s LIMIT 1",
558                         array($_POST['opt_in'], $GLOBALS['userid']), __FILE__, __LINE__);
559
560                 // Rember for next switch() command
561                 $opt_in = $_POST['opt_in'];
562
563                 // "Settings saved..."
564                 OUTPUT_HTML("<P><STRONG class=\"member_done\">".SETTINGS_SAVED."</STRONG></P>");
565         }
566
567         switch ($opt_in)
568         {
569         case "Y":
570                 define('__TRANSFER_ALLOW_Y', " checked=\"checked\"");
571                 define('__TRANSFER_ALLOW_N', "");
572                 define('__TRANSFER_NEW_LINK', "<A href=\"".URL."/modules.php?module=login&amp;what=transfer&amp;mode=new\">".TRANSFER_NOW_LINK."</A>");
573                 break;
574
575         case "N":
576                 define('__TRANSFER_ALLOW_Y', "");
577                 define('__TRANSFER_ALLOW_N', " checked=\"checked\"");
578                 define('__TRANSFER_NEW_LINK', TRANSFER_PLEASE_ALLOW_OPT_IN);
579                 break;
580         }
581
582         // Check for latest out-transfers
583         $result = SQL_QUERY_ESC("SELECT time_trans
584 FROM "._MYSQL_PREFIX."_user_transfers_out
585 WHERE time_trans > (UNIX_TIMESTAMP() - %s) AND userid=%s
586 ORDER BY time_trans DESC
587 LIMIT 1", array(getConfig('transfer_timeout'), $GLOBALS['userid']), __FILE__, __LINE__);
588         if (SQL_NUMROWS($result) == 0) {
589                 // Load template
590                 define('__TRANSFER_SETTINGS_CONTENT', LOAD_TEMPLATE("member_transfer_settings", true));
591         } else {
592                 // Load newest transaction
593                 list($newest) = SQL_FETCHROW($result);
594                 SQL_FREERESULT($result);
595                 define('__TRANSFER_SETTINGS_CONTENT', TRANSFER_LATEST_IS_1.MAKE_DATETIME($newest, "3").TRANSFER_LATEST_IS_2);
596         }
597
598         // Load template
599         LOAD_TEMPLATE("member_transfer_overview");
600         break;
601 }
602 //
603 ?>