/** * IMPORTANT side effect. This method will automatically authenticate using to CMS if * enable_cms_integration is on in config. * * @param Zend_Request_Interface $request * @return bool */ function validate($request) { $result = true; //We check username for alphanumeric $username = $request->getParam('username', null); $validatorChain = new RM_Validate('Username'); $usernameResult = $validatorChain->addValidator(new Zend_Validate_Alnum())->isValid($username); if (!$usernameResult) { $this->_errors = $validatorChain->getErrors(); $result = false; } //We check password for alphanumeric $password = $request->getParam('password', null); $validatorChain = new RM_Validate('Password'); $passwordResult = $validatorChain->addValidator(new Zend_Validate_Alnum())->isValid($password); if (!$passwordResult) { $this->_errors = array_merge($this->_errors, $validatorChain->getErrors()); $result = false; } $config = new RM_Config(); $isCmsAuthentication = $config->getValue('rm_config_enable_cms_integration'); if ($isCmsAuthentication) { $authenticationResult = RM_Environment::getConnector()->authenticate($request->getParam('username'), $request->getParam('password')); if ($authenticationResult !== true) { if (is_object($authenticationResult)) { $this->_errors[] = $authenticationResult->getMessage(); } else { $this->_errors[] = 'UserNotFound'; } $result = false; } } else { $userModel = new RM_Users(); $user = $userModel->getBy($request->getParam('username')); if ($user === null) { $this->_errors[] = 'UserNotFound'; $result = false; } //Finally we tries to find existing user in database with the same username/password $userModel = new RM_Users(); $user = $userModel->getBy($request->getParam('username'), $request->getParam('password')); if ($user === null) { $this->_errors[] = 'WrongPassword'; $result = false; } } return $result; }
/** * 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))); } }
/** * 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'); } }
public function editJsonAction() { $json = new stdClass(); $id = $this->_getParam('id'); $dao = new RM_Users(); $user = $dao->getToGUI($id); $config = new RM_UserConfig(); $fields = $config->getEditFormByUser($user['group_id']); foreach ($fields as $field) { $jsonFields[] = $field->view_preferences; } // just get the selected UserType $groups = new RM_UserGroups(); $groupinfo = $groups->getAll(); $json = array("data" => "{ users : " . Zend_Json::encode($user->toArray()) . ", fields : [" . implode(',', $jsonFields) . "], groupinfo : " . Zend_Json::encode($groupinfo->toArray()) . "}", "encoded" => true); return $json; }
public function getreservationsJsonAction() { $unit_id = $this->_getParam('unitid'); $date = $this->_getParam('date'); // TODO: add admin selected language here:- $lang = RM_Environment::getInstance()->getLocale(); $reservations = new RM_Reservations(); $reservationDetails = $reservations->fetchAllByUnitDate($unit_id, $date, $lang); $jsonReservations = array(); $config = new RM_Config(); $usersObj = new RM_Users(); foreach ($reservationDetails as $reservation) { $jsonData = new stdClass(); $jsonData->reservation_id = $reservation->reservation_id; $jsonData->unit_id = $reservation->unit_id; $jsonData->start_date = $config->convertDates($reservation->start_datetime, RM_Config::PHP_DATEFORMAT, RM_Config::JS_DATEFORMAT); $jsonData->end_date = $config->convertDates($reservation->end_datetime, RM_Config::PHP_DATEFORMAT, RM_Config::JS_DATEFORMAT); $jsonData->total_price = $reservation->total_price; $jsonData->unit_name = $reservation->name; $jsonData->user_id = $reservation->user_id; if ($reservation->confirmed) { $confirmed = "<img src='" . RM_Environment::getConnector()->getRootURL() . "/RM/userdata/images/system/small/reservation_confirmed.png' border='0'>"; } else { $confirmed = "<img src='" . RM_Environment::getConnector()->getRootURL() . "/RM/userdata/images/system/small/reservation_unconfirmed.png' border='0'>"; } $jsonData->confirmed = $confirmed; $titleArray = str_replace(chr(39), chr(34), $this->_translate->_('Common.JSON', 'Titles')); $title = $usersObj->userTitle((int) $reservation->title, $titleArray); $jsonData->title = $title; $jsonData->first_name = $reservation->first_name; $jsonData->last_name = $reservation->last_name; $jsonReservations[] = clone $jsonData; } if (empty($jsonReservations)) { return array('data' => array('success' => false)); } $json = "{\n data : " . Zend_Json::encode($jsonReservations) . "\n }"; return array('data' => $json, 'encoded' => true); }
public function insertNewReservation($user, $unitDetails, $inprogres = 0, $confirmed = 1, $bookingRef = null) { //1. add information into rm_reservation if ($user->id) { $userID = $user->id; } else { // at this point the user does not exist in ResMania let's add it... $userData = array(); foreach ($user as $key => $value) { if ($key == 'name') { $nameArray = explode(" ", $value); $userData['first_name'] = $nameArray[0]; $userData['last_name'] = $nameArray[1] . " " . $nameArray[2]; } $userData[$key] = $value; } $userData['group_id'] = 0; unset($userData['id']); $rmUsers = new RM_Users(); $userID = $rmUsers->insert($userData); } $reservation = $this->createRow(); $reservation->user_id = $userID; $reservation->confirmed = $confirmed; $reservation->in_progress = $inprogres; // this will hide the reservation until we have completed the process if ($bookingRef !== null) { $reservation->id = $bookingRef; } $reservation->creation_datetime = date(RM_Config::MYSQL_DATEFORMAT); //current server datetime $reservationID = $reservation->save(); //2. add information into rm_reservation_details $detailsModel = new RM_ReservationDetails(); $priceSystem = RM_Environment::getInstance()->getPriceSystem(); foreach ($unitDetails as $unitDetail) { $detail = $detailsModel->createRow(); $selectedUnit = $unitDetail->getUnit(); // get the master unit if (class_exists("RM_Groups")) { $groupsObject = new RM_Groups(); $isMaster = $groupsObject->isMain($selectedUnit); if (!$isMaster) { $unitModel = new RM_Units(); $group = $groupsObject->getByUnit($selectedUnit); if ($group != null) { try { $groupID = $group->main_unit_id; $selectedUnit = $unitModel->get($groupID, RM_Environment::getInstance()->getLocale()); } catch (Exception $e) { } } } } $information = new RM_Prices_Information($selectedUnit, $unitDetail->getPeriod(), $unitDetail->getPersons(), $unitDetail->getOtherInfo()); try { $detail->total_price = $priceSystem->getTotalUnitPrice($information); } catch (Exception $e) { $detail->total_price = 0; } $detail->reservation_id = $reservationID; $detail->unit_id = $unitDetail->getUnit()->getId(); $detail->start_datetime = $unitDetail->getPeriod()->getStart()->toMySQL(); $detail->end_datetime = $unitDetail->getPeriod()->getEnd()->toMySQL(); $detail->adults = $unitDetail->getPersons()->getAdults() == 0 ? 1 : $unitDetail->getPersons()->getAdults(); $detail->children = $unitDetail->getPersons()->getChildren(); $detail->infants = $unitDetail->getPersons()->getInfants(); // process other information (this allows the price system to manage // other data i.e: board_types for the hospitality price module $otherInfo = $unitDetail->getOtherInfo(); if ($otherInfo) { foreach ($otherInfo as $key => $value) { $detail->{$key} = $value; } } $detail->save(); $this->_insertDetailExtraData($unitDetail, $detail); } return $reservationID; }