Your IP : 216.73.216.84


Current Path : /home/helpink/www/administrator/components/com_jbusinessdirectory/controllers/
Upload File :
Current File : /home/helpink/www/administrator/components/com_jbusinessdirectory/controllers/discount.php

<?php
/**
 * @package    J-BusinessDirectory
 *
 * @author     CMSJunkie http://www.cmsjunkie.com/
 * @copyright  Copyright (C) 2007 - 2022 CMSJunkie. All rights reserved.
 * @license    https://www.gnu.org/licenses/agpl-3.0.en.html
 */
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.controllerform');

/**
 * Discount Controller
 *
 */
class JBusinessDirectoryControllerDiscount extends JControllerForm {
	/**
	 * Dummy method to redirect back to standard controller
	 *
	 */
	public function display($cachable = false, $urlparams = false) {
		$this->setRedirect(JRoute::_('index.php?option=com_jbusinessdirectory&view=discounts', false));
	}

	public function add() {
		$app     = JFactory::getApplication();
		$context = 'com_jbusinessdirectory.edit.discount';

		$result = parent::add();
		if ($result) {
			$this->setRedirect(JRoute::_('index.php?option=com_jbusinessdirectory&view=discount' . $this->getRedirectToItemAppend(), false));
		}

		return $result;
	}

	/**
	 * Method to cancel an edit.
	 *
	 * @param   string $key The name of the primary key of the URL variable.
	 *
	 * @return  boolean  True if access level checks pass, false otherwise.
	 */
	public function cancel($key = null) {
		JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));

		$app     = JFactory::getApplication();
		$context = 'com_jbusinessdirectory.edit.discount';
		$result  = parent::cancel();
	}

	/**
	 * Method to edit an existing record.
	 *
	 * @param   string $key    The name of the primary key of the URL variable.
	 * @param   string $urlVar The name of the URL variable if different from the primary key
	 *                         (sometimes required to avoid router collisions).
	 *
	 * @return  boolean  True if access level check and checkout passes, false otherwise.
	 *
	 */
	public function edit($key = null, $urlVar = null) {
		$app    = JFactory::getApplication();
		$result = parent::edit();

		return true;
	}

	/**
	 * save a record (and redirect to main page)
	 * @return void
	 */
	public function save($key = null, $urlVar = null) {
		// Check for request forgeries.
		JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
		$app      = JFactory::getApplication();
		$jinput   = $app->input;
		$model    = $this->getModel('discount');
		$data     = $jinput->post->getArray();
		$context  = 'com_jbusinessdirectory.edit.discount';
		$task     = $this->getTask();
		$recordId = $jinput->getInt('id');

		if (!$model->save($data)) {
			// Save the data in the session.
			$app->setUserState('com_jbusinessdirectory.edit.discount.data', $data);

			$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($recordId), false));

			return false;
		}

		$this->setMessage(JText::_('COM_JBUSINESSDIRECTORY_DISCOUNT_SAVE_SUCCESS'));

		// Redirect the user and adjust session state based on the chosen task.
		switch ($task) {
			case 'apply':
				// Set the row data in the session.
				$recordId = $model->getState($this->context . '.id');
				$this->holdEditId($context, $recordId);
				$app->setUserState('com_jbusinessdirectory.edit.discount.data', null);

				// Redirect back to the edit screen.
				$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($recordId), false));
				break;

			default:
				// Clear the row id and data in the session.
				$this->releaseEditId($context, $recordId);
				$app->setUserState('com_jbusinessdirectory.edit.discount.data', null);

				// Redirect to the list screen.
				$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list . $this->getRedirectToListAppend(), false));
				break;
		}
	}

	public function chageState() {
		$model = $this->getModel('Discount');

		if ($model->changeState()) {
			$msg = JText::_('');
		} else {
			$msg = JText::_('LNG_ERROR_CHANGE_STATE');
		}


		$this->setRedirect(JRoute::_('index.php?option=com_jbusinessdirectory&view=discounts', $msg));
	}

	public function generateDiscounts() {
		$model = $this->getModel('Discount');
		$data  = JFactory::getApplication()->input->post->getArray();

		if ($model->generateDiscounts($data)) {
			$msg = JText::_('');
		} else {
			$msg = JText::_('LNG_GENERATE_ERROR');
			$this->setMessage($msg, 'error');
		}

		$this->setRedirect(JRoute::_('index.php?option=com_jbusinessdirectory&view=discounts', false));
	}
}