private function showCreateBookingPage()
 {
     if (WebRequest::wasPosted()) {
         try {
             // get variables
             $bcust = WebRequest::postInt("bcust");
             $badults = WebRequest::postInt("badults");
             $bchildren = WebRequest::postInt("bchildren");
             $bstart = WebRequest::post("bstart");
             $bend = WebRequest::post("bend");
             $bpromo = WebRequest::postInt("bpromo");
             $broom = WebRequest::postInt("broom");
             // data validation
             if ($badults == 0) {
                 throw new CreateBookingException("no-adults");
             }
             if ($bstart == null) {
                 throw new CreateBookingException("no-start-date");
             }
             if ($bend == null) {
                 throw new CreateBookingException("no-end-date");
             }
             if ($bcust == 0) {
                 throw new CreateBookingException("no-customer-for-booking");
             }
             $booking = new Booking();
             // set values
             $booking->setCustomer($bcust);
             $booking->setAdults($badults);
             $booking->setChildren($bchildren);
             $booking->setStartDate($bstart);
             $booking->setEndDate($bend);
             $booking->setPromocode($bpromo);
             $booking->setRoom($broom);
             $booking->save();
             global $cScriptPath;
             $this->mHeaders[] = "Location: {$cScriptPath}/Bookings";
         } catch (CreateBookingException $ex) {
             $this->mBasePage = "mgmt/bookingCreate.tpl";
             $this->error($ex->getMessage());
         }
     } else {
         $this->mBasePage = "mgmt/bookingCreate.tpl";
     }
 }
 protected function runPage()
 {
     if (WebRequest::wasPosted()) {
         if (!WebRequest::postInt("calroom")) {
             $this->showCal();
             return;
         }
         $startdate = new DateTime(WebRequest::post("qbCheckin"));
         $enddate = new DateTime(WebRequest::post("qbCheckout"));
         $room = Room::getById(WebRequest::postInt("calroom"));
         for ($date = $startdate; $date < $enddate; $date->modify("+1 day")) {
             if (!$room->isAvailable($date)) {
                 $this->error("room-not-available");
                 $this->showCal();
                 return;
             }
         }
         // search for customer
         if (!($customer = Customer::getByEmail(WebRequest::post("qbEmail")))) {
             $customer = new Customer();
             $suTitle = WebRequest::post("qbTitle");
             $suFirstname = WebRequest::post("qbFirstname");
             $suLastname = WebRequest::post("qbLastname");
             $suAddress = WebRequest::post("qbAddress");
             $suCity = WebRequest::post("qbCity");
             $suPostcode = WebRequest::post("qbPostcode");
             $suCountry = WebRequest::post("qbCountry");
             $suEmail = WebRequest::post("qbEmail");
             $customer->setPassword($suEmail);
             // set values
             $customer->setTitle($suTitle);
             $customer->setFirstname($suFirstname);
             $customer->setSurname($suLastname);
             $address = new Address();
             $address->setLine1($suAddress);
             $address->setCity($suCity);
             $address->setPostCode($suPostcode);
             $address->setCountry($suCountry);
             $address->save();
             $customer->setAddress($address);
             $customer->setEmail($suEmail);
             // save it
             $customer->save();
             $customer->sendMailConfirm();
             // save it again
             $customer->save();
         }
         $booking = new Booking();
         $booking->setStartDate(WebRequest::post("qbCheckin"));
         $booking->setEndDate(WebRequest::post("qbCheckout"));
         $booking->setAdults(WebRequest::post("qbAdults"));
         $booking->setChildren(WebRequest::post("qbChildren"));
         $booking->setPromocode(WebRequest::post("qbPromoCode"));
         $booking->setRoom($room->getId());
         $booking->setCustomer($customer->getId());
         $booking->save();
         $msg = Message::getMessage("booking-confirmation");
         $msg = str_replace("\$1", $booking->getStartDate(), $msg);
         $msg = str_replace("\$2", $booking->getEndDate(), $msg);
         $msg = str_replace("\$3", $booking->getAdults(), $msg);
         $msg = str_replace("\$4", $booking->getChildren(), $msg);
         $msg = str_replace("\$5", $booking->getRoom()->getName(), $msg);
         Mail::send($customer->getEmail(), Message::getMessage("booking-confimation-subject"), $msg);
         $this->mSmarty->assign("content", $msg);
         return;
     }
     throw new YouShouldntBeDoingThatException();
 }