forked from chaosarium/lwt
-
Notifications
You must be signed in to change notification settings - Fork 20
/
print_text.php
291 lines (272 loc) · 9.78 KB
/
print_text.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
<?php
/**
* Print a text
*
* Call: print_text.php?text=[textid]&...
* ... ann=[annotationcode] ... ann. filter
* ... status=[statuscode] ... status filter
*
* PHP version 8.1
*
* @category User_Interface
*/
require_once 'inc/session_utility.php';
function output_text($saveterm,$saverom,$savetrans,$savetags,
$show_rom,$show_trans,$show_tags,$annplcmnt
): void {
if ($show_tags) {
if ($savetrans == '' && $savetags != '') {
$savetrans = '* ' . $savetags;
} else {
$savetrans = trim($savetrans . ' ' . $savetags);
}
}
if ($show_rom && $saverom == '') {
$show_rom = 0;
}
if ($show_trans && $savetrans == '') {
$show_trans = 0;
}
if ($annplcmnt == 1) {
if ($show_rom || $show_trans) {
echo ' ';
if ($show_trans) {
echo '<span class="anntrans">' . tohtml($savetrans) . '</span> ';
}
if ($show_rom && (! $show_trans)) {
echo '<span class="annrom">' . tohtml($saverom) . '</span> ';
}
if ($show_rom && $show_trans) {
echo '<span class="annrom" dir="ltr">[' . tohtml($saverom) . ']</span> ';
}
echo ' <span class="annterm">';
}
echo tohtml($saveterm);
if ($show_rom || $show_trans) {
echo '</span> ';
}
} elseif ($annplcmnt == 2) {
if ($show_rom || $show_trans) {
echo ' <ruby><rb><span class="anntermruby">' . tohtml($saveterm) . '</span></rb><rt> ';
if ($show_trans) {
echo '<span class="anntransruby">' . tohtml($savetrans) . '</span> ';
}
if ($show_rom && (! $show_trans)) {
echo '<span class="annromrubysolo">' . tohtml($saverom) . '</span> ';
}
if ($show_rom && $show_trans) {
echo '<span class="annromruby" dir="ltr">[' . tohtml($saverom) . ']</span> ';
}
echo '</rt></ruby> ';
} else {
echo tohtml($saveterm);
}
} else {
/* 0 or other */
if ($show_rom || $show_trans) {
echo ' <span class="annterm">';
}
echo tohtml($saveterm);
if ($show_rom || $show_trans) {
echo '</span> ';
if ($show_rom && (! $show_trans)) {
echo '<span class="annrom">' . tohtml($saverom) . '</span>';
}
if ($show_rom && $show_trans) {
echo '<span class="annrom" dir="ltr">[' . tohtml($saverom) . ']</span> ';
}
if ($show_trans) {
echo '<span class="anntrans">' . tohtml($savetrans) . '</span>';
}
echo ' ';
}
}
}
$textid = (int)getreq('text');
if ($textid==0) {
header("Location: edit_texts.php");
exit();
}
$ann = getreq('ann');
if ($ann == '') {
$ann = getSetting('currentprintannotation');
}
if ($ann == '') {
$ann = 3;
}
$show_rom = $ann & 2;
$show_trans = $ann & 1;
$show_tags = $ann & 4;
$statusrange = getreq('status');
if ($statusrange == '') {
$statusrange = getSetting('currentprintstatus');
}
if ($statusrange == '') {
$statusrange = 14;
}
$annplcmnt = getreq('annplcmnt');
if ($annplcmnt == '') {
$annplcmnt = getSetting('currentprintannotationplacement');
}
if ($annplcmnt == '') {
$annplcmnt = 0;
}
$sql = 'select TxLgID, TxTitle, TxSourceURI from ' . $tbpref . 'texts where TxID = ' . $textid;
$res = do_mysqli_query($sql);
$record = mysqli_fetch_assoc($res);
$title = (string) $record['TxTitle'];
$sourceURI = (string) $record['TxSourceURI'];
$langid = (int) $record['TxLgID'];
mysqli_free_result($res);
$sql = 'select LgTextSize, LgRemoveSpaces, LgRightToLeft from ' . $tbpref . 'languages where LgID = ' . $langid;
$res = do_mysqli_query($sql);
$record = mysqli_fetch_assoc($res);
$textsize = $record['LgTextSize'];
$rtlScript = $record['LgRightToLeft'];
mysqli_free_result($res);
saveSetting('currenttext', $textid);
saveSetting('currentprintannotation', $ann);
saveSetting('currentprintstatus', $statusrange);
saveSetting('currentprintannotationplacement', $annplcmnt);
pagestart_nobody('Print');
?>
<div class="noprint">
<div class="flex-header">
<div>
<?php echo_lwt_logo(); ?>
</div>
<div>
<?php echo getPreviousAndNextTextLinks($textid, 'print_text.php?text=', false, ''); ?>
</div>
<div>
<a href="do_text.php?start=<?php echo $textid; ?>" target="_top">
<img src="icn/book-open-bookmark.png" title="Read" alt="Read" /></a>
<a href="do_test.php?text=<?php echo $textid; ?>" target="_top">
<img src="icn/question-balloon.png" title="Test" alt="Test" />
</a>
<?php echo get_annotation_link($textid); ?>
<a target="_top" href="edit_texts.php?chg=<?php echo $textid; ?>">
<img src="icn/document--pencil.png" title="Edit Text" alt="Edit Text" />
</a>
</div>
<div>
<?php quickMenu(); ?>
</div>
</div>
<h1>PRINT ▶ <?php
echo tohtml($title);
(isset($record['TxSourceURI']) && substr(trim($sourceURI), 0, 1)!='#' ?
' <a href="' . $sourceURI . '" target="_blank">
<img src="'.get_file_path('icn/chain.png').'" title="Text Source" alt="Text Source" /></a>' :
'') ?></h1>
<p id="printoptions">
Terms with <b>status(es)</b>
<select id="status" onchange="{val=document.getElementById('status').options[document.getElementById('status').selectedIndex].value;location.href='print_text.php?text=<?php echo $textid; ?>&status=' + val;}">";
<?php echo get_wordstatus_selectoptions($statusrange, true, true, false); ?>
</select> ...<br />
will be <b>annotated</b> with
<select id="ann" onchange="{val=document.getElementById('ann').options[document.getElementById('ann').selectedIndex].value;location.href='print_text.php?text=<?php echo $textid; ?>&ann=' + val;}">
<option value="0"<?php echo get_selected(0, $ann); ?>>Nothing</option>
<option value="1"<?php echo get_selected(1, $ann); ?>>Translation</option>
<option value="5"<?php echo get_selected(5, $ann); ?>>Translation & Tags</option>
<option value="2"<?php echo get_selected(2, $ann); ?>>Romanization</option>
<option value="3"<?php echo get_selected(3, $ann); ?>>Romanization & Translation</option>
<option value="7"<?php echo get_selected(7, $ann); ?>>Romanization, Translation & Tags</option>
</select>
<select id="annplcmnt" onchange="{val=document.getElementById('annplcmnt').options[document.getElementById('annplcmnt').selectedIndex].value;location.href='print_text.php?text=<?php echo $textid; ?>&annplcmnt=' + val;}">
<option value="0"<?php echo get_selected(0, $annplcmnt); ?>>behind</option>
<option value="1"<?php echo get_selected(1, $annplcmnt); ?>>in front of</option>
<option value="2"<?php echo get_selected(2, $annplcmnt); ?>>above (ruby)</option>
</select> the term.<br />
<input type="button" value="Print it!" onclick="window.print();" />
(only the text below the line)
<span class="nowrap"></span>
<?php
if (((int)get_first_value("select length(TxAnnotatedText) as value from {$tbpref}texts where TxID = $textid")) > 0) {
?> Or
<input type="button" value="Print/Edit/Delete"
onclick="location.href='print_impr_text.php?text=<?php echo $textid; ?>';" /> your
<b>Improved Annotated Text</b> <?php echo get_annotation_link($textid) ?>.
<?php
} else {
?>
<input type="button" value="Create"
onclick="location.href='print_impr_text.php?edit=1&text=<?php echo $textid; ?>';" /> an
<b>Improved Annotated Text</b> [<img src="icn/tick.png" title="Annotated Text" alt="Annotated Text" />]."
<?php
}
?>
</p></div>
<!-- noprint -->
<div id="print" <?php echo ($rtlScript ? 'dir="rtl"' : '') ?>>
<h2><?php echo tohtml($title); ?></h2>
<p style="font-size: <?php echo $textsize; ?>%; line-height: 1.35; margin-bottom: 10px; ">
<?php
$sql =
'SELECT
CASE WHEN Ti2WordCount>0 THEN Ti2WordCount ELSE 1 END AS Code,
CASE WHEN CHAR_LENGTH(Ti2Text)>0 THEN Ti2Text ELSE WoText END AS TiText,
Ti2Order,
CASE WHEN Ti2WordCount > 0 THEN 0 ELSE 1 END as TiIsNotWord,
WoID, WoTranslation, WoRomanization, WoStatus
FROM (
' . $tbpref . 'textitems2
LEFT JOIN ' . $tbpref . 'words ON (Ti2WoID = WoID) AND (Ti2LgID = WoLgID)
)
WHERE Ti2TxID = ' . $textid . '
ORDER BY Ti2Order asc, Ti2WordCount desc';
$saveterm = '';
$savetrans = '';
$saverom = '';
$savetags = '';
$until = 0;
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$actcode = (int)$record['Code'];
$order = (int)$record['Ti2Order'];
if ($order <= $until) {
continue;
}
if ($order > $until) {
output_text(
$saveterm, $saverom, $savetrans, $savetags,
$show_rom, $show_trans, $show_tags, $annplcmnt
);
$saveterm = '';
$savetrans = '';
$saverom = '';
$savetags = '';
$until = $order;
}
if ($record['TiIsNotWord'] != 0) {
echo str_replace(
"¶",
'</p><p style="font-size:' . $textsize . '%;line-height: 1.3; margin-bottom: 10px;">',
tohtml($record['TiText'])
);
} else {
$until = $order + 2 * ($actcode-1);
$saveterm = $record['TiText'];
$savetrans = '';
$savetags = '';
$saverom = '';
if (isset($record['WoID'])) {
if (checkStatusRange((int)$record['WoStatus'], $statusrange)) {
$savetrans = $record['WoTranslation'];
$savetags = getWordTagList($record['WoID'], '', 1, 0);
if ($savetrans == '*') {
$savetrans = '';
}
$saverom = trim((string) $record['WoRomanization']);
}
}
}
} // while
mysqli_free_result($res);
output_text(
$saveterm, $saverom, $savetrans, $savetags,
$show_rom, $show_trans, $show_tags, $annplcmnt
);
echo "</p></div>";
pageend();
?>