<?php

require '../../lib/glob.php';
require '../../lib/muoribene.php';
require '../../lib/sessionstart.php';
require '../../lib/myconn.php';
require '../../lib/getadmacc.php';
if ($account['Level']=='guest')
	muoribene('Sorry, you are not authorized.',true);
require '../../lib/menu.php';
$menu['menu']['selected']=true;
$menu['menu']['submenu']['instances']['selected']=true;
buildmenu($menu);
require '../../lib/notifs.php';
$notifs=notifs($link);

$dbg='';

use function mysqli_real_escape_string as myesc;

// praticamente una macro
function hspech($str) {
	return(htmlspecialchars($str,ENT_QUOTES|ENT_HTML5,'UTF-8'));
}

if (array_key_exists('id',$_GET) && preg_match('/^[0-9]+$/',$_GET['id'])===1) {
	$_GET['id']+=0;
	$res=mysqli_query($link,'SELECT *, ID AS IID FROM Instances WHERE ID='.$_GET['id'])
		or muoribene(__LINE__.': '.mysqli_error($link),true);
	if (mysqli_num_rows($res)>0) {
		require '../../lib/columns.php';
		require '../../lib/dispinst.php';
		$inst=mysqli_fetch_assoc($res);
		$out=dispinst($inst,$cols,$link,$dlang,$account,false,0,0);
	} else {
		$out='<p>Non esiste alcuna istanza con ID='.$_GET['id'].'.</p>'.N;
	}
} else {
	$out='<p>Nessuna istanza da mostrare.</p>';
}

mysqli_close($link);

?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Mustard - Visualizzatore istanze</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="description" content="Admin pages for Mastodon Help">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="icon" type="image/png" href="imgs/icona-32.png" sizes="32x32">
<link rel="icon" type="image/png" href="imgs/icona-192.png" sizes="192x192">
<link rel="icon" type="image/png" href="imgs/icona-512.png" sizes="512x512">
<link rel="apple-touch-icon-precomposed" href="imgs/icona-180.png">
<link rel="stylesheet" type="text/css" href="css/theme.css?v=<?php echo($cjrand); ?>">
<script language="JavaScript" src="js/menu.js?v=<?php echo($cjrand); ?>"></script>
<script language="JavaScript">
<!--
<?php require 'js/notifs.js.php'; ?>
//-->
</script>
</head>
<body>

<nav>
<div id="hmenu">
<ul>
<?php echo($menuout); ?>
</ul>
<div class="mtit">Visualizzatore istanze</div>
<div id="rightdiv">
<?php echo('<img src="'.$notifs['imgoff'].'" id="bell" class="rlinks" title="Show notifications" onclick="shidenotifs();">'.N); ?>
<img src="imgs/esci.svg" class="rlinks" title="Logout" onclick="document.location.href='logout.php';">
</div>
</div>
</nav>

<?php echo($notifs['div']); ?>

<div id="popup">
<div id="inpopup">
<div id="popupcont">
...
</div>
</div>
</div>

<!-- <div id="footer">
</div> -->

<div id="fullscreen">
<div id="middlerow">
<?php echo($out); ?>
</div>
</div>

<div id="debug">
<?php echo($dbg); ?>
</div>

</body>
</html>
