-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticipation.php
274 lines (245 loc) · 12.6 KB
/
participation.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?php
// Include necessary files and libraries
require_once 'class/connection.php';
require_once 'class/product.php';
require_once __DIR__ . '/vendor/autoload.php';
// Create a new Connection object
$connection = new Connection();
// Retrieve data from the database using Connection object's methods
$categories = $connection->getCategories();
$colors = $connection->getColors();
$matters = $connection->getMatters();
$states = $connection->getStates();
$sizes = $connection->getSizes();
// Handle form submission and insert product into the database
if ($_POST) :
// Generate a unique identifier for the product
$sku = uniqid();
// Create a new Product object with data submitted through the form
$product = new Product(
$_POST['lastname'],
$_POST['firstname'],
$_POST['email'],
$_POST['phone'],
$_POST['title'],
$_POST['description'],
'' . $sku .'-' . $_FILES['front_pic']['name'],
'' . $sku .'-' . $_FILES['back_pic']['name'],
'' . $sku .'-' . $_FILES['side_pic']['name'],
$_POST['category'],
$_POST['brand'],
$_POST['color'],
$_POST['matter'],
$_POST['state'],
$_POST['size']
);
// Upload the product images to the server
foreach (['front_pic', 'back_pic', 'side_pic'] as $key) {
$img_name = '' . $sku .'-' . $_FILES[$key]['name'];
$tmp_img_name = $_FILES[$key]['tmp_name'];
$temporary = 'images/uploads/products/';
move_uploaded_file($tmp_img_name,$temporary.$img_name);
}
// Insert the new product into the database using Connection object's method
$insert = $connection->insertProduct($product);
// Send a thank-you email to the user who submitted the form
$firstname = $_POST['firstname'];
$email = $_POST['email'];
// Load the content of the email template
$template = file_get_contents("email_template.html");
// Replace placeholders in the email template with actual values
$template = str_replace("{{ name }}", $firstname, $template);
// Set the email sender address (you can use your own email address)
$from = "[email protected]";
// Set the email subject
$subject = "Thank you for your submission!";
// To send an HTML email, set the content-type and character set
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: $from" . "\r\n";
// Send the email with the HTML template
if (mail($email, $subject, $template, $headers)) {
// echo "Email sent successfully.";
} else {
echo "Failed to send email.";
}
endif;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="public/js/forms.js" defer></script>
<link rel="stylesheet" href="public/css/style.css">
<script src="https://kit.fontawesome.com/b050931f68.js" crossorigin="anonymous"></script>
<title>Participer aux dons</title>
</head>
<body class="participation">
<?php include 'public/layouts/_header.php'; ?>
<main class="participation__content">
<aside class="participation__content__banner">
<!-- The banner for the page -->
<h1>Faîtes le bon geste !</h1>
<p>Remplissez les champs requis pour effectuer votre don</p>
</aside>
<!-- Show form when not already submitted -->
<?php if (!isset($insert)) { ?>
<form class="participation__content__form" id="participation-form" method="POST" enctype="multipart/form-data">
<!-- The form used to collect data from the user -->
<fieldset id="step-1" class="participation__content__form__div participation__content__form__owner" style="display: flex;">
<!-- Fieldset for owner information -->
<header class="participation__content__form__div__header">
<!-- Header section for the fieldset -->
<h2>Vos coordonnées</h2>
<p>Veuillez renseigner cos coordonnées pour que les potentiels intéressés puisses vous contacter</p>
</header>
<section>
<!-- Section of the fieldset for related elements -->
<div class="civil">
<div>
<label for="lastname">Nom</label>
<input type="text" name="lastname" id="lastname">
</div>
<div>
<label for="firstname">Prénom</label>
<input type="text" name="firstname" id="firstname">
</div>
</div>
<div>
<label for="email">Email*</label>
<input type="email" name="email" class="required-1" required>
</div>
<div>
<label for="phone">Téléphone*</label>
<input type="tel" name="phone" class="required-1" required>
</div>
</section>
<button type="button" value="1" id="submit-1" disabled>Passer à l'étape suivante</button>
</fieldset>
<fieldset id="step-2" class="participation__content__form__div participation__content__form__products" style="display: none;">
<!-- Fieldset for product information -->
<header class="participation__content__form__div__header">
<!-- Header section for the fieldset -->
<h2>Informations Principales</h2>
<p>Veuillez renseigner les informations principales du produit dont vous souhaitez faire don</p>
</header>
<section>
<!-- Section of the fieldset for related elements -->
<div>
<label for="title">Titre du produit*</label>
<input type="text" name="title" class="required-2" id="title" required>
</div>
<div class="textarea">
<label for="description">Description du produit*</label>
<textarea name="description" class="required-2" id="description" cols="30" required></textarea>
</div>
</section>
<button type="button" value="2" id="submit-2" disabled>Passer à l'étape suivante</button>
</fieldset>
<fieldset id="step-3" class="participation__content__form__div participation__content__form__details" style="display: none;">
<!-- Fieldset for more product details -->
<header class="participation__content__form__div__header">
<!-- Header section for the fieldset -->
<h2>Informations Principales</h2>
<p>Veuillez renseigner les informations principales du produit dont vous souhaitez faire don</p>
</header>
<section>
<!-- Section of the fieldset for related elements -->
<div>
<div>
<label for="category">Catégorie*</label>
<select name="category" class="required-3" id="category" required>
<!-- Looping through the categories from the database to show as options -->
<?php foreach ($categories as $category) : ?>
<option value="<?= $category['id'] ?>"><?= $category['title'] ?></option>
<?php endforeach; ?>
</select>
</div>
<div>
<label for="brand">Marque</label>
<input type="text" name="brand" id="brand">
</div>
</div>
<div>
<div>
<label for="color">Couleur*</label>
<select name="color" class="required-3" id="color" required>
<!-- Looping through the colors from the database to show as options -->
<?php foreach ($colors as $color) : ?>
<option value="<?= $color['id'] ?>"><?= $color['title'] ?></option>
<?php endforeach; ?>
</select>
</div>
<div>
<label for="matter">Matière*</label>
<select name="matter" id="matter">
<!-- Looping through the materials from the database to show as options -->
<?php foreach ($matters as $matter) : ?>
<option value="<?= $matter['id'] ?>"><?= $matter['title'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div>
<div>
<label for="state">Etat*</label>
<select name="state" class="required-3" id="state" required>
<!-- Looping through the states from the database to show as options -->
<?php foreach ($states as $state) : ?>
<option value="<?= $state['id'] ?>"><?= $state['title'] ?></option>
<?php endforeach; ?>
</select>
</div>
<div>
<label for="size">Taille*</label>
<select name="size" class="required-3" id="size" required>
<!-- Looping through the sizes from the database to show as options -->
<?php foreach ($sizes as $size) : ?>
<option value="<?= $size['id'] ?>"><?= $size['title'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="dropbox">
<!-- Three input fields for uploading photos of the item -->
<label class="file-drop-zone" id="front-dropbox" for="front">
<h3>Photo de face*</h3>
<i class="fa-solid fa-file-arrow-down"></i>
<span class="file-name" id="front-file-name"></span>
<span class="file-message">.jpg, .png, .jpeg</span>
</label>
<input type="file" name="front_pic" id="front" class="required-3" accept="image/png, image/jpeg, image/jpg" required>
<label class="file-drop-zone" id="back-dropbox" for="back">
<h3>Photo de profil*</h3>
<i class="fa-solid fa-file-arrow-down"></i>
<span class="file-name" id="back-file-name"></span>
<span class="file-message">.jpg, .png, .jpeg</span>
</label>
<input type="file" name="back_pic" id="back" class="required-3" accept="image/png, image/jpeg, image/jpg" required>
<label class="file-drop-zone" id="side-dropbox" for="side">
<h3>Photo de dos*</h3>
<i class="fa-solid fa-file-arrow-down"></i>
<span class="file-name" id="side-file-name"></span>
<span class="file-message">.jpg, .png, .jpeg</span>
</label>
<input type="file" name="side_pic" id="side" class="required-3" accept="image/png, image/jpeg, image/jpg" required>
</div>
</section>
<button type="submit" id="submit-3" disabled>Effectuer mon don !</button>
</fieldset>
</form>
<?php } else if (isset($insert) && $insert) { ?>
<!-- If the item was successfully donated, display a success message and an option to donate again -->
<section class="participation__content__results">
<h2>Votre don à bien était enregistré</h2>
<p>Les autres utilisateurs peuvent désormais le voir sur la page des objets donnés</p>
<a href="participation.php">Effectuer un autre don</a>
</section>
<?php } ?>
</main>
<?php include 'public/layouts/_footer.php'; ?>
</body>
</html>