forked from chaosarium/lwt
-
Notifications
You must be signed in to change notification settings - Fork 20
/
edit_texts.php
1344 lines (1280 loc) · 45.8 KB
/
edit_texts.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* \file
* \brief Manage active texts
*
* Call: edit_texts.php?....
* ... markaction=[opcode] ... do actions on marked texts
* ... del=[textid] ... do delete
* ... arch=[textid] ... do archive
* ... op=Check ... do check
* ... op=Save ... do insert new
* ... op=Change ... do update
* ... op=Save+and+Open ... do insert new and open
* ... op=Change+and+Open ... do update and open
* ... new=1 ... display new text screen
* ... chg=[textid] ... display edit screen
* ... filterlang=[langid] ... language filter
* ... sort=[sortcode] ... sort
* ... page=[pageno] ... page
* ... query=[titlefilter] ... title filter
*
* 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/edit-texts.html
* @since 1.0.3
*/
require_once 'inc/session_utility.php';
require_once 'inc/start_session.php';
require_once 'inc/text_from_yt.php';
require_once 'inc/classes/Text.php';
/**
* Get the value of $wh_query.
*
* @param string $currentquery Current database query
* @param string $currentquerymode
* @param string $currentregexmode
*
* @return string Content for $wh_query.
*/
function edit_texts_get_wh_query($currentquery, $currentquerymode, $currentregexmode)
{
$wh_query = $currentregexmode . 'LIKE ';
if ($currentregexmode == '') {
$wh_query .= convert_string_to_sqlsyntax(
str_replace("*", "%", mb_strtolower($currentquery, 'UTF-8'))
);
} else {
$wh_query .= convert_string_to_sqlsyntax($currentquery);
}
switch($currentquerymode){
case 'title,text':
$wh_query = ' and (TxTitle ' . $wh_query . ' or TxText ' . $wh_query . ')';
break;
case 'title':
$wh_query = ' and (TxTitle ' . $wh_query . ')';
break;
case 'text':
$wh_query = ' and (TxText ' . $wh_query . ')';
break;
}
if ($currentquery!=='') {
if ($currentregexmode !== ''
&& @mysqli_query(
$GLOBALS["DBCONNECTION"],
'SELECT "test" RLIKE ' . convert_string_to_sqlsyntax($currentquery)
) === false
) {
$wh_query = '';
unset($_SESSION['currentwordquery']);
if (isset($_REQUEST['query'])) {
echo '<p id="hide3" style="color:red;text-align:center;">' .
'+++ Warning: Invalid Search +++</p>';
}
}
} else {
$wh_query = '';
}
return $wh_query;
}
/**
* Return the value for $wh_tag.
*
* @param string|int $currentlang Current language ID
*
* @return string Content for $wh_tag.
*/
function edit_texts_get_wh_tag($currentlang)
{
$wh_tag1 = null;
$wh_tag2 = null;
$currenttag1 = validateTextTag(
(string) processSessParam("tag1", "currenttexttag1", '', false),
$currentlang
);
$currenttag2 = validateTextTag(
(string) processSessParam("tag2", "currenttexttag2", '', false),
$currentlang
);
$currenttag12 = (string) processSessParam("tag12", "currenttexttag12", '', false);
if ($currenttag1 == '' && $currenttag2 == '') {
return '';
}
if ($currenttag1 != '') {
if ($currenttag1 == -1) {
$wh_tag1 = "group_concat(TtT2ID) IS NULL";
}
else {
$wh_tag1 = "concat('/',group_concat(TtT2ID separator '/'),'/') like '%/"
. $currenttag1 . "/%'";
}
}
if ($currenttag2 != '') {
if ($currenttag2 == -1) {
$wh_tag2 = "group_concat(TtT2ID) IS NULL";
}
else {
$wh_tag2 = "concat('/',group_concat(TtT2ID separator '/'),'/') like '%/"
. $currenttag2 . "/%'";
}
}
if ($currenttag1 != '' && $currenttag2 == '') {
return " having (" . $wh_tag1 . ') ';
}
if ($currenttag2 != '' && $currenttag1 == '') {
return " having (" . $wh_tag2 . ') ';
}
return " HAVING (($wh_tag1) " . ($currenttag12 ? 'AND' : 'OR') . " ($wh_tag2)) ";
}
/**
* When a mark action is in use, do the action.
*
* @param string $markaction Type of action
* @param array $marked Texts marked.
* @param string $actiondata Values to insert to the database
*
* @return (null|string)[] Number of rows edited, the second element is always null.
*
* @global string $tbpref Database table prefix
*
* @since 2.4.1-fork The second return field is always null
*
* @psalm-return list{string, null}
*/
function edit_texts_mark_action($markaction, $marked, $actiondata): array
{
global $tbpref;
$message = "Multiple Actions: 0";
if (!isset($marked) || !is_array($marked)) {
return array($message, null);
}
$l = count($marked);
if ($l == 0) {
return array($message, null);
}
$id_list = array();
for ($i = 0; $i < $l; $i++) {
$id_list[] = $marked[$i];
}
$list = "(" . implode(",", $id_list) . ")";
if ($markaction == 'del') {
$message3 = runsql(
'delete from ' . $tbpref . 'textitems2 where Ti2TxID in ' . $list,
"Text items deleted"
);
$message2 = runsql(
'delete from ' . $tbpref . 'sentences where SeTxID in ' . $list,
"Sentences deleted"
);
$message1 = runsql(
'delete from ' . $tbpref . 'texts where TxID in ' . $list,
"Texts deleted"
);
$message = $message1 . " / " . $message2 . " / " . $message3;
adjust_autoincr('texts', 'TxID');
adjust_autoincr('sentences', 'SeID');
runsql(
"DELETE " . $tbpref . "texttags
FROM (
" . $tbpref . "texttags
LEFT JOIN " . $tbpref . "texts
ON TtTxID = TxID
)
WHERE TxID IS NULL",
''
);
} elseif ($markaction == 'arch') {
runsql(
'delete from ' . $tbpref . 'textitems2 where Ti2TxID in ' . $list,
""
);
runsql(
'delete from ' . $tbpref . 'sentences where SeTxID in ' . $list,
""
);
$count = 0;
$sql = "select TxID from " . $tbpref . "texts where TxID in " . $list;
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$id = $record['TxID'];
$count += (int)runsql(
'insert into ' . $tbpref . 'archivedtexts (
AtLgID, AtTitle, AtText, AtAnnotatedText, AtAudioURI, AtSourceURI
)
select TxLgID, TxTitle, TxText, TxAnnotatedText, TxAudioURI, TxSourceURI
from ' . $tbpref . 'texts where TxID = ' . $id,
""
);
$aid = get_last_key();
runsql(
'insert into ' . $tbpref . 'archtexttags (AgAtID, AgT2ID)
select ' . $aid . ', TtT2ID
from ' . $tbpref . 'texttags
where TtTxID = ' . $id,
""
);
}
mysqli_free_result($res);
$message = 'Text(s) archived: ' . $count;
runsql('delete from ' . $tbpref . 'texts where TxID in ' . $list, "");
runsql(
"DELETE " . $tbpref . "texttags
FROM (
" . $tbpref . "texttags
LEFT JOIN " . $tbpref . "texts
on TtTxID = TxID
)
WHERE TxID IS NULL",
''
);
adjust_autoincr('texts', 'TxID');
adjust_autoincr('sentences', 'SeID');
} elseif ($markaction == 'addtag' ) {
$message = addtexttaglist($actiondata, $list);
} elseif ($markaction == 'deltag' ) {
removetexttaglist($actiondata, $list);
header("Location: edit_texts.php");
exit();
} elseif ($markaction == 'setsent') {
$count = 0;
$sql = "select WoID, WoTextLC, min(Ti2SeID) as SeID
from " . $tbpref . "words, " . $tbpref . "textitems2
where Ti2LgID = WoLgID and Ti2WoID = WoID and Ti2TxID in " . $list . " and
ifnull(WoSentence,'') not like concat('%{',WoText,'}%')
group by WoID order by WoID, min(Ti2SeID)";
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$sent = getSentence(
$record['SeID'],
$record['WoTextLC'],
(int) getSettingWithDefault('set-term-sentence-count')
);
$count += (int) runsql(
'UPDATE ' . $tbpref . 'words
SET WoSentence = ' . convert_string_to_sqlsyntax(repl_tab_nl($sent[1])) . '
WHERE WoID = ' . $record['WoID'],
''
);
}
mysqli_free_result($res);
$message = 'Term Sentences set from Text(s): ' . $count;
} elseif ($markaction == 'setactsent') {
$count = 0;
$sql = "SELECT WoID, WoTextLC, MIN(Ti2SeID) AS SeID
FROM " . $tbpref . "words, " . $tbpref . "textitems2
WHERE Ti2LgID = WoLgID AND WoStatus != 98 AND WoStatus != 99 AND
Ti2WoID = WoID AND Ti2TxID IN " . $list . " AND
IFNULL(WoSentence,'') NOT LIKE CONCAT('%{',WoText,'}%')
GROUP BY WoID
ORDER BY WoID, MIN(Ti2SeID)";
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$sent = getSentence(
$record['SeID'],
$record['WoTextLC'],
(int) getSettingWithDefault('set-term-sentence-count')
);
$count += (int) runsql(
'update ' . $tbpref . 'words
set WoSentence = ' . convert_string_to_sqlsyntax(repl_tab_nl($sent[1])) . '
where WoID = ' . $record['WoID'],
''
);
}
mysqli_free_result($res);
$message = 'Term Sentences set from Text(s): ' . $count;
} elseif ($markaction == 'rebuild') {
$count = 0;
$sql = "select TxID, TxLgID from " . $tbpref . "texts where TxID in " . $list;
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$id = (int)$record['TxID'];
runsql(
'delete from ' . $tbpref . 'sentences where SeTxID = ' . $id,
"Sentences deleted"
);
runsql(
'delete from ' . $tbpref . 'textitems2 where Ti2TxID = ' . $id,
"Text items deleted"
);
adjust_autoincr('sentences', 'SeID');
splitCheckText(
get_first_value(
'select TxText as value from ' . $tbpref . 'texts where TxID = ' . $id
),
$record['TxLgID'], $id
);
$count++;
}
mysqli_free_result($res);
$message = 'Text(s) reparsed: ' . $count;
} elseif ($markaction == 'test' ) {
$_SESSION['testsql'] = $list;
header("Location: do_test.php?selection=3");
exit();
}
return array($message, null);
}
/**
* Delete an existing text.
*
* @param string|int $txid Text ID
*
* @return string Texts, sentences, and text items deleted.
*
* @global string $tbpref Database table prefix
*/
function edit_texts_delete($txid): string
{
global $tbpref;
$message3 = runsql(
'DELETE FROM ' . $tbpref . 'textitems2 where Ti2TxID = ' . $txid,
"Text items deleted"
);
$message2 = runsql(
'DELETE FROM ' . $tbpref . 'sentences where SeTxID = ' . $txid,
"Sentences deleted"
);
$message1 = runsql(
'DELETE FROM ' . $tbpref . 'texts where TxID = ' . $txid,
"Texts deleted"
);
$message = $message1 . " / " . $message2 . " / " . $message3;
adjust_autoincr('texts', 'TxID');
adjust_autoincr('sentences', 'SeID');
runsql(
"DELETE {$tbpref}texttags
FROM (
{$tbpref}texttags
LEFT JOIN {$tbpref}texts
ON TtTxID = TxID
)
WHERE TxID IS NULL",
''
);
return $message;
}
/**
* Archive a text.
*
* @param int $txid text ID
*
* @return string Number of archives saved, texts deleted, sentences deleted, text items deleted.
*
* @global string $tbpref Database table prefix
*/
function edit_texts_archive($txid): string
{
global $tbpref;
$message3 = runsql(
"DELETE FROM {$tbpref}textitems2 WHERE Ti2TxID = $txid",
"Text items deleted"
);
$message2 = runsql(
"DELETE FROM {$tbpref}sentences WHERE SeTxID = $txid",
"Sentences deleted"
);
$message4 = runsql(
"INSERT INTO {$tbpref}archivedtexts (
AtLgID, AtTitle, AtText, AtAnnotatedText, AtAudioURI, AtSourceURI
) SELECT TxLgID, TxTitle, TxText, TxAnnotatedText, TxAudioURI, TxSourceURI
FROM {$tbpref}texts
WHERE TxID = $txid",
"Archived Texts saved"
);
$id = get_last_key();
runsql(
"INSERT INTO {$tbpref}archtexttags (AgAtID, AgT2ID)
SELECT $id, TtT2ID
FROM {$tbpref}texttags
WHERE TtTxID = $txid",
""
);
$message1 = runsql(
"DELETE FROM {$tbpref}texts WHERE TxID = $txid",
"Texts deleted"
);
$message = "$message4 / $message1 / $message2 / $message3";
adjust_autoincr('texts', 'TxID');
adjust_autoincr('sentences', 'SeID');
runsql(
"DELETE {$tbpref}texttags
FROM (
{$tbpref}texttags
LEFT JOIN {$tbpref}texts
ON TtTxID = TxID
)
WHERE TxID IS NULL",
''
);
return $message;
}
/**
* Do an operation on texts.
*
* @param string $op Operation name
* @param mixed $message1 Unnused
* @param int|bool $no_pagestart If you don't want a page
*
* @return string Edition message (number of rows edited)
*
* @global string $tbpref Database table prefix
*
* @since 2.4.1-fork $message1 is unnused
*/
function edit_texts_do_operation($op, $message1, $no_pagestart): string
{
global $tbpref;
if (strlen(prepare_textdata($_REQUEST['TxText'])) > 65000) {
$message = "Error: Text too long, must be below 65000 Bytes";
$currentlang = (int) validateLang(
(string) processDBParam("filterlang", 'currentlanguage', '', false)
);
if ($no_pagestart) {
pagestart('My ' . getLanguage($currentlang) . ' Texts', true);
}
return $message;
}
$id = null;
if ($op == 'Check') {
// CHECK
echo '<p>
<input type="button" value="<< Back" onclick="history.back();" />
</p>';
splitCheckText(
remove_soft_hyphens($_REQUEST['TxText']), (int)$_REQUEST['TxLgID'], -1
);
echo '<p>
<input type="button" value="<< Back" onclick="history.back();" />
</p>';
pageend();
exit();
}
if (str_starts_with($op, 'Save')) {
// INSERT
runsql(
"INSERT INTO {$tbpref}texts (
TxLgID, TxTitle, TxText, TxAnnotatedText,
TxAudioURI, TxSourceURI
) values( " .
$_REQUEST["TxLgID"] . ', ' .
convert_string_to_sqlsyntax($_REQUEST["TxTitle"]) . ', ' .
convert_string_to_sqlsyntax(remove_soft_hyphens($_REQUEST["TxText"])) . ",
'', " .
convert_string_to_sqlsyntax_nonull($_REQUEST["TxAudioURI"]) . ', ' .
convert_string_to_sqlsyntax($_REQUEST["TxSourceURI"]) . ')',
"Saved"
);
$id = get_last_key();
} else if (str_starts_with($op, 'Change')) {
// UPDATE
runsql(
"UPDATE {$tbpref}texts SET " .
'TxLgID = ' . $_REQUEST["TxLgID"] . ', ' .
'TxTitle = ' . convert_string_to_sqlsyntax($_REQUEST["TxTitle"]) . ', ' .
'TxText = ' . convert_string_to_sqlsyntax(remove_soft_hyphens($_REQUEST["TxText"])) . ', ' .
'TxAudioURI = ' . convert_string_to_sqlsyntax_nonull($_REQUEST["TxAudioURI"]) . ', ' .
'TxSourceURI = ' . convert_string_to_sqlsyntax($_REQUEST["TxSourceURI"]) . ' ' .
'where TxID = ' . $_REQUEST["TxID"], "Updated"
);
$id = (int) $_REQUEST["TxID"];
}
saveTextTags($id);
$message1 = runsql(
"DELETE FROM {$tbpref}sentences WHERE SeTxID = $id",
"Sentences deleted"
);
$message2 = runsql(
"DELETE FROM {$tbpref}textitems2 WHERE Ti2TxID = $id",
"Textitems deleted"
);
adjust_autoincr('sentences', 'SeID');
splitCheckText(
get_first_value(
"SELECT TxText AS value FROM {$tbpref}texts
WHERE TxID = $id"
),
$_REQUEST["TxLgID"],
$id
);
$message = "$message1 / $message2" .
" / Sentences added: " . get_first_value(
"SELECT COUNT(*) AS value
FROM {$tbpref}sentences
WHERE SeTxID = $id"
) .
" / Text items added: " . get_first_value(
"SELECT COUNT(*) AS value
FROM {$tbpref}textitems2
WHERE Ti2TxID = $id"
);
if (str_ends_with($op, "and Open")) {
header('Location: do_text.php?start=' . $id);
exit();
}
return $message;
}
/**
* Display the main form for text creation and edition.
*
* @param Text $text Text object to edit
* @param bool $annotated True if this text has annotations
*
* @return void
*/
function edit_texts_form($text, $annotated)
{
global $tbpref;
$new_text = $text->id == 0;
$sql = "SELECT LgID, LgGoogleTranslateURI FROM {$tbpref}languages
WHERE LgGoogleTranslateURI<>''";
$res = do_mysqli_query($sql);
$return = array();
while ($lg_record = mysqli_fetch_assoc($res)) {
$url = $lg_record["LgGoogleTranslateURI"];
$return[$lg_record["LgID"]] = langFromDict($url);
}
?>
<h2>
<?php echo ($new_text ? "New" : "Edit") ?> Text
<a target="_blank" href="docs/info.html#howtotext">
<img src="icn/question-frame.png" title="Help" alt="Help" />
</a>
</h2>
<script type="text/javascript" charset="utf-8">
/**
* Change the language of inputs for text and title based on selected
* language.
*/
function change_textboxes_language() {
const lid = document.getElementById("TxLgID").value;
const language_data = <?php echo json_encode($return); ?>;
$('#TxTitle').attr('lang', language_data[lid]);
$('#TxText').attr('lang', language_data[lid]);
}
$(document).ready(lwtFormCheck.askBeforeExit);
$(document).ready(change_textboxes_language);
</script>
<div class="flex-spaced">
<div style="<?php echo ($new_text ? "display: none": ''); ?>">
<a href="edit_texts.php?new=1">
<img src="icn/plus-button.png">
New Text
</a>
</div>
<div>
<a href="long_text_import.php">
<img src="icn/plus-button.png">
Long Text Import
</a>
</div>
<div>
<a href="do_feeds.php?page=1&check_autoupdate=1">
<img src="icn/plus-button.png">
Newsfeed Import
</a>
</div>
<div>
<a href="edit_texts.php?query=&page=1">
<img src="icn/drawer--plus.png">
Active Texts
</a>
</div>
<div style="<?php echo ($new_text ? "": 'display: none'); ?>">
<a href="edit_archivedtexts.php?query=&page=1">
<img src="icn/drawer--minus.png">
Archived Texts
</a>
</div>
</div>
<form class="validate" method="post"
action="<?php echo $_SERVER['PHP_SELF'] . ($new_text ? '' : '#rec' . $text->id); ?>" >
<input type="hidden" name="TxID" value="<?php echo $text->id; ?>" />
<table class="tab1" cellspacing="0" cellpadding="5">
<tr>
<td class="td1 right">Language:</td>
<td class="td1">
<select name="TxLgID" id="TxLgID" class="notempty setfocus"
onchange="change_textboxes_language();">
<?php
echo get_languages_selectoptions($text->lgid, "[Choose...]");
?>
</select>
<img src="icn/status-busy.png" title="Field must not be empty"
alt="Field must not be empty" />
</td>
</tr>
<tr>
<td class="td1 right">Title:</td>
<td class="td1">
<input type="text" class="notempty checkoutsidebmp respinput"
data_info="Title" name="TxTitle" id="TxTitle"
value="<?php echo tohtml($text->title); ?>" maxlength="200" />
<img src="icn/status-busy.png" title="Field must not be empty"
alt="Field must not be empty" />
</td>
</tr>
<tr>
<td class="td1 right">
Text:<br /><br />(max.<br />65,000<br />bytes)
</td>
<td class="td1">
<textarea <?php echo getScriptDirectionTag($text->lgid); ?>
name="TxText" id="TxText"
class="notempty checkbytes checkoutsidebmp respinput"
data_maxlength="65000" data_info="Text" rows="20"
><?php echo tohtml($text->text); ?></textarea>
<img src="icn/status-busy.png" title="Field must not be empty"
alt="Field must not be empty" />
</td>
</tr>
<tr <?php echo ($new_text ? 'style="display: none;"' : ''); ?>>
<td class="td1 right">Ann. Text:</td>
<td class="td1">
<?php
if ($annotated) {
echo '<img src="icn/tick.png" title="With Improved Annotation" alt="With Improved Annotation" /> '.
'Exists - May be partially or fully lost if you change the text!<br />' .
'<input type="button" value="Print/Edit..." onclick="location.href=\'print_impr_text.php?text=' .
$text->id . '\';" />';
} else {
echo '<img src="icn/cross.png" title="No Improved Annotation" alt="No Improved Annotation" /> ' .
'- None | <input type="button" value="Create/Print..." onclick="location.href=\'print_impr_text.php?edit=1&text=' .
$text->id . '\';" />';
}
?>
</td>
</tr>
<tr>
<td class="td1 right">Source URI:</td>
<td class="td1">
<input type="url" class="checkurl checkoutsidebmp respinput"
data_info="Source URI" name="TxSourceURI"
value="<?php echo tohtml($text->source); ?>"
maxlength="1000" />
</td>
</tr>
<tr>
<td class="td1 right">Tags:</td>
<td class="td1">
<?php echo getTextTags($text->id); ?>
</td>
</tr>
<tr>
<td class="td1 right" title="A soundtrack or a video to be display while reading">
Media URI:
</td>
<td class="td1">
<input type="text" class="checkoutsidebmp respinput"
data_info="Audio-URI" name="TxAudioURI" maxlength="2048"
value="<?php echo tohtml($text->media_uri); ?>" />
<span id="mediaselect">
<?php echo selectmediapath('TxAudioURI'); ?>
</span>
</td>
</tr>
<?php if ($new_text && YT_API_KEY != null) {
Lwt\Text_From_Youtube\do_form_fragment();
} ?>
<tr>
<td class="td1 right" colspan="2">
<input type="button" value="Cancel"
onclick="{lwtFormCheck.resetDirty(); location.href='edit_texts.php<?php echo ($new_text ? '' : '#rec' . $text->id); ?>';}" />
<input type="submit" name="op" value="Check" />
<input type="submit" name="op"
value="<?php echo ($new_text ? 'Save' : 'Change') ?>" />
<input type="submit" name="op"
value="<?php echo ($new_text ? 'Save' : 'Change') ?> and Open" />
</td>
</tr>
</table>
</form>
<?php
}
/**
* Create a window to make a new text in the target language.
*
* @param int $lid Language ID
*
* @return void
*
* @global string $tbpref
*/
function edit_texts_new($lid)
{
$text = new Text();
$text->id = 0;
$text->lgid = $lid;
edit_texts_form($text, false);
Lwt\Text_From_Youtube\do_js();
}
/**
* Create the main window to edit an existing text.
*
* @param int $txid Text ID
*
* @return void
*
* @global string $tbpref Database table prefix
*/
function edit_texts_change($txid)
{
global $tbpref;
$sql = "SELECT TxID, TxLgID, TxTitle, TxText, TxAudioURI, TxSourceURI,
TxAnnotatedText <> '' AS annot_exists
FROM {$tbpref}texts
WHERE TxID = {$txid}";
$res = do_mysqli_query($sql);
if ($record = mysqli_fetch_assoc($res)) {
$text = new Text();
$text->load_from_db_record($record);
edit_texts_form($text, (bool)$record['annot_exists']);
}
mysqli_free_result($res);
}
/**
* Do the filters form for texts display.
*
* @param string $currentlang Current language ID
* @param int $recno
* @param int $currentpage Current page number
* @param int $pages Total number of pages
*
* @return void
*/
function edit_texts_filters_form($currentlang, $recno, $currentpage, $pages)
{
$currentquery = (string) processSessParam("query", "currenttextquery", '', false);
$currentquerymode = (string) processSessParam(
"query_mode", "currenttextquerymode", 'title,text', false
);
$currentregexmode = getSettingWithDefault("set-regex-mode");
$currenttag1 = validateTextTag(
(string) processSessParam("tag1", "currenttexttag1", '', false),
$currentlang
);
$currenttag2 = validateTextTag(
(string) processSessParam("tag2", "currenttexttag2", '', false),
$currentlang
);
$currentsort = (int) processDBParam("sort", 'currenttextsort', '1', true);
$currenttag12 = (string) processSessParam("tag12", "currenttexttag12", '', false);
?>
<form name="form1" action="#" onsubmit="document.form1.querybutton.click(); return false;">
<table class="tab2" cellspacing="0" cellpadding="5">
<tr>
<th class="th1" colspan="4">Filter <img src="icn/funnel.png" title="Filter" alt="Filter" />
<input type="button" value="Reset All" onclick="resetAll('edit_texts.php');" /></th>
</tr>
<tr>
<td class="td1 center" colspan="2">
Language:
<select name="filterlang" onchange="{setLang(document.form1.filterlang,'edit_texts.php');}"><?php echo get_languages_selectoptions($currentlang, '[Filter off]'); ?></select>
</td>
<td class="td1 center" colspan="2">
<select name="query_mode" onchange="{val=document.form1.query.value;mode=document.form1.query_mode.value; location.href='edit_texts.php?page=1&query=' + val + '&query_mode=' + mode;}">
<option value="title,text"<?php
if($currentquerymode=="title,text") {
echo ' selected="selected"';
} ?>>Title & Text</option>
<option disabled="disabled">------------</option>
<option value="title"<?php
if($currentquerymode=="title") {
echo ' selected="selected"';
} ?>>Title</option>
<option value="text"<?php
echo ($currentquerymode=="text" ? ' selected="selected"' : '');
?>>Text</option>
</select>
<?php
if($currentregexmode=='') {
echo '<span style="vertical-align: middle"> (Wildc.=*): </span>';
} elseif ($currentregexmode=='r') {
echo '<span style="vertical-align: middle"> RegEx Mode: </span>';
} else {
echo '<span style="vertical-align: middle"> RegEx(CS) Mode: </span>';
}?>
<input type="text" name="query" value="<?php echo tohtml($currentquery); ?>" maxlength="50" size="15" />
<input type="button" name="querybutton" value="Filter" onclick="{val=document.form1.query.value;val=encodeURIComponent(val); location.href='edit_texts.php?page=1&query=' + val;}" />
<input type="button" value="Clear" onclick="{location.href='edit_texts.php?page=1&query=';}" />
</td>
</tr>
<tr>
<td class="td1 center" colspan="2">
Tag #1:
<select name="tag1" onchange="{val=document.form1.tag1.options[document.form1.tag1.selectedIndex].value; location.href='edit_texts.php?page=1&tag1=' + val;}">
<?php echo get_texttag_selectoptions($currenttag1, $currentlang); ?>
</select>
</td>
<td class="td1 center">
Tag #1 ..
<select name="tag12" onchange="{val=document.form1.tag12.options[document.form1.tag12.selectedIndex].value; location.href='edit_texts.php?page=1&tag12=' + val;}">
<?php echo get_andor_selectoptions($currenttag12); ?>
</select> .. Tag #2
</td>
<td class="td1 center">
Tag #2:
<select name="tag2" onchange="{val=document.form1.tag2.options[document.form1.tag2.selectedIndex].value; location.href='edit_texts.php?page=1&tag2=' + val;}">
<?php echo get_texttag_selectoptions($currenttag2, $currentlang); ?>
</select>
</td>
</tr>
<?php
if($recno > 0) {
?>
<tr>
<th class="th1" colspan="2">
<?php echo $recno; ?> Text<?php echo ($recno==1?'':'s'); ?>
</th>
<th class="th1" colspan="1">
<?php makePager($currentpage, $pages, 'edit_texts.php', 'form1'); ?>
</th>
<th class="th1" colspan="1">
Sort Order:
<select name="sort" onchange="{val=document.form1.sort.options[document.form1.sort.selectedIndex].value; location.href='edit_texts.php?page=1&sort=' + val;}">
<?php echo get_textssort_selectoptions($currentsort); ?>
</select>
</th>
</tr>
<?php
}
?>
</table>
</form>
<?php
}
/**
* Make links to navigate to other pages if necessary.
*
* @param int $recno Record number
*
* @return void
*/
function edit_texts_other_pages($recno)
{
$maxperpage = (int) getSettingWithDefault('set-texts-per-page');
$pages = $recno == 0 ? 0 : (intval(($recno-1) / $maxperpage) + 1);
if ($pages <= 0) {
return;
}
$currentpage = (int) processSessParam("page", "currenttextpage", '1', true);
if ($currentpage < 1) {
$currentpage = 1;
}
if ($currentpage > $pages) {
$currentpage = $pages;
}
?>
<table class="tab2" cellspacing="0" cellpadding="5">
<tr>
<th class="th1">
<?php echo $recno; ?> Text<?php echo ($recno==1?'':'s'); ?>
</th>
<th class="th1">
<?php makePager($currentpage, $pages, 'edit_texts.php', 'form2'); ?>
</th>
</tr>
</table>
<?php
}
/**
* Display the content of a table row for text edition.
*
* @param array $txrecord
* Various information about the text should contain 'TxID' at least.
* @param string $currentlang
* Current language ID
* @param array{int<0, 5>|98|99, array{string, string}} $statuses
* List of statuses WITH unknown words (status 0)
*
* @return void
*
* @since 2.6.0-fork Audio was never shown
*/
function edit_texts_show_text_row($txrecord, $currentlang, $statuses)
{
$txid = $txrecord['TxID'];
if (isset($txrecord['TxAudioURI'])) {
$audio = trim($txrecord['TxAudioURI']);
} else {
$audio = '';
}
?>
<tr>
<td class="td1 center">
<a name="rec<?php echo $txid; ?>">
<input name="marked[]" class="markcheck" type="checkbox" value="<?php echo $txid; ?>" <?php echo checkTest($txid, 'marked'); ?> />
</a>
</td>
<td class="td1 center">
<a href="do_text.php?start=<?php echo $txid; ?>">
<img src="icn/book-open-bookmark.png" title="Read" alt="Read" />
</a>
<a href="do_test.php?text=<?php echo $txid; ?>">
<img src="icn/question-balloon.png" title="Test" alt="Test" />
</a>
</td>
<td class="td1 center">
<a href="print_text.php?text=<?php echo $txid; ?>">
<img src="icn/printer.png" title="Print" alt="Print" />
</a>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?arch=<?php echo $txid; ?>">
<img src="icn/inbox-download.png" title="Archive" alt="Archive" />
</a>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?chg=<?php echo $txid; ?>">
<img src="icn/document--pencil.png" title="Edit" alt="Edit" />
</a>
<span class="click" onclick="if (confirmDelete()) location.href='<?php echo $_SERVER['PHP_SELF']; ?>?del=<?php echo $txid; ?>';">
<img src="icn/minus-button.png" title="Delete" alt="Delete" />
</span>
</td>
<?php
if ($currentlang == '') {
echo '<td class="td1 center">' . tohtml($txrecord['LgName']) . '</td>';
}
// title
echo '<td class="td1 center">' . tohtml($txrecord['TxTitle']) . '
<span class="smallgray2">' . tohtml($txrecord['taglist']) . '</span> ' ;
if ($audio != '') {
echo '<img src="' . get_file_path('icn/speaker-volume.png') . '" title="With Audio" alt="With Audio" />';
}
if (isset($txrecord['TxSourceURI']) && substr(trim($txrecord['TxSourceURI']), 0, 1)!='#') {
echo ' <a href="' . $txrecord['TxSourceURI'] . '" target="_blank">
<img src="'.get_file_path('icn/chain.png').'" title="Link to Text Source" alt="Link to Text Source" />
</a>';
}
if ($txrecord['annotlen']) {
echo ' <a href="print_impr_text.php?text=' . $txid . '">
<img src="icn/tick.png" title="Annotated Text available" alt="Annotated Text available" />
</a>';
}
echo '</td>';
?>
<!-- total + composition -->
<td class="td1 center">
<span title="Total" id="total_<?php echo $txid; ?>"></span>
</td>
<td class="td1 center">
<span title="Saved" data_id="<?php echo $txid; ?>">
<a class="status4" id="saved_<?php echo $txid; ?>"
href="edit_words.php?page=1&query=&status=&tag12=0&tag2=&tag1=&text_mode=0&text=<?php echo $txid; ?>">
</a>