/
dragDrop.php
232 lines (195 loc) · 8.5 KB
/
dragDrop.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
<?php
include('cookie.php');
?>
<?php
include('config.inc');
$db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base);
$examid = $_GET['examid'];
if ($_POST['submit'] == "Save Question")
{
$examid = $_POST['examid'];
$question = addslashes(trim($_POST['question']));
if (($_POST['choice1a']) && ($_POST['choice1b']))
{
$choice1 = addslashes(trim($_POST['choice1a']));
$choice1 .= " -1-1-1- ";
$choice1 .= addslashes(trim($_POST['choice1b']));
}
if (($_POST['choice2a']) && ($_POST['choice2b']))
{
$choice2 = addslashes(trim($_POST['choice2a']));
$choice2 .= " -1-1-1- ";
$choice2 .= addslashes(trim($_POST['choice2b']));
}
if (($_POST['choice3a']) && ($_POST['choice3b']))
{
$choice3 = addslashes(trim($_POST['choice3a']));
$choice3 .= " -1-1-1- ";
$choice3 .= addslashes(trim($_POST['choice3b']));
}
if (($_POST['choice4a']) && ($_POST['choice4b']))
{
$choice4 = addslashes(trim($_POST['choice4a']));
$choice4 .= " -1-1-1- ";
$choice4 .= addslashes(trim($_POST['choice4b']));
}
if (($_POST['choice5a']) && ($_POST['choice5b']))
{
$choice5 = addslashes(trim($_POST['choice5a']));
$choice5 .= " -1-1-1- ";
$choice5 .= addslashes(trim($_POST['choice5b']));
}
if (($_POST['choice6a']) && ($_POST['choice6b']))
{
$choice6 = addslashes(trim($_POST['choice6a']));
$choice6 .= " -1-1-1- ";
$choice6 .= addslashes(trim($_POST['choice6b']));
}
$feedback = addslashes(trim($_POST['feedback']));
$category = addslashes(trim($_POST['category']));
$reference = addslashes(trim($_POST['reference']));
$answer ="DRAG";
if ($category == '')
$category = 'None';
$result = mysqli_query($db_connect,"SELECT CURDATE()");
$row = mysqli_fetch_row($result);
$date = $row[0];
$query = "insert into question (questionid,question,choice1,choice2,choice3,choice4,choice5,choice6,answer,date,feedback,category,reference, examid,type ) VALUES (NULL, '$question', '$choice1', '$choice2', '$choice3', '$choice4', '$choice5', '$choice6', '$answer', '$date','$feedback', '$category', '$reference', '$examid', 'dd')";
$result = mysqli_query($db_connect,$query);
$query = mysqli_query($db_connect,"SELECT LAST_INSERT_ID()");
$row = mysqli_fetch_row($query);
$questionid = $row[0];
if ($HTTP_POST_FILES['image']['tmp_name'])
{
$description = $_POST['description'];
// get height and width of image
$imagehw = getimagesize($HTTP_POST_FILES['image']['tmp_name']);
// prepare the image for inserting into the database
// $data = addslashes(fread(fopen($HTTP_POST_FILES['image']['tmp_name'],"r"), filesize($HTTP_POST_FILES['image']['tmp_name'])));
// if the user didn't fill in a description, add a default.
$description = ($description == '') ? 'Attached image' : $description;
$width = $imagehw[0] + 50;
$height = $imagehw[1] + 50;
$type = $HTTP_POST_FILES['image']['type'];
$name = $HTTP_POST_FILES['image']['name'];
$size = $HTTP_POST_FILES['image']['size'];
$query = mysqli_query($db_connect,"INSERT INTO images(imageid,questionid,description,filename,filesize,width,height,filetype) values(NULL,'$questionid', '$description', '$name','$size','$width','$height','$type')");
##################################################
$data = fread(fopen($HTTP_POST_FILES['image']['tmp_name'],"r"), filesize($HTTP_POST_FILES['image']['tmp_name']));
$fd = fopen("images/$name", "w");
$fout = fwrite($fd,$data);
fclose($fd);
##################################################
}
$message = "Question Added Sucessfully";
}
$result = mysqli_query($db_connect,"SELECT DISTINCT category FROM question where examid = '$examid' ");
?>
<html>
<head>
<title>Online-test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script LANGUAGE="JavaScript">
<!-- Begin
function validate()
{
validity = true; // assume valid
if (!check_empty(document.form.question.value))
{ validity = false; alert('The Question is missing.'); }
else if (((!check_empty(document.form.choice1a.value))||(!check_empty(document.form.choice1b.value))) && ((!check_empty(document.form.choice2a.value))||(!check_empty(document.form.choice2b.value))) && ((!check_empty(document.form.choice3a.value))||(!check_empty(document.form.choice3b.value))) && ((!check_empty(document.form.choice4a.value))||(!check_empty(document.form.choice4b.value))) && ((!check_empty(document.form.choice5a.value))||(!check_empty(document.form.choice5b.value))) && ((!check_empty(document.form.choice6a.value))||(!check_empty(document.form.choice6b.value))))
{ validity = false; alert('No Answers, Please give a Answer'); }
else if ((!check_empty(document.form.feedback.value)))
{ validity = false; alert('No Feedback, Please give a Feedback'); }
return validity;
}
function check_empty(text) {
return (text.length > 0); // returns false if empty
}
// End -->
</script>
<link REL=StyleSheet HREF="style.css" TYPE="text/css">
</head>
<body>
<div align="right"><small><a href="javascript:onclick=parent.resizeFrame('0,*')">Change Screen Layout</a><BR><small>(click for fullscreen and click again for normal screen)</small></small></div>
<h3>Matching Question</h3>
<font color=GREEN><?php print("$message") ?></font><BR>
<table border='0' width="100%">
<form name="form" enctype="multipart/form-data" action="dragDrop.php" method="post" onsubmit="return validate()">
<tr>
<td align='right' bgcolor='#dfdfdf'> Category</td>
<td colspan='2'><input name='category' type='text' value='' size='20'>
<select name='Schapter' onblur='this.form.category.value=this.form.Schapter.value'>
<?php
print("<option value=None>None");
while($cat = mysqli_fetch_row($result))
{
if ($cat[0] != "None")
print("<option value=\"$cat[0]\">$cat[0]");
}
?>
</select>
<small>Type in a category or choose from the list.</small>
</td>
</tr>
<tr>
<td valign=top align='right' bgcolor='#dfdfdf'>Question</td>
<td colspan='2'><textarea name='question' rows='4' cols='60'></textarea></td>
</tr>
<tr>
<td align='right' bgcolor='#dfdfdf'> A)</td>
<td><textarea name='choice1a' rows='2' cols='20'></textarea></td>
<td><textarea name='choice1b' rows='2' cols='20'></textarea></td>
</tr>
<tr>
<td align='right' bgcolor='#dfdfdf'> B)</td>
<td><textarea name='choice2a' rows='2' cols='20'></textarea></td>
<td><textarea name='choice2b' rows='2' cols='20'></textarea></td>
</tr>
<tr>
<td align='right' bgcolor='#dfdfdf'> C)</td>
<td><textarea name='choice3a' rows='2' cols='20'></textarea></td>
<td><textarea name='choice3b' rows='2' cols='20'></textarea></td>
</tr>
<tr>
<td align='right' bgcolor='#dfdfdf'> D)</td>
<td><textarea name='choice4a' rows='2' cols='20'></textarea></td>
<td><textarea name='choice4b' rows='2' cols='20'></textarea></td>
</tr>
<tr>
<td align='right' bgcolor='#dfdfdf'> E)</td>
<td><textarea name='choice5a' rows='2' cols='20'></textarea></td>
<td><textarea name='choice5b' rows='2' cols='20'></textarea></td>
</tr>
<tr>
<td align='right' bgcolor='#dfdfdf'> F)</td>
<td><textarea name='choice6a' rows='2' cols='20'></textarea></td>
<td><textarea name='choice6b' rows='2' cols='20'></textarea></td>
</tr>
<tr>
<td align='right' bgcolor='#dfdfdf'> Feedback </td>
<td colspan=2><textarea name='feedback' rows='5' cols='65'></textarea></td>
</tr>
<tr>
<td align='right' bgcolor='#dfdfdf'> Reference </td>
<td colspan=2><input type="text" name='reference' length='20' maxlength='50'></td>
</tr>
<tr>
<td align='right' bgcolor='#dfdfdf'> Image </td>
<td colspan=2><input type="file" name="image"> </td>
</tr>
<tr>
<td align='right' bgcolor='#dfdfdf'> description </td>
<td colspan=2><input type="text" name="description" value=""> </td>
</tr>
<tr>
<td align='right' bgcolor='#dfdfdf'> <input name="examid" type="hidden" value=<?php print("$examid") ?> ></td>
<td colspan='2'><br><input type="submit" name='submit' value='Save Question'></td>
</tr>
<tr>
<td align='right' bgcolor='#dfdfdf'> </td>
<td colspan=2><a href="createTest.php?examid=<?php print $examid ?>"> Add another Types of question</a></td>
</tr>
</form>
</table>
</body>
</html>