| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Administrator 4 * @subpackage com_config 5 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE.txt 7 */ 8 9 // no direct access 10 defined('_JEXEC') or die; 11 12 /** 13 * Note: this view is intended only to be opened in a popup 14 * @package Joomla.Administrator 15 * @subpackage com_config 16 */ 17 class ConfigControllerComponent extends JController 18 { 19 /** 20 * Class Constructor 21 * 22 * @param array $config An optional associative array of configuration settings. 23 * @return void 24 * @since 1.5 25 */ 26 function __construct($config = array()) 27 { 28 parent::__construct($config); 29 30 // Map the apply task to the save method. 31 $this->registerTask('apply', 'save'); 32 } 33 34 /** 35 * Save the configuration 36 */ 37 function save() 38 { 39 // Check for request forgeries. 40 JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); 41 42 // Set FTP credentials, if given. 43 JClientHelper::setCredentialsFromRequest('ftp'); 44 45 // Initialise variables. 46 $app = JFactory::getApplication(); 47 $model = $this->getModel('Component'); 48 $form = $model->getForm(); 49 $data = JRequest::getVar('jform', array(), 'post', 'array'); 50 $id = JRequest::getInt('id'); 51 $option = JRequest::getCmd('component'); 52 53 // Check if the user is authorized to do this. 54 if (!JFactory::getUser()->authorise('core.admin', $option)) 55 { 56 JFactory::getApplication()->redirect('index.php', JText::_('JERROR_ALERTNOAUTHOR')); 57 return; 58 } 59 60 // Validate the posted data. 61 $return = $model->validate($form, $data); 62 63 // Check for validation errors. 64 if ($return === false) { 65 // Get the validation messages. 66 $errors = $model->getErrors(); 67 68 // Push up to three validation messages out to the user. 69 for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { 70 if ($errors[$i] instanceof Exception) { 71 $app->enqueueMessage($errors[$i]->getMessage(), 'warning'); 72 } else { 73 $app->enqueueMessage($errors[$i], 'warning'); 74 } 75 } 76 77 // Save the data in the session. 78 $app->setUserState('com_config.config.global.data', $data); 79 80 // Redirect back to the edit screen. 81 $this->setRedirect(JRoute::_('index.php?option=com_config&view=component&component='.$option.'&tmpl=component', false)); 82 return false; 83 } 84 85 // Attempt to save the configuration. 86 $data = array( 87 'params' => $return, 88 'id' => $id, 89 'option' => $option 90 ); 91 $return = $model->save($data); 92 93 // Check the return value. 94 if ($return === false) 95 { 96 // Save the data in the session. 97 $app->setUserState('com_config.config.global.data', $data); 98 99 // Save failed, go back to the screen and display a notice. 100 $message = JText::sprintf('JERROR_SAVE_FAILED', $model->getError()); 101 $this->setRedirect('index.php?option=com_config&view=component&component='.$option.'&tmpl=component', $message, 'error'); 102 return false; 103 } 104 105 // Set the redirect based on the task. 106 switch ($this->getTask()) 107 { 108 case 'apply': 109 $message = JText::_('COM_CONFIG_SAVE_SUCCESS'); 110 $this->setRedirect('index.php?option=com_config&view=component&component='.$option.'&tmpl=component&refresh=1', $message); 111 break; 112 113 case 'save': 114 default: 115 $this->setRedirect('index.php?option=com_config&view=close&tmpl=component'); 116 break; 117 } 118 119 return true; 120 } 121 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |