<?php 
$result4 = $mysqli->query("SELECT insert_id, page, name, title, text, image FROM sections WHERE promote LIKE '%1%' AND lang_id=$lang ORDER BY priority, parent");
while($row = $result4->fetch_array()) {	
$secid1=$row['insert_id'];
$pagesection1=$row['page'];
$secname=$row['name'];
$secdesc=$row['title'];
$cimage=$row['image'];
if (!$secdesc) { 
$secdesc=$secname;
}
$catt1=$row['text'];
$catt = mb_substr(strip_tags($catt1), 0, 300, 'UTF-8');
$photopath="sections/";
?>
<div class="boxcat"><div class="boxincat">
<div class="boximage-cat colorlight"><?php if ($cimage!=0 AND (file_exists("./files/".$photopath.$secid1.".jpg"))) { ?><a href="<?php echo $pagesection1 ?>."><img src="<?php echo $codepath ?>includes/image.php?image=<?php echo $imagepath.$photopath ?><?php echo $secid1 ?>.jpg&amp;nwidth=400" class="bordercolor1 img-icat" alt="<?php echo $secname ?>" title="<?php echo $secdesc ?>"></a><?php }?></div>
<div class="boxcattitles color1"><?php echo $iconsec ?> <a href="<?php echo $pagesection1 ?>."><?php echo $secname ?></a></div>
<div class="boxcattext color1h"><?php echo $catt ?><?php if ($catt1!=$catt) { echo '...'; }?></div>
<div class="boxsections">
<?php 
$result21 = $mysqli->query("SELECT insert_id, page, name, type FROM categories WHERE level=1 AND insert_id>1 AND promote LIKE '%3%' AND lang_id=$lang AND publish='yes' ORDER BY priority");
while($row = $result21->fetch_array()) {
$mcatid1=$row['insert_id'];
$mpage1=$row['page'];
$mcategory1=$row['name'];
$mtypec1=$row['type'];

$result23 = $mysqli->query("SELECT COUNT(id) FROM items WHERE category_id IN (SELECT insert_id FROM categories WHERE insert_id='$mcatid1' OR parent='$mcatid1') AND section_id>0 AND lang_id=$lang AND publish='yes'");
$rows = $result23->fetch_row();
$nrrows23 = $rows[0];
?>
<?php if ($nrrows23>0) {?>
<div>
<?php if ($mtypec1==2) {?>
<div class="titlesnav titlescat"><a href="<?php echo $pagesection1 ?>.<?php echo $mpage1 ?>"><?php echo $mcategory1 ?></a></div>
<?php }else{?>
<div class="titlesnav titlescat"><?php echo $mcategory1 ?></div>
<?php } ?>
<?php 
$result24 = $mysqli->query("SELECT insert_id, page, name FROM sections WHERE parent='$secid1' AND lang_id=$lang AND publish='yes' ORDER BY priority");
while($row = $result24->fetch_array()) {
$secid2=$row['insert_id'];
$pagesection2=$row['page'];
$section2=$row['name'];

$result25 = $mysqli->query("SELECT COUNT(id) FROM items WHERE category_id='$mcatid1' AND section_id='$secid2' AND lang_id=$lang AND publish='yes'");
$rows = $result25->fetch_row();
$nrrows25 = $rows[0];
?>
<?php if ($nrrows25>0) {?>
<a href="<?php echo $pagesection1 ?>-<?php echo $pagesection2 ?>.<?php echo $mpage1 ?>" class="linkss color1">&raquo; <?php echo $section2 ?></a>
<?php } ?>
<?php } ?>
<?php 
$result26 = $mysqli->query("SELECT insert_id, page, name FROM categories WHERE parent='$mcatid1' AND promote LIKE '%3%' AND lang_id=$lang AND publish='yes' ORDER BY priority");
while($row = $result26->fetch_array()) {
$mcatid2=$row['insert_id'];
$mpage2=$row['page'];
$mcategory2=$row['name'];

$result27 = $mysqli->query("SELECT COUNT(id) FROM items WHERE category_id='$mcatid2' AND section_id='$secid1' AND lang_id=$lang AND publish='yes'");
$rows = $result27->fetch_row();
$nrrows27 = $rows[0];
?>
<?php
$resulti27 = $mysqli->query("SELECT COUNT(id) FROM items WHERE section_id IN (SELECT insert_id FROM sections WHERE parent='$secid1' AND lang_id=$lang AND publish='yes') AND category_id='$mcatid2' AND lang_id=$lang AND publish='yes'");
$rows = $resulti27->fetch_row();
$nrrowsi27 = $rows[0];
?>
<?php if ($nrrowsi27>0) {?>
<div>
<span class="titlescat color2"><a href="<?php echo $pagesection1 ?>.<?php echo $mpage2 ?>" class="color2"><?php echo $mcategory2 ?></a></span>
<?php 
$result28 = $mysqli->query("SELECT insert_id, page, name FROM sections WHERE parent='$secid1' AND lang_id=$lang AND publish='yes' ORDER BY priority");
while($row = $result28->fetch_array()) {
$secid2=$row['insert_id'];
$pagesection2=$row['page'];
$section2=$row['name'];

$result29 = $mysqli->query("SELECT COUNT(id) FROM items WHERE category_id='$mcatid2' AND section_id='$secid2' AND lang_id=$lang AND publish='yes'");
$rows = $result29->fetch_row();
$nrrows29 = $rows[0];
?>
<?php if ($nrrows29>0) {?>
<a href="<?php echo $pagesection1 ?>-<?php echo $pagesection2 ?>.<?php echo $mpage2 ?>" class="linkss color1">&raquo; <?php echo $section2 ?></a>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
<?php } ?>
</div>
<?php } ?><?php } ?>
</div>
</div></div>  
<?php }?><div class="cleared"></div>