diff --git a/app/Http/Controllers/PreApplicationController.php b/app/Http/Controllers/PreApplicationController.php
index aee23f4..6f29a7f 100644
--- a/app/Http/Controllers/PreApplicationController.php
+++ b/app/Http/Controllers/PreApplicationController.php
@@ -7,6 +7,7 @@ use App\Mail\PreApplicationMail;
use App\Models\ChaosEvents;
use App\Models\PreApplications;
use Illuminate\Http\Request;
+use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Log;
@@ -14,6 +15,20 @@ use Nette\Utils\Random;
class PreApplicationController extends Controller
{
+
+ private function generateReferenceNumber($eventId, $passportType, $firstName){
+ $reference_number = null;
+
+ $ce = ChaosEvents::find($eventId);
+ $free_reference_number = false;
+ $counter = 1;
+ while(!$free_reference_number){
+ $reference_number = $ce->shortname . strtoupper($passportType) . '-' . strtoupper($firstName[0]) . Carbon::now()->format('ymd') . sprintf("%04d", $counter++);
+ $free_reference_number = !PreApplications::where('reference_number', $reference_number)->exists();
+ }
+ return $reference_number;
+ }
+
public function send(Request $request){
$event = $request->input('district_region');
@@ -53,20 +68,13 @@ class PreApplicationController extends Controller
//Log::debug('fn: ' . var_export($fn, true) . ' ln: ' . var_export($ln, true) . ' loc: ' . var_export($loc, true) . '');
if($fn && $ln && $loc){
-
- $free_reference_number = false;
- while(!$free_reference_number){
- $reference_number = $ce->shortname . '-' . strtoupper($passport_type) . '-' . Random::generate(4, "0-9") . '-' . Random::generate(4, "0-9") . '-' . Random::generate(4, "0-9");
- $free_reference_number = !PreApplications::where('reference_number', $reference_number)->exists();
- }
-
try{
$pa = new PreApplications();
$pa->first_name = $first_name;
$pa->last_name = $last_name;
$pa->location = $location;
$pa->passport_type = $passport_type;
- $pa->reference_number = $reference_number;
+ $pa->reference_number = $this->generateReferenceNumber($event, $passport_type, $first_name);
$pa->event_id = $event;
$pa->email = $email;
$pa->save();
@@ -101,13 +109,7 @@ class PreApplicationController extends Controller
$pa->event_id = $request->input('district_region');
$pa->email = $request->input('mail');
- $ce = ChaosEvents::find($pa->event_id);
- $free_reference_number = false;
- while(!$free_reference_number){
- $reference_number = $ce->shortname . '-' . strtoupper($pa->passport_type) . '-' . Random::generate(4, "0-9") . '-' . Random::generate(4, "0-9") . '-' . Random::generate(4, "0-9");
- $free_reference_number = !PreApplications::where('reference_number', $reference_number)->exists();
- }
- $pa->reference_number = $reference_number;
+ $pa->reference_number = $this->generateReferenceNumber($request->input('district_region'), $request->input('passport_type'), $request->input('first_name'));
$pa->save();
return ["messageStatus" => "success", "errorMessage" => ""];
diff --git a/app/Http/Controllers/WebsiteController.php b/app/Http/Controllers/WebsiteController.php
index 409573c..24358e7 100644
--- a/app/Http/Controllers/WebsiteController.php
+++ b/app/Http/Controllers/WebsiteController.php
@@ -9,19 +9,6 @@ use Illuminate\Support\Facades\Auth;
class WebsiteController extends Controller
{
- public function __construct()
- {
- $this->setLang($_COOKIE['lang'] ?? 'de');
- }
-
- private function setLang($lang)
- {
- if (!in_array($lang, ['de', 'en'])) {
- $lang = 'de';
- }
-
- App::setLocale($lang);
- }
//
public function index(Request $request)
diff --git a/app/Http/Middleware/SetLocale.php b/app/Http/Middleware/SetLocale.php
new file mode 100644
index 0000000..8c5ef39
--- /dev/null
+++ b/app/Http/Middleware/SetLocale.php
@@ -0,0 +1,28 @@
+cookie('lang', 'de');
+ if (!in_array($lang, ['de', 'en'])) {
+ $lang = 'de';
+ }
+
+ App::setLocale($lang);
+
+ return $next($request);
+ }
+}
diff --git a/app/Mail/PreApplicationMail.php b/app/Mail/PreApplicationMail.php
index 3628247..7fcf45a 100644
--- a/app/Mail/PreApplicationMail.php
+++ b/app/Mail/PreApplicationMail.php
@@ -22,6 +22,7 @@ class PreApplicationMail extends Mailable
public function __construct(protected App\Models\PreApplications $pa, protected string $lang = 'de')
{
//
+ $this->locale($this->lang);
}
/**
@@ -39,7 +40,6 @@ class PreApplicationMail extends Mailable
*/
public function content(): Content
{
- App::setLocale($this->lang);
return new Content(
view: 'mail.preapplication',
with: ['pa' => $this->pa],
@@ -53,13 +53,21 @@ class PreApplicationMail extends Mailable
*/
public function attachments(): array
{
- $lang = match (App::getLocale()) {
+ $langFb = match ($this->locale) {
'de' => 'dk',
'en' => 'ek',
default => 'dk',
};
+
+ $langDonation = match ($this->locale) {
+ 'de' => '',
+ 'en' => '_en',
+ };
+
return [
- Attachment::fromPath(public_path('Dokumente/c3gov_fb5' . $lang . '.pdf'))
+ Attachment::fromPath(public_path('Dokumente/c3gov_fb5' . $langFb . '.pdf'))
+ ->withMime('application/pdf'),
+ Attachment::fromPath(public_path('Dokumente/C3GovSpGV' . $langDonation . '.pdf'))
->withMime('application/pdf'),
];
}
diff --git a/bootstrap/app.php b/bootstrap/app.php
index c183276..95b6d22 100644
--- a/bootstrap/app.php
+++ b/bootstrap/app.php
@@ -11,7 +11,7 @@ return Application::configure(basePath: dirname(__DIR__))
health: '/up',
)
->withMiddleware(function (Middleware $middleware): void {
- //
+ $middleware->append(\App\Http\Middleware\SetLocale::class);
})
->withExceptions(function (Exceptions $exceptions): void {
//
diff --git a/composer.json b/composer.json
index fa83919..c869916 100644
--- a/composer.json
+++ b/composer.json
@@ -48,6 +48,11 @@
"Composer\\Config::disableProcessTimeout",
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1 --timeout=0\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite --kill-others"
],
+ "dev-bind": [
+ "Composer\\Config::disableProcessTimeout",
+ "npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve --host=0.0.0.0\" \"php artisan queue:listen --tries=1 --timeout=0\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite --kill-others"
+ ],
+
"test": [
"@php artisan config:clear --ansi",
"@php artisan test"
diff --git a/lang/de/mail.php b/lang/de/mail.php
index 41d63ec..ecb3125 100644
--- a/lang/de/mail.php
+++ b/lang/de/mail.php
@@ -6,6 +6,7 @@ return [
'body1' => "Hallo,
Ihr Vorantrag wurde erfolgreich eingereicht.
Ihre Bearbeitungsnummer lautet: ",
'body2' => "
Folgende Daten wurden übermittelt:
",
'body3' => "
Bitte heben Sie diese E-Mail unbedingt auf.
Wenn möglich, drucken Sie das Formblatt 5, welches sich im E-Mail-Anhang befindet, aus. Tragen Sie Ihre Bearbeitungsnummer ein und bringen Sie es bei Abholung mit.",
+ 'body4' => "
Wir bitten ebenfalls um die Beachtung der Spendengebührenverordnung, welche sich ebenfalls im Anhang befindet.",
'signature' => "Mit freundlichen Grüßen,
Ihr C3Gov - Ihr Amt in der Bezirksregion CCC"
]
];
diff --git a/lang/en/mail.php b/lang/en/mail.php
index 3fd5c9f..8ac5140 100644
--- a/lang/en/mail.php
+++ b/lang/en/mail.php
@@ -6,6 +6,7 @@ return [
'body1' => "Hello,
Your preliminary application has been successfully submitted.
Your reference number is:",
'body2' => "
The following data has been submitted:
",
'body3' => "
Please keep this email for your records.
If possible, print out form 5, which is attached to the email. Fill in your reference number and bring it with you when you pick up your hacker passport.",
+ 'body4' => "
We also ask you to observe the donation regulation, which is also attached.",
'signature' => "Sincerely,
Your C3Gov – Your office in the CCC district region"
]
];
diff --git a/resources/views/mail/preapplication.blade.php b/resources/views/mail/preapplication.blade.php
index aa3a8c5..703dde5 100644
--- a/resources/views/mail/preapplication.blade.php
+++ b/resources/views/mail/preapplication.blade.php
@@ -4,5 +4,7 @@
{{ __('app.preapplication.firstname') }}: {{ $pa->first_name }}
{{ __('app.preapplication.lastname') }}: {{ $pa->last_name }}
{{ __('app.preapplication.location') }}: {{ $pa->location }}
-{!! __('mail.preapplication.body3') !!}
+{!! __('mail.preapplication.body3') !!}
+{!! __('mail.preapplication.body4') !!}
+
{!! __('mail.preapplication.signature') !!}