<?php
//This code is copyright (c) ViciSoft SL, all rights reserved.
//The contents of this file are protected under law as the intellectual property 
//of ViciSoft SL. Any use, reproduction, disclosure or copying of any kind 
//without the express and written permission of ViciSoft SL is forbidden.
//Author: Vince Reid, vincereid@gmail.com
if(!@$GLOBALS['incfunctionsdefined']){print 'No incfunctions.php file';exit;}
global $topsectionids,$catid,$isrootsection,$globaldiscounts,$maxglobaldiscounts,$tslist,$cs,$explicitid,$manfilterurl,$maxgroupid,$filterurl,$prodsperpage,$TWSP,$WSP,$OWSP,$seocategoryurls,$seourlsthrow301,$usecategoryname,$Count,
		$useproductbodyformat,$productcolumns,$pagebarattop,$catalogroot,$giftcertificateid,$donationid,$countryTaxRate,$prodfilter,$defimagejs,$usecsslayout,$adminProdsPerPage,$currConvUser,$currConvPw,$currLastUpdate,
		$currRate1,$currSymbol1,$currRate2,$currSymbol2,$currRate3,$currSymbol3,$currSymbol1,$currFormat1,$currFormat2,$currFormat3,$usepnamefordetaillinks,$detlinkspacechar,$storeurl,$optjs,$filterpricebands,$nosellzeroprice,
		$showquantonproduct,$magictoolboxproducts,$explicitmanid,$catname,$dosortby,$sprice;
if(@$GLOBALS['xxDsNoAp']=='') $GLOBALS['xxDsNoAp']='The following discount(s) will not apply:';
$isproductspage=TRUE; $hasshippingdiscount=$hasproductdiscount=FALSE;
$manname=$catname=$caturl=$catrootsection=$globaldiscounttext='';
$catrootsection=1;
$iNumOfPages=$maxgroupid=$maxglobaldiscounts=0;
if(! is_numeric(getget('pg')) || strlen(getget('pg'))>8) $CurPage=1; else $CurPage=max(1, (int)getget('pg'));
$GLOBALS['alreadygotadmin']=getadminsettings();
$dothrow301=FALSE;
if(@isset($orprodfilter)) $prodfilter=$orprodfilter;
if(getget('cat')!='') $catid=getget('cat'); else $catid='';
if(getget('man')!='') $manid=getget('man'); else $manid='';
if(@$GLOBALS['iswordpress'] && get_query_var( 'ectcat' ) != '') $catid=urldecode(get_query_var('ectcat'));
if(@$GLOBALS['iswordpress'] && get_query_var( 'ectman' ) != '') $manid=urldecode(get_query_var('ectman'));
if(@$manufacturerpageurl==''){
	$manufacturerpageurl='manufacturers'.$GLOBALS['extension'];
	if(@$GLOBALS['seomanufacturerpattern']!='')$manufacturerpageurl=str_replace('%s','',$GLOBALS['seomanufacturerpattern']);
}
$sprice=preg_replace('/[^\d\-\.]/','',getget('sprice'));
if(!@$GLOBALS['alreadygotattributevars']){
	$GLOBALS['numscrgroup']=$GLOBALS['numscrid']=0;
	$GLOBALS['scrid']=commaseplist(getget('scri'));
	if($GLOBALS['scrid']=='' && is_numeric(@$explicitmanid)) $GLOBALS['scrid']=@$explicitmanid;
	$GLOBALS['scridarr']=explode(',',$GLOBALS['scrid']);
	$GLOBALS['numscrid']=count($GLOBALS['scridarr']);
	for($scrindex=0; $scrindex<$GLOBALS['numscrid']; $scrindex++){
		if(strlen($GLOBALS['scridarr'][$scrindex])>10) $GLOBALS['scrid']='';
	}
	$GLOBALS['alreadygotattributevars']=TRUE;
}
if(is_numeric(@$explicitmanid)) $manid=@$explicitmanid;
if(is_numeric(@$_REQUEST['sortby'])) $_SESSION['sortby']=(int)$_REQUEST['sortby'];
if(@$_SESSION['sortby']!='') $dosortby=$_SESSION['sortby']; elseif(@$GLOBALS['orsortby']!='') $dosortby=$GLOBALS['orsortby'];
if(@$seocategoryurls){$usecategoryname=TRUE;$catid=str_replace(@$detlinkspacechar,' ',$catid);$manid=str_replace(@$detlinkspacechar,' ',$manid);}
if(@$GLOBALS['bmlbannerproducts']!='' && @$GLOBALS['paypalpublisherid']!='') displaybmlbanner($GLOBALS['paypalpublisherid'],$GLOBALS['bmlbannerproducts']);
if(is_numeric(@$explicitid))
	$catid=@$explicitid;
elseif(@$usecategoryname && $catid!=''){
	$sSQL='SELECT sectionID FROM sections WHERE '.(@$seocategoryurls?getlangid('sectionurl',2048)."='".escape_string($catid)."' OR (":'').getlangid('sectionName',256)."='".escape_string($catid)."'".(@$seocategoryurls?' AND '.getlangid('sectionurl',2048)."='')":'');
	$result=ect_query($sSQL) or ect_error();
	if($rs=ect_fetch_assoc($result)){
		$catname=$catid;
		$catid=$rs['sectionID'];
	}elseif(! is_numeric($catid)){
		$catname='Not Found';
		$catid=-1;
		$GLOBALS['prodfilter']=0;
		$GLOBALS['sidefilter']=0;
		$GLOBALS['noshowdiscounts']=TRUE;
		header('HTTP/1.1 404 Not Found');
	}
	ect_free_result($result);
}
if(@$usecategoryname && $manid!=''){
	$sSQL='SELECT scID FROM searchcriteria WHERE ' . (is_numeric(@$explicitmanid)?'scID='.$explicitmanid:'(('.getlangid('scURL',8192)."='' OR ".getlangid('scURL',8192)." IS NULL) AND ".getlangid('scName',131072)."='".escape_string($manid)."') OR ".getlangid('scURL',8192)."='".escape_string($manid)."'") . ' ORDER BY scGroup';
	$result=ect_query($sSQL) or ect_error();
	if($rs=ect_fetch_assoc($result)){ $manname=$manid; $manid=$rs['scID']; }else $manid=-1;
	ect_free_result($result);
}
if(@$usecategoryname && $catname=='' && $manname=='' && @$seourlsthrow301 && (is_numeric($catid) || is_numeric($manid))){
	if(is_numeric($catid))
		$sSQL='SELECT sectionID AS secid,'.getlangid('sectionName',256).' AS secname,'.getlangid('sectionurl',2048).' AS securl,rootSection FROM sections WHERE sectionID='.$catid;
	elseif(is_numeric($manid))
		$sSQL='SELECT scID AS secid,'.getlangid('scName',131072).' AS secname,'.getlangid('scURL',8192).' AS securl,1 AS rootSection FROM searchcriteria WHERE scID='.$manid;
	$result=ect_query($sSQL) or ect_error();
	if($rs=ect_fetch_assoc($result)){
		if(is_numeric($catid)) $catid=$rs['secid']; else $manid=$rs['secid'];
		$dothrow301=(@$explicitid==''&&@$explicitmanid==''); $catname=$rs['secname']; $caturl=trim($rs['securl']); $catrootsection=$rs['rootSection'];
	}
	ect_free_result($result);
}
if(!is_numeric($catid)) $catid=$catalogroot;
if(is_numeric($manid) || @$manufacturers==TRUE) $manufacturers=TRUE; else{ $manufacturers=FALSE; $manid=''; }
foreach(@$_GET as $key => $value) if($key=='man'&&is_numeric($value)) $manufacturers=TRUE;
$cs=$WSP=$OWSP='';
if(@$GLOBALS['styleprefix']!='') $cs=$GLOBALS['styleprefix'];
$TWSP='pPrice';
$sectionheader='';
$sectionfooter='';
if(((@$seocategoryurls && (@$_SERVER['REDIRECT_URL'].@$_SERVER['HTTP_X_ORIGINAL_URL'])=='') || $dothrow301) && @$seourlsthrow301 && ! is_numeric(@$explicitid) && ! is_numeric(@$explicitmanid) && $catid!=-1){
	$newloc=getfullurl(getcategoryurl($catid,$catname,$caturl,$catrootsection));
	$addand=$newqs='';
	foreach($_GET as $key=>$val){
		if($key!='cat'&&!($manufacturers&&$key=='man')){ $newqs.=$addand.$key.'='.urlencode($val); $addand='&'; }
	}
	ob_end_clean();
	header('HTTP/1.1 301 Moved Permanently');
	header('Location: '.$newloc.($newqs!=''?'?'.$newqs:''));
	exit;
}
$sectionurl=htmlentities(str_replace('"','',strip_tags((@$seocategoryurls||@$GLOBALS['iswordpress'])&&@$_SERVER['REQUEST_URI']!=''?current(explode('?',$_SERVER['REQUEST_URI'])):@$_SERVER['PHP_SELF'])));
get_wholesaleprice_sql();
if(@$filterpricebands=='') $filterpricebands=100;
function isinscrid($cscrid){
	$retval=FALSE;
	for($scrind=0; $scrind<$GLOBALS['numscrid']; $scrind++){
		if($cscrid==(int)$GLOBALS['scridarr'][$scrind]) $retval=TRUE;
	}
	return($retval);
}
function getlike($fie,$t,$tjn){
	global $sNOTSQL;
	if(substr($t, 0, 1)=='-'){ // pSKU excluded to work around NULL problems
		if($fie!='pSKU') $sNOTSQL.=$fie." LIKE '%".substr($t, 1)."%' OR ";
	}else
		return $fie . " LIKE '%".$t."%' ".$tjn;
}
function sortline($soid, $sotext){
	global $sortoptions,$dosortby;
	if(($sortoptions & pow(2,($soid-1)))!=0) print '<option value="'.$soid.'"'.($dosortby==$soid?' selected':'').'>'.$sotext.'</option>';
}
$nofirstpg=TRUE;
$pblink='<a class="ectlink" href="'.$sectionurl.'?';
foreach(@$_GET as $objQS => $objValue)
	if($objQS!='cat' && $objQS!='id' && $objQS!='man' && $objQS!='pg' && $objQS!='mux' && gettype($objValue)=='string') $pblink.=urlencode($objQS) . '=' . urlencode($objValue) . '&amp;';
if(($catid!='0' || ($manufacturers && $manid!='')) && @$explicitid=='' && @$explicitmanid=='' && ! (@$seocategoryurls&&@$_SERVER['REDIRECT_URL']!='')) $pblink.=($manufacturers?'man=' . $_GET['man']:'cat=' . getcatid($catid,@$catname,$GLOBALS['seoprodurlpattern'])) . '&amp;pg='; else $pblink.='pg=';
if(@$magictoolboxproducts!=''){
	print '<script src="' . ($magictoolboxproducts=='MagicTouch' ? 'http://www.magictoolbox.com/mt/' . $magictouchid . '/magictouch.js' : strtolower($magictoolboxproducts) . '/' . strtolower($magictoolboxproducts) . '.js') . '"></script>' . @$magictooloptionsjsproducts;
	$magictoolboxproducts=str_replace('MagicZoomPlus','MagicZoom',$magictoolboxproducts);
	$magictool=$magictoolboxproducts;
	if($magictoolboxproducts=='MagicThumb') $magictooloptionsproducts=str_replace('data-options=','rel=',@$magictooloptionsproducts); else $magictooloptionsproducts=str_replace('rel=','data-options=',@$magictooloptionsproducts);
}
$filterurl=$manfilterurl='';
foreach(@$_GET as $objQS=>$objVal){
	if(gettype($objVal)=='string' && $objQS!='recentview' && $objQS!='filter' && $objQS!='pg' && $objQS!='sortby' && $objQS!='perpage' && ! (($objQS=='cat' || $objQS=='man') && @$seocategoryurls)){
		$filterurl.=urlencode($objQS) . '=' . urlencode(unstripslashes($objVal)) . '&';
		if($objQS!='sman' && $objQS!='scri' && $objQS!='sprice') $manfilterurl.=urlencode($objQS) . '=' . urlencode(unstripslashes($objVal)) . '&';
	}
}
if($filterurl=='') $filterurl=$sectionurl.'?filter='; else $filterurl=$sectionurl.'?'.$filterurl.'filter=';
if($manfilterurl=='') $manfilterurl=$sectionurl.'?'; else $manfilterurl=$sectionurl.'?'.$manfilterurl;
function dofilterresults($numfcols){
	global $prodfilter,$prodfiltertext,$sectionurl,$imgfilterproducts,$manufacturers,$manid,$filterpricebands,$sortoptions,$sectionids,$prodsperpage,$filtersql,$filterurl,$manfilterurl,$sprice,$countryTaxRate,$TWSP,$maxgroupid;
	if($prodfilter!=0 && ! ($prodfilter==8 && $sortoptions==0)){
		if(($prodfilter & 2)==2){
			$searchcriterialist='';
			$currgroupid=-1;
			if(! @$GLOBALS['hascheckedectfilters']){
				$sSQL='SELECT COUNT(DISTINCT products.pID) as tcount,scID,'.getlangid('scName',131072).',scGroup,scOrder,scgTitle FROM (searchcriteria INNER JOIN searchcriteriagroup ON searchcriteria.scGroup=searchcriteriagroup.scgID) ' .
					'INNER JOIN multisearchcriteria ON multisearchcriteria.mSCscID=searchcriteria.scID ' . (@$GLOBALS['displayzeroattributes']?'LEFT':'INNER') . ' JOIN (products'.($sectionids!=''?' LEFT JOIN multisections ON products.pId=multisections.pId':'').') ON multisearchcriteria.mSCpID=products.pID ' .
					(@$GLOBALS['displayzeroattributes']?'AND':'WHERE') . ' pDisplay<>0' . (@$GLOBALS['ectsiteid']!='' ? ' AND pSiteID='.$GLOBALS['ectsiteid'] : '');
				if($GLOBALS['useStockManagement'] && @$GLOBALS['noshowoutofstock']) $sSQL.=' AND pInStock>pMinQuant';
				if($sectionids!='') $sSQL.=' AND (products.pSection IN ('.$sectionids.') OR multisections.pSection IN ('.$sectionids.'))';
				$sSQL.=$filtersql.' AND (multisearchcriteria.mSCpID IN (' . "\r\n" . 'SELECT products.pID FROM ';
				if($GLOBALS['numscrid']>1) $sSQL.=str_repeat('(',$GLOBALS['numscrid']-1);
				$sSQL.='(products'.($sectionids!=''?' LEFT JOIN multisections ON products.pId=multisections.pId':'').')' . ($GLOBALS['scrid']!=''?' INNER JOIN multisearchcriteria ON multisearchcriteria.mSCpID=products.pID':'');
				for($scrindex=1; $scrindex<=$GLOBALS['numscrid']-1; $scrindex++){
					$sSQL.=') INNER JOIN multisearchcriteria msc'.$scrindex.' ON products.pID=msc'.$scrindex.'.mSCpID';
				}
				$sSQL.=' WHERE 1=1';
				if(@$GLOBALS['customproductsearch']!='') $sSQL.=' AND ' . $GLOBALS['customproductsearch'];
				if($manid!='0' && is_numeric($manid)) $sSQL.=' AND pManufacturer=' . $manid;
				if($GLOBALS['scSQL']!='') $sSQL.=' AND ' . $GLOBALS['scSQL'];
				$sSQL.=')'."\r\n".($GLOBALS['numscrid']>0?' OR scGroup=0':'').') GROUP BY scID,'.getlangid('scName',131072).',scGroup,scOrder,scgOrder,scgTitle ORDER BY scgOrder,scGroup,scOrder,'.getlangid('scName',131072);
				$result2=ect_query($sSQL) or ect_error();
				$GLOBALS['nectfiltercache']=0;
				while($rs2=ect_fetch_assoc($result2))
					$GLOBALS['ectfiltercache'][$GLOBALS['nectfiltercache']++]=$rs2;
				ect_free_result($result2);
			}
			$GLOBALS['hascheckedectfilters']=TRUE;
			if($GLOBALS['nectfiltercache']>0){
				for($cacheindex=0; $cacheindex<$GLOBALS['nectfiltercache']; $cacheindex++){
					if($currgroupid!=$GLOBALS['ectfiltercache'][$cacheindex]['scGroup']){
						$maxgroupid++;
						if($searchcriterialist!='') $searchcriterialist.='</select>';
						$searchcriterialist.='<select name="scri" class="ectselectinput prodfilter" id="scri'.$maxgroupid.'" onchange="filterbyman(1)"'.(@$GLOBALS['sidefilterstyle']=='multiple'?' size="5" multiple="multiple"':' size="1"').'><option value="" style="font-weight:bold">' . sprintf($GLOBALS['xxSFiAll'],$GLOBALS['ectfiltercache'][$cacheindex]['scgTitle']) . "</option>\r\n";
						$currgroupid=$GLOBALS['ectfiltercache'][$cacheindex]['scGroup'];
					}
					$searchcriterialist.='<option value="'.$GLOBALS['ectfiltercache'][$cacheindex]['scID'].'"'.(isinscrid($GLOBALS['ectfiltercache'][$cacheindex]['scID'])?' selected':'').'>' . $GLOBALS['ectfiltercache'][$cacheindex][getlangid('scName',131072)] . (! isinscrid($GLOBALS['ectfiltercache'][$cacheindex]['scID'])?' ('.$GLOBALS['ectfiltercache'][$cacheindex]['tcount'].')':'') . "</option>\r\n";
				}
			}else
				$prodfilter-=2;
			if($searchcriterialist!='') $searchcriterialist.='</select>';
		}
		$maxprice=$minprice=0;
		if(($prodfilter & 4)==4){
			$sSQL='SELECT MAX(' . $TWSP . ') AS maxprice,MIN(' . $TWSP . ') AS minprice FROM products WHERE ' . (@$GLOBALS['ectsiteid']!='' ? 'pSiteID='.$GLOBALS['ectsiteid'].' AND ' : '') . 'pDisplay<>0';
			if($sectionids!='') $sSQL='SELECT MAX(' . $TWSP . ') AS maxprice,MIN(' . $TWSP . ') AS minprice FROM (products LEFT JOIN multisections ON products.pId=multisections.pId) WHERE ' . (@$GLOBALS['ectsiteid']!='' ? 'pSiteID='.$GLOBALS['ectsiteid'].' AND ' : '') . 'pDisplay<>0 AND (products.pSection IN (' . $sectionids . ') OR multisections.pSection IN (' . $sectionids . '))';
			$result2=ect_query($sSQL) or ect_error();
			if($rs2=ect_fetch_assoc($result2)){ if(! is_null($rs2['maxprice'])){ $maxprice=$rs2['maxprice']; $minprice=$rs2['minprice']; } }
			if(@$GLOBALS['showtaxinclusive']===2){ $maxprice+=$maxprice*($countryTaxRate/100.0); $minprice+=$minprice*($countryTaxRate/100.0); }
			ect_free_result($result2);
		}
		$filtertext=explode('&',$prodfiltertext);
		for($index=0; $index<9; $index++)
			$filtertext[$index]=str_replace('%26','&',trim_(@$filtertext[$index]));
		print '<div class="prodfilterbar">';
?><script>
/* <![CDATA[ */
function filterbyman(caller){
var furl="<?php print str_replace(array('<','"'),array('','\\"'),$manfilterurl)?>";
var allscri='';
if(document.getElementById('sman')){
	var smanobj=document.getElementById('sman');
	if(smanobj.selectedIndex!=0) furl+='sman='+smanobj[smanobj.selectedIndex].value+'&';
}
<?php	for($index=1; $index<=$maxgroupid; $index++){ ?>
	var smanobj=document.getElementById('scri<?php print $index?>');
	for(var i=1;i<smanobj.length;i++){
        if(smanobj.options[i].selected) allscri+=smanobj.options[i].value+',';
    }
<?php	} ?>
	if(allscri!='') furl+='scri='+allscri.substr(0,allscri.length-1)+'&';
if(document.getElementById('spriceobj')){
	var spriceobj=document.getElementById('spriceobj');
	if(spriceobj.selectedIndex!=0) furl+='sprice='+spriceobj[spriceobj.selectedIndex].value+'&';
}
if(document.getElementById('ectfilter')){
	if(document.getElementById('ectfilter').value!='')
		furl+='filter='+encodeURIComponent(document.getElementById('ectfilter').value)+'&';
}
document.location=furl.substr(0,furl.length-1);
}
function changelocation(fact,tobj){
document.location='<?php print $filterurl?>'.replace(/filter=/,fact+'='+tobj[tobj.selectedIndex].value<?php if(($prodfilter & 32)==32) print "+'&filter='+encodeURIComponent(document.getElementById('ectfilter').value)" ?>);
}
function changelocfiltertext(tkeycode,tobj){
if(tkeycode==13)document.location='<?php print $filterurl?>'+tobj.value;
}
/* ]]> */</script>
<?php	if(@$GLOBALS['prodfilterorder']=='') $GLOBALS['prodfilterorder']='1,2,4,8,16,32';
		$filterorderarray=explode(',',$GLOBALS['prodfilterorder']);
		for($indexfilterorder=0; $indexfilterorder<count($filterorderarray); $indexfilterorder++){
			switch($filterorderarray[$indexfilterorder]){
			case 2:
				if(($prodfilter & 2)==2){ // Product Attributes
					if($filtertext[1]!='') print '<div class="prodfiltergrp ectpfattgrp"><div class="prodfilter filtertext ectpfatttext">' . $filtertext[1] . '</div>';
					print '<div class="prodfilter ectpfatt">' . $searchcriterialist . '</div>';
					if($filtertext[1]!='') print '</div>';
				}
			break;
			case 4:
				if(($prodfilter & 4)==4){ // Price bands
					if($filtertext[2]!='') print '<div class="prodfiltergrp ectpfpricegrp"><div class="prodfilter filtertext ectpfpricetext">' . $filtertext[2] . '</div>';
					$rowcounter=2;
					$currpriceband=getget('sprice');
					print '<div class="prodfilter ectpfprice">';
					?><select name="sprice" class="ectselectinput prodfilter" id="spriceobj" size="1" onchange="filterbyman(4)">
					<option value="0"><?php print $GLOBALS['xxPriRan']?></option>
<?php				if($minprice==0 || $filterpricebands>=$minprice){ ?>
					<option value="1"<?php if($currpriceband=="1") print ' selected'?>><?php print $GLOBALS['xxFilUnd'].' '.FormatCurrencyZeroDP($filterpricebands)?></option>
<?php				}
					if(strpos($sprice,'-')!==FALSE && $GLOBALS['paminprice']!='' && $GLOBALS['pamaxprice']!='' && $filterpricebands>=$GLOBALS['paminprice']){ ?>
					<option value="<?php print $sprice?>" selected><?php print FormatCurrencyZeroDP($GLOBALS['paminprice'])." - ".FormatCurrencyZeroDP($GLOBALS['pamaxprice'])?></option>
<?php				}
					for($index=$filterpricebands; $index<$maxprice; $index+=$filterpricebands){
						if(strpos($sprice,'-')!==FALSE && $GLOBALS['paminprice']!='' && $GLOBALS['pamaxprice']!='' && $index<=$GLOBALS['paminprice'] && ($index+$filterpricebands)>=$GLOBALS['paminprice']){ ?>
					<option value="<?php print $sprice?>" selected><?php print FormatCurrencyZeroDP($GLOBALS['paminprice'])." - ".FormatCurrencyZeroDP($GLOBALS['pamaxprice'])?></option>
<?php					}
						if($minprice==0 || ($index+$filterpricebands)>=$minprice){ ?>
					<option value="<?php print $rowcounter?>"<?php if($currpriceband==$rowcounter) print ' selected'?>><?php print FormatCurrencyZeroDP($index)." - ".FormatCurrencyZeroDP($index+$filterpricebands)?></option>
<?php					}
						$rowcounter++;
						if($rowcounter>1000) break;
					} ?>
					</select><?php
					print '</div>';
					if($filtertext[2]!='') print '</div>';
				}
			break;
			case 8:
				if(($prodfilter & 8)==8 && $sortoptions!=0){
					if($filtertext[3]!='') print '<div class="prodfiltergrp ectpfsortgrp"><div class="prodfilter filtertext ectpfsorttext">' . $filtertext[3] . '</div>';
					print  '<div class="prodfilter ectpfsort">';
					?><select class="ectselectinput prodfilter" size="1" onchange="changelocation('sortby',this)">
					<option value="0"><?php print $GLOBALS['xxSortBy']?></option>
<?php				sortline(1, @$GLOBALS['sortoption1']!=''?$GLOBALS['sortoption1']:'Sort Alphabetically');
					sortline(11, @$GLOBALS['sortoption11']!=''?$GLOBALS['sortoption11']:'Alphabetically (Desc.)');
					sortline(2, @$GLOBALS['sortoption2']!=''?$GLOBALS['sortoption2']:'Sort by Product ID');
					sortline(12, @$GLOBALS['sortoption12']!=''?$GLOBALS['sortoption12']:'Product ID (Desc.)');
					sortline(14, @$GLOBALS['sortoption14']!=''?$GLOBALS['sortoption14']:'Sort By SKU');
					sortline(15, @$GLOBALS['sortoption15']!=''?$GLOBALS['sortoption15']:'Sort By SKU (Desc.)');
					sortline(3, @$GLOBALS['sortoption3']!=''?$GLOBALS['sortoption3']:'Sort Price (Asc.)');
					sortline(4, @$GLOBALS['sortoption4']!=''?$GLOBALS['sortoption4']:'Sort Price (Desc.)');
					sortline(5, @$GLOBALS['sortoption5']!=''?$GLOBALS['sortoption5']:'Database Order');
					sortline(6, @$GLOBALS['sortoption6']!=''?$GLOBALS['sortoption6']:'Product Order');
					sortline(7, @$GLOBALS['sortoption7']!=''?$GLOBALS['sortoption7']:'Product Order (Desc.)');
					sortline(8, @$GLOBALS['sortoption8']!=''?$GLOBALS['sortoption8']:'Date Added (Asc.)');
					sortline(9, @$GLOBALS['sortoption9']!=''?$GLOBALS['sortoption9']:'Date Added (Desc.)');
					sortline(10, @$GLOBALS['sortoption10']!=''?$GLOBALS['sortoption10']:'Sort by Manufacturer');
					sortline(16, @$GLOBALS['sortoption16']!=''?$GLOBALS['sortoption16']:'Number of Ratings');
					sortline(17, @$GLOBALS['sortoption17']!=''?$GLOBALS['sortoption17']:'Average Rating');
					sortline(18, @$GLOBALS['sortoption18']!=''?$GLOBALS['sortoption18']:'Sales Rank');
					sortline(19, @$GLOBALS['sortoption19']!=''?$GLOBALS['sortoption19']:'Popularity');
?>					</select><?php
					print '</div>';
					if($filtertext[3]!='') print '</div>';
				}
			break;
			case 16:
				if(($prodfilter & 16)==16){
					if($filtertext[4]!='') print '<div class="prodfiltergrp ectpfpagegrp"><div class="prodfilter filtertext ectpfpagetext">' . $filtertext[4] . '</div>';
					print '<div class="prodfilter ectpfpage">';
					?><select class="ectselectinput prodfilter" size="1" onchange="changelocation('perpage',this)">
<?php				for($index=1; $index<=5; $index++){
						print '<option value="'.$index.'"'.(@$_SESSION['perpage']==$index?' selected':'').'>'.($prodsperpage*$index).' '.$GLOBALS['xxPerPag'].'</option>';
					}
					if(@$GLOBALS['xxAllRes']!='') print '<option value="all"'.(@$_SESSION['perpage']=='all'?' selected':'').'>'.$GLOBALS['xxAllRes'].'</option>';
?>					</select><?php
					print '</div>';
					if($filtertext[4]!='') print '</div>';
				}
			break;
			case 32:
				if(($prodfilter & 32)==32){
					if($filtertext[5]!='') print '<div class="prodfiltergrp ectpfkeywordgrp"><div class="prodfilter filtertext ectpfkeywordtext">' . $filtertext[5] . '</div>';
					print '<div class="prodfilter ectpfkeyword">' ?><input onkeydown="changelocfiltertext(event.keyCode,this)" type="text" class="ecttextinput prodfilter" size="20" id="ectfilter" name="filter" value="<?php print htmlspecials(getget('filter'))?>" placeholder="<?php print $GLOBALS['xxSeaFil']?>" aria-label="<?php print $GLOBALS['xxSeaFil']?>"><?php
					print imageorbutton(@$imgfilterproducts,$GLOBALS['xxGo'],"prodfilter","document.location='".str_replace('&','&amp;',$filterurl)."'+encodeURIComponent(document.getElementById('ectfilter').value)",TRUE);
					print '</div>';
					if($filtertext[5]!='') print '</div>';
				}
			}
		}
		print '</div>';
	}
}
if(@$orprodsperpage!='') $adminProdsPerPage=$orprodsperpage;
$prodsperpage=$adminProdsPerPage;
checkCurrencyRates($currConvUser,$currConvPw,$currLastUpdate,$currRate1,$currSymbol1,$currRate2,$currSymbol2,$currRate3,$currSymbol3);
$tslist="";
$thetopts=$catid;
$topsectionids=$catid;
$categorydepth=0;
$isrootsection=FALSE;
$sectiondisabled=FALSE;
if(@$_SESSION['clientID']!='' && @$_SESSION['clientLoginLevel']!='') $minloglevel=$_SESSION['clientLoginLevel']; else $minloglevel=0;
if($manufacturers){
	$sSQL='SELECT '.getlangid('scName',131072).','.getlangid('scHeader',524288).' FROM searchcriteria WHERE scID=' . $manid;
	$result2=ect_query($sSQL) or ect_error();
	if($rs2=ect_fetch_assoc($result2)){ $mfname=$rs2[getlangid('scName',131072)]; $sectionheader=$rs2[getlangid('scHeader',524288)]; }else{ $mfname='Not Found'; header('HTTP/1.1 404 Not Found'); $GLOBALS['xxNoPrds']='<div class="ectwarning" style="text-align:center;padding:50px;overflow:auto;">This manufacturer could not be found.</div>'; }
	ect_free_result($result2);
	$tslist='<a class="ectlink" href="'.$GLOBALS['storehomeurl'].'">'.$GLOBALS['xxHome'].'</a> &raquo; <a class="ectlink" href="'.$manufacturerpageurl.'">'.$GLOBALS['xxManuf'].'</a> &raquo; ' . $mfname;
	if(@$explicitmanid!='') $sectionurl=htmlentities(str_replace(array('"',"'"),'',strip_tags(@$_SERVER['PHP_SELF'])));
	$isrootsection=TRUE;
}else{
	for($categorydepth=0; $categorydepth<=10; $categorydepth++){
		if($thetopts==$catalogroot){
			$caturl=$GLOBALS['storehomeurl'];
			$sSQL='SELECT sectionID,topSection,'.getlangid('sectionName',256).',rootSection,sectionDisabled,'.getlangid('sectionurl',2048).','.getlangid('sectionHeader',524288).','.getlangid('sectionFooter',524288)." FROM sections WHERE sectionID='" . $catalogroot . "'";
			$result=ect_query($sSQL) or ect_error();
			if($rs=ect_fetch_assoc($result)){
				$GLOBALS['xxHome']=$rs[getlangid('sectionName',256)];
				if(trim($rs[getlangid('sectionurl',2048)])!='') $caturl=$rs[getlangid('sectionurl',2048)];
				if($rs['sectionID']==(int)$catid){
					$sectionheader=$rs[getlangid('sectionHeader',524288)];
					$sectionfooter=$rs[getlangid('sectionFooter',524288)];
				}
			}
			ect_free_result($result);
			$tslist='<a class="ectlink" href="'.$caturl.'">' . $GLOBALS['xxHome'] . '</a>' . $tslist;
			break;
		}elseif($categorydepth==10){
			$tslist='<strong>Loop</strong>' . $tslist;
		}else{
			$sSQL='SELECT sectionID,topSection,'.getlangid('sectionName',256).',rootSection,sectionDisabled,'.getlangid('sectionurl',2048).' AS sectionurl,'.getlangid('sectionHeader',524288).','.getlangid('sectionFooter',524288)." FROM sections WHERE sectionID='" . escape_string($thetopts) . "'";
			$result2=ect_query($sSQL) or ect_error();
			if(ect_num_rows($result2) > 0){
				$rs2=ect_fetch_assoc($result2);
				if($rs2['sectionID']==(int)$catid){ $isrootsection=($rs2['rootSection']==1); $sectionheader=$rs2[getlangid('sectionHeader',524288)]; $sectionfooter=$rs2[getlangid('sectionFooter',524288)]; }
				if($rs2['sectionDisabled']>$minloglevel) $catid=-1;
				if($rs2['sectionID']==(int)$catid && $isrootsection){
					if(@$GLOBALS['dynamicbreadcrumbs'])
						$tslist='<div class="ectbreadcrumb"><span class="navcurrentcat">&raquo; ' . breadcrumbselect($rs2['sectionID'],$rs2['topSection']) . '</span></div>' . $tslist;
					else
						$tslist='<div class="ectbreadcrumb"><span class="navcurrentcat">&raquo; ' . $rs2[getlangid('sectionName',256)] . '</span></div>' . $tslist;
					if(@$explicitid!='' && trim($rs2['sectionurl'])!='') $sectionurl=trim($rs2['sectionurl']);
					if(@$explicitid=='' && trim($rs2['sectionurl'])!='' && @$redirecttostatic==TRUE){
						ob_end_clean();
						header('HTTP/1.1 301 Moved Permanently');
						if($rs2['sectionurl'][0]=='/')$thelocation='http://'.$_SERVER['HTTP_HOST'].$rs2['sectionurl'];elseif(substr(strtolower($rs2['sectionurl']),0,7)=='http://')$thelocation=$rs2['sectionurl'];else $thelocation='http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'],'/')).'/'.$rs2['sectionurl'];
						header('Location: '.$thelocation);
						exit;
					}
				}else{
					if(@$GLOBALS['dynamicbreadcrumbs'])
						$tslist='<div class="ectbreadcrumb">&raquo; ' . breadcrumbselect($rs2['sectionID'],$rs2['topSection']) . '</div>' . $tslist;
					else
						$tslist='<div class="ectbreadcrumb">&raquo; <a class="ectlink" href="' . getcategoryurl($rs2['sectionID'],$rs2[getlangid('sectionName',256)],$rs2['sectionurl'],$rs2['rootSection']) . '">' . $rs2[getlangid('sectionName',256)] . '</a></div>' . $tslist;
					if(trim($rs2['sectionurl'])!='' && @$explicitid!='' && $rs2['sectionID']==(int)$catid) $sectionurl=trim($rs2['sectionurl']);
				}
				$thetopts=$rs2['topSection'];
				$topsectionids.=',' . $thetopts;
			}else{
				if($tslist==''&&$catname!='Not Found'){
					$catname='Not Found';
					$catid=-1;
					$GLOBALS['prodfilter']=0;
					$GLOBALS['sidefilter']=0;
					$GLOBALS['noshowdiscounts']=TRUE;
					header('HTTP/1.1 404 Not Found');
				}
				$tslist='<a class="ectlink" href="'.$GLOBALS['storehomeurl'].'">'.$GLOBALS['xxHome'].'</a> ' . ($catid!=-1 ? '&raquo; Top Section Deleted ' : '') . $tslist . ' &raquo; <a class="ectlink" href="' . (@$seocategoryurls?str_replace('%s','',$GLOBALS['seoprodurlpattern']):'products'.$GLOBALS['extension']) . '">' . $GLOBALS['xxAlProd'] . '</a>';
				$GLOBALS['xxAlProd']='';
				break;
			}
			ect_free_result($result2);
		}
	}
}
if(! $isrootsection && @$GLOBALS['xxAlProd']!='') $tslist.='<div class="ectbreadcrumb">&raquo; ' . $GLOBALS['xxAlProd'] . '</div>';
$filtersql='';
if(getget('filter')!=''){
	$Xstext=escape_string(substr(getget('filter'), 0, 1024));
	$aText=explode(' ',$Xstext);
	$aFields[0]='products.pId';
	$aFields[1]=getlangid('pName',1);
	$aFields[2]=getlangid('pDescription',2);
	$aFields[3]=getlangid('pLongDescription',4);
	$aFields[4]='pSKU';
	$aFields[5]='pSearchParams';
	$sNOTSQL=$sYESSQL='';
	foreach($aText as $theopt){
		$tmpSQL='';
		$arrelms=count($aText);
		for($index=0;$index<=5;$index++){
			if(is_array($theopt))$theopt=$theopt[0];
			if(! ((@$nosearchdescription==TRUE && $index==2) || (@$nosearchlongdescription==TRUE && $index==3) || (@$nosearchsku==TRUE && $index==4) || (@$nosearchparams==TRUE && $index==5)))
				$tmpSQL.=getlike($aFields[$index], $theopt, 'OR ');
		}
		if($tmpSQL!='') $sYESSQL.= '(' . substr($tmpSQL, 0, strlen($tmpSQL)-3) . ') ';
		if($tmpSQL!='') $sYESSQL.='AND ';
	}
	$sYESSQL=substr($sYESSQL, 0, -4);
	if($sYESSQL!='') $filtersql=' AND (' . $sYESSQL . ') ';
	if($sNOTSQL!='') $filtersql.=' AND NOT (' . substr($sNOTSQL, 0, strlen($sNOTSQL)-4) . ')';
}
$GLOBALS['paminprice']=$GLOBALS['pamaxprice']='';
if($sprice!=''){
	$taxlevel=1;
	if(@$GLOBALS['showtaxinclusive']===2) $taxlevel+=($countryTaxRate/100.0);
	if(strpos($sprice,'-')!==FALSE){
		$spricearr=explode('-',$sprice);
		$GLOBALS['paminprice']=$spricearr[0];
		$GLOBALS['pamaxprice']=$spricearr[1];
		if(is_numeric($GLOBALS['pamaxprice'])){
			if(! is_numeric($GLOBALS['paminprice'])) $GLOBALS['paminprice']=0;
		}else
			$GLOBALS['pamaxprice']='';
	}elseif(is_numeric($sprice)){
		$priceband=(int)$sprice;
		$GLOBALS['paminprice']=($priceband-1)*$filterpricebands;
		$GLOBALS['pamaxprice']=$priceband*$filterpricebands;
	}
	if($GLOBALS['paminprice']!=='' && $GLOBALS['pamaxprice']!='') $filtersql.=' AND ((' . $TWSP . '*'.$taxlevel.')>=' . $GLOBALS['paminprice'] . ' AND (' . $TWSP . '*'.$taxlevel.')<=' . $GLOBALS['pamaxprice'] . ')';
}
if(($prodfilter & 1)==1 && ! $manufacturers){
	$manid=getget('sman');
	if(! is_numeric($manid)) $manid="";
}
$GLOBALS['sectionids']='';
if((($GLOBALS['sidefilter'] & 2)==2 || ($GLOBALS['prodfilter'] & 2)==2) && !@$GLOBALS['alreadycheckedscsql']){
	$GLOBALS['numscrid']=0;
	$GLOBALS['numscrgroup']=0;
	if($GLOBALS['scrid']!=''){
		$currgroup=-1;
		$GLOBALS['scSQL']='(multisearchcriteria.mSCscID IN (';
		$sSQL='SELECT scID,scGroup,'.getlangid('scName',131072).' FROM searchcriteria WHERE scID IN (' . $GLOBALS['scrid'] . ') ORDER BY scGroup';
		$result=ect_query($sSQL) or ect_error();
		$GLOBALS['scrid']='';
		$GLOBALS['removalbuttons']='';
		while($rs=ect_fetch_assoc($result)){
			$GLOBALS['scrid'].=$rs['scID'].',';
			$GLOBALS['removalbuttons'].='<button class="ectbutton removefilter" onclick="ectRAm(' . $rs['scID'] . ',false,false)">' . $rs[getlangid('scName',131072)] . '</button> ';
			if($rs['scGroup']!=$currgroup){
				$addcomma='';
				if($currgroup!=-1) $GLOBALS['scSQL'].=') AND msc'.$GLOBALS['numscrgroup'].'.mSCscID IN (';
				$GLOBALS['numscrgroup']++;
				$currgroup=$rs['scGroup'];
			}
			$GLOBALS['scSQL'].=$addcomma.$rs['scID'];
			$addcomma=',';
		}
		if($GLOBALS['scrid']!=''){
			$GLOBALS['scrid']=rtrim($GLOBALS['scrid'],',');
			$GLOBALS['scridarr']=explode(',',$GLOBALS['scrid']);
			$GLOBALS['numscrid']=count($GLOBALS['scridarr']);
		}
		if($GLOBALS['numscrid']==0) $GLOBALS['scSQL']=''; else $GLOBALS['scSQL'].='))';
	}else
		$GLOBALS['scSQL']='';
	$GLOBALS['alreadycheckedscsql']=TRUE;
}
if(getget('recentview')=='true')
	$sSQL='SELECT SQL_CALC_FOUND_ROWS products.pId,'.getlangid('pName',1).','.$WSP.'pPrice,pOrder,pDateAdded,pManufacturer,pSKU,pPopularity,pNumSales FROM products INNER JOIN recentlyviewed ON recentlyviewed.rvProdID=products.pID WHERE ' . (@$_SESSION['clientID']!='' ? 'rvCustomerID=' . escape_string(@$_SESSION['clientID']) : "(rvCustomerID=0 AND rvSessionID='".getsessionid()."')");
else{
	$result2=ect_query('SELECT sectionID FROM sections WHERE sectionDisabled>'.$minloglevel.' LIMIT 0,1') or ect_error();
	if($rs2=ect_fetch_assoc($result2)) $disabledsections=TRUE; else $disabledsections=FALSE;
	ect_free_result($result2);
	if($catid==$catalogroot&&@$GLOBALS['ectsiteid']==''){
		$sSQL='SELECT SQL_CALC_FOUND_ROWS products.pId,'.getlangid('pName',1).','.$WSP.'pPrice,pOrder,pDateAdded,pManufacturer,pSKU,pPopularity,pNumSales FROM ';
		if($GLOBALS['numscrgroup']>1) $sSQL.=str_repeat('(',$GLOBALS['numscrgroup']-1);
		$sSQL.='products' . ($disabledsections?' INNER JOIN sections ON products.pSection=sections.sectionID':'') . ($GLOBALS['scrid']!=''?' INNER JOIN multisearchcriteria ON multisearchcriteria.mSCpID=products.pID':'');
		for($scrindex=1; $scrindex<=$GLOBALS['numscrgroup']-1; $scrindex++){
			$sSQL.=') INNER JOIN multisearchcriteria msc'.$scrindex.' ON products.pID=msc'.$scrindex.'.mSCpID';
		}
		$sSQL.=' WHERE' . ($disabledsections?' sectionDisabled<='.$minloglevel.' AND':'') . (@$GLOBALS['ectsiteid']!='' ? ' pSiteID='.$GLOBALS['ectsiteid'].' AND' : '') . ' pDisplay<>0' . $filtersql;
	}else{
		$GLOBALS['sectionids']=getsectionids($catid, FALSE);
		$sSQL='SELECT SQL_CALC_FOUND_ROWS DISTINCT products.pId,'.getlangid('pName',1).','.$WSP.'pPrice,pOrder,pDateAdded,pManufacturer,pSKU,pPopularity,pNumSales FROM ';
		if($GLOBALS['numscrgroup']>1) $sSQL.=str_repeat('(',$GLOBALS['numscrgroup']-1);
		$sSQL.='(products LEFT JOIN multisections ON products.pId=multisections.pId)' . ($disabledsections?' INNER JOIN sections ON products.pSection=sections.sectionID':'') . ($GLOBALS['scrid']!=''?' INNER JOIN multisearchcriteria ON multisearchcriteria.mSCpID=products.pID':'');
		for($scrindex=1; $scrindex<=$GLOBALS['numscrgroup']-1; $scrindex++){
			$sSQL.=') INNER JOIN multisearchcriteria msc'.$scrindex.' ON products.pID=msc'.$scrindex.'.mSCpID';
		}
		$sSQL.=' WHERE' . ($disabledsections?' sectionDisabled<='.$minloglevel.' AND':'') . (@$GLOBALS['ectsiteid']!='' ? ' pSiteID='.$GLOBALS['ectsiteid'].' AND' : '') . ' pDisplay<>0' . $filtersql.' AND (products.pSection IN (' . $GLOBALS['sectionids'] . ') OR multisections.pSection IN (' . $GLOBALS['sectionids'] . '))';
	}
	if(@$GLOBALS['customproductsearch']!='') $sSQL.=' AND ' . $GLOBALS['customproductsearch'];
	if($manid!='0' && is_numeric($manid)) $sSQL.=' AND pManufacturer=' . $manid;
	if(@$GLOBALS['scSQL']!='') $sSQL.=' AND ' . $GLOBALS['scSQL'];
	if($GLOBALS['scrid']!=''||$sprice!=''||getget('filter')!=''){
		$GLOBALS['xxNoPrds']=$GLOBALS['xxNoMatc'].'<div class="resetfilters">'.imageorbutton(@$resetfilters,$GLOBALS['xxResFil'],'resetfilters',$manfilterurl,FALSE).'</div>';
		$GLOBALS['xxPagNoA']='';
	}
	if($GLOBALS['useStockManagement'] && @$GLOBALS['noshowoutofstock']) $sSQL.=' AND pInStock>pMinQuant';
}
if(@$_REQUEST['perpage']!='' && is_numeric(@$_REQUEST['perpage'])) $_SESSION['perpage']=(int)@$_REQUEST['perpage'];
if(@$_REQUEST['perpage']=='all' && @$GLOBALS['xxAllRes']!='') $_SESSION['perpage']='all';
if(@$_SESSION['perpage']!='' && is_numeric(@$_SESSION['perpage'])) $adminProdsPerPage=(int)$_SESSION['perpage']*$prodsperpage;
if(@$_SESSION['perpage']=='all' && @$GLOBALS['xxAllRes']!='') $adminProdsPerPage=4000;
if($adminProdsPerPage>1000 && @$GLOBALS['xxAllRes']=='') $adminProdsPerPage=$prodsperpage;
if($adminProdsPerPage>4000) $adminProdsPerPage=$prodsperpage;
if(@$GLOBALS['customsortby']!='')
	$sSortBy=' ORDER BY ' . $GLOBALS['customsortby'];
elseif(@$dosortby==2 || @$dosortby==12)
	$sSortBy=' ORDER BY products.pId'.(@$dosortby==12?' DESC':'');
elseif(@$dosortby==14||@$dosortby==15)
	$sSortBy=' ORDER BY pSKU'.(@$dosortby==15?' DESC,pId':',pId');
elseif(@$dosortby==3||@$dosortby==4)
	$sSortBy=' ORDER BY '.$TWSP.(@$dosortby==4?' DESC,pId':',pId');
elseif(@$dosortby==5)
	$sSortBy='';
elseif(@$dosortby==6||@$dosortby==7)
	$sSortBy=' ORDER BY pOrder'.(@$dosortby==7?' DESC,pId':',pId');
elseif(@$dosortby==8||@$dosortby==9)
	$sSortBy=' ORDER BY pDateAdded'.(@$dosortby==9?' DESC,pId':',pId');
elseif(@$dosortby==10)
	$sSortBy=' ORDER BY pManufacturer,pID';
elseif(@$dosortby==16)
	$sSortBy=' ORDER BY pNumRatings DESC,pId';
elseif(@$dosortby==17)
	$sSortBy=' ORDER BY IF(pNumRatings=0,0,pTotRating/pNumRatings) DESC,pNumRatings DESC,pId';
elseif(@$dosortby==18)
	$sSortBy=' ORDER BY pNumSales DESC,pId';
elseif(@$dosortby==19)
	$sSortBy=' ORDER BY pPopularity DESC,pId';
else
	$sSortBy=' ORDER BY '.getlangid('pName',1).(@$dosortby==11?' DESC,pId':',pId');
$sSQL.= $sSortBy . ' LIMIT ' . ($adminProdsPerPage*($CurPage-1)) . ', '.$adminProdsPerPage;
$allprods=ect_query($sSQL) or ect_error();
$foundrows=ect_query('SELECT FOUND_ROWS() AS bar') or ect_error();
$rs=ect_fetch_assoc($foundrows);
$iNumOfPages=ceil($rs['bar']/$adminProdsPerPage);
ect_free_result($foundrows);		
if(ect_num_rows($allprods) > 0){
	$prodlist='';
	$addcomma='';
	while($rs=ect_fetch_assoc($allprods)){
		$prodlist.=$addcomma . "'" . $rs['pId'] . "'";
		$addcomma=',';
	}
	ect_free_result($allprods);
	$GLOBALS['wantmanufacturer']=(strpos(@$GLOBALS['productpagelayout'].@$GLOBALS['quickbuylayout'],'manufacturer')!==FALSE) || (@$useproductbodyformat==3 && strpos(@$GLOBALS['cpdcolumns'], 'manufacturer')!==FALSE) || ((! @$GLOBALS['usecsslayout'] || @$useproductbodyformat!=2) && @$GLOBALS['xxManLab']!='') || @$GLOBALS['googletagid']!='';
	$sSQL='SELECT pId,pSKU,'.getlangid('pName',1).','.$WSP.'pPrice,pListPrice,pSection,pSell,pStockByOpts,pStaticPage,'.getaltlang('pStaticURL',8388608).',pInStock,pExemptions,pTax,pTotRating,pNumRatings,pBackOrder,pCustomCSS,';
	$templayoutarray=explode(',',strtolower(@$GLOBALS['productpagelayout'].','.@$GLOBALS['quickbuylayout']));
	foreach($templayoutarray as $layoutoption){
		if(substr(strtolower(trim($layoutoption)),0,6)=='custom'){
			if(strpos($sSQL,str_replace('custom','pCustom',$layoutoption).',')===FALSE)$sSQL.=str_replace('custom','pCustom',$layoutoption).',';
		}elseif(substr(trim($layoutoption),0,1)=='<'&&preg_match('/%custom(\d+)%/i',$layoutoption,$matchnum)){
			if(strpos($sSQL,'pCustom'.$matchnum[1].',')===FALSE)$sSQL.='pCustom'.$matchnum[1].',';
		}
	}
	$sSQL.='pDateAdded,pMinQuant,pSchemaType,'.($GLOBALS['wantmanufacturer']?getlangid('scName',131072).',':'').(@$shortdescriptionlimit===0?"'' AS ":'').getlangid('pDescription',2).','.getlangid('pLongDescription',4).' FROM products '.($GLOBALS['wantmanufacturer']?'LEFT OUTER JOIN searchcriteria on products.pManufacturer=searchcriteria.scID ':'').'WHERE pId IN (' . $prodlist . ')' . $sSortBy;
	$allprods=ect_query($sSQL) or ect_error();
}
if(! @isset($Count)) $Count=0; else $Count=($Count+$adminProdsPerPage)-($Count % $adminProdsPerPage);
if(@$nowholesalediscounts==TRUE && @$_SESSION['clientUser']!='')
	if((($_SESSION['clientActions'] & 8)==8) || (($_SESSION['clientActions'] & 16)==16)) $GLOBALS['noshowdiscounts']=TRUE;
if(@$GLOBALS['noshowdiscounts']!=TRUE){
	$sSQL='SELECT DISTINCT cpnID,'.getlangid('cpnName',1024).',cpnType,cpnSitewide,cpaType FROM coupons LEFT OUTER JOIN cpnassign ON coupons.cpnID=cpnassign.cpaCpnID WHERE (';
	$addor='';
	if($catid!='0'||$manufacturers){
		$sSQL.=$addor . '((cpnSitewide=0 OR cpnSitewide=3 OR cpnSitewide=4) AND cpaType='.($manufacturers?3:1)." AND cpaAssignment IN ('" . ($manufacturers?$manid:str_replace(",","','",$topsectionids)) . "'))";
		$addor=' OR ';
	}
	$sSQL.=$addor . "(cpnSitewide=1 OR cpnSitewide=2)) AND cpnNumAvail>0 AND cpnStartDate<='" . date('Y-m-d',time()) ."' AND cpnEndDate>='" . date('Y-m-d',time()) ."' AND cpnIsCoupon=0 AND ((cpnLoginLevel>=0 AND cpnLoginLevel<=".$minloglevel.') OR (cpnLoginLevel<0 AND -1-cpnLoginLevel='.$minloglevel.')) ORDER BY '.getlangid('cpnName',1024);
	$result2=ect_query($sSQL) or ect_error();
	if(ect_num_rows($result2) > 0){
		$lastcouponname='';
		while($rs2=ect_fetch_assoc($result2)){
			if($rs2[getlangid('cpnName',1024)]!=$lastcouponname) $globaldiscounttext.='<div class="adiscount">' . ($lastcouponname=$rs2[getlangid('cpnName',1024)]) . '</div>';
			if($rs2['cpnType']==0) $hasshippingdiscount=TRUE; else $hasproductdiscount=TRUE;
			if($catid!='0'||$manid!=''){
				if(($rs2['cpnSitewide']==0 || $rs2['cpnSitewide']==3 || $rs2['cpnSitewide']==4) && ($rs2['cpaType']==1||$rs2['cpaType']==3)){
					$globaldiscounts[$maxglobaldiscounts][0]=$rs2['cpnID'];
					$globaldiscounts[$maxglobaldiscounts][1]=$rs2[getlangid('cpnName',1024)];
					$globaldiscounts[$maxglobaldiscounts][2]='xxx';
					$maxglobaldiscounts++;
				}
			}
		}
	}
	ect_free_result($result2);
}
if(@$GLOBALS['ectsiteid']!='') $_SESSION['savecatid']=$catid;
$GLOBALS['alreadycalculatedattributes']=TRUE;
		if(! @$usecsslayout){
?>
	<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
		<tr> 
			<td colspan="3" width="100%">
<?php	}else
			print '<div>';
		if($sectionheader) print '<div class="catheader">' . $sectionheader . '</div>';
if(@$useproductbodyformat==3)
	include './vsadmin/inc/incproductbody3.php';
elseif(@$useproductbodyformat==2)
	include './vsadmin/inc/incproductbody2.php';
else
	include './vsadmin/inc/incproductbody.php';
ect_free_result($allprods);
		if($sectionfooter) print '<div class="catfooter">' . $sectionfooter . '</div>';
		if(! @$usecsslayout){ ?>
			</td>
		</tr>
	</table>
<?php	}else
			print '</div>';
?>