-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.php
533 lines (490 loc) · 26 KB
/
backend.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
<?php
// To start the session
session_start();
$student_data = [];
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// if($_POST['data']){
// $data = json_decode($_POST['data'],true);
// print_r( $data['feedback']);
// echo $data['feedback'][0]['course_id'];
// echo implode(",",$data['feedback']);
// echo $data['request'];
// echo $data['feedback'];
// echo implode(",",$data);
// }
if($_POST['request'] == 'student_form'){
$email= $_POST['email'];
$servername = 'localhost';
$username = 'root';
$password = '';
$db = 'mitaoe';
$connection = new mysqli($servername, $username, $password, $db);
if ($connection->connect_error) {
die("Connection failed: " . $connection->connect_error);
}
$query = 'select * from students where email = "'.$email.'"';
$result = $connection->query($query);
if($result->num_rows>0){
$student_data = $result->fetch_row();
if($student_data[8] == 0){
$student_detail_form = '
<form class="student-details row g-3 mt-3 p-3" id="student-details" autocomplete="off">
<div class="form-floating mb-3">
<input type="text" name="name" class="form-control" id="floatingName" value="'.$student_data[1].'" disabled required>
<label for="floatingName">Name</label>
</div>
<div class="form-floating mb-3">
<input type="text" name="PRN" class="form-control" id="floatingPRN" placeholder="12 digit" minlength="12" maxlength="12" value="'.$student_data[2].'" disabled>
<label for="floatingPRN">PRN number</label>
</div>
<div class="form-floating mb-3">
<input type="email" name="email" class="form-control" id="floatingEmail" value="'.$student_data[3].'" disabled>
<label for="floatingEmail">Email address</label>
</div>
<div class="form-floating mb-3">
<input type="text" name="branch" class="form-control" id="floatingBranch" placeholder="12 digit" value="'.$student_data[4].'" disabled>
<label for="floatingPRN">Branch</label>
</div>
<div class="form-floating mb-3">
<input type="text" name="division" class="form-control" id="floatingDiv" value="'.$student_data[5].'" disabled>
<label for="floatingEmail">Division</label>
</div>
<div class="form-floating mb-3">
<input type="text" name="batch" class="form-control" id="floatingBatch" value="" placeholder="Enter your batch" required>
<label for="floatingName">Batch</label>
</div>
<button aria-label="Next" class="stud_info_btn btn btn-outline-primary btn-sm mt-3">Next</button>
</form>
<script>
$(".student-details .stud_info_btn").click(function(e) {
e.preventDefault()
// To keep track of current visible form
let formCounter = 1;
$.ajax({
datatype: "json",
type: "post",
url: "backend.php",
data: {"request":"feedback_form","batch":$("#student-details #floatingBatch").val(), "branch":$("#student-details #floatingBranch").val(),"division":$("#student-details #floatingDiv").val()},
success: function(response) {
if (!response) {
alert("error")
}
else if(response == 0){
alert("Invalid batch")
$("#floatingBatch").focus()
} else {
console.log(response)
let data = response.split("/,");
$(".student-info").addClass("d-none")
$(".feedback .feedback-forms").removeClass("d-none");
$(".feedback .feedback-forms").html(data[0]);
for (let j = 2; j <= data[1]; j++) {
$("#ratingForm" + j).addClass("d-none");
}
}
}
})
});
</script>
';
$_SESSION['email'] = $email;
echo $student_detail_form;
}
else{
echo 0;
echo '<div class="outer-box">
<div class="inner-box">
<h1>You have already responded</h1>
<p>Your response has been recorded.</p>
</div>
</div>';
}
}
else{
echo 0;
echo '<div class="outer-box">
<div class="inner-box">
<h1>Access denied</h1>
<p>You can access the feedback form using your official mail id only. <a href="">Re-enter email</a></p>
</div>
</div>';
}
}
elseif($_POST['request'] == 'feedback_form'){
$batch = $_POST['batch'];
$branch = $_POST['branch'];
$division = $_POST['division'];
if($batch!=""){
$connection = createConn();
$result = $connection->query("select * from course_allocation where branch='".$branch."' and batch='".$batch."'");
if($result->num_rows == 0){
echo 0;
return;
}
}
$data = getforms($branch, $batch,$division);
echo $data['forms'].','.$data['count'];
}
elseif($_POST['request'] == 'feedback-data')
{
$feedback = $_POST['feedback'];
save_feedback($feedback);
}
else {
echo false;
}
}
function createConn()
{
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mitaoe";
global $connection;
$connection = new mysqli($servername, $username, $password, $dbname);
if ($connection->connect_error) {
die("Connection failed: " . $connection->connect_error);
}
return $connection;
}
function fetch_courses($branch, $batch, $division)
{
$conn = createConn();
$query = mysqli_query($conn, "SELECT * FROM course_allocation where branch = '$branch' and (batch = '$division' or batch = '$batch')");
$feedback = array();
while ($row = mysqli_fetch_assoc($query)) {
$course_name = get_course_name($row['course_id']);
$faculty_name = get_faculty_name($row['faculty_id']);
$form_row = array($row['course_id'],$course_name, $row['faculty_id'],$faculty_name);
array_push($feedback, $form_row);
}
return $feedback;
}
function get_course_name($course_id)
{
$conn = createConn();
$sql = mysqli_query($conn,"SELECT name FROM course where id = '$course_id'");
$row = mysqli_fetch_row($sql);
return $row[0];
}
function get_faculty_name($faculty_id)
{
$conn = createConn();
$sql = mysqli_query($conn,"SELECT name FROM faculty where id = '$faculty_id'");
$row = mysqli_fetch_row($sql);
return $row[0];
}
function get_course_id($course_name, $branch)
{
$conn = createConn();
$sql = mysqli_query($conn,"SELECT id FROM course where name = '$course_name' and branch = '$branch'");
$row = mysqli_fetch_row($sql);
return $row[0];
}
function get_faculty_id($faculty_name)
{
$conn = createConn();
$sql = $conn->prepare("SELECT id FROM faculty where name = ?");
$sql->bind_param("s", $faculty_name);
$sql->execute();
if ($sql->num_rows > 0) {
$result = $sql->get_result();
while ($data = $result->fetch_assoc()) {
return $data['id'];
}
} else {
return -1;
}
}
function save_feedback($feedback)
{
$conn = createConn();
$success = 0;
for ($i=0; $i < sizeof($feedback); $i++) {
$sql = mysqli_query($conn," UPDATE feedback set
q1 = q1 + ".(int)$feedback[$i][4].",
q2 = q2 + ".(int)$feedback[$i][5].",
q3 = q3 + ".(int)$feedback[$i][6].",
q4 = q4 + ".(int)$feedback[$i][7].",
q5 = q5 + ".(int)$feedback[$i][8].",
q6 = q6 + ".(int)$feedback[$i][9].",
q7 = q7 + ".(int)$feedback[$i][10].",
responses = responses + 1,
average = (q1+q2+q3+q4+q5+q6+q7)/7
where course_id = ".(int)$feedback[$i][3]."
and faculty_id = ".(int)$feedback[$i][2]);
if ($sql) {
$success = 1;
} else {
$success = 0;
}
}
if($success){
$sql = mysqli_query($conn, 'update students set response = 1 where email = "'.$_SESSION['email'].'"');
echo 1;
}
else{
echo 0;
}
}
function getforms($branch,$batch,$division)
{
$formData = fetch_courses($branch, $batch, $division);
// $formData = array(
// array('Teacher 1','Subject 1'),
// array('Teacher 2','Subject 2'),
// array('Teacher 3','Subject 3')
// );
$forms = '';
$i = 0;
for($i; $i < sizeof($formData); $i++)
{
$forms.='
<form method="post" class="row mt-3" id="ratingForm'.($i+1).'" autocomplete="off">
<div class="course-details mt-4">
<div>'.($i+1).'</div>
<div class="cid">'.$formData[$i][0].'</div>
<div class="cname">'.$formData[$i][1].'</div>
<div class="tid">'.$formData[$i][2].'</div>
<div class="tname">'.$formData[$i][3].'</div>
</div>
<div class="heading mt-3">
<h5></h5>
<h5>Poor</h5>
<h5>Satisfactory</h5>
<h5>Good</h5>
<h5>Very Good</h5>
<h5>Excellent</h5>
</div>
<div class="all-ratings">
<div class="ratings">
<div class="title">
Depth of knowledge <span>*</span>
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions1" id="inlineRadio1" value="1" required>
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions1" id="inlineRadio2" value="2">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions1" id="inlineRadio3" value="3">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions1" id="inlineRadio4" value="4">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions1" id="inlineRadio5" value="5">
</div>
</div>
<div class="ratings">
<div class="title">
Way of presentation<span>*</span>
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions2" id="inlineRadio1" value="1" required>
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions2" id="inlineRadio2" value="2">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions2" id="inlineRadio3" value="3">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions2" id="inlineRadio4" value="4">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions2" id="inlineRadio5" value="5">
</div>
</div>
<div class="ratings">
<div class="title">
Attitude / Behaviour<span>*</span>
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions3" id="inlineRadio1" value="1" required>
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions3" id="inlineRadio2" value="2">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions3" id="inlineRadio3" value="3">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions3" id="inlineRadio4" value="4">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions3" id="inlineRadio5" value="5">
</div>
</div>
<div class="ratings">
<div class="title">
Lectures conducted with involvement<span>*</span>
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions4" id="inlineRadio1" value="1" required>
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions4" id="inlineRadio2" value="2">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions4" id="inlineRadio3" value="3">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions4" id="inlineRadio4" value="4">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions4" id="inlineRadio5" value="5">
</div>
</div>
<div class="ratings">
<div class="title">
Syllabus covered<span>*</span>
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions5" id="inlineRadio1" value="1" required>
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions5" id="inlineRadio2" value="2">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions5" id="inlineRadio3" value="3">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions5" id="inlineRadio4" value="4">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions5" id="inlineRadio5" value="5">
</div>
</div>
<div class="ratings">
<div class="title">
Innovative teaching techniques<span>*</span>
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions6" id="inlineRadio1" value="1" required>
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions6" id="inlineRadio2" value="2">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions6" id="inlineRadio3" value="3">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions6" id="inlineRadio4" value="4">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions6" id="inlineRadio5" value="5">
</div>
</div>
<div class="ratings">
<div class="title">
Attractive and clean board writing<span>*</span>
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions7" id="inlineRadio1" value="1" required>
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions7" id="inlineRadio2" value="2">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions7" id="inlineRadio3" value="3">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions7" id="inlineRadio4" value="4">
</div>
<div class="rating form-check form-check-inline">
<input class="form-check-input" type="radio" name="RadioOptions7" id="inlineRadio5" value="5">
</div>
</div>
<div class="navigateBtn ">
';
if($i != 0)
{
$forms.='
<button class=" btn btn-outline-primary btn-sm prev mt-5">Previous</button>'
;
}
if($i == sizeof($formData)-1){
$forms.='<button class=" btn btn-outline-primary btn-sm submitForm mt-5">Submit</button>';
}
else{
$forms.='<button class=" btn btn-outline-primary btn-sm next mt-5">Next</button>';
}
$forms.='</div>
</div>
<span class="pageNumber">'.($i+1).'/'.sizeof($formData).'</span>
</form>
';
}
$forms.='
<script>
let formCounter = 1;
$(".feedback .feedback-forms .next").click(function(e) {
if($("#ratingForm"+formCounter+" input[name='."RadioOptions1".']").is(":checked") && $("#ratingForm"+formCounter+" input[name='."RadioOptions2".']").is(":checked") && $("#ratingForm"+formCounter+" input[name='."RadioOptions3".']").is(":checked") && $("#ratingForm"+formCounter+" input[name='."RadioOptions4".']").is(":checked") && $("#ratingForm"+formCounter+" input[name='."RadioOptions5".']").is(":checked") && $("#ratingForm"+formCounter+" input[name='."RadioOptions6".']").is(":checked") && $("#ratingForm"+formCounter+" input[name='."RadioOptions7".']").is(":checked")){
e.preventDefault();
$("#ratingForm" + formCounter).addClass("d-none");
$("#ratingForm" + (++formCounter)).removeClass("d-none");
}else{
alert("All questions are mandetory")
$("#ratingForm" + formCounter).focus();
return;
}
})
$(".feedback .feedback-forms .prev").click(function(e) {
e.preventDefault();
$("#ratingForm" + formCounter).addClass("d-none");
$("#ratingForm" + (--formCounter)).removeClass("d-none");
})
$(".feedback .feedback-forms .submitForm").click(function(e) {
if($("#ratingForm"+formCounter+" input[name='."RadioOptions1".']").is(":checked") && $("#ratingForm"+formCounter+" input[name='."RadioOptions2".']").is(":checked") && $("#ratingForm"+formCounter+" input[name='."RadioOptions3".']").is(":checked") && $("#ratingForm"+formCounter+" input[name='."RadioOptions4".']").is(":checked") && $("#ratingForm"+formCounter+" input[name='."RadioOptions5".']").is(":checked") && $("#ratingForm"+formCounter+" input[name='."RadioOptions6".']").is(":checked") && $("#ratingForm"+formCounter+" input[name='."RadioOptions7".']").is(":checked")){
e.preventDefault();
let feedback = [];
for(let j=1;j<='.$i.';j++){
console.log($("#ratingForm"+j))
console.log($("#ratingForm"+j+" .tname").text())
let arr = [];
arr[0] = $("#ratingForm"+j+" .tname").text();
arr[1] = $("#ratingForm"+j+" .cname").text();
arr[2] = $("#ratingForm"+j+" .tid").text();
arr[3] = $("#ratingForm"+j+" .cid").text();
arr[4] = $("#ratingForm"+j+" input[name="+"RadioOptions1"+"]:checked").val();
arr[5] = $("#ratingForm"+j+" input[name="+"RadioOptions2"+"]:checked").val();
arr[6] = $("#ratingForm"+j+" input[name="+"RadioOptions3"+"]:checked").val();
arr[7] = $("#ratingForm"+j+" input[name="+"RadioOptions4"+"]:checked").val();
arr[8] = $("#ratingForm"+j+" input[name="+"RadioOptions5"+"]:checked").val();
arr[9] = $("#ratingForm"+j+" input[name="+"RadioOptions6"+"]:checked").val();
arr[10] = $("#ratingForm"+j+" input[name="+"RadioOptions7"+"]:checked").val();
feedback[j-1] = arr;
};
if(confirm("Confirm submit feedback ?"))
{
$.ajax({
type: "post",
url:"backend.php",
data:{"request":"feedback-data","feedback":feedback},
success:function(response){
console.log(response)
if(response)
{
$("#feedback").addClass("d-none");
$(".errorPage").html(`<div class="outer-box"><div class="inner-box"><h1>Feedback submitted successfully</h1><p>Your response has been recorded.</p></div></div>`);
}
else{
alert("Oops something went wrong!! Try re-submitting the form.")
}
}
})
}
}else{
alert("All questions are mandetory")
$("#ratingForm" + formCounter).focus();
return;
}
})
</script>/';
$data = array("forms"=>$forms,"count"=>$i);
return $data;
}
?>