Add export to students view

This commit is contained in:
Artur Savitskiy 2024-06-17 15:12:29 +02:00
parent cc49dfa052
commit 3ef38eab77
8 changed files with 55 additions and 13 deletions

View File

@ -17,7 +17,8 @@
$returnValue = array();
$querystr = "SELECT * FROM li_enroll, li_students
WHERE li_enroll.sid = li_students.sid
WHERE li_students.deleted = 0
AND li_enroll.sid = li_students.sid
AND li_enroll.cid = $cid
AND li_enroll.begin < '{$date}'
AND li_enroll.end > '{$date}'";

View File

@ -11,16 +11,16 @@
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;
#}
$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";
$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) {
@ -31,7 +31,7 @@
$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";
$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";
}
}

View File

@ -52,7 +52,8 @@
}
$querystr = "SELECT *, 1 AS visited FROM li_enroll, li_students
WHERE li_enroll.sid = li_students.sid
WHERE li_students.deleted = 0
AND li_enroll.sid = li_students.sid
AND li_enroll.cid = {$returnValue->cid}
AND li_enroll.begin <= '{$date}'
AND li_enroll.end >= '{$date}'
@ -62,7 +63,8 @@
AND li_visits.date = '{$date}')
UNION
SELECT *, 0 AS visited FROM li_enroll, li_students
WHERE li_enroll.sid = li_students.sid
WHERE li_students.deleted = 0
AND li_enroll.sid = li_students.sid
AND li_enroll.cid = {$returnValue->cid}
AND li_enroll.begin <= '{$date}'
AND li_enroll.end >= '{$date}'

View File

@ -2,7 +2,9 @@
<div class="grid-item">
<button class="button-add" (click)="add()">Hinzufügen</button>
</div>
<div class="grid-item"></div>
<div class="grid-item right">
<button class="button-export" (click)="export()">Export</button>
</div>
<div class="grid-item-full">
<div *ngIf="loading; else table">
<mat-spinner class="center"></mat-spinner>

View File

@ -21,10 +21,15 @@ button {
font-size: 1.5em;
}
button.button-add {
button.button-add,
button.button-export {
background-color: #411ccc;
}
.right {
justify-self: end;
}
.center {
width: 50%;
margin: auto;

View File

@ -86,6 +86,19 @@ export class StudentListComponent implements OnInit {
this.getData();
}
public export(): void {
this.studentsService.export().subscribe(async (response) => {
const blob = new Blob([response], { type: 'attachment/csv' });
const url = window.URL.createObjectURL(blob);
const anchor = document.createElement("a");
anchor.download = `${this.timestamp()}-li-dance-report.csv`;
anchor.href = url;
anchor.click();
anchor.remove();
});
}
private getData() {
this.studentsService.get().subscribe({
next: students => {
@ -97,4 +110,18 @@ export class StudentListComponent implements OnInit {
this.coursesService.get().subscribe(c => (this.courses = c));
}
private timestamp(): string {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are 0-based, so we add 1
const day = String(now.getDate()).padStart(2, '0');
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
return `${year}${month}${day}${hours}${minutes}${seconds}`;
}
}

View File

@ -5,7 +5,6 @@ import { StudentRegistration } from '../models/student-registration';
@Pipe({ name: 'gender' })
export class GenderPipe implements PipeTransform {
transform(student: Student | StudentRegistration): string {
console.log(student);
switch (Number(student.gender)) {
case 0:
return 'M';

View File

@ -41,4 +41,10 @@ export class StudentsService {
this.headers
);
}
public export(): Observable<any> {
return this.http.get(
`${environment.apiUrl}${this.serviceName}/export.php`, { responseType: 'arraybuffer', ... this.headers }
);
}
}