<?php
print "
<div class='sidebar ";
if (isset($_SESSION['backend']['toggle_sidebar'])) print $_SESSION['backend']['toggle_sidebar'];
print "'>
	<nav class='main-nav'>
		<ul>";
if (isset($_SESSION['backend']['id_session'])) {
	$sql_tmp = "SELECT title, text, icon FROM backend_modules WHERE c_cms = '1' AND c_active = '1' AND (1 = '1' ";
	if ($_SESSION['backend']['permissions']['admin'] == 1) $sql_tmp .= "OR c_admin = '1' ";
	if ($_SESSION['backend']['permissions']['editor'] == 1) $sql_tmp .= "OR c_editor = '1' ";
	if ($_SESSION['backend']['permissions']['viewer'] == 1) $sql_tmp .= "OR c_viewer = '1' ";
	$sql_tmp.=") AND language = :language ORDER BY sortorder ASC";
	
	$result_tmp = $conn->prepare($sql_tmp);
	$result_tmp->bindValue(':language', $_SESSION['backend']['language'], PDO::PARAM_STR);
	$result_tmp->execute();
	
	if ($result_tmp->rowCount()){
		while ($arr_tmp = $result_tmp->fetch()){
			if (check_table($arr_tmp['title'].'_modules')){
				$sql_sub = "SELECT title, text, icon FROM ".$arr_tmp['title']."_modules WHERE c_cms = '1' AND c_active = '1' AND (1 = '1' ";
				if ($_SESSION['backend']['permissions']['admin'] == 1) $sql_sub .= "OR c_admin = '1' ";
				if ($_SESSION['backend']['permissions']['editor'] == 1) $sql_sub .= "OR c_editor = '1' ";
				if ($_SESSION['backend']['permissions']['viewer'] == 1) $sql_sub .= "OR c_viewer = '1'";
				$sql_sub.=") AND language = :language ORDER BY sortorder ASC LIMIT 1";
				
				$result_sub = $conn->prepare($sql_sub);
				$result_sub->bindValue(':language', $_SESSION['backend']['language'], PDO::PARAM_STR);
				$result_sub->execute();
				
				if ($result_sub->rowCount()){
					$arr_sub = $result_sub->fetch();
					print "<li ";
					if ($arr_sub['title'] == $module) print "class='current'";
					print "><a href='index.php?module=".$arr_sub['title']."&backend_module=".$arr_tmp['title']."' title='".$arr_tmp['text']."'>";
					if (isset($arr_tmp['icon']) && $arr_tmp['icon']) print "<i class='material-icons md-24'>".$arr_tmp['icon']."</i>";
					else print "<i class='material-icons md-24'>insert_drive_file</i>";
					print "<span class='text'>".$arr_tmp['text']."</span></a></li>";
				} else if ($arr_tmp['title'] == 'custom'){
					print "<li ";
					if ($module == 'custom_options') print "class='current'";
					print "><a href='index.php?module=custom_options&backend_module=".$arr_tmp['title']."' title='".$arr_tmp['text']."'>";
					if (isset($arr_tmp['icon']) && $arr_tmp['icon']) print "<i class='material-icons md-24'>".$arr_tmp['icon']."</i>";
					else print "<i class='material-icons md-24'>insert_drive_file</i>";
					print "<span class='text'>".$arr_tmp['text']."</span></a></li>";
				}
			}
		}
	}
}
print "
		</ul>
	</nav><!-- /.main-nav -->
</div><!-- /.sidebar -->";