-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateQuestion.php
More file actions
182 lines (174 loc) · 6.32 KB
/
createQuestion.php
File metadata and controls
182 lines (174 loc) · 6.32 KB
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
<div id="target"></div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<!-- <script>
$(document).ready(function () {
$("#target").load("menu.html");
});
</script> -->
<body>
<?php
include 'navbar.html';
?>
<h2 align ="center"> Create Question</h2>
<table border ="0" align="center">
<form action="createQuestion.php" method="POST">
<tr>
<td>Question Id:</td>
<td><input type="text" name="name" required="required" class="form-control"><br></td>
</tr>
<tr>
<td>Title:</td>
<td>
<textarea name="title" required="required" class="form-control" rows="4" cols="50">
</textarea>
</td>
</tr>
<tr>
<td>Choices</td>
<td>
<textarea name="choices" required="required" class="form-control" rows="4" cols="50" placeholder="Enter choices">
</textarea><br>
</td>
</tr>
<tr>
<td>Type:</td>
<td>
<select name="type" required="required" class="form-control" onchange="toggleInputVisibility()">
<option value="radiogroup">Radiogroup</option>
<option value="checkbox">Checkbox</option>
<option value="text">Text</option>
<option value="ranking">Ranking</option>
<option value="boolean">Boolean</option>
<option value="dropdown">Dropdown</option>
</select>
</td>
</tr>
<tr>
<td>Required:</td>
<td>
<select name="is_required" required="required" class="form-control">
<option value="true">True</option>
<option value="false">False</option>
</select>
</td>
</tr>
<tr>
<td>Flag:</td>
<td><input type="text" name="flag" required="required" class="form-control"><br></td>
</tr>
<tr>
<td>Description:</td>
<td>
<textarea name="description" required="required" class="form-control" rows="4" cols="50">
</textarea></td>
</tr>
<tr>
<td>Group:</td>
<td>
<label><input type="checkbox" name="selectedOptions[]" value="CEO">CEO</label><br>
<label><input type="checkbox" name="selectedOptions[]" value="CFO">CFO</label><br>
<label><input type="checkbox" name="selectedOptions[]" value="CPO">CPO</label><br>
<label><input type="checkbox" name="selectedOptions[]" value="CISO">CISO</label><br>
<label><input type="checkbox" name="selectedOptions[]" value="CIO">CIO</label><br>
<label><input type="checkbox" name="selectedOptions[]" value="CTO">CTO</label><br>
</td>
</tr>
<tr>
<td>Category:</td>
<td><input type="text" name="category" required="required" class="form-control"><br></td>
</tr>
<tr>
<td>Data Capture</td>
<td><input type="text" name="data_capture" required="required" class="form-control"><br></td>
</tr>
<tr>
<td>Visible If:</td>
<td>
<label for="input1">Depends on(Question id):</label>
<input type="text" id="input1" name="visible" placeholder="Depends on">
<br><br>
<label for="input2">If Answer is:</label>
<input type="text" id="input2" name="visibleMessage" placeholder="Choice">
</td>
</tr>
<tr>
<td>Has Other options:</td>
<td>
<select name="show_other" required="required" class="form-control" id="showOtherSelect">
<option value="true">True</option>
<option value="false">False</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td></br>
<input type="SUBMIT" name="send" value="send" required="required" class="btn btn-success"><br>
</td>
</tr>
</form>
<tr><td>
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
if(isset($_REQUEST['send'])){
$name=addslashes($_POST['name']);
$title=addslashes($_POST['title']);
$type=addslashes($_POST['type']);
$is_required=addslashes($_POST['is_required']);
$flag=addslashes($_POST['flag']);
$description=addslashes($_POST['description']);
//$groupe=addslashes($_POST['groupe[]']);
$category=addslashes($_POST['category']);
$visible = addslashes($_POST['visible']);
$visibleMessage = addslashes($_POST['visibleMessage']);
$data_capture = addslashes($_POST['data_capture']);
$show_other = '';
$choices='';
$selectedOptions = $_POST['selectedOptions'];
$groupe=implode(',', $selectedOptions);
if(isset($_POST['show_other'])){
$show_other= addslashes($_POST['show_other']);
}
if(isset($_POST['choices'])){
$choices=addslashes($_POST['choices']);
}
$visibility = '{' . $visible . '} = \'' . $visibleMessage . '\'';
$visibility1 = addslashes($visibility);
include 'connect.php';
$querry="INSERT INTO `question`(`name`, `title`, `type`,`is_required`,`flag`,`description`,`groupe`,`category`,`visible_if`,`show_other`,`data_capture`)
VALUES ('$name','$title','$type','$is_required','$flag','$description','$groupe','$category','$visibility1','$show_other','$data_capture')";
$choicesQuery="INSERT INTO `choice`( `question_name`, `choice_name`)
VALUES ('$name','$choices')";
$result=$connect->query($querry);
$message='Failed';
if($result){
$result2=$connect->query($choicesQuery);
if($result2){
$message= "Querry run successifully";
}else{
echo mysqli_error($connect);
}
}else{
echo mysqli_error($connect);
}
echo $message;
mysqli_close($connect);
}
?>
</td></tr>
</div>
<script>
function toggleInputVisibility() {
var typeSelect = document.querySelector('select[name="type"]');
var showOtherSelect = document.querySelector('#showOtherSelect');
if ((typeSelect.value === 'text')||(typeSelect.value === 'boolean')) {
showOtherSelect.value = 'false';
showOtherSelect.disabled = true;
} else {
showOtherSelect.disabled = false;
}
}
</script>
</body>
</html>