Source for file override.php

Documentation is available at override.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_languages
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Languages Override Controller
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_languages
  17.  * @since       2.5
  18.  */
  19. {
  20.     /**
  21.      * Method to edit an existing override
  22.      *
  23.      * @param       string    $key        The name of the primary key of the URL variable (not used here).
  24.      * @param       string    $urlVar    The name of the URL variable if different from the primary key (not used here).
  25.      *
  26.      * @return  void 
  27.      *
  28.      * @since        2.5
  29.      */
  30.     public function edit($key null$urlVar null)
  31.     {
  32.         $app     JFactory::getApplication();
  33.         $cid     $this->input->post->get('cid'array()'array');
  34.         $context "$this->option.edit.$this->context";
  35.  
  36.         // Get the constant name
  37.         $recordId (count($cid$cid[0$this->input->get('id'));
  38.  
  39.         // Access check
  40.         if (!$this->allowEdit())
  41.         {
  42.             $this->setError(JText::_('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'));
  43.             $this->setMessage($this->getError()'error');
  44.             $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend()false));
  45.  
  46.             return;
  47.         }
  48.  
  49.         $app->setUserState($context.'.data'null);
  50.         $this->setRedirect('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId'id'));
  51.     }
  52.  
  53.     /**
  54.      * Method to save an override
  55.      *
  56.      * @param       string    $key        The name of the primary key of the URL variable (not used here).
  57.      * @param       string    $urlVar    The name of the URL variable if different from the primary key (not used here).
  58.      *
  59.      * @return  void 
  60.      *
  61.      * @since        2.5
  62.      */
  63.     public function save($key null$urlVar null)
  64.     {
  65.         // Check for request forgeries
  66.         JSession::checkToken(or jexit(JText::_('JINVALID_TOKEN'));
  67.  
  68.         $app     JFactory::getApplication();
  69.         $model   $this->getModel();
  70.         $data    $this->input->post->get('jform'array()'array');
  71.         $context "$this->option.edit.$this->context";
  72.         $task    $this->getTask();
  73.  
  74.         $recordId $this->input->get('id');
  75.         $data['id'$recordId;
  76.  
  77.         // Access check
  78.         if (!$this->allowSave($data'id'))
  79.         {
  80.             $this->setError(JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'));
  81.             $this->setMessage($this->getError()'error');
  82.             $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend()false));
  83.  
  84.             return;
  85.         }
  86.  
  87.         // Validate the posted data
  88.         $form $model->getForm($datafalse);
  89.         if (!$form)
  90.         {
  91.             $app->enqueueMessage($model->getError()'error');
  92.  
  93.             return;
  94.         }
  95.  
  96.         // Require helper for filter functions called by JForm
  97.         require_once JPATH_COMPONENT.'/helpers/languages.php';
  98.  
  99.         // Test whether the data is valid.
  100.         $validData $model->validate($form$data);
  101.  
  102.         // Check for validation errors.
  103.         if ($validData === false)
  104.         {
  105.             // Get the validation messages
  106.             $errors    $model->getErrors();
  107.  
  108.             // Push up to three validation messages out to the user.
  109.             for ($i 0$n count($errors)$i $n && $i 3$i++)
  110.             {
  111.                 if ($errors[$iinstanceof Exception)
  112.                 {
  113.                     $app->enqueueMessage($errors[$i]->getMessage()'warning');
  114.                 }
  115.                 else
  116.                 {
  117.                     $app->enqueueMessage($errors[$i]'warning');
  118.                 }
  119.             }
  120.  
  121.             // Save the data in the session
  122.             $app->setUserState($context.'.data'$data);
  123.  
  124.             // Redirect back to the edit screen
  125.             $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId'id')false));
  126.  
  127.             return;
  128.         }
  129.  
  130.         // Attempt to save the data
  131.         if (!$model->save($validData))
  132.         {
  133.             // Save the data in the session
  134.             $app->setUserState($context.'.data'$validData);
  135.  
  136.             // Redirect back to the edit screen
  137.             $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED'$model->getError()));
  138.             $this->setMessage($this->getError()'error');
  139.             $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId'id')false));
  140.  
  141.             return;
  142.         }
  143.  
  144.         // Add message of success
  145.         $this->setMessage(JText::_('COM_LANGUAGES_VIEW_OVERRIDE_SAVE_SUCCESS'));
  146.  
  147.         // Redirect the user and adjust session state based on the chosen task
  148.         switch ($task)
  149.         {
  150.             case 'apply':
  151.                 // Set the record data in the session
  152.                 $app->setUserState($context.'.data'null);
  153.  
  154.                 // Redirect back to the edit screen
  155.                 $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($validData['key']'id')false));
  156.                 break;
  157.  
  158.             case 'save2new':
  159.                 // Clear the record id and data from the session
  160.                 $app->setUserState($context.'.data'null);
  161.  
  162.                 // Redirect back to the edit screen
  163.                 $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend(null'id')false));
  164.                 break;
  165.  
  166.             default:
  167.                 // Clear the record id and data from the session
  168.                 $app->setUserState($context.'.data'null);
  169.  
  170.                 // Redirect to the list screen
  171.                 $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend()false));
  172.                 break;
  173.         }
  174.     }
  175.  
  176.     /**
  177.      * Method to cancel an edit
  178.      *
  179.      * @param       string    $key    The name of the primary key of the URL variable (not used here).
  180.      *
  181.      * @return  void 
  182.      *
  183.      * @since        2.5
  184.      */
  185.     public function cancel($key null$test null)
  186.     {
  187.         JSession::checkToken(or jexit(JText::_('JINVALID_TOKEN'));
  188.  
  189.         $app     JFactory::getApplication();
  190.         $context "$this->option.edit.$this->context";
  191.  
  192.         $app->setUserState($context.'.data',    null);
  193.         $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend()false));
  194.     }
  195. }

Documentation generated on Tue, 19 Nov 2013 15:09:56 +0100 by phpDocumentor 1.4.3