Пример #1
0
 function renewJsonAction()
 {
     $extensions = RM_Environment::getInstance()->getOutOfDateExtensions();
     $pluginModel = new RM_Plugins();
     $pluginManager = new RM_Plugin_Manager($this->_translate);
     $failedPlugins = array();
     foreach ($extensions['plugins'] as $pluginName) {
         $plugin = $pluginModel->fetchByName($pluginName);
         try {
             $pluginManager->autoUpgrade($plugin);
         } catch (Exception $e) {
             $failedPlugins[] = $pluginName;
             continue;
         }
     }
     $moduleModel = new RM_Modules();
     $moduleManager = new RM_Module_Manager($this->_translate);
     $failedModules = array();
     foreach ($extensions['modules'] as $moduleName) {
         $module = $moduleModel->fetchByName($moduleName);
         try {
             $moduleManager->autoUpgrade($module);
         } catch (Exception $e) {
             $failedModules[] = $moduleName;
             continue;
         }
     }
     return array('data' => array('success' => true));
 }
Пример #2
0
 /**
  * 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";
 }
Пример #3
0
 /**
  * @see RM_Dependency_Abstract::validate method
  * @return bool
  */
 public function validate()
 {
     //1. check if plugin is installed
     $pluginClassName = 'RM_Plugin_' . $this->_getName();
     if (class_exists($pluginClassName) == false) {
         return false;
     }
     //2. check if plugin is enabled
     $pluginModel = new RM_Plugins();
     $pluginRow = $pluginModel->fetchByName($this->_getName());
     if ($pluginModel->isEnabled($pluginRow) == false) {
         return false;
     }
     //3. check it's min version
     $minPluginVersion = $this->_getVersion();
     $pluginVersion = $pluginRow->version;
     if (version_compare($pluginVersion, $minPluginVersion, '<')) {
         return false;
     }
     return true;
 }
Пример #4
0
 /**
  * Private constructor that invokes only from 'getInstance' method
  */
 private function __construct()
 {
     $this->_initializeLocale();
     $model = new RM_Modules();
     $allModules = $model->fetchAll();
     $modules = $model->fetchAllEnabled();
     foreach ($modules as $module) {
         $moduleObject = RM_Module_Manager::getModule($module->name);
         //We will get the last enabled module in the system
         //that implements one of our internal interfaces
         if ($moduleObject instanceof RM_Payments_Interface) {
             $this->_paymentSystem = $moduleObject;
         }
         if ($moduleObject instanceof RM_Extras_Interface) {
             $this->_extrasSystems[] = $moduleObject;
         }
         if ($moduleObject instanceof RM_Others_Interface) {
             $this->_othersSystems[] = $moduleObject;
         }
         if ($moduleObject instanceof RM_SEF_Manager_Interface) {
             $this->_sefManager = $moduleObject;
         }
     }
     $pluginModel = new RM_Plugins();
     $allPlugins = $pluginModel->fetchAll();
     $plugins = $pluginModel->fetchAllEnabled();
     $this->_taxSystem = new RM_Taxes_Default();
     foreach ($plugins as $plugin) {
         $pluginObject = RM_Plugin_Manager::getPlugin($plugin->name);
         if ($pluginObject instanceof RM_Taxes_Interface) {
             $this->_taxSystem = $pluginObject;
         }
         if ($pluginObject instanceof RM_Discounts_Plugin_Interface) {
             $this->_discounts[] = $pluginObject;
         }
         //We will assign only one deposit system (the last one enabled)
         if ($pluginObject instanceof RM_Deposit_Plugin_Interface) {
             $this->_depositSystem = $pluginObject;
         }
     }
     $this->_initializeTranslate($allModules, $allPlugins);
 }
Пример #5
0
 public function uninstall()
 {
     $pluginsModel = new RM_Plugins();
     $plugin = $pluginsModel->find($this->name)->current();
     if ($plugin !== null) {
         $dependenciesModel = new RM_Dependencies();
         $dependencies = $dependenciesModel->getDependencies($plugin);
         foreach ($dependencies as $dependency) {
             $dependency->delete();
         }
     }
 }
Пример #6
0
 /**
  * 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;
 }
Пример #7
0
 /**
  * Uninstall module
  *
  * @param RM_Module_Row $module
  * @throws RM_Exception is some error occures
  */
 function uninstall($module)
 {
     //1. get module path
     $moduleFolderPath = self::getModuleFolderpath($module->name);
     //3. invoke uninstall from module main class
     $className = self::_getClassname($module->name);
     $moduleObject = new $className();
     $moduleObject->uninstall();
     //5. invoke SQL uninstall file
     self::uninstallDatabase($moduleFolderPath);
     //6. remove userdata module directories
     $result = RM_Filesystem::deleteFolder($moduleFolderPath);
     $result = RM_Filesystem::deleteFolder(self::getModuleUserFolderpath($module->name));
     //7. disable all modules that are connected to this module if this is possible
     $pluginsManager = new RM_Plugin_Manager(RM_Environment::getInstance()->getTranslation());
     $pluginsModel = new RM_Plugins();
     $plugins = $pluginsModel->fetchByModuleName($module->name, true);
     foreach ($plugins as $plugin) {
         try {
             $pluginsManager->disable($plugin);
         } catch (Exception $e) {
             //TODO: add some log message that we could not disable this plugin
             continue;
         }
     }
     //8. remove module row from database
     $module->delete();
     return true;
 }
Пример #8
0
 /**
  * Returns all (or only enabled) plugins that depends to a module
  *
  * @param bool $onlyEnabled
  * @return Zend_Db_Table_Rowset
  */
 public function getAllPlugins($onlyEnabled = false)
 {
     $model = new RM_Plugins();
     return $model->fetchByModuleName($this->name, $onlyEnabled);
 }
Пример #9
0
 /**
  * Initialize autoloading for modules and plugins
  */
 public function initAuloadMP()
 {
     $isSafeMode = $this->isSafeMode();
     $paths = array();
     $modulesDAO = new RM_Modules();
     $modules = $modulesDAO->fetchAll();
     foreach ($modules as $module) {
         if ($isSafeMode && $module->core == 0) {
             continue;
         }
         $bothPath = RM_Module_Manager::getModuleFolderpath($module->name, $this->_rootPath) . DIRECTORY_SEPARATOR;
         $paths[] = $bothPath . RM_Module_Config::CLASSES;
         $paths[] = $bothPath . RM_Module_Config::CONTROLLERS;
     }
     $pluginsDAO = new RM_Plugins();
     $plugins = $pluginsDAO->fetchAll();
     foreach ($plugins as $plugin) {
         if ($isSafeMode && $plugin->core == 0) {
             continue;
         }
         $bothPath = RM_Plugin_Manager::getPluginFolderpath($plugin->name, $this->_rootPath) . DIRECTORY_SEPARATOR;
         $paths[] = $bothPath . RM_Plugin_Config::CLASSES;
         $paths[] = $bothPath . RM_Plugin_Config::CONTROLLERS;
     }
     $MPPathString = implode(PATH_SEPARATOR, $paths);
     set_include_path(get_include_path() . PATH_SEPARATOR . $MPPathString);
 }
Пример #10
0
 /**
  * Returns data for the info grid (grid with language files) on the language page.
  *
  * This method returns the list data in JSON format. This is implicated in
  * lists.js
  *
  * @param    request iso   
  * @return   json    the json data for the list.
  */
 public function infogridJsonAction()
 {
     $iso = $this->_getParam('iso');
     $files = RM_Language_Manager::$files;
     $jsonFiles = array();
     foreach ($files as $file) {
         $jsonFiles[] = array($file, RM_Language_Manager::TYPE_MAIN . ',' . RM_Language_Manager::TYPE_MAIN, $iso . ',' . $file . ',' . RM_Language_Manager::TYPE_MAIN . ',' . RM_Language_Manager::TYPE_MAIN);
     }
     $extensionFiles = RM_Language_Manager::$extensionFiles;
     $moduleModel = new RM_Modules();
     $modules = $moduleModel->fetchAll();
     foreach ($modules as $module) {
         foreach ($extensionFiles as $file) {
             $jsonFiles[] = array($file, RM_Language_Manager::TYPE_MODULE . ',' . $moduleModel->get($module->name)->getName(), $iso . ',' . $file . ',' . RM_Language_Manager::TYPE_MODULE . ',' . $module->name);
         }
     }
     $pluginModel = new RM_Plugins();
     $plugins = $pluginModel->fetchAll();
     foreach ($plugins as $plugin) {
         foreach ($extensionFiles as $file) {
             $jsonFiles[] = array($file, RM_Language_Manager::TYPE_PLUGIN . ',' . $pluginModel->get($plugin->name)->getName(), $iso . ',' . $file . ',' . RM_Language_Manager::TYPE_PLUGIN . ',' . $plugin->name);
         }
     }
     $json = new stdClass();
     $json->total = count($jsonFiles);
     $json->data = $jsonFiles;
     return array('data' => $jsonFiles);
 }
Пример #11
0
 /**
  * Returns all unit objects by it's type
  *
  * @param object    $criteria this object contains the specification for the
  * search.
  * @return Zend_Db_Table_Rowset All units objects
  */
 public function getAll(RM_Unit_Search_Criteria $criteria)
 {
     $fieldsNames = array();
     $fieldsNames[] = 'rm_units.*';
     $languageFieldsNames = array();
     $languageFieldsNames[] = 'rm_unit_language_details.*';
     if ($criteria->offset === null) {
         $criteria->offset = 0;
     }
     $sql = "\r\n            SELECT\r\n                " . implode(',', $fieldsNames);
     if (count($languageFieldsNames) > 0) {
         $sql .= ", " . implode(',', $languageFieldsNames);
     }
     if (!$criteria->language) {
         $criteria->language = RM_Environment::getInstance()->getLocale();
     }
     $sql .= "\r\n            FROM\r\n                rm_units\r\n            INNER JOIN\r\n                rm_unit_language_details ON\r\n                rm_units.id = rm_unit_language_details.unit_id";
     $sql .= "\r\n            AND rm_unit_language_details.iso = '{$criteria->language}'\r\n                WHERE 1=1 ";
     if ($criteria->type) {
         $sql .= " AND type_id = '" . $criteria->type->id . "' ";
     }
     // this gets the units that are unavailable so these are excluded from the results
     if ($criteria->start_datetime && $criteria->end_datetime) {
         $reservationPeriod = new RM_Reservation_Period(new RM_Date(strtotime($criteria->start_datetime)), new RM_Date(strtotime($criteria->end_datetime)));
         if ($criteria->flexible) {
             //My dates are flexible: every unit with at least one day available should we shown
             $availableUnitIDs = $this->getFlexibleAvailable($reservationPeriod);
             if (count($availableUnitIDs) == 0) {
                 $sql .= " AND 1=0 ";
                 //This will returns 0 rows
                 return $this->_getBySQL($sql);
             } else {
                 $sql .= "\r\n                        AND rm_units.id IN (" . implode(',', $availableUnitIDs) . ")\r\n                    ";
             }
         } else {
             $reservedUnits = $this->getReservedUnits($reservationPeriod)->toArray();
             $unitsWithAvailbilityCheckDisabled = RM_Environment::getInstance()->getPriceSystem()->getUnitWithAvailabiltyCheckDisabled();
             if (count($reservedUnits) > 0) {
                 $reservedUnits = array_diff($reservedUnits, $unitsWithAvailbilityCheckDisabled);
             }
             if (count($reservedUnits) > 0) {
                 $reservedUnitIDs = array();
                 foreach ($reservedUnits as $unit) {
                     if ($unit['id']) {
                         $reservedUnitIDs[] = $unit['id'];
                     }
                 }
                 $reservedUnitsCSV = implode(',', $reservedUnitIDs);
                 if ($reservedUnitsCSV != "," && $reservedUnitsCSV != "") {
                     $sql .= "\r\n                            AND rm_units.id NOT IN (" . $reservedUnitsCSV . ")\r\n                        ";
                 }
             }
             //we need to check min period length
             $manager = RM_Prices_Manager::getInstance();
             $minPeriodNotUnitIDs = $manager->getByMinPeriod($reservationPeriod);
             if (count($minPeriodNotUnitIDs) > 0) {
                 $minPeriodNotUnitIDsCSV = implode(',', $minPeriodNotUnitIDs);
                 if ($minPeriodNotUnitIDsCSV != "," && $minPeriodNotUnitIDsCSV != "") {
                     $sql .= "\r\n                            AND rm_units.id NOT IN (" . $minPeriodNotUnitIDsCSV . ")\r\n                        ";
                 }
             }
         }
     }
     if ($criteria->image == 1) {
         $unitIDsWithImages = $this->getWithImages();
         if (count($unitIDsWithImages) == 0) {
             $sql .= " AND 1=0 ";
             //This will returns 0 rows
             return $this->_getBySQL($sql);
         } else {
             $sql .= "\r\n                    AND rm_units.id IN (" . implode(',', $unitIDsWithImages) . ")\r\n                ";
         }
     }
     //3. prices: from - to
     if ((int) $criteria->prices_from != 0 || (int) $criteria->prices_to != 99999999) {
         if ($criteria->prices_from || $criteria->prices_to) {
             if ($criteria->start_datetime && $criteria->end_datetime) {
                 $reservationPeriod = new RM_Reservation_Period(new RM_Date(strtotime($criteria->start_datetime)), new RM_Date(strtotime($criteria->end_datetime)));
             } else {
                 $reservationPeriod = null;
             }
             $priceRangeUnitIDs = RM_Environment::getInstance()->getPriceSystem()->getByPriceRange($criteria->prices_from, $criteria->prices_to, $reservationPeriod);
             if (count($priceRangeUnitIDs) == 0) {
                 $sql .= " AND 1=0 ";
                 //This will returns 0 rows
                 return $this->_getBySQL($sql);
             } else {
                 $sql .= "\r\n                        AND rm_units.id IN (" . implode(',', $priceRangeUnitIDs) . ")\r\n                    ";
             }
         }
     }
     //4. check all plugins and modules to extend advanced search
     $model = new RM_Modules();
     $modules = $model->getAllEnabled();
     foreach ($modules as $module) {
         if ($module instanceof RM_Search_Advanced_Interface) {
             $unitIDs = $module->getAdvancedSearchUnitIDs($criteria);
             if ($unitIDs !== false) {
                 if (count($unitIDs) == 0) {
                     $sql .= " AND 1=0 ";
                     //This will returns 0 rows
                     return $this->_getBySQL($sql);
                 } elseif (count($unitIDs) > 0) {
                     $sql .= "\r\n                            -- added by modules: " . $module->name . "\r\n                            AND rm_units.id IN (" . implode(',', $unitIDs) . ")\r\n                        ";
                 }
             }
         }
     }
     $pluginModel = new RM_Plugins();
     $plugins = $pluginModel->getAllEnabled();
     foreach ($plugins as $plugin) {
         if ($plugin instanceof RM_Search_Advanced_Interface) {
             $unitIDs = $plugin->getAdvancedSearchUnitIDs($criteria);
             if ($unitIDs !== false) {
                 if (count($unitIDs) == 0) {
                     $sql .= " AND 1=0 ";
                     //This will returns 0 rows
                     return $this->_getBySQL($sql);
                 } elseif (count($unitIDs) > 0) {
                     $sql .= "\r\n                            -- added by modules: " . $plugin->name . "\r\n                            AND rm_units.id IN (" . implode(',', $unitIDs) . ")\r\n                        ";
                 }
             }
         }
     }
     if ($criteria->publishedOnly === true) {
         $sql .= " AND rm_units.published='1'";
     }
     if (count($criteria->filters) > 0) {
         $filterConditions = array();
         foreach ($criteria->filters as $filter) {
             $filterConditions = array_merge($filterConditions, $this->_getConditions($filter));
         }
         $filterSQL = implode(" AND ", $filterConditions);
         $sql .= " AND " . $filterSQL;
     }
     if ($criteria->order !== null) {
         if ($criteria->order == 'random') {
             $sessionID = session_id();
             $random = hexdec($sessionID[0]);
             $sql .= " ORDER BY RAND(" . $random . ") ";
         } elseif ($criteria->order != 'price') {
             $sql .= " ORDER BY {$criteria->order} ";
         }
     }
     if ($criteria->count !== null) {
         $sql .= " LIMIT {$criteria->offset}, {$criteria->count} ";
     }
     return $this->_getBySQL($sql);
 }
Пример #12
0
 private function _getPlugins()
 {
     $model = new RM_Plugins();
     $plugins = $model->getAllEnabled();
     $result = array();
     foreach ($plugins as $plugin) {
         $node = $plugin->getNode();
         if ($node !== null) {
             $result[] = $node;
         }
     }
     return $result;
 }
Пример #13
0
 public function disableJsonAction()
 {
     $json = new stdClass();
     $json->success = 1;
     $json->msg = array();
     $ids = $this->_getParam('ids', array());
     $manager = new RM_Plugin_Manager($this->_translate);
     $model = new RM_Plugins();
     foreach ($ids as $id) {
         $row = $model->find($id)->current();
         try {
             $manager->disable($row);
         } catch (Exception $e) {
             $json->success = 0;
             $json->msg[] = $e->getMessage();
         }
     }
     return array('data' => $json);
 }