<?php

include "conf/config.inc.php";
$value = $_POST['value'];
$attribute = $_POST['attr'];
$manufac = $_POST['manufact'];
$classname = $_POST["class"];
if ($classname == "") {
    $classname = "customStyleSelectBox";
}
$search = new search();
$com = new common();
if ($attribute == "manufacturer") {
    $dataArray = array("{$attribute}" => $value);
    $carid = $search->attributeSearch($dataArray, "");
    $set = implode(",", $carid);
    $returnvalue = '<select class="' . $classname . '" id="model" name="model" onchange="ajaxcall(this.value,\'model\',\'year\',' . $value . ')">';
    $returnvalue .= "<option value=''>Modèles</option>";
    //echo "Select DISTINCT(value) from car_varchar where attribute_id = '4' and FIND_IN_SET(car_id, '".$set."') order by value";
    $year = $com->CustomQuery("Select DISTINCT(value) from car_varchar where attribute_id = '4' and FIND_IN_SET(car_id, '" . $set . "') order by value");
    while ($yrow = mysql_fetch_object($year)) {
        $returnvalue .= "<option value='" . $yrow->value . "'>" . $yrow->value . "</option>";
    }
    $returnvalue .= '</select>';
    echo $returnvalue;
}
if ($attribute == "model") {
    $dataArray = array("{$attribute}" => $value, "manufacturer" => $manufac);
    $carid = $search->attributeSearch($dataArray, "");
    $set = implode(",", $carid);
    $returnvalue = '<select class="' . $classname . '" name="madeYear" id="madeYear">';
 $apicall .= $where;
 //echo $apicall;die;
 // Load the call and capture the document returned by eBay API
 $resp = simplexml_load_file($apicall);
 $ebay_total = (int) $resp->paginationOutput->totalEntries;
 $pages = new Paginator();
 $pages->items_per_page = 110;
 $pages->current_page = $fillfor;
 if (count($dataArray) >= 1) {
     if ($groupby != "" && $sort != "") {
         $order = explode("~", $sort);
         $orderby = $groupby . "," . $order[0];
         $total_rows = $search->attributeSearchCount($dataArray, $groupby);
         $pages->items_total += $total_rows;
         $pages->paginate();
         $cars = $search->attributeSearch($dataArray, $orderby, $order[1], $pages->limit);
     } else {
         if ($groupby == "" && $sort != "") {
             $order = explode("~", $sort);
             $total_rows = $search->attributeSearchCount($dataArray, $groupby);
             $pages->items_total += $total_rows;
             $pages->paginate();
             $cars = $search->attributeSearch($dataArray, $order[0], $order[1], $pages->limit);
         } else {
             if ($groupby != "" && $sort == "") {
                 $total_rows = $search->attributeSearchCount($dataArray, $groupby);
                 $pages->items_total += $total_rows;
                 $pages->paginate();
                 $cars = $search->attributeSearch($dataArray, $groupby, 'ASC', $pages->limit);
             } else {
                 $total_rows = $search->attributeSearchCount($dataArray);
$obj_search = new search();
if (isset($_GET['field']) and $_GET['field'] != '') {
    $field = $_GET['field'];
} else {
    $field = 'car_id';
}
if (isset($_GET['orderBy']) and $_GET['orderBy'] != '') {
    $orderby = $_GET['orderBy'];
} else {
    $orderby = 'ASC';
}
$addCarToQuery = '';
$dataArr = array("featured" => 169);
if ($submitcar == 'Search') {
    $backtype = explode("~", $searchattr);
    if ($backtype[2] == "select" or $backtype[2] == "radio" or $backtype[2] == "multiselect" or $backtype[2] == "checkbox") {
        $value_id = $obj_setting->customQuery("select value_id from attribute_option_value where attribute_id = '" . $backtype['0'] . "' and value like '" . "%" . $searchcar . "%" . "' ");
        $value_id = mysql_fetch_object($value_id);
        $value = $value_id->value_id;
    } else {
        $value = $searchcar;
    }
    $attribute_code = $obj_setting->customQuery("select attribute_code from attribute where attribute_id = " . $backtype['0']);
    $attribute_code = mysql_fetch_object($attribute_code);
    $dataArr[$attribute_code->attribute_code] = $value;
}
$pages->items_total = $obj_search->attributeSearchCount($dataArr);
$total_rows = $pages->items_total;
$pages->paginate();
$all_car = $obj_search->attributeSearch($dataArr, "fullName", "ASC", $pages->limit);
$all_car = $obj_setting->CarAttributesFromID($all_car);