<?php
//echo __FILE__ . '<br>';
$optres['css'][] = $module_css_path . 'amodules/events_ext/css/events.css';
$optres['js'][] = $path . 'amodules/events_ext/js/events_main.js';

//echo '<pre>$_route = ', var_export($_route, true), '</pre>';
//echo '<pre>$events_config = ', var_export($events_config, true), '</pre>';

if($_route[0] == "category") {
    $categ_code = $_route[1];
    $categ_code_parts = explode("-", $categ_code);
    if (is_array($categ_code_parts) && count($categ_code_parts) == 2) {
        $event_srch['event_category'] = $categ_code;
    } else {
        $event_srch['event_category'] = intval($categ_code) . '-0';
    }
}
else {
    $town_str = str_replace('in-', '', $_route[0]);
    $town_dcode = '';
    foreach($events_config['locations'] as $dcode=>$loc) {
        if(strcmp(url_slug($loc['title']), $town_str) == 0) {
            $town_dcode = $dcode;
        }
    }

    if($town_dcode != '') {
        $event_srch['event_location'] = $town_dcode;
    }

    if(isset($_route['1']) && trim($_route['1']) == "category") {
        if(isset($_route['2']) && trim($_route['2']) != "") {
            $categ_code = $_route[2];
            $categ_code_parts = explode("-", $categ_code);
            if (is_array($categ_code_parts) && count($categ_code_parts) == 2) {
                $event_srch['event_category'] = $categ_code;
            } else {
                $event_srch['event_category'] = intval($categ_code) . '-0';
            }
        }
    }
}

require_once(dirname(__FILE__) . "/find_events.php");
