<?php
print "
<div class='container'>
	<ul class='tabs'>";
if (isset($_SESSION['backend']['id_session'])) {
	if (isset($backend_module) && $backend_module && check_table($backend_module.'_modules')){
		$sql_tmp = "SELECT title, text, icon FROM ".$backend_module."_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()){
				print "<li class='";
				if ($arr_tmp['title'] == $module) print "current";
				print "'><a href='index.php?module=".$arr_tmp['title']."&backend_module=".$backend_module."' 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 $arr_tmp['text']."</a></li>";
			}
		}
		if ($_SESSION['backend']['permissions']['admin'] == 1){
			if (check_table($backend_module."_options")){
				$sql_tmp = "SELECT id FROM ".$backend_module."_modules WHERE title = :title";
				$result_tmp = $conn->prepare($sql_tmp);
				$result_tmp->bindValue(':title', $backend_module."_options", PDO::PARAM_STR);
				$result_tmp->execute();
				if (!$result_tmp->rowCount()){
					print "<li class='options ";
					if ($backend_module."_options" == $module) print "current";
					print "'><a href='index.php?module=".$backend_module."_options&backend_module=".$backend_module."' title='".LABEL_OPTIONS."'><i class='material-icons md-24'>settings</i></a></li>";
				}
			}
			if (check_table($backend_module."_labels")){
				$sql_tmp = "SELECT id FROM ".$backend_module."_modules WHERE title = :title";
				$result_tmp = $conn->prepare($sql_tmp);
				$result_tmp->bindValue(':title', $backend_module."_labels", PDO::PARAM_STR);
				$result_tmp->execute();
				if (!$result_tmp->rowCount()){
					print "<li class='labels ";
					if ($backend_module."_labels" == $module) print "current";
					print "'><a href='index.php?module=".$backend_module."_labels&backend_module=".$backend_module."' title='".LABEL_LABELS."'><i class='material-icons md-24'>local_offer</i></a></li>";
				}
			}
		}
	} else if (isset($module) && ($module == 'backend_modules' OR $module == 'modules_manager')){
		$sql_tmp = "SELECT title, text, icon FROM backend_modules WHERE title = 'settings' 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()){
				print "<li class='";
				if ($module == 'backend_modules') print "current";
				print "'><a href='index.php?module=backend_modules&backend_module=backend_modules' 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 $arr_tmp['text'];
				print "</a></li>";
			}
			print "<li class='options ";
			if ($module == 'modules_manager') print "current";
			print "'><a href='index.php?module=modules_manager&backend_module=backend_modules' title='".LABEL_OPTIONS."'><i class='material-icons md-24'>update</i></a></li>";
		}
	}
}

print "
	</ul>
</div><!-- /.container -->";