Repository navigation
Expand file tree
/
Copy pathset_test_status.php
More file actions
190 lines (172 loc) · 5.12 KB
/
Copy pathset_test_status.php
File metadata and controls
190 lines (172 loc) · 5.12 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
<?php
/**
* \file
* \brief Change status of term while testing
*
* Call: set_test_status.php?wid=[wordid]&stchange=+1/-1
* set_test_status.php?wid=[wordid]&status=1..5/98/99
*
* @package Lwt
* @author LWT Project <lwt-project@hotmail.com>
* @license Unlicense <http://unlicense.org/>
* @link https://hugofara.github.io/lwt/docs/html/do__test__header_8php.html
* @since 1.0.3
*/
require_once 'inc/session_utility.php';
/**
* Echo the page HTML content when setting word status.
*
* @param int $status New learning status for the word
* @param int $oldstatus Previous learning status
* @param int $newscore New score for the word
* @param int $oldscore Previous score
*
* @return void
*/
function do_set_test_status_html($status, $oldstatus, $newscore, $oldscore)
{
if ($oldstatus == $status) {
echo '<p>Status ' . get_colored_status_msg($status) . ' not changed.</p>';
} else {
echo '<p>
Status changed from ' . get_colored_status_msg($oldstatus) .
' to ' . get_colored_status_msg($status) . '
.</p>';
}
echo "<p>Old score was $oldscore, new score is now $newscore.</p>";
}
/**
* Increment the session progress in learning new words.
*
* @param int $stchange -1, 0, or 1 if status is rising or not
*
* @return void
*/
function set_test_status_change_progress($stchange)
{
$totaltests = $_SESSION['testtotal'];
$wrong = $_SESSION['testwrong'];
$correct = $_SESSION['testcorrect'];
$notyettested = $totaltests - $correct - $wrong;
if ($notyettested > 0) {
if ($stchange >= 0) {
$_SESSION['testcorrect']++;
}
else {
$_SESSION['testwrong']++;
}
}
}
/**
* Make the JavaScript action for setting a word status.
*
* @param int $wid Word ID
* @param int $status New learning status for the word
* @param int $stchange -1, 0, or 1 if status is rising or not
*
* @return void
*/
function do_set_test_status_javascript($wid, $status, $stchange)
{
?>
<script type="text/javascript">
//<![CDATA[
const context = window.parent;
$('.word<?php echo $wid; ?>', context)
.removeClass('todo todosty')
.addClass('done<?php echo ($stchange >= 0 ? 'ok' : 'wrong'); ?>sty')
.attr('data_status','<?php echo $status; ?>')
.attr('data_todo','0');
// Waittime <= 0 causes the page to loop-reloading
const waittime = <?php
echo json_encode((int)getSettingWithDefault('set-test-main-frame-waiting-time'));
?> + 500;
if (waittime <= 0) {
console.log("aaa");
window.parent.location.reload();
} else {
console.log("bbb");
setTimeout('window.parent.location.reload();', waittime);
}
//]]>
</script>
<?php
}
/**
* Make the page content of the word status page.
*
* @param int $wid Word ID
* @param int $status New learning status for the word
* @param int $oldstatus Previous learning status
* @param int $stchange -1, 0, or 1 if status is rising or not
*
* @return void
*
* @global string $tbpref Database table prefix
*/
function do_set_test_status_content($wid, $status, $oldstatus, $stchange)
{
global $tbpref;
$word = get_first_value(
"SELECT WoText AS value FROM " . $tbpref . "words
WHERE WoID = " . $wid
);
$oldscore = (int)get_first_value(
'SELECT greatest(0,round(WoTodayScore,0)) AS value FROM ' . $tbpref . 'words
WHERE WoID = ' . $wid
);
runsql(
'UPDATE ' . $tbpref . 'words SET WoStatus = ' .
$status . ', WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . '
WHERE WoID = ' . $wid,
'Status changed'
);
$newscore = (int)get_first_value(
'SELECT greatest(0,round(WoTodayScore,0)) AS value
FROM ' . $tbpref . 'words where WoID = ' . $wid
);
pagestart("Term: " . $word, false);
do_set_test_status_html($status, $oldstatus, $newscore, $oldscore);
set_test_status_change_progress($stchange);
do_set_test_status_javascript($wid, $status, $stchange);
pageend();
}
/**
* Start the word status set page.
*
* @return void
*
* @global string $tbpref Database table prefix
*/
function start_set_text_status()
{
global $tbpref;
if (!is_numeric(getreq('status')) && !is_numeric(getreq('stchange'))) {
my_die('status or stchange should be specified!');
}
$wid = (int)getreq('wid');
$oldstatus = (int)get_first_value(
"SELECT WoStatus AS value FROM " . $tbpref . "words
WHERE WoID = " . $wid
);
if (!is_numeric(getreq('stchange'))) {
$status = (int)getreq('status');
$stchange = $status - $oldstatus;
if ($stchange <= 0) {
$stchange = -1;
} else if ($stchange > 0) {
$stchange = 1;
}
} else {
$stchange = (int)getreq('stchange');
$status = $oldstatus + $stchange;
if ($status < 1) {
$status = 1;
} else if ($status > 5) {
$status = 5;
}
}
do_set_test_status_content($wid, $status, $oldstatus, $stchange);
}
start_set_text_status();
?>