| Current Path : /home/smartconb/www/armencom33/administrator/components/com_jmailalerts/controllers/ |
| Current File : /home/smartconb/www/armencom33/administrator/components/com_jmailalerts/controllers/subscriber.php |
<?php
/**
* @package JMailAlerts
* @subpackage com_jmailalerts
*
* @author Techjoomla <extensions@techjoomla.com>
* @copyright Copyright (C) 2009 - 2018 Techjoomla. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access
defined('_JEXEC') or die;
jimport('joomla.application.component.controllerform');
/**
* Subscriber controller class.
*
* @package JMailAlerts
* @subpackage com_jmailalerts
* @since 2.6.1
*/
class JmailalertsControllerSubscriber extends JControllerForm
{
/**
* Constructor
*
* @throws Exception
*/
public function __construct()
{
$this->view_list = 'subscribers';
parent::__construct();
}
/**
* Method to save a subscription data.
*
* @param string $key TO ADD
* @param string $urlVar TO ADD
*
* @return void|boolean
*
* @since 1.6
*/
public function save($key = null, $urlVar = null)
{
// Check for request forgeries.
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Initialise variables.
$app = JFactory::getApplication();
$model = $this->getModel('subscriber', 'JmailalertsModel');
// Get the subscription data.
$allJformData = JFactory::getApplication()->input->get('jform', array(), 'array');
// Validate the posted data.
$form = $model->getForm();
if (!$form)
{
JError::raiseError(500, $model->getError());
return false;
}
// Validate the posted data.
$data = $model->validate($form, $allJformData);
$return = $model->save($data);
// Check for errors.
if ($return === false)
{
/* Save the data in the session.*/
$app->setUserState('com_jmailalerts.edit.subscriber.data', $allJformData);
// Redirect back to the edit screen.
$id = (int) $app->getUserState('com_jmailalerts.edit.subscriber.id');
$this->setMessage(JText::sprintf('COM_JMAILALERTS_SUBSCRIPTION_ERROR_MSG_SAVE', $model->getError()), 'error');
$this->setRedirect(JRoute::_('index.php?option=com_jmailalerts&view=subscriber&layout=edit&id=' . $id, false));
return false;
}
$msg = JText::_('COM_JMAILALERTS_SUBSCRIPTION_SUCCESS_MSG_SAVE');
$input = JFactory::getApplication()->input;
$id = $input->get('id');
if (empty($id))
{
$id = $return;
}
$task = $input->get('task');
if ($task == 'apply')
{
$redirect = JRoute::_('index.php?option=com_jmailalerts&view=subscriber&layout=edit&id=' . $id, false);
$app->redirect($redirect, $msg);
}
if ($task == 'save2new')
{
$redirect = JRoute::_('index.php?option=com_jmailalerts&view=subscriber&layout=edit', false);
$app->redirect($redirect, $msg);
}
// Clear the profile id from the session.
$app->setUserState('com_jmailalerts.edit.subscriber.id', null);
// Check in the profile.
if ($return)
{
$model->checkin($return);
}
// Redirect to the list screen.
$redirect = JRoute::_('index.php?option=com_jmailalerts&view=subscribers', false);
$app->redirect($redirect, $msg);
// Flush the data from the session.
$app->setUserState('com_jmailalerts.edit.subscriber.data', null);
}
}