<?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(@$storesessionvalue=="") $storesessionvalue="virtualstore".time();
if(@$_SESSION['loggedon']!=$storesessionvalue||@$GLOBALS['disallowlogin']||!@$GLOBALS['incfunctionsdefined']) exit;
$success=TRUE;
if(@$admincatsperpage=='')$admincatsperpage=200;
if(is_numeric(getrequest("perpage"))) $admincatsperpage=(int)getrequest("perpage");
if(getrequest("perpage")=="x") $admincatsperpage=1000000;
if(@$maxloginlevels=='') $maxloginlevels=5;
$dorefresh=FALSE;
$sortorder='';
if(strtolower($adminencoding)=='iso-8859-1') $raquo='»'; else $raquo='>';
function getstaticprodcurl($prodid,$prodname,$forcelower,$spacereplace,$removepunctuation,$addextension){
	if(getpost("addprodid")=="prepend") $prodname=$prodid." ".$prodname;
	if(getpost("addprodid")=="append") $prodname.=' '.$prodid;
	$prodname=replaceaccents($prodname);
	$prodname=strip_tags($prodname);
	if($forcelower) $prodname=strtolower($prodname);
	if($spacereplace=="remove") $spacereplace='';
	$prodname=replace($prodname," ",$spacereplace);
	if($removepunctuation){
		$prodname=preg_replace('/&(?:[a-z\d]+|#\d+|#x[a-f\d]+);/i','',$prodname);
		$prodname=preg_replace('/[$&+,\/:;=?@\'"<>#%{}|\\^~\[\]`]/','',$prodname);
	}
	if($spacereplace!=''){
		$prodname=preg_replace('/['.$spacereplace.']{2,}/',$spacereplace,$prodname);
	}
	if($addextension) $prodname.=".php";
	return($prodname);
}
function writemenulevel($id,$itlevel){
	global $allcatsa,$numcats,$thecat,$raquo;
	if($itlevel<10){
		$startindex=0;
		$highindex=$numcats-1;
		$hasmatch=FALSE;
		while($startindex<=$highindex){
			$midindex=floor(($startindex + $highindex) / 2);
			if($allcatsa[$midindex]['topSection']==$id){
				$hasmatch=TRUE;
				break;
			}
			if($id<$allcatsa[$midindex]['topSection'])
				$highindex=$midindex-1;
			else
				$startindex=$midindex+1;
		}
		if($hasmatch){
			while($midindex>0&&$allcatsa[$midindex-1]['topSection']==$id) $midindex--;
			for($wmlindex=$midindex; $wmlindex < $numcats; $wmlindex++){
				if($allcatsa[$wmlindex]['topSection']==$id){
					print "[" . $allcatsa[$wmlindex]['sectionID'] . ',' . $itlevel . ",'" . jsspecials($allcatsa[$wmlindex]['sectionWorkingName']) . "'";
					if($thecat==$allcatsa[$wmlindex]['sectionID']) print ',1';
					print "],\n";
					if($allcatsa[$wmlindex]['rootSection']==0) writemenulevel($allcatsa[$wmlindex]['sectionID'],$itlevel+1);
					if($wmlindex+1<$numcats && $allcatsa[$wmlindex+1]['topSection']>$id) break;
				}
			}
		}
	}
}
function dodeletecat($cid,$delimages){
	if(getpost("delimage")=="1"||$delimages){
		$sSQL="SELECT sectionImage FROM sections WHERE sectionID='" . $cid . "'";
		$result=ect_query($sSQL) or ect_error();
		if($rs=ect_fetch_assoc($result)){
			dodeleteimage($rs['sectionImage'],$errormsg);
		}
	}
	$sSQL="DELETE FROM cpnassign WHERE cpaType=1 AND cpaAssignment='" . $cid . "'";
	ect_query($sSQL) or ect_error();
	$sSQL="DELETE FROM sections WHERE sectionID=" . $cid;
	ect_query($sSQL) or ect_error();
	$sSQL="DELETE FROM multisections WHERE pSection=" . $cid;
	ect_query($sSQL) or ect_error();
}
$sSQL='';
$alldata='';
$alreadygotadmin=getadminsettings();
if(@$defaultcatimages=='') $defaultcatimages='images/';
$defaultprodimages=$defaultcatimages;
if(getpost('act')=='changepos'){
	$theid=(int)getpost('id');
	$neworder=((int)getpost('newval'))-1;
	$sSQL="SELECT sectionOrder,topSection FROM sections WHERE sectionID=" . $theid;
	$result=ect_query($sSQL) or ect_error();
	if($rs=ect_fetch_assoc($result)) $topsection=$rs['topSection'];
	ect_free_result($result);
	$rc=0;
	if(@$menucategoriesatroot && $catalogroot!=0){
		$sSQL="SELECT sectionID,topSection FROM sections WHERE (sectionID=".$topsection." OR topSection=".$topsection.") AND sectionID=".$catalogroot;
		$result=ect_query($sSQL) or ect_error();
		if($rs=ect_fetch_assoc($result)) $topsection=$rs['sectionID'].','.$rs['topSection'];
		ect_free_result($result);
	}
	$sSQL='SELECT sectionID,sectionOrder FROM sections WHERE topSection IN ('.$topsection.') ORDER BY sectionOrder';
	$result=ect_query($sSQL) or ect_error();
	while($rs=ect_fetch_assoc($result)){
		if($rs['sectionID']==$theid)
			$sSQL="UPDATE sections SET sectionOrder=".$neworder." WHERE sectionID=".$theid;
		else
			$sSQL="UPDATE sections SET sectionOrder=".($rc<$neworder?$rc:$rc+1)." WHERE sectionID=".$rs['sectionID'];
		ect_query($sSQL) or ect_error();
		$rc++;
	}
	ect_free_result($result);
	$dorefresh=TRUE;
}elseif(getpost('posted')=='1'){
	if(getpost('act')=='delete'){
		dodeletecat(getpost('id'),FALSE);
		$dorefresh=TRUE;
	}elseif(getpost('act')=='quickupdate'){
		foreach(@$_POST as $objItem => $objValue){
			if(substr($objItem, 0, 4)=='pra_'){
				$origid=substr($objItem, 4);
				$theid=getpost('pid'.$origid);
				$theval=trim(unstripslashes($objValue));
				$cract=getpost('cract');
				$sSQL='';
				if($cract=='can'){
					if($theval!='') $sSQL="UPDATE sections SET sectionName='" . escape_string($theval) . "'";
				}elseif($cract=='can2'||$cract=='can3'){
					$sSQL="UPDATE sections SET sectionName".($cract=='can2'?'2':'3')."='" . escape_string($theval) . "'";
				}elseif($cract=='cwn'){
					if($theval!='') $sSQL="UPDATE sections SET sectionWorkingName='" . escape_string($theval) . "'";
				}elseif($cract=='cim'){
					$sSQL="UPDATE sections SET sectionImage='" . escape_string($theval) . "'";
				}elseif($cract=='dis'&&getpost('currentdiscount')!=''){
					ect_query("DELETE FROM cpnassign WHERE cpaType=1 AND cpaAssignment='".escape_string($theid)."' AND cpaCpnID=".getpost('currentdiscount')) or ect_error();
					if(getpost('prb_' . $origid)=='1'){
						ect_query("INSERT INTO cpnassign (cpaType,cpaAssignment,cpaCpnID) VALUES (1,'".escape_string($theid)."',".getpost('currentdiscount').')');
					}
				}elseif($cract=='ptt')
					$sSQL="UPDATE sections SET sTitle='" . escape_string($theval) . "'";
				elseif($cract=='ptt2')
					$sSQL="UPDATE sections SET sTitle2='" . escape_string($theval) . "'";
				elseif($cract=='ptt3')
					$sSQL="UPDATE sections SET sTitle3='" . escape_string($theval) . "'";
				elseif($cract=='med')
					$sSQL="UPDATE sections SET sMetaDesc='" . escape_string($theval) . "'";
				elseif($cract=='med2')
					$sSQL="UPDATE sections SET sMetaDesc2='" . escape_string($theval) . "'";
				elseif($cract=='med3')
					$sSQL="UPDATE sections SET sMetaDesc3='" . escape_string($theval) . "'";
				elseif($cract=='cur'){
					$sSQL="UPDATE sections SET sectionURL='" . escape_string($theval) . "'";
				}elseif($cract=='lol'){
					$sSQL="UPDATE sections SET sectionDisabled='" . escape_string($theval) . "'";
				}elseif($cract=='rec'){
					$sSQL='UPDATE sections SET sRecommend=' . (@$_POST['prb_' . $origid]=='1'?'1':'0');
				}elseif($cract=='cur2'||$cract=='cur3'){
					$sSQL="UPDATE sections SET sectionURL".($cract=='cur2'?'2':'3')."='" . escape_string($theval) . "'";
				}elseif($cract=='css'){
					$sSQL="UPDATE sections SET sCustomCSS='" . escape_string($theval) . "'";
				}elseif($cract=='del'){
					if($theval=='del') dodeletecat($theid,FALSE);
					$sSQL='';}
				elseif($cract=='dei'){
					if($theval=='del') dodeletecat($theid,TRUE);
					$sSQL='';
				}elseif(substr($cract,0,3)=='csu'){
					$langid=substr($cract,3);
					$result=ect_query("SELECT sectionID,sectionName".$langid." FROM sections WHERE sectionID='".escape_string($theid)."'") or ect_error();
					if($rs=ect_fetch_assoc($result))
						$sSQL="UPDATE sections SET sectionURL".$langid."='".escape_string(getstaticprodcurl($rs['sectionID'],$rs['sectionName'.$langid],getpost("lcase")=="yes",@$_POST['space'],getpost("punctuation")=="remove",getpost("extension")=="yes"))."'";
					ect_free_result($result);
				}
				if($sSQL!=''){
					$sSQL.=" WHERE sectionID='".escape_string($theid)."'";
					ect_query($sSQL) or ect_error();
				}
			}
		}
		$dorefresh=TRUE;
	}elseif(getpost('act')=='domodify'){
		$olddisabled=0;
		$sSQL="SELECT sectionDisabled FROM sections WHERE sectionID=" . getpost('id');
		$result=ect_query($sSQL) or ect_error();
		if($rs=ect_fetch_assoc($result)){
			$olddisabled=$rs['sectionDisabled'];
		}
		ect_free_result($result);
		$sSQL="UPDATE sections SET sectionName='" . escape_string(getpost('secname')) . "',sectionDescription='" . escape_string(getpost('secdesc')) . "',sectionImage='" . escape_string(getpost('secimage')) . "',topSection=" . getpost('tsTopSection') . ",rootSection=" . getpost('catfunction');
		$workname=escape_string(getpost('secworkname'));
		if($workname!='')
			$sSQL.=",sectionWorkingName='" . $workname . "'";
		else
			$sSQL.=",sectionWorkingName='" . escape_string(getpost('secname')) . "'";
		for($index=2; $index <= $adminlanguages+1; $index++){
			if(($adminlangsettings & 256)==256) $sSQL.=",sectionName" . $index . "='" . escape_string(getpost('secname' . $index)) . "'";
			if(($adminlangsettings & 512)==512) $sSQL.=",sectionDescription" . $index . "='" . escape_string(getpost('secdesc' . $index)) . "'";
			if(($adminlangsettings & 2048)==2048) $sSQL.=',sectionurl' . $index . "='" . escape_string(getpost('sectionurl' . $index)) . "'";
		}
		$sSQL.=",sectionDisabled=" . getpost('sectionDisabled');
		$sSQL.=",sectionHeader='" . escape_string(getpost('sectionHeader')) . "'";
		$sSQL.=",sectionFooter='" . escape_string(getpost('sectionFooter')) . "'";
		for($index=2; $index <= $adminlanguages+1; $index++){
			if(($adminlangsettings & 524288)==524288){
				$sSQL.=",sectionHeader" . $index . "='" . escape_string(getpost('sectionHeader' . $index)) . "'";
				$sSQL.=",sectionFooter" . $index . "='" . escape_string(getpost('sectionFooter' . $index)) . "'";
			}
			if(($adminlangsettings & 2097152)==2097152) $sSQL.=",sTitle" . $index . "='" . escape_string(getpost('sTitle' . $index)) . "'";
			if(($adminlangsettings & 2097152)==2097152) $sSQL.=",sMetaDesc" . $index . "='" . escape_string(getpost('sMetaDesc' . $index)) . "'";
		}
		$sSQL.=",sectionurl='" . escape_string(getpost('sectionurl')) . "',sTitle='" . escape_string(getpost('sTitle')) . "',sMetaDesc='" . escape_string(getpost('sMetaDesc')) . "'";
		$sSQL.=' WHERE sectionID=' . getpost('id');
		ect_query($sSQL) or ect_error();
		if(getpost('catalogroot')=='ON'){
			if($catalogroot!=(int)getpost('id'))
				ect_query('UPDATE admin SET catalogRoot='.getpost('id').' WHERE adminID=1') or ect_error();
		}else{
			if($catalogroot==(int)getpost('id'))
				ect_query('UPDATE admin SET catalogRoot=0 WHERE adminID=1') or ect_error();
		}
		if(($olddisabled!=(int)getpost('sectionDisabled') || getpost('forcesubsection')=='1') && getpost('forcesubsection')!='2'){
			$idlist=getpost('id');
			ect_query('UPDATE sections SET sectionDisabled=' . getpost('sectionDisabled') . ' WHERE topSection=' . $idlist) or ect_error();
			for($index=1; $index<=10; $index++){
				$sSQL='SELECT sectionID,sectionDisabled,rootSection FROM sections WHERE rootSection=0 AND topSection IN (' . $idlist . ')';
				$idlist='';
				$result=ect_query($sSQL) or ect_error();
				while($rs=ect_fetch_assoc($result)){
					$sSQL='UPDATE sections SET sectionDisabled=' . getpost('sectionDisabled') . ' WHERE topSection=' . $rs['sectionID'];
					ect_query($sSQL) or ect_error();
					$idlist.=$rs['sectionID'].',';
				}
				ect_free_result($result);
				if($idlist!='') $idlist=substr($idlist,0,-1); else break;
			}
		}
		$dorefresh=TRUE;
	}elseif(getpost('act')=="doaddnew"){
		$haveuniqueindex=FALSE;
		if(getpost('catfunction')=='2'){
			$uniqueindex=0;
			$mxOrder=0;
		}else{
			$uniqueindex=1;
			while(!$haveuniqueindex){
				$result=ect_query("SELECT sectionID FROM sections WHERE sectionID=".$uniqueindex) or ect_error();
				if(ect_num_rows($result)==0) $haveuniqueindex=TRUE; else $uniqueindex++;
				ect_free_result($result);
			}
			$sSQL="SELECT MAX(sectionOrder) AS mxOrder FROM sections";
			$result=ect_query($sSQL) or ect_error();
			$rs=ect_fetch_assoc($result);
			$mxOrder=$rs["mxOrder"];
			if(is_null($mxOrder) || $mxOrder=="") $mxOrder=1; else $mxOrder++;
			ect_free_result($result);
		}
		$sSQL="INSERT INTO sections (sectionID,sectionName,sectionName2,sectionName3,sectionDescription,sectionDescription2,sectionDescription3,sectionImage,sectionOrder,topSection,rootSection,sectionWorkingName";
		$sSQL.=',sectionDisabled,sectionHeader,sectionHeader2,sectionHeader3,sectionFooter,sectionFooter2,sectionFooter3';
		$sSQL.=',sectionurl,sectionurl2,sectionurl3,sTitle,sTitle2,sTitle3,sMetaDesc,sMetaDesc2,sMetaDesc3) VALUES ('.$uniqueindex.",'" . escape_string(getpost('secname')) . "','" . escape_string(getpost('secname2')) . "','" . escape_string(getpost('secname3')) . "','" . escape_string(getpost('secdesc')) . "','" . escape_string(getpost('secdesc2')) . "','" . escape_string(getpost('secdesc3')) . "','" . escape_string(getpost('secimage')) . "'," . $mxOrder . "," . getpost('tsTopSection') . "," . getpost('catfunction');
		$workname=escape_string(getpost('secworkname'));
		if($workname!='')
			$sSQL.=",'" . $workname . "'";
		else
			$sSQL.=",'" . escape_string(getpost('secname')) . "'";
		$sSQL.=',' . getpost('sectionDisabled');
		$sSQL.=",'" . escape_string(getpost('sectionHeader')) . "','" . escape_string(getpost('sectionHeader2')) . "','" . escape_string(getpost('sectionHeader3')) . "'";
		$sSQL.=",'" . escape_string(getpost('sectionFooter')) . "','" . escape_string(getpost('sectionFooter2')) . "','" . escape_string(getpost('sectionFooter3')) . "'";
		$sSQL.=",'" . escape_string(getpost('sectionurl')) . "','" . escape_string(getpost('sectionurl2')) . "','" . escape_string(getpost('sectionurl3')) . "','" . escape_string(getpost('sTitle')) . "','" . escape_string(getpost('sTitle2')) . "','" . escape_string(getpost('sTitle3')) . "','" . escape_string(getpost('sMetaDesc')) . "','" . escape_string(getpost('sMetaDesc2')) . "','" . escape_string(getpost('sMetaDesc3')) . "')";
		ect_query($sSQL) or ect_error();
		$dorefresh=TRUE;
	}elseif(getpost('act')=='dodiscounts'){
		$sSQL='INSERT INTO cpnassign (cpaCpnID,cpaType,cpaAssignment) VALUES (' . getpost('assdisc') . ",1,'" . getpost('id') . "')";
		ect_query($sSQL) or ect_error();
		$dorefresh=TRUE;
	}elseif(getpost('act')=='deletedisc'){
		$sSQL='DELETE FROM cpnassign WHERE cpaType=1 AND cpaID=' . getpost('id');
		ect_query($sSQL) or ect_error();
		$dorefresh=TRUE;
	}elseif(getpost('act')=='sort'){
		setcookie('catsort', getpost('sort'), time()+31536000, '/', '', @$_SERVER['HTTPS']=='on');
	}
	if(getpost("act")!="sort" && getpost("act")!="deletedisc" && getpost("act")!="dodiscounts"){
		ect_query("DELETE FROM subsectionidcache");
	}
}elseif(getget('catorman')!=''){
	setcookie('ccatorman', getget('catorman'), time()+80000000, '/', '', @$_SERVER['HTTPS']=='on');
}
if($dorefresh){
	print '<meta http-equiv="refresh" content="'.(getpost('act')=='changepos'?0:1).'; url=admincats.php';
	print '?sos=' . urlencode(getrequest('sos')) . '&stext=' . urlencode(getrequest('stext')) . '&catfun=' . @$_REQUEST['catfun'] . '&stype=' . getrequest('stype') . '&scat=' . getrequest('scat') . '&perpage=' . getrequest('perpage') . '&pg=' . getrequest('pg');
	print '">' . "\n";
}else{
?>
<script>
/* <![CDATA[ */
var deletedimage='data:image/gif;base64,R0lGODlhZABQAMZ7AMcaAMcgDcglFsgpHMgtIsgwJsk2Lsk5Msk8Nco/OMpBO8pDPcpGQMtIQstKRcxQS8xUT8xVUc1ZVc1bVs5eWs5fXM5hXc5iX89kYM9oZc9qZtBtatJwbdFxbtFycNJ2c9N4dtR+fNN/fdWDgdaEgtaGhNWIhteKiNeLideMitiOjNiQjtmTkdmVlNubmtudm9yfnt2hn92jot2ko96lo9+npt+pqN+qqd+rquCrquGvruGxr+GxsOO0s+O2teO3tuS4t+S7uuW7u+W8u+W9vObAwOfBwOfCwejExOjGxenHx+nJyOrKyerKyurLy+vMy+vNzOvOze3S0e7V1O7W1e/X1/DZ2PDa2vHc2/Hd3PLe3fLf3/Pg3/Pg4PTi4vTj4/Tk5PTl5fXn5/bq6vfs7Pft7fju7vjv7/nw8Pnx8fry8vrz8/v19fv29vv39vz39/z4+Pz5+f36+v37+/38+/38/P78/P79/f7+/v/+/v///0RERERERERERERERERERCH5BAEKAH8ALAAAAABkAFAAAAf+gHqCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tqtpDAC7vL0mkm0QvcMALLeCTcTDSpEvyrwNaseCKM+7CWePU9a7T9OCZwncJ47B3Crfg0ncAEuNztYKaOmCeSTc8ovb3O70gmUGuKVQZM7aL3+DirBrkgjeMwRmEA66E4LbgjSH9llDIpHQmALnDBV8NiJPR0JC2Dkp5FCZATInCdn5wI0BRkEanxWJWUjMAG4rBI1UFuIOz0I+2EHR05JYgTFHC9HhwK0BEnZEohr6IoAdNxBGtRba4fUZATFiDcnJUJYYkLT+h7i07eWhDtxDN+YCEBDm7qE4Fub28IsIS9sNcwgjmuE1gBfFiN5MYKcDMqI2Edi5sHyo6bMpnAlRaQuhTWg9mOe+OO2ZHRXOo/UCiGBacWrZAGBAbt22CuHYuHdJcHP39rMIQdjFuMubF5U8JdhZSQv82WY9ZQ5wm/BGq3FlD9gMOsJOhtbmu6QQwiOC3ZWj1ZW1MPSRGwU4Mb8Tc7Dm0BB2NMSEHgBRIHIHCOxg0VF8xASViE/cVICfP/oNc9EiP7BTA0IDMsEIHR2wkwU9DA5DTiNgdGWNBXF8U2Ev2DzCAzs2fDNgEpDMoQE7WhxTYi8kmARJFwFwg0GLtbwqyIsBZUySAzs42DKgEZTEcQE7W5ym5ZZcdunll2CGKeaYZJZp5plolhkIADs=';
function formvalidator(theForm){
  if(theForm.secname.value==""){
    alert("<?php print jscheck($yyPlsEntr . ' "' . $yyCatNam)?>\".");
    theForm.secname.focus();
    return (false);
  }
  if(theForm.tsTopSection[theForm.tsTopSection.selectedIndex].value==""){
    alert("<?php print jscheck($yyPlsSel . ' "' . $yyCatSub)?>\".");
    theForm.tsTopSection.focus();
    return (false);
  }
  return (true);
}
function dodeleteimagecb(){
	if(ajaxobj.readyState==4){
		if(ajaxobj.responseText.substr(0,7)=='SUCCESS'){
			document.getElementById('secimage').value='';
			document.getElementById('previewimage').src=deletedimage;
			alert('Image Deleted Successfully');
		}else
			alert(ajaxobj.responseText);
	}
}
function deleteimage(imobj){
	if(confirm('Are you sure you want to delete this image?')){
		ajaxobj=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("MSXML2.XMLHTTP");
		ajaxobj.onreadystatechange=dodeleteimagecb;
		ajaxobj.open("GET","doupload.php?dodelete=true&imgfname="+encodeURIComponent(document.getElementById('secimage').value),true);
		ajaxobj.send(null);
	}
}
function uploadimage(imfield){
	var ajaxobj=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("MSXML2.XMLHTTP");
	document.getElementById('preloaderdiv').style.display='';
	ajaxobj.open("GET",'doupload.php?uploadform=admincats&imfield='+imfield+'&defaultprodimages='+encodeURIComponent('<?php print $defaultcatimages?>'),false);
	ajaxobj.send(null);
	document.getElementById('preloaderdiv').innerHTML=ajaxobj.responseText;
	//Globals
	imagefield=imfield
	fileselectinput=document.getElementById("fileselectinput");
	ectuploadimgsrc='';
	uploadedimages=0;
	hasfiletoupload=false;
	dropArea = document.getElementById("drag-area"),
	dragText = document.getElementById("uploadheader");
	button = document.getElementById("browsebutton");
	button.onclick = ()=>{
		fileselectinput.click(); // click button causes input click
	}
	fileselectinput.addEventListener("change", function(){ hasselectedimage(this.files); });
	dropArea.addEventListener("dragover", (event)=>{
		event.preventDefault();
		dropArea.classList.add("hoverwithfile");
		dragText.textContent = "Release to Upload Files";
	});
	dropArea.addEventListener("dragleave", ()=>{
		dropArea.classList.remove("hoverwithfile");
		dragText.textContent = "Drag & Drop Files to Upload Here";
	});
	dropArea.addEventListener("drop", (event)=>{
		dropArea.classList.remove("hoverwithfile");
		event.preventDefault();
		hasselectedimage(event.dataTransfer.files);
	});
}
function expandckeditor(divid){
	document.getElementById(divid).style.border='none';
	document.getElementById(divid).style.padding=0;
}
function displaymultilangname(elem){
	for(var index=2;index<=3;index++){
		if(document.getElementById(elem+index))document.getElementById(elem+index).style.display='block';
	}
}
function errorimage(e) {
	document.getElementById('previewimage').src='data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8IS0tIENyZWF0b3I6IENvcmVsRFJBVyAtLT4NCjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWw6c3BhY2U9InByZXNlcnZlIiB3aWR0aD0iNzJweCIgaGVpZ2h0PSI3MnB4IiB2ZXJzaW9uPSIxLjEiIHN0eWxlPSJzaGFwZS1yZW5kZXJpbmc6Z2VvbWV0cmljUHJlY2lzaW9uOyB0ZXh0LXJlbmRlcmluZzpnZW9tZXRyaWNQcmVjaXNpb247IGltYWdlLXJlbmRlcmluZzpvcHRpbWl6ZVF1YWxpdHk7IGZpbGwtcnVsZTpldmVub2RkOyBjbGlwLXJ1bGU6ZXZlbm9kZCINCnZpZXdCb3g9IjAgMCA3MiA3MiINCiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayINCiB4bWxuczp4b2RtPSJodHRwOi8vd3d3LmNvcmVsLmNvbS9jb3JlbGRyYXcvb2RtLzIwMDMiPg0KIDxkZWZzPg0KICA8c3R5bGUgdHlwZT0idGV4dC9jc3MiPg0KICAgPCFbQ0RBVEFbDQogICAgLmZpbDAge2ZpbGw6IzRENEQ0RH0NCiAgICAuZmlsMSB7ZmlsbDpyZWR9DQogICBdXT4NCiAgPC9zdHlsZT4NCiA8L2RlZnM+DQogPGcgaWQ9IkxheWVyX3gwMDIwXzEiPg0KICA8bWV0YWRhdGEgaWQ9IkNvcmVsQ29ycElEXzBDb3JlbC1MYXllciIvPg0KICA8cGF0aCBjbGFzcz0iZmlsMCIgZD0iTTIyLjk1IDE4LjM5YzIuMTcsMCAzLjkzLC0xLjc2IDMuOTMsLTMuOTMgMCwtMi4xNyAtMS43NiwtMy45MyAtMy45MywtMy45MyAtMi4xNywwIC0zLjkzLDEuNzYgLTMuOTMsMy45MyAwLDIuMTcgMS43NiwzLjkzIDMuOTMsMy45M3ptLTE1LjE3IDE4LjEybDE1LjE3IC0xNS4xNyA1LjA5IDUuMDkgOC42NyAtOC42NyAxNi42NCAxNi42MyAwIC0yNi42MSAtNDUuNTcgMCAwIDI4Ljczem0tMS44OSAtMzIuNTFsNTEuMjQgMCAwIDM2LjMzYy0wLjYyLC0wLjA4IC0xLjI1LC0wLjEyIC0xLjg5LC0wLjEyIC0wLjcsMCAtMS4zOCwwLjA1IC0yLjA1LDAuMTRsLTE2LjQ4IC0xNi40OCAtMTcgMTcgLTMuMDUgLTMuMDYgOC4zMiAtOC4zMiAtMi4wMyAtMi4wMyAtMTUuMTcgMTUuMTYgMCAxMC43MyAzMi41NSAwYy0wLjA4LDAuNjIgLTAuMTIsMS4yNSAtMC4xMiwxLjg5IDAsMC42NCAwLjA0LDEuMjcgMC4xMiwxLjg5bC0zNi4zMyAwIDAgLTUzLjEzIDEuODkgMHoiLz4NCiAgPHBhdGggY2xhc3M9ImZpbDEiIGQ9Ik00Ny44OSA1OS45MmwxMi4wMyAtMTIuMDNjLTEuMzUsLTAuODYgLTIuOTYsLTEuMzYgLTQuNjgsLTEuMzYgLTQuODEsMCAtOC43MSwzLjkgLTguNzEsOC43MSAwLDEuNzIgMC41LDMuMzMgMS4zNiw0LjY4em0xNC42OSAtOS4zNmwtMTIuMDIgMTIuMDJjMS4zNSwwLjg3IDIuOTYsMS4zNyA0LjY4LDEuMzcgNC44MSwwIDguNzEsLTMuOSA4LjcxLC04LjcxIDAsLTEuNzIgLTAuNSwtMy4zMyAtMS4zNywtNC42OHptNS40MiA0LjY4YzAsNy4wNSAtNS43MSwxMi43NiAtMTIuNzYsMTIuNzYgLTcuMDUsMCAtMTIuNzYsLTUuNzEgLTEyLjc2LC0xMi43NiAwLC03LjA1IDUuNzEsLTEyLjc2IDEyLjc2LC0xMi43NiA3LjA1LDAgMTIuNzYsNS43MSAxMi43NiwxMi43NnoiLz4NCiA8L2c+DQo8L3N2Zz4NCg==';
}
function changeimage(tobj){
	var timg=tobj.value;
	if(!(timg.substr(0,5).toLowerCase()=='http:'||timg.substr(0,6).toLowerCase()=='https:'||timg.substr(0,1)=='/'||timg==''))
		timg='../'+timg;
	else if(timg=='')
		timg=deletedimage;
	document.getElementById('previewimage').src=timg;
}
/* ]]> */
</script>
<?php
}
if(getpost('posted')=='1' && (getpost('act')=='modify' || getpost('act')=='addnew' || getpost('act')=='clone')){
		imageuploadscripts();
		print '<div id="preloaderdiv" class="ectopaque" style="display:none" onclick="if(event.target==this)this.style.display=\'none\'" tabindex="0"><img src="adminimages/preloader.gif" alt="" class="ectpreloader"></div>';
		if(@$htmleditor=='ckeditor'){ ?>
<script src="ckeditor/ckeditor.js"></script>
<?php	}
		$ntopsections=0;
		$sectionID='';
		$sectionName='';
		$sectionDescription='';
		for($index=2; $index <= $adminlanguages+1; $index++){
			$sectionNames[$index]='';
			$sectionDescriptions[$index]='';
			$sectionurls[$index]='';

			$pTitles[$index]='';
			$pMetaDescs[$index]='';
		}
		$sectionImage='';
		$sectionWorkingName='';
		$topSection=0;
		$sectionDisabled=0;
		$rootSection=1;
		$sectionurl='';
		$sTitle='';
		$sMetaDesc='';
		$sectionHeader=$sectionFooter='';
		$sSQL="SELECT sectionID, sectionWorkingName FROM sections WHERE rootSection=0 ORDER BY sectionWorkingName";
		$result=ect_query($sSQL) or ect_error();
		while($rs=ect_fetch_assoc($result))
			$alltopsections[$ntopsections++]=$rs;
		ect_free_result($result);
		if((getpost('act')=='modify' || getpost('act')=='clone') && is_numeric(getpost('id'))){
			$sSQL="SELECT sectionID,sectionName,sectionName2,sectionName3,sectionDescription,sectionDescription2,sectionDescription3,sectionImage,sectionWorkingName,topSection,sectionDisabled,rootSection,sectionurl";
			if(($adminlangsettings & 2048)==2048){
				if($adminlanguages>=1) $sSQL.=',sectionurl2';
				if($adminlanguages>=2) $sSQL.=',sectionurl3';
			}
			$sSQL.=',sTitle,sTitle2,sTitle3,sMetaDesc,sMetaDesc2,sMetaDesc3,sectionHeader,sectionHeader2,sectionHeader3,sectionFooter,sectionFooter2,sectionFooter3 FROM sections WHERE sectionID=' . getpost('id');
			$result=ect_query($sSQL) or ect_error();
			if($rs=ect_fetch_assoc($result)){
				$sectionID=$rs['sectionID'];
				$sectionName=$rs['sectionName'];
				$sectionDescription=$rs['sectionDescription'];
				for($index=2; $index <= $adminlanguages+1; $index++){
					$sectionNames[$index]=$rs['sectionName' . $index];
					$sectionDescriptions[$index]=$rs['sectionDescription' . $index];
					if(($adminlangsettings & 2048)==2048) $sectionurls[$index]=$rs['sectionurl' . $index];
					$pTitles[$index]=$rs['sTitle' . $index];
					$pMetaDescs[$index]=$rs['sMetaDesc' . $index];
				}
				$sectionImage=$rs['sectionImage'];
				$sectionWorkingName=$rs['sectionWorkingName'];
				$topSection=$rs['topSection'];
				$sectionDisabled=$rs['sectionDisabled'];
				$rootSection=$rs['rootSection'];
				$sectionurl=$rs['sectionurl'];
				$sectionHeader=$rs['sectionHeader'];
				$sectionFooter=$rs['sectionFooter'];
				$sTitle=$rs['sTitle'];
				$sMetaDesc=$rs['sMetaDesc'];
				for($index=2; $index<=$adminlanguages+1; $index++){
					$sectionHeaders[$index]=$rs['sectionHeader' . $index];
					$sectionFooters[$index]=$rs['sectionFooter' . $index];
				}
			}
			ect_free_result($result);
		}else{
			for($index=2; $index<=$adminlanguages+1; $index++){
				$sectionHeaders[$index]='';
				$sectionFooters[$index]='';
			}
		}
?>
		  <form name="mainform" method="post" action="admincats.php" onsubmit="return formvalidator(this)">
			<input type="hidden" name="posted" value="1">
			<?php if(getpost('act')=='modify'){ ?>
			<input type="hidden" name="act" value="domodify">
			<?php }else{ ?>
			<input type="hidden" name="act" value="doaddnew">
			<?php }
			writehiddenvar('stext', getpost('stext'));
			writehiddenvar('stype', getpost('stype'));
			writehiddenvar('catfun', getpost('catfun'));
			writehiddenvar('scat', getpost('scat'));
			writehiddenvar('pg', getpost('pg'));
			writehiddenvar('id', getpost('id'));
			writehiddenvar('sos', getpost('sos')); ?>
            <table width="100%" border="0" cellspacing="2" cellpadding="3">
			  <tr>
                <td width="100%" colspan="2" align="center"><strong><?php print (getpost('act')=='clone'?$yyClone.': ':(getpost('act')=='modify'?$yyModify.': ':'')) . $yyCatAdm?></strong><br>&nbsp;</td>
			  </tr>
			  <tr>
				<td align="right"><?php print $redasterix . $yyCatNam?>:</td><td><input type="text" name="secname" style="width:100%;max-width:500px" value="<?php print htmlspecialsucode($sectionName)?>"></td>
			  </tr>
<?php	for($index=2; $index <= $adminlanguages+1; $index++){
			if(($adminlangsettings & 256)==256){ ?>
			  <tr>
				<td align="right"><?php print $yyCatNam . " " . $index ?>:</td>
				<td><input type="text" name="secname<?php print $index?>" style="width:100%;max-width:500px" value="<?php print htmlspecialsucode($sectionNames[$index])?>"></td>
			  </tr>
<?php		}
		} ?>
			<tr>
				<td align="right"><?php print $yyCatWrNa?>:</td>
				<td><input type="text" name="secworkname" style="width:100%;max-width:500px" value="<?php print htmlspecialsucode($sectionWorkingName)?>"></td>
			</tr>
			<tr>
				<td align="right"><?php print $yyCatSub?>:</td>
				<td><select name="tsTopSection" size="1"><option value="0"><?php print $yyCatHom?></option>
				<?php	$foundcat=($topSection==0);
						for($index=0;$index<$ntopsections; $index++){
							if($alltopsections[$index]["sectionID"] != $sectionID){
								print '<option value="' . $alltopsections[$index]["sectionID"] . '"';
								if($topSection==$alltopsections[$index]["sectionID"]){
									print ' selected';
									$foundcat=TRUE;
								}
								print ">" . $alltopsections[$index]["sectionWorkingName"] . "</option>\n";
							}
						}
						if(! $foundcat) print '<option value="" selected>**undefined**</option>';
					?></select>
                </td>
			</tr>
			<tr>
				<td align="right"><?php print $yyCatFn?>:</td>
				<td><select name="catfunction" id="catfunction" size="1">
				  <option value="1"><?php print $yyCatPrd?></option>
				  <option value="0"<?php if($rootSection==0&&getpost('id')!='0') print ' selected'?>><?php print $yyCatCat?></option>
<?php	if((int)getpost('id')==0){ ?>
				  <option value="2"<?php if($rootSection==2) print ' selected'?>>Root Category</option>
<?php	} ?>
				  </select></td>
			</tr>
			<tr>
				<td align="right">Preview Image:</td>
				<td><img src="<?php
					if($sectionImage!='')
						print (substr($sectionImage,0,7)=="http://"||substr($sectionImage,0,8)=="https://"||substr($sectionImage,0,1)=="/" ? $sectionImage : '../' . $sectionImage);
					else
						print 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=';
				?>" alt="Image Preview" style="max-width:300px;max-height:300px;border:1px solid darkgrey;padding:5px;box-shadow:0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19)" id="previewimage" onerror="errorimage()">
				</td>
			</tr>
			<tr>
				<td align="right"><?php print $yyCatImg?>:</td>
				<td><input type="text" name="secimage" id="secimage" size="40" value="<?php print str_replace("\"","&quot;",$sectionImage)?>" onchange="changeimage(this)"> <input type="button" value="..." onclick="uploadimage('secimage')" title="<?php print $yyUplIma?>"> <input type="button" value="Delete" onclick="deleteimage(this)"></td>
			</tr>
			<tr>
				<td align="right"><?php print $yyCatDes?>:</td><td>
<?php	if(@$htmleditor=='froala') print '<div id="secdescdiv" class="htmleditorcontainer">'; ?>
				<textarea name="secdesc" id="sectionDescription" cols="48" rows="8" style="width:100%;max-width:500px"><?php print $sectionDescription?></textarea></td>
<?php	if(@$htmleditor=='froala') print '</div>'; ?>
			</tr>
<?php	for($index=2; $index <= $adminlanguages+1; $index++){
			if(($adminlangsettings & 512)==512){ ?>
			  <tr>
				<td align="right"><?php print $yyCatDes . " " . $index ?>:</td>
				<td>
<?php	if(@$htmleditor=='froala') print '<div id="secdescdiv'.$index.'" class="htmleditorcontainer">'; ?>
				<textarea name="secdesc<?php print $index?>" id="sectionDescription<?php print $index?>" cols="48" rows="8" style="width:100%;max-width:500px"><?php print $sectionDescriptions[$index]?></textarea>
<?php	if(@$htmleditor=='froala') print '</div>'; ?>
				</td>
			  </tr>
<?php		}
		} ?>
			  <tr>
				<td align="right">Restrictions:</td>
				<td><select name="sectionDisabled" size="1">
				<option value="0"><?php print $yyNoRes?></option>
<?php	for($index=1; $index<= $maxloginlevels; $index++){
						print '<option value="' . $index . '"';
						if($sectionDisabled==$index) print ' selected';
						print '>' . $yyLiLev . ' ' . $index . '</option>';
		} ?>
				<option value="127"<?php if($sectionDisabled==127) print ' selected'?>><?php print $yyDisCat?></option>
				</select>
<?php	if(getpost('act')=='modify'){ ?>
				<select name="forcesubsection" size="1">
				<option value="0"><?php print $yySSForM?></option>
				<option value="1"><?php print $yySSForF?></option>
				<option value="2"><?php print $yySSForN?></option>
				</select>
<?php	} ?>
			  </td>
			</tr>
			<tr>
			  <td align="right">Page Title Tag<?php print ' ('.$yyOptnl.')'?>:</td>
			  <td><input type="text" name="sTitle" style="width:100%;max-width:500px" value="<?php print htmlspecials($sTitle)?>" onfocus="displaymultilangname('sTitle')"><?php
			for($index=2; $index <= $adminlanguages+1; $index++){
				if(($adminlangsettings & 2097152)==2097152){
			?><input type="text" style="width:100%;max-width:500px;display:none;margin-top:2px" name="sTitle<?php print $index?>" id="sTitle<?php print $index?>" placeholder="Page Title Language <?php print $index?>" value="<?php print htmlspecialsucode($pTitles[$index])?>"><?php
				}
			} ?></td>
			</tr>
			<tr>
			  <td align="right">Meta Description<?php print ' ('.$yyOptnl.')'?>:</td>
			  <td><input type="text" name="sMetaDesc" style="width:100%" value="<?php print htmlspecials($sMetaDesc)?>" onfocus="displaymultilangname('sMetaDesc')" maxlength="250"><?php
			for($index=2; $index <= $adminlanguages+1; $index++){
				if(($adminlangsettings & 2097152)==2097152){
			?><input type="text" style="width:100%;display:none;margin-top:2px" name="sMetaDesc<?php print $index?>" id="sMetaDesc<?php print $index?>" placeholder="Meta Description Language <?php print $index?>" size="40" value="<?php print htmlspecialsucode($pMetaDescs[$index])?>"><?php
				}
			} ?></td>
			</tr>
			<tr>
			  <td align="right"><?php print $yyCatURL.' ('.$yyOptnl.')'?>:</td>
			  <td><input type="text" name="sectionurl" style="width:100%;max-width:500px" value="<?php print htmlspecials($sectionurl)?>"></td>
			</tr>
<?php	for($index=2; $index <= $adminlanguages+1; $index++){
			if(($adminlangsettings & 2048)==2048){ ?>
			<tr>
			  <td align="right"><?php print $yyCatURL.' '.$index.' ('.$yyOptnl.')'?>:</td>
			  <td><input type="text" name="sectionurl<?php print $index?>" style="width:100%;max-width:500px" value="<?php print htmlspecials($sectionurls[$index])?>"></td>
			</tr>
<?php		}
		} ?>
			<tr>
			  <td align="right">Catalog Root (Optional):</td>
			  <td><input type="checkbox" name="catalogroot" value="ON" <?php if($catalogroot==$sectionID) print 'checked="checked" '?>/> Check to make this category the product catalog root.</td>
			</tr>
			<tr>
				<td align="right">Category Header:</td><td>
<?php	if(@$htmleditor=='froala') print '<div id="secheaddiv" class="htmleditorcontainer">'; ?>
				<textarea name="sectionHeader" id="sectionHeader" cols="48" rows="8" style="width:100%;max-width:500px"><?php print htmlspecials($sectionHeader)?></textarea>
<?php	if(@$htmleditor=='froala') print '</div>'; ?>
				</td>
			</tr>
<?php	for($index=2; $index <= $adminlanguages+1; $index++){
			if(($adminlangsettings & 524288)==524288){ ?>
			  <tr>
				<td align="right"><?php print 'Category Header' . " " . $index?>:</td>
                <td>
<?php	if(@$htmleditor=='froala') print '<div id="secheaddiv'.$index.'" class="htmleditorcontainer">'; ?>
				<textarea name="sectionHeader<?php print $index?>" id="sectionHeader<?php print $index?>" cols="55" rows="8" style="width:100%;max-width:500px"><?php print htmlspecials($sectionHeaders[$index])?></textarea>
<?php	if(@$htmleditor=='froala') print '</div>'; ?>
				</td>
			  </tr>
<?php		}
		} ?>
			<tr>
				<td align="right">Category Footer:</td><td>
<?php	if(@$htmleditor=='froala') print '<div id="secfootdiv" class="htmleditorcontainer">'; ?>
				<textarea name="sectionFooter" id="sectionFooter" cols="48" rows="8" style="width:100%;max-width:500px"><?php print htmlspecials($sectionFooter)?></textarea>
<?php	if(@$htmleditor=='froala') print '</div>'; ?>
				</td>
			</tr>
<?php	for($index=2; $index <= $adminlanguages+1; $index++){
			if(($adminlangsettings & 524288)==524288){ ?>
			  <tr>
				<td align="right"><?php print 'Category Footer' . " " . $index?>:</td>
                <td>
<?php	if(@$htmleditor=='froala') print '<div id="secfootdiv'.$index.'" class="htmleditorcontainer">'; ?>
				<textarea name="sectionFooter<?php print $index?>" id="sectionFooter<?php print $index?>" cols="55" rows="8" style="width:100%;max-width:500px"><?php print htmlspecials($sectionFooters[$index])?></textarea>
<?php	if(@$htmleditor=='froala') print '</div>'; ?>
				</td>
			  </tr>
<?php		}
		} ?>
			  <tr> 
                <td width="100%" colspan="2" align="center"><br><input type="submit" value="<?php print $yySubmit?>"></td>
			  </tr>
			  <tr> 
                <td width="100%" colspan="2"><br><ul>
				  <li><?php print $yyCatEx1?></li>
				  <li><?php print $yyCatEx2?></li>
				  </ul></td>
			  </tr>
			  <tr> 
                <td width="100%" colspan="2" align="center"><br>
                          <a href="admin.php"><strong><?php print $yyAdmHom?></strong></a><br>
                          &nbsp;</td>
			  </tr>
            </table>
		  </form>
<script>
changeimage(document.getElementById('secimage'));
</script>
<?php
	if(@$htmleditor=='ckeditor'){
		print '<script>';
		$pathtovsadmin=dirname(@$_SERVER['PHP_SELF']);
		print 'function loadeditors(){';
		$streditor="var sectionHeader=CKEDITOR.replace('sectionHeader',{extraPlugins : 'stylesheetparser,autogrow',autoGrow_maxHeight : 800,removePlugins : 'resize', toolbarStartupExpanded : false, toolbar : 'Basic', filebrowserBrowseUrl :'ckeditor/filemanager/browser/default/browser.html?Connector=".$pathtovsadmin."/ckeditor/filemanager/connectors/php/connector.php',filebrowserImageBrowseUrl : 'ckeditor/filemanager/browser/default/browser.html?Type=Image&Connector=".$pathtovsadmin."/ckeditor/filemanager/connectors/php/connector.php',filebrowserFlashBrowseUrl :'ckeditor/filemanager/browser/default/browser.html?Type=Flash&Connector=".$pathtovsadmin."/ckeditor/filemanager/connectors/php/connector.php',filebrowserUploadUrl:'".$pathtovsadmin."/ckeditor/filemanager/connectors/php/upload.php?Type=File',filebrowserImageUploadUrl:'".$pathtovsadmin."/ckeditor/filemanager/connectors/php/upload.php?Type=Image',filebrowserFlashUploadUrl:'".$pathtovsadmin."/ckeditor/filemanager/connectors/php/upload.php?Type=Flash'});\n";
		$streditor.="sectionHeader.on('instanceReady',function(event){var myToolbar='Basic';event.editor.on( 'beforeMaximize', function(){if(event.editor.getCommand('maximize').state==CKEDITOR.TRISTATE_ON && myToolbar != 'Basic'){sectionHeader.setToolbar('Basic');myToolbar='Basic';sectionHeader.execCommand('toolbarCollapse');}else if(event.editor.getCommand('maximize').state==CKEDITOR.TRISTATE_OFF && myToolbar != 'Full'){sectionHeader.setToolbar('Full');myToolbar='Full';sectionHeader.execCommand('toolbarCollapse');}});event.editor.on('contentDom', function(e){event.editor.document.on('blur', function(){if(!sectionHeader.isToolbarCollapsed){sectionHeader.execCommand('toolbarCollapse');sectionHeader.isToolbarCollapsed=true;}});event.editor.document.on('focus',function(){if(sectionHeader.isToolbarCollapsed){sectionHeader.execCommand('toolbarCollapse');sectionHeader.isToolbarCollapsed=false;}});});sectionHeader.fire('contentDom');sectionHeader.isToolbarCollapsed=true;});\n";
		print $streditor;
		print replace($streditor, 'sectionHeader', 'sectionDescription');
		for($index=2; $index <= $adminlanguages+1; $index++){
			if(($adminlangsettings & 512)==512) print str_replace('sectionHeader', 'sectionDescription' . $index, $streditor);
			if(($adminlangsettings & 524288)==524288) print str_replace('sectionHeader', 'sectionHeader' . $index, $streditor);
		}
		print '}window.onload=function(){loadeditors();}';
		print '</script>';
	}elseif(@$htmleditor=='froala'){
		displayfroalaeditor('sectionDescription',$yyCatDes,'.on(\'froalaEditor.focus\',function(){expandckeditor("secdescdiv");})');
		displayfroalaeditor('sectionHeader','Category Header','.on(\'froalaEditor.focus\',function(){expandckeditor("secheaddiv");})');
		displayfroalaeditor('sectionFooter','Category Footer','.on(\'froalaEditor.focus\',function(){expandckeditor("secfootdiv");})');
		for($index=2; $index <= $adminlanguages+1; $index++){
			if(($adminlangsettings & 512)==512) displayfroalaeditor('sectionDescription'.$index,$yyCatDes.' (language '.$index.')','.on(\'froalaEditor.focus\',function(){expandckeditor("secdescdiv'.$index.'");})');
			if(($adminlangsettings & 524288)==524288){
				displayfroalaeditor('sectionHeader'.$index,'Category Header'.' (language '.$index.')','.on(\'froalaEditor.focus\',function(){expandckeditor("secheaddiv'.$index.'");})');
				displayfroalaeditor('sectionFooter'.$index,'Category Footer'.' (language '.$index.')','.on(\'froalaEditor.focus\',function(){expandckeditor("secfootdiv'.$index.'");})');
			}
		}
	}
}elseif(getpost('act')=='discounts'){
		$sSQL="SELECT sectionName FROM sections WHERE sectionID=" . getpost('id');
		$result=ect_query($sSQL) or ect_error();
		$rs=ect_fetch_assoc($result);
		$thisname=$rs["sectionName"];
		ect_free_result($result);
		$numassigns=0;
		$alldata=[];
		$sSQL="SELECT cpaID,cpaCpnID,cpnWorkingName,cpnSitewide,cpnEndDate,cpnType FROM cpnassign LEFT JOIN coupons ON cpnassign.cpaCpnID=coupons.cpnID WHERE cpaType=1 AND cpaAssignment='" . getpost('id') . "'";
		$result=ect_query($sSQL) or ect_error();
		while($rs=ect_fetch_assoc($result))
			$alldata[$numassigns++]=$rs;
		ect_free_result($result);
		$numcoupons=0;
		$sSQL="SELECT cpnID,cpnWorkingName,cpnSitewide FROM coupons WHERE (cpnSitewide=0 OR cpnSitewide=3 OR cpnSitewide=4) AND cpnEndDate >='" . date("Y-m-d",time()) ."'";
		$result=ect_query($sSQL) or ect_error();
		while($rs=ect_fetch_assoc($result))
			$alldata2[$numcoupons++]=$rs;
		ect_free_result($result);
?>
<script>
/* <![CDATA[ */
function delrec(id){
if(confirm("<?php print jscheck($yyConAss)?>\n")) {
	document.mainform.id.value=id;
	document.mainform.act.value="deletedisc";
	document.mainform.submit();
}
}
/* ]]> */
</script>
		  <form name="mainform" method="post" action="admincats.php">
			<input type="hidden" name="posted" value="1">
			<input type="hidden" name="act" value="dodiscounts">
			<input type="hidden" name="id" value="<?php print getpost('id')?>">
			<input type="hidden" name="pg" value="<?php print getpost('pg')?>">
            <table width="100%" border="0" cellspacing="0" cellpadding="3">
			  <tr> 
                <td width="100%" colspan="4" align="center"><strong><?php print $yyAssDis?> &quot;<?php print $thisname?>&quot;.</strong><br>&nbsp;</td>
			  </tr>
<?php
	$gotone=FALSE;
	if($numcoupons>0){
		$thestr='<tr><td colspan="4" align="center">' . $yyAsDsCp . ': <select name="assdisc" size="1">';
		for($index=0;$index < $numcoupons;$index++){
			$alreadyassign=FALSE;
			if($numassigns>0){
				for($index2=0;$index2<$numassigns;$index2++){
					if($alldata2[$index]["cpnID"]==$alldata[$index2]["cpaCpnID"]) $alreadyassign=TRUE;
				}
			}
			if(! $alreadyassign){
				$thestr.="<option value='" . $alldata2[$index]["cpnID"] . "'>" . $alldata2[$index]["cpnWorkingName"] . "</option>\n";
				$gotone=TRUE;
			}
		}
		$thestr.='</select> <input type="submit" value="'.$yyGo.'"></td></tr>';
	}
	if($gotone){
		print $thestr;
	}else{
?>
			  <tr> 
                <td width="100%" colspan="4" align="center"><br><strong><?php print $yyNoDis?></td>
			  </tr>
<?php
	}
	if($numassigns>0){
?>
			  <tr> 
                <td width="100%" colspan="4" align="center"><br><strong><?php print $yyCurDis?> &quot;<?php print $thisname?>&quot;.</strong><br>&nbsp;</td>
			  </tr>
			  <tr> 
                <td><strong><?php print $yyWrkNam?></strong></td>
				<td><strong><?php print $yyDisTyp?></strong></td>
				<td><strong><?php print $yyExpire?></strong></td>
				<td align="center"><strong><?php print $yyDelete?></strong></td>
			  </tr>
<?php
		for($index=0;$index<$numassigns;$index++){
			$prefont='';
			$postfont='';
			if((int)$alldata[$index]["cpnSitewide"]==1 || ($alldata[$index]["cpnEndDate"] != '3000-01-01 00:00:00' && strtotime($alldata[$index]["cpnEndDate"])-time() < 0)){
				$prefont='<span style="color:#FF0000">';
				$postfont='</span>';
			}
?>
			  <tr> 
                <td><?php	print $prefont . $alldata[$index]["cpnWorkingName"] . $postfont ?></td>
				<td><?php	if($alldata[$index]["cpnType"]==0)
								print $prefont . $yyFrSShp . $postfont;
							elseif($alldata[$index]["cpnType"]==1)
								print $prefont . $yyFlatDs . $postfont;
							elseif($alldata[$index]["cpnType"]==2)
								print $prefont . $yyPerDis . $postfont; ?></td>
				<td><?php	print $prefont;
							if($alldata[$index]["cpnEndDate"]=='3000-01-01 00:00:00')
								print $yyNever;
							elseif(strtotime($alldata[$index]["cpnEndDate"])-time() < 0)
								print $yyExpird;
							else
								print date("Y-m-d",strtotime($alldata[$index]["cpnEndDate"]));
							print $postfont; ?></td>
				<td align="center"><input type="button" name="discount" value="Delete Assignment" onclick="delrec('<?php print $alldata[$index]["cpaID"]?>')"></td>
			  </tr>
<?php
		}
	}else{
?>
			  <tr> 
                <td width="100%" colspan="4" align="center"><br><strong><?php print $yyNoAss?></strong></td>
			  </tr>
<?php
	}
?>
			  <tr>
                <td width="100%" colspan="4" align="center"><br>&nbsp;</td>
			  </tr>
			  <tr> 
                <td width="100%" colspan="4" align="center"><br>
                          <a href="admin.php"><strong><?php print $yyAdmHom?></strong></a><br>&nbsp;</td>
			  </tr>
            </table>
		  </form>
<?php
}elseif(getpost('act')=="changepos"){ ?>
      <table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
        <tr>
          <td width="100%" align="center">
			<p>&nbsp;</p>
			<p>&nbsp;</p>
			<p>&nbsp;</p>
			<p><strong><?php print $yyUpdat?> . . . . . . . </strong></p>
			<p>&nbsp;</p>
			<p><?php print $yyNoFor?> <a href="admincats.php"><?php print $yyClkHer?></a>.</p>
			<p>&nbsp;</p>
			<p>&nbsp;</p>
		  </td>
		</tr>
	  </table>
<?php
}elseif(getpost('posted')=='1' && getpost('act')!='sort' && $success){ ?>
      <table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
        <tr>
          <td width="100%">
			<table width="100%" border="0" cellspacing="0" cellpadding="3">
			  <tr> 
                <td width="100%" colspan="2" align="center"><br><strong><?php print $yyUpdSuc?></strong><br><br><?php print $yyNowFrd?><br><br>
                        <?php print $yyNoAuto?> <a href="admincats.php"><strong><?php print $yyClkHer?></strong></a>.<br>&nbsp;<br>&nbsp;
                </td>
			  </tr>
			</table></td>
        </tr>
	  </table>
<?php
}elseif(getpost('posted')=='1' && getpost('act')!='sort'){ ?>
      <table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
        <tr>
          <td width="100%">
			<table width="100%" border="0" cellspacing="0" cellpadding="2">
			  <tr> 
                <td width="100%" colspan="2" align="center"><br><span style="color:#FF0000;font-weight:bold"><?php print $yyOpFai?></span><br><br><?php print $errmsg?><br><br>
				<a href="javascript:history.go(-1)"><strong><?php print $yyClkBac?></strong></a></td>
			  </tr>
			</table></td>
        </tr>
	  </table>
<?php
}else{
	$cract=trim_(@$_COOKIE['cract']);
	if(getrequest('sort')!='') $sortorder=getrequest('sort'); else $sortorder=@$_COOKIE['catsort'];
	if(getget('catorman')!='') $catorman=getget('catorman'); else $catorman=@$_COOKIE['ccatorman'];
	$allcoupon=[];
	$numcoupons=0;
	$sSQL='SELECT DISTINCT cpaAssignment FROM cpnassign WHERE cpaType=1';
	$result=ect_query($sSQL) or ect_error();
	while($rs=ect_fetch_assoc($result))
		$allcoupon[$numcoupons++]=$rs;
	ect_free_result($result);
	$modclone=@$_COOKIE['modclone'];
?>
<div id="deletecategory" class="ectopaque" style="display:none" onclick="if(event.target==this)this.style.display='none'" tabindex="0">
	<div class="ectsoftwrapper">
		<h1 style="margin:5%"><?php print "Delete Category"?></h1>
		<div style="margin:5%"><?php print $yyConDel?></div>
		<div style="margin:5%"><input type="checkbox" value="delimage" value="1" onchange="document.getElementById('delimage').value=this.checked?1:''">Also delete category image?</div>
		<div style="margin:5%;text-align:right"><input type="button" value="OK" onclick="document.mainform.submit()"> <input type="button" value="Cancel" onclick="document.getElementById('deletecategory').style.display='none'"></div>
	</div>
</div>
<script>
/* <![CDATA[ */
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
var rowsingrp=[];
function cpu(x,theid,grpid,secid){
	if(x.length>1) return;
	x.onchange=function(){chi(secid,x);};
	var totrows=rowsingrp[grpid];
	for(index=theid-1; index>0; index--){
		var y=document.createElement('option');
		y.text=index;
		y.value=index;
		var sel=x.options[0];
		try{
			x.add(y, sel); // FF etc
		}
		catch(ex){
			x.add(y, 0); // IE
		}
	}
	for(index=theid+1; index<=totrows; index++){
		var y=document.createElement('option');
		y.text=index;
		y.value=index;
		try{
			x.add(y, null); // FF etc
		}
		catch(ex){
			x.add(y); // IE
		}
	}
}
function chi(id,obj){
	document.mainform.action="admincats.php?catfun=<?php print @$_REQUEST['catfun']?>&stext=<?php print urlencode(getrequest('stext'))?>&perpage=<?php print urlencode(getrequest('perpage'))?>&sprice=<?php print urlencode(getrequest('sprice'))?>&stype=<?php print @$_REQUEST['stype']?>&scat=<?php print @$_REQUEST['scat']?>&pg=<?php print (getget('pg')=='' ? 1 : getget('pg'))?>";
	document.mainform.newval.value=obj.selectedIndex+1;
	document.mainform.id.value=id;
	document.mainform.act.value="changepos";
	document.mainform.submit();
}
function mr(id){
	document.mainform.action="admincats.php";
	document.mainform.id.value=id;
	document.mainform.act.value="modify";
	document.mainform.submit();
}
function cr(id){
	document.mainform.action="admincats.php";
	document.mainform.id.value=id;
	document.mainform.act.value="clone";
	document.mainform.submit();
}
function newrec(id){
	document.mainform.action="admincats.php";
	document.mainform.id.value=id;
	document.mainform.act.value="addnew";
	document.mainform.submit();
}
function quickupdate(){
	if(document.mainform.cract.value=="del"||document.mainform.cract.value=="dei"){
		if(!confirm("<?php print jscheck($yyConDel)?>\n"))
			return;
	}
	document.mainform.action="admincats.php";
	document.mainform.act.value="quickupdate";
	document.mainform.posted.value="1";
	document.mainform.submit();
}
function changecract(obj){
	setCookie('cract',obj[obj.selectedIndex].value,600);
	startsearch();
}
function dsc(id) {
	document.mainform.action="admincats.php";
	document.mainform.id.value=id;
	document.mainform.act.value="discounts";
	document.mainform.submit();
}
function dr(id){
	document.mainform.action="admincats.php";
	document.mainform.id.value=id;
	document.mainform.act.value="delete";
	document.getElementById('deletecategory').style.display='';
}
function startsearch(){
	document.mainform.action="admincats.php";
	document.mainform.act.value="search";
	document.mainform.posted.value='';
	document.mainform.submit();
}
function inventorymenu(){
	themenuitem=document.mainform.inventoryselect.options[document.mainform.inventoryselect.selectedIndex].value;
	if(themenuitem=="1") document.mainform.act.value="catinventory";
	document.mainform.action="dumporders.php";
	document.mainform.submit();
}
function changesortorder(men){
	var selectedopt=men.options[men.selectedIndex].value;
	if(selectedopt=='act'){
		setCookie('cract','cor',600);
		setCookie('catsort','act',600);
	}
	document.mainform.action="admincats.php<?php if(getpost('act')=='search' || getget('pg')!='') print '?pg=1'?>";
	document.mainform.id.value=selectedopt;
	document.mainform.act.value="sort";
	document.mainform.posted.value="1";
	document.mainform.submit();
}
function checkboxes(docheck){
	maxitems=document.getElementById("resultcounter").value;
	for(index=0;index<maxitems;index++){
		var thiselem=document.getElementById("chkbx"+index);
		if(thiselem.checked!=docheck){
			thiselem.checked=docheck;
			thiselem.onchange();
		}
	}
}
function setto(){
	maxitems=document.getElementById("resultcounter").value;
	amnt=document.getElementById("txtadd").value;
	for(index=0;index<maxitems;index++){
		if(document.getElementById("chkbx"+index)){
			document.getElementById("chkbx"+index).value=amnt;
			document.getElementById("chkbx"+index).onchange();
		}
	}
}
function switchcatorman(obj){
	document.location="admincats.php?catorman="+obj[obj.selectedIndex].value+"&stext=<?php print urlencode(getrequest('stext'))?>&stype=<?php print @$_REQUEST['stype']?>&perpage=<?php print @$_REQUEST['perpage']?>&pg=<?php print (getget('pg')=='' && getpost('act')=='search' ? 1 : getget('pg'))?>";
}
function changemodclone(modclone){
	setCookie('modclone',modclone[modclone.selectedIndex].value,600);
	startsearch();
}
function changeso(){
	var sos=1;
	if(!document.getElementById('sos1').checked) sos+=2;
	if(!document.getElementById('sos2').checked) sos+=4;
	if(!document.getElementById('sos3').checked) sos+=8;
	if(!document.getElementById('sos4').checked) sos+=16;
	document.getElementById('sos').value=sos;
}
/* ]]> */
</script>
<?php
$numcats=0;
$thecat=@$_REQUEST['scat'];
if($thecat!='') $thecat=(int)$thecat;
$sos=getrequest('sos');
if(is_numeric($sos)) $sos=(int)$sos; else $sos=29;
if(@$noadmincategorysearch!=TRUE){
	$sSQL='SELECT sectionID,sectionWorkingName,topSection,rootSection FROM sections WHERE rootSection=0 ORDER BY topSection,sectionWorkingName';
	$allcats=ect_query($sSQL) or ect_error();
	while($row=ect_fetch_assoc($allcats)){
		$allcatsa[$numcats++]=$row;
	}
	ect_free_result($allcats);
} ?>
<h2><?php print $yyAdmCat?></h2>
		  <form name="mainform" method="post" action="admincats.php">
			<input type="hidden" name="posted" value="1">
			<input type="hidden" name="act" value="xxxxx">
			<input type="hidden" name="id" value="xxxxx">
			<input type="hidden" name="pg" value="<?php if(getpost('act')=='search') print '1'; else print getget('pg')?>">
			<input type="hidden" name="newval" value="1">
			<input type="hidden" name="delimage" id="delimage" value="">
			<input type="hidden" id="sos" name="sos" value="<?php print $sos?>">
			<table class="cobtbl" width="100%" border="0" cellspacing="1" cellpadding="3">
			  <tr> 
				<td class="cobhl" width="25%" align="right"><?php print $yySrchFr?>:</td>
				<td class="cobll" width="25%"><input type="text" name="stext" size="20" value="<?php print @$_REQUEST['stext']?>"></td>
				<td class="cobhl" width="25%" align="right"><?php print str_replace('...','',$yyCatFn)?>:</td>
				<td class="cobll" width="25%"><select name="catfun" size="1">
					<option value=""><?php print $yySrchAC?></option>
					<option value="1"<?php if(@$_REQUEST['catfun']=='1') print ' selected'?>><?php print $yyCatPrd?></option>
					<option value="2"<?php if(@$_REQUEST['catfun']=='2') print ' selected'?>><?php print $yyCatCat?></option>
					<option value="6"<?php if(@$_REQUEST['catfun']=='6') print ' selected'?>>Unrestricted Categories</option>
					<option value="3"<?php if(@$_REQUEST['catfun']=='3') print ' selected'?>>Restricted Categories</option>
					<option value="4"<?php if(@$_REQUEST['catfun']=='4') print ' selected'?>>Disabled Categories</option>
					<option value="5"<?php if(@$_REQUEST['catfun']=='5') print ' selected'?>>Recommended Categories</option>
				</select></td>
			  </tr>
			  <tr>
				<td class="cobhl" width="25%" align="right"><?php print $yySrchTp?>:</td>
				<td class="cobll" width="25%"><select name="stype" size="1">
					<option value=""><?php print $yySrchAl?></option>
					<option value="any"<?php if(@$_REQUEST['stype']=='any') print ' selected'?>><?php print $yySrchAn?></option>
					<option value="exact"<?php if(@$_REQUEST['stype']=='exact') print ' selected'?>><?php print $yySrchEx?></option>
					</select>
					<input type="checkbox" id="sos4" title="Category ID" onchange="changeso()" style="vertical-align:middle;"<?php if(($sos & 16)!=16) print ' checked '?>>
					<input type="checkbox" id="sos1" title="Name" onchange="changeso()" style="vertical-align:middle;"<?php if(($sos & 2)!=2) print ' checked '?>>
					<input type="checkbox" id="sos2" title="Working Name" onchange="changeso()" style="vertical-align:middle;"<?php if(($sos & 4)!=4) print ' checked '?>>
					<input type="checkbox" id="sos3" title="Description" onchange="changeso()" style="vertical-align:middle;"<?php if(($sos & 8)!=8) print ' checked '?>>
				</td>
				<td class="cobhl" width="25%" align="right"><select size="1" name="catorman" onchange="switchcatorman(this)">
					<option value="cat"><?php print $yySrchCt?></option>
					<option value="non"<?php if($catorman=='non') print ' selected'?>><?php print $yyNone?></option>
					</select></td>
				<td class="cobll" width="25%">
<?php	if($catorman=='non')
			print '&nbsp;';
		else{ ?>
				  <select name="scat" id="scat" size="1" style="max-width:300px">
				  <option value=""><?php print $yySrchAC?></option>
				  </select>
<script>
var catmenu=[<?php writemenulevel(0,1) ?>];
var scatmenu=document.getElementById("scat");
for(var catmenuind in catmenu){
	var option=document.createElement("option");
	option.text="\u00BB ".repeat(catmenu[catmenuind][1]) + catmenu[catmenuind][2];
	option.value=catmenu[catmenuind][0];
	if(catmenu[catmenuind][3]) option.selected=true;
	scatmenu.add(option);
}
</script>
<?php	} ?>
				</td>
			  </tr>
			  <tr>
				<td class="cobhl" align="center"><?php
				if(getpost('act')=='search' || getget('pg')!=''){
					if($cract=='del'||$cract=='dei'||$cract=='dis'||$cract=='rec'||substr($cract,0,3)=='csu'){ ?>
					<input type="button" value="<?php print $yyUpdate?>" onclick="quickupdate()"> <input type="button" value="<?php print $yyCheckA?>" onclick="checkboxes(true)"> <input type="button" value="<?php print $yyUCheck?>" onclick="checkboxes(false)">
<?php				}elseif(! ($cract=='cor'||$cract=='lol'||$cract=='vim')){ ?>
					<input type="button" value="<?php print $yyUpdate?>" onclick="quickupdate()"> <input type="text" name="txtadd" id="txtadd" size="5" value="" style="vertical-align:middle"> <input type="button" value="Set" onclick="setto()"></div>
<?php				}
				}?></td>
				<td class="cobll" colspan="3"><table width="100%" cellspacing="0" cellpadding="0" border="0">
					<tr>
					  <td class="cobll" align="center" style="white-space:nowrap">
						<select name="perpage" size="1" style="vertical-align:middle" title="Per Page">
						<option value="">200</option>
						<option value="300"<?php print (getrequest("perpage")=="300"?" selected":'')?>>300</option>
						<option value="500"<?php print (getrequest("perpage")=="500"?" selected":'')?>>500</option>
						<option value="1000"<?php print (getrequest("perpage")=="1000"?" selected":'')?>>1000</option>
						<option value="2000"<?php print (getrequest("perpage")=="2000"?" selected":'')?>>2000</option>
						<option value="x"<?php print (getrequest("perpage")=="x"?" selected":'')?>>ALL</option>
						</select>
						<select name="sort" size="1" style="vertical-align:middle" onchange="changesortorder(this)">
						<option value="can"<?php if($sortorder=='can') print ' selected'?>>Sort - Cat Name</option>
						<option value="cwn"<?php if($sortorder=='cwn') print ' selected'?>>Sort - Working Name</option>
						<option value="act"<?php if($sortorder=='act'||$sortorder=='') print ' selected'?>>Sort - Actual Order</option>
						<option value="pra"<?php if($sortorder=='pra') print ' selected'?>>Sort - Products Assigned</option>
						<option value="caa"<?php if($sortorder=='caa') print ' selected'?>>Sort - Categories Assigned</option>
<?php	if($useStockManagement){ ?>
						<option value="sta"<?php if($sortorder=='sta') print ' selected'?>>Sort - Stock Assigned</option>
<?php	} ?>
						<option value="qui"<?php if($sortorder=='qui') print ' selected'?>>Sort - Quick Update Setting</option>
						<option value="qud"<?php if($sortorder=='qud') print ' selected'?>>Sort - Quick Update (Desc.)</option>
						<option value="nsf"<?php if($sortorder=='nsf') print ' selected'?>>No Sort (Fastest)</option>
						</select>
						<input type="submit" value="List Categories" onclick="startsearch();">
						<input type="button" value="<?php print $yyNewCat?>" onclick="newrec()">
					  </td>
					  <td class="cobll" height="26" width="20%" align="right" style="white-space:nowrap">
					<select name="inventoryselect" size="1">
						<option value="1">Category Inventory</option>
					</select>&nbsp;<input type="button" value="<?php print $yyGo?>" onclick="inventorymenu();">
					  </td>
					</tr>
				  </table></td>
			  </tr>
			</table>
<br>
            <table width="100%" class="stackable admin-table-a sta-white" id="catstable">
<?php
function displayheaderrow(){
	global $sortorder,$cract,$yyStck,$yyOrder,$yyCatPat,$yyCatNam,$yyDiscnt,$yyModify,$yyCatWrNa,$yyCatImg,$yyCatURL,$yyDelete,$yyDiscnt,$yyRecomd,$useStockManagement,$adminlangsettings,$adminlanguages,$currentdiscount; ?>
	  <tr>
		<th class="small minicell">
	  <select name="cract" id="cract" size="1" onchange="changecract(this)" style="width:150px">
				<option value="none">Quick Entry...</option>
				<option value="" disabled="disabled">---------------------</option>
				<option value="cor"<?php if($cract=='cor'||$cract=='') print ' selected'?>>Actual Order</option>
				<option value="" disabled="disabled">---------------------</option>
				<option value="can"<?php if($cract=='can') print ' selected'?>><?php print $yyCatNam?></option>
<?php	for($index=2; $index<=$adminlanguages+1; $index++){
			if(($adminlangsettings & 256)==256) print '<option value="can'.$index.'"' . ($cract==('can'.$index)?' selected':'') . '>' . $yyCatNam . ' ' . $index . '</option>';
		} ?>
				<option value="cwn"<?php if($cract=='cwn') print ' selected'?>><?php print $yyCatWrNa?></option>
				<option value="cim"<?php if($cract=='cim') print ' selected'?>><?php print $yyCatImg?></option>
				<option value="dis"<?php if($cract=='dis') print ' selected'?>><?php print $yyDiscnt?></option>
				<option value="rec"<?php if($cract=='rec') print ' selected'?>><?php print $yyRecomd?></option>
				<option value="lol"<?php if($cract=='lol') print ' selected'?>><?php print 'Restrictions'?></option>
				<option value="css"<?php if($cract=='css') print ' selected'?>><?php print 'Custom CSS Class'?></option>
				<option value="cur"<?php if($cract=='cur') print ' selected'?>><?php print $yyCatURL?></option>
<?php	for($index=2; $index<=$adminlanguages+1; $index++){
			if(($adminlangsettings & 2048)==2048) print '<option value="cur'.$index.'"' . ($cract==('cur'.$index)?' selected':'') . '>' . $yyCatURL . ' ' . $index . '</option>';
		} ?>
				<option value="csu"<?php if($cract=='csu') print ' selected'?>>Create <?php print $yyCatURL?></option>
<?php	for($index=2; $index <= $adminlanguages+1; $index++){
			if(($adminlangsettings & 2048)==2048) print '<option value="csu'.$index.'"' . ($cract==('csu'.$index)?' selected':'') . '>Create ' . $yyCatURL . ' ' . $index . '</option>';
		} ?>
				<option value="" disabled="disabled">---------------------</option>
				<option value="ptt"<?php if($cract=='ptt') print ' selected'?>><?php print 'Page Title Tag'?></option>
<?php	for($index=2; $index <= $adminlanguages+1; $index++){
			if(($adminlangsettings & 2097152)==2097152) print '<option value="ptt'.$index.'"' . ($cract==('ptt'.$index)?' selected':'') . '>' . 'Page Title Tag' . ' ' . $index . '</option>';
		} ?>
				<option value="med"<?php if($cract=='med') print ' selected'?>><?php print 'Meta Description'?></option>
<?php	for($index=2; $index <= $adminlanguages+1; $index++){
			if(($adminlangsettings & 2097152)==2097152) print '<option value="med'.$index.'"' . ($cract==('med'.$index)?' selected':'') . '>' . 'Meta Description' . ' ' . $index . '</option>';
		} ?>
				<option value="" disabled="disabled">---------------------</option>
				<option value="vim"<?php if($cract=='vim') print ' selected'?>>View Category Image</option>
				<option value="" disabled="disabled">---------------------</option>
				<option value="del"<?php if($cract=='del') print ' selected'?>><?php print $yyDelete?></option>
				<option value="dei"<?php if($cract=='dei') print ' selected'?>><?php print $yyDelete.' + image'?></option>
				</select><?php
			if($cract=='dis'){
				if(is_numeric(@$_COOKIE['ccurrdisc'])){
					$currentdiscount=(int)$_COOKIE['ccurrdisc'];
					$result2=ect_query('SELECT cpnID FROM coupons WHERE (cpnSitewide=0 OR cpnSitewide=3 OR cpnSitewide=4) AND cpnID='.$currentdiscount) or ect_error();
					if(ect_num_rows($result2)==0) $currentdiscount='';
					ect_free_result($result2);
				}else
					$currentdiscount='';
				print '<div style="margin-top:2px"><select style="width:150px" name="currentdiscount" size="1" onchange="setCookie(\'ccurrdisc\',this[this.selectedIndex].value,600);changecract(document.getElementById(\'cract\'))">';
				$sSQL='SELECT cpnID,cpnWorkingName FROM coupons WHERE cpnSitewide=0 OR cpnSitewide=3 OR cpnSitewide=4 ORDER BY cpnWorkingName';
				$result2=ect_query($sSQL) or ect_error();
				if(ect_num_rows($result2)==0) print '<option value="" disabled="disabled">== No Assignable Discounts Defined ==</option>' . "\n";
				while($rs2=ect_fetch_assoc($result2)){
					print '<option value="' . $rs2['cpnID'] . '"' . ($currentdiscount==$rs2['cpnID']?' selected':'') . '>' . $rs2['cpnWorkingName'] . "</option>\n";
					if($currentdiscount=='') $currentdiscount=$rs2['cpnID'];
				}
				ect_free_result($result2);
				print '</select></div>';
			}elseif($cract=='csu'||$cract=='csu2'||$cract=='csu3'){
				print '<div style="margin-top:6px;margin-left:6px;text-align:left">';
				print '<div style="text-align:center" id="staticurlshow"><input type="button" value="Show Options" onclick="document.getElementById(\'staticurlshow\').style.display=\'none\';document.getElementById(\'staticurloptions\').style.display=\'\';"></div>';
				print '<div id="staticurloptions" style="display:none"><select class="staticopts" size="1" name="extension" title="Has Extension (.php)" onchange="setCookie(\'incpextension\',this[this.selectedIndex].value,365)"><option value="yes">Extension (.php)</option><option value="no"'.(@$seodetailurls || @$_COOKIE['incpextension']=='no'?' selected':'').'>Extensionless</option></select>';
				print '<select class="staticopts" size="1" name="space" title="Space Replacement" onchange="setCookie(\'incpspace\',this[this.selectedIndex].value,365)">' .
					'<option value=" ">No Space Replacement</option>' .
					'<option value="_"'.(@$_COOKIE['incpspace']=='_' && @$detlinkspacechar!='_'?' selected':'').(@$detlinkspacechar=='_'?' disabled="disabled"':'').'>Underscore'.(@$detlinkspacechar=='_'?' ($detlinkspacechar)':'').'</option>' .
					'<option value="-"'.(@$_COOKIE['incpspace']=='-' && @$detlinkspacechar!='-'?' selected':'').(@$detlinkspacechar=='-'?' disabled="disabled"':'').'>Dash'.(@$detlinkspacechar=='-'?' ($detlinkspacechar)':'').'</option>' .
					'<option value="remove"'.(@$_COOKIE['incpspace']=='remove'?' selected':'').'>Remove</option></select>';
				print '<select class="staticopts" size="1" name="lcase" title="Lower Case" onchange="setCookie(\'incplcase\',this[this.selectedIndex].value,365)"><option value="no">Keep Original Case</option><option value="yes"'.(@$_COOKIE['incplcase']=='yes'?' selected':'').'>Force Lower Case</option></select>';
				print '<select class="staticopts" size="1" name="punctuation" title="Remove Punctuation" onchange="setCookie(\'incpunctuation\',this[this.selectedIndex].value,365)"><option value="">Keep Punctuation</option><option value="remove"'.(@$_COOKIE['incpunctuation']=='remove'?' selected':'').'>Remove Punctuation</option></select>';
				print '<select class="staticopts" size="1" name="wholedb" title="Create Static URL\'s for All Products"><option value="">Selected Items Only</option><option value="clear">Clear All Static URL\'s</option><option value="set">Create All Static URL\'s</option></select>';
				print '<select class="staticopts" size="1" name="addprodid" title="Include Product ID"><option value="">Don\'t Include Product ID</option><option value="prepend">Prepend Product ID</option><option value="append">Append Product ID</option></select></div>';
				print '</div>';
			} ?>
		</th>
		<th class="maincell"><?php print $yyCatPat?></th>
		<th class="maincell"><?php print $yyCatNam?></th>
		<th class="minicell"><?php print 'Products'?></th>
<?php	if($useStockManagement){ ?>
		<th class="minicell"><?php print $yyStck?></th>
<?php	} ?>
		<th class="minicell"><?php print $yyDiscnt?></th>
		<th class="minicell"><?php print $yyModify?></th>
	  </tr>
<?php
}
	if($catalogroot!=0){
		$sSQL="SELECT sectionID FROM sections WHERE sectionID='".escape_string($catalogroot)."'";
		$result=ect_query($sSQL) or ect_error();
		if(ect_num_rows($result)==0){ ect_query('UPDATE admin SET catalogRoot=0 WHERE adminID=1') or ect_error(); }
		ect_free_result($result);
	}
	$rowsingrp=$jscript=$qetype=$qesize='';
	$rowcounter=0;
	if(getpost('act')=='search' || getget('pg')!=''){
		$CurPage=1;
		$roottopsection=0;
		$sSQL_WHERE='';
		if(@$menucategoriesatroot){
			$sSQL="SELECT topSection FROM sections WHERE sectionID=".$catalogroot;
			$result=ect_query($sSQL) or ect_error();
			if($rs=ect_fetch_assoc($result)) $roottopsection=$rs['topSection'];
			ect_free_result($result);
		}
		if(! @$menucategoriesatroot)
			$sSQL='SELECT sec1.sectionID,sec1.sectionName,sec1.sectionName2,sec1.sectionName3,sec1.sCustomCSS,sec1.sectionWorkingName,sec1.sectionImage,sec1.sRecommend,sec1.sTitle,sec1.sTitle2,sec1.sTitle3,sec1.sMetaDesc,sec1.sMetaDesc2,sec1.sMetaDesc3,sec1.sectionurl,sec1.sectionurl2,sec1.sectionurl3,sec1.sectionDescription,sec1.topSection AS topSection,sec1.rootSection,sec1.sectionDisabled,sec1.sectionOrder FROM sections AS sec1 LEFT JOIN sections AS sec2 ON sec1.topSection=sec2.sectionID';
		else
			$sSQL='SELECT sec1.sectionID,sec1.sectionName,sec1.sectionName2,sec1.sectionName3,sec1.sCustomCSS,sec1.sectionWorkingName,sec1.sectionImage,sec1.sRecommend,sec1.sTitle,sec1.sTitle2,sec1.sTitle3,sec1.sMetaDesc,sec1.sMetaDesc2,sec1.sMetaDesc3,sec1.sectionurl,sec1.sectionurl2,sec1.sectionurl3,sec1.sectionDescription,IF(sec1.topSection='.$catalogroot.','.$roottopsection.',sec1.topSection) AS topSection,sec1.rootSection,sec1.sectionDisabled,sec1.sectionOrder FROM sections AS sec1 LEFT JOIN sections AS sec2 ON IF(sec1.topSection='.$catalogroot.','.$roottopsection.',sec1.topSection)=sec2.sectionID';
		$whereand=' WHERE ';
		if($sortorder=='pra'||$sortorder=='sta'){
			$sSQL='SELECT sectionID,sectionName,sectionName2,sectionName3,sCustomCSS,sectionWorkingName,sectionImage,sRecommend,sTitle,sTitle2,sTitle3,sMetaDesc,sMetaDesc2,sMetaDesc3,sectionurl,sectionurl2,sectionurl3,sectionDescription,topSection,rootSection,sectionDisabled,'.($useStockManagement?'SUM(pInStock) AS sumStock,':'').'COUNT(pSection) AS sectionCount FROM sections AS sec1 LEFT JOIN products ON sec1.sectionID=products.pSection';
			$sSQL_WHERE=' WHERE rootSection=1';
			$whereand=' AND ';
		}elseif($sortorder=='caa'){
			$sSQL="SELECT sec1.sectionID,sec1.sectionName,sec1.sectionName2,sec1.sectionName3,sec1.sCustomCSS,sec1.sectionWorkingName,sec1.sectionImage,sec1.sRecommend,sec1.sTitle,sec1.sTitle2,sec1.sTitle3,sec1.sMetaDesc,sec1.sMetaDesc2,sec1.sMetaDesc3,sec1.sectionurl,sec1.sectionurl2,sec1.sectionurl3,sec1.topSection,sec1.rootSection,sec1.sectionDisabled,".($useStockManagement?"1 AS sumStock,":'')."COUNT(sec2.sectionID) AS sectionCount FROM sections AS sec1 LEFT JOIN sections AS sec2 ON sec1.sectionID=sec2.topSection WHERE sec1.rootSection=0";
			$whereand=' AND ';
		}
		if($thecat!=''){
			$returnalltopsections=TRUE;
			$sectionids=getsectionids($thecat, TRUE);
			if($sectionids!='')
				$sSQL_WHERE.=$whereand . 'sec1.sectionID IN (' . $sectionids . ') ';
			$whereand=' AND ';
		}
		if(getrequest('stext')!='' && $sos!=31){
			$Xstext=escape_string(@$_REQUEST['stext']);
			$aText=explode(' ',$Xstext);
			if(($sos&2)==2) $aFields[0]=''; else $aFields[0]=getlangid('sectionName',256);
			if(($sos&4)==4) $aFields[1]=''; else $aFields[1]='sectionWorkingName';
			if(($sos&8)==8) $aFields[2]=''; else $aFields[2]=getlangid('sectionDescription',512);
			if(($sos&16)==16) $aFields[3]=''; else $aFields[3]='sectionID';
			if(@$_REQUEST['stype']=='exact'){
				$sSQL_WHERE.=$whereand . '(';
				if(($sos&2)!=2) $sSQL_WHERE.="sec1.sectionName LIKE '%" . $Xstext . "%' OR ";
				if(($sos&4)!=4) $sSQL_WHERE.="sec1.sectionWorkingName LIKE '%" . $Xstext . "%' OR ";
				if(($sos&8)!=8) $sSQL_WHERE.="sec1.sectionDescription LIKE '%" . $Xstext . "%' OR ";
				if(($sos&16)!=16) $sSQL_WHERE.="sec1.sectionID='" . (is_numeric($Xstext)?$Xstext:0) . "' OR ";
				$sSQL_WHERE=substr($sSQL_WHERE,0,strlen($sSQL_WHERE)-3) . ') ';
				$whereand=' AND ';
			}else{
				$sJoin='AND ';
				if(@$_REQUEST['stype']=='any') $sJoin='OR ';
				$sSQL_WHERE.=$whereand . '(';
				$whereand=' AND ';
				for($index=0;$index<=3;$index++){
					if($aFields[$index]!=''){
						$sSQL_WHERE.='(';
						$rowcounter=0;
						$arrelms=count($aText);
						foreach($aText as $theopt){
							if(is_array($theopt))$theopt=$theopt[0];
							if($index==3)
								$sSQL_WHERE.='sec1.' . $aFields[$index] . "='" . (is_numeric($theopt)?$theopt:0) . "' " . $sJoin;
							else
								$sSQL_WHERE.='sec1.' . $aFields[$index] . " LIKE '%" . $theopt . "%' " . $sJoin;
						}
						$sSQL_WHERE=substr($sSQL_WHERE,0,strlen($sSQL_WHERE)-strlen($sJoin)) . ') OR ';
					}
				}
				$sSQL_WHERE=substr($sSQL_WHERE,0,strlen($sSQL_WHERE)-4) . ') ';
			}
		}
		if(@$_REQUEST['catfun']=='1'){ $sSQL_WHERE.=$whereand . "sec1.rootSection=1 "; $whereand=" AND "; }
		if(@$_REQUEST['catfun']=='2'){ $sSQL_WHERE.=$whereand . "sec1.rootSection=0 "; $whereand=" AND "; }
		if(@$_REQUEST['catfun']=='3'){ $sSQL_WHERE.=$whereand . "sec1.sectionDisabled<>0 "; $whereand=" AND "; }
		if(@$_REQUEST['catfun']=='4'){ $sSQL_WHERE.=$whereand . "sec1.sectionDisabled=127 "; $whereand=" AND "; }
		if(@$_REQUEST['catfun']=='5'){ $sSQL_WHERE.=$whereand . "sec1.sRecommend<>0 "; $whereand=" AND "; }
		if(@$_REQUEST['catfun']=='6'){ $sSQL_WHERE.=$whereand . "sec1.sectionDisabled=0 "; $whereand=" AND "; }
		
		if(is_numeric(getget('pg'))) $CurPage=(int)(getget('pg'));
		$sSQL_CNT="SELECT COUNT(*) AS bar FROM sections AS sec1".$sSQL_WHERE;
		$result=ect_query($sSQL_CNT) or ect_error();
		$rs=ect_fetch_assoc($result);
		
		$iNumOfPages=ceil(($totalcats=$rs['bar'])/$admincatsperpage);
		ect_free_result($result);
		
		$sSQL.=$sSQL_WHERE;
		
		if($sortorder=='can')
			$sSQL.=" ORDER BY sec1.sectionName";
		elseif($sortorder=='cwn')
			$sSQL.=" ORDER BY sec1.sectionWorkingName";
		elseif($sortorder=='nsf')
			; // Nothing
		elseif($sortorder=='caa')
			$sSQL.=" GROUP BY sec1.sectionID,sec1.sectionName,sec1.sectionName2,sec1.sectionName3,sec1.sCustomCSS,sec1.sectionWorkingName,sec1.sectionImage,sec1.sRecommend,sec1.sTitle,sec1.sTitle2,sec1.sTitle3,sec1.sMetaDesc,sec1.sMetaDesc2,sec1.sMetaDesc3,sec1.sectionurl,sec1.sectionurl2,sec1.sectionurl3,sec1.topSection,sec1.rootSection,sec1.sectionDisabled ORDER BY COUNT(sec2.sectionID)";
		elseif($sortorder=='pra')
			$sSQL.=" GROUP BY sectionID ORDER BY COUNT(pSection)";
		elseif($sortorder=='sta')
			$sSQL.=" GROUP BY sectionID ORDER BY SUM(pInStock)";
		elseif($sortorder=='qui' || $sortorder=='qud'){
			if($cract=="cur"){
				$sSQL.=" ORDER BY sec1.sectionURL";
				if($sortorder=="qud") $sSQL.=" DESC";
			}
		}else
			$sSQL.=" ORDER BY sec2.sectionOrder,sec2.sectionID,sec1.sectionOrder";
		$sSQL.=' LIMIT ' . ($admincatsperpage*($CurPage-1)) . ', ' . $admincatsperpage;
		$currgroup=-1;
		$result=ect_query($sSQL) or ect_error();
		if($totalcats > 0){
			$islooping=FALSE;
			$noproducts=FALSE;
			$hascatinprodsection=FALSE;
			$pblink='<a href="admincats.php?scat='.@$_REQUEST['scat'].'&stext='.urlencode(@$_REQUEST['stext']).'&perpage='.urlencode(@$_REQUEST['perpage']).'&stype='.@$_REQUEST['stype'].($sortorder!=''?'&sort='.$sortorder:'').'&catfun='.@$_REQUEST['catfun'].'&pg=';
			if($iNumOfPages > 1) print '<tr><td align="center" colspan="' . ($useStockManagement?7:6) . '">' . writepagebar($CurPage,$iNumOfPages,$yyPrev,$yyNext,$pblink,FALSE) . '<br><br></td></tr>';
			displayheaderrow();
			$ordingroup=1;
			$checkfirstgroup=($CurPage!=1);
			while($rs=ect_fetch_assoc($result)){
				if($currgroup==-1) $currgroup=$rs['topSection'];
				if($currgroup!=$rs['topSection']){
					if($checkfirstgroup){
						$result2=ect_query('SELECT COUNT(*) AS catcnt FROM sections WHERE topSection='.$currgroup) or ect_error();
						if($rs2=ect_fetch_assoc($result2)) $ordingroup=$rs2['catcnt']+1;
						ect_free_result($result2);
						$checkfirstgroup=FALSE;
					}
					if($sortorder==''||$sortorder=='act') print '<tr><td colspan="' . ($useStockManagement?7:6) . '">&nbsp;</td></tr>';
					$rowsingrp.='rowsingrp['.$currgroup.']='.($ordingroup-1).";";
					$currgroup=$rs['topSection'];
					$ordingroup=1;
				}
				$jscript.='pa['.$rowcounter.']=[';
				print '<tr id="tr' . $rowcounter . '"><td>';
				$qetype='text';
				$qesize='18';
				if($cract=='can'){
					$jscript.="'".jsspecials($rs['sectionName'])."'";
				}elseif($cract=='can2'){
					$jscript.="'".jsspecials($rs['sectionName2'])."'";
				}elseif($cract=='can3'){
					$jscript.="'".jsspecials($rs['sectionName3'])."'";
				}elseif($cract=='cwn'){
					$jscript.="'".jsspecials($rs['sectionWorkingName'])."'";
				}elseif($cract=='cim'){
					$jscript.="'".jsspecials($rs['sectionImage'])."'";
				}elseif($cract=='ptt'){
					$jscript.="'".jsspecials($rs['sTitle'])."'";
				}elseif($cract=='ptt2'){
					$jscript.="'".jsspecials($rs['sTitle2'])."'";
				}elseif($cract=='ptt3'){
					$jscript.="'".jsspecials($rs['sTitle3'])."'";
				}elseif($cract=='med'){
					$jscript.="'".jsspecials($rs['sMetaDesc'])."'";
				}elseif($cract=='med2'){
					$jscript.="'".jsspecials($rs['sMetaDesc2'])."'";
				}elseif($cract=='med3'){
					$jscript.="'".jsspecials($rs['sMetaDesc3'])."'";
				}elseif($cract=='rec'){
					$jscript.=($rs['sRecommend']!=0?1:0);
					$qetype='checkbox';
				}elseif($cract=='cur'){
					$jscript.="'".jsspecials($rs['sectionurl'])."'";
				}elseif($cract=='cur2'){
					$jscript.="'".jsspecials($rs['sectionurl2'])."'";
				}elseif($cract=='cur3'){
					$jscript.="'".jsspecials($rs['sectionurl3'])."'";
				}elseif($cract=='cor'||$cract==''){
					$qetype='special';
					$jscript.="''";
					if($sortorder==''||$sortorder=='act'){
						$currpos=min($totalcats,max(1,$rs['sectionOrder']));
						print '<select onmouseover="cpu(this,'.$ordingroup.','.$rs['topSection'].','.$rs['sectionID'].')">';
						print '<option value="'.$currpos.'">'.$ordingroup.($ordingroup<100?'&nbsp;':'').'</option>';
						print '</select>';
					}else
						print '&nbsp;';
				}elseif($cract=='del'||$cract=='dei'){
					$jscript.="'del'";
					$qetype='delbox';
				}elseif($cract=='dis'&&$currentdiscount!=''){
					$sSQL="SELECT cpaID FROM cpnassign WHERE cpaType=1 AND cpaAssignment='".escape_string($rs['sectionID'])."' AND cpaCpnID=".$currentdiscount;
					$result2=ect_query($sSQL) or ect_error();
					$jscript.=(ect_num_rows($result2)==0?0:1);
					ect_free_result($result2);
					$qetype='checkbox';
				}elseif($cract=='vim'){
					$jscript.="'";
					if(trim($rs['sectionImage'])!='') $jscript.=(strtolower(substr($rs['sectionImage'],0,5))!='http:' && strtolower(substr($rs['sectionImage'],0,6))!='https:' && substr($rs['sectionImage'],0,1)!='/'?'../':'') . jsspecials($rs['sectionImage']);
					$jscript.="'";
					$qetype="image";
				}elseif($cract=='lol'){
					$jscript.=$rs['sectionDisabled'];
					$qetype='loginlevel';
				}elseif($cract=='css'){
					$jscript.="'".jsspecials($rs['sCustomCSS'])."'";
					$qesize=16;
				}elseif($cract=='csu'||$cract=='csu2'||$cract=='csu3'){
					$jscript.='0';
					$qetype='checkbox';
				}else
					$qetype='';
				print '</td>';
				if($rs['rootSection']==0){
					$sumStock='-';
					if($sortorder=="caa") $sectionCount=$rs['sectionCount']; else $sectionCount='-';
				}elseif($sortorder=='pra'||$sortorder=='sta'||$sortorder=='caa'){
					$sumStock=$useStockManagement?$rs['sumStock']:0;
					$sectionCount=$rs['sectionCount'];
				}else{
					$sSQL='SELECT '.($useStockManagement?'SUM(pInStock) AS sumStock,':'').'COUNT(pSection) AS sectionCount FROM products WHERE pSection=' . $rs['sectionID'];
					$result2=ect_query($sSQL) or ect_error();
					$rs2=ect_fetch_assoc($result2);
					$sumStock=$useStockManagement?$rs2['sumStock']:0;
					$sectionCount=$rs2['sectionCount'];
				}
				print '<td>';
				$tslist='';
				$thetopts=$rs["topSection"];
				for($index=0; $index <= 10; $index++){
					if($thetopts==0){
						$tslist=substr($tslist,3);
						break;
					}elseif($index==10){
						$tslist='<span class="ectred">' . $yyLoop . '</span>' . $tslist;
						$islooping=TRUE;
					}else{
						$sSQL="SELECT sectionID,topSection,sectionWorkingName,rootSection FROM sections WHERE sectionID=" . $thetopts;
						$result2=ect_query($sSQL) or ect_error();
						if(ect_num_rows($result2) > 0){
							$rs2=ect_fetch_assoc($result2);
							$errstart=$errend='';
							if($rs2['rootSection']==1){
								$errstart='<span class="ectred">';
								$errend='</span>';
								$hascatinprodsection=TRUE;
							}
							$tslist=' '.$raquo.' '.$errstart.$rs2['sectionWorkingName'].$errend.$tslist;
							$thetopts=$rs2['topSection'];
						}else{
							$tslist='<span class="ectred">' . $yyTopDel . '</span>' . $tslist;
							break;
						}
						ect_free_result($result2);
					}
				}
				print $tslist . '</td><td>';
				if($rs['rootSection']==1) print '<strong>';
				if($rs['sectionDisabled']==127) print '<span style="color:#FF0000;text-decoration:line-through">';
				if($catalogroot==$rs['sectionID']) print '<span title="Catalog Root" style="padding-left:10px;text-decoration:underline overline;font-size:larger;">';
				print $rs['sectionWorkingName'] . ' (' . $rs['sectionID'] . ')';
				if($catalogroot==$rs['sectionID']) print '</span>';
				if($rs['sectionDisabled']==127) print '</span>';
				if($rs['rootSection']==1) print '</strong>';
				$hascoupon='0';
				for($index=0;$index<$numcoupons;$index++){
					if((int)$allcoupon[$index]['cpaAssignment']==$rs['sectionID']){
						$hascoupon='1';
						break;
					}
				}
				print '</td><td>' . $sectionCount . '</td>';
				if($useStockManagement) print '<td class="minicell">' . $sumStock . '</td>';
				print "<td>-</td><td>-</td></tr>\n";
				$jscript.=','.$rs['sectionID'].','.$hascoupon . "];\n";
				$rowcounter++;
				$ordingroup++;
			}
			if($iNumOfPages > 1) print '<tr><td align="center" colspan="' . ($useStockManagement?7:6) . '"><br>' . writepagebar($CurPage,$iNumOfPages,$yyPrev,$yyNext,$pblink,FALSE) . '</td></tr>';
			if($islooping){ ?>
				  <tr><td width="100%" colspan="<?php print ($useStockManagement?7:6)?>"><br><span style="color:#FF0000;font-weight:bold">** </span><?php print $yyCatEx3?></td></tr>
<?php		}
			if($hascatinprodsection){ ?>
				  <tr><td width="100%" colspan="<?php print ($useStockManagement?7:6)?>"><br><ul><li><?php print $yyCPErr?></li></ul></td></tr>
<?php		} ?>
				  <tr><td width="100%" colspan="<?php print ($useStockManagement?7:6)?>"><br><ul><li><?php print $yyCatEx4?></li></ul></td></tr>
<?php	}else{ ?>
				  <tr><td width="100%" colspan="<?php print ($useStockManagement?7:6)?>" align="center"><br><strong><?php print $yyCatEx5?><br>&nbsp;</td></tr>
<?php	}
		ect_free_result($result);
		$result=ect_query('SELECT COUNT(*) AS catcnt FROM sections WHERE topSection='.$currgroup) or ect_error();
		if($rs=ect_fetch_assoc($result)) $ordingroup=$rs['catcnt']+1;
		ect_free_result($result);
		$rowsingrp.='rowsingrp['.$currgroup.']='.($ordingroup-1).';';
	}else{
		if(trim(@$detlinkspacechar)!=''){
			$rowcounter=0;
			$sSQL="SELECT sectionID,sectionWorkingName,sectionURL,rootSection,sectionDisabled FROM sections WHERE sectionDisabled<>127 AND sectionURL LIKE '%\\".escape_string($detlinkspacechar)."%'";
			$result=ect_query($sSQL) or ect_error();
			if(ect_num_rows($result)>0){
				print '<tr><td colspan="' . ($useStockManagement?7:6) . '" style="color:#FF0000">You have the $detlinkspacechar parameter set as &quot;' . $detlinkspacechar. '&quot; but have categories where the Static URL uses this character and these will not display properly. Consider removing the $detlinkspacechar parameter, or replacing it with a space in the Static URL for these products.</td></tr>';
				displayheaderrow();
				while($rs=ect_fetch_assoc($result)){
					$jscript.='pa['.$rowcounter.']=['.$rs['sectionID'].",0];\n";
					print '<tr id="tr' . $rowcounter . '"><td class="minicell">-</td><td>' . $rs['sectionURL'] . '</td><td>' . $rs['sectionWorkingName'] . '</td>' . ($useStockManagement?'<td></td>':'') . "<td>-</td><td>-</td><td>-</td></tr>\n";
					$rowcounter++;
				}
			}
		}
		$numitems=0;
		$sSQL='SELECT COUNT(*) as totcount FROM sections';
		$result=ect_query($sSQL) or ect_error();
		if($rs=ect_fetch_assoc($result))
		$numitems=$rs['totcount'];
		print '<tr><td colspan="' . ($useStockManagement?7:6) . '"><div class="itemsdefine">You have ' . $numitems . ' categories defined.</div></td></tr>';
	}
?>
			  <tr style="height:50px">
				<td align="center" style="white-space:nowrap"><?php if($rowcounter>0 && $cract!='' && $cract!='none' && $cract!='cor') print '<input type="hidden" name="resultcounter" id="resultcounter" value="'.$rowcounter.'"><input type="button" value="'.$yyUpdate.'" onclick="quickupdate()"> <input type="reset" value="'.$yyReset.'">'; else print '&nbsp;'?></td>
                <td width="100%" colspan="<?php print ($useStockManagement?5:4)?>" align="center"><br><a href="admin.php"><strong><?php print $yyAdmHom?></strong></a></td>
				<td>&nbsp;</td>
			  </tr>
            </table>
		  </form>
<script>
/* <![CDATA[ */
var pa=[];
<?php	if($qetype=="image"){ ?>
function imageisvisible(img){
    var rect=img.getBoundingClientRect();
    return(rect.top<=(window.innerHeight||document.documentElement.clientHeight));
}
function checkvisibleimages(){
	var lzimgs=document.getElementById('catstable').getElementsByClassName('lazyload');
	var tarray=[];
	if(lzimgs.length==0){
		removeEventListener('scroll',setcheckvisibletimeout);
	}else{
		for(var lzi=0; lzi<lzimgs.length; lzi++){
			var telem=lzimgs[lzi];
			if(imageisvisible(telem)){
				telem.src=telem.getAttribute('data-src');
				tarray.push(telem.id);
			}
		}
		for(var lzi=0; lzi<tarray.length; lzi++){
			document.getElementById(tarray[lzi]).className='lazydoneload';
		}
	}
}
var checkvisibletimeout='';
function setcheckvisibletimeout(){
	if(checkvisibletimeout!='') clearTimeout(checkvisibletimeout);
	checkvisibletimeout=setTimeout(checkvisibleimages,300)
}
addEventListener('scroll',setcheckvisibletimeout);
addEventListener('load',checkvisibleimages);
<?php	}
print $jscript; ?>
function createloginlevel(pid,sid){
	var mup='<select size="1" id="sec'+pid+'" onchange="this.name=\'pra_'+patch_pid(pidind)+'\'"><option value="0">No Restriction</option>';
	for(var cli=1; cli<=<?php print $maxloginlevels?>; cli++){
		mup+='<option value="'+cli+'"' + (cli==sid?' selected':'') + '>Login Level '+cli+'</option>';
	}
	mup+='<option value="127"' + (sid==127?' selected':'') + '>Disable Category</option>';
	return(mup+'</select>');
}
function patch_pid(pid){
	document.getElementById('pid'+pid).name='pid'+pid;
	document.getElementById('pid'+pid).value=pa[pid][1];
	return pid;
}
for(var pidind in pa){
	var ttr=document.getElementById('tr'+pidind);
	var stockcell=<?php print $useStockManagement?1:0 ?>;
	ttr.cells[0].className="minicell";
	ttr.cells[1].className="maincell small";
	ttr.cells[3].className="minicell";
	ttr.cells[1].innerHTML+='<input type="hidden" id="pid'+pidind+'" value="">';
	ttr.cells[4+stockcell].style.textAlign='center';
	ttr.cells[5+stockcell].style.textAlign='center';
	ttr.cells[5+stockcell].style.whiteSpace='nowrap';
	ttr.cells[4+stockcell].innerHTML='<input type="button" '+(pa[pidind][2]?' class="ectset"':'')+' value="<?php print jsescape(htmlspecials($yyAssign))?>" onclick="dsc(\''+pa[pidind][1]+'\')">';
	ttr.cells[5+stockcell].innerHTML='<input type="button" value="M" style="width:30px;margin-right:4px" onclick="mr(\''+pa[pidind][1]+'\')" title="<?php print jsescape(htmlspecials($yyModify))?>">' +
		'<input type="button" value="C" style="width:30px;margin-right:4px" onclick="cr(\''+pa[pidind][1]+'\')" title="<?php print jsescape(htmlspecials($yyClone))?>">' +
		'<input type="button" value="X" style="width:30px" onclick="dr(\''+pa[pidind][1]+'\')" title="<?php print jsescape(htmlspecials($yyDelete))?>">';
<?php	if($cract!='cor'&&$cract!=''){ ?>
	ttr.cells[0].innerHTML=
<?php		if($qetype=='text'){ ?>
	pa[pidind][0]===false?'-':'<input type="text" id="chkbx'+pidind+'" size="<?php print $qesize?>" onchange="this.name=\'pra_'+patch_pid(pidind)+'\'" value="'+pa[pidind][0].replace('"','&quot;')+'" tabindex="'+(pidind+1)+'">';
<?php		}elseif($qetype=="delbox"){ ?>
	'<input type="checkbox" id="chkbx'+pidind+'" onchange="this.name=\'pra_'+patch_pid(pidind)+'\'" value="del" tabindex="'+(pidind+1)+'">';
<?php		}elseif($qetype=="checkbox"){ ?>
	'<input type="hidden" id="pra_'+pa[pidind][1]+'" value="1"><input type="checkbox" id="chkbx'+pidind+'" onchange="this.name=\'prb_'+patch_pid(pidind)+'\';document.getElementById(\'pra_'+pa[pidind][1]+'\').name=\'pra_'+patch_pid(pidind)+'\'" value="1" '+(pa[pidind][0]==1?'checked="checked" ':'')+'tabindex="'+(pidind+1)+'">';
<?php		}elseif($qetype=="image"){ ?>
	(pa[pidind][0]==''?'-':'<img class="lazyload" id="lazyimg'+pidind+'" src="adminimages/imageload.png" data-src="'+pa[pidind][0]+'" style="max-width:80px;cursor:pointer" alt="" onclick="mr(\''+pa[pidind][1]+'\')">');
<?php		}elseif($qetype=="loginlevel"){ ?>
	createloginlevel(pidind,pa[pidind][0]);
<?php		}else{ ?>
	'&nbsp;';
<?php		}
		} ?>
}
<?php print @$rowsingrp?>
/* ]]> */
</script>
<?php
}
?>