-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparagraphe.php
132 lines (105 loc) · 5.51 KB
/
paragraphe.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php $page = "paragraphe";
include("entete.php");
$idMarquePage =0;
if ($_SESSION["connected"]) {
if(isset($_GET['id']) && isset($_SESSION['id_histoire_enCours'])){
$id_parag = htmlspecialchars($_GET['id']);
// Vérification de si il y a réellement un paragraphe, si oui on l'affiche, si non, on a un code erreur
$reqTest = "SELECT * from paragraphe WHERE id_histoire = ?";
$prepTest = $BDD -> prepare ($reqTest);
$prepTest -> execute(array($_SESSION['id_histoire_enCours']));
$tabTest = $prepTest -> fetchAll();
$test = false;
foreach ($tabTest as $key => $ligne){
if($ligne['parag_numero']==$_GET['id']){
$test = true;
}
}
if($test == false){
//Suppression du marque page si bug et renvoie code erreur
$reqRecup = "SELECT * FROM paragraphe WHERE id_histoire = ? AND parag_numero=?";
$prepRecup = $BDD -> prepare($reqRecup);
$prepRecup ->execute(array($_SESSION['id_histoire_enCours'],$_SESSION['ancien_parag']));
$ligneRecup = $prepRecup -> fetch();
$reqPB = "DELETE from marquePage WHERE id_user = ? AND id_paragraphe = ?";
$prepPB = $BDD -> prepare($reqPB);
$prepPB -> execute(array($_SESSION["id_user"],$ligneRecup['id']));
$_SESSION['erreur_histoire'] = true;
header('Location: histoire.php?id='.$_SESSION['id_histoire_enCours']);
exit;
}
// =============================================== //
$reqParag = "SELECT * FROM paragraphe WHERE id_histoire=? AND parag_numero=?";
$prepParag = $BDD -> prepare($reqParag);
$prepParag -> execute(array($_SESSION['id_histoire_enCours'],$id_parag));
$ligneParag = $prepParag ->fetch();
$verifExistence = "SELECT * FROM marquePage WHERE id_user = ?";
$prep = $BDD -> prepare($verifExistence);
$prep-> execute(array($_SESSION["id_user"]));
$tab = $prep->fetchAll();
$test = false;
//$n = $prep->rowCount();
foreach ($tab as $key => $ligneMarquePage ){
$verif = "SELECT * FROM paragraphe WHERE id=?";
$prep = $BDD -> prepare($verif);
$prep-> execute(array($ligneMarquePage["id_paragraphe"]));
$ligne = $prep->fetch();
if($ligne['id_histoire']==$_SESSION['id_histoire_enCours']){
$verifUser= "UPDATE marquePage SET id_paragraphe=? WHERE id_user=? AND id_paragraphe=? ";
$prepUser = $BDD -> prepare($verifUser);
$prepUser -> execute(array($ligneParag["id"],$_SESSION["id_user"],$ligneMarquePage['id_paragraphe']));
$idMarquePage = $ligneMarquePage['id'];
$test = true;
break;
}
}
if ($test == false){
$verifReq = "INSERT INTO `marquePage`(id_paragraphe,id_user) VALUES (?,?)";
$prepReq = $BDD -> prepare($verifReq);
$prepReq -> execute(array($ligneParag['id'],$_SESSION["id_user"]));
$idMarquePage = $BDD->lastInsertId();
}
$verif = "SELECT * FROM paragraphe WHERE parag_numero =? AND id_histoire = ?";
$prep = $BDD -> prepare($verif);
$prep-> execute(array($_GET['id'],$_SESSION['id_histoire_enCours']));
$ligne = $prep->fetch();
$_SESSION['ancien_parag']=$_GET['id'];
?>
<?php include("scripts/script_MAJ_Chemin.php"); ?>
<div class="text-center"><h2><?=$ligne["parag_nom"]?></h2></div>
<div class="container text-white">
<div class="row">
<?php if ($ligne['parag_image']!=NULL){?>
<div class="col-md-5 col-sm-7 ml-2 d-flex">
<img class="img-fluid histoireImage w-30 h-30" src="images/<?=$ligne['parag_image']?>" alt="<?=$ligne['parag_nom']?>" />
</div>
<?php }?>
<div class="col-md-7 col-sm-5 mr-2 pl-1">
<p class="p-3"><?=$ligne['parag_contenu'] ?> </p>
</div>
</div>
<div class="d-flex justify-content-around mt-4">
<?php
// Si on a indiqué qu'il y aurait une suite au paragraphe
if($ligne["suiteHistoire"] == "continuer"){
$requete = "SELECT * FROM lien WHERE id_parag_debut =? AND id_histoire=?";
$prep = $BDD -> prepare($requete);
$prep-> execute(array($_GET['id'], $_SESSION['id_histoire_enCours']));
$tab = $prep->fetchAll();
foreach ($tab as $key => $ligneLien) { ?>
<button onclick="location.href='paragraphe.php?id=<?=$ligneLien['id_parag_cible']?>'" type="button" class="btn btn-outline-info"><?=$ligneLien['lien_nomaction']?></button>
<?php
}}
else if($ligne["suiteHistoire"] == "victoire")
{?>
<button onclick="location.href='victoire.php?id=<?=$idMarquePage?>'" type="button" class="btn btn-outline-success">Continuer</button>
<?php }
else{ ?>
<button onclick="location.href='defaite.php?id=<?=$idMarquePage?>'" type="button" class="btn btn-outline-warning">Continuer</button>
<?php }
?>
</div>
</div>
<?php } ?>
<?php }
include("footer.php") ?>