li-dance-backoffice/backend/api/students/export.php

43 lines
2.2 KiB
PHP
Raw Normal View History

<?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');
2024-06-17 15:12:29 +02:00
$authorization = $_SERVER["HTTP_AUTHORIZATION"];
if(strcmp($authorization, INTERNAL_API_KEY) !== 0) {
echo 'STOP TRYING TO STEAL MY DATA!';
exit;
}
$connection = connect();
$export = "";
2024-06-17 15:12:29 +02:00
$querystr = "SELECT stud.*, reg.accountholder, reg.iban, reg.bic, reg.bank, reg.registrationfrom FROM li_registrations reg, li_students stud WHERE stud.sid=reg.imported AND stud.exported=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');
2024-06-17 15:12:29 +02:00
$export .= "{$row->lastname};{$row->firstname};{$row->iban};;{$row->bic};;{$row->bank};{$row->accountholder};{$reference};1;{$formattedRegistrationFrom};{$price}; ; ;\t{$row->phone};{$row->email};{$address};{$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());
?>