Esempio n. 1
0
 /**
  * Execute the controller.
  *
  * @return  boolean  True if controller finished execution, false if the controller did not
  *                   finish execution. A controller might return false if some precondition for
  *                   the controller to run has not been satisfied.
  *
  * @since   12.1
  * @throws  LogicException
  * @throws  RuntimeException
  */
 public function execute()
 {
     $model = new MonitorModelIssue();
     $id = $this->input->getInt('id');
     $user = JFactory::getUser();
     // Get the params
     // TODO: may be removed when new MVC is implemented completely
     $this->app = JFactory::getApplication();
     if ($this->app instanceof JApplicationSite) {
         $params = $this->app->getParams();
     }
     if (!$model->canEdit($user, $id)) {
         if ($user->guest && isset($params) && $params->get('redirect_login', 1)) {
             $this->app->enqueueMessage(JText::_('JGLOBAL_YOU_MUST_LOGIN_FIRST'), 'error');
             $this->app->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode(JUri::getInstance()->toString()), '403'));
         } else {
             throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403);
         }
     }
     if ($id) {
         $model->setIssueId($id);
     }
     $model->loadForm();
     $view = new MonitorViewIssueHtml($model);
     $view->setLayout('edit');
     $view->loadForm();
     echo $view->render();
     return true;
 }
Esempio n. 2
0
 /**
  * Method to remove root in global configuration.
  *
  * @return  boolean  True on success.
  *
  * @since   3.2
  */
 public function execute()
 {
     // Check for request forgeries.
     if (!JSession::checkToken('get')) {
         $this->app->enqueueMessage(JText::_('JINVALID_TOKEN'));
         $this->app->redirect('index.php');
     }
     // Check if the user is authorized to do this.
     if (!JFactory::getUser()->authorise('core.admin')) {
         $this->app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'));
         $this->app->redirect('index.php');
     }
     // Initialise model.
     $model = new ConfigModelApplication();
     // Attempt to save the configuration and remove root.
     try {
         $model->removeroot();
     } catch (RuntimeException $e) {
         // 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', false));
     }
     // Set the redirect based on the task.
     $this->app->enqueueMessage(JText::_('COM_CONFIG_SAVE_SUCCESS'));
     $this->app->redirect(JRoute::_('index.php', false));
 }
Esempio n. 3
0
 /**
  * Method to save global configuration.
  *
  * @return  boolean  True on success.
  *
  * @since   3.2
  */
 public function execute()
 {
     // Check for request forgeries.
     if (!JSession::checkToken()) {
         $this->app->enqueueMessage(JText::_('JINVALID_TOKEN'));
         $this->app->redirect('index.php');
     }
     // Check if the user is authorized to do this.
     if (!JFactory::getUser()->authorise('core.admin')) {
         $this->app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'));
         $this->app->redirect('index.php');
     }
     // Set FTP credentials, if given.
     JClientHelper::setCredentialsFromRequest('ftp');
     $model = new ConfigModelConfig();
     $form = $model->getForm();
     $data = $this->input->post->get('jform', array(), 'array');
     // 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&controller=config.display.config', false));
     }
     // Attempt to save the configuration.
     $data = $return;
     // Access back-end com_config
     JLoader::registerPrefix('Config', JPATH_ADMINISTRATOR . '/components/com_config');
     $saveClass = new ConfigControllerApplicationSave();
     // Get a document object
     $document = JFactory::getDocument();
     // Set back-end required params
     $document->setType('json');
     // Execute back-end controller
     $return = $saveClass->execute();
     // Reset params back after requesting from service
     $document->setType('html');
     // Check the return value.
     if ($return === false) {
         /*
          * The save 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);
         // Save failed, go back to the screen and display a notice.
         $this->app->redirect(JRoute::_('index.php?option=com_config&controller=config.display.config', false));
     }
     // Redirect back to com_config display
     $this->app->enqueueMessage(JText::_('COM_CONFIG_SAVE_SUCCESS'));
     $this->app->redirect(JRoute::_('index.php?option=com_config&controller=config.display.config', false));
     return true;
 }
Esempio n. 4
0
 public function __construct(&$subject, $config = array())
 {
     $this->app = JFactory::getApplication();
     JLoader::register('Gantry5\\Loader', JPATH_LIBRARIES . '/gantry5/Loader.php');
     // Detect Gantry Framework or fail gracefully.
     if (!class_exists('Gantry5\\Loader')) {
         if ($this->app->isAdmin()) {
             $this->loadLanguage('plg_system_gantry5.sys');
             $this->app->enqueueMessage(JText::sprintf('PLG_SYSTEM_GANTRY5_LIBRARY_MISSING', JText::_('PLG_SYSTEM_GANTRY5')), 'warning');
         }
         return;
     }
     parent::__construct($subject, $config);
 }
Esempio n. 5
0
 /**
  * Execute the controller.
  *
  * @return  boolean  True if controller finished execution, false if the controller did not
  *                   finish execution. A controller might return false if some precondition for
  *                   the controller to run has not been satisfied.
  *
  * @since   12.1
  * @throws  LogicException
  * @throws  RuntimeException
  */
 public function execute()
 {
     $id = $this->input->getInt('id');
     $user = JFactory::getUser();
     if ($user->guest) {
         $this->app->enqueueMessage(JText::_('JGLOBAL_YOU_MUST_LOGIN_FIRST'), 'error');
     } else {
         $model = new MonitorModelSubscription();
         if ($model->isSubscriberIssue($id, $user->id)) {
             $model->unsubscribeIssue($id, $user->id);
             $this->app->enqueueMessage(JText::_('COM_MONITOR_SUBSCRIPTION_ISSUE_UNSUBSCRIBED'), 'message');
         }
     }
     $this->app->redirect(JRoute::_('index.php?option=com_monitor&view=issue&id=' . $id, false));
 }
Esempio n. 6
0
 /**
  * Validates data from a form.
  *
  * @param   array  $data  The data to validate.
  * @param   JForm  $form  The form to use for validation.
  *
  * @return  mixed|bool  Array of filtered data if valid, false otherwise.
  *
  * @see ConfigModelForm::validate
  */
 public function validate($data, $form = null)
 {
     if (!$form) {
         if (!$this->form) {
             $this->loadForm();
         }
         $form = $this->form;
     }
     // Filter and validate the form data.
     $data = $form->filter($data);
     $return = $form->validate($data);
     // Store data for eventual redirects.
     $this->app->setUserState($form->getName() . '.data', $data);
     // Check for an error.
     if ($return instanceof Exception) {
         $this->app->enqueueMessage($return->getMessage(), 'error');
         return false;
     }
     // Check the validation results.
     if ($return === false) {
         // Get the validation messages from the form.
         foreach ($form->getErrors() as $message) {
             $this->app->enqueueMessage($message->getMessage(), 'error');
         }
         return false;
     }
     $this->app->setUserState($form->getName() . '.data', null);
     return $data;
 }
Esempio n. 7
0
 /**
  * Method to refresh help in global configuration.
  *
  * @return  boolean  True on success.
  *
  * @since   3.2
  */
 public function execute()
 {
     jimport('joomla.filesystem.file');
     // Set FTP credentials, if given
     JClientHelper::setCredentialsFromRequest('ftp');
     if (($data = file_get_contents('http://help.joomla.org/helpsites.xml')) === false) {
         $this->app->enqueueMessage(JText::_('COM_CONFIG_ERROR_HELPREFRESH_FETCH'), 'error');
         $this->app->redirect(JRoute::_('index.php?option=com_config', false));
     } elseif (!JFile::write(JPATH_BASE . '/help/helpsites.xml', $data)) {
         $this->app->enqueueMessage(JText::_('COM_CONFIG_ERROR_HELPREFRESH_ERROR_STORE'), 'error');
         $this->app->redirect(JRoute::_('index.php?option=com_config', false));
     } else {
         $this->app->enqueueMessage(JText::_('COM_CONFIG_HELPREFRESH_SUCCESS'), 'error');
         $this->app->redirect(JRoute::_('index.php?option=com_config', false));
     }
 }
Esempio n. 8
0
 /**
  * Check the PHP version after the admin component has been dispatched.
  *
  * @param   string  $context  The calling context
  *
  * @return  void
  *
  * @since   __DEPLOY_VERSION__
  */
 public function onGetIcons($context)
 {
     if (!$this->shouldDisplayMessage()) {
         return;
     }
     $supportStatus = $this->getPhpSupport();
     if ($supportStatus['status'] !== self::PHP_SUPPORTED) {
         // Enqueue the notification message; set a warning if receiving security support or "error" if unsupported
         switch ($supportStatus['status']) {
             case self::PHP_SECURITY_ONLY:
                 $this->app->enqueueMessage($supportStatus['message'], 'warning');
                 break;
             case self::PHP_UNSUPPORTED:
                 $this->app->enqueueMessage($supportStatus['message'], 'error');
                 break;
         }
     }
 }
Esempio n. 9
0
 /**
  * Execute the controller.
  *
  * @return  boolean  True if controller finished execution, false if the controller did not
  *                   finish execution. A controller might return false if some precondition for
  *                   the controller to run has not been satisfied.
  *
  * @since   12.1
  * @throws  LogicException
  * @throws  RuntimeException
  */
 public function execute()
 {
     $id = $this->input->getInt('id');
     $user = JFactory::getUser();
     if ($user->guest) {
         $this->app->enqueueMessage(JText::_('JGLOBAL_YOU_MUST_LOGIN_FIRST'), 'error');
     } else {
         $model = new MonitorModelSubscription();
         if (!$model->isSubscriberProject($id, $user->id)) {
             $model->subscribeProject($id, $user->id);
             $this->app->enqueueMessage(JText::_('COM_MONITOR_SUBSCRIPTION_PROJECT'), 'message');
         }
     }
     $return = base64_decode($this->app->input->get('return', '', 'BASE64'));
     if (!JUri::isInternal($return)) {
         $return = 'index.php?option=com_monitor&view=project&id=' . $id;
     }
     $this->app->redirect(JRoute::_($return, false));
 }
 /**
  * Execute the controller.
  *
  * @return  mixed  A rendered view or true
  *
  * @since   3.2
  */
 public function execute()
 {
     // Get the document object.
     $document = JFactory::getDocument();
     $componentFolder = $this->input->getWord('option', 'com_config');
     if ($this->app->isAdmin()) {
         $viewName = $this->input->getWord('view', 'application');
     } else {
         $viewName = $this->input->getWord('view', 'config');
     }
     $viewFormat = $document->getType();
     $layoutName = $this->input->getWord('layout', 'default');
     // Register the layout paths for the view
     $paths = new SplPriorityQueue();
     if ($this->app->isAdmin()) {
         $paths->insert(JPATH_ADMINISTRATOR . '/components/' . $componentFolder . '/view/' . $viewName . '/tmpl', 1);
     } else {
         $paths->insert(JPATH_BASE . '/components/' . $componentFolder . '/view/' . $viewName . '/tmpl', 1);
     }
     $viewClass = $this->prefix . 'View' . ucfirst($viewName) . ucfirst($viewFormat);
     $modelClass = $this->prefix . 'Model' . ucfirst($viewName);
     if (class_exists($viewClass)) {
         $model = new $modelClass();
         $component = $model->getState()->get('component.option');
         // Access check.
         if (!JFactory::getUser()->authorise('core.admin', $component) && !JFactory::getUser()->authorise('core.options', $component)) {
             $this->app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'error');
             return;
         }
         $view = new $viewClass($model, $paths);
         $view->setLayout($layoutName);
         // Push document object into the view.
         $view->document = $document;
         // Reply for service requests
         if ($viewFormat == 'json') {
             return $view->render();
         }
         // Render view.
         echo $view->render();
     }
     return true;
 }
Esempio n. 11
0
 /**
  * This method should handle any login logic and report back to the subject
  *
  * @param   array  $user     Holds the user data
  * @param   array  $options  Array holding options (remember, autoregister, group)
  *
  * @return  boolean  True on success
  *
  * @since   1.5
  */
 public function onUserLogin($user, $options = array())
 {
     $instance = $this->_getUser($user, $options);
     // If _getUser returned an error, then pass it back.
     if ($instance instanceof Exception) {
         return false;
     }
     // If the user is blocked, redirect with an error
     if ($instance->block == 1) {
         $this->app->enqueueMessage(JText::_('JERROR_NOLOGIN_BLOCKED'), 'warning');
         return false;
     }
     // Authorise the user based on the group information
     if (!isset($options['group'])) {
         $options['group'] = 'USERS';
     }
     // Check the user can login.
     $result = $instance->authorise($options['action']);
     if (!$result) {
         $this->app->enqueueMessage(JText::_('JERROR_LOGIN_DENIED'), 'warning');
         return false;
     }
     // Mark the user as logged in
     $instance->guest = 0;
     $session = JFactory::getSession();
     // Grab the current session ID
     $oldSessionId = $session->getId();
     // Fork the session
     $session->fork();
     $session->set('user', $instance);
     // Ensure the new session's metadata is written to the database
     $this->app->checkSession();
     // Purge the old session
     $query = $this->db->getQuery(true)->delete('#__session')->where($this->db->quoteName('session_id') . ' = ' . $this->db->quote($oldSessionId));
     try {
         $this->db->setQuery($query)->execute();
     } catch (RuntimeException $e) {
         // The old session is already invalidated, don't let this block logging in
     }
     // Hit the user last visit field
     $instance->setLastVisit();
     // Add "user state" cookie used for reverse caching proxies like Varnish, Nginx etc.
     $conf = JFactory::getConfig();
     $cookie_domain = $conf->get('cookie_domain', '');
     $cookie_path = $conf->get('cookie_path', '/');
     if ($this->app->isSite()) {
         $this->app->input->cookie->set("joomla_user_state", "logged_in", 0, $cookie_path, $cookie_domain, 0);
     }
     return true;
 }
Esempio n. 12
0
 /**
  * This method should handle any login logic and report back to the subject
  *
  * @param   array  $user     Holds the user data
  * @param   array  $options  Array holding options (remember, autoregister, group)
  *
  * @return  boolean  True on success
  *
  * @since   1.5
  */
 public function onUserLogin($user, $options = array())
 {
     $instance = $this->_getUser($user, $options);
     // If _getUser returned an error, then pass it back.
     if ($instance instanceof Exception) {
         return false;
     }
     // If the user is blocked, redirect with an error
     if ($instance->get('block') == 1) {
         $this->app->enqueueMessage(JText::_('JERROR_NOLOGIN_BLOCKED'), 'warning');
         return false;
     }
     // Authorise the user based on the group information
     if (!isset($options['group'])) {
         $options['group'] = 'USERS';
     }
     // Check the user can login.
     $result = $instance->authorise($options['action']);
     if (!$result) {
         $this->app->enqueueMessage(JText::_('JERROR_LOGIN_DENIED'), 'warning');
         return false;
     }
     // Mark the user as logged in
     $instance->set('guest', 0);
     // Register the needed session variables
     $session = JFactory::getSession();
     $session->set('user', $instance);
     // Check to see the the session already exists.
     $this->app->checkSession();
     // Update the user related fields for the Joomla sessions table.
     $query = $this->db->getQuery(true)->update($this->db->quoteName('#__session'))->set($this->db->quoteName('guest') . ' = ' . $this->db->quote($instance->guest))->set($this->db->quoteName('username') . ' = ' . $this->db->quote($instance->username))->set($this->db->quoteName('userid') . ' = ' . (int) $instance->id)->where($this->db->quoteName('session_id') . ' = ' . $this->db->quote($session->getId()));
     try {
         $this->db->setQuery($query)->execute();
     } catch (RuntimeException $e) {
         return false;
     }
     // Hit the user last visit field
     $instance->setLastVisit();
     // Add "user state" cookie used for reverse caching proxies like Varnish, Nginx etc.
     $conf = JFactory::getConfig();
     $cookie_domain = $conf->get('cookie_domain', '');
     $cookie_path = $conf->get('cookie_path', '/');
     if ($this->app->isSite()) {
         $this->app->input->cookie->set("joomla_user_state", "logged_in", 0, $cookie_path, $cookie_domain, 0);
     }
     return true;
 }
 /**
  * This method should handle any login logic and report back to the subject
  *
  * @param   array  $user     Holds the user data
  * @param   array  $options  Array holding options (remember, autoregister, group)
  *
  * @return  boolean  True on success
  *
  * @since   1.5
  */
 public function onUserLogin($user, $options = array())
 {
     $instance = $this->_getUser($user, $options);
     // If _getUser returned an error, then pass it back.
     if ($instance instanceof Exception) {
         return false;
     }
     // If the user is blocked, redirect with an error
     if ($instance->get('block') == 1) {
         $this->app->enqueueMessage(JText::_('JERROR_NOLOGIN_BLOCKED'), 'warning');
         return false;
     }
     // Authorise the user based on the group information
     if (!isset($options['group'])) {
         $options['group'] = 'USERS';
     }
     // Check the user can login.
     $result = $instance->authorise($options['action']);
     if (!$result) {
         $this->app->enqueueMessage(JText::_('JERROR_LOGIN_DENIED'), 'warning');
         return false;
     }
     // Mark the user as logged in
     $instance->set('guest', 0);
     // If the user has an outdated hash, update it.
     if (substr($user['password'], 0, 4) != '$2y$' && $this->useStrongEncryption && JCrypt::hasStrongPasswordSupport() == true) {
         if (strlen($user['password']) > 55) {
             $user['password'] = substr($user['password'], 0, 55);
             JFactory::getApplication()->enqueueMessage(JText::_('JLIB_USER_ERROR_PASSWORD_TRUNCATED'), 'notice');
         }
         $instance->password = password_hash($user['password'], PASSWORD_BCRYPT);
         $instance->save();
     }
     // Register the needed session variables
     $session = JFactory::getSession();
     $session->set('user', $instance);
     // Check to see the the session already exists.
     $this->app->checkSession();
     // Update the user related fields for the Joomla sessions table.
     $query = $this->db->getQuery(true)->update($this->db->quoteName('#__session'))->set($this->db->quoteName('guest') . ' = ' . $this->db->quote($instance->guest))->set($this->db->quoteName('username') . ' = ' . $this->db->quote($instance->username))->set($this->db->quoteName('userid') . ' = ' . (int) $instance->id)->where($this->db->quoteName('session_id') . ' = ' . $this->db->quote($session->getId()));
     $this->db->setQuery($query)->execute();
     // Hit the user last visit field
     $instance->setLastVisit();
     return true;
 }
Esempio n. 14
0
File: joomla.php Progetto: 01J/topm
 /**
  * This method should handle any login logic and report back to the subject
  *
  * @param   array  $user     Holds the user data
  * @param   array  $options  Array holding options (remember, autoregister, group)
  *
  * @return  boolean  True on success
  *
  * @since   1.5
  */
 public function onUserLogin($user, $options = array())
 {
     $instance = $this->_getUser($user, $options);
     // If _getUser returned an error, then pass it back.
     if ($instance instanceof Exception) {
         return false;
     }
     // If the user is blocked, redirect with an error
     if ($instance->get('block') == 1) {
         $this->app->enqueueMessage(JText::_('JERROR_NOLOGIN_BLOCKED'), 'warning');
         return false;
     }
     // Authorise the user based on the group information
     if (!isset($options['group'])) {
         $options['group'] = 'USERS';
     }
     // Check the user can login.
     $result = $instance->authorise($options['action']);
     if (!$result) {
         $this->app->enqueueMessage(JText::_('JERROR_LOGIN_DENIED'), 'warning');
         return false;
     }
     // Mark the user as logged in
     $instance->set('guest', 0);
     // Register the needed session variables
     $session = JFactory::getSession();
     $session->set('user', $instance);
     // Check to see the the session already exists.
     $this->app->checkSession();
     // Update the user related fields for the Joomla sessions table.
     $query = $this->db->getQuery(true)->update($this->db->quoteName('#__session'))->set($this->db->quoteName('guest') . ' = ' . $this->db->quote($instance->guest))->set($this->db->quoteName('username') . ' = ' . $this->db->quote($instance->username))->set($this->db->quoteName('userid') . ' = ' . (int) $instance->id)->where($this->db->quoteName('session_id') . ' = ' . $this->db->quote($session->getId()));
     $this->db->setQuery($query)->execute();
     // Hit the user last visit field
     $instance->setLastVisit();
     return true;
 }
Esempio n. 15
0
 /**
  * Method to save global configuration.
  *
  * @return  mixed  Calls $app->redirect() for all cases except JSON
  *
  * @since   3.2
  */
 public function execute()
 {
     // Check for request forgeries.
     if (!JSession::checkToken()) {
         $this->app->enqueueMessage(JText::_('JINVALID_TOKEN'));
         $this->app->redirect('index.php');
     }
     // Check if the user is authorized to do this.
     if (!JFactory::getUser()->authorise('core.admin')) {
         $this->app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'));
         $this->app->redirect('index.php');
     }
     // Set FTP credentials, if given.
     JClientHelper::setCredentialsFromRequest('ftp');
     $model = new ConfigModelApplication();
     $data = $this->input->post->get('jform', array(), 'array');
     // Complete data array if needed
     $oldData = $model->getData();
     $data = array_replace($oldData, $data);
     // Get request type
     $saveFormat = JFactory::getDocument()->getType();
     // Handle service requests
     if ($saveFormat == 'json') {
         return $model->save($data);
     }
     // Must load after serving service-requests
     $form = $model->getForm();
     // 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&controller=config.display.application', false));
     }
     // Attempt to save the configuration.
     $data = $return;
     $return = $model->save($data);
     // Check the return value.
     if ($return === false) {
         /*
          * The save 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);
         // Save failed, go back to the screen and display a notice.
         $this->app->redirect(JRoute::_('index.php?option=com_config&controller=config.display.application', false));
     }
     // Set the success message.
     $this->app->enqueueMessage(JText::_('COM_CONFIG_SAVE_SUCCESS'));
     // Set the redirect based on the task.
     switch ($this->options[3]) {
         case 'apply':
             $this->app->redirect(JRoute::_('index.php?option=com_config', false));
             break;
         case 'save':
         default:
             $this->app->redirect(JRoute::_('index.php', false));
             break;
     }
 }
Esempio n. 16
0
 /**
  * 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;
 }
Esempio n. 17
0
 /**
  * Get tab categories and merge as necessary to get down to tab limit
  *
  * @return   array  Tabs
  */
 private function getTabCategories()
 {
     /**
      * 2013-07-19 Paul - This function determines the tabs to be shown at the top of the list table.
      * The tabs are defined by the contents of a user specified field e.g for alphabetic tabs you might
      * use a calc field with the first character of a surname.
      * To prevent a list of
      **/
     $params = $this->getParams();
     $tabsField = $tabsElName = $this->getTabField();
     if (empty($tabsField)) {
         return array();
     }
     list($tableName, $tabsField) = explode('___', $tabsField);
     $table = $this->getTable();
     if ($tableName != $table->db_table_name) {
         $this->app->enqueueMessage(sprintf(FText::_('COM_FABRIK_LIST_TABS_TABLE_ERROR'), $tableName, $table->db_table_name), 'error');
         return array();
     }
     $tabsMax = (int) $params->get('tabs_max', 10);
     $tabsAll = (bool) $params->get('tabs_all', '1');
     // @FIXME - starting to implement code to handle join elements, not cooked yet
     $formModel = $this->getFormModel();
     $elementModel = $formModel->getElement($tabsElName);
     $is_join = is_subclass_of($elementModel, 'PlgFabrik_ElementDatabasejoin') || get_class($elementModel) == 'PlgFabrik_ElementDatabasejoin';
     if (!$is_join) {
         // Get values and count in the tab field
         $db = $this->getDb();
         $query = $db->getQuery(true);
         $query->select(array($tabsField, 'Count(' . $tabsField . ') as count'))->from($db->qn($table->db_table_name))->group($tabsField)->order($tabsField);
     } else {
         $this->app->enqueueMessage(sprintf(FText::_('COM_FABRIK_LIST_TABS_TABLE_ERROR'), $tableName, $table->db_table_name), 'error');
         $joinTable = $elementModel->getJoinModel()->getJoin();
         $fullFk = $joinTable->table_join . '___' . $joinTable->table_join_key;
         return array();
     }
     /**
     		 * Filters include any existing tab filters - so we cannot calculate tabs based on any user set filters
     		 * or pre-filters, until we can exclude them from being used here.
     		 $this->buildQueryWhere($this->app->input->getInt('incfilters', 1), $query, false);
     		 **/
     $db->setQuery($query);
     FabrikHelperHTML::debug($query->dump(), 'list getTabCategories query:' . $table->label);
     $profiler = JProfiler::getInstance('Application');
     JDEBUG ? $profiler->mark('before fabrik list tabs query run') : null;
     $db->execute();
     $counts = $db->loadRowList();
     JDEBUG ? $profiler->mark('after fabrik list tabs query run') : null;
     FabrikHelperHTML::debug($counts, 'list getTabCategories counts: ' . $table->label);
     /**
      * We consolidate by finding the two consecutive rows with the smallest total and merging them.
      * To avoid excessive looping if user tabField is too fragmented, we should skip tabs if
      * we will iterate more than 100 times.
      **/
     if (count($counts) - $tabsMax > 100) {
         $this->app->enqueueMessage(sprintf(FText::_('COM_FABRIK_LIST_TABS_MERGE_ERROR'), count($counts), $tabsMax), 'notice');
         return array();
     }
     $tabs = array();
     if ($tabsAll) {
         // Set value to null to differentiate between all and empty string values
         $tabs[] = array(FText::_('COM_FABRIK_LIST_TABS_ALL'), null);
     }
     while (count($counts) > $tabsMax) {
         /**
          * Primary algorithm is to find the two consecutive rows whose total count is smallest and merge them.
          *
          * If this turns out to be too time consuming in real-life scenarios, we can add further optimisation
          * by adding logic to the loop so that first time through it sums the total of count, and
          * second time through it merges any consecutive rows whose values total less than a small proportion (say 1/4)
          * of the total count / tabs. This will not be completely optimum but will be a whole lot quicker for many small
          * categories than the base iteration. Using 1/4 should result in no more than 3 further iterations per tab to get to
          * the number of tabs required. In this case we can probably remove the test / error message above.
          **/
         $minCount = 999999999;
         $minIndex = 0;
         for ($i = 1; $i < count($counts); $i++) {
             $totCount = $counts[$i - 1][1] + $counts[$i][1];
             if ($totCount < $minCount) {
                 $minCount = $totCount;
                 $minIndex = $i;
             }
         }
         // Merge mins
         $counts[$minIndex - 1][0] = (array) $counts[$minIndex - 1][0];
         $counts[$minIndex][0] = (array) $counts[$minIndex][0];
         $counts[$minIndex - 1][0] = array($counts[$minIndex - 1][0][0], end($counts[$minIndex][0]));
         $counts[$minIndex - 1][1] += $counts[$minIndex][1];
         // Array_splice not working as advertised - working like array_slice for some reason!!
         // $counts = array_splice($counts, $minIndex, 1);
         unset($counts[$minIndex]);
         $counts = array_values($counts);
     }
     JDEBUG ? $profiler->mark('after fabrik list tabs counts merge') : null;
     FabrikHelperHTML::debug($counts, 'list getTabCategories merged counts: ' . $table->label);
     for ($i = 0; $i < count($counts); $i++) {
         if (is_array($counts[$i][0])) {
             $tabs[] = array($counts[$i][0][0] . '-' . $counts[$i][0][1], $counts[$i][0]);
         } else {
             $tabLabel = empty($counts[$i][0]) ? '-' : $counts[$i][0];
             $tabs[] = array($tabLabel, $counts[$i][0]);
         }
     }
     return $tabs;
 }
Esempio n. 18
0
 /**
  * Process a certain field.
  *
  * @param   JApplicationCms  $app        Application object
  * @param   string           $table_name The name of the table that contains the field.
  * @param   SimpleXMLElement $field      Field Information.
  *
  * @return void
  */
 private function processField($app, $table_name, $field)
 {
     $db = JFactory::getDbo();
     if (isset($field['action'])) {
         switch ($field['action']) {
             case 'add':
                 $result = $this->addField($table_name, $field);
                 if ($result === MODIFIED) {
                     $app->enqueueMessage(JText::sprintf('Field `%s` has been successfully added', $field['field_name']));
                 } else {
                     if ($result !== NOT_MODIFIED) {
                         $app->enqueueMessage(JText::sprintf('There was an error adding the field `%s`. Error: %s', $field['field_name'], $result), 'error');
                     }
                 }
                 break;
             case 'change':
                 if (isset($field['old_name']) && isset($field['new_name'])) {
                     if ($this->existsField($table_name, $field['old_name'])) {
                         $renaming_statement = JText::sprintf('ALTER TABLE %s CHANGE %s %s %s', $table_name, $field['old_name'], $field['new_name'], $this->getFieldType($field));
                         $db->setQuery($renaming_statement);
                         try {
                             $db->execute();
                             $app->enqueueMessage(JText::sprintf('Field `%s` has been successfully modified', $field['old_name']));
                         } catch (Exception $ex) {
                             $app->enqueueMessage(JText::sprintf('There was an error modifying the field `%s`. Error: %s', $field['field_name'], $ex->getMessage()), 'error');
                         }
                     } else {
                         $result = $this->addField($table_name, $field);
                         if ($result === MODIFIED) {
                             $app->enqueueMessage(JText::sprintf('Field `%s` has been successfully modified', $field['field_name']));
                         } else {
                             if ($result !== NOT_MODIFIED) {
                                 $app->enqueueMessage(JText::sprintf('There was an error modifying the field `%s`. Error: %s', $field['field_name'], $result), 'error');
                             }
                         }
                     }
                 } else {
                     $result = $this->addField($table_name, $field);
                     if ($result === MODIFIED) {
                         $app->enqueueMessage(JText::sprintf('Field `%s` has been successfully added', $field['field_name']));
                     } else {
                         if ($result !== NOT_MODIFIED) {
                             $app->enqueueMessage(JText::sprintf('There was an error adding the field `%s`. Error: %s', $field['field_name'], $result), 'error');
                         }
                     }
                 }
                 break;
             case 'remove':
                 // Check if the field exists first to prevent issue removing the field
                 if ($this->existsField($table_name, $field['field_name'])) {
                     $drop_statement = JText::sprintf('ALTER TABLE %s DROP COLUMN %s', $table_name, $field['field_name']);
                     $db->setQuery($drop_statement);
                     try {
                         $db->execute();
                         $app->enqueueMessage(JText::sprintf('Field `%s` has been successfully deleted', $field['field_name']));
                     } catch (Exception $ex) {
                         $app->enqueueMessage(JText::sprintf('There was an error deleting the field `%s`. Error: %s', $field['field_name'], $ex->getMessage()), 'error');
                     }
                 }
                 break;
         }
     } else {
         $result = $this->addField($table_name, $field);
         if ($result === MODIFIED) {
             $app->enqueueMessage(JText::sprintf('Field `%s` has been successfully added', $field['field_name']));
         } else {
             if ($result !== NOT_MODIFIED) {
                 $app->enqueueMessage(JText::sprintf('There was an error adding the field `%s`. Error: %s', $field['field_name'], $result), 'error');
             }
         }
     }
 }