<?php
  require 'php/connexion.php';
  require 'php/user-class.php';
  require 'php/additional-functions.php';
  require 'php/login-form.php';
  require 'php/forgot-form.php';
  require 'php/create-account-form.php';
  require 'php/user-menu.php';
  require 'php/edit-account-form.php';
  require 'php/form-p.php';
  require 'php/form-s.php';

  $browserLang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);

  if (isset($_COOKIE['user-lang']) && $_COOKIE['user-lang'] == 'en')
  {
    $lang = 'en';
    require 'php/lang-array-en.php';
    $swichLangTo = 'fr';
  }
  else if (isset($_COOKIE['user-lang']) && $_COOKIE['user-lang'] == 'fr')
  {
    $lang = 'fr';
    require 'php/lang-array.php';
    $swichLangTo = 'en';
  }
  else // If lang cookie not set
  {
    if ($browserLang == 'en')
    {
      $lang = 'en';
      setcookie('user-lang', $browserLang, 2147483647, "/");
      require 'php/lang-array-en.php';
      $swichLangTo = 'fr';
    }
    else if ($browserLang == 'fr')
    {
      $lang = 'fr';
      setcookie('user-lang', $browserLang, 2147483647, "/");
      require 'php/lang-array.php';
      $swichLangTo = 'en';
    }
  }

  session_start();

  $html = '';
?>
<!DOCTYPE html>
<html lang="<?php echo($lang); ?>">
<head>
  <title>ISO-ACTIF</title>
  <meta charset="utf8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.11.9/validator.min.js"></script>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  <script src='https://www.google.com/recaptcha/api.js'></script>
  <script src="js/block_ui.js"></script>
  <script src="js/scripts.js"></script>
  <link rel="stylesheet" href="css/styles.css">
</head>
<?php
  if (isset($_SESSION['usagerEcoleIsoActif']))
	 $html .= '<body onload="autoLogOutApres24minutes();">';
  else
	 $html .= '<body>';

  // Modal standard
  $html .= '<div id="modal-standard" class="modal fade" tabindex="-1" role="dialog">';
    $html .= '<div class="modal-dialog">';
      $html .= '<div class="modal-content">';
        $html .= '<div class="modal-header">';
          $html .= '<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
          $html .= '<h4 class="modal-title"></h4>';
        $html .= '</div>';
        $html .= '<div class="modal-body">';
          $html .= '<p class="modal-body-p"></p>';
        $html .= '</div>';
        $html .= '<div class="modal-footer">';
          $html .= '<button type="button" class="btn btn-default" data-dismiss="modal">' . $txt['close'] . '</button>';
        $html .= '</div>';
      $html .= '</div><!-- /.modal-content -->';
    $html .= '</div><!-- /.modal-dialog -->';
  $html .= '</div><!-- /.modal -->';

  // Main container (fixed width)
  $html .= '<div class="container">';

    // Header
    $html .= '<header>';
      $html .= '<div class="text-right">';
        $html .= '<a href="php/set-lang.php?lang=' . $swichLangTo . '"><span class="glyphicon glyphicon-globe" aria-hidden="true"></span> ' . strtoupper($swichLangTo) . '</a>';
      $html .= '</div>';
      $html .= '<img src="images/header.png" title="RSEQ Provincial" alt="RSEQ Provincial" class="img-responsive" style="margin: 0 auto;">';
      $html .= '<img src="images/title.png" alt="Formulaire d\'auto-évaluation" title="Formulaire d\'auto-évaluation" class="img-responsive">';
    $html .= '</header>';

    $html .= '<hr></hr>';

    if (isset($_SESSION['usagerEcoleIsoActif']))
    {
      $html .= '<div class="text-right bottom-buffer-10">';
      if (isset($_SESSION['usagerEcoleIsoActif']))
        $html .= '<strong>' . $txt['user'] . ' : </strong>' . $_SESSION['usagerEcoleIsoActif']->u_prenom . ' ' .  $_SESSION['usagerEcoleIsoActif']->u_nom . ' - <a href="php/logout.php">' . $txt['logout'] . '</a>';
      $html .= '</div>';

			if (isset($_GET['fmip']))
				$html .= afficherFormModifInfosCompte($_SESSION['usagerEcoleIsoActif']->u_id);
			else if (isset($_GET['formP']) && $_SESSION['usagerEcoleIsoActif']->u_form == 'P')
				$html .= afficherFormP();
			else if (isset($_GET['formS']) && $_SESSION['usagerEcoleIsoActif']->u_form == 'S')
				$html .= afficherFormS();
			else
				$html .= userMenu();
    }
    else
    {
      if (isset($_GET['oubli']))
        $html .= forgotForm();
      else if (isset($_GET['createAccount']))
        $html .= createAccountForm();
      else
        $html .= loginForm();
    }
    
    //  if($lang == 'fr') {
    //      $html .= '<p>Ce formulaire est actuellement fermé</p>';
    //  }else {
    //      $html .= '<p>The form is now closed</p>';
    //  }

    echo $html;
    $connexion->close();
  ?>
  <hr></hr>
  <footer class="row margin-bottom-20 text-center">
    <span class="footer-copyrights">&copy; <?php echo(date("Y")); ?> Réseau du sport étudiant du Québec - Tous droits réservés</span>
  </footer>
</div> <!-- End container -->
</body>
</html>
