<!DOCTYPE html>

<?php
// http://jt.ag/021YD7tPUixeQRfnSSItUyPcPdVWpS6tOhu
// http://jt.ag/?prf=02&out=1YD7tPUixeQRfnSSItUyPcPdVWpS6tOhu
// http://jt.ag/?prf=02&crp=j9SgNZQ6laBPQepqB-nk1rJoN-GThrTq
// http://jt.ag/?prf=02&cod=3mBSSF5PyMvUrU7-KS8j
// http://jt.ag/?prf=02&bin=110111100110000001010010010010000101111001001111110010001100101111010100101011010100111011111110001010010010111100100011
// http://jt.ag/?prf=02&val=13-14-6_0-5-2_4-8-5_14-4-15_12-8-12_11-13-4_10-13-4_14-15-14_2-9-2_15-2-3

$srv = $_SERVER["SERVER_NAME"];

$prf = $_GET["prf"]; // Prefixe
if (!$prf)
    $prf = "05";

//recupere les proprietes de ce prf
//$fichierPropriete = file_get_contents("json/sURLset.json");
$fichierPropriete = file_get_contents("json/sURLset.json");
$tab_propriete = json_decode($fichierPropriete, true);


//    $propriete = $tab_propriete["serveur"]["jtag"]["prefixe"][$tabGET["prf"]];
$lesProprietes = $tab_propriete["sURLSet"]["sURL"];

foreach ($lesProprietes as $value) {
    if ($value["key"]) {
        if ($value["key"]["dom"] === $srv && $value["key"]["prf"] === $prf) { //cle complete
            $propriete = $value;

            if ($propriete["drw"]["typ_drw"]) {
                $javascript = $propriete["drw"]["typ_drw"];
            }
            if ($propriete["drw"]["rdr_drw"]) {
                $renderer = $propriete["drw"]["rdr_drw"];
            }
            if ($propriete["drw"]["alg_drw"]) {
                $type = $propriete["drw"]["alg_drw"];
            }
            if ($propriete["drw"]["rot_drw"]) {
                $rotation = $propriete["drw"]["rot_drw"];
            }

            break;
        } else if ($value["key"]["dom"] === $srv) { //cle incomplete, donnees generales pour ce serveur
            if ($propriete["drw"]["typ_drw"]) {
                $javascript = $propriete["drw"]["typ_drw"];
            }
            if ($propriete["drw"]["rdr_drw"]) {
                $renderer = $propriete["drw"]["rdr_drw"];
            }
            if ($propriete["drw"]["alg_drw"]) {
                $type = $propriete["drw"]["alg_drw"];
            }
            if ($propriete["drw"]["rot_drw"]) {
                $rotation = $propriete["drw"]["rot_drw"];
            }
        }
    }
}
//aucune cle ou donnees non precisees
if (!$javascript) {
    $javascript = $lesProprietes[0]["drw"]["typ_drw"];
}
if (!$renderer) {
    $renderer = $lesProprietes[0]["drw"]["rdr_drw"];
}
if (!$type) {
    $type = $lesProprietes[0]["drw"]["alg_drw"];
}
if (!$rotation) {
    $rotation = $lesProprietes[0]["drw"]["rot_drw"];
}

if($_GET['rot']) {
    $rotation = $_GET['rot'];
}

//print_r($lesProprietes[0]["drw"]);
//exit();

?>
<html lang="en">
    <!-- based on canvas_geometry_shapes.html -->
    <head>
        <title>(c)mobiLead - Noodle </title>
        <meta charset="utf-8" name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"></meta>

        <!-- Bootstrap -->
        <link type="text/css" rel="stylesheet" media="screen" href="js_ext/bower_components/bootstrap/dist/css/bootstrap.min.css" ></link>
        <link type="text/css" rel="stylesheet" media="screen" href="js_ext/bower_components/bootstrap/dist/css/bootstrap-switch.min.css" ></link>

        <!-- indexM.css -->
        <link type="text/css" rel="stylesheet" media="screen" href="css/indexM.css" rel="stylesheet" media="screen" />

        <!--jquery et bootstrap-->
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <script type="text/javascript" src="js_ext/bower_components/bootstrap/js/collapse.js"></script>
        <script type="text/javascript" src="js_ext/bower_components/bootstrap/js/dropdown.js"></script>
        <script type="text/javascript" src="js_ext/bower_components/bootstrap/js/bootstrap-switch.min.js"></script>

        <!--pour enregistrer l'image en svg-->
        <script type="text/javascript" src="./js/ext/libs/base64.js"></script>	
        <script type="text/javascript" src="./js/ext/libs/svgtodataurl.js"></script>

        <!-- pour generer toutes les infos a afficher et dessiner -->
        <script type="text/javascript" src="js/paramJSON.js"></script>
        
        <!--crypto et changement de base-->
        <script type="text/javascript" src="js/encode/aes.js"></script>
        <script type="text/javascript" src="js/encode/pad_radix.js"></script>  
        <script type="text/javascript" src="js/encode/changeBase.js"></script>
        <script type="text/javascript" src="js/encode/crypto.js"></script>
        <script type="text/javascript" src="js/encode/mobiLead.js"></script>             

    </head>
    <body>

        <?php // print_r($lesProprietes[0]['drw']) ?>
        
        <!--Le menu responsif-->
        <nav class="navbar navbar-default" id="navbar">
            <div class="container-fluid">



                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">


                    <?php
                    if ($javascript == "threeNoodle2D" || $javascript == "threeNoodleGyr") { //bouton pour tourner si 3D
                        echo
                        '<!--menu deroulant gauche-->
                    <div class="nav navbar-nav pull-left">
                        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                    </div>
                    <!--fin menu deroulant gauche-->

                    <div class="collapse navbar-collapse" id="navbar-collapse-1">
                        <ul class="nav navbar-nav pull-left">
                            <li id="menuGauche" class="dropdown">';

                        echo '<button class="btn btn-danger" onclick="turn(180, \'true\');">Red</button>';
                        echo '<button class="btn btn-primary" onclick="turn(0, \'true\');">Blue</button>';
                        echo '<button class="btn btn-success" onclick="showAngle()">Angle</button>';


                        //bouton enregistrer svg
                        if ($renderer == "svg" || $_GET["rdr"] === "svg") {
                            echo '<button class="btn btn-info" onclick="encode_svg()">SVG</button>';
                        }
//                        bouton on/off tourner
                        if ($rotation === "true") {
                            echo '<input type="checkbox" autocomplete="off" name="turnOnOff" checked>';
                        } else {
                            echo '<input type="checkbox" autocomplete="off" name="turnOnOff">';
                        }
                        echo '</li>
                        </ul>
                    </div><!-- /.navbar-collapse 1 -->';
                    } else {
                        //bouton enregitstrer svg
                        echo '<ul class="nav navbar-nav pull-left">
                            <li id="menuGauche">';
                        echo '<button class="btn btn-info" onclick="encode_svg()">SVG</button>';
                        echo '</ul></li>';
                    }
                    ?>

                    <!--<div id="info"> INFO </div>-->

                    <!--menu deroulant droit-->
                    <div class="nav navbar-nav pull-right">
                        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-2">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                    </div>
                    <!--fin menu deroulant droit-->

                </div>


                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="navbar-collapse-2">
                    <ul class="nav navbar-nav navbar-right">
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Liens <span class="caret"></span></a>
                            <ul id="menuLiens" class="dropdown-menu" role="menu">
                                <!--les liens-->
                            </ul>
                        </li>
                    </ul>

                    <ul class="nav navbar-nav navbar-right">
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">QR code<span class="caret"></span></a>
                            <ul id="menuQR" class="dropdown-menu" role="menu">
                                <!--Le QR-->
                            </ul>
                        </li>
                    </ul>
                </div><!-- /.navbar-collapse 2 -->

            </div><!-- /.container-fluid -->
        </nav>

        <!--fin du menu-->

        <!--affichage angles debug gyroscope-->
        <div id="angleDelta" class="row">
            <h3><div id = "testGyr" class="col-xs-4 col-md-4"></div></h3>
            <h3><div id = "testGyr2" class="col-xs-4 col-md-4"></div></h3>
            <h3><div id = "testGyrDelta" class="col-xs-4 col-md-4"></div></h3>
        </div>
        <!--fin angles debug gyroscope-->


        <div class="container-fluid" id="centre">

            <!--La div container de la forme three js-->
            <div class="container-fluid" id="noodle"></div>
            <!--<div id="noodle"></div>-->

        </div>

        <!--les scripts necessaires a la generation three js-->
        <!--<script src="js/build/three.min.js"></script>-->
        <script src="js/ext/build/three.js"></script>

        <script src="js/ext/renderers/Projector.js"></script>

        <script src="js/getParamNoodle2.js"></script>
        <!--pour verifier si webgl est supporte-->
        <script src="js/ext/renderers/Detector.js"></script>

<!--<script src="bubble.js"></script>-->

        <?php
//                            if ($premierChar == 'a' || $premierChar == 'b') {
//                                echo '<script src="js/threeNoodle2D.js"></script>';
//                            } else if ($premierChar == 'c' || $premierChar == 'd') {
//                                echo '<script src="js/svgNoodle.js"></script>';
//                            } else {
//                                echo '<script src="js/threeNoodleGyr.js"></script>';
//                            }
        $src = "js/" . $javascript . ".js";
        echo '<script src="' . $src . '"></script>';

//        if ($javascript === "threeNoodleGyr" || $javascript === "threeNoodle2D") {
//            if ($type === "tube" || $type === "superTube" || $type === "line" || $type === "metalTube") {
//                echo '<script src="js/draw/noodle.js"></script>';
//            }
//            if ($type === "superTube" || $type === "bubble") {
//                echo '<script src="js/draw/skyBox.js"></script>';
//            }
//        } else if ($javascript === "svgNoodle") {
//            echo '<script src="js/draw/scale.js"></script>';
//            echo '<script src="js/draw/path.js"></script>';
//        }
//
//        $src = "js/draw/" . $type . ".js";
//        echo '<script src="' . $src . '"></script>';

//        switch ($renderer) {
//            case "svg":
//                echo '<script src="js/renderers/SVGRenderer.js"></script>';
//                break;
//            case "web":
//                echo '<script src="js/renderers/WebGLRenderer.js"></script>';
//                break;
//            case "canvas":
//                echo '<script src="js/renderers/CanvasRenderer.js"></script>';
//                break;
//        }
        
        echo '<script src="js/ext/renderers/SVGRenderer.js"></script>';
        echo '<script src="js/ext/renderers/WebGLRenderer.js"></script>';
        echo '<script src="js/ext/renderers/CanvasRenderer.js"></script>';

//        switch ($type) {
//            case 'line':
//            case 'tube':
//            case 'superTube':
//                echo '<script src="js/ext/curves/NURBSCurve.js"></script>';
//                echo '<script src="js/ext/curves/NURBSUtils.js"></script>';
//                break;
//        }
        ?>

        <script>
            var options = {
                onColor: 'primary',
                offColor: 'danger',
                animate: true,
                size: 'normal',
                handleWidth: 40,
                onSwitchChange: function (event, state) {
                    setTurn();
                }
            };
            //lance le bouton on off
            $("[name='turnOnOff']").bootstrapSwitch(options);

            //ouvrir le menu avec les boutons par defaut
            //                                    function OpenDropDown() {
            //                                        $('#menuGauche').dropdown('toggle');
            //                                    }
            //
            //                                    window.setTimeout(OpenDropDown, 2);


            // Les parametres recus en GET 
            var tabGET;
<?php
$tabGET['out'] = $_GET["out"];
$tabGET['crp'] = $_GET["crp"];
$tabGET['cod'] = $_GET["cod"];
$tabGET['bin'] = $_GET["bin"];
$tabGET['val'] = $_GET["val"];
$tabGET['prf'] = $prf;
$tabGET['srv'] = $srv;
$tabGET['index'] = "indexM";

$tabGET['ang'] = $_GET["ang"]; // Angle
$tabGET['gyr'] = $_GET["gyr"]; // on/off Gyroscope
$tabGET['rgb'] = $_GET["rgb"]; // Surchage rgb
$tabGET['bck'] = $_GET["bck"]; // Surchage couleur de fond
$tabGET['sav'] = $_GET['sav'];//enregistrer le svg
$tabGET['dir'] = $_GET['dir'];//si on veut enregistrer dans un dossier particulier
$tabGET['nom'] = $_GET['nom'];//si on veut enregistrer avec un nom particulier
// DEBUG
$tabGET['rotation'] = $_GET["rot"]; // on/off Rotation
$tabGET['axe'] = $_GET["axe"]; // on/off Axe coordonnées
$tabGET['sphere'] = $_GET["sph"]; // on/off  Sphères B/R
$tabGET['rdr'] = $_GET["rdr"];

$tabGET = json_encode($tabGET);

//print_r("tabGET : ".$tabGET);
//exit();

echo "tabGET='" . $tabGET . "';";
//echo 'prf="' . $prf . '";';
//echo 'srv="' . $srv . '";';
?>

            /*
             * Recupere les liens crp, cod, bin etc. et dots.
             * Construit Noodle et le QR et les affiche
             */
            getParam(tabGET);

        </script>

    </body>
</html>