/** * This function is used to find the extended search * @param integer $sort * @param string $mode * @return string */ function extendedSearch($sort, $mode) { $attrib_value_id = $_GET['attrib_value_id']; $catid = $_GET['category']; $pagesize = 10; if (isset($_GET['page'])) { $start = trim($_GET['page'] - 1) * $pagesize; $end = $pagesize; } else { $start = 0; $end = $pagesize; } $total = 0; $sortby = $_POST['selsort']; if (empty($sortby)) { $sortby = 0; } $catid = $_POST['subcatsel']; if (empty($catid)) { $catid = $_GET['category']; } $ob = new Core_CKeywordSearch(); $subcategoryname = $ob->categoryName($catid); $mm = $_SESSION['category']; $categoryname = $ob->categoryName($mm); $head = $_GET['head']; $attib_value_id = $_GET['attrib_value_id']; // echo 'the value is '.$attib_value_id; $brand = $_GET['brand']; if ((int) $attib_value_id > 0) { $_SESSION['selectedbrand'] = 'You have Selected <b>' . $categoryname . '</b> >><b> ' . $subcategoryname . '</b>>>' . '<b> ' . $head . ' </b>'; } elseif (count($brand) > 0) { $_SESSION['selectedbrand'] = 'You have Selected <b>' . $categoryname . '</b> >><b> ' . $subcategoryname . '</b>'; } if ((int) $attrib_value_id > 0) { if ($sortby == 0) { //$sql="select * from products_table a inner join product_attrib_values_table b on a.product_id=b.product_id inner join category_table c on c.category_id=a.category_id inner join category_table d on d.category_id=c.category_parent_id where b.attrib_value_id=".$attrib_value_id." and category_id=".catid." group by a.title order by a.msrp"; // $sql="select a.* from products_table a inner join product_attrib_values_table b on a.product_id=b.product_id inner join category_table c on c.category_id=a.category_id inner join category_table d on c.category_parent_id=d.category_id where b.attrib_value_id=".$attrib_value_id." and c.category_parent_id=".$catid ." order by a.msrp"; $sql = "select a.*,sum(r.rating)/count(r.user_id) as rating,count(r.user_id) as rcount from products_table a inner join product_attrib_values_table b on a.product_id=b.product_id inner join category_table c on c.category_id=a.category_id inner join category_table d on c.category_parent_id=d.category_id where b.attrib_value_id=" . $attrib_value_id . " and c.category_id=" . $catid . " and a.intro_date <= '" . date('Y-m-d') . "' and a.status=1 group by a.product_id order by a.msrp"; } elseif ($sortby == 1) { //$sql="select * from products_table a inner join product_attrib_values_table b on a.product_id=b.product_id inner join category_table c on c.category_id=a.category_id inner join category_table d on d.category_id=c.category_parent_id where b.attrib_value_id=".$attrib_value_id." ".$mycat." group by a.title order by a.msrp desc "; // $sql="select a.* from products_table a inner join product_attrib_values_table b on a.product_id=b.product_id inner join category_table c on c.category_id=a.category_id inner join category_table d on c.category_parent_id=d.category_id where b.attrib_value_id=".$attrib_value_id." and c.category_parent_id=".$catid ." order by a.msrp desc"; $sql = "select a.*,sum(r.rating)/count(r.user_id) as rating,count(r.user_id) as rcount from products_table a inner join product_attrib_values_table b on a.product_id=b.product_id inner join category_table c on c.category_id=a.category_id inner join category_table d on c.category_parent_id=d.category_id left join product_reviews_table r on a.product_id=r.product_id where b.attrib_value_id=" . $attrib_value_id . " and c.category_id=" . $catid . " and a.intro_date <= '" . date('Y-m-d') . "' and a.status=1 group by a.product_id order by a.msrp desc"; } elseif ($sortby == 2) { // $sql="select * from products_table a inner join product_attrib_values_table b on a.product_id=b.product_id inner join category_table c on c.category_id=a.category_id inner join category_table d on d.category_id=c.category_parent_id where b.attrib_value_id=".$attrib_value_id." ".$mycat." group by a.title order by a.title"; // $sql="select a.* from products_table a inner join product_attrib_values_table b on a.product_id=b.product_id inner join category_table c on c.category_id=a.category_id inner join category_table d on c.category_parent_id=d.category_id where b.attrib_value_id=".$attrib_value_id." and c.category_parent_id=".$catid ." order by a.title"; $sql = "select a.*,sum(r.rating)/count(r.user_id) as rating,count(r.user_id) as rcount from products_table a inner join product_attrib_values_table b on a.product_id=b.product_id inner join category_table c on c.category_id=a.category_id inner join category_table d on c.category_parent_id=d.category_id left join product_reviews_table r on a.product_id=r.product_id where b.attrib_value_id=" . $attrib_value_id . " and c.category_id=" . $catid . " and a.intro_date <= '" . date('Y-m-d') . "' and a.status=1 group by a.product_id order by a.title"; } elseif ($sortby == 3) { //$sql="select * from products_table a inner join product_attrib_values_table b on a.product_id=b.product_id inner join category_table c on c.category_id=a.category_id inner join category_table d on d.category_id=c.category_parent_id where b.attrib_value_id=".$attrib_value_id." ".$mycat." group by a.title order by a.title desc "; //$sql="select a.* from products_table a inner join product_attrib_values_table b on a.product_id=b.product_id inner join category_table c on c.category_id=a.category_id inner join category_table d on c.category_parent_id=d.category_id where b.attrib_value_id=".$attrib_value_id." and c.category_parent_id=".$catid ." order by a.title desc"; $sql = "select a.*,sum(r.rating)/count(r.user_id) as rating,count(r.user_id) as rcount from products_table a inner join product_attrib_values_table b on a.product_id=b.product_id inner join category_table c on c.category_id=a.category_id inner join category_table d on c.category_parent_id=d.category_id left join product_reviews_table r on a.product_id=r.product_id where b.attrib_value_id=" . $attrib_value_id . " and c.category_id=" . $catid . " and a.intro_date <= '" . date('Y-m-d') . "' and a.status=1 group by a.product_id order by a.title desc"; } } $obj = new Bin_Query(); if ($obj->executeQuery($sql)) { $_SESSION['countsearch'] = $obj->totrows; $sql1 = $sql . ' LIMIT ' . $start . ',' . $end; $total = ceil($obj->totrows / $pagesize); include 'classes/Lib/paging.php'; $tmp = new Lib_Paging('classic', array('totalpages' => $total, 'length' => 10), 'pagination'); $this->data['paging'] = $tmp->output; $this->data['prev'] = $tmp->prev; $this->data['next'] = $tmp->next; $query = new Bin_Query(); if ($query->executeQuery($sql1)) { $i = 0; if ((int) $query->totrows > 0) { foreach ($query->records as $row) { $r[$i] = $row; $prid = $row['product_id']; $obj1 = new Core_CKeywordSearch(); $minval = $obj1->disRates($prid); if ($minval > 0 or $minval != '') { $r[$i]['msrp'] = '$' . number_format($row['msrp'], 2) . ' - $' . number_format($minval, 2); } else { $r[$i]['msrp'] = '$' . number_format($row['msrp'], 2); } $i++; } } } return Display_DKeywordSearch::extendedSearch($r, $mode, $this->data['paging'], $this->data['prev'], $this->data['next']); } }