-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquiz.php
360 lines (344 loc) · 15 KB
/
quiz.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<?php
$test = 1;
if(isset($_GET['test']))
$test = $_GET['test'];
include "./module/test-{$test}.php";
?>
<!DOCTYPE html>
<html lang="ro">
<head>
<meta charset="utf-8">
<title>Test</title>
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.5/css/bulma.min.css">
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<link rel="icon" href="./images/icon.png">
<style>
.aligning {
display: flex;
justify-content: center;
}
.back {
background: url("images/quiz.png");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
background-position: center;
}
div.separator {
padding: 10px 0;
}
.corect {
color: green;
}
.gresit,.red {
color: red;
}
.corect1 {
color: #00ff00;
}
</style>
</head>
<body>
<nav class="navbar" role="navigation" aria-label="main navigation">
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="Nav">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
<div id="Nav" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item" href="index.php">Acasă</a>
<div class="navbar-item has-dropdown is-hoverable">
<a href="" class="navbar-link">Evaluare</a>
<div class="navbar-dropdown">
<a href="quiz.php" class="navbar-item" style="color:#00d1b2">Test</a>
<a href="doc/bac.pdf" class="navbar-item">Model subiect bacalaureat</a>
</div>
</div>
<a href="contact.php" class="navbar-item">Contact</a>
<a href="despre.php" class="navbar-item">Despre</a>
</div>
</div>
</nav>
<div class="back">
<div class="separator"></div>
<div class="separator"></div>
<main class="bd-main-container">
<div class="content">
<?php
session_start();
if(! isset($_POST['formular']))
{
?>
<h2 style="text-align:center;">Evaluează-ți cunostințele</h2>
<form action="quiz.php" method="post">
<input type="hidden" name="formular" value="1">
<ol>
<?php
foreach($intrebari as $index => $intrebare)
{
?>
<li>
<p><?=$intrebare['enunt']?></p>
<blockquote>
<?php
if(!empty($intrebare['text']))
{
?>
<p><?=$intrebare['text']?></p>
<?php
}
if($intrebare['tip'] == 'radio')
{
?>
<?php
foreach($intrebare['variante'] as $iv => $varianta)
{
?>
<label><input type="radio" name="intrebare_<?=$index?>" value="<?=$iv?>"><?=$varianta['raspuns']?></label><br>
<?php
}
?>
<?php
}
if($intrebare['tip'] == 'select')
{
?>
<div>
<select name="intrebare_<?=$index?>">
<option disabled selected value="-1"></option>
<?php
foreach($intrebare['variante'] as $iv => $varianta)
{
?>
<option value="<?=$iv?>"><?=$varianta['raspuns']?></option>
<?php
}
?>
</select>
</div>
<?php
}
?>
</blockquote>
</li>
<?php
}
?>
</ol>
<div class="aligning">
<div class="buttons">
<input type="submit" class="button is-outlined is-success is-medium" value="Trimite" id="buton" /> <input type="reset" class="button is-outlined is-danger is-medium" value="Resetează" id="buton" />
</div>
</div>
</form>
<?php
}
else
{
$rezultate = [];
foreach($intrebari as $index => $intrebare)
{
$rezultate[$index] = [
'raspuns' => 0,
'corect' => false
];
if(isset($_POST["intrebare_{$index}"]))
{
$rezultate[$index]['raspuns'] = intval($_POST["intrebare_{$index}"]);
if($intrebare['variante'][$rezultate[$index]['raspuns']]['corect'])
$rezultate[$index]['corect'] = true;
}
}
$nr_raspunsuri = count($rezultate);
$nr_raspunsuri_corecte = 0;
foreach($rezultate as $r)
{
if($r['corect'])
$nr_raspunsuri_corecte++;
}
$rasp=$nr_raspunsuri_corecte;
$_SESSION['rasp']=$rasp;
$_SESSION['nr_raspunsuri']=$nr_raspunsuri;
?>
<div style="text-align:center;" class="content">
<h2>Răspunsuri corecte</h2>
<div style="font-size:5em;">
<?=$nr_raspunsuri_corecte?>/<?=$nr_raspunsuri?>
</div>
<p>
<a href="quiz.php" class="button is-primary is-outlined" id="buton" style="margin:0;text-decoration:none;">Încearcă din nou</a>
</p>
<div class="content has-text-centered">
<a class="button is-link bmail">Trimite rezultatul pe e-mail</a>
</div>
</div>
<ol>
<?php
foreach($intrebari as $index => $intrebare)
{
?>
<li>
<p>
<?=$intrebare['enunt']?>
</p>
<blockquote>
<?php
if(!empty($intrebare['text']))
{
?>
<p><?=$intrebare['text']?></p>
<?php
}
if($intrebare['tip'] == 'radio')
{
?>
<ul type="a">
<?php
foreach($intrebare['variante'] as $iv => $varianta)
{
$class= "";
if(!isset($_POST["intrebare_{$index}"]))
{
if($varianta['corect'])
$class = "corect1";
}
else
{
if($rezultate[$index]['corect'])
{
if($varianta['corect'])
$class = "corect";
}
else
{
if($varianta['corect'])
$class = "corect";
else
if($rezultate[$index]['raspuns'] == $iv)
{
$class = "gresit";
}
}
}
?>
<li class="<?=$class?>">
<?=$varianta['raspuns']?>
</li>
<?php
}
?>
</ul>
<?php
}
if($intrebare['tip'] == 'select')
{
?>
<div>
<ul>
<?php
foreach($intrebare['variante'] as $iv => $varianta)
{
$class= "";
if(!isset($_POST["intrebare_{$index}"]))
{
if($varianta['corect'])
$class = "corect1";
}
else
{
if($rezultate[$index]['corect'])
{
if($varianta['corect'])
$class = "corect";
}
else
{
if($varianta['corect'])
$class = "corect";
else
if($rezultate[$index]['raspuns'] == $iv)
{
$class = "gresit";
}
}
}
?>
<li class="<?=$class?>">
<?=$varianta['raspuns']?>
</li>
<?php
}
?>
</ul>
</div>
<?php
}
?>
</blockquote>
</li>
<?php
}
?>
</ol>
<?php
}
?>
</div>
</main>
<section class="is-medium">
<div class="content aligning" style="padding:20px;">
<a href="doc/test.pdf" class="button is-link">Versiunea offline <i class="fas fa-download"></i></a>
</div>
</section>
</div>
<script>
$(document).on('click', '.navbar-burger', function() {
$(".navbar-burger").toggleClass("is-active");
$(".navbar-menu").toggleClass("is-active");
});
$(document).on('click', '.bmail', function(e) {
e.preventDefault;
$(".mail").addClass("is-active");
});
$(document).on('click', '.close_modal', function(e) {
e.preventDefault;
$(".modal").removeClass("is-active");
});
</script>
<?php
include "module/mail.php";
?>
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if(isset($_POST['submit']))
{
require 'phpmail/src/Exception.php';
require 'phpmail/src/PHPMailer.php';
require 'phpmail/src/SMTP.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "Memoria2410";
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->From = "[email protected]";
$mail->FromName = "Memoria";
$mail->addAddress($_POST['email']);
$mail->isHTML(true);
$mail->Subject = "Rezultat evaluare";
$mail->Body = "<h2>Răspunsuri corecte</h2><h3>Ai răspuns corect la {$_SESSION['rasp']} întrebări din {$_SESSION['nr_raspunsuri']}</h3>";
if(!$mail->send())
{
echo '<h1 style="color:red">Încearcă mai târziu!</h1>';
}
}
?>
</body>
</html>