/** * indexAction * Create the User object and get all the records. * @return unknown_type */ public function indexAction() { // get the group id $groupid = $this->getRequest()->getParam('groupid'); // Check if the groupid is a number if (empty($groupid) || !is_numeric($groupid)) { $grp = SettingsGroups::findbyName('General'); $groupid = $grp['group_id']; } $group = SettingsGroups::find($groupid); if (!empty($group)) { $this->view->title = $group['name']; $this->view->description = $group['description']; $this->view->help = $group['help']; } else { $this->view->title = $this->translator->translate("Settings"); $this->view->description = $this->translator->translate("Set here all the ShineISP parameters."); } $form = SettingsParameters::createForm($groupid); if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) { Settings::saveRecord($groupid, $form->getValues()); } $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit'))); // Create the html form $this->view->form = $form; }
protected function _initLayoutHelper() { $this->bootstrap('frontController'); if (Shineisp_Main::isReady()) { // Loading the configuration parameters $module = $this->getModuleName(); SettingsParameters::loadParams($module); Zend_Controller_Action_HelperBroker::addHelper(new Shineisp_Controller_Action_Helper_LayoutLoader()); } }
public function init() { // Set the custom decorator $this->addElementPrefixPath('Shineisp_Decorator', 'Shineisp/Decorator/', 'decorator'); $translate = Shineisp_Registry::get('Zend_Translate'); $this->addElement('select', 'parameter_id', array('filters' => array('StringTrim'), 'label' => $translate->_('parameter'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('parameter_id')->setAllowEmpty(false)->setMultiOptions(SettingsParameters::getList('admin')); $this->addElement('textarea', 'value', array('filters' => array('StringTrim'), 'required' => true, 'label' => $translate->_('value'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('select', 'isp_id', array('filters' => array('StringTrim'), 'required' => true, 'label' => $translate->_('Isp'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('isp_id')->setAllowEmpty(false)->setMultiOptions(Isp::getList()); $this->addElement('hidden', 'setting_id'); }
/** * Update the database item translation using the poedit! * This method creates a temporary file that helps you to parse the * database table common contents. */ public function updatetranslationAction() { $content = "<?php\n "; $content .= "# WARNING: This file has been created only for the POEDIT software.\n"; $content .= "# You can delete it, if you don't use it! \n\n"; // Setting Parameters $data = SettingsParameters::getAllInfo(); foreach ($data as $item) { $content .= "echo _('" . $item['name'] . "');\n"; $content .= "echo _('" . $item['description'] . "');\n"; } // Server Types $data = Servers_Types::getList(); foreach ($data as $id => $item) { $content .= "echo _('" . $item . "');\n"; } // Contact types $data = ContactsTypes::getList(); foreach ($data as $id => $item) { $content .= "echo _('" . $item . "');\n"; } // Legal form $data = Legalforms::getList(); foreach ($data as $id => $item) { $content .= "echo _('" . $item . "');\n"; } // Get the default navigation items $config = new Zend_Config_Xml(APPLICATION_PATH . '/modules/default/navigation.xml', 'nav'); $navigation = new Zend_Navigation($config); // Iterate recursively using RecursiveIteratorIterator $pages = new RecursiveIteratorIterator($navigation, RecursiveIteratorIterator::SELF_FIRST); foreach ($pages as $page) { $label = (string) $page->label; $content .= "echo _('{$label}');\n"; } // Get the administration navigation items $config = new Zend_Config_Xml(APPLICATION_PATH . '/modules/admin/navigation.xml', 'nav'); $navigation = new Zend_Navigation($config); // Iterate recursively using RecursiveIteratorIterator $pages = new RecursiveIteratorIterator($navigation, RecursiveIteratorIterator::SELF_FIRST); foreach ($pages as $page) { $label = $page->getLabel(); $content .= "echo _('{$label}');\n"; } $content .= "?>"; Shineisp_Commons_Utilities::writefile($content, "tmp", "translations.php"); die('Ok! Now update the default.po file by the poedit software'); }
/** * saveRecord * save the setting record group parameters * @param integer $groupid * @param integer $isp */ public static function saveRecord($groupid, $post, $isp = 1) { $i = 0; if (!empty($post)) { $records = new Doctrine_Collection('Settings'); foreach ($post as $field => $value) { // Get the old setting parameter value $setting = self::findRecord($field, $isp); if (!empty($setting)) { // Delete the old record self::deleteItem($setting['setting_id']); } // Get the parameter record $paramenter = SettingsParameters::getParameterbyVar($field); // Create the collection of records $records[$i]->isp_id = $isp; $records[$i]->parameter_id = $paramenter->get('parameter_id'); $records[$i]->value = $value; $i++; } // Save the records $records->save(); // Refresh the parameters SettingsParameters::loadParams(null, true); } return true; }
public function initAll() { // Get the Zend Event Manager $em = Shineisp_Registry::get('em'); $mainConfigfile = APPLICATION_PATH . "/configs/config.xml"; if (file_exists($mainConfigfile)) { $mainconfig = simplexml_load_file($mainConfigfile); } else { throw new Exception($mainConfigfile . " has been not found"); } if (!count($mainconfig->xpath("/shineisp/modules"))) { $modules = $mainconfig->addChild('modules'); } else { $modules = $mainconfig->xpath("/shineisp/modules"); } $path = PROJECT_PATH . "/library/Shineisp/Plugins" . DIRECTORY_SEPARATOR; // << The last slash is very important in the plugin path // Read all the directory recursivelly and get all the files and folders $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); foreach ($iterator as $filename => $path_object) { $pluginConfigFile = $filename; $info = pathinfo($filename); // Select only the plugins that have a xml configuration file if (!empty($info['extension']) && $info['extension'] == "xml") { // Get the directory of the plugin $PluginPath = $info['dirname']; // Delete the main plugin path $PluginBasePath = str_replace($path, "", $info['dirname']); // Convert the result as array $PluginBasePathArray = explode(DIRECTORY_SEPARATOR, $PluginBasePath); // Create the name of the Plugin class $pluginName = 'Shineisp_Plugins_' . implode("_", $PluginBasePathArray) . '_Main'; // Check if plugins looks good $reflectionClass = new ReflectionClass($pluginName); if (!($reflectionClass->isInstantiable() && $reflectionClass->implementsInterface('Shineisp_Plugins_Interface') && is_callable(array($pluginName, 'events')))) { Shineisp_Commons_Utilities::logs("Skipping not instantiable plugin '" . $pluginName . "'"); continue; } // Initialize $plugin = new $pluginName(); $plugin->events($em); // Check if the Main exists if (file_exists($pluginConfigFile) && is_readable($pluginConfigFile)) { $info = pathinfo($pluginConfigFile); if (!empty($info['extension']) && $info['extension'] == "xml") { if (file_exists($pluginConfigFile)) { $config = simplexml_load_file($pluginConfigFile); // If the config file has been created for the registrar ignore it // because the configuration is delegated to the registrar management if (isset($config->attributes()->type) && "registrars" == (string) $config->attributes()->type) { continue; } $panelName = (string) $config->attributes()->name; $var = (string) $config['var']; // Save the module setup in the config.xml file // Now we are checking if the module is already set in the config.xml file if (!count($mainconfig->xpath("/shineisp/modules/{$var}"))) { // The module is not present, we have to create it $module = $modules[0]->addChild($var); // Now we add the setup date as attribute $module->addAttribute('setup', date('YmdHis')); } else { // The module is present and we get it $module = $mainconfig->xpath("/shineisp/modules/{$var}"); // If the setup date attribute is present skip the module process setup if (!empty($module[0]) && $module[0]->attributes()->setup) { continue; } else { // The setup attribute is not present restart the module setup process $module[0]->addAttribute('setup', date('YmdHis')); } } $help = (string) $config->general->help ? (string) $config->general->help : NULL; $description = (string) $config->general->description ? (string) $config->general->description : NULL; $group_id = SettingsGroups::addGroup($config['name'], $description, $help); if (!empty($config->settings) && $config->settings->children()) { foreach ($config->settings->children() as $node) { $configclass = array(); $arr = $node->attributes(); $var = strtolower($config['var']) . "_" . (string) $arr['var']; $label = (string) $arr['label']; $type = (string) $arr['type']; $description = (string) $arr['description']; if ((string) $arr['configclass']) { $configclass = json_decode((string) $arr['configclass'], true); } if (!empty($var) && !empty($label) && !empty($type)) { SettingsParameters::addParam($label, $description, $var, $type, 'admin', 1, $group_id, $configclass); } } if (!empty($config->customfields)) { foreach ($config->customfields->children() as $node) { $arr = $node->attributes(); $var = (string) $node; $label = (string) $arr['label']; $type = (string) $arr['type']; $section = (string) $arr['section']; // Fetch panel_id from database if (!empty($panelName)) { $Panels = Panels::getAllInfoByName($panelName); } $panel_id = !empty($Panels) && isset($Panels['panel_id']) && $Panels['panel_id'] > 0 ? intval($Panels['panel_id']) : null; if (!empty($var) && !empty($label) && !empty($type)) { CustomAttributes::createAttribute($var, $label, $type, $section, $panel_id); } } } } } $xmlstring = $mainconfig->asXML(); // Prettify and save the xml configuration $dom = new DOMDocument('1.0'); $dom->loadXML($xmlstring); $dom->formatOutput = TRUE; $dom->preserveWhiteSpace = TRUE; $dom->saveXML(); if (!@$dom->save($mainConfigfile)) { throw new Exception("Error on saving the xml file in {$mainConfigfile} <br/>Please check the folder permissions"); } } } } } }
/** * addParam * Add a new parameter * @param string $label * @param string $description * @param string $var * @param string $type * @param string $module * @param boolean $enabled * @param integer $groupID */ public static function addParam($label, $description, $var, $type, $module, $enabled, $groupID, $config = array()) { $p = self::getParameterbyVar($var); if (!empty($p)) { return $p->get('parameter_id'); } $parameter = new SettingsParameters(); $parameter['name'] = $label; $parameter['description'] = $description; $parameter['var'] = $var; $parameter['type'] = $type; $parameter['module'] = $module; $parameter['enabled'] = $enabled; $parameter['group_id'] = $groupID; $parameter['config'] = json_encode($config); $parameter->save(); return $parameter['parameter_id']; }