assign('toptitle','Автотовары - '._SHOT_TOP_DESC_);
$pageurl='/tuning/';
$smarty->assign('pageurl',$pageurl);
$action=@$_GET['action'];
if (@$pst[0]<>'') { $action=$pst[0]; }
if (isset($_POST['action'])) { $action=$_POST['action']; }
$Tuning = new Tuning();
//<--постраничный вывод
if(!empty($_GET['page'])) {
$page=intval(abs(@$_GET['page']-1));
} else $page=0;
$smarty->assign("sel_page",$page+1);
$s=array("/&page=[0-9]*/","/pst=[a-z]*/","/\/&/");
$r=array();
$qstr=preg_replace($s,$r,$_SERVER['QUERY_STRING']);
if ($qstr=='/') $qstr='/tuning'.$qstr;
else $qstr='/tuning/&'.$qstr;
$smarty->assign("url",$qstr);
$page_limit=20;
//постраничный вывод-->
$sqlsearch='';
if (@$_GET['catid']) {
$sqlsearch.=" AND p_catid=".intval($_GET['catid']);
}
if (@$_GET['child']) {
$sqlsearch.=" AND catid=".intval($_GET['child']);
}
if (@$_GET['search']) {
$sqlsearch.=" AND name LIKE '%".in_text(strip_tags($_GET['search']))."%'";
}
$smarty->assign('mas_tuning_cat',$Tuning->GetAllCategories());
$smarty->assign('mas_pickup',get_pickup(3));
$smarty->assign('link_img_s','/upload/tuning_s/');
$smarty->assign('link_img_m','/upload/tuning_m/');
$smarty->assign('link_img_l','/upload/tuning_l/');
$smarty->assign('link_img','/tuning.php?');
$smarty->assign('no_image','no_parts_m_text.gif');
switch ($action)
{
default:
$region=$assoc_region[$CURRENT_REGION_ID];
$cities=array();
foreach ($mas_city as $c){
if ($c['region']==$region) $cities[]=$c['id'];
}
$search=$sqlsearch." AND t.cityid IN (".implode(",",$cities)." ) ";
//<--постраничный вывод
$q="SELECT COUNT(*) AS ct FROM tuning t WHERE publ>0 $search LIMIT 1";
$res=$DB->query($q);
$row=$DB->nextRow($res);
if ($row[ct]<1){
$search=$sqlsearch;
$q="SELECT COUNT(*) AS ct FROM tuning WHERE publ>0 $search LIMIT 1";
$res=$DB->query($q);
$row=$DB->nextRow($res);
}
$smarty->assign("pages",intval(ceil($row['ct']/$page_limit)));
$smarty->assign('offers_ct',$row['ct']);
//постраничный вывод-->
$smarty->assign('mas_offers',$Tuning->ShowList($page,$page_limit,$search));
$smarty->display('tuning/main.tpl');
break;
case 'show':
$mas=array();
$oid=intval($pst[1]);
if ($oid){
$Tuning->AddView($oid);
}
$offer=$Tuning->Show($oid);
//обратная навигация
$mas_back_nav=array();
$mas_back_nav[]=array('name'=>'Автотовары','link'=>$pageurl);
$mas_back_nav[]=array('name'=>$offer['name'],'link'=>'');
$smarty->assign('mas_back_nav',$mas_back_nav);
if ($offer['p_catid']) $mas_tuning=$Tuning->GetSimilar($offer['p_catid'],$oid);
//print_r($mas_tuning); exit(0);
//print_r($offer); exit(0);
$smarty->assign('offer',$offer);
$smarty->assign('mas_tuning', $mas_tuning);
$smarty->display('tuning/show.tpl');
break;
}
include("../inc/bottom.php");
?>