<?php
// messagecode.php

require_once __DIR__ . "/connexion.php"; // doit créer $conn (conn)

$jeu = isset($_GET["jeu"]) ? (int)$_GET["jeu"] : 0;

$Reponse = $Question = $LeTitre = $Phrase = $Indice = $Limage = "";
$CompteDeID = 0;

if ($jeu > 0) {
  // 1) Récupère l'item correspondant à "jeu" (en ordre DESC)
  $sql = "SELECT ID, Reponse, Question, LeTitre, Phrase, Indice, Limage
          FROM CodeSecret
          ORDER BY ID DESC";
  if ($res = $conn->query($sql)) {
    $i = 0;
    while ($row = $res->fetch_assoc()) {
      $i++;
      if ($i === $jeu) {
        $Reponse  = (string)$row["Reponse"];
        $Question = (string)$row["Question"];
        $LeTitre  = (string)$row["LeTitre"];
        $Phrase   = (string)$row["Phrase"];
        $Indice   = (string)$row["Indice"];
        $Limage   = (string)$row["Limage"];
        break;
      }
    }
    $res->free();
  }

  // 2) Compte total
  $sqlCount = "SELECT COUNT(ID) AS CompteDeID FROM CodeSecret";
  if ($res2 = $conn->query($sqlCount)) {
    $row2 = $res2->fetch_assoc();
    $CompteDeID = $row2 ? (int)$row2["CompteDeID"] : 0;
    $res2->free();
  }
}

$titredepage = "message codé";

$conn->close();

require_once __DIR__ . "/haut.php";
?>

<script language="JavaScript" type="text/JavaScript">
function clicMenu(num) {
  var isIE = (document.all);
  var isNN6 = (!isIE) && (document.getElementById);

  var menu = null;
  if (isIE) menu = document.all['menu' + num];
  if (isNN6) menu = document.getElementById('menu' + num);

  if (menu && menu.style) {
    menu.style.display = (menu.style.display == "none") ? "" : "none";
  }
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
</script>

<br />
<p align="center" class="Style14">Message cod&eacute; <?php echo (int)$jeu; ?></p>
<div align="center"></div>

<?php if ($jeu > 0): ?>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" id="Jeu1">
  <tr>
    <td width="44" rowspan="3" valign="top" bgcolor="#FFFFFF"><p>&nbsp;</p></td>

    <td width="722" align="right" valign="top" bgcolor="#FFFFFF">
      <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
          <td align="right" valign="top">
            <div align="right">
              <span class="textebleu">
                <a href="#haut" onClick="window.print();return false" class="Style23">Imprime la page pour jouer !</a>
              </span>
              <span class="Style3"></span>
            </div>
          </td>
        </tr>

        <tr>
          <td valign="top" align="left">
            <br />
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="30%" valign="top">
                  <img border="0" src="Images/<?php echo htmlspecialchars($Limage, ENT_QUOTES, "UTF-8"); ?>" alt="">
                </td>
                <td width="70%" valign="top">
                  <?php echo $Question; ?><strong><br><br>
                  <?php echo $Phrase; ?><br>
                  </strong><br />
                  <a name="haut"></a><br /><br /><br />&nbsp;
                </td>
              </tr>
            </table>

            <div align="left">
              <table border="0" cellspacing="0" width="100%" bordercolorlight="#F2A41C" bordercolordark="#F2A41C"
                     height="134" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111">
                <tr>
                  <td width="25%" valign="top">
                    <p align="left"><b><br />
                      <a href="#haut" class="Style23" onClick="clicMenu('1')">Clique ici pour un indice...</a>
                    </b></p>

                    <table width="100%" border="0" cellspacing="0" cellpadding="0" id="menu1" style="display:none;">
                      <tr>
                        <td valign="top">
                          <span class="textebleu">Le code est-il trop difficile?</span>
                          <p><strong>Indice :</strong><br />
                            <?php echo $Indice; ?><br />
                          </p>
                          <br />
                        </td>
                      </tr>
                    </table>

                    <p align="left"><b>
                      <a href="#haut" class="Style23" onClick="clicMenu('2')">Clique ici pour vérifier ta réponse...</a>
                    </b></p>

                    <table width="100%" border="0" cellspacing="0" cellpadding="0" id="menu2" style="display:none;">
                      <tr>
                        <td valign="top">
                          <span class="textebleu"><strong>Solution :</strong></span><strong><br /><br /></strong>
                          <?php echo $Reponse; ?><br /><br />
                        </td>
                      </tr>
                    </table>

                  </td>
                </tr>
              </table>
            </div>
          </td>
        </tr>

        <tr><td valign="top" align="left" width="441"></td></tr>
        <tr><td valign="top" align="left" width="441"></td></tr>
        <tr><td valign="top" align="left" width="441"></td></tr>
        <tr><td valign="top" align="left" width="441"></td></tr>
      </table>

      <p align="right">
        <?php if (($jeu + 1) <= $CompteDeID): ?>
          <a href="messagecode.php?jeu=<?php echo (int)($jeu + 1); ?>" class="Style23"><strong>Jeu suivant &gt;&gt;</strong></a>
        <?php endif; ?>
        <br />
      </p>
    </td>

    <td width="29" valign="top" bgcolor="#FFFFFF">&nbsp;</td>
  </tr>

  <tr>
    <td valign="top" bgcolor="#FFFFFF"><br /></td>
    <td valign="top" bgcolor="#FFFFFF">&nbsp;</td>
  </tr>
</table>

<?php else: ?>

<table width="561" height="462" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="589" height="339" background="Images/Consigne.gif">
      <table width="382" height="312" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="382" height="312" valign="top">
            <div align="left">
              <p><strong><br />
                D&eacute;chiffrer des codes, pour moi, Marie-P d&eacute;tective, cela fait partie de mon quotidien.
                Si tu veux suivre mes traces, je t'offre la chance de t'exercer.<br /><br />
                Bon travail de d&eacute;tective!
              </strong></p>

              <p align="center"><strong><br />
                <a href="messagecode.php?jeu=1" class="Style23">JOUER</a>
              </strong></p>
            </div>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>

<?php endif; ?>

<p align="center"><a href="mysteres.php" class="Style23">Retour aux jeux</a></p>
<br />

<?php require_once __DIR__ . "/bas.php"; ?>
