- md5
- a2018b4302040c7b20442b4690a3e685
- sha1
- 93ffd1033a9bb9c518679de4a52e9e0e4524e234
- sha256
- d4e884f158ed25965560a417fe465c4df88dd8b7114931bf0b6a4c79e949bcb8
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
<?php
/**
* @package Joomla.Administrator
* @subpackage com_languages
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die;
jimport('joomla.application.component.controllerform');
/**
* Languages Override Controller
*
* @package Joomla.Administrator
* @subpackage com_languages
* @since 2.5
*/
class LanguagesControllerOverride extends JControllerForm
{
/**
* Method to edit an existing override
*
* @return void
*
* @since 2.5
*/
public function edit()
{
// Initialize variables
$app = JFactory::getApplication();
$cid = JRequest::getVar('cid', array(), 'post', 'array');
$context = "$this->option.edit.$this->context";
// Get the constant name
$recordId = (count($cid) ? $cid[0] : JRequest::getCmd('id'));
// Access check
if (!$this->allowEdit())
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false));
return;
}
$app->setUserState($context.'.data', null);
$this->setRedirect('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId, 'id'));
}
/**
* Method to save an override
*
* @return void
*
* @since 2.5
*/
public function save()
{
// Check for request forgeries
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Initialize variables
$app = JFactory::getApplication();
$model = $this->getModel();
$data = JRequest::getVar('jform', array(), 'post', 'array');
$context = "$this->option.edit.$this->context";
$task = $this->getTask();
$recordId = JRequest::getCmd('id');
$data['id'] = $recordId;
// Access check
if (!$this->allowSave($data, 'id'))
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false));
return;
}
// Validate the posted data
$form = $model->getForm($data, false);
if (!$form)
{
$app->enqueueMessage($model->getError(), 'error');
return;
}
// Require helper for filter functions called by JForm
require_once JPATH_COMPONENT.'/helpers/languages.php';
// Test whether the data is valid.
$validData = $model->validate($form, $data);
// Check for validation errors.
if ($validData === 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($context.'.data', $data);
// Redirect back to the edit screen
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId, 'id'), false));
return;
}
// Attempt to save the data
if (!$model->save($validData))
{
// Save the data in the session
$app->setUserState($context.'.data', $validData);
// Redirect back to the edit screen
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId, 'id'), false));
return;
}
// Add message of success
$this->setMessage(JText::_('COM_LANGUAGES_VIEW_OVERRIDE_SAVE_SUCCESS'));
// Redirect the user and adjust session state based on the chosen task
switch ($task)
{
case 'apply':
// Set the record data in the session
$recordId = $model->getState($this->context.'.id');
$app->setUserState($context.'.data', null);
// Redirect back to the edit screen
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($validData['key'], 'id'), false));
break;
case 'save2new':
// Clear the record id and data from the session
$app->setUserState($context.'.data', null);
// Redirect back to the edit screen
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend(null, 'id'), false));
break;
default:
// Clear the record id and data from the session
$app->setUserState($context.'.data', null);
// Redirect to the list screen
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false));
break;
}
}
/**
* Method to cancel an edit
*
* @return void
*
* @since 2.5
*/
public function cancel()
{
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Initialize variables
$app = JFactory::getApplication();
$context = "$this->option.edit.$this->context";
$app->setUserState($context.'.data', null);
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false));
}
}
The same content is in 4 releases, Joomla 2.5.0 to 2.5.3. See them all, or every version of this file.