<?php #bin/print.php

//array $page = (int main, string sub, array css = [strings], array js = [strings])

//Include CSS
$tplcss = tplExtrSection($output["stat"], "###CSS###");
$css = "";
$x = false;
foreach ($output["css"] as $val)
{
  $css.= tplReplMarker($tplcss, "###CSSFILE###", $val."?id=".lgnGenSalt()).($x ? "\n" : "");
  $x = true;
}
$output["stat"] = tplReplSection($output["stat"], "###CSS###", $css);

//Include Javascript
$tpljs = tplExtrSection($output["stat"], "###JS###");
$js = "";
$x= false;
foreach ($output["js"] as $val)
{
  $js.= tplReplMarker($tpljs, "###JSFILE###", $val).($x ? "\n" : "");
  $x = true;
}
$output["stat"] = tplReplSection($output["stat"], "###JS###", $js);

//Additional
$output["stat"] = tplReplMarker($output["stat"], "###NAV###", $output["navi"]);
$output["stat"] = tplReplMarker($output["stat"], "###MAIN###", $output["main"]);
$output["stat"] = tplReplMarker($output["stat"], "###PAGETYPE###", $page["main"]=="" ? "frontpage" : "content");
$output["stat"] = tplReplMarker($output["stat"], "###TITLE###", TITLE);
$output["stat"] = tplReplMarker($output["stat"], "###LINKSTART###", "");
$output["stat"] = tplReplMarker($output["stat"], "###PAGEMAIN###", $page["main"]);
$url = parse_url("https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$output["stat"] = tplReplMarker($output["stat"], "###PAGEURL###", "https://".$url["host"].$url["path"]);
$output["stat"] = tplReplMarker($output["stat"], "###PAGEDOMAIN###", str_replace("www.", "", $url["host"]));
$output["stat"] = tplReplMarker($output["stat"], "###ERRORS###", $output["error"]);

//Print login/logout forms
if ($output["showlogin"]=="in") {
  //$tpllgn = tplExtrSection($output["stat"], "###LOGIN###");
  $output["stat"] = tplReplSection($output["stat"], "###LOGOFF###", "");
  $gets = "";
  foreach ($_GET as $key => $value) {
    $gets.= ($gets=="" ? "?" : "&").$key."=".$value;
  }
  $output["stat"] = tplReplMarker($output["stat"], "###PAGEGET###", $gets);
} elseif ($output["showlogin"]=="off") {
  //$tpllgn = tplExtrSection($output["stat"], "###LOGOFF###");
  $output["stat"] = tplReplSection($output["stat"], "###LOGIN###", "");
}

foreach ($lang as $key => $value) {
  $output["stat"] = tplReplMarker($output["stat"], $key, $value[$user["address.plural"]]);
}

$output["stat"] = tplReplMarker($output["stat"], "###SECTOKEN###", $_SESSION["secTokenUse"]);

//Print page
echo $output["stat"]; 


?>