<?php
/**
 * @package DJ-Events
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 * @developer Szymon Woronowski - szymon.woronowski@design-joomla.eu
 *
 */

defined ('_JEXEC') or die('Restricted access');

if (!defined('DS')) {
	define('DS', DIRECTORY_SEPARATOR);
}

require_once(JPATH_BASE.DS.'components'.DS.'com_djevents'.DS.'helpers'.DS.'djevents.php');

$app = JFactory::getApplication();

DJEventsHelper::setAssets();
$lang = JFactory::GetLanguage();
$lang->load('com_djevents');

JModelLegacy::addIncludePath('components/com_djevents/models', 'DJEventsModel');
$model = JModelLegacy::getInstance('EventsList', 'DJEventsModel', array('ignore_request'=>true));

if($params->get('use_as_filter')) {
    $category = $app->input->get('cid');
    $city = $app->input->get('city');
    $location = $app->input->get('location');


    if($app->input->get('from')) {
        $model->setState('filter.from', $app->input->get('from'));
    }

    if($app->input->get('to')) {
        $model->setState('filter.to', $app->input->get('to'));
    }
    $model->setState('filter.category', $category);
    $model->setState('filter.city', $city);
    $model->setState('filter.location', $location);

}

$options = array();
$options['categories'] = $model->getCategories($params->get('use_as_filter'));
$options['cities'] = $model->getCities(0, $params->get('use_as_filter'));
$options['locations'] = $model->getLocations(0, $params->get('use_as_filter'));

$Itemid = $app->input->get('Itemid', 0, 'int');

// Include module js
$doc = JFactory::getDocument();
$doc->addScript(JUri::base() . '/modules/mod_djevents_search/assets/js/script.js');

require(JModuleHelper::getLayoutPath('mod_djevents_search'));
