<?php

date_default_timezone_set('Europe/Berlin');
function stripp($x){return preg_replace('/pages\/(.*)\.inc/', '${1}', $x);};
function inc($q) { return "./pages/".$q.".inc"; }
$default_page = 'Home';
$globber = glob("pages/*inc");
$pages = array_map("stripp", glob("pages/*inc"));
$products = array_map("stripp", glob("pages/products/*inc"));
$q = array_key_exists('q', $_REQUEST) ? $_REQUEST['q'] : $default_page; 
//$fp = fopen('/tmp/guzi.log', 'a'); fwrite($fp, "file_exists(inc($q)): ".file_exists(inc($q))."\n"); fclose($fp);

function is_collection_page($page, $coll) {
  $res = in_array($page, $coll);
  $fp = fopen('/tmp/guzi.log', 'a'); fwrite($fp, "in_array(".$page.", ".print_r($coll,1)."): ".$res."\n"); fclose($fp);
  return $res;
}

if ( !file_exists(inc($q)) ) { $q = $default_page; } 
$master_site = "zinias.nl";

function realIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="/libs/maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<!--
    <link rel="stylesheet" href="/libs/fontawesome.io/assets/css/site.css"> 
    <link rel="stylesheet" href="/libs/fontawesome.io/assets/css/pygments.css">
-->
    <link rel="stylesheet" href="/libs/fontawesome.io/assets/font-awesome/css/font-awesome.css"> 
    <link rel="stylesheet" href="css/zinias.css">

    <?php if ( $_SERVER['HTTP_HOST'] != $master_site ) { ?>
      <link rel="canonical" href="//<?php echo $master_site . $_SERVER['REQUEST_URI'] ?>"/>        
    <?php } ?>

  </head>
  </body>
    <div class="container">
      <div class="header clearfix">
        <nav>
          <ul class="nav nav-pills pull-right">
            <?php 
              foreach($pages as $page) { 
                $active = ( $page == $q ? "class='active'" : '' );
                if ( !$active && $page == 'Products' && is_collection_page($q, $products) ) $active = "class='active'";
                echo "<li role='presentation' $active><a href='/$page'>$page</a></li>";
              }
            ?>
          </ul>
        </nav>
        <h3 class="text-muted">Zinias B.V.</h3>
      </div>

      <div class="jumbotron">
        <?php require(inc($q)); ?>
      </div>

      <footer class="footer">
        <p>&copy; Zinias B.V. 2000 - 2017</p>
      </footer>

    </div> <!-- /container -->


    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug 
      <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
    -->

    <?php  if ( false ) { ?>
      <pre><?php echo print_r($_REQUEST,true); ?></pre>
      <pre><?php echo print_r($_SERVER,true); ?></pre>
    <?php } ?>
  </body>

</html>
