getCategory($cat, $_SESSION["LANGUAGE"], DEFAULT_LANGUAGE); $pageTitle = buildPageTitle($cat_name["title"]); } else if(isset($_GET['search'])) { $search=$_GET['search']; if ($search == $L["INPUT_SEARCH"]) $search = ""; $pageTitle = buildPageTitle($search); } else { $pageTitle = buildPageTitle($L["MAIN_TITLE"]); } include ('./lib/header.php'); $_SESSION['REFERAL_URL'] = getURL(); ?> "; //WELCOME PAGE if (($search=='') && ($cat=='')) { drawImageSlider(); drawHotProducts(); } else { if ($cat!="") { $subcat = $product->getSubCategoriesId($cat, true, null); $count_query = "SELECT COUNT(ref) as total "; $common_query = "FROM produto WHERE activo = '1' AND (categoria = '".$cat."'"; for ($i = 0; $i < count($subcat); $i++) $common_query .= " OR categoria = '".$subcat[$i]."'"; $common_query .= ")"; $count_query .= $common_query; } else if ($search!="") { $count_query = "SELECT COUNT(DISTINCT produto.ref) as total "; $common_query = "FROM produto, produto_lang WHERE produto.activo=1 AND produto.ref = produto_lang.ref AND ("; $session = session_id(); $product->insertLogSearch($search,$session); $search_word = explode(" ", $search); $count_words = count($search_word); for ($i = 0; $i < $count_words; $i++) { $common_query .= "("; /* $common_query .= "produto_lang.titulo LIKE '%".$search_word[$i]."%'"; $common_query .= " OR "; $common_query .= "produto_lang.descricao LIKE '%".$search_word[$i]."%'"; $common_query .= " OR "; $common_query .= "produto_lang.keywords LIKE '%".$search_word[$i]."%'"; $common_query .= " OR "; $common_query .= "produto.ref LIKE '%".$search_word[$i]."%'"; $common_query .= " OR "; $common_query .= "produto.reffab LIKE '%".$search_word[$i]."%'";$common_query .= " OR "; $common_query .= "produto.marca LIKE '%".$search_word[$i]."%'"; REGEXP '[[:<:]]2[[:>:]]' */ $common_query .= "produto_lang.titulo REGEXP '[[:<:]]".$search_word[$i]."[[:>:]]'"; $common_query .= " OR "; $common_query .= "produto_lang.descricao REGEXP '[[:<:]]".$search_word[$i]."[[:>:]]'"; $common_query .= " OR "; $common_query .= "produto_lang.keywords REGEXP '[[:<:]]".$search_word[$i]."[[:>:]]'"; $common_query .= " OR "; $common_query .= "produto.ref REGEXP '[[:<:]]".$search_word[$i]."[[:>:]]'"; $common_query .= " OR "; $common_query .= "produto.reffab REGEXP '[[:<:]]".$search_word[$i]."[[:>:]]'"; $common_query .= " OR "; $common_query .= "produto.marca REGEXP '[[:<:]]".$search_word[$i]."[[:>:]]'"; $common_query .= ")"; if ($i < ($count_words - 1)) $common_query .= " AND "; } $common_query .= ")"; $count_query .= $common_query; } $db = new sql($count_query); if ($db->next_record()) $total = $db->f("total"); else $total = 0; if (!(isset($_GET['page']))) $page = 1; else $page = $_GET['page']; $last = ceil($total/MAX_PRODUCTS_PER_PAGE); //ultima pag if ($page < 1) $page = 1; else if ($page > $last) $page = $last; if (!(isset($_GET['sort']))) $sort = 0; else $sort = $_GET['sort']; if($sort == 0) $sort_query = " ORDER BY views DESC "; else if($sort == 1) { if ($user->type == '2') $sort_query = " ORDER BY preco_publico ASC "; else $sort_query = " ORDER BY preco_revenda ASC "; } else if($sort == 2) { if ($user->type == '2') $sort_query = " ORDER BY preco_publico DESC "; else $sort_query = " ORDER BY preco_revenda DESC "; } $limit_query = "LIMIT ".(($page - 1) * MAX_PRODUCTS_PER_PAGE).",".MAX_PRODUCTS_PER_PAGE; if ($cat!="") { $var = "cat=".$cat; $query = "SELECT ref " . $common_query.$sort_query.$limit_query; } else if ($search!="") { $var = "search=".$search; $query = "SELECT DISTINCT (produto.ref) ".$common_query.$sort_query.$limit_query; } else $query = ""; $db = new sql($query); //O QUE MOSTRA ANTES DOS RESULTADOS if ($cat!="") { echo "
".$cat_name["title"]."
"; echo "
"; $subcat = $product->getSubCategoriesId($cat, false, null); $index = 0; echo ""; for ($i = 0; $i < ceil(count($subcat) / 3); $i++) { echo ""; for ($j = 0; $j < 3 ; $j++) { if ($subcat[$index] == null) break; else { echo ""; } } echo ""; } echo "
"; $subcat_name = $product->getCategory($subcat[$index], $_SESSION["LANGUAGE"], DEFAULT_LANGUAGE); echo "» ".$subcat_name["title"]." (".$product->countCategoryItems($subcat[$index], true).")"; $index++; echo "
"; echo "
"; } else if ($search!="") { if($total > 0) echo "
".$total." ".$L["SEARCH_RESULTS"]." \"".$search."\"
"; } if ($db->nf() > 0) { echo ""; echo ""; echo "
"; echo "
"; echo"
"; if($cat != "") echo ""; if($search !='') echo ""; echo "
"; echo "
"; echo"
"; echo "
".$L["ORGANIZE_TEXT"].":
"; echo"
"; echo "
"; $product->drawBreadCrumb($cat,"0"); echo "
"; echo "
"; while ($db->next_record()) $product->drawProducts($db->f("ref")); loadAddCartPopUp(); //SEM OCORRENCIAS } else { if ($cat!="") { echo "
"; echo "A categoria seleccionada não possui artigos."; echo "
"; } if ($search!="") { echo "

".$L["MAIN_TITLE_NORESULTS"]."


".$L["TITLE1_NORESULTS"].":
".$L["TEXT1_NORESULTS"]."

".$L["TITLE2_NORESULTS"].":
".$L["TEXT2_NORESULTS"].".

".$L["TITLE3_NORESULTS"].":
".$L["TEXT3_NORESULTS"]."

"; echo "
"; } } //DIV PARA COLOCAR A PAGINAÇÃO echo "
"; //INICIA PAGINACAO ** GOOGLE STYLE if ($last > 1) { $offsetToFirst = $page - 1; $offsetToLast = $last - $page; if ($offsetToFirst <= (PAGINATION_HITS / 2)) $PaginationStart = $page - $offsetToFirst; else if (($offsetToFirst > (PAGINATION_HITS / 2)) && ($offsetToLast <= (PAGINATION_HITS / 2))) $PaginationStart = $page - (PAGINATION_HITS / 2) - ((PAGINATION_HITS / 2) - $offsetToLast); else $PaginationStart = $page - (PAGINATION_HITS / 2); $PaginationEnd = $PaginationStart + PAGINATION_HITS; if ($PaginationEnd > $last) $PaginationEnd = $last; if ($PaginationStart < 1) $PaginationStart = 1; //SETA DO ANTERIOR if ($page > 1) { if($last>PAGINATION_HITS+1 && $offsetToFirst>PAGINATION_HITS/2 ) echo "<< "; echo "< "; } for ($i = $PaginationStart; $i <= $PaginationEnd; $i++) { //PAGINA ACTUAL if ($page == $i) echo "$i"; //OUTRAS PAGINAS else echo "".$i." "; } //SETA DO PROXIMO if ($page < $last){ echo "> "; if($last>(PAGINATION_HITS+1) && $offsetToLast>PAGINATION_HITS/2) echo ">> "; } } $product_ini = ($page-1)*MAX_PRODUCTS_PER_PAGE + 1; $product_fin = $page*MAX_PRODUCTS_PER_PAGE; if ($product_fin > $total) $product_fin = $total; echo "
"; if($total != 0){ echo "
".$L['TEXT_RESULTS_PAGE'][0]."".$product_ini."".$L['TEXT_RESULTS_PAGE'][1]." ".$product_fin." ".$L['TEXT_RESULTS_PAGE'][2]." ".$total." | ".$last."".$L['TEXT_RESULTS_PAGE'][3]."
"; } } echo ""; include('./lib/side_menu.php'); // echo "

















CATEGORIA: ".$cat."
"; // echo "TOTAL PRODUTOS: ".$total."
"; // echo "TOTAL PAGINAS: ".$last."
"; // echo "CONT QUERY: ".$count_query ."

"; // echo "CAT QUERY: ".$query ."

"; include ('./lib/footer.php'); ?>