<?php
$def_event_srch = array(
    'event_category' => '',
    'event_location' => '',
    'event_period' => '',
    'event_keyword' => '',
    'i_limit' => 10,
    'i_from' => 0
);

$form_title = 'Search Events';

if(!isset($event_srch)) {
    $event_srch = $def_event_srch;
}
else {
    $event_srch = array_merge($def_event_srch, $event_srch);
}

if(isset($past_events) && $past_events) {
    $event_srch['event_period'] = 'past';
    $form_title = 'Search Past Events';
}

$global_js['event_srch'] = $event_srch;

//echo '<pre>$event_srch = ', var_export($event_srch, true), '</pre>';
?>


<div class="row">
    <div class="col-sm-10">

        <form method="post" action="events/" name="events_search_frm" id="events_search_frm" class="form-horizontal role="form">
            <section class="evsrch_container box box-srch">
                <div class="box-srch-header">
                    <a class="trigger-collapse" data-toggle="collapse" href="#event-search-form" aria-expanded="false" aria-controls="event-search-form">
                        <b><i class="fa fa-search fa-fw fa-lg"></i> <?=$form_title;?></b>
                        <span class="pull-right clickable"><i class="glyphicon glyphicon-chevron-down"></i></span>
                    </a>
                </div>

                <div class="box-body collapse" id="event-search-form">

                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-5">
                                <div class="form-group">
                                    <label class="control-label sr-only" for="event_category"><?php echo 'Event Category';?></label>
                                    <select name="event_srch[event_category]" id="event_category" class=" event-selectbox show-menu-arrow form-control input-sm" data-title="All Categories">
                                        <option value="" <?php echo ($event_srch['event_category'] == '' ? 'selected="selected"' : '');?>><?php echo 'All Categories';?></option>
                                        <?php
                                        $all_event_categs = $events_config['categories'];
                                        foreach ($all_event_categs as $gr_id => $gr_data){
                                            $categ_code = $gr_id;
                                            $selected = '';
                                            if($event_srch['event_category'] == $categ_code) $selected = ' selected="selected"';
                                            echo '<option value="',$categ_code,'" ',$selected,' class="event-category-group">', $gr_data['title'], '</option>';
                                            if(count($gr_data['subs']) > 0) {
                                                foreach($gr_data['subs'] as $cat_id=>$cat_title) {
                                                    $categ_code = $gr_id . '-' . $cat_id;
                                                    $selected = '';
                                                    if($event_srch['event_category'] == $categ_code) $selected = ' selected="selected"';
                                                    echo '<option value="',$categ_code,'" ',$selected,' class="event-category-opt">', $cat_title, '</option>';
                                                }
                                            }
                                        }

                                        ?>
                                    </select>
                                </div>
                            </div>
                            <div class="col-sm-5">
                                <div class="form-group sm-no-margin-left">
                                    <label class="control-label sr-only" for="jobs_Location"><?php echo 'All Cyprus';?></label>
                                    <select name="event_srch[event_location]" id="event_Location" class=" event-selectbox show-menu-arrow form-control input-sm" data-title="All Cyprus">

                                        <?php
                                        $locations = $events_config['locations'];
                                        foreach ($locations as $dcode=>$loc) {
                                            $selected = '';
                                            if($event_srch['event_location'] == $dcode) $selected = 'selected="selected"';
                                            echo '<option value="',$dcode,'" ',$selected,'>', $loc['title'], '</option>';
                                        }
                                        ?>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-sm-5">
                                <div class="form-group">
                                    <label class="control-label sr-only" for="jobs_posted"><?php echo 'Period';?></label>
                                    <select name="event_srch[event_period]" id="event_period" class=" event-selectbox show-menu-arrow form-control input-sm" data-title="All Future Events">
                                        <?php
                                        if(!isset($past_events) || !$past_events) {
                                            ?>
                                            <option value="" selected="selected">All Future Events</option>
                                            <?php
                                            $posted_vals = array(
                                                'today' => 'Today',
                                                'tomorrow' => 'Tomorrow',
                                                'next7days' => 'Next 7 Days',
                                                'next30days' => 'Next 30 Days',
                                                'next60days' => 'Next 60 Days'

                                            );

                                            foreach ($posted_vals as $pv => $pv_title) {
                                                $selected = '';
                                                if (isset($event_srch['event_period']) && $event_srch['event_period'] != "all" && $event_srch['event_period'] == $pv) $selected = 'selected="selected"';
                                                echo '<option value="', $pv, '" ', $selected, '>', $pv_title, '</option>';
                                            }
                                        }
                                        else {
                                            ?>
                                            <option value="past" selected="selected">All Past Events</option>
                                            <?php
                                        }
                                        ?>
                                    </select>
                                </div>
                            </div>
                            <div class="col-sm-5">
                                <div class="form-group sm-no-margin-left">
                                    <label class="control-label sr-only" for="jobs_posted"><?php echo 'Keyword';?></label>
                                    <input type="text" value="<?=$event_srch['event_keyword'];?>" placeholder="Keyword" name="event_srch[event_keyword]" id="event_keyword" class="form-control input-sm">

                                </div>
                            </div>
                        </div>

                    </div>




                    <div class="container-fluid">
                        <div class="row">
                            <!--<div class="col-sm-5">
                                <div class="form-group form-inline">
                                    <?php
/*                                    echo 'Show', ' ';
                                    echo '<select name="event_srch[i_limit]" style="width: 70px; display: inline-block!important;" class="form-control input-sm">';
                                    $limit_ar = array('10', '15', '20', '25', '30', '50');
                                    foreach ($limit_ar as $lt) {
                                        $selected = '';
                                        if(intval($event_srch['i_limit']) == intval($lt)) $selected = 'selected="selected"';
                                        echo '<option value="',$lt,'" ',$selected,'>',$lt,'</option>';
                                    }
                                    echo '</select> ', 'results per page';
                                    */?>
                                </div>
                            </div>-->
                            <div class="col-sm-10 text-center">
                                <div class="form-group sm-no-margin-left">
                                    <button type="submit" class="load-disabled btn btn-primary btn-sm" disabled="disabled"><i class="fa fa-search fa-lg fa-spin"></i> Search Events</button>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

                <input type="hidden" name="event_srch[i_from]" value="0">
                <input type="hidden" name="module_page" value="events_ext">
                <input type="hidden" name="events_url" value="events"/>
                <input type="hidden" name="event_srch[display]" value="yes"/>
                <input type="hidden" name="domain_id" value="<?=$domain_id;?>"/>

            </section>
        </form>
    </div>


</div>