public function autoupgradeJsonAction() { $json = new stdClass(); $json->success = 1; $json->msg = array(); $config = new RM_Config(); $licenseKey = $config->getValue('rm_config_licensekey'); if ($licenseKey == "") { $json->success = 0; $json->msg[] = "License Key Not Entered"; return array('data' => $json); } $ids = $this->_getParam('ids', array()); $manager = new RM_Module_Manager($this->_translate); try { $dao = new RM_Modules(); foreach ($ids as $id) { $row = $dao->find($id)->current(); $manager->autoUpgrade($row, $json); } } catch (Exception $e) { $json->success = 0; $json->msg[] = $e->getMessage(); } return array('data' => $json); }
/** * Returns extra HTML for a summary reservation page to present current system * * @abstract * @param RM_Reservation_Details $detail * @return string HTML code to paste */ public function getSummary(RM_Reservation_Details $detail) { $model = new RM_Extras(); $extras = $model->getByUnit($detail->getUnit()); if (0 == $extras->count()) { return ""; } // tax $taxSystem = RM_Environment::getInstance()->getTaxSystem(); $taxes = $taxSystem->getAllTaxes($detail->getUnit()); $request = RM_Environment::getConnector()->getRequestHTTP(); $request->setControllerName('Extras'); $request->setActionName('summary'); $controller = new RM_User_ExtrasController($request, new Zend_Controller_Response_Http()); $controller->setFrontController(Zend_Controller_Front::getInstance()); $controller->view->unit = $detail->getUnit(); $config = new RM_Config(); $controller->view->currencySymbol = $config->getValue('rm_config_currency_symbol'); $translate = RM_Environment::getInstance()->getTranslation(); $extraTypes = array('day' => $translate->_('User.Extras.Type', 'Day'), 'percentage' => $translate->_('User.Extras.Type', 'Percentage'), 'single' => $translate->_('User.Extras.Type', 'Single')); $viewExtras = array(); foreach ($extras as $extra) { $extraTotal = RM_Environment::getInstance()->roundPrice($extra->calculateBy($detail->getTotal(), $detail->getPeriod()->getSeconds())); // calculate the tax due on the extra... $taxTotal = 0; foreach ($taxes as $tax) { $taxTotal = $taxTotal + $tax->calculate($extraTotal, $detail); } // $extraTotal = $extraTotal + $taxTotal; $viewExtras[] = array('id' => $extra->id, 'name' => $extra->getName(), 'type' => $extraTypes[$extra->type], 'value' => $extraTotal, 'tax' => $taxTotal, 'max' => $extra->max, 'min' => $extra->min); } $controller->view->extras = $viewExtras; return $controller->view->render('Extras/summary.phtml'); }
function datepickerAction() { ob_clean(); $unitID = $this->_getParam('unit_id', null); $unitModel = new RM_Units(); $unit = $unitModel->get($unitID); $reservationModel = new RM_Reservations(); $reservations = $reservationModel->fetchAllForUnitCalendar($unit); $config = new RM_Config(); $RMdate = new RM_Date(); $jsonDisabledPeriods = new stdClass(); $jsonDisabledPeriods->start = array(); $jsonDisabledPeriods->end = array(); foreach ($reservations as $period) { $jsonPeriod = new stdClass(); $jsonPeriod->start = $config->convertDates($period->start_datetime, RM_Config::JS_DATEFORMAT, RM_Config::PHP_DATEFORMAT); $jsonPeriod->end = $config->convertDates($period->end_datetime, RM_Config::JS_DATEFORMAT, RM_Config::PHP_DATEFORMAT); // store the start date picker blocked periods $jsonDisabledPeriods->start[] = clone $jsonPeriod; $jsonPeriod->start = $RMdate->dateAdd($config->convertDates($period->start_datetime, RM_Config::JS_DATEFORMAT, RM_Config::PHP_DATEFORMAT), 1); $jsonPeriod->end = $RMdate->dateAdd($config->convertDates($period->end_datetime, RM_Config::JS_DATEFORMAT, RM_Config::PHP_DATEFORMAT), 1); $jsonDisabledPeriods->end[] = clone $jsonPeriod; } $json = Zend_Json::encode($jsonDisabledPeriods); $this->view->calendardata = $json; $this->view->unit_id = $unitID; echo $this->view->render('DailyPrices/datepicker.phtml'); die; }
/** * Get the plugins CSS and combine these */ public function getPluginCSS() { $cacheDir = RM_Environment::getConnector()->getRootPath() . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'css'; if (is_dir($cacheDir) == false) { $rmConfig = new RM_Config(); $chmodOctal = intval($rmConfig->getValue('rm_config_chmod_value'), 8); mkdir($cacheDir, $chmodOctal); } $cachedCSS = file_exists($cacheDir . DIRECTORY_SEPARATOR . "plugins.css"); if (!$cachedCSS) { $newfileContents = ""; $pluginsDAO = new RM_Plugins(); $plugins = $pluginsDAO->fetchAllEnabled(); $config = new RM_plugin_Config(); foreach ($plugins as $plugin) { $files = RM_plugin_Manager::getCssFiles($plugin->name); foreach ($files as $file) { // read in the css and change the relative paths then add to a cached css file that we will load $fileContents = file_get_contents(RM_Environment::getConnector()->getRootURL() . "RM/userdata/plugins/" . $plugin->name . "/" . RM_Module_Config::CSS . '/' . $file); $search = "/url\\(([^\\)]*)\\)/"; $replace = "url(../../../userdata/plugins/" . $plugin->name . "/images/\$1)"; $newfileContents .= preg_replace($search, $replace, $fileContents); } } $this->_saveCachedCSS($newfileContents, $cacheDir . DIRECTORY_SEPARATOR . "plugins.css"); } // return the cached CSS url so it can be included return RM_Environment::getConnector()->getRootURL() . "RM/userdata/temp/css/plugins.css"; }
public function postDispatch() { parent::postDispatch(); $config = new RM_Config(); if ($config->getValue('rm_config_show_poweredby_logo') === '1') { $this->writePoweredByIcon(); } }
/** * Create folder for media files * * @param int $unitID - unit primary key value * @return bool success or failure; */ function createFolder() { // get config values $rmConfig = new RM_Config(); $chmodOctal = intval($rmConfig->getValue('rm_config_chmod_value'), 8); $folder = $this->getFolder(); return mkdir($folder, $chmodOctal, true); }
/** * Returns PHP dateformat to present reservation start and end date on the UI * * @param bool $php - internal PHP date format or UI date format, if true - internal PHP date format * @return string */ public function getDateformat($php = false) { if ($php) { return RM_Config::MYSQL_DATEFORMAT_SHORT; } $config = new RM_Config(); return $config->getJSDateformat(); }
/** * Contructor * */ public function __construct() { // get settings $config = new RM_Config(); $this->_enabled = $config->getValue('rm_config_recaptcha_enabled'); $this->_useSSL = $config->getValue('rm_config_recaptcha_ssl'); $this->_publickey = $config->getValue('rm_config_recaptcha_publickey'); $this->_privatekey = $config->getValue('rm_config_recaptcha_privatekey'); }
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; }
public function convertToGUI($data) { $info = $this->info(); foreach ($info['metadata'] as $column) { switch ($column['DATA_TYPE']) { case 'datetime': case 'date': $config = new RM_Config(); $data[$column['COLUMN_NAME']] = $config->convertDates($data[$column['COLUMN_NAME']], RM_Config::MYSQL_DATEFORMAT, RM_Config::JS_DATEFORMAT); break; } } return $data; }
protected function _init() { $this->_period = RM_Reservation_Period::getDefault(); if ($this->_criteria->start_datetime && $this->_criteria->end_datetime) { $this->_isDefaultPeriod = false; $this->_period = new RM_Reservation_Period(new RM_Date(strtotime($this->_criteria->start_datetime)), new RM_Date(strtotime($this->_criteria->end_datetime))); } $this->_persons = new RM_Reservation_Persons(array("adults" => $this->_criteria->adults, "children" => $this->_criteria->children, "infants" => $this->_criteria->infants)); $config = new RM_Config(); $this->_showPriceWithTax = (bool) $config->getValue('rm_config_prices_with_tax'); if ($this->_showPriceWithTax) { $this->_taxSystem = RM_Environment::getInstance()->getTaxSystem(); } }
/** * 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; }
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); }
/** * @see system/libs/Zend/Controller/Zend_Controller_Action#preDispatch() */ public function preDispatch() { $this->view->setTranslate(RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN)); $this->_translate = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN); $this->view->setRouter($this->getFrontController()->getRouter()); $config = new RM_Config(); $this->view->guiDateFormat = $config->getJSDateformat(); $this->view->GUIMaximisedState = $config->getValue("rm_config_admin_gui_maximised"); $this->view->mysqlDateFormat = RM_Config::MYSQL_DATEFORMAT; $this->view->phpDateFormat = RM_Config::PHP_DATEFORMAT; $this->view->calStartDay = $config->getValue("rm_config_calendar_startday"); $this->view->CMSIntegration = $config->getValue("rm_config_enable_cms_integration"); $this->view->enableUserGroups = $config->getValue("rm_config_enable_user_groups"); $this->view->enableUnitsOnTreeMenu = $config->getValue("rm_config_enable_units_on_treemenu"); $this->view->reservationsListBufferSize = $config->getValue("rm_config_reservations_list_buffersize"); $this->view->editorType = $config->getValue("rm_config_editor"); }
/** * Create and return new user row from information from reguest. * This method is not saving row objcet into database. * * @param Zend_Request_Interface $request * @param int $groupID [optional] default RM_UserGroups::REGULAR * @param bool $resmania - if true force system to create resmania user instead of cms user */ function createNewUser($request, $groupID = RM_UserGroups::REGULAR, $resmania = false) { $fields = $this->_getFieldsByGroup($groupID); $notRequestFields = array('group_id', 'cms_id'); $data = array(); $data['group_id'] = $groupID; foreach ($fields as $field) { if ($field->view_new == '1' && in_array($field->column_name, $notRequestFields) === false) { $data[$field->column_name] = $request->getParam($field->column_name); } } $config = new RM_Config(); if ($config->getValue('rm_config_enable_cms_user_creation') && $resmania == false) { $connectorObj =& RM_Environment::getConnector(); $users = $connectorObj->getUsersModel(); $userInfo = $users->createRow($data); } else { $userInfo = $this->createRow($data); } return $userInfo; }
/** * Copy folder recursive (with all sub folders and files) * * @params string $source - the source folder * @params string $destination - the destination folder * @params array $skipSources - [optional][default=array()] array of relative paths (from RM root) of * files and folders that need to be skipped while copy process * @return bool */ public function recursivecopy($source, $destination, &$skipSources = array()) { $return = true; $rmConfig = new RM_Config(); $chmodOctal = intval($rmConfig->getValue('rm_config_chmod_value'), 8); $dir = dir($source); while (false !== ($entry = $dir->read())) { if ($entry == '.' || $entry == '..') { continue; } $fullPathDestination = $destination . DIRECTORY_SEPARATOR . $entry; $skipped = false; foreach ($skipSources as $skipSource) { if (strpos($fullPathDestination, $skipSource) !== false) { $skipped = true; break; } } if ($skipped) { continue; } $fullPathEntry = $source . DIRECTORY_SEPARATOR . $entry; if (is_file($fullPathEntry)) { $return &= copy($fullPathEntry, $fullPathDestination); } elseif (is_link($fullPathEntry)) { $return &= symlink(readlink($fullPathEntry), $fullPathDestination); } elseif (is_dir($fullPathEntry)) { if (!is_dir($fullPathDestination)) { $return &= mkdir($fullPathDestination); chmod($fullPathDestination, $chmodOctal); // allows deletion via ftp } // Deep copy directories using recursion $return &= $this->recursivecopy($fullPathEntry, $fullPathDestination, $skipSources); } } $dir->close(); return $return; }
public function toString() { $config = new RM_Config(); return $config->getValue('rm_config_currency_symbol') . $this->_discount->amount; }
/** * Delete language with all information * * @param request iso */ public function deleteJsonAction() { $iso = $this->_getParam('iso'); $model = new RM_Languages(); $language = $model->find($iso)->current(); if ($language == null) { continue; } // set back to default language $model = new RM_Config(); $configData = $model->fetchAll(); foreach ($configData as $data) { if ($data->id == 'rm_config_language_default_back') { $data->value = "cms"; $data->save(); } if ($data->id == 'rm_config_language_default_front') { $data->value = "cms"; $data->save(); } } $manager = new RM_Language_Manager(); $manager->deleteLanguage($iso); return array('data' => array('success' => true)); }
/** * Updates configuration. * * @param request all values this values for the config update * @return json boolean response of true or false in json format (true is success) */ function updateJsonAction() { $model = new RM_Config(); $fields = $model->fetchAll(); foreach ($fields as $field) { switch ($field->xtype) { case "checkbox": $value = $this->_getParam($field->id); break; default: $value = $this->_getParam($field->id, $this->_getParam($field->id . "_hidden")); } if ($value !== null) { $field->value = $value; $field->save(); } } // process image resizing if ($this->_getParam('image_resize', 0) == 1) { //1. resize images for media, if we will later add extra options for admin thumnails //$mediaManager = new RM_Media_Manager(); //$mediaManager->resize(); //2. resize images for units $unitModel = new RM_Units(); $units = $unitModel->fetchAll(); foreach ($units as $unit) { $unitMediaManager = new RM_Media_Unit_Manager($unit); $unitMediaManager->resize(); } } return array('data' => array('success' => true)); }
public function listhtmlJsonAction() { $reservationID = $this->_getParam('id', null); if ($reservationID == null) { return array('data' => array('success' => false)); } $reservationModel = new RM_Reservations(); $reservation = $reservationModel->find($reservationID)->current(); if ($reservation == null) { return array('data' => array('success' => false)); } $unitModel = new RM_Units(); $reservationDetails = $reservation->getDetails(); $reservationDetailsJson = array(); foreach ($reservationDetails as $reservationDetail) { $unit = $reservationDetail->findUnit(); $extrasModel = new RM_Extras(); $extras = $extrasModel->getByUnit($unit); if ($extras->count() == 0) { continue; } $config = new RM_Config(); $currencySymbol = $config->getValue('rm_config_currency_symbol'); // tax $taxSystem = RM_Environment::getInstance()->getTaxSystem(); $taxes = $taxSystem->getAllTaxes($unit); // we need to create a new reservation details object so that the tax can be calculated $periodObj = new RM_Reservation_Period(new RM_Date(strtotime($reservationDetail->start_datetime)), new RM_Date(strtotime($reservationDetail->end_datetime))); $persons = new RM_Reservation_Persons(array("adults" => $reservationDetail->adults, "children" => $reservationDetail->children, "infants" => $reservationDetail->infants)); $fullReservationDetails = new RM_Reservation_Details($unit, $periodObj, $persons, array()); $summaryModel = new RM_ReservationSummary(); $extrasJson = array(); foreach ($extras as $extra) { // calculate the tax due on the extra... $extraSubTotal = $extra->calculate($reservationDetail); $taxTotal = 0; foreach ($taxes as $tax) { $taxTotal = $taxTotal + $tax->calculate($extraSubTotal, $fullReservationDetails); } $extraSubTotal = $extraSubTotal + $taxTotal; $extraJson = new stdClass(); $extraJson->id = $extra->id; $extraJson->name = $extra->getName(RM_Environment::getInstance()->getLocale()); $extraJson->min = (int) $extra->min; $extraJson->max = (int) $extra->max; $extraJson->type = RM_Environment::getInstance()->getTranslation()->_('Admin.Extras.Type', ucfirst($extra->type)); $extraJson->price = $currencySymbol . $extraSubTotal; $reservationDetailsExtra = $summaryModel->getByDetail($reservationDetail, RM_Module_Extras::SUMMARY_TYPE, $extra->id); if ($reservationDetailsExtra == null) { $extraJson->saved_price = $currencySymbol . '0'; $extraJson->value = 0; } else { $extraJson->saved_price = $currencySymbol . $reservationDetailsExtra->total_amount; $extraJson->value = (int) $reservationDetailsExtra->value; } $extrasJson[] = $extraJson; } $unit = $unitModel->get($reservationDetail->unit_id); if ($unit == null) { $unitName = "DELETED"; } else { $unitName = $unit->name; } $priceSystem = RM_Prices_Manager::getInstance()->getRealPriceSystem($unit); $reservationDetailJson = new stdClass(); $reservationDetailJson->id = $reservationDetail->id; $reservationDetailJson->extras = $extrasJson; $reservationDetailJson->unit_id = $reservationDetail->unit_id; $reservationDetailJson->unit_name = $unitName; $reservationDetailJson->start = $reservationDetail->getStartDatetime($priceSystem->getDateformat(true)); $reservationDetailJson->end = $reservationDetail->getEndDatetime($priceSystem->getDateformat(true)); $reservationDetailJson->subtotal = $reservationDetail->total_price; $reservationDetailsJson[] = $reservationDetailJson; } $json = new stdClass(); $json->details = $reservationDetailsJson; return array('data' => $json); }
/** * Returns latest extensions versions in format: * array( * modules => * [ <module name> => '<version number in std php format>' ] * plugins => * [ <plugin name> => '<version number in std php format>' ] * ) * or null is connection to server is lost * * @return array|null */ public function getExtensionVersions() { $frontendName = 'Core'; $frontendOptions = array(); $frontendOptions['lifetime'] = Zend_Registry::get('config')->get('cache')->get('lifetime'); $frontendOptions['automatic_serialization'] = true; $backendName = 'File'; $backendOptions = array(); $cacheDir = self::getConnector()->getRootPath() . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'extensions'; if (is_dir($cacheDir) == false) { $rmConfig = new RM_Config(); $chmodOctal = intval($rmConfig->getValue('rm_config_chmod_value'), 8); mkdir($cacheDir, $chmodOctal); } $backendOptions['cache_dir'] = $cacheDir; $backendOptions['file_name_prefix'] = 'rm_extensions_cache'; $cacheName = 'versions'; $cache = Zend_Cache::factory($frontendName, $backendName, $frontendOptions, $backendOptions); if ($config = $cache->load($cacheName)) { return $config; } $configJson = @file_get_contents($this->_extensionVersionURL); try { if (isset($configJson) && $configJson !== false) { $config = Zend_Json::decode($configJson, Zend_Json::TYPE_ARRAY); $cache->save($config, $cacheName); return $config; } else { return null; } } catch (Exception $e) { return null; } }
/** * 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'); } }
/** * Method to get a string representation of this object * * @param RM_Taxes_Row $taxRow * @param float $amount */ public function toString(RM_Taxes_Row $taxRow) { $config = new RM_Config(); return $config->getValue('rm_config_currency_symbol') . $taxRow->amount; }
public function listresJsonAction() { $id = $this->_getParam('id'); $config = new RM_Config(); // used for date conversion $model = new RM_Reservations(); $Users_Reservation_Total = $model->fetchAllByUserID($id)->count(); $Users_Reservation_Info = $model->fetchAllByUserID($id)->toArray(); $jsonReservations = array(); $reservationDetailsModel = new RM_ReservationDetails(); foreach ($Users_Reservation_Info as $reservation) { $tempVal->reservation_id = $reservation['reservation_id']; $tempVal->unit_id = $reservation['unit_id']; //TODO: We need to convert this to a meaningful word ie: unitname (ID:X) $tempVal->start_date = $config->convertDates($reservation['start_datetime'], RM_Config::MYSQL_DATEFORMAT, RM_Config::JS_DATEFORMAT); $tempVal->end_date = $config->convertDates($reservation['end_datetime'], RM_Config::MYSQL_DATEFORMAT, RM_Config::JS_DATEFORMAT); $jsonReservations[] = clone $tempVal; } $ret = array("data" => '{"total": ' . $Users_Reservation_Total . ', "data" : ' . Zend_Json::encode($jsonReservations) . '}', 'encoded' => true); return $ret; }
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()); }
/** * Initialize internal state of the paypal class * * @param string $invoiceNumber * @param string $description - the text description for the payment * @param string $total - the total amount to be charged * @throw RM_Exception * @return void */ public function initialize($invoiceNumber, $description, $total) { $config = $this->_getConfig(); if (!$config) { //TODO: add language constant throw new RM_Exception('No PayPal config defined.'); } $configModel = new RM_Config(); $currencyISO = $configModel->getValue('rm_config_currency_iso'); $this->_addField('business', $config['account']); $this->_addField('notify_url', RM_Environment::getInstance()->getRouter()->_('PayPal_External', 'ipn')); $this->_addField('item_name', $description); $this->_addField('invoice', $invoiceNumber); $this->_addField('currency_code', $currencyISO); $this->_addField('amount', $total); }
/** * Full installation process of plugin * * @param string $tempFileName * @param string $tempFilePath * @param stdclass $json * @return stdclass */ function install($tempFileName, $tempFilePath, $json) { // get config values $rmConfig = new RM_Config(); $chmodOctal = intval($rmConfig->getValue('rm_config_chmod_value'), 8); $rootPath = RM_Environment::getConnector()->getRootPath(); $chunks = explode('.', $tempFileName); $pluginName = $chunks[0]; //Plugin name will be always the first chunk, example: price.0.1.1.zip $pluginModel = new RM_Plugins(); $existingPlugin = $pluginModel->fetchByName($pluginName); if ($existingPlugin !== null) { unlink($tempFilePath); throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'PluginAlreadyInstalled')); } $pluginFolderPath = $rootPath . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $pluginName; if (is_dir($pluginFolderPath)) { $result = RM_Filesystem::deleteFolder($pluginFolderPath); if ($result == false) { unlink($tempFilePath); throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'PluginFolderAlreadyExists') . ': ' . $pluginFolderPath); } } $result = mkdir($pluginFolderPath, $chmodOctal); if ($result == false) { unlink($tempFilePath); throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'CreatePluginFolderFailer')); } else { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.InstallMsg', 'PluginFolderCreatedSuccessfully')); } //4. unzip plugin into new directory if (!extension_loaded('zlib')) { unlink($tempFilePath); RM_Filesystem::deleteFolder($pluginFolderPath); throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'ZlibNotSupported')); } $zip = new PclZip($tempFilePath); $result = $zip->extract(PCLZIP_OPT_PATH, $pluginFolderPath); if (!$result) { unlink($tempFilePath); RM_Filesystem::deleteFolder($pluginFolderPath); throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'UnzipFailed')); } else { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.InstallMsg', 'UnzipSuccessfully')); } unlink($tempFilePath); chmod($pluginFolderPath, $chmodOctal); //4.0. create separate folder in 'userdata/plugins' for a new plugin $userdataFolderPath = $rootPath . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $pluginName; if (is_dir($userdataFolderPath)) { $result = RM_Filesystem::deleteFolder($userdataFolderPath); if ($result == false) { throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'PluginFolderAlreadyExists') . ': ' . $userdataFolderPath); } } $result = mkdir($userdataFolderPath . DIRECTORY_SEPARATOR, $chmodOctal); if ($result == false) { RM_Filesystem::deleteFolder($pluginFolderPath); throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'CreatePluginUserdataFolderFailer')); } else { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.InstallMsg', 'PluginFolderCreatedSuccessfully')); } @rename($pluginFolderPath . DIRECTORY_SEPARATOR . 'views', $userdataFolderPath . DIRECTORY_SEPARATOR . 'views'); @chmod($pluginFolderPath . DIRECTORY_SEPARATOR . 'views', $chmodOctal); @rename($pluginFolderPath . DIRECTORY_SEPARATOR . 'languages', $userdataFolderPath . DIRECTORY_SEPARATOR . 'languages'); @chmod($pluginFolderPath . DIRECTORY_SEPARATOR . 'languages', $chmodOctal); @rename($pluginFolderPath . DIRECTORY_SEPARATOR . 'css', $userdataFolderPath . DIRECTORY_SEPARATOR . 'css'); @chmod($pluginFolderPath . DIRECTORY_SEPARATOR . 'css', $chmodOctal); @rename($pluginFolderPath . DIRECTORY_SEPARATOR . 'images', $userdataFolderPath . DIRECTORY_SEPARATOR . 'images'); @chmod($pluginFolderPath . DIRECTORY_SEPARATOR . 'images', $chmodOctal); @chmod($userdataFolderPath, $chmodOctal); //5. get INI file $iniFilePath = $pluginFolderPath . DIRECTORY_SEPARATOR . self::$_iniFilename; if (is_file($iniFilePath) == false) { RM_Filesystem::deleteFolder($pluginFolderPath); throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'NoIniFile')); } //6. parse INI file $parser = new RM_Plugin_Config_Parser(); try { $config = $parser->getConfig($iniFilePath); } catch (RM_Exception $e) { //Error in ini file parsing RM_Filesystem::deleteFolder($pluginFolderPath); throw new RM_Exception($e->getMessage()); } //Check: could be a module if no 'module' value is in config if ($config->information['module'] == "") { RM_Filesystem::deleteFolder($pluginFolderPath); throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'WrongTryToInstallModule')); } $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.InstallMsg', 'UnzipSuccess')); //7. invoke SQL install file try { $result = self::installDatabase($pluginFolderPath); } catch (Exception $e) { self::uninstallDatabase($pluginFolderPath); RM_Filesystem::deleteFolder($pluginFolderPath); throw new RM_Exception($e->getMessage()); } if ($result == false) { self::uninstallDatabase($pluginFolderPath); RM_Filesystem::deleteFolder($pluginFolderPath); throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'WrongInstallSQLQueries')); } else { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.InstallMsg', 'InstallSQLSuccess')); } //8. create a new record in Plugin database $pluginRow = array(); $pluginRow = $config->information; $pluginRow['module_name'] = $pluginRow['module']; unset($pluginRow['module']); //convert creation date into MySQL format $rmConfig = new RM_Config(); $pluginRow['creation_date'] = $rmConfig->convertDates(strtotime($pluginRow['creation_date']), RM_Config::TIMESTAMP_DATEFORMAT, RM_Config::MYSQL_DATEFORMAT); //TODO: //1.check the insertions $pkey = $pluginModel->insert($pluginRow); //Create a new records in dependencies database table $model = new RM_Dependencies(); if (is_array($config->dependencies)) { foreach ($config->dependencies as $dependency) { $model->insert($dependency); } } //9. get the main class of the plugin $pluginClassFilepath = $pluginFolderPath . DIRECTORY_SEPARATOR . RM_Plugin_Config::CLASSES . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'Plugin' . DIRECTORY_SEPARATOR . $config->information['name'] . '.php'; if (is_file($pluginClassFilepath) == false) { self::uninstallDatabase($pluginFolderPath); RM_Filesystem::deleteFolder($pluginFolderPath); throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'DoesntExists')); } require_once $pluginClassFilepath; $pluginClassName = 'RM_Plugin_' . $config->information['name']; if (class_exists($pluginClassName) == false) { self::uninstallDatabase($pluginFolderPath); RM_Filesystem::deleteFolder($pluginFolderPath); throw new RM_Exception($pluginClassName . $this->_translate->_('Admin.Plugins.InstallMsg', 'DoesntExists')); } $pluginObject = new $pluginClassName(); if (!$pluginObject instanceof RM_Plugin_Interface) { self::uninstallDatabase($pluginFolderPath); RM_Filesystem::deleteFolder($pluginFolderPath); throw new RM_Exception($pluginClassName . $this->_translate->_('Admin.Plugins.InstallMsg', 'WrongInterface')); } //10. invoke install method of that class (if we need something extra) $result = $pluginObject->install(); $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.InstallMsg', 'InstallSuccess')); //Check dependencies and if some of them is validate==false disable plugin $dependencyManager = new RM_Dependency_Manager(); $plugin = $pluginModel->find($pkey)->current(); $dependencies = $dependencyManager->getDependencies($plugin); foreach ($dependencies as $dependency) { if ($dependency->validate() == false) { try { $pluginModel->disable($plugin); break; } catch (Exception $e) { //TODO: add log message that we could not disable this module. } } } return $json; }
/** * Return JSON data for the chart * * @return string */ function getData() { $config = new RM_Config(); $units = $this->_getUnits(); $datetimes = $this->_getDatetimes(); $reservationDetailsModel = new RM_ReservationDetails(); // for fusion charts we need xml, so the data needs to be formatted // so that the json data can render the xml using an xtemplate. // we need:- // array dates containing all dates of the period we need to chart. // array units containing 'name', 'color', array: 'data' containing the unit reservation count for each period $jsonSeries = new stdClass(); $jsonDates = new stdClass(); $feildsArray = array(); $jsonSeriesArray = array(); $jsonChartDataArray = array(); $feildsArray[] = 'date'; // this loop, loops through the units once to get the series data foreach ($units as $unit) { $feildsArray[] = 'unit' . $unit->getId(); $jsonSeries->yField = 'unit' . $unit->getId(); $jsonSeries->displayName = $unit->name; $jsonSeries->type = 'line'; // the graph type $jsonSeries->style = '{color: 0x' . $unit->color . '}'; // the graph type $jsonSeriesArray[] = clone $jsonSeries; } // this loop, loops through all dates and gets the data for each period for ($i = 0; $i < count($datetimes) - 1; $i++) { // get the date $date = $config->convertDates($datetimes[$i], RM_Config::PHP_DATEFORMAT, RM_Config::HUMAN_MONTH_DATEFORMAT); $chartData = array(); $chartData['date'] = $date; // loop through each unit foreach ($units as $unit) { $SdateParts = explode("-", $datetimes[$i]); $startDatetimes = mktime(0, 0, 0, (int) $SdateParts[1], (int) $SdateParts[2], (int) $SdateParts[0]); // set the endDatetimes to the last day of the month $EdateParts = explode("-", $datetimes[$i + 1]); $endDatetimes = mktime(0, 0, 0, (int) $EdateParts[1], (int) $SdateParts[2], (int) $EdateParts[0]); //mktime($hour, $minute, $second, $month, $day, $year) $period = new RM_Reservation_Period(new RM_Date($datetimes[$i]), new RM_Date($datetimes[$i + 1])); $count = $reservationDetailsModel->getReservationCount($unit, $period); $chartData['unit' . $unit->getId()] = $count; } //$chartData->units = $dataArray; $jsonChartDataArray[] = $chartData; } $returnData = new stdClass(); // fields: array containing all the fields ie: 'date', 'unit1', 'unit2', 'unit3' // // series: array containing objects for each series item:- // type: 'line',displayName: 'Unit 1',yField: 'unit1',style: {color:0x99BBE8} // note yField = the field name. // // data should contain the data:- // data: [ // {date:'Jul 07', unit1: 9, unit2: 11, unit3: 4}, // {date:'Aug 07', unit1: 5, unit2: 0, unit3: 3}, // {date:'Sep 07', unit1: 4, unit2: 0, unit3: 4}, // {date:'Oct 07', unit1: 8, unit2: 5, unit3: 5}, // {date:'Nov 07', unit1: 4, unit2: 6, unit3: 6}, // {date:'Dec 07', unit1: 0, unit2: 8, unit3: 7}, // {date:'Jan 08', unit1: 0, unit2: 11, unit3: 0}, // {date:'Feb 08', unit1: 8, unit2: 15, unit3: 7} // ] $returnData->fields = $feildsArray; $returnData->series = $jsonSeriesArray; $returnData->data = $jsonChartDataArray; return $returnData; }
public function getConfigValues() { // config values to be exposed to js $filter = ' rm_config_admin_help_panel_enable, rm_config_calendar_startday, rm_config_dateformat '; $config = new RM_Config(); $configValues = $config->get($filter); $configResult = array(); foreach ($configValues as $index => $value) { $configResult[] = "'" . $index . "':'" . $value . "'"; } return "RM.Config={" . implode(',', $configResult) . "}"; }
/** * Initialize all objects at a first time, or if config has been changed. */ public static function initialize() { self::$_list = array(); $adminThumbnail = new RM_Media_Image(); $adminThumbnail->_postfix = self::ADMIN; $adminThumbnail->_width = 100; $adminThumbnail->_height = 100; $adminThumbnail->_quality = 100; $adminThumbnail->_keepAspect = true; self::$_list[self::ADMIN] = $adminThumbnail; $config = new RM_Config(); $thumbnail = new RM_Media_Image(); $thumbnail->_postfix = self::THUMB; $thumbnail->_width = $config->getValue('rm_config_image_thumb_settings_x_res'); $thumbnail->_height = $config->getValue('rm_config_image_thumb_settings_y_res'); $thumbnail->_quality = $config->getValue('rm_config_image_thumb_settings_quality'); $thumbnail->_keepAspect = (bool) $config->getValue('rm_config_image_thumb_settings_aspect'); self::$_list[self::THUMB] = $thumbnail; $main = new RM_Media_Image(); $main->_postfix = self::MAIN; $main->_width = $config->getValue('rm_config_image_settings_x_res'); $main->_height = $config->getValue('rm_config_image_settings_y_res'); $main->_quality = $config->getValue('rm_config_image_settings_quality'); $main->_keepAspect = (bool) $config->getValue('rm_config_image_settings_aspect'); self::$_list[self::MAIN] = $main; }