public function getDefaultPricePlan() { return RoomPricePlan::fetchFromDbDefaultForRoom($this->id); }
if (!$roomPricePlan->save()) { $logger->LogError("Error saving room price plan."); foreach ($roomPricePlan->errors as $error) { $logger->LogError($error); $errors[] = $error; } } else { header("Location: room_price_list.php"); $message = "Values were updated successfully!"; } } else { if (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) { $logger->LogInfo("Page was called for edit of id: " . $_REQUEST['id']); $id = intval($_REQUEST['id']); $logger->LogDebug("Numeric id is: {$id}"); $roomPricePlan = RoomPricePlan::fetchFromDb($id); if ($roomPricePlan == null) { $logger->LogError("Invalid request. No room price plan with id: {$id} exists."); $errors[] = "Invalid request. No room price plan with id: {$id} exists."; } } } include "header.php"; ?> </td> </tr> <tr> <td valign="top"> <?php if (sizeof($errors) > 0) {
public function isValid() { $this->errors = array(); if (strlen(trim($this->roomId)) == 0) { $this->setError("Room id cannot be empty"); } if ($this->startDate == NULL && !$this->isDefault) { $this->setError("Start date name cannot be empty"); } if ($this->endDate == NULL && !$this->isDefault) { $this->setError("End date name cannot be empty"); } if (!is_float($this->price)) { $this->setError("Price is invalid"); } if ($this->price <= 0) { $this->setError("Price must be greater than zero"); } if (!is_float($this->extraBedPrice)) { $this->setError("Extra bed price is invalid"); } if ($this->extraBedPrice < 0) { $this->setError("Extra bed price must be greater than zero"); } if (sizeof($this->errors) == 0) { $existingPricePlans = RoomPricePlan::fetchAllFromDbForRoomAndDates($this->roomId, $this->startDate, $this->endDate); foreach ($existingPricePlans as $existingPricePlan) { if (!$existingPricePlan->isDefault && $existingPricePlan->id != $this->id) { $this->setError("Plan whose dates overlap already exists"); break; } } } return sizeof($this->errors) == 0; }
global $logger; $errors = array(); $message = ""; $room = new Room(); $roomPricePlan = new RoomPricePlan(); if (isset($_POST['SBMT_REG'])) { $logger->LogInfo("Form has been submitted."); $room = Room::fetchFromParameters($_POST); if (!$room->save()) { $logger->LogError("Error saving room."); foreach ($room->errors as $error) { $logger->LogError($error); $errors[] = $error; } } else { $roomPricePlan = RoomPricePlan::fetchFromParameters($_POST); $roomPricePlan->id = intval($_POST['price_plan_id']); $roomPricePlan->isDefault = true; $roomPricePlan->roomId = $room->id; if (!$roomPricePlan->save()) { $logger->LogError("Error saving room."); foreach ($room->errors as $error) { $logger->LogError($error); $errors[] = $error; } } else { header("Location: rooms_list.php"); $message = "Values were updated successfully!"; } } } else {