<?php
    require_once __DIR__ . '/../../server/server/config/boot_global.php';
    require_once __DIR__ . '/../../server/server/config/boot_local.php';

    $version = time();//Francis_Utils_Config::get( 'version' );
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-title" content="ProBuddy">
    <title>ProBuddy &copy; TBuddy UG (haftungsbeschränkt)</title>

    <!-- Google Analytics -->
    <script>
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

        ga('create', 'UA-139730172-1', 'auto');
        ga('set', 'anonymizeIp', true);
        ga('send', 'pageview');
    </script>
    <!-- End Google Analytics -->

    <link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
    <link rel="icon" type="image/png" sizes="192x192"  href="/android-icon-192x192.png">
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
    <link rel="manifest" href="/manifest.json">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
    <meta name="theme-color" content="#ffffff">

    <link href="https://fonts.googleapis.com/css?family=Crimson+Text:400,400i,600|Montserrat:200,300,400" rel="stylesheet">
    <link rel="stylesheet"
          href="https://use.fontawesome.com/releases/v5.5.0/css/all.css"
          integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU"
          crossorigin="anonymous">
    <link href="js/libs/chartist/chartist.min.css?<?php echo $version ?>" rel="stylesheet" />

    <link href="css/bootstrap.min.css?<?php echo $version ?>" rel="stylesheet" />
    <link href="css/js-offcanvas.css?<?php echo $version ?>" rel="stylesheet" />
    <link href="css/helpers.css?<?php echo $version ?>" rel="stylesheet" />
    <link href="css/style.css?<?php echo $version ?>" rel="stylesheet" />
    <link href="css/bootstrap-clockpicker.min.css?<?php echo $version ?>" rel="stylesheet" />
    <link href="css/notiny.css?<?php echo $version ?>" rel="stylesheet" />

    <!--
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons<?php echo $version ?>" rel="stylesheet" />
    -->

    <link href="css/app.css?<?php echo $version ?>" rel="stylesheet" />

    <link rel="stylesheet" href="//cdn.materialdesignicons.com/3.3.92/css/materialdesignicons.min.css">
</head>
<body>
<!-- loader -->
<div id="pb_loader" class="show fullscreen">
    <div class="row h-100 justify-content-center align-items-center">
        <!--
        <img src="./img-system/logo-blue.png" style="margin-top: 2px;width: 32px; height:32px"/>
        -->
        <div>
            <div class="text-center">
                <img src="./img-system/pb-icon-big.png"
                     style="width: 72px" />
                <div style="padding: 32px;">
                    <div data-id="loader-quote" style=""></div>
                    <div data-id="loader-quote-author" style="font-style: italic;font-size: smaller"></div>
                </div>
            </div>
            <div class="pusher"></div>
        </div>
    </div>
    <!--
    <svg class="circular" width="48px" height="48px"><circle class="path-bg" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke="#eeeeee"/><circle class="path" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke-miterlimit="10" stroke="#1d82ff"/></svg>
    -->
</div>

<!-- Google Analytics -->
<script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
</script>
<!-- End Google Analytics -->

<!-- start: Templates -->
<?php

// Include all templates
$pagesPath = __DIR__ . '/tmpl/';

// Create recursive dir iterator which skips dot folders
$dir = new RecursiveDirectoryIterator( $pagesPath, FilesystemIterator::SKIP_DOTS );

// Flatten the recursive iterator, folders come before their files
$it  = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::SELF_FIRST );

// Maximum depth is 1 level deeper than the base folder
$it->setMaxDepth( 1 );

// Write javascript includes
foreach ( $it as $fileinfo )
{

    if ( $fileinfo->isFile() )
    {
        echo '<script type="application/x-template" id="tpl-' . $fileinfo->getBasename( ".html" ) . '">' . "\n";
        echo file_get_contents( $pagesPath . $fileinfo->getFilename() ) . "\n";
        echo '</script>' . "\n";
    }
}

?>

<!-- end: Templates -->

<!-- start: JS libs -->

<script src="js/libs/jquery/jquery-3.3.1.min.js?<?php echo $version ?>" type="text/javascript"></script>
<script src="js/libs/bootstrap/bootstrap.bundle.min.js?<?php echo $version ?>" type="text/javascript"></script>
<script src="js/libs/micro-template/micro-template.js?<?php echo $version ?>" type="text/javascript"></script>
<script src="js/libs/rlite/Rlite.min.js?<?php echo $version ?>" type="text/javascript"></script>
<script src="js/libs/shotgun/shotgun.min.js?<?php echo $version ?>" type="text/javascript"></script>
<script src="js/libs/store-js/store-legacy.min.js?<?php echo $version ?>" type="text/javascript"></script>
<script src="js/libs/js-offcanvas/js-offcanvas.pkgd.min.js?<?php echo $version ?>" type="text/javascript"></script>
<script src="js/libs/chartist/chartist.min.js?<?php echo $version ?>" type="text/javascript"></script>
<script src="js/libs/momentjs/moment-with-locales.js?<?php echo $version ?>" type="text/javascript"></script>
<script src="js/libs/notiny/notiny.min.js?<?php echo $version ?>" type="text/javascript"></script>
<!--
<script src="js/libs/notify/notify.js?<?php echo $version ?>" type="text/javascript"></script>
-->
<script src="js/libs/clockpicker/bootstrap-clockpicker.min.js?<?php echo $version ?>" type="text/javascript"></script>
<script src="js/libs/alloycrop/transform.js?<?php echo $version ?>" type="text/javascript"></script>
<script src="js/libs/alloycrop/alloy-finger.js?<?php echo $version ?>" type="text/javascript"></script>
<script src="js/libs/alloycrop/alloy-crop.js?<?php echo $version ?>" type="text/javascript"></script>
<script src="js/libs/zipcelx/zipcelx.js?<?php echo $version ?>" type="text/javascript"></script>
<script src="js/libs/autocomplete/jquery.autocomplete.min.js?<?php echo $version ?>" type="text/javascript"></script>
<!--
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.js?<?php echo $version ?>" type="text/javascript"></script>
-->
<!-- end: JS libs -->

<!-- start: app JS -->

<?php

// Custom code
$incs = array( 'js/app/core', 'js/app/gui', 'js/app/model', 'js/app/state', 'js/app/util' );
foreach( $incs as $jspath )
{
    if ( !is_dir( $jspath ) )
    {
        continue;
    }

    // Create recursive dir iterator which skips dot folders
    $dir = new RecursiveDirectoryIterator( __DIR__ . '/' . $jspath,
        FilesystemIterator::SKIP_DOTS);

    // Flatten the recursive iterator, folders come before their files
    $it  = new RecursiveIteratorIterator( $dir,
        RecursiveIteratorIterator::SELF_FIRST);

    // Maximum depth is 1 level deeper than the base folder
    $it->setMaxDepth(0);

    // Get javascript includes
    foreach ($it as $fileinfo)
    {
        if ( $fileinfo->isFile() )
        {
            echo '<script type="text/javascript" src="' . $jspath . '/' . $fileinfo->getFilename() . '?' . $version . '"></script>' . "\n";
        }
    }
}

?>

<?php if ( isset( $_GET[ 'fromCordova' ] ) ):   ?>

    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript">
        function onDeviceReady()
        {
            window.isNativeMobile = true;
            app.core.App.run( { rpc : 'api.php' } );
        }
        document.addEventListener('deviceready', onDeviceReady.bind(this), false);
    </script>

<?php else: ?>

    <script type="text/javascript">
        $(document).ready(function()
        {
            window.isNativeMobile = false;
            app.core.App.run( { rpc : 'api.php' } );
        });
    </script>

<?php endif; ?>

<!-- end: app JS -->
</body>
</html>