forked from rebillar/site-accueil-insa
126 lines
No EOL
3.5 KiB
PHP
126 lines
No EOL
3.5 KiB
PHP
<?php
|
|
ob_start(); // Start reading html
|
|
|
|
include "script/db.php";
|
|
|
|
$end = false;
|
|
|
|
if(isset($_POST['send'])) {
|
|
$req = $db->query('SELECT id, name FROM mot_croise');
|
|
while($r = $req->fetch()) {
|
|
$input[$r['id']] = htmlspecialchars($_POST["input".$r['id']]);
|
|
if(htmlspecialchars($_POST["input".$r['id']]) == $r['name']) {
|
|
$color[$r['id']] = "green";
|
|
} elseif(!empty($_POST["input".$r['id']])) {
|
|
$color[$r['id']] = "red";
|
|
} else {
|
|
$color[$r['id']] = "grey";
|
|
}
|
|
}
|
|
|
|
$end = true;
|
|
$i = 1;
|
|
|
|
while($end AND $i <= count($color)) {
|
|
if($color[$i] != "green") {
|
|
$end = false;
|
|
}
|
|
$i++;
|
|
}
|
|
|
|
|
|
$req = $db->prepare("SELECT * FROM scores WHERE texte = ?");
|
|
$req->execute(array("Mots croises"));
|
|
$req_exist = $req->rowCount();
|
|
if($req_exist == 0) {
|
|
if($end) {
|
|
if(isset($_POST['team']) AND !empty($_POST['team'])) {
|
|
|
|
$team = htmlspecialchars($_POST['team']);
|
|
if($team == "pkpeach") {
|
|
$team = 0;
|
|
} elseif($team == "boomario") {
|
|
$team = 1;
|
|
} else {
|
|
header('Refresh: 0');
|
|
}
|
|
|
|
$req = $db->prepare("INSERT INTO scores(texte, points, team) VALUES(?, ?, ?)");
|
|
$req->execute(array("Mots croises","500", $team));
|
|
|
|
?><script type="text/javascript">alert("Félicitation, vous avez fait gagner 500points à votre équipe");</script><?php
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<main>
|
|
<div class="box-jaune">
|
|
<span class="corners corners-top"></span>
|
|
<span class="corners corners-bottom"></span>
|
|
|
|
<div class="title">Mots croisés pour vous occuper pendant les vacances</div>
|
|
|
|
<span class="circles circles-top"></span>
|
|
<span class="circles circles-bottom"></span>
|
|
</div><br>
|
|
<section>
|
|
<img src="assets/img/mot_croise.svg" class="mot_croise">
|
|
</section>
|
|
<section>
|
|
<form method="POST">
|
|
Tout les mots doivent être indiqués en minuscule, sans accent, sans espaces ni caractères spéciaux.<br><br>
|
|
<?php
|
|
$req = $db->query('SELECT id FROM mot_croise');
|
|
|
|
while($r = $req->fetch()) {
|
|
?>
|
|
<input type="text" name="input<?= $r['id'] ?>" placeholder="Mot <?= $r['id'] ?>" value="<?php if(isset($input[$r['id']])) { echo $input[$r['id']]; } ?>" style="border: <?= $color[$r['id']] ?>;" class="input">
|
|
<?php
|
|
}
|
|
|
|
|
|
$req = $db->prepare("SELECT team FROM scores WHERE texte = ?");
|
|
$req->execute(array("Mots croises"));
|
|
$req_exist = $req->rowCount();
|
|
$team_gg = $req -> fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if($end AND $req_exist == 0) {
|
|
?> <br>
|
|
Franchement GG à vous, choisissez votre équipe ci-dessous pour lui faire remporter les points :<br>
|
|
<select name="team" class="input">
|
|
<option value="">Choisissez votre équipe</option>
|
|
<option value="pkpeach">PKpeach</option>
|
|
<option value="boomario">Boomario</option>
|
|
</select>
|
|
<?php
|
|
}
|
|
?><br><br>
|
|
<input type="submit" name="send" value="Envoyer" class="submit">
|
|
|
|
<font color="red">
|
|
<?php if(isset($error)) {
|
|
echo $error;
|
|
} ?>
|
|
</font>
|
|
|
|
<br><br>
|
|
|
|
<?php
|
|
if($req_exist == 0) {
|
|
echo "Aucune des deux équipes n'a réussit à trouver tout les mots";
|
|
} else {
|
|
if($team_gg[0]['team'] == 0) {
|
|
echo "Pkpeach à déjà tout trouvé";
|
|
} else {
|
|
echo "Boomario à déjà tout trouvé";
|
|
}
|
|
}
|
|
?>
|
|
</form>
|
|
</section>
|
|
</main>
|
|
<?php
|
|
$infopage = ["", "Cahier de vacances", ob_get_clean(), "", "vacances"]; //relativepath, pagetitle, pagecontent, pagescript | cf structure/template.php ligne 2 à 6
|
|
include("structure/template.php");
|
|
?>
|