forked from edoreld/learning-with-texts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
do_test_test.php
executable file
·315 lines (268 loc) · 11.3 KB
/
do_test_test.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
<?php
/**************************************************************
"Learning with Texts" (LWT) is free and unencumbered software
released into the PUBLIC DOMAIN.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a
compiled binary, for any purpose, commercial or non-commercial,
and by any means.
In jurisdictions that recognize copyright laws, the author or
authors of this software dedicate any and all copyright
interest in the software to the public domain. We make this
dedication for the benefit of the public at large and to the
detriment of our heirs and successors. We intend this
dedication to be an overt act of relinquishment in perpetuity
of all present and future rights to this software under
copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
For more information, please refer to [http://unlicense.org/].
***************************************************************/
/**************************************************************
Call: do_test_test.php?type=[testtype]&lang=[langid]
Call: do_test_test.php?type=[testtype]&text=[textid]
Call: do_test_test.php?type=[testtype]&selection=1
(SQL via $_SESSION['testsql'])
Show test frame
***************************************************************/
require_once( 'settings.inc.php' );
require_once( 'connect.inc.php' );
require_once( 'dbutils.inc.php' );
require_once( 'utilities.inc.php' );
$p = '';
if (isset($_REQUEST['selection']) && isset($_SESSION['testsql'])) {
$testsql = $_SESSION['testsql'];
}
elseif (isset($_REQUEST['lang'])) {
$testsql = ' ' . $tbpref . 'words where WoLgID = ' . $_REQUEST['lang'] . ' ';
}
elseif (isset($_REQUEST['text'])) {
$testsql = ' ' . $tbpref . 'words, ' . $tbpref . 'textitems where TiLgID = WoLgID and TiTextLC = WoTextLC and TiTxID = ' . $_REQUEST['text'] . ' ';
}
else my_die("do_test_test.php called with wrong parameters");
$testtype = getreq('type') + 0;
if ($testtype < 1) $testtype=1;
if ($testtype > 5) $testtype=5;
$nosent = 0;
if ($testtype > 3) {
$testtype = $testtype - 3;
$nosent = 1;
}
$totaltests = $_SESSION['testtotal'];
$wrong = $_SESSION['testwrong'];
$correct = $_SESSION['testcorrect'];
pagestart_nobody('','html, body { width:100%; height:100%; } html {display:table;} body { display:table-cell; vertical-align:middle; } #body { max-width:95%; margin:0 auto; }');
$cntlang = get_first_value('select count(distinct WoLgID) as value from ' . $testsql);
if ($cntlang > 1) {
echo '<p>Sorry - The selected terms are in ' . $cntlang . ' languages, but tests are only possible in one language at a time.</p>';
pageend();
exit();
}
?>
<div id="body">
<?php
$count = get_first_value('SELECT count(distinct WoID) as value FROM ' . $testsql . ' AND WoStatus BETWEEN 1 AND 5 AND WoTranslation != \'\' AND WoTranslation != \'*\' AND WoTodayScore < 0');
if ($debug) echo 'DEBUG - COUNT TO TEST: ' . $count . '<br />';
$notyettested = $count;
if ($count <= 0) {
$count2 = get_first_value('SELECT count(distinct WoID) as value FROM ' . $testsql . ' AND WoStatus BETWEEN 1 AND 5 AND WoTranslation != \'\' AND WoTranslation != \'*\' AND WoTomorrowScore < 0');
echo '<p class="center"><img src="img/ok.png" alt="Done!" /><br /><br /><span class="red2">Nothing ' . ($totaltests ? 'more ' : '') . 'to test here!<br /><br />Tomorrow you\'ll find here ' . $count2 . ' test' . ($count2 == 1 ? '' : 's') . '!</span></p></div>';
$count = 0;
} else {
$lang = get_first_value('select WoLgID as value from ' . $testsql . ' limit 1');
$sql = 'select LgName, LgDict1URI, LgDict2URI, LgGoogleTranslateURI, LgTextSize, LgRemoveSpaces, LgRegexpWordCharacters, LgRightToLeft from ' . $tbpref . 'languages where LgID = ' . $lang;
$res = do_mysqli_query($sql);
$record = mysqli_fetch_assoc($res);
$wb1 = isset($record['LgDict1URI']) ? $record['LgDict1URI'] : "";
$wb2 = isset($record['LgDict2URI']) ? $record['LgDict2URI'] : "";
$wb3 = isset($record['LgGoogleTranslateURI']) ? $record['LgGoogleTranslateURI'] : "";
$textsize = $record['LgTextSize'];
$removeSpaces = $record['LgRemoveSpaces'];
$regexword = $record['LgRegexpWordCharacters'];
$rtlScript = $record['LgRightToLeft'];
$langname = $record['LgName'];
mysqli_free_result($res);
// Find the next word to test
$pass = 0;
$num = 0;
while ($pass < 2) {
$pass++;
$sql = 'SELECT DISTINCT WoID, WoText, WoTextLC, WoTranslation, WoRomanization, WoSentence, (ifnull(WoSentence,\'\') not like concat(\'%{\',WoText,\'}%\')) as notvalid, WoStatus, DATEDIFF( NOW( ), WoStatusChanged ) AS Days, WoTodayScore AS Score FROM ' . $testsql . ' AND WoStatus BETWEEN 1 AND 5 AND WoTranslation != \'\' AND WoTranslation != \'*\' AND WoTodayScore < 0 ' . ($pass == 1 ? 'AND WoRandom > RAND()' : '') . ' order by WoTodayScore, WoRandom LIMIT 1';
if ($debug) echo 'DEBUG TEST-SQL: ' . $sql . '<br />';
$res = do_mysqli_query($sql);
$record = mysqli_fetch_assoc($res);
if ( $record ) {
$num = 1;
$wid = $record['WoID'];
$word = $record['WoText'];
$wordlc = $record['WoTextLC'];
$trans = repl_tab_nl($record['WoTranslation']) . getWordTagList($wid,' ',1,0);
$roman = $record['WoRomanization'];
$sent = repl_tab_nl($record['WoSentence']);
$notvalid = $record['notvalid'];
$status = $record['WoStatus'];
$days = $record['Days'];
$score = $record['Score'];
$pass = 2;
}
mysqli_free_result($res);
}
if ($num == 0) {
// should not occur but...
echo '<p class="center"><img src="img/ok.png" alt="Done!" /><br /><br /><span class="red2">Nothing to test here!</span></p></div>';
$count = 0;
} else {
if ( $nosent) { // No sent. mode 4+5
$num = 0;
$notvalid = 1;
}
else { // $nosent == FALSE, mode 1-3
$pass = 0;
$sentexcl = '';
while ( $pass < 3 ) {
$pass++;
if ($debug) echo "DEBUG search sent: pass: $pass <br />";
$sql = 'SELECT DISTINCT SeID FROM ' . $tbpref . 'sentences, ' . $tbpref . 'textitems WHERE TiTextLC = ' . convert_string_to_sqlsyntax($wordlc) . $sentexcl . ' AND SeID = TiSeID AND SeLgID = ' . $lang . ' order by rand() limit 1';
$res = do_mysqli_query($sql);
$record = mysqli_fetch_assoc($res);
if ( $record ) { // random sent found
$num = 1;
$seid = $record['SeID'];
if (AreUnknownWordsInSentence ($seid)) {
if ($debug) echo "DEBUG sent: $seid has unknown words<br />";
$sentexcl = ' AND SeID != ' . $seid . ' ';
$num = 0;
// not yet found, $num == 0 (unknown words in sent)
} else {
// echo ' OK ';
$sent = getSentence($seid, $wordlc, (int) getSettingWithDefault('set-test-sentence-count'));
$sent = $sent[1];
if ($debug) echo "DEBUG sent: $seid OK: $sent <br />";
$pass = 3;
// found, $num == 1
}
} else { // no random sent found
$num = 0;
$pass = 3;
if ($debug) echo "DEBUG no random sent found<br />";
// no sent. take term sent. $num == 0
}
mysqli_free_result($res);
} // while ( $pass < 3 )
} // $nosent == FALSE
if ($num == 0 ) {
// take term sent. if valid
if ($notvalid) $sent = '{' . $word . '}';
if ($debug) echo "DEBUG not found, use sent = $sent<br />";
}
$cleansent = trim(str_replace("{", '', str_replace("}", '', $sent)));
// echo $cleansent;
echo '<p ' . ($rtlScript ? 'dir="rtl"' : '') . ' style="' . ($removeSpaces ? 'word-break:break-all;' : '') . 'font-size:' . $textsize . '%;line-height: 1.4; text-align:center; margin-bottom:300px;">';
$l = mb_strlen($sent,'utf-8');
$r = '';
$save = '';
$on = 0;
for ($i=0; $i < $l; $i++) { // go thru sent
$c = mb_substr($sent, $i, 1, 'UTF-8');
if ($c == '}') {
$r .= ' <span style="word-break:normal;" class="click todo todosty word wsty word' . $wid . '" data_wid="' . $wid . '" data_trans="' . tohtml($trans) . '" data_text="' . tohtml($word) . '" data_rom="' . tohtml($roman) . '" data_sent="' . tohtml($cleansent) . '" data_status="' . $status . '" data_todo="1"';
if ($testtype ==3) $r .= ' title="' . tohtml($trans) . '"';
$r .= '>';
if ($testtype == 2) {
if ($nosent) $r .= tohtml($trans);
else $r .= '<span dir="ltr">[' . tohtml($trans) . ']</span>';
}
elseif ($testtype == 3)
$r .= tohtml(str_replace("{", '[', str_replace("}", ']',
mask_term_in_sentence('{' . $save . '}',
$regexword) )));
else
$r .= tohtml($save);
$r .= '</span> ';
$on = 0;
}
elseif ($c == '{') {
$on = 1;
$save = '';
}
else {
if ( $on ) $save .= $c;
else $r .= tohtml($c);
}
} // for: go thru sent
echo $r; // Show Sentence
}
?>
<script type="text/javascript">
//<![CDATA[
WBLINK1 = '<?php echo $wb1; ?>';
WBLINK2 = '<?php echo $wb2; ?>';
WBLINK3 = '<?php echo $wb3; ?>';
SOLUTION = <?php echo prepare_textdata_js ( $testtype==1 ? ( $nosent ? ($trans) : (' [' . $trans . '] ')) : $save ); ?>;
OPENED = 0;
WID = <?php echo $wid; ?>;
$(document).ready( function() {
$(document).keydown(keydown_event_do_test_test);
$('.word').click(word_click_event_do_test_test);
});
//]]>
</script>
</p></div>
<?php
}
$wrong = $_SESSION['testwrong'];
$correct = $_SESSION['testcorrect'];
$totaltests = $wrong + $correct + $notyettested;
$totaltestsdiv = 1;
if ($totaltests > 0) $totaltestsdiv = 1.0/$totaltests;
$l_notyet = round(($notyettested * $totaltestsdiv)*100,0);
$b_notyet = ($l_notyet == 0) ? '' : 'borderl';
$l_wrong = round(($wrong * $totaltestsdiv)*100,0);
$b_wrong = ($l_wrong == 0) ? '' : 'borderl';
$l_correct = round(($correct * $totaltestsdiv)*100,0);
$b_correct = ($l_correct == 0) ? 'borderr' : 'borderl borderr';
?>
<div id="footer">
<img src="icn/clock.png" title="Elapsed Time" alt="Elapsed Time" />
<span id="timer" title="Elapsed Time"></span>
<img class="<?php echo $b_notyet; ?>" src="icn/test_notyet.png" title="Not yet tested" alt="Not yet tested" height="10" width="<?php echo $l_notyet; ?>" /><img class="<?php echo $b_wrong; ?>" src="icn/test_wrong.png" title="Wrong" alt="Wrong" height="10" width="<?php echo $l_wrong; ?>" /><img class="<?php echo $b_correct; ?>" src="icn/test_correct.png" title="Correct" alt="Correct" height="10" width="<?php echo $l_correct; ?>" />
<span title="Total number of tests"><?php echo $totaltests; ?></span>
=
<span class="todosty" title="Not yet tested"><?php echo $notyettested; ?></span>
+
<span class="donewrongsty" title="Wrong"><?php echo $wrong; ?></span>
+
<span class="doneoksty" title="Correct"><?php echo $correct; ?></span>
</div>
<script type="text/javascript">
//<![CDATA[
$(document).ready( function() {
window.parent.frames['ru'].location.href='empty.htm';
<?php
$waittime = getSettingWithDefault('set-test-edit-frame-waiting-time') + 0;
if ($waittime <= 0 ) {
?>
window.parent.frames['ro'].location.href='empty.htm';
<?php
} else {
?>
setTimeout('window.parent.frames[\'ro\'].location.href=\'empty.htm\';', <?php echo $waittime; ?>);
<?php
}
?>
new CountUp(<?php echo time() . ', ' . $_SESSION['teststart']; ?>,
'timer', <?php echo ($count ? 0 : 1); ?>);
});
//]]>
</script>
<?php
pageend();
?>