getVar('id', 'none'); $task = $uri->getVar('gk_module_task', 'none'); $file = $uri->getVar('gk_module_file', 'none'); $base_path = str_replace('admin'.DS.'elements', '', dirname(__FILE__)).'config'.DS; // helping variables $msg = ''; // if the URL contains proper variables if($mod_id !== 'none' && is_numeric($mod_id) && $task !== 'none') { if($task == 'load') { if(JFile::exists($base_path . $file)) { // $query = ' UPDATE #__modules SET params = '.$db->quote(file_get_contents($base_path . $file)).' WHERE id = '.$mod_id.' LIMIT 1 '; // Executing SQL Query $db->setQuery($query); $result = $db->query(); // check the result if($result) { $msg = '
'.JText::_('MOD_TABS_GK5_CONFIG_LOADED_AND_SAVED').'
'; } else { $msg = '
'.JText::_('MOD_TABS_GK5_CONFIG_SQL_ERROR').'
'; } } else { $msg = '
'.JText::_('MOD_TABS_GK5_CONFIG_SELECTED_FILE_DOESNT_EXIST').'
'; } } else if($task == 'save') { if($file == '') { $file = date('d_m_Y_h_s'); } // variable used to detect if the specified file exists $i = 0; // check if the file to save doesn't exist if(JFile::exists($base_path . $file . '.json')) { // find the proper name for the file by incrementing $i = 1; while(JFile::exists($base_path . $file . $i . '.json')) { $i++; } } // get the settings from the database $query = ' SELECT params AS params FROM #__modules WHERE id = '.$mod_id.' LIMIT 1 '; // Executing SQL Query $db->setQuery($query); $row = $db->loadObject(); // write it if(JFile::write($base_path . $file . (($i != 0) ? $i : '') . '.json' , $row->params)) { if($i == 0) { $msg = '
'.JText::_('MOD_TABS_GK5_CONFIG_FILE_SAVED_AS'). ' '. $file .'.json
'; } else { $msg = '
'.JText::_('MOD_TABS_GK5_CONFIG_FILE_SAVED_AS'). ' '. $file . $i .'.json
'; } } else { $msg = '
'.JText::_('MOD_TABS_GK5_CONFIG_FILE_WASNT_SAVED_PLEASE_CHECK_PERM') .'
'; } // Delete Function } else if($task == 'delete') { // Check if file exists before deleting if(JFile::exists($base_path . $file)) { if(JFile::delete($base_path . $file)) { $msg = '
'. $file . ' ' . JText::_('MOD_TABS_GK5_CONFIG_FILE_DELETED_AS') .'
'; } else { $msg = '
'. $file . ' ' . JText::_('MOD_TABS_GK5_CONFIG_FILE_WASNT_DELETED_PLEASE_CHECK_PERM') .'
'; } } else { $msg = '
'. $file . ' ' . JText::_('MOD_TABS_GK5_CONFIG_FILE_WASNT_DELETED_PLEASE_CHECK_FILE') .'
'; } } } // generate the select list $options = (array) $this->getOptions(); $file_select = JHtml::_('select.genericlist', $options, 'name', '', 'value', 'text', 'default', 'config_manager_load_filename'); $file_delete = JHtml::_('select.genericlist', $options, 'name', '', 'value', 'text', 'default', 'config_manager_delete_filename'); // return the standard formfield output $html = ''; $html .= '
Follow us on the social media: Follow @gavickpro
'; $html .= '
'; $html .= $msg; $html .= '
'.$file_select.'
'; $html .= '
.json
'; $html .= '
'.$file_delete.'
'; $html .= '
'.JText::_('MOD_TABS_GK4_CONFIG_DIRECTORY').''.$base_path.'
'; $html .= '
'; // finish the output return $html; } protected function getOptions() { $options = array(); $path = (string) $this->element['directory']; if (!is_dir($path)) $path = JPATH_ROOT.DS.$path; $files = JFolder::files($path, '.json'); if (is_array($files)) { foreach($files as $file) { $options[] = JHtml::_('select.option', $file, $file); } } return array_merge($options); } } /* EOF */