Repository navigation
Expand file tree
/
Copy pathset_word_status.php
More file actions
153 lines (140 loc) · 4.36 KB
/
Copy pathset_word_status.php
File metadata and controls
153 lines (140 loc) · 4.36 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
<?php
/**
* \file
* \brief Change status of term while reading
*
* Call: set_word_status.php?...
* ... tid=[textid]&wid=[wordid]&status=1..5/98/99
*
* @package Lwt
* @author LWT Project <lwt-project@hotmail.com>
* @license Unlicense <http://unlicense.org/>
* @since 1.0.3
*/
require_once 'inc/session_utility.php';
/**
* Get various data for the word corresponding to the ID.
*
* @param string $wid ID of the word
*
* @return array{0: string, 1: string, 2: string} The word in plain text,
* his translation and his romanization
*
* @global string $tbpref
*/
function get_word_data($wid)
{
global $tbpref;
$sql = 'SELECT WoText, WoTranslation, WoRomanization
FROM ' . $tbpref . 'words WHERE WoID = ' . $wid;
$res = do_mysqli_query($sql);
$record = mysqli_fetch_assoc($res);
if (!$record) {
my_die("Word not found in set_word_status.php");
}
$word = $record['WoText'];
$trans = repl_tab_nl($record['WoTranslation']) . getWordTagList($wid, ' ', 1, 0);
$roman = $record['WoRomanization'];
mysqli_free_result($res);
return array($word, $trans, $roman);
}
/**
* Edit the word from the database.
*
* @param string $wid ID of the word to delete
* @param string $status New status to set
*
* @return string Some edit message, number of affected rows or error message
*
* @global string $tbpref
*/
function set_word_status_database($wid, $status)
{
global $tbpref;
$m1 = runsql(
'UPDATE ' . $tbpref . 'words
SET WoStatus = ' . $status . ', WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . '
WHERE WoID = ' . $wid,
'Status changed'
);
return $m1;
}
/**
* Do the JavaScript action for changing display of the word.
*
* @param string $tid Text ID
* @param string $wid ID of the word that changed status
* @param string $status New status
* @param string $word Word in plain text
* @param string $trans Translation of the word
* @param string $roman Romanization of the word
*
* @return void
*/
function set_word_status_javascript($tid, $wid, $status, $word, $trans, $roman)
{
?>
<script type="text/javascript">
//<![CDATA[
let context = window.parent.document.getElementById('frame-l');
let contexth = window.parent.document.getElementById('frame-h');
let status = '<?php echo $status; ?>';
let title = '';
if (!window.parent.JQ_TOOLTIP) {
title = make_tooltip(
<?php echo prepare_textdata_js($word); ?>, <?php echo prepare_textdata_js($trans); ?>, <?php echo prepare_textdata_js($roman); ?>, status
);
}
$('.word<?php echo $wid; ?>', context)
.removeClass('status98 status99 status1 status2 status3 status4 status5')
.addClass('status<?php echo $status; ?>')
.attr('data_status','<?php echo $status; ?>')
.attr('title',title);
$('#learnstatus', contexth).html('<?php echo addslashes(texttodocount2($tid)); ?>');
cleanupRightFrames();
//]]>
</script>
<?php
}
/**
* Echo the HTML content of the page.
*
* @param string $tid Text ID
* @param string $wid ID of the word that changed status
* @param string $status New status
* @param string $word Word in plain text
* @param string $trans Translation of the word
* @param string $roman Romanization of the word
*
* @return void
*/
function set_word_status_display_page($tid, $wid, $status, $word, $trans, $roman)
{
pagestart("Term: " . $word, false);
echo '<p>OK, this term has status ' . get_colored_status_msg($status) . ' from now!</p>';
set_word_status_javascript($tid, $wid, $status, $word, $trans, $roman);
pageend();
}
/**
* Complete workflow for updating a word.
* It edits the database, show the success message
* and do JavaScript action to change its display.
*
* @param string $textid ID of the affected text
* @param string $wordid ID of the word to update
* @param string $status New status for this word
*
* @return void
*
* @since 2.0.4-fork
*/
function do_set_word_status($textid, $wordid, $status)
{
list($word, $trans, $roman) = get_word_data($wordid);
set_word_status_database($wordid, $status);
set_word_status_display_page($textid, $wordid, $status, $word, $trans, $roman);
}
if (getreq('tid') != '' && getreq('wid') != '' && getreq('status') != '') {
do_set_word_status(getreq('tid'), getreq('wid'), getreq('status'));
}
?>