|
11 | 11 | * @package Lwt |
12 | 12 | * @author LWT Project <lwt-project@hotmail.com> |
13 | 13 | * @license Unlicense <http://unlicense.org/> |
| 14 | + * @link https://hugofara.github.io/lwt/docs/html/do__test__table_8php.html |
14 | 15 | * @since 1.5.4 |
15 | 16 | */ |
16 | 17 |
|
17 | 18 | require_once 'inc/session_utility.php'; |
18 | 19 |
|
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; |
28 | 49 | } |
29 | 50 |
|
30 | | -//pagestart_nobody('', 'html, body { margin:3px; padding:0; }'); |
31 | 51 |
|
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'); |
38 | 57 |
|
39 | | -$lang = get_first_value('SELECT WoLgID AS value FROM ' . $testsql . ' LIMIT 1'); |
| 58 | + if (!isset($lang)) { |
| 59 | + echo '<p class="center"> <br /> |
| 60 | + Sorry - No terms to display or to test at this time.</p>'; |
| 61 | + pageend(); |
| 62 | + exit(); |
| 63 | + } |
40 | 64 |
|
41 | | -if (!isset($lang)) { |
42 | | - echo '<p class="center"> <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; |
45 | 71 | } |
46 | 72 |
|
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 | +} |
65 | 86 |
|
| 87 | +function do_test_table_javascript() |
| 88 | +{ |
66 | 89 | ?> |
67 | 90 | <script type="text/javascript"> |
68 | 91 | //<![CDATA[ |
|
156 | 179 | }); |
157 | 180 | //]]> |
158 | 181 | </script> |
| 182 | +<?php |
| 183 | +} |
| 184 | + |
| 185 | + |
| 186 | +function do_test_table_settings($settings) |
| 187 | +{ |
| 188 | +?> |
159 | 189 | <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 |
166 | 196 | </p> |
| 197 | +<?php |
| 198 | +} |
| 199 | + |
167 | 200 |
|
168 | | -<table class="sortable tab1" style="width:auto;" cellspacing="0" cellpadding="5"> |
| 201 | +function do_test_table_header() |
| 202 | +{ |
| 203 | +?> |
169 | 204 | <tr> |
170 | 205 | <th class="th1">Ed</th> |
171 | 206 | <th class="th1 clickable">Status</th> |
|
175 | 210 | <th class="th1 clickable">Sentence</th> |
176 | 211 | </tr> |
177 | 212 | <?php |
| 213 | +} |
| 214 | + |
| 215 | +function do_test_table_table_content($lang_record, $testsql) |
| 216 | +{ |
| 217 | + global $debug; |
178 | 218 |
|
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>' : ''); |
184 | 225 |
|
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); |
187 | 240 | } |
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 | +{ |
190 | 244 | $sent = tohtml(repl_tab_nl($record["WoSentence"])); |
191 | 245 | $sent1 = str_replace( |
192 | 246 | "{", ' <b>[', str_replace( |
|
232 | 286 | <?php echo $sent1; ?></span><?php echo $span2; ?> |
233 | 287 | </td> |
234 | 288 | </tr> |
235 | | - <?php |
| 289 | +<?php |
236 | 290 | } |
237 | | -mysqli_free_result($res); |
238 | 291 |
|
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); |
242 | 300 |
|
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>'; |
244 | 306 |
|
| 307 | + //pageend(); |
| 308 | +} |
245 | 309 | ?> |
0 commit comments