Skip to content

Commit 7e084f9

Browse files
committed
Fixed test table.
Now all the test part works with less frames. Fixed the wrong rendering of tests when crashing.
1 parent ed5468e commit 7e084f9

4 files changed

Lines changed: 138 additions & 68 deletions

File tree

‎do_test.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
require_once 'vendor/mobiledetect/mobiledetectlib/Mobile_Detect.php';
2121
require_once 'do_test_header.php';
2222
require_once 'do_test_test.php';
23+
require_once 'do_test_table.php';
2324

2425
/**
2526
* Return true if we should use mobile mode.
@@ -271,7 +272,11 @@ function do_test_desktop_page($property)
271272
<hr />
272273
<div id="frame-l">
273274
<?php
274-
do_test_test_content();
275+
if (getreq('type') == 'table') {
276+
do_test_table();
277+
} else {
278+
do_test_test_content();
279+
}
275280
?>
276281
</div>
277282
</div>

‎do_test_header.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ function startWordTest(type, property) {
189189
function startTestTable(property) {
190190
resetFrames();
191191
//parent.frames['l'].location.href='do_test_table.php?' + property;
192-
window.location.href='do_test_table.php?' + property;
192+
//window.location.href='do_test_table.php?' + property;
193+
window.location.href = 'do_test.php?type=table&' + property;
193194
}
194195
</script>
195196
<?php

‎do_test_table.php‎

Lines changed: 125 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,81 @@
1111
* @package Lwt
1212
* @author LWT Project <lwt-project@hotmail.com>
1313
* @license Unlicense <http://unlicense.org/>
14+
* @link https://hugofara.github.io/lwt/docs/html/do__test__table_8php.html
1415
* @since 1.5.4
1516
*/
1617

1718
require_once 'inc/session_utility.php';
1819

19-
if (isset($_REQUEST['selection']) && isset($_SESSION['testsql'])) {
20-
$testsql = $_SESSION['testsql'];
21-
} elseif (isset($_REQUEST['lang'])) {
22-
$testsql = ' ' . $tbpref . 'words WHERE WoLgID = ' . $_REQUEST['lang'] . ' ';
23-
} elseif (isset($_REQUEST['text'])) {
24-
$testsql = ' ' . $tbpref . 'words, ' . $tbpref . 'textitems2
25-
WHERE Ti2LgID = WoLgID AND Ti2WoID = WoID and Ti2TxID = ' . $_REQUEST['text'] . ' ';
26-
} else {
27-
my_die("do_test_table.php called with wrong parameters");
20+
/**
21+
* Set sql request for the word test.
22+
*
23+
* @return string SQL request string
24+
*
25+
* @global string $tbpref Table prefix
26+
*/
27+
function get_test_table_sql()
28+
{
29+
global $tbpref;
30+
if (isset($_REQUEST['selection']) && isset($_SESSION['testsql'])) {
31+
$testsql = $_SESSION['testsql'];
32+
$cntlang = get_first_value('SELECT count(distinct WoLgID) AS value FROM ' . $testsql);
33+
if ($cntlang > 1) {
34+
//pagestart('', false);
35+
echo '<p>Sorry - The selected terms are in ' . $cntlang .
36+
' languages, but tests are only possible in one language at a time.</p>';
37+
//pageend();
38+
exit();
39+
}
40+
} else if (isset($_REQUEST['lang'])) {
41+
$testsql = ' ' . $tbpref . 'words where WoLgID = ' . $_REQUEST['lang'] . ' ';
42+
} else if (isset($_REQUEST['text'])) {
43+
$testsql = ' ' . $tbpref . 'words, ' . $tbpref . 'textitems2
44+
WHERE Ti2LgID = WoLgID AND Ti2WoID = WoID AND Ti2TxID = ' . $_REQUEST['text'] . ' ';
45+
} else {
46+
my_die("do_test_table.php called with wrong parameters");
47+
}
48+
return $testsql;
2849
}
2950

30-
//pagestart_nobody('', 'html, body { margin:3px; padding:0; }');
3151

32-
$cntlang = get_first_value('SELECT COUNT(DISTINCT WoLgID) AS value FROM ' . $testsql);
33-
if ($cntlang > 1) {
34-
echo '<p>Sorry - The selected terms are in ' . $cntlang . ' languages, but tests are only possible in one language at a time.</p>';
35-
pageend();
36-
exit();
37-
}
52+
function do_test_table_language_settings($testsql)
53+
{
54+
global $tbpref;
55+
56+
$lang = get_first_value('SELECT WoLgID AS value FROM ' . $testsql . ' LIMIT 1');
3857

39-
$lang = get_first_value('SELECT WoLgID AS value FROM ' . $testsql . ' LIMIT 1');
58+
if (!isset($lang)) {
59+
echo '<p class="center">&nbsp;<br />
60+
Sorry - No terms to display or to test at this time.</p>';
61+
pageend();
62+
exit();
63+
}
4064

41-
if (!isset($lang)) {
42-
echo '<p class="center">&nbsp;<br />Sorry - No terms to display or to test at this time.</p>';
43-
pageend();
44-
exit();
65+
$sql = 'SELECT LgTextSize, LgRegexpWordCharacters, LgRightToLeft
66+
FROM ' . $tbpref . 'languages WHERE LgID = ' . $lang;
67+
$res = do_mysqli_query($sql);
68+
$record = mysqli_fetch_assoc($res);
69+
mysqli_free_result($res);
70+
return $record;
4571
}
4672

47-
$sql = 'SELECT LgTextSize, LgRegexpWordCharacters, LgRightToLeft
48-
FROM ' . $tbpref . 'languages WHERE LgID = ' . $lang;
49-
$res = do_mysqli_query($sql);
50-
$record = mysqli_fetch_assoc($res);
51-
$textsize = round(((int)$record['LgTextSize']-100)/2, 0)+100;
52-
53-
$regexword = $record['LgRegexpWordCharacters'];
54-
$rtlScript = $record['LgRightToLeft'];
55-
mysqli_free_result($res);
56-
$span1 = ($rtlScript ? '<span dir="rtl">' : '');
57-
$span2 = ($rtlScript ? '</span>' : '');
58-
59-
$currenttabletestsetting1 = getSettingZeroOrOne('currenttabletestsetting1', 1);
60-
$currenttabletestsetting2 = getSettingZeroOrOne('currenttabletestsetting2', 1);
61-
$currenttabletestsetting3 = getSettingZeroOrOne('currenttabletestsetting3', 0);
62-
$currenttabletestsetting4 = getSettingZeroOrOne('currenttabletestsetting4', 1);
63-
$currenttabletestsetting5 = getSettingZeroOrOne('currenttabletestsetting5', 0);
64-
$currenttabletestsetting6 = getSettingZeroOrOne('currenttabletestsetting6', 1);
73+
function get_test_table_settings()
74+
{
75+
$currenttabletestsetting1 = getSettingZeroOrOne('currenttabletestsetting1', 1);
76+
$currenttabletestsetting2 = getSettingZeroOrOne('currenttabletestsetting2', 1);
77+
$currenttabletestsetting3 = getSettingZeroOrOne('currenttabletestsetting3', 0);
78+
$currenttabletestsetting4 = getSettingZeroOrOne('currenttabletestsetting4', 1);
79+
$currenttabletestsetting5 = getSettingZeroOrOne('currenttabletestsetting5', 0);
80+
$currenttabletestsetting6 = getSettingZeroOrOne('currenttabletestsetting6', 1);
81+
return array(
82+
$currenttabletestsetting1, $currenttabletestsetting2, $currenttabletestsetting3,
83+
$currenttabletestsetting4, $currenttabletestsetting5, $currenttabletestsetting6
84+
);
85+
}
6586

87+
function do_test_table_javascript()
88+
{
6689
?>
6790
<script type="text/javascript">
6891
//<![CDATA[
@@ -156,16 +179,28 @@
156179
});
157180
//]]>
158181
</script>
182+
<?php
183+
}
184+
185+
186+
function do_test_table_settings($settings)
187+
{
188+
?>
159189
<p>
160-
<input type="checkbox" id="cbEdit" <?php echo get_checked($currenttabletestsetting1); ?> /> Edit
161-
<input type="checkbox" id="cbStatus" <?php echo get_checked($currenttabletestsetting2); ?> /> Status
162-
<input type="checkbox" id="cbTerm" <?php echo get_checked($currenttabletestsetting3); ?> /> Term
163-
<input type="checkbox" id="cbTrans" <?php echo get_checked($currenttabletestsetting4); ?> /> Translation
164-
<input type="checkbox" id="cbRom" <?php echo get_checked($currenttabletestsetting5); ?> /> Romanization
165-
<input type="checkbox" id="cbSentence" <?php echo get_checked($currenttabletestsetting6); ?> /> Sentence
190+
<input type="checkbox" id="cbEdit" <?php echo get_checked($settings[0]); ?> /> Edit
191+
<input type="checkbox" id="cbStatus" <?php echo get_checked($settings[1]); ?> /> Status
192+
<input type="checkbox" id="cbTerm" <?php echo get_checked($settings[2]); ?> /> Term
193+
<input type="checkbox" id="cbTrans" <?php echo get_checked($settings[3]); ?> /> Translation
194+
<input type="checkbox" id="cbRom" <?php echo get_checked($settings[4]); ?> /> Romanization
195+
<input type="checkbox" id="cbSentence" <?php echo get_checked($settings[5]); ?> /> Sentence
166196
</p>
197+
<?php
198+
}
199+
167200

168-
<table class="sortable tab1" style="width:auto;" cellspacing="0" cellpadding="5">
201+
function do_test_table_header()
202+
{
203+
?>
169204
<tr>
170205
<th class="th1">Ed</th>
171206
<th class="th1 clickable">Status</th>
@@ -175,18 +210,37 @@
175210
<th class="th1 clickable">Sentence</th>
176211
</tr>
177212
<?php
213+
}
214+
215+
function do_test_table_table_content($lang_record, $testsql)
216+
{
217+
global $debug;
178218

179-
$sql = 'SELECT DISTINCT WoID, WoText, WoTranslation, WoRomanization,
180-
WoSentence, WoStatus, WoTodayScore As Score
181-
FROM ' . $testsql . ' AND WoStatus BETWEEN 1 AND 5
182-
AND WoTranslation != \'\' AND WoTranslation != \'*\'
183-
ORDER BY WoTodayScore, WoRandom*RAND()';
219+
$textsize = round(((int)$lang_record['LgTextSize']-100)/2, 0)+100;
220+
221+
$regexword = $lang_record['LgRegexpWordCharacters'];
222+
$rtlScript = $lang_record['LgRightToLeft'];
223+
$span1 = ($rtlScript ? '<span dir="rtl">' : '');
224+
$span2 = ($rtlScript ? '</span>' : '');
184225

185-
if ($debug) {
186-
echo $sql;
226+
$sql = 'SELECT DISTINCT WoID, WoText, WoTranslation, WoRomanization,
227+
WoSentence, WoStatus, WoTodayScore As Score
228+
FROM ' . $testsql . ' AND WoStatus BETWEEN 1 AND 5
229+
AND WoTranslation != \'\' AND WoTranslation != \'*\'
230+
ORDER BY WoTodayScore, WoRandom*RAND()';
231+
232+
if ($debug) {
233+
echo $sql;
234+
}
235+
$res = do_mysqli_query($sql);
236+
while ($record = mysqli_fetch_assoc($res)) {
237+
do_test_table_row($record, $regexword, $textsize, $span1, $span2);
238+
}
239+
mysqli_free_result($res);
187240
}
188-
$res = do_mysqli_query($sql);
189-
while ($record = mysqli_fetch_assoc($res)) {
241+
242+
function do_test_table_row($record, $regexword, $textsize, $span1, $span2)
243+
{
190244
$sent = tohtml(repl_tab_nl($record["WoSentence"]));
191245
$sent1 = str_replace(
192246
"{", ' <b>[', str_replace(
@@ -232,14 +286,24 @@
232286
<?php echo $sent1; ?></span><?php echo $span2; ?>
233287
</td>
234288
</tr>
235-
<?php
289+
<?php
236290
}
237-
mysqli_free_result($res);
238291

239-
?>
240-
</table>
241-
<?php
292+
function do_test_table()
293+
{
294+
//pagestart_nobody('', 'html, body { margin:3px; padding:0; }');
295+
$testsql = get_test_table_sql();
296+
$lang_record = do_test_table_language_settings($testsql);
297+
$settings = get_test_table_settings();
298+
do_test_table_javascript();
299+
do_test_table_settings($settings);
242300

243-
pageend();
301+
echo '<table class="sortable tab1" style="width:auto;" cellspacing="0" cellpadding="5">';
302+
303+
do_test_table_header();
304+
do_test_table_table_content($lang_record, $testsql);
305+
echo '</table>';
244306

307+
//pageend();
308+
}
245309
?>

‎do_test_test.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ function get_test_sql()
3434
$testsql = $_SESSION['testsql'];
3535
$cntlang = get_first_value('SELECT count(distinct WoLgID) AS value FROM ' . $testsql);
3636
if ($cntlang > 1) {
37-
pagestart('', false);
37+
//pagestart('', false);
3838
echo '<p>Sorry - The selected terms are in ' . $cntlang . ' languages, but tests are only possible in one language at a time.</p>';
39-
pageend();
39+
//pageend();
4040
exit();
4141
}
4242
} else if (isset($_REQUEST['lang'])) {
@@ -45,9 +45,9 @@ function get_test_sql()
4545
$testsql = ' ' . $tbpref . 'words, ' . $tbpref . 'textitems2
4646
WHERE Ti2LgID = WoLgID AND Ti2WoID = WoID AND Ti2TxID = ' . $_REQUEST['text'] . ' ';
4747
} else {
48-
$testsql = '';
49-
$title = 'Request Error!';
50-
pagestart($title, true);
48+
//$testsql = '';
49+
//$title = 'Request Error!';
50+
//pagestart($title, true);
5151
my_die("do_test_test.php called with wrong parameters");
5252
}
5353
return $testsql;

0 commit comments

Comments
 (0)