forked from chaosarium/lwt
-
Notifications
You must be signed in to change notification settings - Fork 20
/
print_impr_text.php
267 lines (249 loc) · 8.2 KB
/
print_impr_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
<?php
/**
* \file
* \brief Print/Edit an improved annotated text
*
* Call: print_impr_text.php?text=[textid]&...
* ... edit=1 ... edit own annotation
* ... del=1 ... delete own annotation
*
* PHP version 8.1
*
* @category User_Interface
* @package Lwt
* @author LWT Project <[email protected]>
* @license Unlicense <http://unlicense.org/>
* @link https://hugofara.github.io/lwt/docs/php/files/print-impr-text.html
* @since 1.5.0
*/
namespace Lwt\Interface\Print_Impr_text;
require_once 'inc/session_utility.php';
require_once 'inc/ajax_edit_impr_text.php';
use function Lwt\Ajax\Improved_Text\edit_term_form;
function edit_mode_display($textid, $ann_exists): void
{
if (!$ann_exists) {
// No annotations, try create them
$ann = create_save_ann($textid);
$ann_exists = strlen($ann) > 0;
}
?>
<div id="printoptions">
<h2>Improved Annotated Text (Edit Mode)
<img src="icn/question-frame.png" title="Help" alt="Help" class="click"
onclick="window.open('docs/info.html#il');" />
</h2>
<input type="button" value="Display/Print Mode" onclick="location.href='print_impr_text.php?text=<?php echo $textid; ?>';" />
</div>
</div>
<!-- noprint -->
<?php
if (!$ann_exists) {
// No annotations, creation not possible
echo '<p>No annotated text found, and creation seems not possible.</p>';
} else {
// Annotations exist, set up for editing.
?>
<div data_id="<?php echo $textid; ?>" id="editimprtextdata">
<?php echo edit_term_form($textid); ?>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('input.impr-ann-text').on('change', changeImprAnnText);
$('input.impr-ann-radio').on('change', changeImprAnnRadio);
});
</script>
<?php
}
?>
<div class="noprint">
<input type="button" value="Display/Print Mode"
onclick="location.href='print_impr_text.php?text=<?php echo $textid; ?>" />
</div>
<?php
}
function print_mode_display($textid, $langid, $audio, $ann, $title): void
{
global $tbpref;
$sql = "SELECT LgTextSize, LgRemoveSpaces, LgRightToLeft, LgGoogleTranslateURI
from {$tbpref}languages where LgID = $langid";
$res = do_mysqli_query($sql);
$record = mysqli_fetch_assoc($res);
$textsize = $record['LgTextSize'];
$rtlScript = $record['LgRightToLeft'];
$ttsClass = '';
if (!empty($record['LgGoogleTranslateURI'])) {
$ttsLg = preg_replace(
'/.*[?&]sl=([a-zA-Z\-]*)(&.*)*$/', '$1',
$record['LgGoogleTranslateURI']
);
if ($record['LgGoogleTranslateURI'] != $ttsLg) {
$ttsClass = 'tts_' . $ttsLg . ' ';
}
}
mysqli_free_result($res);
?>
<div id="printoptions">
<h2>Improved Annotated Text (Display/Print Mode)</h2>
<div class="flex-spaced">
<input type="button" value="Edit"
onclick="location.href='print_impr_text.php?edit=1&text=<?php echo $textid; ?>';" />
<input type="button" value="Delete"
onclick="if (confirm ('Are you sure?')) location.href='print_impr_text.php?del=1&text=<?php echo $textid; ?>';" />
<input type="button" value="Print" onclick="window.print();" />
<input type="button"
value="Display <?php echo (($audio != '') ? ' with Audio Player' : ''); ?> in new Window"
onclick="window.open('display_impr_text.php?text=<?php echo $textid; ?>');" />
</div>
</div>
</div>
<!-- noprint -->
<div id="print"<?php echo ($rtlScript ? ' dir="rtl"' : ''); ?>>
<p style="font-size:<?php echo $textsize; ?>%;line-height: 1.35; margin-bottom: 10px; ">
<?php echo tohtml($title); ?>
<br /><br />
<?php
$items = preg_split('/[\n]/u', $ann);
foreach ($items as $item) {
$vals = preg_split('/[\t]/u', $item);
if ($vals[0] > -1) {
$trans = '';
if (count($vals) > 3) {
$trans = $vals[3];
}
if ($trans == '*') {
$trans = $vals[1] . " "; // <- U+200A HAIR SPACE
}
echo ' <ruby>
<rb>
<span class="' . $ttsClass . 'anntermruby">' .
tohtml($vals[1]) .
'</span>
</rb>
<rt>
<span class="anntransruby2">' . tohtml($trans) . '</span>
</rt>
</ruby> ';
} else if (count($vals) >= 2) {
echo str_replace(
"¶",
'</p><p style="font-size:' . $textsize . '%;line-height: 1.3; margin-bottom: 10px;">',
" " . tohtml($vals[1]) . " "
);
}
}
?>
</p>
</div>
<?php
}
/**
* @return void
*/
function do_content()
{
global $tbpref;
$textid = (int)getreq('text');
$editmode = getreq('edit');
$editmode = ($editmode == '' ? 0 : (int)$editmode);
$delmode = getreq('del');
$delmode = ($delmode == '' ? 0 : (int)$delmode);
$ann = (string) get_first_value(
"SELECT TxAnnotatedText AS value FROM {$tbpref}texts
WHERE TxID = $textid"
);
$ann_exists = strlen($ann) > 0;
if ($ann_exists) {
$ann = recreate_save_ann($textid, $ann);
$ann_exists = strlen($ann) > 0;
}
if ($textid == 0) {
header("Location: edit_texts.php");
exit();
}
if ($delmode) {
// Delete
if ($ann_exists) {
runsql(
"UPDATE {$tbpref}texts
SET TxAnnotatedText = NULL
WHERE TxID = $textid",
""
);
}
$ann_exists = (int)get_first_value(
"SELECT LENGTH(TxAnnotatedText) AS value
FROM {$tbpref}texts
WHERE TxID = $textid"
) > 0;
if (!$ann_exists) {
header("Location: print_text.php?text=$textid");
exit();
}
}
$sql = "SELECT TxLgID, TxTitle, TxAudioURI, 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'];
if (isset($record['TxAudioURI'])) {
$audio = (string) $record['TxAudioURI'];
} else {
$audio = '';
}
$audio = trim($audio);
mysqli_free_result($res);
saveSetting('currenttext', $textid);
pagestart_nobody('Annotated Text', 'input[type="radio"]{display:inline;}');
?>
<div class="noprint">
<div class="flex-header">
<div>
<?php echo_lwt_logo(); ?>
</div>
<div>
<?php echo getPreviousAndNextTextLinks(
$textid, 'print_impr_text.php?text=', true, ''
); ?>
</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>
<a href="print_text.php?text=<?php echo $textid; ?>" target="_top">
<img src="icn/printer.png" title="Print" alt="Print" />
</a>
<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>ANN.TEXT ▶ <?php echo tohtml($title) .
(isset($record['TxSourceURI']) && substr(trim($sourceURI), 0, 1) != '#' ?
' <a href="<?php echo $sourceURI; ?>" target="_blank">
<img src="'.get_file_path('icn/chain.png') .
'" title="Text Source" alt="Text Source" />
</a>'
: '') ?>
</h1>
<?php
if ($editmode) {
edit_mode_display($textid, $ann_exists);
} else {
print_mode_display(
$textid, $langid, $audio, $ann, $title
);
}
pageend();
}
do_content();
?>