Version 0.9.9

- several bugfixes
- Code cleaning
This commit is contained in:
football
2021-04-06 17:58:31 +02:00
parent 25dc3154aa
commit 7ab5247437
3 changed files with 102 additions and 95 deletions

View File

@@ -16,7 +16,7 @@ if ( !$this->auth->acl_get('u_use_football') )
} }
$action=''; $action='';
$phpbb_root_path = './../../'; $phpbb_root_path = './../../';
if (!$season OR !$league) if (!$season OR !$league)
{ {
@@ -90,14 +90,10 @@ else
} }
$user_rows = $db->sql_fetchrowset($result); $user_rows = $db->sql_fetchrowset($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$export_file = $league_short . '_' . $season . '_bank.csv';
$newline = "\r\n"; $newline = "\r\n";
header('Pragma: no-cache'); $csv_data= '';
header("Content-Type: text/csv; name=\"$export_file\""); $csv_data .= $league_name . ' ' . sprintf($user->lang['SEASON']) . ' ' . $season. $newline;
header("Content-disposition: attachment; filename=$export_file"); $csv_data .= sprintf($user->lang['NAME']) . ';' . $config['football_win_name'] . ';' . sprintf($user->lang['BET_POINTS']) . ';' .
$export= '';
$export .= $league_name . ' ' . sprintf($user->lang['SEASON']) . ' ' . $season. $newline;
$export .= sprintf($user->lang['NAME']) . ';' . $config['football_win_name'] . ';' . sprintf($user->lang['BET_POINTS']) . ';' .
sprintf($user->lang['DEPOSITED']) . ';' . sprintf($user->lang['DEPOSIT']) . ';' . sprintf($user->lang['WINS']) . ';' . sprintf($user->lang['DEPOSITED']) . ';' . sprintf($user->lang['DEPOSIT']) . ';' . sprintf($user->lang['WINS']) . ';' .
sprintf($user->lang['PAID']) . ';' . sprintf($user->lang['PAYOUT']) . ';' . $newline; sprintf($user->lang['PAID']) . ';' . sprintf($user->lang['PAYOUT']) . ';' . $newline;
@@ -118,7 +114,7 @@ else
$no_cash_wins = ''; $no_cash_wins = '';
$no_cash_paid = ''; $no_cash_paid = '';
} }
$export .= str_replace("\"", "\"\"", $user_row['username']) . ';' . $csv_data .= str_replace("\"", "\"\"", $user_row['username']) . ';' .
str_replace('.', ',', $user_row['user_points']) . ';' . str_replace('.', ',', $user_row['user_points']) . ';' .
str_replace('.', ',', $user_row['bet_points']) . $no_cash_bet_points . ';' . str_replace('.', ',', $user_row['bet_points']) . $no_cash_bet_points . ';' .
str_replace('.', ',', $user_row['deposit']) . $no_cash_deposit . ';' . str_replace('.', ',', $user_row['deposit']) . $no_cash_deposit . ';' .
@@ -127,9 +123,24 @@ else
str_replace('.', ',', $user_row['paid']) . $no_cash_paid . ';' . str_replace('.', ',', $user_row['paid']) . $no_cash_paid . ';' .
str_replace('.', ',', $user_row['new_pay']) . ';' . $newline; str_replace('.', ',', $user_row['new_pay']) . ';' . $newline;
} }
echo utf8_decode($export);
exit; // Output the csv file
$filename = $league_short . '_' . $season . '_bank.csv';
$fp = fopen('php://output', 'w');
header('Content-Type: application/octet-stream');
header("Content-disposition: attachment; filename=\"" . basename($filename) . "\"");
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Pragma: public');
header('Content-Transfer-Encoding: binary');
fwrite($fp, "\xEF\xBB\xBF"); // UTF-8 BOM
fwrite($fp, utf8_decode($csv_data));
fclose($fp);
exit_handler();
} }
} }
} }
?>

View File

@@ -50,14 +50,10 @@ else
} }
$user_rows = $db->sql_fetchrowset($result); $user_rows = $db->sql_fetchrowset($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$export_file = $season. '_bank.csv';
$newline = "\r\n"; $newline = "\r\n";
header('Pragma: no-cache'); $csv_data= '';
header("Content-Type: text/csv; name=\"$export_file\""); $csv_data .= sprintf($user->lang['SEASON']) . ' ' . $season. $newline;
header("Content-disposition: attachment; filename=$export_file"); $csv_data .= sprintf($user->lang['NAME']) . ';' . sprintf($user->lang['SEASON']) . ';' . sprintf($user->lang['LEAGUE']) . ';Saldo;' . $newline;
$export= '';
$export .= sprintf($user->lang['SEASON']) . ' ' . $season. $newline;
$export .= sprintf($user->lang['NAME']) . ';' . sprintf($user->lang['SEASON']) . ';' . sprintf($user->lang['LEAGUE']) . ';Saldo;' . $newline;
$last_username = ''; $last_username = '';
$sum_saldo = 0.0; $sum_saldo = 0.0;
@@ -65,11 +61,11 @@ else
{ {
if ($last_username != '' AND $last_username != $user_row['username']) if ($last_username != '' AND $last_username != $user_row['username'])
{ {
$export .= str_replace("\"", "\"\"", $last_username) . ';Summe;;' . $csv_data .= str_replace("\"", "\"\"", $last_username) . ';Summe;;' .
str_replace('.', ',', $sum_saldo) . ';' . $newline; str_replace('.', ',', $sum_saldo) . ';' . $newline;
$sum_saldo = 0.0; $sum_saldo = 0.0;
} }
$export .= str_replace("\"", "\"\"", $user_row['username']) . ';' . $csv_data .= str_replace("\"", "\"\"", $user_row['username']) . ';' .
$user_row['season'] . ';' . $user_row['season'] . ';' .
$user_row['league'] . ';' . $user_row['league'] . ';' .
str_replace('.', ',', $user_row['saldo']) . ';' . $newline; str_replace('.', ',', $user_row['saldo']) . ';' . $newline;
@@ -78,11 +74,26 @@ else
} }
if ($last_username != '') if ($last_username != '')
{ {
$export .= str_replace("\"", "\"\"", $last_username) . ';Summe;;' . $csv_data .= str_replace("\"", "\"\"", $last_username) . ';Summe;;' .
str_replace('.', ',', $sum_saldo) . ';' . $newline; str_replace('.', ',', $sum_saldo) . ';' . $newline;
} }
echo utf8_decode($export); // Output the csv file
exit; $filename = $season. '_bank.csv';
$fp = fopen('php://output', 'w');
header('Content-Type: application/octet-stream');
header("Content-disposition: attachment; filename=\"" . basename($filename) . "\"");
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Pragma: public');
header('Content-Transfer-Encoding: binary');
fwrite($fp, "\xEF\xBB\xBF"); // UTF-8 BOM
fwrite($fp, utf8_decode($csv_data));
fclose($fp);
exit_handler();
} }
} }
?> ?>

View File

@@ -22,25 +22,8 @@ if( !$result = $db->sql_query($sql) )
} }
$league_short = $db->sql_fetchfield('league_name_short'); $league_short = $db->sql_fetchfield('league_name_short');
$db->sql_freeresult($result); $db->sql_freeresult($result);
$export_file = $league_short . '_'. $season. '_Tipps.csv';
$path_attachment = './../../files/' . $export_file;
$newline = "\r\n"; $newline = "\r\n";
$phpbb_root_path = './../../';
if (!isset($_POST['send']))
{
header('Pragma: no-cache');
header("Content-Type: text/csv; name=\"$export_file\"");
header("Content-disposition: attachment; filename=$export_file");
// header('Content-Type: text/x-csv');
// header('Expires: ' . gmdate('D, d M Y H:i:m') . ' GMT');
// header('Content-Disposition: attachment; filename='. $export_file);
$phpbb_root_path = './../';
}
else
{
$phpbb_root_path = './../../';
}
$sql_users = 'SELECT DISTINCT $sql_users = 'SELECT DISTINCT
b.user_id, b.user_id,
@@ -96,16 +79,16 @@ foreach ($rows_users as $row_user)
$bet_column[$row_user['user_id']] = $lastcolumn; $bet_column[$row_user['user_id']] = $lastcolumn;
$j++; $j++;
} }
$export_row_users = "\"\";\"\";\"\";\"\";\"\";\"\";"; $csv_data_row_users = "\"\";\"\";\"\";\"\";\"\";\"\";";
for($j = 8; $j <= $lastcolumn; $j = $j + 3) for($j = 8; $j <= $lastcolumn; $j = $j + 3)
{ {
$export_row_users .= "\"\";\"\";\"" . $column[$j] . "\""; $csv_data_row_users .= "\"\";\"\";\"" . $column[$j] . "\"";
if($j != $lastcolumn) if($j != $lastcolumn)
{ {
$export_row_users .= ';'; $csv_data_row_users .= ';';
} }
} }
$export_row_users .= $newline; $csv_data_row_users .= $newline;
if( !$result_results = $db->sql_query($sql_results) ) if( !$result_results = $db->sql_query($sql_results) )
{ {
@@ -138,16 +121,16 @@ foreach ($rows_bets as $row_bet)
{ {
if ($lastcolumn > 0) if ($lastcolumn > 0)
{ {
$export_bets[$last_match_num] = ''; $csv_data_bets[$last_match_num] = '';
for($j=8; $j<=$lastcolumn; $j++) for($j=8; $j<=$lastcolumn; $j++)
{ {
$export_bets[$last_match_num] .= "\"" . $column[$j] . "\""; $csv_data_bets[$last_match_num] .= "\"" . $column[$j] . "\"";
if($j!=$lastcolumn) if($j!=$lastcolumn)
{ {
$export_bets[$last_match_num] .= ';'; $csv_data_bets[$last_match_num] .= ';';
} }
} }
$export_bets[$last_match_num] .= $newline; $csv_data_bets[$last_match_num] .= $newline;
} }
$column = array(); $column = array();
$last_match_num = $row_bet['match_no']; $last_match_num = $row_bet['match_no'];
@@ -157,21 +140,21 @@ foreach ($rows_bets as $row_bet)
$lastcolumn = $bet_column[$row_bet['user_id']] + 2; $lastcolumn = $bet_column[$row_bet['user_id']] + 2;
} }
} }
$export_bets[$last_match_num] = ''; $csv_data_bets[$last_match_num] = '';
for($j = 8; $j <= $lastcolumn; $j++) for($j = 8; $j <= $lastcolumn; $j++)
{ {
$export_bets[$last_match_num] .= "\"" . $column[$j] . "\""; $csv_data_bets[$last_match_num] .= "\"" . $column[$j] . "\"";
if($j != $lastcolumn) if($j != $lastcolumn)
{ {
$export_bets[$last_match_num] .= ';'; $csv_data_bets[$last_match_num] .= ';';
} }
} }
$export_bets[$last_match_num] .= $newline; $csv_data_bets[$last_match_num] .= $newline;
$last_matchday = 0; $last_matchday = 0;
$export= ''; $csv_data= '';
$export .= 'CSV;'. $league. ';'. $season. $newline; $csv_data .= 'CSV;'. $league. ';'. $season. $newline;
$i = 0; $i = 0;
foreach ($rows_results as $row_result) foreach ($rows_results as $row_result)
@@ -180,32 +163,32 @@ foreach ($rows_results as $row_result)
{ {
if ($last_matchday != 0) if ($last_matchday != 0)
{ {
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
$export .= ";;". str_replace("\"", "\"\"", $row_result['match_time']). $newline; $csv_data .= ";;". str_replace("\"", "\"\"", $row_result['match_time']). $newline;
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
} }
else else
{ {
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
$export .= ";;". str_replace("\"", "\"\"", $row_result['match_time']). $newline; $csv_data .= ";;". str_replace("\"", "\"\"", $row_result['match_time']). $newline;
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
$export .= $newline; $csv_data .= $newline;
} }
$export .= $export_row_users; $csv_data .= $csv_data_row_users;
$column = array(); $column = array();
$last_matchday = $row_result['matchday']; $last_matchday = $row_result['matchday'];
} }
@@ -242,29 +225,31 @@ foreach ($rows_results as $row_result)
$column[2] = ''; $column[2] = '';
$column[4] = ''; $column[4] = '';
} }
$export .= "\"" . $column[0] . "\";\"" . $column[1] . "\";\"" . $column[2] . "\";\"\";\"" . $column[4] . "\";\"\";\"\";\"\";"; $csv_data .= "\"" . $column[0] . "\";\"" . $column[1] . "\";\"" . $column[2] . "\";\"\";\"" . $column[4] . "\";\"\";\"\";\"\";";
if ($export_bets[$row_result['match_no']] == '') if ($csv_data_bets[$row_result['match_no']] == '')
{ {
$export .= $newline; $csv_data .= $newline;
} }
else else
{ {
$export .= $export_bets[$row_result['match_no']]; $csv_data .= $csv_data_bets[$row_result['match_no']];
} }
$column = array(); $column = array();
$i++; $i++;
} }
if (isset($_POST['send'])) // Output the csv file
{ $filename = $league_short . '_'. $season. '_Tipps.csv';
$fp = fopen($path_attachment , "b"); $fp = fopen('php://output', 'w');
ftruncate ($fp, 0);
rewind($fp); header('Content-Type: application/octet-stream');
fwrite ($fp, $export); header("Content-disposition: attachment; filename=\"" . basename($filename) . "\"");
fclose($fp); header('Expires: 0');
} header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
else header('Cache-Control: private', false);
{ header('Pragma: public');
echo utf8_decode($export); header('Content-Transfer-Encoding: binary');
exit;
} fwrite($fp, "\xEF\xBB\xBF"); // UTF-8 BOM
fwrite($fp, $csv_data);
fclose($fp);