-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
131 lines (109 loc) · 4.4 KB
/
index.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
<?php
include 'includes/header.php';
// Connect to database
include ('connect_to_loc_db.php');
// Query to get 5 random questions
$query1 = "SELECT ID, Statement, Best FROM learnwellquestions WHERE ID LIKE 'LP%' OR ID LIKE 'PR%' ORDER BY RAND() LIMIT 5;";
$query2 = "SELECT ID, Statement, Best FROM learnwellquestions WHERE ID LIKE 'LE%' ORDER BY RAND() LIMIT 5;";
$query3 = "SELECT ID, Statement, Best FROM learnwellquestions WHERE ID LIKE 'WB%' ORDER BY RAND() LIMIT 5;";
$query4 = "SELECT ID, Statement, Best FROM learnwellquestions WHERE ID LIKE 'IN%' OR ID LIKE 'DS%' OR ID LIKE 'CO%' OR ID LIKE 'SD%' OR ID LIKE 'EN%' OR ID LIKE 'CP%' OR ID LIKE 'CD%' ORDER BY RAND() LIMIT 5;";
$process = mysqli_query($conn, $query1);
$environemnt = mysqli_query($conn, $query2);
$skills = mysqli_query($conn, $query3);
$wellbeing = mysqli_query($conn, $query4);
$questions = array();
if ($process) {
while ($row = mysqli_fetch_assoc($process)) {
$question = array(
'surveyStatement' => $row['Statement'],
'options' => array('Strongly Disagree', 'Disagree', 'Neutral', 'Agree', 'Strongly Agree'),
'name' => $row['ID'],
'best' => $row['Best']
);
array_push($questions, $question);
}
} else {
echo "Error: " . mysqli_error($conn);
}
if ($environemnt) {
while ($row = mysqli_fetch_assoc($environemnt)) {
$question = array(
'surveyStatement' => $row['Statement'],
'options' => array('Strongly Disagree', 'Disagree', 'Neutral', 'Agree', 'Strongly Agree'),
'name' => $row['ID'],
'best' => $row['Best']
);
array_push($questions, $question);
}
} else {
echo "Error: " . mysqli_error($conn);
}
if ($skills) {
while ($row = mysqli_fetch_assoc($skills)) {
$question = array(
'surveyStatement' => $row['Statement'],
'options' => array('Strongly Disagree', 'Disagree', 'Neutral', 'Agree', 'Strongly Agree'),
'name' => $row['ID'],
'best' => $row['Best']
);
array_push($questions, $question);
}
} else {
echo "Error: " . mysqli_error($conn);
}
if ($wellbeing) {
while ($row = mysqli_fetch_assoc($wellbeing)) {
$question = array(
'surveyStatement' => $row['Statement'],
'options' => array('Strongly Disagree', 'Disagree', 'Neutral', 'Agree', 'Strongly Agree'),
'name' => $row['ID'],
'best' => $row['Best']
);
array_push($questions, $question);
}
} else {
echo "Error: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
<div class= 'contents'>
<form id="Survey" action="process_survey.php" method="post">
<div class= 'container'>
<h1>LearnWell Questionaire</h1>
</div>
<div id="Surveyquestions"></div>
<div class= 'container'>
<button id="submitButton" type="submit" name = "submit">Submit</button>
</div>
<div class="gdpr">
<p>Know about how we process your data</p>
<span class="tooltip">We don't collect any personal data. The data is used and processed solely by HAMK.</span>
</div>
</form>
<script>
const questions = <?php echo json_encode($questions); ?>;
const Surveyquestions = document.getElementById("Surveyquestions");
questions.forEach((question, index) => {
const questionDiv = document.createElement("div");
questionDiv.classList.add("question");
const questionParagraph = document.createElement("p");
questionParagraph.classList.add("question-text");
questionParagraph.textContent = question.surveyStatement;
questionDiv.appendChild(questionParagraph);
question.options.forEach((option, optionIndex) => {
if(question.best == 5)
{ $weight = optionIndex + 1; }
else if(question.best == 1)
{ $weight = ( (optionIndex - 5) * (-1) ) ;}
const label = document.createElement("label");
label.innerHTML = `
<input type="radio" name="${question.name}" value="${$weight}">
${option}
`;
questionDiv.appendChild(label);
});
Surveyquestions.appendChild(questionDiv);
});
</script>
</div>
<?php include 'includes/footer.php'; ?>