<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

require 'functions.php';

$cursos = listarCursos();
$alunos = listarAlunos($_GET['curso']);
$exercicios = listarExercicios($_GET['curso']);

$curso_selecionado = $_GET['curso'];
$aluno_selecionado = $_GET['aluno'];
$exercicio_selecionado = $_GET['exercicio'];

$logsAlunoString = pegarLogsDoAlunoComoString($curso_selecionado, $aluno_selecionado, $exercicio_selecionado);

$arquivo_ivph_aluno = pegarArquivoMaisRecente($curso_selecionado, $aluno_selecionado, $exercicio_selecionado);

?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>ivprog_log_analysis</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="dist/style.css">
  <link href="css/bootstrap.min.css" rel="stylesheet" />
    <link href="css/style.css" rel="stylesheet" />
  <style>
    #line-heatmap-canvas { width:1500px; height:1500px; position:absolute;}
    #line-heatmap-view { width:1500px; height:1500px; position:absolute;}
    #line-heatmap-tooltip { position:absolute; left:0; top:0; background:rgba(0,0,0,.8); color:white; font-size:14px; padding:5px; line-height:18px; display:none; z-index:10}
  </style>
  <title>Test</title>
  <script src="dist/line_heatmap.js"></script>
  <style type="text/css">
  </style>
</head>
<body>

	<nav class="navbar navbar-expand-md navbar-dark fixed-top" style="background-color: #03396c;">
      <b><a class="navbar-brand" href="./">ivprog_log_analysis - Ambiente de análise dos logs do iVProgH</a></b>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarsExampleDefault">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item active">
            <a class="nav-link" href="./" title=""></a>
          </li>
          </ul>
      </div>
    </nav>

    <main role="main">
      <div class="jumbotron ivprogh-desc">
        <div class="container">
          <?= instrucoes() ?>
        </div>
      </div>


      <div class="container ivprog-container" style="padding: 3em; margin-top: 3em;">
        <form action="process.php" method="get" novalidate>

          <div class="form-group row">
            <label for="inputname" class="col-sm-2 col-form-label">Curso:</label>
            <div class="col-sm-10">
              <select class="form-control" id="inputname" name="curso">
                <?php
                  for ($i = 0; $i < count($cursos); $i++) {
                    echo "<option" . ($cursos[$i] == $_GET['curso']?" selected":"") . ">" . $cursos[$i] . "</option>";
                  }
                ?>
              </select>
            </div>
          </div>

          <div class="form-group row">
            <label for="inputaluno" class="col-sm-2 col-form-label">Aluno:</label>
            <div class="col-sm-10">
              <select class="form-control" id="inputaluno" name="aluno">
                <option>Todos</option>
                <?php
                  foreach ($alunos as $aluno) {
                    echo "<option value='$aluno' ". ($aluno == $_GET['aluno']?" selected":"") .">"
                          . str_replace('-', ' ', $aluno)
                          . "</option>";
                  }
                ?>
              </select>
            </div>
        </div>

      <div class="form-group row">
            <label for="inputexercicio" class="col-sm-2 col-form-label">Exercício:</label>
            <div class="col-sm-10">
              <select class="form-control" id="inputexercicio" name="exercicio">
                <?php
<<<<<<< HEAD

                  foreach ($exercicios as $exercicio) {
                    echo "<option value='$exercicio' " . ($exercicio == $_GET['exercicio']?" selected":"") . ">"
                          . str_replace('-', ' ', $exercicio)
                          . "</option>";
=======
                  for ($i = 0; $i < count($exercicios); $i++) {
                    echo "<option value='".$exercicios[$i][1]."'" . ($exercicios[$i][1] == $_GET['exercicio']?" selected":"") . ">" . str_replace('_', ' ', $exercicios[$i][0]) . "</option>";
>>>>>>> master
                  }

                ?>
              </select>
            </div>
        </div>

      <div class="form-group row">
          <div class="offset-sm-2 col-sm-10">
            <button type="button" class="btn btn-secondary" onclick="window.history.back();">Voltar</button>
            <button type="submit" class="btn btn-primary">Continuar</button>
            <span class="reported" style="color: green; font-size: 120%;"></span>
            <span class="error" style="color: red; font-size: 120%;"></span>
          </div>
        </div>

        </form>
      </div>

      <div>
        
      </div>
    </main>
    <script src="./js/jquery.min.js"></script>
    <script src="./js/bootstrap.bundle.min.js"></script>

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/octicons/3.5.0/octicons.min.css">


  <div>
    <div id="hea">
    </div>
 

	  <?php
	  if (empty($logsAlunoString)) {
	  	echo "<center><h4>O aluno não enviou resposta para o exercício selecionado!</h4></center>";
	  } else {

	  ?>
  
	  <script>
	    line_heatmap.Container.init('hea','<?= $logsAlunoString ?>', true);
	  </script>

	  <iframe frameborder="0" name="iLM" src="ivprog/index.html?1=1&iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=../temp/<?=$curso_selecionado.'/'.$arquivo_ivph_aluno ?>&iLM_PARAM_SendAnswer=false&iLM_PARAM_ServerToGetAnswerURL=&lang=pt" style='width: 800px; height: 1500px;' >
	</iframe>

  <?php
	}
  ?>
 </div>


</body>
</html>