-
Notifications
You must be signed in to change notification settings - Fork 0
/
manageQuestionnaires.php
373 lines (354 loc) · 15.8 KB
/
manageQuestionnaires.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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Ankietour - Manage questionnaires</title>
<script src="js/checkFields.js"></script>
<script src="js/utils.js"></script>
<script src="alertify/lib/alertify.min.js"></script>
<link rel="stylesheet" href="css/pure-min.css">
<!--[if lte IE 8]>
<link rel="stylesheet" href="css/layouts/side-menu-old-ie.css">
<![endif]-->
<!--[if gt IE 8]><!-->
<link rel="stylesheet" href="css/layouts/side-menu.css">
<link rel="stylesheet" href="alertify/themes/alertify.core.css" />
<link rel="stylesheet" href="alertify/themes/alertify.default.css" />
<!--<![endif]-->
</head>
<body>
<?php
include 'php_libs/updateFunctions.php';
include 'php_libs/deleteFunctions.php';
include 'php_libs/questionnaireInfoGeneration.php';
session_start();
?>
<?php
$newName = $newDescription = $newEmail = "";
$newTypeId = $newPersonId = 0;
$editName = $editDesciption = "";
$editTypeId = $newPersonId = 0;
$errMsg = $errMsg2 = $errMsg3 = "";
$selectedQuestionnaire = $selectedUser = $selectedProductType = $selectProductTypeForQuestionnaire = 0;
$selectedUsers = array();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST["removeQuestionnaire"])) {
if (!empty($_POST['check_list_remove'])) {
$ids = $_POST['check_list_remove'];
deleteQuestionnaires($ids);
echo "<script> alertify.alert(\"Selected questionnaires were removed.\")</script>";
}
} else if (isset($_POST["addQuestionnaire"])) {
$newName = $_POST["newName"];
$newDescription = $_POST["newDescription"];
$newTypeId = $_POST["newTypeId"];
$newMail = $_POST["newEmail"];
$i = 0;
if (isset( $_POST["newPersonId"])){
$newPersonIds = $_POST["newPersonId"];
foreach($newPersonIds as $newPersonId){
$insertedId = addQuestionnaire($newName . "#$i", $newDescription, $newPersonId, $newTypeId);
if ($insertedId >= 0) {
if (!empty($_POST['check_list_remove'])) {
$productsIds = $_POST['check_list_remove'];
addExcludedProducts($productsIds, $insertedId);
}
}
$i++;
}
echo "<script> alertify.alert(\"New questionnaires were added and assigned to selected users.\")</script>";
}
if (!empty($newMail)) {
$p_emails = explode(",", $newMail);
foreach ($p_emails as $email) {
if (strpos($email, '@')) {
$insertedId = addQuestionnaire($newName . "#$i", $newDescription, 0, $newTypeId);
if ($insertedId >= 0) {
if (!empty($_POST['check_list_remove'])) {
$productsIds = $_POST['check_list_remove'];
addExcludedProducts($productsIds, $insertedId);
}
sendMailWithQuestionnaire($newMail, $insertedId);
}
$i++;
}
}
echo "<script> alertify.alert(\"New questionnaires were added and emails were sent to $newMail.\")</script>";
}
} else if (isset($_POST["newTypeId"])) {
$selectedProductType = $_POST["newTypeId"];
$newName = $_POST["newName"];
$newDescription = $_POST["newDescription"];
$newEmail = $_POST["newEmail"];
if (isset($_POST["newPersonId"])){
$selectedUsers = $_POST["newPersonId"];
}
} else if (isset($_POST["selectQuestionnaire"])) {
if (isset($_POST["selectProductType"])){
$selectProductTypeForQuestionnaire = $_POST["selectProductType"];
}
$selectedQuestionnaire = $_POST['selectQuestionnaire'];
} else if (isset($_POST["selectProductType"])) {
$selectProductTypeForQuestionnaire = $_POST['selectProductType'];
} else if (isset($_POST["selectPerson"])) {
$selectedUser = $_POST['selectPerson'];
}
}
?>
<div id="layout">
<a href="#menu" id="menuLink" class="menu-link">
<!-- Hamburger icon -->
<span></span>
</a>
<?php generateMenu(); ?>
<div id="main">
<div class="header">
<h1>Ankietour</h1>
<?php
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
echo "Hello, " . $_SESSION['username'];
}
?>
<h2>Manage questionnaires</h2>
</div>
<div class="content">
<?php
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
?>
<div class="pure-menu pure-menu-open pure-menu-horizontal">
<ul>
<li><a href="#"><h3
onclick="showAndHideDiv('addQuestionnaireDiv', 'allQuestionnairesDiv', 'manageSelectedQuestionnaireDiv')"
onmouseover="" style="cursor: pointer;">Add questionnaire</h3></a></li>
<li><a href="#"><h3
onclick="showAndHideDiv('allQuestionnairesDiv', 'addQuestionnaireDiv', 'manageSelectedQuestionnaireDiv')"
onmouseover="" style="cursor: pointer;">All questionnaires</h3></a></li>
<li><a href="#"><h3
onclick="showAndHideDiv('manageSelectedQuestionnaireDiv', 'allQuestionnairesDiv', 'addQuestionnaireDiv')"
onmouseover="" style="cursor: pointer;">Manage selected
questionnaire</h3></a></li>
</ul>
</div>
<!-- ------------ Add questionnaire -------------------------------------------------------------------->
<div id="addQuestionnaireDiv">
<form class="pure-form pure-form-stacked" name="addQuestionnaireForm" enctype="multipart/form-data"
onsubmit="return checkQuestionnaireFields()"
method="post"
action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<div class="pure-u-1-3">
Name: <input class="full_width" type="text" id="newName" name="newName"
value="<?php echo $newName; ?>" required/>
</div>
<div class="pure-u-2-3"></div>
<div class="pure-u-1-3">
Description: <textarea class="full_width" name="newDescription"><?php echo $newDescription; ?></textarea>
</div>
<div class="pure-u-2-3"></div>
<div class="pure-u-3-3">
Choose person or put an email:
</div>
<div class="pure-u-1-3">
Person:
<select class="full_width" id="newPersonId" name="newPersonId[]" multiple="multiple">
<?php
$ret = selectUsersWithPrivilege(3);
if ($ret != false) {
while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
$rowValue = $row["login"];
$rowId = $row["id"];
if (in_array($rowId,$selectedUsers)) {
echo "<option value=\"$rowId\" selected=\"selected\">$rowValue</option>";
} else {
echo "<option value=\"$rowId\">$rowValue</option>";
}
}
}
?>
</select>
</div>
<div class="pure-u-1-3">
Email:<textarea class="full_width" name="newEmail"><?php echo $newEmail; ?></textarea>
<p id="errPersonId"></p>
</div>
<div class="pure-u-1-3"></div>
<div class="pure-u-1-3">
Product type:
<select class="full_width" id="newTypeId" name="newTypeId" onchange="this.form.submit()">
<?php
$ret = selectProductsTypes();
if ($ret != false) {
echo "<option value=0></option>";
while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
$rowValue = $row["name"];
$rowId = $row["id"];
if ($rowId == $selectedProductType) {
echo "<option value=\"$rowId\" selected=\"selected\">$rowValue</option>";
} else {
echo "<option value=\"$rowId\">$rowValue</option>";
}
}
}
?>
</select>
<p id="errTypeId"></p>
</div>
<div class="pure-u-2-3"></div>
<?php
if ($selectedProductType != 0) {
?>
<div class="pure-u-2-3">Select products to exclude from questionnaire:
<?php
$ret = selectProductsByProductType($selectedProductType);
if ($ret != false) {
echo "<table class=\"pure-table\">";
while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
echo "<tr>";
$rowName = $row["name"];
$rowId = $row["id"];
echo "<td>$rowName</td>";
echo "<td><input type=\"checkbox\" name=\"check_list_remove[]\" value=\"$rowId\"></td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
}
?>
<?php
}
?>
<p>
<input class="button-success pure-button" type="submit" name="addQuestionnaire"
value="Add questionnaire"
/>
<input class="pure-button" type="button" name="cancelButton" value="Cancel" />
</p>
<p id="errMsg"></p>
</form>
</div>
<span class="error"><?php global $errMsg;
echo $errMsg ?></span>
<!-- ------------ All questionnaires -------------------------------------------------------------------->
<div id="allQuestionnairesDiv">
<form class="pure-form pure-form-stacked" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"
method="post">
<?php
$ret = selectQuestionnaires();
if ($ret != false) {
echo "<table class=\"pure-table\">";
while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
echo "<tr>";
$rowName = $row["name"];
$rowProductType = selectProductTypeName($row["typeid"]);
$rowUser = selectUserLogin($row["personid"]);
$rowId = $row["id"];
echo "<td>$rowName</td>";
echo "<td>$rowProductType</td>";
echo "<td>$rowUser</td>";
echo "<td><input type=\"checkbox\" name=\"check_list_remove[]\" value=\"$rowId\"></td>";
echo "</tr>";
}
echo "</table>";
}
?>
<p><input class="button-success pure-button" type="submit" name="removeQuestionnaire"
value="Remove selected questionnaires" /></p>
<p>
<span class="error"><?php global $errMsg3;
echo $errMsg3 ?></span>
</p>
</form>
</div>
<!-- ------------ Manage selected questionnaire -------------------------------------------------------------------->
<div id="manageSelectedQuestionnaireDiv">
<form class="pure-form pure-form-stacked" id="selectQuestionnaireForm" enctype="multipart/form-data"
name="selectPersonForm"
onsubmit="return checkQuestionnaireFields()" method="post"
action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<div class="pure-u-1-3">
Choose product type:
<select class="full_width" id="selectProductType" name="selectProductType" onChange="this.form.submit()">
<?php
$ret = selectProductsTypes();
if ($ret != false) {
echo "<option value=0></option>";
while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
$rowValue = $row["name"];
$rowId = $row["id"];
if ($rowId == $selectProductTypeForQuestionnaire) {
echo "<option value=\"$rowId\" selected=\"selected\">$rowValue</option>";
} else {
echo "<option value=\"$rowId\">$rowValue</option>";
}
}
}
?>
</select>
</div>
<div class="pure-u-2-3">
</div>
<div class="pure-u-1-3">
Choose questionnaire:
<select class="full_width" id="selectQuestionnaire" name="selectQuestionnaire" onchange="this.form.submit()">
<?php
$ret = selectQuestionnaireByProductType($selectProductTypeForQuestionnaire);
if ($ret != false) {
echo "<option value=0></option>";
while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
$rowValue = $row["name"];
$rowId = $row["id"];
if ($rowId == $selectedQuestionnaire) {
echo "<option value=\"$rowId\" selected=\"selected\">$rowValue</option>";
} else {
echo "<option value=\"$rowId\">$rowValue</option>";
}
}
}
?>
</select>
</div>
<?php
if ($selectedQuestionnaire != 0 && $selectProductTypeForQuestionnaire != 0){
if (selectProductTypeNameFromQuestionnaire($selectedQuestionnaire) == selectProductTypeName($selectProductTypeForQuestionnaire)){
generateMatrix($selectedQuestionnaire);
generateInfo($selectedQuestionnaire);
}
}
?>
<p class="error" id="errMsg2"></p>
<span class="error"><?php global $errMsg2;
echo $errMsg2 ?></span>
</form>
</div>
<?php
echo "<script>hideAll('manageSelectedQuestionnaireDiv', 'allQuestionnairesDiv', 'addQuestionnaireDiv')</script>";
if (isset($_POST["removeQuestionnaire"])) {
echo "<script>reloadShowAndHideDiv('allQuestionnairesDiv', 'addQuestionnaireDiv','manageSelectedQuestionnaireDiv')</script>";
} else if (isset($_POST["addQuestionnaire"])) {
echo "<script>reloadShowAndHideDiv('addQuestionnaireDiv', 'allQuestionnairesDiv','addPersonDiv')</script>";
} else if (isset($_POST["editQuestionnaire"])) {
echo "<script>reloadShowAndHideDiv('manageSelectedQuestionnaireDiv', 'addQuestionnaireDiv','allQuestionnairesDiv')</script>";
} else if (isset($_POST["selectQuestionnaire"])) {
echo "<script>reloadShowAndHideDiv('manageSelectedQuestionnaireDiv', 'addQuestionnaireDiv','allQuestionnairesDiv')</script>";
} else if (isset($_POST["selectProductType"])) {
echo "<script>reloadShowAndHideDiv('manageSelectedQuestionnaireDiv', 'addQuestionnaireDiv','allQuestionnairesDiv')</script>";
} else if (isset($_POST["newTypeId"])) {
echo "<script>reloadShowAndHideDiv('addQuestionnaireDiv', 'allQuestionnairesDiv','addPersonDiv')</script>";
}
} else {
loginFirstMsg();
}
?>
<!-- ------------ Back to menu -------------------------------------------------------------------->
<p>
<a class="button-secondary pure-button" href="index.php">Back to menu</a>
</p>
</div>
</div>
</div>
<script>
var e = document.getElementById("selectQuestionnaire").value;
document.getElementById("selectedQuestionnaireId").value = e;
</script>
<script src="js/ui.js"></script>
</body>
</html>