-
Notifications
You must be signed in to change notification settings - Fork 0
/
produits.php
170 lines (144 loc) · 7.93 KB
/
produits.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
session_start();
if(isset($_SESSION["email"])){
?>
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="../assets/css/bootstrap.min.css" rel="stylesheet"/>
<link href="../assets/css/styles.css" rel="stylesheet"/>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Cabin:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700&display=swap" rel="stylesheet">
<title>PRODUITS</title>
</head>
<body>
<header>
<?php
require_once "menu.php";
?>
</header>
<?php
$user = "root";
$pass = "";
$hote = "localhost";
$dbname = "produits_1";
// CONNEXION A MYSQL
try {
$basedonnees = new PDO('mysql:host=localhost;dbname="produits_1"', $user, $pass);
// Débug de la connexion à MySql
$basedonnees->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "<p class='alert alert-success text-center p-3'>VOUS ETES CONNECTE A PDO MYSQL</p>";
}catch (PDOException $exception){
echo "Erreur de connexion à MySql " . $exception->getMessage();
}
// REQUETE SQL
// Vérifier la connexion à MySql
if($basedonnees == true){
// Ecrire ma requête sql stockée dans une variable
$nomtable = "livres";
$sql = "SELECT * FROM livres";
$produitsTableau = $basedonnees->query($sql);
}
?>
<div class="container-fluid">
<span class="mt-3 d-flex justify-content-around">
<h3 class="mt-3 text-warning">BIENVENUE <?= $_SESSION['email'] ?></h3>
<form method="post">
<button id="btn-deconnexion" name="btn-deconnexion" class="btn btn-danger">DECONNEXION</button>
</form>
</span>
</div>
<div class="container">
<div class="row">
<h4 class="text-warning text-center">NOS PRODUITS</h4>
<?php
foreach ($produitsTableau as $produit){
//Afficher la date de depot
$date_depot = new DateTime($produit['date_depot']);
?>
<div class="col-md-4 col-sm-12 p-3">
<div class="card p-3">
<div class="text-center">
<h4 class="card-title text-info">
<?= $produit['nom_produit'] ?>
</h4>
<a href="details_produit.php?id_produit=<?= $produit['id_produit'] ?>" class="btn btn-warning">
<img src="<?= $produit['image_produit'] ?>" alt="<?= $produit['nom_produit'] ?>" title="<?= $produit['nom_produit'] ?>" class="card-img-top img-fluid">
</a>
<div class="card-body">
<p class="card-text"><?= $produit['description_produit'] ?></p>
<p>PRIX : <?= $produit['prix_produit'] ?> €</p>
<p>Stock :
<?php
if($produit['stock_produit'] == true){
echo "OUI";
}else{
echo "NON";
}
?>
</p>
<p>Date de depot : <?= $date_depot->format("d/m/Y h:i:s") ?></p>
<a href="details_produit.php?id_produit=<?= $produit['id_produit'] ?>" class="btn btn-info">Detail produits</a>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#test<?= $produit['id_produit'] ?>">
popup details produit
</button>
<!-- Modal -->
<div class="modal fade" id="test<?= $produit['id_produit'] ?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Détail du produit <?= $produit['nom_produit'] ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<?= $produit['nom_produit'] ?>
<img src="<?= $produit['image_produit'] ?>" alt="<?= $produit['nom_produit'] ?>" title="<?= $produit['nom_produit'] ?>" class="card-img-top img-fluid">
<p class="card-text"><?= $produit['description_produit'] ?></p>
<p>PRIX : <?= $produit['prix_produit'] ?> €</p>
<p>Stock :
<?php
if($produit['stock_produit'] == true){
echo "OUI";
}else{
echo "NON";
}
?>
</p>
<p>Date de depot : <?= $date_depot->format("d/m/Y h:i:s") ?></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</body>
</html>
<?php
//Deconnexion et destruction de la session $_SESSION['email']
function deconnexion(){
var_dump("hello");
echo "elloo";
session_unset();
session_destroy();
header('Location: ../index.php');
}
//Click sur le bouton de deconnexion
if(isset($_POST['btn-deconnexion'])){
deconnexion();
}
}else{
echo "<a href='' class='btn btn-warning'>S'inscrire</a>";
header('Location: ../index.php');
}