Permalink
Browse files

Show form when terms are available

  • Loading branch information...
vojtasvoboda committed Aug 17, 2014
1 parent 9a189ec commit efd19fa927ff487b20034df887eab31956ab71d0
Showing with 35 additions and 21 deletions.
  1. +28 −19 index.php
  2. +1 −1 models/Reservations.php
  3. +6 −1 templates/index.php
View
@@ -17,31 +17,40 @@
$dates = $reservations->getDates();
$times = $reservations->getTimes();
// create registration form
$form = new RegistrationForm($dates, $times);
// if we have available dates and times
if ( !empty($dates) && !empty($times) ) {
// form sent and valid
if ($form->isSuccess()) {
// create registration form
$form = new RegistrationForm($dates, $times);
// form values
$values = $form->getValues();
// form sent and valid
if ($form->isSuccess()) {
// check e-mail
if (!$reservations->checkEmail($values->email)) {
$form->addError('Na tento e-mail je již provedena rezervace.');
}
// form values
$values = $form->getValues();
// check date and time
if (!$reservations->isFree($values->date, $values->time)) {
$form->addError('Tato hodina je již obsazena, zkuste vybrat jinou.');
}
// check e-mail
if (!$reservations->checkEmail($values->email)) {
$form->addError('Na tento e-mail je již provedena rezervace.');
}
// check date and time
if (!$reservations->isFree($values->date, $values->time)) {
$form->addError('Tato hodina je již obsazena, zkuste vybrat jinou.');
}
// if is form still valid
if ($form->isValid()) {
// then save reservation
$reservations->create($form->getValues());
// if is form still valid
if ($form->isValid()) {
// redirect
header("HTTP/1.1 303 See Other");
header("Location: /?done=1");
exit;
// then save reservation
$reservations->create($form->getValues());
echo "Saved!";
}
}
View
@@ -6,7 +6,7 @@
class Reservations {
/** max amout of reservations for one term (one time within one date) */
const MAX_PERSON_PER_TERM = 2;
const MAX_PERSON_PER_TERM = 10;
/** @var \Connection $db */
private $db;
View
@@ -12,13 +12,18 @@
<script src="js/netteForms.js"></script>
<style>
.error { color: red; }
th { text-align: right; }
</style>
</head>
<body>
<?=$form;?>
<?php if (isset($form)) { ?>
<?=$form;?>
<?php } else { ?>
<p>All terms are full.</p>
<?php } ?>
</body>
</html>

0 comments on commit efd19fa

Please sign in to comment.