public function uninstall() { parent::uninstall(); //1. remove template for advanced search panel $rootPath = RM_Environment::getConnector()->getRootPath(); $file = implode(DIRECTORY_SEPARATOR, array($rootPath, 'RM', 'userdata', 'views', 'user', 'scripts', 'Search', 'advanced', 'category_advancedsearch.phtml')); RM_Filesystem::deleteFile($file); //2. remove information about this panel from database in form->state field $formModel = new RM_Forms(); $form = $formModel->find('advancedsearch')->current(); $deleted = $form->deletePanel('category_advancedsearch'); if ($deleted) { $form->save(); } }
function unsetFromForm($panelID) { $panel = $this->find($panelID)->current(); $panelXtype = RM_Form_Naming_Manager::generatePanelXType($panelID); $model = new RM_Forms(); $form = $model->find($panel->form_id)->current()->getForm(); $formState = Zend_Json::decode($form->state); foreach ($formState as $columnKey => $column) { foreach ($column as $key => $panel) { if ($panel['xtype'] == $panelXtype) { unset($formState[$columnKey][$key]); $form->state = Zend_Json::encode($formState); $form->save(); return true; } } } return false; }
public function advancedvalidateJsonAction() { $this->_withoutView(); $formModel = new RM_Forms(); $form = $formModel->find('advancedsearch')->current(); $formvalid = $form->validate($this->getRequest()); $data = $this->_getParam('search', array()); // count records to be returned $criteria = new RM_Unit_Search_Criteria($data); $criteria->publishedOnly = true; $unitModel = new RM_Units(); $totalUnits = $unitModel->getAll($criteria)->count(); // count records end if ($formvalid == false) { $errors = $form->getErrors(); $returnData = array('data' => array('success' => false, 'errors' => $errors, 'count' => $totalUnits)); } else { $errors = $form->getErrors(); $returnData = array('data' => array('success' => true, 'errors' => null, 'count' => $totalUnits)); } return $returnData; }
/** * Saving form state into database * * @param formID * @param value * @return json information for the front-end */ function savestateJsonAction() { $formID = $this->_getParam('formID'); $state = $this->_getParam('state'); $columns = $this->_getParam('columns'); $column1width = $this->_getParam('column1width'); $column2width = $this->_getParam('column2width'); $column3width = $this->_getParam('column3width'); $unitTypeID = $this->_getParam('unitTypeID', RM_UnitTypes::DEFAULT_TYPE); $model = new RM_Forms(); $form = $model->find($formID)->current(); $unitTypesModel = new RM_UnitTypes(); $unitType = $unitTypesModel->find($unitTypeID)->current(); if ($unitType == null) { $unitTypeID = RM_UnitTypes::DEFAULT_TYPE; $unitType = $unitTypesModel->find($unitTypeID)->current(); } $unitTypeFormsModel = new RM_UnitTypeForms(); if ($unitTypeFormsModel->check($form, $unitType)) { $unitTypeForm = $unitTypeFormsModel->fetchBy($form, $unitType); } else { //We need to create a new row for this unit type $unitTypeForm = $unitTypeFormsModel->createRow(); $unitTypeForm->form_id = $form->id; $unitTypeForm->unit_type_id = $unitTypeID; } $unitTypeForm->columns = $columns; $unitTypeForm->column1width = $column1width; $unitTypeForm->column2width = $column2width; $unitTypeForm->column3width = $column3width; $unitTypeForm->state = $state; $result = $unitTypeForm->save(); $resultJson = false; if ($result) { $resultJson = true; } return array('data' => array('success' => $resultJson)); }
/** * Action for validating user details form parameters. * * If some of the parameters are invalid this method will redirect user to previous page with error * text messages about every wrong parameter. * If all user detail information is valid this method will save user information into global * reservation manager object and will redirect user to the next step of the reservation process. */ function detailsvalidateAction() { $this->_withoutView(); $user = RM_Reservation_Manager::getInstance()->getUser(); if ($user == null || $user->isGuest()) { $userModel = new RM_Users(); // validate reCaptcha $config = new RM_Config(); $useReCaptcha = $config->getValue('rm_config_recaptcha_enabled'); if ($useReCaptcha) { $reCaptcha = new RM_Captcha_Recaptcha(); if (!$reCaptcha->validate()) { RM_Reservation_Manager::getInstance()->resetFormErrors('userdetails')->setFormErrors('userdetails', RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_ERRORS)->_('RM.User.Creation', 'CaptchaIncorrect'))->save(); $user = $userModel->createNewUser($this->getRequest(), RM_UserGroups::REGULAR, true); RM_Reservation_Manager::getInstance()->setUser($user); $this->_redirect('User', 'userdetails'); } } try { $user = $userModel->createNewUser($this->getRequest()); } catch (RM_Exception $e) { RM_Reservation_Manager::getInstance()->resetFormErrors('userdetails')->setFormErrors('userdetails', RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_ERRORS)->_('RM.User.Creation', $e->getMessage()))->save(); $user = $userModel->createNewUser($this->getRequest(), RM_UserGroups::REGULAR, true); RM_Reservation_Manager::getInstance()->setUser($user); $this->_redirect('User', 'userdetails'); } } //Save user object in global reservation manager object RM_Reservation_Manager::getInstance()->setUser($user); $this->_fireUserCreationEvent(); $formModel = new RM_Forms(); $form = $formModel->find('userdetails')->current(); $valid = $form->validate($this->getRequest()); if ($valid) { RM_Reservation_Manager::getInstance()->resetFormErrors('userdetails')->save(); //TODO: add code for getting next stage controller/action from admin preferences $controller = 'Reservations'; $action = 'summary'; $this->_redirect($controller, $action); } else { RM_Reservation_Manager::getInstance()->setFormErrors('userdetails', $form->getErrors())->save(); $this->_redirect('User', 'userdetails'); } }
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()); }
/** * Action for validating unit details form parameters. * If some of the parameters are invalid this method will redirect user to previous page with error * text messages about every wrong parameter. * If all unit detail information is valid this method will save unit information into global * reservation manager object and will redirect user to the next step of the reservation process. */ function detailsvalidateAction() { $this->_withoutView(); $unitID = $this->_getParam('unit_id', null); if ($unitID == null) { $this->_redirect('Unit', 'list'); return; } // this is the subunits if groups is being implemented $selectedUnitIds = json_decode($this->_getParam('selected_unit_ids', "[]")); $quantity = $this->_getParam('quantity', 1); $formModel = new RM_Forms(); $form = $formModel->find('unitdetails')->current(); $valid = $form->validate($this->getRequest()); if ($valid == false) { RM_Reservation_Manager::getInstance()->setFormErrors('unitdetails', $form->getErrors())->save(); $this->_redirect('Unit', 'details', array('unit_id' => $unitID)); } //We have a priority to use a user selected dates on the page, not from criteria if ($this->_request->getParam('rm_calendar_dates', null) != null) { // get the dates from the calendar selection $datesString = $this->_request->getParam('rm_calendar_dates'); $dates = explode(',', $datesString); $startDateMySQL = $dates[0]; $endDateMySQL = $dates[count($dates) - 1]; $adults = $this->_getParam("adults", 1); $children = $this->_getParam("children", 0); $infants = $this->_getParam("infants", 0); $persons = new RM_Reservation_Persons(array("adults" => $adults, "children" => $children, "infants" => $infants)); } else { $criteria = RM_Reservation_Manager::getInstance()->getCriteria(); $startDateMySQL = $criteria->start_datetime; $endDateMySQL = $criteria->end_datetime; $persons = new RM_Reservation_Persons(array("adults" => $criteria->adults, "children" => $criteria->children, "infants" => $criteria->infants)); } $period = new RM_Reservation_Period(new RM_Date(strtotime($startDateMySQL)), new RM_Date(strtotime($endDateMySQL))); $unitModel = new RM_Units(); $otherinfo = $this->_getParam("otherInfo", array()); $manager = RM_Reservation_Manager::getInstance(); // use a temporary session to pass a value to the groups module init $_SESSION["returnAllUnits"] = true; // get price... $unit = $unitModel->get($unitID, RM_Environment::getInstance()->getLocale(), array("summary", "description")); $information = new RM_Prices_Information($unit, $period, $persons, $otherinfo); $priceSystem = RM_Environment::getInstance()->getPriceSystem(); try { $calculatedTotalPrice = $priceSystem->getTotalUnitPrice($information); } catch (RM_Exception $e) { RM_Reservation_Manager::getInstance()->setFormErrors('unitdetails', array($e->getMessage()))->save(); $this->_redirect('Unit', 'details', array('unit_id' => $selectedUnitId)); } $selectedCount = 1; // loop through the selected units and save these foreach ($selectedUnitIds as $selectedUnitId) { if ($selectedCount >= $quantity) { break; } $selectedUnit = $unitModel->get($selectedUnitId, RM_Environment::getInstance()->getLocale()); $details = new RM_Reservation_Details($selectedUnit, $period, $persons, $otherinfo, $calculatedTotalPrice); $manager->addDetails($details); $selectedCount += 1; } $manager->resetFormErrors('unitdetails')->save(); $details = $manager->getAllDetails(); // reset the returnAllUnits if it's set unset($_SESSION["returnAllUnits"]); $cmsUser = RM_Environment::getConnector()->getUser(); if ($cmsUser->isGuest() == false) { $user = $cmsUser->findResmaniaUser(); if ($user !== null) { RM_Reservation_Manager::getInstance()->setUser($user); $this->_redirect('Reservations', 'summary'); } } elseif (RM_Reservation_Manager::getInstance()->getUser() !== null) { $this->_redirect('Reservations', 'summary'); } $this->_redirect('User', 'userdetails'); }