-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
397 lines (370 loc) · 15.9 KB
/
test.php
File metadata and controls
397 lines (370 loc) · 15.9 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
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
{
"author_id" : 3,
"course_id" : 130,
"type" : "SERIES_QUESTIONS",
"level" : 4,
"time" : "1:10",
"tags" : "",
"is_test" : false,
"test_section" : "",
"body" : {
"description" : "In 2009, the Taiwu Elementary School Folk Singers were invited to perform in Belgium, France, Germany, and Luxemburg. In 2011, they were voted as one of the world’s top five performance groups by audiences of Japan Broadcasting Corporation’s Amazing Voice program. Recalling the group’s first tour in Europe, Camake Valaule, a physical education teacher and the founder of the Taiwu Elementary School Folk Singers, admitted that he felt very nervous. He was worried that the audience would fall asleep since most of the 75-minute performance was a cappella ... ",
"questions" : [
{
"question" : "Which of the following is true about Taiwu Elementary School Folk Singers?",
"options" : [
{
"content" : "The group was first established in 2009. ",
"is_answer" : false
},
{
"content" : "The group was founded by a PE teacher. ",
"is_answer" : true
},
{
"content" : "The singers usually sing popular folk songs.",
"is_answer" : false
},
{
"content" : "The singers learn to sing from their parents. ",
"is_answer" : false
}
]
},
{
"question" : "On his first trip to Europe, why did Camake think the audience might fall asleep? ",
"options" : [
{
"content" : "The average age of the audience was between fifty and sixty.",
"is_answer" : false
},
{
"content" : "Most of the performance was not accompanied by any instrument.",
"is_answer" : true
},
{
"content" : "Nobody could understand the language and the meaning of the songs.",
"is_answer" : false
},
{
"content" : " The audience could not visualize the theme sung by the school children.",
"is_answer" : false
}
]
}
]
}
}
<?php
include_once('api/auth.php');
include_once('mysql.php');
include_once('mongodb.php');
include_once('api/isLogin.php');
session_start();
$_SESSION['url'] = $_SERVER['REQUEST_URI'];
$author_id = $_SESSION['member_id'];
// get POST data from addExam page (exam name....)
$course_id = $_POST['course_id'];
$course_name = $_POST['course_name'];
$type = $_POST['type'];
$from_date = $_POST['from_date'];
// exam period start
$start_date = $_POST['start_date'];
$start_hour = $_POST['start_hour'];
$start_min = $_POST['start_min'];
$start_time = $start_hour . ':' . $start_min ;
$end_date = $_POST['end_date'];
$end_hour = $_POST['end_hour'];
$end_min = $_POST['end_min'];
$end_time = $end_hour . ':' . $end_min ;
// exam period end
$explanation = $_POST['explanation'];
$generateType = $_POST['generateType'];
if($generateType == "autoMode"){
$level = $_POST['level'];
$time = $_POST['time'];
$check_time = $_POST['check_time'];
$trueFalse = $_POST['trueFalse'];
$singleChoice = $_POST['singleChoice'];
$multiChoice = $_POST['multiChoice'];
$seriesQues = $_POST['seriesQues'];
}
$generate_type = 'manualMode';
// Get course meta data
$sql = "SELECT * FROM course WHERE course_id='$course_id'";
$result = mysql_query($sql);
$courseMetadata = mysql_fetch_assoc($result);
// get all questions of the course from mongo
$mongoQuery = array('course_id' => (int)$course_id);
$mon = $exercise -> find($mongoQuery) -> sort(array('create_date' => -1));
// group questions by type
$trueFalseQues = array();
$singleChoiceQues = array();
$multiChoiceQues = array();
$seriesQues = array();
foreach($mon as $data){
if($data['type'] == "TRUE_FALSE"){
$trueFalseQues[] = $data;
}else if($data['type'] == "SINGLE_CHOICE"){
$singleChoiceQues[] = $data;
}else if($data['type'] == "MULTI_CHOICE"){
$multiChoiceQues[] = $data;
}else if($data['type'] == "SERIES_QUESTIONS"){
$seriesQues[] = $data;
}
}
// start to generate exam:
$questionList = array();
$examList = array();
if ($generate_type == 'manualMode') {
$questionList['trueFalseQues'] = $trueFalseQues;
$questionList['singleChoiceQues'] = $singleChoiceQues;
$questionList['multiChoiceQues'] = $multiChoiceQues;
$questionList['seriesQues'] = $seriesQues;
}else if($generate_type == 'autoMode') {
$examList = $seriesQues;
// start auto generate exam
// randomly(Algorithmly) pick questions form grouped question to examList
// e.g. : $trueFalseQues ---- take 3 questions ----> $examlist
}
// get course chapter content from mongo
$mongoQuery = array('course_id' => (int)$course_id);
$mon = $collection -> find($mongoQuery);
foreach($mon as $data){
$courseData = $data;
break;
}
$contentData = $courseData['content'];
//all sectionName
foreach($contentData['chapters'] as $i => $chapter){
foreach($chapter['sections'] as $j => $section){
$sectionName = sprintf("%d-%d %s", $i+1, $j+1, $section['name']);
$courseURL = sprintf("../courseSections.php?course_id=%d&chapter_id=%d§ion_id=%d"
,$courseData['course_id'], $i, $j);
$sectionNameArray[$section['uid']] = $sectionName;
$courseURLArray[$section['uid']] = $courseURL;
}
}
?>
<div class="addExerciseTitle">新增題目</div>
<div class="add_userControl">
<ul class="add_tab-list">
<li><a href="#add_true_false">是非題</a></li>
<li><a href="#add_single_choice">單選題</a></li>
<li><a href="#add_multi_choice">多選題</a></li>
<li><a href="#add_series_question">題組</a></li>
</ul>
</div>
<div class="addExercise_wrap">
<!-- 是非題 -->
<form id="add_true_false" class="add_tab-content">
<div class="question_content_wrap">
<label for="question">題目</label>
<textarea class="question_textarea" name="question"></textarea>
<label for="TF_answer">本題解答</label>
<div class="opt">
<input id="true" value="true" type="radio" name="answer">
<label for="true" name="TF_answer">O</label>
<input id="false" value="false" type="radio" name="answer">
<label for="false" name="TF_answer">X</label>
</div>
<div class="tags_wrap">
<label for="tags">標籤</label>
<input type="text" class="tagsInput" name="tags" value="">
</div>
<label for="level">難易度</label>
<div class="opt">
<?php for($i=1; $i<=5; $i++){ ?>
<input id="truefalse_level<?php echo $i;?>" value="<?php echo $i;?>" type="radio" name="level">
<label for="truefalse_level<?php echo $i;?>" name="level"><?php for($j=1; $j<=$i; $j++){?>★<?php }?></label>
<?php } ?>
</div>
<label for="time">答題時間</label>
<select name="min" class="time_select min">
<?php for($i=0; $i<=30; $i++){ ?> <option value="<?php echo $i;?>"><?php echo $i;?></option> <?php } ?>
</select>
<a class="time_char">分</a>
<select name="sec" class="time_select sec">
<?php for($i=0; $i<=50; $i+=10){ ?><option value="<?php echo $i;?>"><?php echo $i;?></option> <?php }?>
</select>
<a class="time_char">秒</a>
<label for="is_test">選為隨堂練習</label>
<div class="opt">
<input id="is_test_false" target="trueFalse" value="false" type="radio" name="is_test" checked>
<label for="is_test_false" name="is_test">否</label>
<input id="is_test_true" target="trueFalse" value="true" type="radio" name="is_test">
<label for="is_test_true" name="is_test">是</label>
</div>
<div id="section_trueFalse" class="chapter_select">
<label for="section">適用章節</label>
<select class="testSection_select" name="section">
<?php
foreach($contentData['chapters'] as $i => $chapter){
$courseName = sprintf("CH%d: %s", $i+1, $chapter['name'] ); ?>
<optgroup label='<?php echo $courseName; ?>'>
<?php foreach($chapter['sections'] as $j => $section){
$sectionName = sprintf("%d-%d %s", $i+1, $j+1, $section['name']); ?>
<option value="<?php echo $section['uid'];?>"><?php echo $sectionName;?></option>
<?php } ?>
</optgroup>
<?php } ?>
</select>
</div>
</div>
<div class="resultBtn_wrap">
<a class="resultBtn save tfSave">新增此題</a>
<a class="resultBtn closeBox">關 閉</a>
</div>
<div class="spinner_wrap" style="display:none;">
<div class="spinner" >
<div class="cube1"></div>
<div class="cube2"></div>
</div>
</div>
</form>
<!-- 單選題 -->
<form id="add_single_choice" class="add_tab-content">
<div class="question_content_wrap">
<label for="question">題目</label>
<textarea class="question_textarea" name="question"></textarea>
<label for="single_opt_content">選項內容</label>
<div class="opt_content">
<?php for($i=1; $i<=4; $i++){ ?>
<div><span>(<?php echo $i;?>)</span><textarea name="single_opt_content_<?php echo $i;?>"></textarea></div>
<?php }?>
</div>
<label for="single_answer">本題解答</label>
<div class="opt">
<?php for($i=1; $i<=4; $i++){ ?>
<input id="single_opt<?php echo $i;?>" value="<?php echo $i;?>" type="radio" name="answer">
<label for="single_opt<?php echo $i;?>" name="single_answer">(<?php echo $i;?>)</label>
<?php }?>
</div>
<label for="tags">標籤</label>
<input class="tagsInput" name="tags">
<label for="level">難易度</label>
<div class="opt">
<?php for($i=1; $i<=5; $i++){ ?>
<input id="single_level<?php echo $i;?>" value="<?php echo $i;?>" type="radio" name="level">
<label for="single_level<?php echo $i;?>" name="level"><?php for($j=1; $j<=$i; $j++){?>★<?php }?></label>
<?php } ?>
</div>
<label for="time">答題時間</label>
<select name="min" class="time_select">
<?php for($i=0; $i<=30; $i++){ ?> <option value="<?php echo $i;?>"><?php echo $i;?></option> <?php } ?>
</select>
<a class="time_char">分</a>
<select name="sec" class="time_select">
<?php for($i=0; $i<=50; $i+=10){ ?><option value="<?php echo $i;?>"><?php echo $i;?></option> <?php }?>
</select>
<a class="time_char">秒</a>
<label for="is_test">選為隨堂練習</label>
<div class="opt">
<input id="is_test_false_single" target="single" value="false" type="radio" name="is_test" checked>
<label for="is_test_false_single" name="is_test">否</label>
<input id="is_test_true_single" target="single" value="true" type="radio" name="is_test">
<label for="is_test_true_single" name="is_test">是</label>
</div>
<div id="section_single" class="chapter_select">
<label for="section">適用章節</label>
<select class="testSection_select" name="section">
<?php
foreach($contentData['chapters'] as $i => $chapter){
$courseName = sprintf("CH%d: %s", $i+1, $chapter['name'] ); ?>
<optgroup label='<?php echo $courseName; ?>'>
<?php foreach($chapter['sections'] as $j => $section){
$sectionName = sprintf("%d-%d %s", $i+1, $j+1, $section['name']); ?>
<option value="<?php echo $section['uid'];?>"><?php echo $sectionName;?></option>
<?php } ?>
</optgroup>
<?php } ?>
</select>
</div>
</div>
<div class="resultBtn_wrap">
<a class="resultBtn save">新增此題</a>
<a class="resultBtn closeBox">關 閉</a>
</div>
</form>
<!-- 多選題 -->
<form id="add_multi_choice" class="add_tab-content">
<div class="question_content_wrap">
<label for="question">題目</label>
<textarea class="question_textarea" name="question"></textarea>
<label for="single_opt_content">選項內容</label>
<div class="opt_content">
<?php for($i=1; $i<=5; $i++){ ?>
<div><span>(<?php echo $i;?>)</span><textarea name="multi_opt_content_<?php echo $i;?>"></textarea></div>
<?php } ?>
</div>
<label for="single_answer">本題解答</label>
<div class="opt">
<?php for($i=1; $i<=5; $i++){ ?>
<input id="multi_opt<?php echo $i;?>" value="<?php echo $i;?>" type="checkbox" name="answer[]">
<label for="multi_opt<?php echo $i;?>" name="single_answer">(<?php echo $i;?>)</label>
<?php } ?>
</div>
<label for="tags">標籤</label>
<input class="tagsInput" name="tags">
<label for="level">難易度</label>
<div class="opt">
<?php for($i=1; $i<=5; $i++){ ?>
<input id="multi_level<?php echo $i;?>" value="<?php echo $i;?>" type="radio" name="level">
<label for="multi_level<?php echo $i;?>" name="level"><?php for($j=1; $j<=$i; $j++){?>★<?php }?></label>
<?php } ?>
</div>
<label for="time">答題時間</label>
<select name="min" class="time_select">
<?php for($i=0; $i<=30; $i++){ ?> <option value="<?php echo $i;?>"><?php echo $i;?></option> <?php } ?>
</select>
<a class="time_char">分</a>
<select name="sec" class="time_select">
<?php for($i=0; $i<=50; $i+=10){ ?><option value="<?php echo $i;?>"><?php echo $i;?></option> <?php }?>
</select>
<a class="time_char">秒</a>
<label for="is_test">選為隨堂練習</label>
<div class="opt">
<input id="is_test_false_multi" target="multi" value="false" type="radio" name="is_test" checked>
<label for="is_test_false_multi" name="is_test">否</label>
<input id="is_test_true_multi" target="multi" value="true" type="radio" name="is_test">
<label for="is_test_true_multi" name="is_test">是</label>
</div>
<div id="section_multi" class="chapter_select">
<label for="section">適用章節</label>
<select class="testSection_select" name="section">
<?php
foreach($contentData['chapters'] as $i => $chapter){
$courseName = sprintf("CH%d: %s", $i+1, $chapter['name'] ); ?>
<optgroup label='<?php echo $courseName; ?>'>
<?php foreach($chapter['sections'] as $j => $section){
$sectionName = sprintf("%d-%d %s", $i+1, $j+1, $section['name']); ?>
<option value="<?php echo $section['uid'];?>"><?php echo $sectionName;?></option>
<?php } ?>
</optgroup>
<?php } ?>
</select>
</div>
</div>
<div class="resultBtn_wrap">
<a class="resultBtn save">新增此題</a>
<a class="resultBtn closeBox">關 閉</a>
</div>
</form>
<!-- 題組 -->
<form id="add_series_question" class="add_tab-content">
<div class="resultBtn_wrap">
<a class="resultBtn save">新增此題</a>
<a class="resultBtn closeBox">關 閉</a>
</div>
</form>
<input id="author_id" type="hidden" value="<?php echo $author_id;?>">
<?php
$sectionNameArray_Iterator = new ArrayIterator($sectionNameArray);
$courseURLArray_Iterator = new ArrayIterator($courseURLArray);
$combine = new MultipleIterator;
$combine->attachIterator($sectionNameArray_Iterator);
$combine->attachIterator($courseURLArray_Iterator);
foreach($combine as $key => $Item){ ?>
<input id="key<?php echo $key[0];?>" type="hidden" data-section-name="<?php echo $Item[0];?>" data-course-url="<?php echo $Item[1];?>">
<?php } ?>
</div>