/** * 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'); }
/** * 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; }
/** * Constructor */ function __construct() { $connector = RM_Environment::getConnector(); $rootPath = $connector->getRootPath(); $ds = DIRECTORY_SEPARATOR; $this->_imageFolder = $rootPath . $ds . 'RM' . $ds . 'userdata' . $ds . 'images' . $ds . 'media'; $this->_rootURL = $connector->getRootURL(); $this->_imageURL = $this->_rootURL . 'RM/userdata/images/media'; }
/** * Constructor */ function __construct(RM_Unit_Row $unit) { $this->_unit = $unit; parent::__construct(); $connector = RM_Environment::getConnector(); $rootPath = $connector->getRootPath(); $ds = DIRECTORY_SEPARATOR; $this->_unitsFolder = $rootPath . $ds . 'RM' . $ds . 'userdata' . $ds . 'images' . $ds . 'units'; $this->_unitURL = $this->_rootURL . 'RM/userdata/images/units'; }
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; }
/** * Constructor */ function __construct($extensionName) { $this->_extensionName = $extensionName; parent::__construct(); $connector = RM_Environment::getConnector(); $rootPath = $connector->getRootPath(); $ds = DIRECTORY_SEPARATOR; $this->_mediaFolder = $rootPath . $ds . 'RM' . $ds . 'userdata' . $ds . 'images' . $ds . $extensionName; if (!file_exists($this->_mediaFolder)) { $this->createFolder(); } $this->_extensionsMediaURL = RM_Environment::getConnector()->getUserRootURL() . "RM/userdata/images/" . $extensionName; }
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; }
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; }
/** * Public constructor */ public function __construct() { $this->_ipnLogFile = RM_Environment::getConnector()->getCorePath() . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR . 'paypal_ipn_log.txt'; $this->_addField('rm', '2'); // Return method = POST $this->_addField('cmd', '_xclick'); $config = $this->_getConfig(); if (!$config) { return false; } // fail if no config if ((int) $config['sandbox'] == 1) { $this->_paypalURL = self::$_sandboxURL; } else { $this->_paypalURL = self::$_realURL; } }
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; } }
public function beginTransaction($value, $reservationID, $description, $successUrl, $cancelUrl, $callbackClassName) { $payPalService = new RM_PayPal_Service(); try { $payPalService->initialize($payPalService->createInvoiceNumber($reservationID, true), $description, $value); } catch (RM_Exception $e) { RM_Log::toLog("PayPal transaction aborted: " . $e->getMessage()); throw new RM_Transaction_Exception(); } $fields = $payPalService->getFields(); $request = RM_Environment::getConnector()->getRequestHTTP(); $request->setControllerName('PayPal'); $request->setActionName('form'); $controller = new RM_User_PayPalController($request, new Zend_Controller_Response_Http()); $controller->setFrontController(Zend_Controller_Front::getInstance()); $controller->view->setScriptPath(RM_Environment::getConnector()->getRootPath() . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'PayPal' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'user' . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'PayPal'); $fields['custom'] = $callbackClassName; $fields['return'] = $successUrl; $fields['cancel_return'] = $cancelUrl; $controller->view->fields = $fields; $controller->view->paypal_url = $payPalService->getPaypalURL(); echo $controller->view->render('form.phtml'); return; }
public function deleteLanguage($locale) { $languageFolderPath = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getRootPath(), 'RM', 'userdata', 'modules', $this->name, 'languages', $locale)); $fileSystem = new RM_Filesystem(); return $fileSystem->deleteFolder($languageFolderPath); }
/** * This method should check if user is already loginned into CMS and if * we have linked user in the Resmania we need to set this user object to RM_Reservation_Manager class. * * @return bool */ public function initUser() { $config = new RM_Config(); if ($this->_module == 'admin' && (int) $config->getValue('rm_config_enable_user_groups') === 0) { return; } $user = RM_Reservation_Manager::getInstance()->getUser(); if ($user !== null) { return; } if ($config->getValue('rm_config_enable_cms_integration')) { $cmsUser = RM_Environment::getConnector()->getUser(); if ($cmsUser->isGuest()) { return; } $user = $cmsUser->findResmaniaUser(); if ($user == null) { $user = $cmsUser->convertToResmaniaUser(); } RM_Reservation_Manager::getInstance()->setUser($user); } }
/** * Login validate action * * validates the users login then redirects the user */ function loginvalidateAction() { $this->_withoutView(); $formModel = new RM_Forms(); $form = $formModel->find('login')->current(); $valid = $form->validate($this->getRequest()); if (!$valid) { RM_Reservation_Manager::getInstance()->setFormErrors('login', $form->getErrors())->save(); $this->_redirect('User', 'userdetails'); } $config = new RM_Config(); $isCmsAuthentication = $config->getValue('rm_config_enable_cms_integration'); if ($isCmsAuthentication) { $cmsUser = RM_Environment::getConnector()->getUser(); $user = $cmsUser->findResmaniaUser(); if ($user == null) { $user = $cmsUser->convertToResmaniaUser(); } RM_Reservation_Manager::getInstance()->setUser($user); } else { $userModel = new RM_Users(); $user = $userModel->getBy($this->_getParam('username'), $this->_getParam('password')); } if ($user !== null) { RM_Reservation_Manager::getInstance()->resetFormErrors('login')->setUser($user)->save(); $this->_redirect('Reservations', 'summary'); } }
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * * @access public * @author Valentin * @copyright 2011 ResMania Ltd. * @version 1.2 * @link http://docs.resmania.com/api/ * @since 06-2011 */ include_once RM_Environment::getConnector()->getRootPath() . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR . 'recaptcha-php-1.10' . DIRECTORY_SEPARATOR . 'recaptchalib.php'; /** * Class bridge between 'recaptchalib' and RM_Captcha_Interface. */ class RM_Captcha_Recaptcha implements RM_Captcha_Interface { /** * Enabled * * Sets if reCaptcha should be used. */ private $_enabled = true; /** * Default public key for reCaptcha service * @var string */
/** * 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 deleteLanguage($iso) { $languageFolder = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getRootPath(), 'RM', 'userdata', 'plugins', $this->name, 'languages', $iso)); RM_Filesystem::deleteFolder($languageFolder); }
/** * clear up * remove old upgrade files */ public function cleanupJsonAction() { // upgrade temp file path $filePath = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getRootPath(), 'RM', 'userdata', 'temp', 'upgrade')); $deleteArray = array($filePath . DIRECTORY_SEPARATOR . "core.zip", $filePath . DIRECTORY_SEPARATOR . "modules", $filePath . DIRECTORY_SEPARATOR . "plugins", $filePath . DIRECTORY_SEPARATOR . "system", $filePath . DIRECTORY_SEPARATOR . "tests", $filePath . DIRECTORY_SEPARATOR . "userdata", $filePath . DIRECTORY_SEPARATOR . "license", $filePath . DIRECTORY_SEPARATOR . "postupgrade.php"); foreach ($deleteArray as $item) { RM_Log::toLog('Upgrade - temp file/folder deleted: ' . $item, RM_Log::INFO); RM_Filesystem::deleteFolder($item); } return array('data' => array('success' => true)); }
/** * 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'); }
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); }
private static function _getClassName($directory, $file) { $classPath = str_replace($directory . DIRECTORY_SEPARATOR, '', $file); $classPath = str_replace('.php', '', $classPath); $classChunks = explode(DIRECTORY_SEPARATOR, $classPath); $className = 'RM_' . ucfirst(RM_Environment::getConnector()->getModule()) . '_' . implode('_', $classChunks); return $className; }
/** * Upload module zip file. * * @param string $formName name of the form on the user interface * @param stdclass $json * @return array * * $tempFileName, * $tempFilePath, * $json */ function upload($formName, $json) { $rootPath = RM_Environment::getConnector()->getRootPath(); //1. upload zip - check if this file name a .zip extension //2. move zip to temp directory $tempFolderName = 'temp'; $tempFolderPath = $rootPath . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . $tempFolderName; $validators = array(); $validators[] = new Zend_Validate_File_Extension('zip'); $adapter = new Zend_File_Transfer_Adapter_Http(); $adapter->setValidators($validators); try { $adapter->setDestination($tempFolderPath); } catch (Zend_File_Transfer_Exception $exception) { throw new RM_Exception($exception->getMessage()); } if (!$adapter->receive()) { $message = $this->_translate->_('Admin.Modules.InstallMsg', 'UploadFailed'); $message .= '. ' . implode("; ", $adapter->getMessages()); throw new RM_Exception($message); } else { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Modules.InstallMsg', 'UploadSuccess')); } //3. create new directory for a module $files = $adapter->getFileInfo(); $tempFileName = $files[$formName]['name']; $tempFilePath = $tempFolderPath . DIRECTORY_SEPARATOR . $tempFileName; return array($tempFileName, $tempFilePath, $json); }
/** * Get all form panels returns JSON with title and link to JS * */ public function helppageAction() { ob_clean(); $view = new RM_View(); $view->addScriptPath(implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getRootPath(), 'RM', 'userdata', 'modules', 'FormDesigner', 'views', 'admin', 'scripts', 'FormDesigner'))); echo $view->render('help.phtml'); die; }
/** * 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; }
/** * 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; }
/** * !!!IMPORTANT!!! This will not work on IE, 'cause there is a limit (31) for css include files * * @param $cssLibFiles * @return void */ private function _includeCssLibFilesInOldStyle($cssLibFiles) { $html = array(); foreach ($cssLibFiles as $cssFile) { $html[] = '<link rel="stylesheet" type="text/css" href="' . RM_Environment::getConnector()->getRootURL() . $cssFile . '"/>'; } return implode("\n", $html); }
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()); }
/** * this method will clear the module css cache */ public function clearCSSCache() { // clear the module CSS Cache $cacheDir = RM_Environment::getConnector()->getRootPath() . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'css'; if (file_exists($cacheDir)) { RM_Filesystem::emptyFolder($cacheDir); } }
/** * Sync CMS users with Resmania users. * Basically it copy cms users that are not presented in Resmania into Resmania user database table, * without passwords. */ public function syncJsonAction() { try { $users = RM_Environment::getConnector()->getUsers(); } catch (Exception $e) { return array('data' => array('success' => false, 'message' => $e->getMessage())); } $count = 0; $table = new RM_Users(); foreach ($users as $user) { $resmaniaUser = $user->findResmaniaUser(); if ($resmaniaUser == null) { $newResmaniaUser = $user->convertToResmaniaUser(); $newResmaniaUser->group_id = RM_UserGroups::REGULAR; $newResmaniaUser->setTable($table); //This is for internal class connecting. $newResmaniaUser->save(); $count++; } } if ($count == 0) { $message = $this->_translate->_('Admin.Users.List', 'SyncSuccessNoNew'); } else { $message = $this->_translate->_('Admin.Users.List', 'SyncSuccess') . $count; } return array('data' => array('success' => true, 'message' => $message)); }