-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester_goman.php
421 lines (336 loc) · 10.5 KB
/
tester_goman.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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<?php
#
# tester_hangee.php
#
# Written by HyoGi Sim <sandrain@gmail.com>
#
require_once("__lib.php");
hangee_init(1);
###########################################################################
function do_add_test_words($form)
{
global $dbconn;
global $table_rows;
global $uid;
global $testwords;
$ch = $form['word_select'];
$marked = $form['marked'];
if (!$ch)
return;
$session_str = sprintf("%02d%s", $ch, $marked);
$page = 500 + (int) $ch;
$sql = "select count(*) from hangee_words where page=$page";
if ($marked == "m") {
$op = $form['mc_op'];
$mc = $form['mc_sel'];
$session_str .= $op.$mc;
switch ($op) {
case 'eq': $cond = "count = $mc"; break;
case 'gt': $cond = "count >= $mc"; break;
case 'lt': $cond = "count <= $mc"; break;
default: break;
}
$sql .= " and id in (select wid from hangee_marked where uid=$uid and $cond)";
}
else if ($marked == "n") {
$session_str .= "000";
$sql .= " and id not in (select wid from hangee_marked where uid=$uid)";
}
else { // $marked == 'a'
$session_str .= "000";
}
$res = mysql_query($sql, $dbconn);
if (!$res) {
$msg = "query failed: $sql : ".mysql_error($dbconn);
return $msg;
}
$row = mysql_fetch_array($res);
$count = $row[0];
if (isset($_SESSION['testwords'])) {
$testwords = $_SESSION['testwords'];
if (strstr($testwords, $ch)) {
$msg = "DAY $ch is already in the list!";
$msg.= "::<b>$testwords</b>";
return $msg;
}
$_SESSION['testwords'] .= ":".$session_str;
}
else
$_SESSION['testwords'] = $session_str;
$html = "<p><strong>DAY $ch</strong>, <strong>$count</strong> words</p>";
return $html;
}
function add_test_words($form)
{
$ch = strtolower($form['word_select']);
if ($ch == 'all') {
for ($i = 1; $i <= 24; $i++) {
$form['word_select'] = $i;
$html.= do_add_test_words($form);
}
}
else
$html = do_add_test_words($form);
$response = new xajaxResponse();
$response->append("word_browser", "innerHTML", $html);
$response->assign("start_button", "style.display", "block");
$response->assign("word_browser", "style.display", "block");
$response->assign("result", "style.display", "none");
return $response;
}
function start_test($random)
{
global $dbconn;
global $uid;
$response = new xajaxResponse();
$testwords = $_SESSION['testwords'];
$testcrc = crc32($testwords + (string) time());
//$sql = "delete from hangee_test where uid = $uid and testcrc <> $testcrc";
$sql = "delete from hangee_test where uid = $uid";
$res = mysql_query($sql, $dbconn);
if (!$res) {
$msg = "query failed: $sql : ".mysql_error($dbconn);
$response->assign("result", "innerHTML", $msg);
$response->assign("result", "style.display", "block");
return $response;
}
$chunks = explode(":", $testwords);
foreach ($chunks as $chunk) {
$page = 500 + ((int) substr($chunk, 0, 2));
$marked = substr($chunk, -4, 1);
$sql = "select id from hangee_words where page=$page ";
switch ($marked) {
case 'a': break; // All words, do nothing
case 'm': // Marked only
$op = substr($chunk, -3, 2);
$mc = substr($chunk, -1, 1);
switch ($op) {
case 'eq': $cond = "count = $mc"; break;
case 'gt': $cond = "count >= $mc"; break;
case 'lt': $cond = "count <= $mc"; break;
default: break;
}
$sql .= " and id in (select wid from hangee_marked where uid=$uid and $cond)";
break;
case 'n': // Not marked only
$sql .= " and id not in (select wid from hangee_marked where uid=$uid)";
break;
default: break;
}
/*
$msg = "$marked:$sql";
$response->assign("result", "innerHTML", $msg);
$response->assign("result", "style.display", "block");
return $response;
*/
$res = mysql_query($sql, $dbconn);
if (!$res) {
$msg = "query failed: $sql : ".mysql_error($dbconn);
$response->assign("result", "innerHTML", $msg);
$response->assign("result", "style.display", "block");
}
$rows = array();
while ($row = mysql_fetch_assoc($res))
$rows[] = $row;
foreach ($rows as $row) {
$wid = $row['id'];
$sql = "insert into hangee_test (uid, wid, testcrc) "
."values ($uid, $wid, $testcrc)";
$res = mysql_query($sql, $dbconn);
if (!$res) {
$msg = "query failed: $sql : ".mysql_error($dbconn);
$response->assign("result", "innerHTML", $msg);
$response->assign("result", "style.display", "block");
}
}
}
$sql = "select id,wid from hangee_test where uid=$uid and testcrc=$testcrc ";
if ($random)
$sql .= "order by rand()";
else
$sql .= "order by wid asc";
$res = mysql_query($sql, $dbconn);
if (!$res) {
$msg = "query failed: $sql : ".mysql_error($dbconn);
$response->assign("result", "innerHTML", $msg);
$response->assign("result", "style.display", "block");
return $response;
}
$rows = array();
while ($row = mysql_fetch_assoc($res))
$rows[] = $row;
$seq = 1;
$msg = $random;
foreach ($rows as $row) {
$id = $row['id'];
$sql = "update hangee_test set seq=$seq where id=$id";
$res = mysql_query($sql, $dbconn);
if (!$res) {
$msg = "query failed: $sql : ".mysql_error($dbconn);
$response->assign("result", "innerHTML", $msg);
$response->assign("result", "style.display", "block");
return $response;
}
$seq++;
}
$sql = "update hangee_users set testcrc = $testcrc, testpos = 1 where id=$uid";
$res = mysql_query($sql, $dbconn);
if (!$res) {
$msg = "query failed: $sql : ".mysql_error($dbconn);
$response->assign("result", "innerHTML", $msg);
$response->assign("result", "style.display", "block");
return $response;
}
$_SESSION['testcrc'] = $testcrc;
$_SESSION['testpos'] = 1;
unset ($_SESSION['testwords']);
$response->script("document.location.href='display.php'");
return $response;
}
function clear_list()
{
$response = new xajaxResponse();
unset($_SESSION['testwords']);
$response->assign("word_browser", "innerHTML", "");
$response->assign("word_browser", "style.display", "none");
$response->assign("start_button", "style.display", "none");
return $response;
}
function check_registered_test()
{
global $uid;
global $dbconn;
$sql = "select testcrc from hangee_users where id=$uid";
$res = mysql_query($sql, $dbconn);
if (!$res)
die ("query failed: $sql : ".mysql_error($dbconn));
$row = mysql_fetch_array($res);
$testcrc = $row['testcrc'];
if ($testcrc == 0)
return false;
if (isset($_SESSION['testcrc']) && $_SESSION['testcrc'] != $testcrc)
return false;
$sql = "select count(*) from hangee_test where uid=$uid and testcrc=$testcrc";
$res = mysql_query($sql, $dbconn);
if (!$res)
die ("query failed: $sql : ".mysql_error($dbconn));
$row = mysql_fetch_array($res);
$count = $row[0];
if ($count > 0) {
$_SESSION['testcrc'] = $testcrc;
return true;
}
return false;
}
function register_new_test()
{
global $dbconn;
global $uid;
$response = new xajaxResponse();
if (isset($_SESSION['testwords']))
unset($_SESSION['testwords']);
if (isset($_SESSION['testpos']))
unset($_SESSION['testpos']);
if (isset($_SESSION['maxseq']))
unset($_SESSION['maxseq']);
if (isset($_SESSION['testcrc']))
unset($_SESSION['testcrc']);
$sql = "update hangee_users set testcrc = 0, testpos = 0 where id=$uid";
$res = mysql_query($sql, $dbconn);
if (!$res) {
$msg = "query failed: $sql : ".mysql_error($dbconn);
$response->assign("result", "innerHTML", $msg);
$response->assign("result", "style.display", "block");
return $response;
}
$sql = "delete from hangee_test where uid=$uid";
$res = mysql_query($sql, $dbconn);
if (!$res) {
$msg = "query failed: $sql : ".mysql_error($dbconn);
$response->assign("result", "innerHTML", $msg);
$response->assign("result", "style.display", "block");
return $response;
}
$response->script("document.location.href='tester_goman.php'");
return $response;
}
$xajax = new xajax();
$xajax->registerFunction("add_test_words");
$xajax->registerFunction("start_test");
$xajax->registerFunction("clear_list");
$xajax->registerFunction("register_new_test");
$xajax->processRequest();
###########################################################################
hangee_header("HanGEE: Tester");
$xajax->printJavascript("xajax");
?>
<script language='javascript' type='text/javascript'>
<!--//
function destroy_test_condition()
{
if (confirm('Are you sure?'))
xajax_register_new_test();
return;
}
function show_mpref()
{
var mpref = document.getElementById('mpref');
mpref.style.display = 'inline-block';
}
function hide_mpref()
{
var mpref = document.getElementById('mpref');
mpref.style.display = 'none';
}
//-->
</script>
<?php if (check_registered_test()) { // if a test already registered for this user ?>
<div id="word_browser" style='display:block'>
<p>There exists a test that you haven't finished, yet. Do you like to resume it?</p>
<p><button onClick='document.location.href = "display.php";'>Resume</button>
<button onClick='destroy_test_condition();'>Destroy it</button></p>
</div>
<?php } else { //////////////////////// if not registed ////////////////////////// ?>
<div id="navigation">
<p> <!--// HanGEE //-->
<form id="test_select_form" onSubmit='javascript:void(0); return false;'>
GoMAN:
<select id="word_select" name="word_select">
<option value="0">Select DAY</option>
<?php
for ($i = 1; $i <= 24; $i++) {
echo "<option value=\"$i\">DAY $i</option>";
}
?>
<option value="all">ALL</option>
</select>
<input type="radio" name="marked" value="a" onClick="hide_mpref();" checked/> <label for="marked">ALL</label>
<input type="radio" name="marked" value="m" onClick="show_mpref();" /> <label for="marked">Marked Only</label>
<input type="radio" name="marked" value="n" onClick="hide_mpref();" /> <label for="marked">Not Marked Only</label>
<span id='mpref' style='margin-left:10px; margin-right: 10px; display:none;'>( Marked count
<select name='mc_op'>
<option value='gt' selected> >= </option>
<option value='lt'> <= </option>
<option value='eq'> == </option>
</select>
<select name='mc_sel'>
<option value='1' selected>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
</select> )
</span>
<button onClick="xajax_add_test_words(xajax.getFormValues('test_select_form'));">ADD</button>
</form>
</p>
</div>
<div id="word_browser"></div>
<div id="start_button">
<button onClick="xajax_start_test(confirm('Do you like to test in random order?'));">Start the Test</button>
<button onClick="xajax_clear_list();">Clear</button>
</div>
<?php } /////////////////////////////// end of if ////////////////////////////////
hangee_footer();
hangee_exit();
?>