+ // As the last table transfer data from outgoing table to temporary
+ $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",
+ array(getUserId(), getConfig('transfer_max')), __FILE__, __LINE__);
+ while ($DATA = SQL_FETCHROW($result)) {
+ $DATA[] = 'OUT';
+ $DATA = implode("','", $DATA);
+ $res_temp = SQL_QUERY("INSERT INTO `{!_MYSQL_PREFIX!}_transfers_tmp` (trans_id, party_uid, points, reason, time_trans, trans_type) VALUES ('".$DATA."')", __FILE__, __LINE__);
+ }
+
+ // Free memory
+ SQL_FREERESULT($result);
+
+ $total = 0;
+ if (SQL_NUMROWS($result) > 0) {
+ // Search for entries
+ $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__);
+
+ // Output rows
+ $OUT = ''; $SW = 2;
+ while ($content = SQL_FETCHARRAY($result)) {
+ // Rewrite points
+ if ($content['trans_type'] == 'OUT') $content['points'] = '-'.$content['points']."";
+
+ // Prepare content for template
+ $content['sw'] = $SW;
+ $content['time'] = generateDateTime($content['time_trans'], '3');
+ $content['points'] = translateComma($content['points']);
+
+ // Load row template
+ $OUT .= LOAD_TEMPLATE("member_transfer_row", true, $content);
+
+ // Add points and switch color
+ $total += $content['points'];
+ $SW = 3 - $SW;
+ } // END - while
+
+ // Free memory
+ SQL_FREERESULT($result);
+ } else {
+ // Nothing for in and out
+ $OUT = "<tr>
+ <td colspan=\"5\" align=\"center\" class=\"bottom2\" height=\"70\">
+ ".LOAD_TEMPLATE('admin_settings_saved', true, getMessage('TRANSFER_NO_INOUT_TRANSFERS'))."
+ </td>
+</tr>";
+ }
+
+ // ... and add them to a constant for the template
+ // @TODO Rewrite all these constants
+ define('__TRANSFER_ROWS', $OUT);
+
+ // Remeber total amount
+ define('__TRANSFER_TOTAL_VALUE', $total);
+
+ // Set title
+ define('__TRANSFER_TITLE', getMessage('TRANSFER_LIST_ALL'));
+
+ // Set "balance" word
+ define('__TRANSFER_SUM', getMessage('TRANSFER_TOTAL_BALANCE'));
+
+ // Load final template
+ LOAD_TEMPLATE('member_transfer_list');
+
+ // At the end we don't need a temporary table in memory
+ $result = SQL_QUERY("DROP TABLE IF EXISTS `{!_MYSQL_PREFIX!}_transfers_tmp`", __FILE__, __LINE__);
+
+ // Free some memory...
+ SQL_FREERESULT($result);
+ break;
+
+ case '': // Overview page
+ // Check incoming transfers
+ $result = SQL_QUERY_ESC("SELECT COUNT(id) FROM `{!_MYSQL_PREFIX!}_user_transfers_in` WHERE userid=%s", array(getUserId()), __FILE__, __LINE__);
+ list($dmy) = SQL_FETCHROW($result);
+ SQL_FREERESULT($result);
+
+ $total=$dmy;
+ if ($dmy > 0) {
+ define('__TRANSFER_IN_LINK', "<a href=\"{!URL!}/modules.php?module=login&what=transfer&mode=list_in\">".$dmy."</a>");
+ } else {
+ define('__TRANSFER_IN_LINK', $dmy);
+ }
+
+ // Check outgoing transfers
+ $result = SQL_QUERY_ESC("SELECT COUNT(id) FROM `{!_MYSQL_PREFIX!}_user_transfers_out` WHERE userid=%s", array(getUserId()), __FILE__, __LINE__);
+ list($dmy) = SQL_FETCHROW($result);
+ SQL_FREERESULT($result);
+
+ $total+=$dmy;
+ if ($dmy > 0) {
+ define('__TRANSFER_OUT_LINK', "<a href=\"{!URL!}/modules.php?module=login&what=transfer&mode=list_out\">".$dmy."</a>");
+ } else {
+ define('__TRANSFER_OUT_LINK', $dmy);
+ }
+
+ // Total transactions
+ if ($total > 0) {
+ define('__TRANSFER_ALL_LINK', "<a href=\"{!URL!}/modules.php?module=login&what=transfer&mode=list_all\">".$total."</a>");
+ } else {
+ define('__TRANSFER_ALL_LINK', $total);
+ }
+
+ if (isFormSent()) {
+ // Save settings
+ SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET opt_in='%s' WHERE userid=%s LIMIT 1",
+ array(REQUEST_POST('opt_in'), getUserId()), __FILE__, __LINE__);
+
+ // Rember for next switch() command
+ $opt_in = REQUEST_POST('opt_in');
+
+ // "Settings saved..."
+ LOAD_TEMPLATE('admin_settings_saved', false, "<div class=\"member_done\">{--SETTINGS_SAVED--}</div>");
+ } // END - if
+
+ switch ($opt_in) {
+ case 'Y':
+ define('__TRANSFER_ALLOW_Y', ' checked="checked"');
+ define('__TRANSFER_ALLOW_N', '');
+ define('__TRANSFER_NEW_LINK', "<a href=\"{!URL!}/modules.php?module=login&what=transfer&mode=new\">{--TRANSFER_NOW_LINK--}</a>");
+ break;
+
+ case 'N':
+ define('__TRANSFER_ALLOW_Y', '');
+ define('__TRANSFER_ALLOW_N', ' checked="checked"');
+ define('__TRANSFER_NEW_LINK', getMessage('TRANSFER_PLEASE_ALLOW_OPT_IN'));
+ break;
+ } // END - switch
+
+ // Check for latest out-transfers
+ $result = SQL_QUERY_ESC("SELECT time_trans
+FROM `{!_MYSQL_PREFIX!}_user_transfers_out`
+WHERE time_trans > (UNIX_TIMESTAMP() - %s) AND `userid`=%s
+ORDER BY time_trans DESC
+LIMIT 1",
+ array(getConfig('transfer_timeout'), getUserId()), __FILE__, __LINE__);
+ if (SQL_NUMROWS($result) == 0) {
+ // Load template
+ define('__TRANSFER_SETTINGS_CONTENT', LOAD_TEMPLATE("member_transfer_settings", true));
+ } else {
+ // Load newest transaction
+ list($newest) = SQL_FETCHROW($result);
+ SQL_FREERESULT($result);
+ define('__TRANSFER_SETTINGS_CONTENT', sprintf(getMessage('TRANSFER_LATEST_IS'), generateDateTime($newest, '3')));
+ }
+
+ // Load template
+ LOAD_TEMPLATE("member_transfer_overview");
+ break;