diff --git a/backend/api/enroll/get.php b/backend/api/enroll/get.php index f02a05e..f324a00 100644 --- a/backend/api/enroll/get.php +++ b/backend/api/enroll/get.php @@ -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}'"; diff --git a/backend/api/students/export.php b/backend/api/students/export.php index 529d1ac..52c8626 100644 --- a/backend/api/students/export.php +++ b/backend/api/students/export.php @@ -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"; } } diff --git a/backend/api/visits/get.php b/backend/api/visits/get.php index 13516d2..bd15f5b 100644 --- a/backend/api/visits/get.php +++ b/backend/api/visits/get.php @@ -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}' diff --git a/frontend/src/app/components/students/student-list/student-list.component.html b/frontend/src/app/components/students/student-list/student-list.component.html index 8bdd3ab..402e449 100644 --- a/frontend/src/app/components/students/student-list/student-list.component.html +++ b/frontend/src/app/components/students/student-list/student-list.component.html @@ -2,7 +2,9 @@
-
+
+ +
diff --git a/frontend/src/app/components/students/student-list/student-list.component.scss b/frontend/src/app/components/students/student-list/student-list.component.scss index 2934183..c7ef22e 100644 --- a/frontend/src/app/components/students/student-list/student-list.component.scss +++ b/frontend/src/app/components/students/student-list/student-list.component.scss @@ -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; diff --git a/frontend/src/app/components/students/student-list/student-list.component.ts b/frontend/src/app/components/students/student-list/student-list.component.ts index 5355536..e9eb3ca 100644 --- a/frontend/src/app/components/students/student-list/student-list.component.ts +++ b/frontend/src/app/components/students/student-list/student-list.component.ts @@ -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}`; + } } + diff --git a/frontend/src/app/pipes/gender.pipe.ts b/frontend/src/app/pipes/gender.pipe.ts index bb324e6..9277520 100644 --- a/frontend/src/app/pipes/gender.pipe.ts +++ b/frontend/src/app/pipes/gender.pipe.ts @@ -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'; diff --git a/frontend/src/app/services/students/students.service.ts b/frontend/src/app/services/students/students.service.ts index e4d353a..c7a426a 100644 --- a/frontend/src/app/services/students/students.service.ts +++ b/frontend/src/app/services/students/students.service.ts @@ -41,4 +41,10 @@ export class StudentsService { this.headers ); } + + public export(): Observable { + return this.http.get( + `${environment.apiUrl}${this.serviceName}/export.php`, { responseType: 'arraybuffer', ... this.headers } + ); + } }