/** * Method to save global configuration. * * @return mixed Calls $app->redirect() * * @since 3.2 */ public function execute() { // Check for request forgeries. if (!JSession::checkToken()) { $this->app->enqueueMessage(JText::_('JINVALID_TOKEN')); $this->app->redirect('index.php'); } // Set FTP credentials, if given. JClientHelper::setCredentialsFromRequest('ftp'); $model = new ConfigModelComponent(); $form = $model->getForm(); $data = $this->input->get('jform', array(), 'array'); $id = $this->input->getInt('id'); $option = $this->input->get('component'); // Check if the user is authorized to do this. if (!JFactory::getUser()->authorise('core.admin', $option)) { $this->app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR')); $this->app->redirect('index.php'); } $returnUri = $this->input->post->get('return', null, 'base64'); $redirect = ''; if (!empty($returnUri)) { $redirect = '&return=' . urlencode($returnUri); } // Validate the posted data. $return = $model->validate($form, $data); // Check for validation errors. if ($return === false) { /* * The validate method enqueued all messages for us, so we just need to redirect back. */ // Save the data in the session. $this->app->setUserState('com_config.config.global.data', $data); // Redirect back to the edit screen. $this->app->redirect(JRoute::_('index.php?option=com_config&view=component&component=' . $option . $redirect, false)); } // Attempt to save the configuration. $data = array('params' => $return, 'id' => $id, 'option' => $option); try { $model->save($data); } catch (RuntimeException $e) { // Save the data in the session. $this->app->setUserState('com_config.config.global.data', $data); // Save failed, go back to the screen and display a notice. $this->app->enqueueMessage(JText::sprintf('JERROR_SAVE_FAILED', $e->getMessage()), 'error'); $this->app->redirect(JRoute::_('index.php?option=com_config&view=component&component=' . $option . $redirect, false)); } // Set the redirect based on the task. switch ($this->options[3]) { case 'apply': $this->app->enqueueMessage(JText::_('COM_CONFIG_SAVE_SUCCESS')); $this->app->redirect(JRoute::_('index.php?option=com_config&view=component&component=' . $option . $redirect, false)); break; case 'save': default: $redirect = 'index.php?option=' . $option; if (!empty($returnUri)) { $redirect = base64_decode($returnUri); } $this->app->redirect(JRoute::_($redirect, false)); break; } return true; }
/** * Save the parameters */ public function save($key = null, $urlVar = null) { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); // Get the old component parameters jimport('joomla.application.component.helper'); $old_params = JComponentHelper::getParams('com_attachments'); $old_secure = JRequest::getInt('old_secure'); // Set FTP credentials, if given. jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); // Initialise variables. $model = new ConfigModelComponent(); $form = $model->getForm(); $data = JRequest::getVar('jform', array(), 'post', 'array'); $id = JRequest::getInt('id'); $option = JRequest::getCmd('component'); // Get the new component parameters $new_secure = $data['secure']; // Check if the user is authorized to do this. if (!JFactory::getUser()->authorise('core.admin', $option)) { JFactory::getApplication()->redirect('index.php', JText::_('JERROR_ALERTNOAUTHOR')); return; } // Validate the posted data. $return = $model->validate($form, $data); // Check for validation errors. if ($return === false) { // Get the validation messages. $errors = $model->getErrors(); // Push up to three validation messages out to the user. for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { if ($errors[$i] instanceof Exception) { $app->enqueueMessage($errors[$i]->getMessage(), 'warning'); } else { $app->enqueueMessage($errors[$i], 'warning'); } } // Save the data in the session. $app->setUserState('com_config.config.global.data', $data); // Redirect back to the edit screen. $this->setRedirect(JRoute::_('index.php?option=com_attachments&task=params.edit', false)); return false; } // Attempt to save the configuration. $data = array('params' => $return, 'id' => $id, 'option' => $option); $return = $model->save($data); // Check the return value. if ($return === false) { // Save the data in the session. $app->setUserState('com_config.config.global.data', $data); // Save failed, go back to the screen and display a notice. $message = JText::sprintf('JERROR_SAVE_FAILED', $model->getError()); $this->setRedirect(JRoute::_('index.php?option=com_attachments&task=params.edit'), $message, 'error'); return false; } // Deal with any changes in the 'secure mode' (or upload directories) if ($new_secure != $old_secure) { // Check/update the security status require_once JPATH_SITE . '/components/com_attachments/helper.php'; $attach_dir = JPATH_SITE . '/' . AttachmentsDefines::$ATTACHMENTS_SUBDIR; AttachmentsHelper::setup_upload_directory($attach_dir, $new_secure == 1); $msg = JText::_('ATTACH_UPDATED_ATTACHMENTS_PARAMETERS_AND_SECURITY_SETTINGS'); } else { $msg = JText::_('ATTACH_UPDATED_ATTACHMENTS_PARAMETERS'); } // Set the redirect based on the task. switch ($this->getTask()) { case 'apply': $this->setRedirect('index.php?option=com_attachments&task=params.edit', $msg, 'message'); break; case 'save': default: $this->setRedirect('index.php?option=com_attachments', $msg, 'message'); break; } return true; }