<?php
$module_css_path = ($line_domain['theme'] != "" && $line_domain['theme'] != "default") ? ($path . ('assets/themes/' . $line_domain['theme'] . '/')) : $path;
$form_action = $homepage_url . 'cyprus';
$form_target = "_self";
$catdom_id_search = $domain_id;

if(!isset($search)) {
    $search = array(
        'now' => 'no',
        'catdom_id' => '',
        'keyword' => '',
        'filter_ids' => array()
    );
}

//echo '<pre>', var_export($search, true), '</pre>';

?>
<section class="advanced-search" aria-label="Advanced Search">
    <form action="<?php echo $form_action; ?>" target="<?php echo $form_target; ?>" method="post" name="formadvsearch" id="formadvsearch" class="form-horizontal" role="search">
        <div class="box box-default box-solid box-compact">
            <div class="box-header with-border">
                <i class="fa fa-search"></i>
                <b>Advanced Search</b>
            </div>
            <div class="box-body">
                <div>
                    <?php
                    if ($catdom_id_search != 611) {

                        $query_adv_sear_domain = "SELECT * FROM domaincategories WHERE parent_id='$catdom_id_search' AND active='yes' ORDER BY order_seq ASC";
                        //echo $query_adv_sear_domain;
                        $result_adv_sear_domain = mysql_query($query_adv_sear_domain);
                        if ($result_adv_sear_domain && mysql_num_rows($result_adv_sear_domain) > 0) {
                            //$line_adv_sear_domain = mysql_fetch_assoc($result_adv_sear_domain);
                            ?>
                            <div class="form-group">
                                <label class="control-label col-sm-3">
                                    <?php
                                    /*if(trim($line_adv_sear_domain["title_tr"]) == ""){
                                        echo "Town";
                                    }
                                    else {
                                        echo $line_adv_sear_domain["title_tr"];
                                    }*/
                                    echo 'Search in';
                                    ?>
                                </label>

                                <div class="col-sm-7">
                                    <select class="form-control input-sm" name="search[catdom_id]"
                                            id="search_catdom_id">
                                        <option value="" selected="selected">All</option>
                                        <?php
                                        while ($linedistricts = mysql_fetch_assoc($result_adv_sear_domain)) {
                                            $selected = '';
                                            if (isset($search["catdom_id"]) && $linedistricts["catdom_id"] == $search["catdom_id"]) {
                                                $selected = 'selected="selected"';
                                            }
                                            ?>
                                            <option value="<?php echo $linedistricts["catdom_id"]; ?>" <?=$selected;?>>
                                                <?php echo str_replace("| ", "", $linedistricts["title_el"]); ?>
                                            </option>
                                            <?php
                                        }
                                        ?>
                                    </select>
                                </div>
                            </div>
                            <?php
                        }
                    }
                    ?>
                    <?php
                    $query2 = "SELECT * FROM filters WHERE parent_id='$catdom_id_search' AND active='yes' ORDER BY title_en ASC";
                    //echo $q;
                    $result2 = mysql_query($query2) or die (mysql_error());
                    $search_filters = array();
                    if ($result2 && mysql_num_rows($result2) > 0) {
                        while ($line2 = mysql_fetch_assoc($result2)) {
                            $search_filters[$line2['filter_id']] = $line2['title_en'];
                        }

                    }

                    if(count($search_filters) > 0){
                        //echo '<pre>$search_filters = ', var_export($search_filters, true), '</pre>';
                        ?>
                        <div class="form-group">
                            <label class="control-label col-sm-3">Filter By</label>

                            <div class="col-sm-7">
                                <div class="">
                                    <?php
                                    foreach ($search_filters as $filter_id => $filter_name) {
                                        $fchecked = '';
                                        if(in_array($filter_id, $search['filter_ids'])) {
                                            $fchecked = 'checked="checked"';
                                        }
                                        ?>
                                        <label>
                                            <input type="checkbox" name="search[filter_ids][]" value="<?=$filter_id; ?>" <?=$fchecked;?>>
                                            <?php echo $filter_name; ?>
                                        </label>
                                        <?php
                                    }

                                    ?>
                                </div>

                            </div>
                        </div>
                        <?php
                    }
                    ?>
                    <div class="form-group">
                        <label class="control-label col-sm-3"> Keyword </label>

                        <div class="col-sm-7">
                            <input class="form-control input-sm" name="search[keyword]" type="text" value="<?=$search['keyword'];?>" id="adv_search_keyword"/>
                        </div>
                    </div>

                </div>
            </div>
            <div class="box-footer text-center">
                <input name="search[now]" type="hidden" id="adv_search_now" value="yes"/>
                <input name="module_page" type="hidden" id="adv_module_page" value="search_adv"/>
                <button type="submit" name="Submit2" class="btn btn-primary btn-sm"><i class="fa fa-search"></i>
                    Search
                </button>
                <button type="reset" name="reset" class="btn btn-default btn-sm"><i class="fa fa-times"></i> Reset
                </button>
            </div>
        </div>
    </form>
</section>