Add export functionality

This commit is contained in:
Artur Savitskiy 2024-06-03 01:28:56 +02:00
parent bb6751c649
commit 4820dc8612
3 changed files with 58 additions and 1 deletions

View File

@ -0,0 +1,43 @@
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: GET, POST");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
require_once('../../utils/config.php');
require_once('../../utils/db.php');
require_once('../../utils/strings.php');
require_once('../../utils/tools.php');
require_once('../../libs/fpdf/fpdf.php'); // DON'T TRY TO MOVE THIS INSIDE REGISTRATION.PHP, THIS FUCKS UP CORS
require_once('../../libs/registration/registration.php');
#$authorization = $_SERVER["HTTP_AUTHORIZATION"];
#if(strcmp($authorization, INTERNAL_API_KEY) !== 0) {
# echo 'STOP TRYING TO STEAL MY DATA!';
# exit;
#}
$connection = connect();
$export = "";
$querystr = "SELECT * FROM li_registrations WHERE imported=0";
$result = mysqli_query($connection, $querystr);
if($result->num_rows !== 0) {
while ($row = mysqli_fetch_object($result)) {
$reference = "LD" . substr(strtoupper(umlaute_as_e($row->firstname)),0,1) . strtoupper(umlaute_as_e($row->lastname));
$price = getRegistrationPrice($row->birthday);
$address = $row->street . ' ' . $row->house . ';' . $row->zip . ' ' . $row->city;
$gender = $row->gender == 0 ? 'm' : ($row->gender == 1 ? 'w' : 'd');
$formattedRegistrationFrom = (new DateTime($row->registrationfrom))->format('d.m.Y');
$formattedBirthday = (new DateTime($row->birthday))->format('d.m.Y');
$export .= "{$row->lastname};{$row->firstname};{$row->iban};;{$row->bic};;{$row->bank};{$row->accountholder};{$reference};1;\t{$formattedRegistrationFrom};{$price}; ; ;\t{$row->phone};{$row->email};{$address};\t{$formattedBirthday};{$gender}\n";
}
}
mysqli_free_result($result);
header('Content-Type: charset=utf-8');
header('Content-Disposition: attachment; filename="li-dance-export.csv";');
echo chr(239) . chr(187) . chr(191) . mb_convert_encoding($export, 'UTF-8', mb_list_encodings());
?>

View File

@ -11,6 +11,17 @@ function umlaute($string) {
return $string;
}
function umlaute_as_e($string) {
$string = str_replace("ä", "ae", $string);
$string = str_replace("ü", "ue", $string);
$string = str_replace("ö", "oe", $string);
$string = str_replace("Ä", "Ae", $string);
$string = str_replace("Ü", "Ue", $string);
$string = str_replace("Ö", "Oe", $string);
return $string;
}
function gender($num) {
switch ($num)
{

View File

@ -33,7 +33,10 @@
<ng-container matColumnDef="Actions">
<mat-header-cell *matHeaderCellDef></mat-header-cell>
<mat-cell *matCellDef="let element" class="actions"><mat-icon (click)="delete(element)">delete</mat-icon></mat-cell>
<mat-cell *matCellDef="let element" class="actions">
<mat-icon (click)="delete(element)">delete</mat-icon>
<mat-icon >login</mat-icon>
</mat-cell>
</ng-container>
<mat-header-row