<?php include 'sets.php';?>
<?php
$resultsections = $mysqli->query("SELECT COUNT(id) FROM sections WHERE lang_id=$lang AND publish='yes'");
$rows = $resultsections->fetch_row();
$srows = $rows[0];
if ($srows>0) {

if ($_REQUEST['section']) { 
$section = $mysqli->real_escape_string(stripslashes($_REQUEST['section']));
$resultfs = $mysqli->query("SELECT * FROM sections WHERE page='$section' AND lang_id=$lang");
$row = $resultfs->fetch_array();
$fsid=$row['insert_id'];
$separent=$row['parent'];
$sepage=$row['page'];
$secategory=$row['name'];
$secategory = strip_tags($secategory);
$setitle=$row['title'];
if ($setitle=='') {
$setitle=$secategory;
}
$sedescription=$row['description'];
if ($sedescription=='') {
$sedescription=$secategory;
}
$sekeywords=$row['keywords'];
$secimage=$row['image'];
$photopaths="sections/";
$photovars="section_id";

$resultsec1 = $mysqli->query("SELECT * FROM sections WHERE insert_id='$separent' AND lang_id=$lang");
$row = $resultsec1->fetch_array();
$secategory1=$row['name'];
$secategory1 = strip_tags($secategory1);
$siteactivity="$setitle $secategory1";

if ($_REQUEST['ssection']) { 
$section = $mysqli->real_escape_string(stripslashes($_REQUEST['ssection']));
$resultss = $mysqli->query("SELECT * FROM sections WHERE page='$section' AND lang_id=$lang");
$row = $resultss->fetch_array();
$fsid2=$row['insert_id'];
$fsid=$row['parent'];
$separent=$fsid;
$sepage2=$row['page'];
$secategory2=$row['name'];
$secategory2 = strip_tags($secategory2);
$setitle2=$row['title'];
if ($setitle2=='') {
$setitle2=$secategory2;
}
$sedescription2=$row['description'];
if ($sedescription2=='') {
$sedescription2=$secategory2;
}
$sekeywords2=$row['keywords'];
$siteactivity="$setitle2 $setitle";
$secimage2=$row['image'];
}

$resultsec = $mysqli->query("SELECT * FROM sections WHERE page='$section' AND parent='$separent' AND lang_id=$lang");
$row = $resultsec->fetch_array();
$secid=$row['insert_id'];

}else{
$secid=0;
}
}
if (!$fsid) {
$secid=0;
}

$page = $mysqli->real_escape_string(stripslashes($_REQUEST['page']));
$result = $mysqli->query("SELECT * FROM categories WHERE page='$page' AND lang_id=$lang");
$row = $result->fetch_array();
$catid=$row['insert_id'];
$page=$row['page'];
$category=$row['name'];
$category = strip_tags($category);
$title=$row['title'];
$maintitle=$row['title'];
if ($maintitle=='') {
$maintitle=$category;
}
$description=$row['description'];
$maindescription=$row['description'];
if ($maindescription=='') {
$maindescription=$category;
}
$keywords=$row['keywords'];
$cattext=$row['text'];
$catscript=$row['script'];
$discount=$row['discount'];
$catimage=$row['image'];
$typec=$row['type'];
$typec1=$row['type'];
$parent=$row['parent'];
$photopath="categories/";
$photovar="category_id";

$resultfc = $mysqli->query("SELECT * FROM categories WHERE insert_id='$parent' AND lang_id=$lang");
$row = $resultfc->fetch_array();
$catimage1=$row['image'];

if (!$catid) {
header ("Location: .");
exit;
}

if ($catimage==2) {
$pid=$catid;
} else if ($catimage1==2) {
$pid=$parent;
} else {

if ($fsid AND $secimage!=0) {
$photopath = $photopaths;
$photovar = $photovars;
if ($secimage2!=0) {
$pid=$fsid2;
} else {
$pid=$fsid;
}
}
}

if ($secid==0) { 
//category
if ($title=='') { 
$title1="$category $siteactivity";
} else {
$title1="$title";	
}
if ($description=='') { 
$description1="$category $sitecompany - $siteactivity";
} else {
$description1="$description";	
}
if ($keywords=='') { 
$keywords1="$category, $sitecompany, $category $siteactivity";
} else {
$keywords1="$keywords";	
}
} else {
// sections
if (!$sedescription2) {
$sedescription2=$sedescription;
}
$title1="$maintitle $siteactivity";
$description1="$maindescription $sedescription2 - $setitle $secategory1";	
$keywords1="$category $secategory $secategory2, $setitle $category, $category $siteactivity, $sekeywords";
}
?>
<!DOCTYPE html>
<html lang="<?php echo $langname ?>">
<head>
<meta charset="utf-8">
<title><?php echo $title1 ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="<?php echo $description1 ?>">
<meta name="keywords" content="<?php echo $keywords1 ?>">
<?php include 'codes.php';?>
</head>
<body>
<?php include 'menunav.php';?>
<div class="container">
<?php if ($menu1==1) { ?><?php include 'menu1.php';?><?php }?>
<div class="contentstyle">
<div class="pages"><div class="content"><h1><?php if ($secid>0) {?><span class="color2"><?php echo $secategory ?><?php if ($secategory2) { echo ' &raquo; '; } ?><?php echo $secategory2 ?> &raquo; </span><?php }?><?php echo $category ?></h1></div>
</div>
<?php if ($cattext) {?><div class="content divcattext"><?php echo $cattext ?></div><?php }?>
<?php include 'includes/filters.php';?>

<?php if ($typec==0 OR $typec==1) { ?>
<?php
$result1 = $mysqli->query("SELECT id FROM items WHERE (category_id='$catid' OR category_id=ANY (SELECT insert_id FROM categories WHERE parent='$catid' AND lang_id=$lang AND publish='yes')) AND section_id='$secid' AND lang_id=$lang AND publish='yes'");
$rows = mysqli_num_rows($result1);

include ('includes/pagination.php');

$result2 = $mysqli->query("SELECT * FROM items WHERE (category_id='$catid' OR category_id=ANY (SELECT insert_id FROM categories WHERE parent='$catid' AND lang_id=$lang AND publish='yes')) AND section_id='$secid' AND lang_id=$lang AND publish='yes' ORDER BY category_id, section_id, $orderpriority LIMIT $start,$nritems");
while($row = $result2->fetch_array()) {	
$count++;
$id=$row['insert_id'];
$category_id=$row['category_id'];
$section_id=$row['section_id'];
$pageid=$row['page_id'];
$pageitem=$row['page'];
if ($itempage==1) { $siteitem=$pageitem; }
$pagesiteitem=$siteitem.".".$pageid;
$name=$row['name'];
$description=$row['description'];
$details=$row['details'];
$text=$row['text'];
$extra=$row['extra'];
$code=$row['code'];
$url=$row['url'];
$itemail=$row['email'];
$script=$row['script'];
$price=$row['price'];
$price1=$row['price'];
$offerprice=$row['offerprice'];
$weight=$row['weight'];
$unit=$row['unit'];
$image=$row['image'];
$file=$row['file'];
$new=$row['new'];
$available=$row['available'];
$size=$row['size'];
$color=$row['color'];
$showpage=$row['showpage'];
$priority=$row['priority'];
$itemdate=$row['date'];
?>
<?php include 'includes/info.php';?>
<?php } ?>
<div class="content"><div class="itemscontent">
<?php
$result3 = $mysqli->query("SELECT * FROM items WHERE insert_id IN (SELECT item_id FROM groups WHERE category_id='$catid') AND lang_id=$lang AND publish='yes' ORDER BY category_id, section_id, $orderpriority");
while($row = $result3->fetch_array()) {	
include 'includes/itemq.php';
?><?php include 'includes/itemb.php';?><?php } ?>
</div></div>
<?php }else{?>
<div class="content padbottom20"><div class="itemscontent">
<?php
$result1 = $mysqli->query("SELECT id FROM items WHERE (category_id='$catid' OR category_id=ANY (SELECT insert_id FROM categories WHERE parent='$catid' AND lang_id=$lang AND publish='yes')
OR insert_id IN (SELECT item_id FROM groups WHERE category_id='$catid')) AND (section_id='$secid' OR section_id=ANY (SELECT insert_id FROM sections WHERE parent='$secid')) AND lang_id=$lang AND publish='yes'");
$rows = mysqli_num_rows($result1);

include ('includes/pagination.php');

$result2 = $mysqli->query("SELECT * FROM items WHERE (category_id='$catid' OR category_id=ANY (SELECT insert_id FROM categories WHERE parent='$catid' AND lang_id=$lang AND publish='yes') OR insert_id IN (SELECT item_id FROM groups WHERE category_id='$catid')) AND (section_id='$secid' OR section_id=ANY (SELECT insert_id FROM sections WHERE parent='$secid')) AND lang_id=$lang AND publish='yes' ORDER BY category_id, section_id, $orderpriority LIMIT $start,$nritems");
while($row = $result2->fetch_array()) {	
include 'includes/itemq.php';
?><?php include 'includes/itemb.php';?><?php } ?>
</div><div class="cleared"><?php echo $txtitems ?></div></div>
<?php } ?>
<?php include 'includes/paginate.php';?>
<?php
$resultpcat = $mysqli->query("SELECT id FROM items WHERE category_id IN (SELECT insert_id FROM categories WHERE type=2 AND promote LIKE '%3%' AND lang_id=$lang) 
AND (section_id='$secid' OR section_id IN (SELECT insert_id FROM sections WHERE (insert_id='$secid' OR parent='$secid')) AND lang_id=$lang AND publish='yes')
AND lang_id=$lang AND publish='yes'");
$rowspromotecat = mysqli_num_rows($resultpcat);

if ($rowspromotecat>0 AND $typec==1) { ?>
<!--promote cat -->
<?php echo $promotecat ?>
<?php
$resultp = $mysqli->query("SELECT insert_id, page, name, type FROM categories WHERE type=2 AND promote LIKE '%3%' AND lang_id=$lang ORDER BY priority");
while($row = $resultp->fetch_array()) {
$catidp=$row['insert_id'];
$catpagep=$row['page'];
$categoryp=$row['name'];
$typep=$row['type'];
?>
<?php
$resultitems = $mysqli->query("SELECT id FROM items WHERE category_id='$catidp' 
AND (section_id='$secid' OR section_id IN (SELECT insert_id FROM sections WHERE (insert_id='$secid' OR parent='$secid')) AND lang_id=$lang AND publish='yes')
AND lang_id=$lang AND publish='yes'");
$rowscatitems = mysqli_num_rows($resultitems);
?>
<?php if ($rowscatitems>0) { ?>
<div class="titles1 color3 text-center"><?php echo $categoryp ?> &raquo; <span class="color1"><?php echo $secategory ?><?php if ($separent>0) { ?> &raquo; <?php echo $secategory2 ?><?php } ?></span></div>
<div class="content"><div class="itemscontent">
<?php
$resultpi = $mysqli->query("SELECT * FROM items WHERE category_id='$catidp' 
AND (section_id='$secid' OR section_id IN (SELECT insert_id FROM sections WHERE (insert_id='$secid' OR parent='$secid')) AND lang_id=$lang AND publish='yes')
AND lang_id=$lang AND publish='yes' ORDER BY section_id, $orderpriority");
while($row = $resultpi->fetch_array()) {
include 'includes/itemq.php';
?><?php include 'includes/itemb.php';?><?php }?>
</div><div class="cleared"></div></div>
<?php echo $promotecat2 ?>
<?php } ?>
<?php } ?>
<!--end promote cat -->
<?php } ?>
</div>
<?php if ($menu2==1) { ?><?php include 'menu2.php';?><?php }?>
</div>
<?php include 'menudown.php';?>
</body>
</html>