<?php
echo("<script>
  function noModelsSelected(){
    alert('You have not made any requests, click on \"model selection\" to proceed');
  }
</script>");

// to enable calling header from multiple folder levels
if(file_exists('Pages/stuff.php'))include "Pages/stuff.php";
if(file_exists('stuff.php'))include "stuff.php";

$con = mysqli_connect($server,$user,$password,$db);
$user_id = 0;
$latest_model = 0;
$user_id = get_userid($con);
if($user_id != 0){
	$res = mysqli_query($con,"SELECT latest_model FROM users WHERE id={$user_id}");
	$row = mysqli_fetch_array($res);
	$latest_model = $row[0];
}
// this file may be called from high level (where index.php lives) or from
// one folder down (from within folder called Pages). Test where you are
// and set links to other pages appropriately
if(file_exists('Images/hit2gap_logo_high.png')){
  $image = 'Images/hit2gap_logo_high.png';
  $estate_link = 'index.php';
  if($latest_model == 0){
    $assmnt_link = 'javascript:noModelsSelected()';
  }else{
    $assmnt_link = 'assmnt_req.php?mid={$latest_model}';
  }
  $dashb_link = 'dashboard.php';
  $logout_link = 'Pages/logout.php';
}
if(file_exists('../Images/hit2gap_logo_high.png')){
  $image = '../Images/hit2gap_logo_high.png';
  $estate_link = '../index.php';
  if($latest_model == 0){
    $assmnt_link = 'javascript:noModelsSelected()';
  }else{
    $assmnt_link = '../assmnt_req.php?mid={$latest_model}';
  }
  $dashb_link = '../dashboard.php';
  $logout_link = '../Pages/logout.php';
}
$IP = $_SERVER['REMOTE_ADDR'];

echo("
<div id='header'>
  <div style='width:30%;float:left'>
    <table>
      <tr>
        <td>
          <a class='black-text XXXlarge-text'><strong>Marathon</strong></a>
        </td>
      </tr>
      <tr>
        <td>
          <a class='black-text medium-text'><strong>Reslience Testing Environment</strong></a>
        </td>
      </tr>
      <tr></tr>
    </table>
  </div>
  <div style='width:60%;float:left;margin-top:8px;' >
    <br>
    <table>
      <tr>
");
if($user_id != 0){
  echo("<td width='20%'><a href='{$estate_link}' class='grey-text small-text' style='float:right'>model selection</a></td>");
  echo("<td><a href='{$assmnt_link}' class='grey-text small-text' style='float:right'>assessment request</a></td>");
  echo("<td><a href='{$dashb_link}' class='grey-text small-text' style='float:right'>dashboard</a></td>");
}
echo("<td>
  &nbsp <!--<a href='http://www.esru.strath.ac.uk/liveservices/bpa/wikilink.html'  target='_blank'class='grey-text small-text'>further information</a>-->
  <a href='Images/page-under-construction.png'  class='grey-text small-text'>further information</a></td>");
if($user_id != 0){
  echo("<td><a href='{$logout_link}' class='grey-text small-text' style='float:right'>logout</a></td>");
}
echo("</tr>
    </table>
  </div>
  <div style='width:10%;float:right;margin-top:12px;'>
");
if($user_id != 0){
        // echo("<a class='grey-text medium-text'> - model selection</a>");
        $res = mysqli_query($con,"SELECT name FROM users WHERE id = {$user_id}");
        $row = mysqli_fetch_array($res);
        echo("<a class='grey-text large-text' style='float:right'>{$row[0]}</a><br>"); // TODO
        date_default_timezone_set("Europe/London");
        $dt = date("d/m/Y", time());
        echo("<a class='grey-text large-text' style='float:right'>{$dt}</a>"); // TODO
}
echo("
  </div>
<div style='width:100%;float:left'><hr></div>
</div>
");
?>
