<?php require_once 'includes/protect.php'; ?>
<?php
$result100 = $mysqli->query("SELECT * FROM lang WHERE active=1 ORDER BY main desc, priority asc");
while($row = $result100->fetch_array()) {
$langid=$row['id'];
$language=$row['language'];
$dir=$row['dir'];
$langurl=$row['url'];
$main=$row['main'];

if ($langurl) {
$langpath=$langurl;
} else {
$langpath=$codepath;
}
if ($pagename=='index.php') {
$pageurl="";
}

if ($pagename=='items.php') {
$result102 = $mysqli->query("SELECT page FROM categories WHERE insert_id='$catid' AND lang_id=$langid");
$row = $result102->fetch_array();
$pagec=$row['page'];
$pageurl=$pagec;

$result103 = $mysqli->query("SELECT page FROM sections WHERE insert_id='$secid' AND lang_id=$langid");
$row = $result103->fetch_array();
$pagesc=$row['page'];

$result103b = $mysqli->query("SELECT page FROM sections WHERE insert_id='$separent' AND lang_id=$langid");
$row = $result103b->fetch_array();
$pagesc1=$row['page'];

if ($pagesc1) {
$pageurl=$pagesc1."-".$pagesc.".".$pagec;
} else {
if ($pagesc) {
$pageurl=$pagesc.".".$pagec;
} else {
$pageurl=$pagec;
}}
}

if ($pagename=='item.php') {
$result105 = $mysqli->query("SELECT page_id, page FROM items WHERE insert_id='$id' AND lang_id=$langid");
$row = $result105->fetch_array();
$pageid=$row['page_id'];
$pageitem=$row['page'];
if ($itempage==1) { $siteitem=$pageitem; }
$pageurl=$siteitem.".".$pageid;
}
?>
<?php if ($main==1) {?>
<a href="<?php echo $langpath ?><?php echo $pageurl ?>" title="<?php echo $language ?>" class="iclang"><?php if ($langimg==0) {?><?php echo $language ?><?php } else {?><img src="<?php echo $filepath ?><?php echo $dir ?>.png" alt="<?php echo $language ?>"><?php } ?></a>
<?php }else{?>
<a href="<?php echo $langpath ?><?php if (!$langurl) {?><?php echo $dir ?>/<?php } ?><?php echo $pageurl ?>" title="<?php echo $language ?>" class="iclang"><?php if ($langimg==0) {?><?php echo $language ?><?php } else {?><img src="<?php echo $filepath ?><?php echo $dir ?>.png" alt="<?php echo $language ?>"><?php } ?></a>
<?php } ?>
<?php } ?>