-
Notifications
You must be signed in to change notification settings - Fork 264
/
Copy pathReservationSavePage.php
554 lines (459 loc) · 10.4 KB
/
ReservationSavePage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
<?php
/**
* Copyright 2011-2016 Nick Korbel
*
* This file is part of Booked Scheduler.
*
* Booked Scheduler is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Booked Scheduler is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Booked Scheduler. If not, see <http://www.gnu.org/licenses/>.
*/
require_once(ROOT_DIR . 'Pages/SecurePage.php');
require_once(ROOT_DIR . 'Pages/Ajax/IReservationSaveResultsView.php');
require_once(ROOT_DIR . 'Presenters/Reservation/ReservationPresenterFactory.php');
interface IReservationSavePage extends IReservationSaveResultsView, IRepeatOptionsComposite
{
/**
* @return int
*/
public function GetUserId();
/**
* @return int
*/
public function GetResourceId();
/**
* @return string
*/
public function GetTitle();
/**
* @return string
*/
public function GetDescription();
/**
* @return string
*/
public function GetStartDate();
/**
* @return string
*/
public function GetEndDate();
/**
* @return string
*/
public function GetStartTime();
/**
* @return string
*/
public function GetEndTime();
/**
* @return int[]
*/
public function GetResources();
/**
* @return int[]
*/
public function GetParticipants();
/**
* @return int[]
*/
public function GetInvitees();
/**
* @param string $referenceNumber
*/
public function SetReferenceNumber($referenceNumber);
/**
* @param bool $requiresApproval
*/
public function SetRequiresApproval($requiresApproval);
/**
* @return AccessoryFormElement[]|array
*/
public function GetAccessories();
/**
* @return AttributeFormElement[]|array
*/
public function GetAttributes();
/**
* @return UploadedFile[]
*/
public function GetAttachments();
/**
* @return bool
*/
public function HasStartReminder();
/**
* @return string
*/
public function GetStartReminderValue();
/**
* @return string
*/
public function GetStartReminderInterval();
/**
* @return bool
*/
public function HasEndReminder();
/**
* @return string
*/
public function GetEndReminderValue();
/**
* @return string
*/
public function GetEndReminderInterval();
/**
* @return bool
*/
public function GetAllowParticipation();
/**
* @return string[]
*/
public function GetParticipatingGuests();
/**
* @return string[]
*/
public function GetInvitedGuests();
}
class ReservationSavePage extends SecurePage implements IReservationSavePage
{
/**
* @var ReservationSavePresenter
*/
private $_presenter;
/**
* @var bool
*/
private $_reservationSavedSuccessfully = false;
public function __construct()
{
parent::__construct();
$factory = new ReservationPresenterFactory();
$this->_presenter = $factory->Create($this, ServiceLocator::GetServer()->GetUserSession());
}
public function PageLoad()
{
try
{
$this->EnforceCSRFCheck();
$reservation = $this->_presenter->BuildReservation();
$this->_presenter->HandleReservation($reservation);
if ($this->_reservationSavedSuccessfully)
{
$this->Set('Resources', $reservation->AllResources());
$this->Set('Instances', $reservation->Instances());
$this->Set('Timezone', ServiceLocator::GetServer()->GetUserSession()->Timezone);
$this->Display('Ajax/reservation/save_successful.tpl');
}
else
{
$this->Display('Ajax/reservation/save_failed.tpl');
}
} catch (Exception $ex)
{
Log::Error('ReservationSavePage - Critical error saving reservation: %s', $ex);
$this->Display('Ajax/reservation/reservation_error.tpl');
}
}
public function SetSaveSuccessfulMessage($succeeded)
{
$this->_reservationSavedSuccessfully = $succeeded;
}
public function SetReferenceNumber($referenceNumber)
{
$this->Set('ReferenceNumber', $referenceNumber);
}
public function SetRequiresApproval($requiresApproval)
{
$this->Set('RequiresApproval', $requiresApproval);
}
public function SetErrors($errors)
{
$this->Set('Errors', $errors);
}
public function SetWarnings($warnings)
{
// set warnings variable
}
public function GetReservationAction()
{
return $this->GetForm(FormKeys::RESERVATION_ACTION);
}
public function GetReferenceNumber()
{
return $this->GetForm(FormKeys::REFERENCE_NUMBER);
}
public function GetUserId()
{
return $this->GetForm(FormKeys::USER_ID);
}
public function GetResourceId()
{
return $this->GetForm(FormKeys::RESOURCE_ID);
}
public function GetTitle()
{
return $this->GetForm(FormKeys::RESERVATION_TITLE);
}
public function GetDescription()
{
return $this->GetForm(FormKeys::DESCRIPTION);
}
public function GetStartDate()
{
return $this->GetForm(FormKeys::BEGIN_DATE);
}
public function GetEndDate()
{
return $this->GetForm(FormKeys::END_DATE);
}
public function GetStartTime()
{
return $this->GetForm(FormKeys::BEGIN_PERIOD);
}
public function GetEndTime()
{
return $this->GetForm(FormKeys::END_PERIOD);
}
public function GetResources()
{
$resources = $this->GetForm(FormKeys::ADDITIONAL_RESOURCES);
if (is_null($resources))
{
return array();
}
if (!is_array($resources))
{
return array($resources);
}
return $resources;
}
public function GetRepeatOptions()
{
return $this->_presenter->GetRepeatOptions();
}
public function GetRepeatType()
{
return $this->GetForm(FormKeys::REPEAT_OPTIONS);
}
public function GetRepeatInterval()
{
return $this->GetForm(FormKeys::REPEAT_EVERY);
}
public function GetRepeatWeekdays()
{
$days = array();
$sun = $this->GetForm(FormKeys::REPEAT_SUNDAY);
if (!empty($sun))
{
$days[] = 0;
}
$mon = $this->GetForm(FormKeys::REPEAT_MONDAY);
if (!empty($mon))
{
$days[] = 1;
}
$tue = $this->GetForm(FormKeys::REPEAT_TUESDAY);
if (!empty($tue))
{
$days[] = 2;
}
$wed = $this->GetForm(FormKeys::REPEAT_WEDNESDAY);
if (!empty($wed))
{
$days[] = 3;
}
$thu = $this->GetForm(FormKeys::REPEAT_THURSDAY);
if (!empty($thu))
{
$days[] = 4;
}
$fri = $this->GetForm(FormKeys::REPEAT_FRIDAY);
if (!empty($fri))
{
$days[] = 5;
}
$sat = $this->GetForm(FormKeys::REPEAT_SATURDAY);
if (!empty($sat))
{
$days[] = 6;
}
return $days;
}
public function GetRepeatMonthlyType()
{
return $this->GetForm(FormKeys::REPEAT_MONTHLY_TYPE);
}
public function GetRepeatTerminationDate()
{
return $this->GetForm(FormKeys::END_REPEAT_DATE);
}
public function GetSeriesUpdateScope()
{
return $this->GetForm(FormKeys::SERIES_UPDATE_SCOPE);
}
/**
* @return int[]
*/
public function GetParticipants()
{
$participants = $this->GetForm(FormKeys::PARTICIPANT_LIST);
if (is_array($participants))
{
return $participants;
}
return array();
}
/**
* @return int[]
*/
public function GetInvitees()
{
$invitees = $this->GetForm(FormKeys::INVITATION_LIST);
if (is_array($invitees))
{
return $invitees;
}
return array();
}
public function GetInvitedGuests()
{
$invitees = $this->GetForm(FormKeys::GUEST_INVITATION_LIST);
if (is_array($invitees))
{
return $invitees;
}
return array();
}
public function GetParticipatingGuests()
{
$participants = $this->GetForm(FormKeys::GUEST_PARTICIPATION_LIST);
if (is_array($participants))
{
return $participants;
}
return array();
}
/**
* @return AccessoryFormElement[]
*/
public function GetAccessories()
{
$accessories = $this->GetForm(FormKeys::ACCESSORY_LIST);
if (is_array($accessories))
{
$af = array();
foreach ($accessories as $a)
{
$af[] = new AccessoryFormElement($a);
}
return $af;
}
return array();
}
/**
* @return AttributeFormElement[]|array
*/
public function GetAttributes()
{
return AttributeFormParser::GetAttributes($this->GetForm(FormKeys::ATTRIBUTE_PREFIX));
}
/**
* @return UploadedFile[]
*/
public function GetAttachments()
{
if ($this->AttachmentsEnabled())
{
return $this->server->GetFiles(FormKeys::RESERVATION_FILE);
}
return array();
}
private function AttachmentsEnabled()
{
return Configuration::Instance()->GetSectionKey(ConfigSection::UPLOADS,
ConfigKeys::UPLOAD_ENABLE_RESERVATION_ATTACHMENTS,
new BooleanConverter());
}
public function HasStartReminder()
{
$val = $this->server->GetForm(FormKeys::START_REMINDER_ENABLED);
return !empty($val);
}
public function GetStartReminderValue()
{
return $this->server->GetForm(FormKeys::START_REMINDER_TIME);
}
public function GetStartReminderInterval()
{
return $this->server->GetForm(FormKeys::START_REMINDER_INTERVAL);
}
public function HasEndReminder()
{
$val = $this->server->GetForm(FormKeys::END_REMINDER_ENABLED);
return !empty($val);
}
public function GetEndReminderValue()
{
return $this->server->GetForm(FormKeys::END_REMINDER_TIME);
}
public function GetEndReminderInterval()
{
return $this->server->GetForm(FormKeys::END_REMINDER_INTERVAL);
}
public function GetAllowParticipation()
{
$val = $this->server->GetForm(FormKeys::ALLOW_PARTICIPATION);
return !empty($val);
}
public function SetCanBeRetried($canBeRetried)
{
$this->Set('CanBeRetried', $canBeRetried);
}
public function SetRetryParameters($retryParameters)
{
$this->Set('RetryParameters', $retryParameters);
}
public function GetRetryParameters()
{
return ReservationRetryParameter::GetParamsFromForm($this->GetForm(FormKeys::RESERVATION_RETRY_PREFIX));
}
public function SetRetryMessages($messages)
{
$this->Set('RetryMessages', $messages);
}
public function SetCanJoinWaitList($canJoinWaitlist)
{
$this->Set('CanJoinWaitList', $canJoinWaitlist);
}
}
class AccessoryFormElement
{
public $Id;
public $Quantity;
public function __construct($formValue)
{
$idAndQuantity = $formValue;
$y = explode('-', $idAndQuantity);
$params = explode(',', $y[1]);
$id = explode('=', $params[0]);
$quantity = explode('=', $params[1]);
$name = explode('=', $params[2]);
$this->Id = $id[1];
$this->Quantity = $quantity[1];
$this->Name = urldecode($name[1]);
}
public static function Create($id, $quantity)
{
$element = new AccessoryFormElement("accessory-id=$id,quantity=$quantity,name=");
return $element;
}
}