|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use App\Event; |
|
6
|
|
|
use App\Http\Controllers\Controller; |
|
7
|
|
|
use App\Location; |
|
8
|
|
|
use App\PriceCategory; |
|
9
|
|
|
use App\PriceList; |
|
10
|
|
|
use App\Project; |
|
11
|
|
|
use App\Purchase; |
|
12
|
|
|
use App\SeatMap; |
|
13
|
|
|
use App\Setting; |
|
14
|
|
|
use App\Ticket; |
|
15
|
|
|
use App\User; |
|
16
|
|
|
use Illuminate\Http\Request; |
|
17
|
|
|
use Illuminate\Support\Facades\App; |
|
18
|
|
|
use Illuminate\Support\Facades\DB; |
|
19
|
|
|
use Illuminate\Support\Str; |
|
20
|
|
|
use Mews\Purifier\Facades\Purifier; |
|
21
|
|
|
use Spipu\Html2Pdf\Exception\Html2PdfException; |
|
22
|
|
|
use Spipu\Html2Pdf\Html2Pdf; |
|
23
|
|
|
|
|
24
|
|
|
class SettingsController extends Controller |
|
25
|
|
|
{ |
|
26
|
|
|
// Display all available settings |
|
27
|
|
|
public function index() |
|
28
|
|
|
{ |
|
29
|
|
|
$terms = Setting::where('name', 'terms')->where('lang', App::getLocale())->first(); |
|
30
|
|
|
$termsHtml = $terms ? $terms->value : view('components.default-texts.terms')->render(); |
|
31
|
|
|
|
|
32
|
|
|
$privacy = Setting::where('name', 'privacy')->where('lang', App::getLocale())->first(); |
|
33
|
|
|
$privacyHtml = $privacy ? $privacy->value : view('components.default-texts.privacy')->render(); |
|
34
|
|
|
|
|
35
|
|
|
return view('admin.settings', [ |
|
36
|
|
|
'terms' => $termsHtml, |
|
37
|
|
|
'privacy' => $privacyHtml |
|
38
|
|
|
]); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Receives HTML-input |
|
43
|
|
|
* |
|
44
|
|
|
* Attention: Function might be target for XSS attacks. Handle input carfully!!! |
|
45
|
|
|
*/ |
|
46
|
|
|
public function updateTerms(Request $request) |
|
47
|
|
|
{ |
|
48
|
|
|
Setting::updateOrCreate( |
|
49
|
|
|
['name' => 'terms', 'lang' => App::getLocale()], |
|
50
|
|
|
['value' => Purifier::clean($request->input('terms'))] |
|
51
|
|
|
); |
|
52
|
|
|
return redirect()->route('admin.settings.dashboard')->with('state', 'Success - Terms and Conditions updated.'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Receives HTML-input |
|
57
|
|
|
* |
|
58
|
|
|
* Attention: Function might be target for XSS attacks. Handle input carfully!!! |
|
59
|
|
|
*/ |
|
60
|
|
|
public function updatePrivacy(Request $request) |
|
61
|
|
|
{ |
|
62
|
|
|
Setting::updateOrCreate( |
|
63
|
|
|
['name' => 'privacy', 'lang' => App::getLocale()], |
|
64
|
|
|
['value' => Purifier::clean($request->input('privacy'))] |
|
65
|
|
|
); |
|
66
|
|
|
return redirect()->route('admin.settings.dashboard')->with('state', 'Success - Privacy statement updated.'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* File-Upload |
|
71
|
|
|
*/ |
|
72
|
|
|
public function updateLogo(Request $request) |
|
73
|
|
|
{ |
|
74
|
|
|
$validatedFile = $request->validate([ |
|
75
|
|
|
'file' => 'file|max:30000|mimes:jpeg,bmp,png,svg,jpg' |
|
76
|
|
|
]); |
|
77
|
|
|
|
|
78
|
|
|
// Only extract file extension of the new logo picture |
|
79
|
|
|
$extension = $validatedFile['file']->extension(); |
|
80
|
|
|
// set it to a generic name to overwrite any existing logo with the same extension |
|
81
|
|
|
$logoStoreName = 'logo.' . $extension; |
|
82
|
|
|
|
|
83
|
|
|
// Store file as new logo and update the corresponding setting |
|
84
|
|
|
$validatedFile['file']->storeAs('images', $logoStoreName); |
|
85
|
|
|
Setting::updateOrCreate( |
|
86
|
|
|
['name' => 'logo', 'lang' => 'en'], |
|
87
|
|
|
['value' => 'images/' . $logoStoreName] |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
// Redirect to source page with success message |
|
91
|
|
|
return redirect()->route('admin.settings.dashboard')->with('state', 'Success - Logo updated.'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Returns a ticket filled with dummy data to check the |
|
96
|
|
|
* correct processing of the logo in the layout |
|
97
|
|
|
*/ |
|
98
|
|
|
public function testTicket() |
|
99
|
|
|
{ |
|
100
|
|
|
// Wrap dummy data creation in a transaction in order |
|
101
|
|
|
// to not actually store it in the production database. |
|
102
|
|
|
// |
|
103
|
|
|
// We have to use eloquent models and cannot use factories, |
|
104
|
|
|
// because factories are not available on prod installations. |
|
105
|
|
|
DB::beginTransaction(); |
|
106
|
|
|
$vendor = User::create([ |
|
107
|
|
|
'name' => 'TestVendor FamilynameOfVendor', |
|
108
|
|
|
'email' => '[email protected]', |
|
109
|
|
|
'password' => '' |
|
110
|
|
|
]); |
|
111
|
|
|
$customer = User::create([ |
|
112
|
|
|
'name' => 'Avery LongName ButItShouldWork', |
|
113
|
|
|
'email' => '[email protected]', |
|
114
|
|
|
'password' => '' |
|
115
|
|
|
]); |
|
116
|
|
|
|
|
117
|
|
|
$priceList = PriceList::create([ |
|
118
|
|
|
'name' => 'Testlist' |
|
119
|
|
|
]); |
|
120
|
|
|
$priceCategory = PriceCategory::create([ |
|
121
|
|
|
'name' => 'TestCategory', |
|
122
|
|
|
'price' => 450, |
|
123
|
|
|
'description' => 'Just for testing the ticket layout' |
|
124
|
|
|
]); |
|
125
|
|
|
$priceList->categories()->save($priceCategory); |
|
126
|
|
|
|
|
127
|
|
|
$location = Location::create([ |
|
128
|
|
|
'name' => 'Some Test Location anywhere', |
|
129
|
|
|
'address' => 'Somewhere over the rainbox street 42, 424242 Kummerland, Wilde13' |
|
130
|
|
|
]); |
|
131
|
|
|
$project = Project::create([ |
|
132
|
|
|
'name' => 'A Test project', |
|
133
|
|
|
'description' => 'Something something testing', |
|
134
|
|
|
'is_archived' => false |
|
135
|
|
|
]); |
|
136
|
|
|
$seatMap = SeatMap::create([ |
|
137
|
|
|
'name' => 'TestSeatMap', |
|
138
|
|
|
'seats' => 2000, |
|
139
|
|
|
'description' => 'Some test description that does not really matter', |
|
140
|
|
|
'layout' => null |
|
141
|
|
|
]); |
|
142
|
|
|
$now = now(); |
|
143
|
|
|
|
|
144
|
|
|
$purchase = new Purchase(); |
|
145
|
|
|
$purchase->state = 'paid'; |
|
146
|
|
|
$purchase->state_updated = $now; |
|
147
|
|
|
$purchase->random_id = Str::random(20); |
|
148
|
|
|
$purchase->payment_secret = Str::random(20); |
|
149
|
|
|
$purchase->customer_id = $customer->id; |
|
150
|
|
|
$purchase->vendor_id = $vendor->id; |
|
151
|
|
|
$purchase->payment_id = 'dummy-reference'; |
|
152
|
|
|
$purchase->save(); |
|
153
|
|
|
|
|
154
|
|
|
$event = new Event(); |
|
155
|
|
|
$event->second_name = 'First event'; |
|
156
|
|
|
$event->customer_sell_stop = $now->add(1, 'day'); |
|
157
|
|
|
$event->retailer_sell_stop = $now->add(2, 'day'); |
|
158
|
|
|
$event->start_date = $now->add(1, 'day'); |
|
159
|
|
|
$event->end_date = $now->add(10, 'day'); |
|
160
|
|
|
$event->project_id = $project->id; |
|
161
|
|
|
$event->location_id = $location->id; |
|
162
|
|
|
$event->seat_map_id = $seatMap->id; |
|
163
|
|
|
$event->price_list_id = $priceList->id; |
|
164
|
|
|
$event->state = 'open'; |
|
165
|
|
|
$event->save(); |
|
166
|
|
|
|
|
167
|
|
|
for($i = 0; $i < 8; $i++) { |
|
168
|
|
|
$ticket = new Ticket(); |
|
169
|
|
|
$ticket->random_id = Str::random(20); |
|
170
|
|
|
$ticket->seat_number = $i + 1000; |
|
171
|
|
|
$ticket->event_id = $event->id; |
|
172
|
|
|
$ticket->purchase_id = $purchase->id; |
|
173
|
|
|
$ticket->price_category_id = $priceCategory->id; |
|
174
|
|
|
$ticket->state = 'consumed'; |
|
175
|
|
|
$ticket->save(); |
|
176
|
|
|
} |
|
177
|
|
|
try { |
|
178
|
|
|
$html2pdf = new HTML2PDF('P', 'A4', 'de', true, 'UTF-8', 0); |
|
179
|
|
|
$html2pdf->pdf->SetDisplayMode('fullpage'); |
|
180
|
|
|
$html2pdf->pdf->SetAuthor(config('app.name')); |
|
181
|
|
|
$html2pdf->pdf->SetTitle('Purchase #' . $purchase->id); |
|
182
|
|
|
|
|
183
|
|
|
// Generate pdf-content by passing the tickets to the view |
|
184
|
|
|
$content = view('pdfs.ticket-v2', ['tickets' => $purchase->tickets])->render(); |
|
185
|
|
|
$html2pdf->writeHTML($content); |
|
186
|
|
|
|
|
187
|
|
|
$html2pdf->output('tickets-' . $purchase->id . '.pdf'); |
|
188
|
|
|
} catch (Html2PdfException $e) { |
|
189
|
|
|
$html2pdf->clean(); |
|
190
|
|
|
DB::rollBack(); |
|
191
|
|
|
return redirect()->route('ticket.purchase', ['purchase' => $purchase])->with('state', $e->getMessage()); |
|
192
|
|
|
} |
|
193
|
|
|
DB::rollBack(); |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|