function summaryvalidateAction()
 {
     $formModel = new RM_Forms();
     $form = $formModel->find('summary')->current();
     $valid = $form->validate($this->getRequest());
     if ($valid == false) {
         RM_Reservation_Manager::getInstance()->setFormErrors('summary', $form->getErrors())->save();
         $this->_redirect('Reservations', 'summary');
     }
     //Apply extras
     $extrasSystems = RM_Environment::getInstance()->getExtrasSystems();
     if (count($extrasSystems) !== 0) {
         $details = RM_Reservation_Manager::getInstance()->getAllDetails();
         foreach ($details as $detail) {
             foreach ($extrasSystems as $extrasSystem) {
                 $newDetail = $extrasSystem->applySelection($this->getRequest(), $detail);
                 if (false === $newDetail) {
                     RM_Reservation_Manager::getInstance()->setFormErrors('summary', array('ExtrasSelectionIsWrong'))->save();
                     $this->_redirect('Reservations', 'summary');
                 }
             }
             RM_Reservation_Manager::getInstance()->addDetails($newDetail);
         }
     }
     //Apply others
     $othersSystems = RM_Environment::getInstance()->getOthersSystems();
     if (count($othersSystems) !== 0) {
         $details = RM_Reservation_Manager::getInstance()->getAllDetails();
         foreach ($details as $detail) {
             foreach ($othersSystems as $othersSystem) {
                 $newDetail = $othersSystem->applySelection($this->getRequest(), $detail);
                 if (false === $newDetail) {
                     RM_Reservation_Manager::getInstance()->setFormErrors('summary', array('OthersSelectionIsWrong'))->save();
                     $this->_redirect('Reservations', 'summary');
                 }
             }
             RM_Reservation_Manager::getInstance()->addDetails($newDetail);
         }
     }
     // Create the User
     $manager = RM_Reservation_Manager::getInstance();
     if ($manager->getCriteria() === null) {
         $this->_redirect('Reservations', 'sessiontimedout');
     }
     $user = $manager->getUser();
     // this is the resmania user instance
     $loginStatus = RM_Environment::getConnector()->getLoginStatus();
     // get the Host CMS login status.
     if (isset($user)) {
         if (!$loginStatus) {
             // check if the user is logged into the CMS
             $userPassword = $user->password;
             //This in unencrypted one, we need to login to cms.
             $registered = $user->isRegistered();
             if ($registered == false) {
                 // if we are not logged in and not registered, register the user
                 $config = new RM_Config();
                 if ($config->getValue('rm_config_enable_cms_user_creation')) {
                     $user->setTable(RM_Environment::getConnector()->getUsersModel());
                 } else {
                     $user->setTable(new RM_Users());
                 }
                 if ($user->group_id == null) {
                     $user->group_id = RM_UserGroups::REGULAR;
                 }
                 $user->save();
             }
             // login
             RM_Environment::getConnector()->authenticate($user->username, $userPassword);
         }
     }
     // save the reservation with the in_progress flag set as true.
     // this manse the reservation will not be visable until the processing is complete.
     $reservationModel = new RM_Reservations();
     // we need to check is there a reservation in status progress in database with the same
     // id as we have here.
     $inProgressReservation = $reservationModel->find($manager->getReservationID())->current();
     if ($inProgressReservation !== null) {
         if ($inProgressReservation->in_progress == 1) {
             $inProgressReservation->delete();
         } else {
             //we already have a full stored reservation in database so we need reset Manager and go to the first page
             $manager->reset();
             $this->_redirect('Unit', 'list');
         }
     }
     $reservationModel->insertNewReservation($manager->getUser(), $manager->getAllDetails(), 1, 0, $manager->getReservationID());
     RM_Log::toLog("New Reservation Created with the ID: " . $manager->getReservationID());
     // direct the process to the payment provider form...
     $this->_forward('form', RM_Environment::getInstance()->getPaymentSystem()->getControllerName());
 }
示例#2
0
 /**
  * saves the new reservation selection
  *
  * @return JSON
  */
 public function insertJsonAction()
 {
     // get the data
     $data = Zend_Json::decode($this->_getParam('data'));
     $unitID = $data['cid'];
     $userID = $data['uid'];
     $start = $data['start'];
     $end = $data['end'];
     // get the unit object
     $unitModel = new RM_Units();
     $unit = $unitModel->get($unitID);
     // convert the date selection to a period object
     $periodObj = new RM_Reservation_Period(new RM_Date(strtotime($start)), new RM_Date(strtotime($end)));
     // check if the dates are allowed
     $reservationModel = new RM_ReservationDetails();
     $currentReservationCount = $reservationModel->getReservationCount($unit, $periodObj);
     if ($currentReservationCount > 0) {
         return array('data' => array('success' => false, 'message' => RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN)->_('Admin.Reservations.Edit', 'InvalidSelection')));
         die;
     }
     $unitDetails = null;
     // reset the unit array for safe keeping
     $unitDetails = array(new RM_Reservation_Details($unit, $periodObj, new RM_Reservation_Persons()));
     $userModel = new RM_Users();
     $user = $userModel->find($userID)->current();
     // get the "system user"
     // get a reservation ID
     $reservationID = RM_Reservations::createReservationID();
     $reservationModel = new RM_Reservations();
     $result = $reservationModel->insertNewReservation($user, $unitDetails, 0, 1, $reservationID);
     if (!$result) {
         return array('data' => array('success' => false, 'message' => RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_ERRORS)->_('Admin.Reservation.Edit', 'ServerError')));
     } else {
         // mark the new block as paid
         $reservation = $reservationModel->find($reservationID)->current();
         if ($userID === "") {
             $reservationModel->markPaid($reservation);
         }
         $idArray = explode("-", $reservationID);
         $id = (int) $idArray[1];
         // check time
         $ad = true;
         // all day
         $starttime = explode(" ", $start);
         if ($starttime[1] !== "00:00:00") {
             $ad = false;
         }
         $endtime = explode(" ", $end);
         if ($endtime[1] !== "00:00:00") {
             $ad = false;
         }
         return array('data' => array("success" => true, "message" => RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN)->_('Admin.Reservation.Edit', "LoadedData"), "data" => array("id" => $id, "cid" => $unitID, "uid" => (int) $userID, "title" => $reservationID, "start" => $start, "end" => $end, "ad" => $ad)));
     }
 }
 /**
  * Invoked from the New Reservation Wizard form via an AJAX request (wizard.js) and is used to insert the reservation.
  *
  * @param  	request array   All of the reservation data passed via the form submit.
  * @return 	json    boolean (true if success)
  * @deprecated
  */
 public function wizardinsertJsonAction()
 {
     // all parameters from the new wizard...
     $ids = $this->_getParam('ids');
     $ref = $this->_getParam('bookingref');
     $userid = $this->_getParam('userid');
     $startdatetime = $this->_getParam('start_datetime');
     $enddatetime = $this->_getParam('end_datetime');
     $config = new RM_Config();
     $startDate = $config->convertDates($startdatetime, RM_Config::JS_DATEFORMAT, RM_Config::PHP_DATEFORMAT);
     $endDate = $config->convertDates($enddatetime, RM_Config::JS_DATEFORMAT, RM_Config::PHP_DATEFORMAT);
     $period = new RM_Reservation_Period(new RM_Date(strtotime($startDate)), new RM_Date(strtotime($endDate)));
     $unitModel = new RM_Units();
     $unitDetails = array();
     $uids = explode(",", $ids);
     foreach ($uids as $uid) {
         $unitDetails[] = new RM_Reservation_Details($unitModel->get($uid), $period, new RM_Reservation_Persons());
     }
     $userModel = new RM_Users();
     $user = $userModel->find($userid)->current();
     $reservationModel = new RM_Reservations();
     $reservationModel->insertNewReservation($user, $unitDetails, 0, 1, $ref);
     return array('data' => array('success' => true));
 }