public function formAction() { $reservationDetails = RM_Reservation_Manager::getInstance()->getAllDetails(); $reservationsModel = new RM_Reservations(); $unitModel = new RM_Units(); $lang = RM_Environment::getInstance()->getLocale(); //$chargetotal = 0; $bookingref = RM_Reservation_Manager::getInstance()->getReservationID(); // create the description text $description = $bookingref . ": "; $count = 1; foreach ($reservationDetails as $details) { $unit = $details->getUnit(); $period = $details->getPeriod(); $unit_details = $unitModel->get($unit->getId(), $lang); $description .= $this->_translate->_('User.PayPal.Main', 'Selection') . " " . $count . "(" . $unit_details->name . " (" . $unit->getId() . ") " . $period->getStart() . " " . $this->_translate->_('User.PayPal.Main', 'To') . " " . $period->getEnd() . ")"; $count += 1; } $plugin = new RM_Plugin_PayPal(); $chargetotal = $plugin->getTotalPrice($reservationsModel->find($bookingref)->current()); RM_Reservation_Manager::getInstance()->setPaymentTotal($chargetotal); $provider = new RM_Plugin_PayPal(); $result = $provider->initialize($description, $bookingref, $chargetotal); $this->view->fields = $provider->getFields(); $this->view->paypal_url = $provider->getPaypalURL(); // return the json data so that the submit form can be rendered to pass this to paypal }
/** * Return name of the extra * * @param string $iso ISO code * @return string */ public function getName($iso = null) { if ($iso == null) { $iso = RM_Environment::getInstance()->getLocale(); } return $this->{$iso}; }
/** * This method for internal use, for checking translation * @example * administrator/index.php?option=com_resmania&act=Language&task=testJson&main=en&test=ru&type=rm_translate_main * it will combine 2 language no admin end and will check what language constants are in 'en' but not in 'ru' translation * the same method is also for user end */ public function testJsonAction() { ob_clean(); $type = $this->_getParam('type', RM_Environment::TRANSLATE_MAIN); $adapter = RM_Environment::getInstance()->getTranslation($this->_getParam('type', $type))->getAdapter(); $enMessages = $adapter->getMessages($this->_getParam('main', 'en_GB')); $ruMessages = $adapter->getMessages($this->_getParam('test', 'ru_RU')); $diffMessages = array(); foreach ($enMessages as $key => $value) { list($name, $section) = $this->_parseKey($key); if (isset($ruMessages[$key]) == false || $ruMessages[$key] == $enMessages[$key]) { if (isset($diffMessages[$section]) == false) { $diffMessages[$section] = array(); } $diffMessages[$section][$name] = $value; } } foreach ($diffMessages as $section => $messages) { echo "[" . $section . "] <br/>"; foreach ($messages as $key => $value) { echo "{$key}=\"\" ;" . $value . " <br/>"; } echo "<br/>"; } die; }
/** * Load translation data * * @param string|array $data * @param string $locale Locale/Language to add data for, identical with locale identifier, * see Zend_Locale for more information * @param array $options OPTIONAL Options to use */ protected function _loadTranslationData($data, $locale, array $options = array()) { if (isset($this->_data) == false) { $this->_data = array(); } if (!file_exists($data)) { return $this->_data; } $inidata = parse_ini_file($data, true); $options = array_merge($this->_options, $options); if ($options['clear'] == true || !isset($this->_data[$locale])) { $this->_data[$locale] = array(); } foreach ($inidata as $section => $data) { $moduleName = ucfirst(strtolower(RM_Environment::getConnector()->getModule())); $sectionChunks = explode('.', $section); if ($sectionChunks[0] != $moduleName && $sectionChunks[0] != self::$_commonSection && $sectionChunks[0] != self::$_globalSection) { continue; } foreach ($data as $key => $value) { $this->_data[$locale][$section . '.' . $key] = $value; } } return $this->_data; }
function validate(RM_Module_Config $config) { if (isset($config->information['name']) === false) { $translate = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_ERRORS); throw new RM_Exception($translate->_('RM.Module.Config.Validator', 'NoModuleName')); } return true; }
function getAllAssigned($language = null) { if ($language == null) { $language = RM_Environment::getInstance()->getLocale(); } $sql = "\r\n SELECT u.id, u." . $language . ", ut.type_id\r\n FROM rm_unit_types u\r\n JOIN rm_units ut\r\n "; return $this->_getBySQL($sql); }
public function getadminmapAction() { // do a quick net check $parsed = parse_url('http://maps.google.com/maps'); $host = $parsed["host"]; $fp = @fsockopen($host, 80, $errno, $errstr, 20); if (!$fp) { $this->view->error = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_ERRORS)->_('Admin.GMaps.Errors', 'ConnectionError'); } else { $this->view->error = 'false'; // get the unit information ob_clean(); $unitID = $this->_getParam('unit_id'); $locationsModel = new RM_Locations(); $location = $locationsModel->fetchByUnit($unitID)->toArray(); if (!empty($location)) { $location = $location[0]; // get the coordinates $coordinates = new stdClass(); // set default map center points... if (empty($location['longitude']) || empty($location['latitude'])) { $location['longitude'] = 150.644; $location['latitude'] = -34.397; } $coordinates->longitude = $location['longitude']; $coordinates->latitude = $location['latitude']; $this->view->coordinates = $coordinates; // construct the address for GMAPs to use $address = ""; if ($location['address1']) { $address .= $location['address1']; } if ($location['address2']) { $address .= ", " . $location['address2']; } if ($location['city']) { $address .= ", " . $location['city']; } if ($location['address1']) { $address .= ", " . $location['state']; } if ($location['address1']) { $address .= ", " . $location['postcode']; } if ($location['address1']) { $address .= ", " . $location['country']; } $this->view->address = $address; } // gmaps settings $settingsObj = new RM_GMaps(); $settings = $settingsObj->getSettings()->toArray(); $this->view->settings = $settings[0]; } // call the view echo $this->view->render('GMaps/adminmap.phtml'); die; }
/** * Form initialization * * @return void */ public function init() { $translate = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN); $this->setTranslator($translate); $this->setMethod('post'); $this->setDecorators(array('FormElements', array('TabContainer', array('id' => 'tabContainer', 'style' => 'width: 600px; height: 500px;', 'dijitParams' => array('tabPosition' => 'top'))), 'DijitForm')); $this->addElement('HorizontalSlider', 'horizontal', array('label' => 'HorizontalSlider', 'value' => 5, 'minimum' => -10, 'maximum' => 10, 'discreteValues' => 5, 'intermediateChanges' => true, 'showButtons' => true, 'topDecorationDijit' => 'HorizontalRuleLabels', 'topDecorationContainer' => 'topContainer')); $this->addElement('editor', 'content', array('plugins' => array('undo', '|', 'bold', 'italic'), 'editActionInterval' => 2, 'focusOnLoad' => true, 'height' => '250px', 'inheritWidth' => true, 'styleSheets' => array('/js/custom/editor.css'))); }
/** * @return string */ public function __toString() { $translate = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN); $value = $this->_getValue(); if (is_array($value)) { return sprintf($translate->_('Admin.Dependency', 'INIDependencyMultiple'), $this->_getName(), implode(", ", $value)); } else { return sprintf($translate->_('Admin.Dependency', 'INIDependency'), $this->_getName(), $value); } }
function getTitle($iso = null) { $titles = Zend_Json::decode(str_replace("'", '"', RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN)->_('Common.JSON', 'Titles'))); foreach ($titles as $title) { if ($this->title == $title['id']) { return $title['title']; } } return ''; }
private function _initTotalPrice() { $priceSystem = RM_Environment::getInstance()->getPriceSystem(); $information = new RM_Prices_Information($this->_unit, $this->_period, $this->_persons, $this->_otherInfo); try { $this->_total = $priceSystem->getTotalUnitPrice($information); } catch (Exception $e) { $this->_total = 0; } }
protected function _getUpgradeURL($extensionName) { $config = new RM_Config(); $licenseKey = $config->getValue('rm_config_licensekey'); if ($licenseKey == "") { return false; } $sourceFile = RM_Environment::getInstance()->getDistroURL() . "d.php?d=" . base64_encode('{"d": "' . $_SERVER['SERVER_NAME'] . '", "l": "' . $licenseKey . '", "v":"0", "p": "' . $extensionName . '", "qt": "validate"}'); return $sourceFile; }
/** * Return dependency object by it's database row representation * * @param RM_Dependency_Row $row * @return RM_Dependency_Abstract * @throw RM_Exception if dependency class name not exists */ private function _getDependencyInstance($row) { $type = $row->parent_type; $className = 'RM_Dependency_' . ucfirst(strtolower($type)); if (!class_exists($className)) { $translate = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN); throw new RM_Exception($translate->_('Admin.Dependencies', 'WrongDependencyClassName')); } return new $className($row); }
public function isRestricted(RM_Plugin_Row $plugin) { if ($plugin->module_name != $this->name) { return false; } $currentActive = $this->getAllPlugins(true)->count(); if ($plugin->enabled == 1 && $currentActive <= 1) { throw new RM_Exception(RM_Environment::getInstance()->getTranslation()->_('Admin.Payments.Restriction', 'LastError')); } return false; }
function validate(RM_Plugin_Config $config) { if (isset($config->information['name']) === false) { $translate = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_ERRORS); throw new RM_Exception($translate->_('RM.Plugin.Config.Validator', 'NoPluginName')); } //TODO: checkk all files that needed in zip folder //SQL install //SQL uninstall //Main class return true; }
public function saveCSSFile($data) { $cssPathArray = array("userdata", "css", "user_overrides.css"); $cssFilePath = $corePath = RM_Environment::getConnector()->getCorePath() . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $cssPathArray); $f = fopen($cssFilePath, 'w'); $result = fwrite($f, $data, strlen($data)); fclose($f); if (!$result) { return false; } return true; }
/** * Returns all translated periods. * * @param Zend_Translate $translate OPTIONAL If don't provide method will use default one from Zend_Registry * @return array */ public static function getAllTranslated($translate = null) { if ($translate == null) { $translate = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN); } $section = self::languageSection; $result = array(); foreach (self::$periods as $id => $name) { $result[$id] = $translate->_($section, $name); } return $result; }
/** * This method internally return total reservation due for payment * There could be a deposit system installed and enabled * * @deprecated * @param RM_Reservation_Row $reservation * @return float */ public function getTotalPrice(RM_Reservation_Row $reservation) { $totalPrice = $reservation->getTotalPrice(); $depositSystem = RM_Environment::getInstance()->getDepositSystem(); if ($depositSystem == null) { return $totalPrice; } if ($depositSystem->isDepositUsedFor($reservation->id)) { return $depositSystem->calculate($totalPrice); } return $totalPrice; }
/** * Returns array of translated error messages * * @param array $errors * @param string $locale * @return array */ public function getErrorMessages($errors, $locale = null) { $errorMessages = array(); $translate = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_ERRORS); if (!is_array($errors)) { $errors = array($errors); } foreach ($errors as $errormsg) { $errorMessages[] = $translate->_('User.Form.' . ucfirst($this->id) . '.Validation', $errormsg, $locale); } return $errorMessages; }
function listallAction() { ob_clean(); $uid = $this->_getParam('uid'); $unitModel = new RM_Units(); $language = RM_Environment::getInstance()->getLocale(); $unit = $unitModel->get($uid, $language); $priceObj = new RM_UnitDailyPrices(); $prices = $priceObj->getCurrent($unit)->toArray(); $this->view->unit = $unit; $this->view->prices = $prices; echo $this->view->render('DailyPrices/listall.phtml'); die; }
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(); } }
/** * 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; }
/** * Recalculate all reservation extras information. Important!!! * this method need to be extended if we will add some other system that are affected reservation price. */ public function recalculate() { $extrasSystems = RM_Environment::getInstance()->getExtrasSystems(); foreach ($extrasSystems as $extrasSystem) { $extrasSystem->recalculate($this); } $othersSystems = RM_Environment::getInstance()->getOthersSystems(); foreach ($othersSystems as $othersSystem) { $othersSystem->recalculate($this); } $discountsSystems = RM_Environment::getInstance()->getDiscounts(); foreach ($discountsSystems as $system) { $system->recalculate($this); } RM_Environment::getInstance()->getTaxSystem()->recalculate($this); }
/** * this returns the saved price information for a reservation * * @param string $reservationID * @return object a complete price breakdown. */ public function getPrice($reservationID) { // TODO: we will need to add code to dynamically check modules and plugins that // have code that adds prices/charges in order to dynamcially check any saved // prices that have been charged to customers if (!isset($reservationID)) { return false; } $reservationModel = new RM_Reservations(); $reservation = $reservationModel->find($reservationID)->current(); $priceObj = new stdClass(); $priceObj->tax = RM_Environment::getInstance()->getTaxSystem()->getTotalTaxes($reservation); $priceObj->total = $reservation->getTotalPrice(); $priceObj->subtotal = $priceObj->total - $priceObj->tax; return $priceObj; }
private static function _load($locale) { $filename = RM_Environment::getConnector()->getCorePath() . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . "locations.ini"; if (!is_file($filename)) { return false; } $locations = parse_ini_file($filename, true); $result = array(); foreach ($locations as $isoName => $cities) { list($iso, $name) = explode('.', $isoName); $result[$iso]['iso'] = $iso; $result[$iso]['name'] = $name; $result[$iso]['cities'] = array(); $result[$iso]['cities'] = $cities; } return $result; }
/** * Parsed ini file into config object * * @param string $filepath Physical path to ini config file * @return RM_Language_Config * @throws RM_Exception If ini file have wrong format or validation fails */ function getConfig($filepath) { $configArray = parse_ini_file($filepath); if ($configArray === false) { $translate = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_ERRORS); throw new RM_Exception($translate->_('RM.Language.Config.Parser', 'InvalidIniFileFormat')); } $config = new RM_Language_Config(); foreach ($configArray as $key => $value) { $config->{$key} = $value; } if ($config->validate() == false) { $translate = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_ERRORS); throw new RM_Exception($translate->_('RM.Language.Config.Parser', 'InvalidIniFileFormat')); } return $config; }
public static function toLog($message, $level = Zend_Log::INFO, $file = 'system_log.txt') { $filename = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getCorePath(), 'userdata', 'logs', $file)); if (is_file($filename) == false) { return false; } if (is_writable($filename) == false) { return false; } try { $stream = new Zend_Log_Writer_Stream($filename); $logger = new RM_Log($stream); $logger->log($message, $level); $stream->shutdown(); return true; } catch (Exception $e) { return false; } }
/** * Calculate * * @param RM_Discounts_Row $row * @param float $amount * @return float */ public function calculate(RM_Reservation_Details $detail) { $discountPeriod = $this->_discount->getPeriod(); $totalDiscount = 0; $discountPercentage = $this->_discount->amount; $priceSystem = RM_Environment::getInstance()->getPriceSystem(); try { $priceDays = $priceSystem->getTotalUnitPrice(new RM_Prices_Information($detail->getUnit(), $detail->getPeriod(), $detail->getPersons()), true); } catch (RM_Exception $e) { $priceDays = 0; } foreach ($priceDays as $day) { if ($discountPeriod->isInternal($day['step'])) { $discountedPrice = $day['price']; $totalDiscount += $day['price'] / 100 * $discountPercentage; } } return RM_Environment::getInstance()->roundPrice($totalDiscount); }
public function listJsonAction() { $offset = $this->_getParam('start'); $count = $this->_getParam('limit'); $sort = $this->_getParam('sort', 'id'); $direction = $this->_getParam('dir', 'DESC'); $filters = $this->_getParam('filter', array()); $order = $sort . ' ' . $direction; $dao = new RM_Modules(); $total = $dao->filterAll($order, null, null, $filters)->count(); $rows = $dao->filterAll($order, $count, $offset, $filters)->toArray(); $extensions = RM_Environment::getInstance()->getOutOfDateExtensions(); foreach ($rows as $key => $row) { $rows[$key]['upgrade'] = in_array($row['name'], $extensions['modules']); } $json = new stdClass(); $json->total = $total; $json->data = $rows; return array('data' => $json); }
function getpriceJsonAction() { $unitIDs = $this->_getParam('ids'); $start_datetime = $this->_getParam('start_datetime'); $end_datetime = $this->_getParam('end_datetime'); $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)); $unitsDAO = new RM_Units(); $stardateObj = new RM_Date(strtotime($start_datetime)); $enddateObj = new RM_Date(strtotime($end_datetime)); $periodObj = new RM_Reservation_Period($stardateObj, $enddateObj); $priceSystem = RM_Environment::getInstance()->getPriceSystem(); $units = explode(",", $unitIDs); $taxSystem = RM_Environment::getInstance()->getTaxSystem(); $tax = 0; foreach ($units as $uid) { $unitObj = $unitsDAO->get($uid); $information = new RM_Prices_Information($unitObj, $periodObj, $persons); try { $subtotal = $subtotal + $priceSystem->getTotalUnitPrice($information); } catch (Exception $e) { // no return needed } $tax += $taxSystem->calculateTotalTax($unitObj, $subtotal); } // get currency symbol $config = new RM_Config(); $currency_symbol = $config->get('rm_config_currency_symbol'); // calculate the total $total = $subtotal + $tax; return array('data' => '{ data: [{ info: "Subtotal", value: "' . $currency_symbol['rm_config_currency_symbol'] . ' ' . $subtotal . '" },{ info: "Tax", value: "' . $currency_symbol['rm_config_currency_symbol'] . ' ' . $tax . '" },{ info: "Total", value: "' . $currency_symbol['rm_config_currency_symbol'] . ' ' . $total . '" }] }', 'encoded' => true); }