-
Notifications
You must be signed in to change notification settings - Fork 8
/
utilities.inc.php
executable file
·3408 lines (2984 loc) · 130 KB
/
utilities.inc.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
/**************************************************************
"Learning with Texts" (LWT) is free and unencumbered software
released into the PUBLIC DOMAIN.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a
compiled binary, for any purpose, commercial or non-commercial,
and by any means.
In jurisdictions that recognize copyright laws, the author or
authors of this software dedicate any and all copyright
interest in the software to the public domain. We make this
dedication for the benefit of the public at large and to the
detriment of our heirs and successors. We intend this
dedication to be an overt act of relinquishment in perpetuity
of all present and future rights to this software under
copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
For more information, please refer to [http://unlicense.org/].
***************************************************************/
/**************************************************************
PHP Utility Functions
Plus (at end): Database Connect, .. Select, .. Updates
***************************************************************/
// -------------------------------------------------------------
function get_version() {
global $debug;
return '1.6.3 (April 06 2020)' .
($debug ? ' <span class="red">DEBUG</span>' : '');
}
// -------------------------------------------------------------
function get_version_number() {
$r = 'v';
$v = get_version();
$pos = strpos($v,' ',0);
if ($pos === false) my_die ('Wrong version: '. $v);
$vn = preg_split ("/[.]/", substr($v,0,$pos));
if (count($vn) < 3) my_die ('Wrong version: '. $v);
for ($i=0; $i<3; $i++) $r .= substr('000' . $vn[$i],-3);
return $r; // 'vxxxyyyzzz' wenn version = x.y.z
}
// -------------------------------------------------------------
function my_die($text) {
echo '</select></p></div><div style="padding: 1em; color:red; font-size:120%; background-color:#CEECF5;">' .
'<p><b>Fatal Error:</b> ' .
tohtml($text) .
"</p></div><hr /><pre>Backtrace:\n\n";
debug_print_backtrace ();
echo '</pre><hr />';
die('</body></html>');
}
// -------------------------------------------------------------
function stripTheSlashesIfNeeded($s) {
if(get_magic_quotes_gpc())
return stripslashes($s);
else
return $s;
}
// -------------------------------------------------------------
function getPreviousAndNextTextLinks($textid,$url,$onlyann,$add) {
global $tbpref;
$currentlang = validateLang(processDBParam("filterlang",'currentlanguage','',0));
$wh_lang = ($currentlang != '') ? (' and TxLgID=' . $currentlang) : '';
$currentquery = processSessParam("query","currenttextquery",'',0);
$wh_query = convert_string_to_sqlsyntax(str_replace("*","%",mb_strtolower($currentquery, 'UTF-8')));
$wh_query = ($currentquery != '') ? (' and TxTitle like ' . $wh_query) : '';
$currenttag1 = validateTextTag(processSessParam("tag1","currenttexttag1",'',0),$currentlang);
$currenttag2 = validateTextTag(processSessParam("tag2","currenttexttag2",'',0),$currentlang);
$currenttag12 = processSessParam("tag12","currenttexttag12",'',0);
if ($currenttag1 == '' && $currenttag2 == '')
$wh_tag = '';
else {
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 == '')
$wh_tag = " having (" . $wh_tag1 . ') ';
elseif ($currenttag2 != '' && $currenttag1 == '')
$wh_tag = " having (" . $wh_tag2 . ') ';
else
$wh_tag = " having ((" . $wh_tag1 . ($currenttag12 ? ') AND (' : ') OR (') . $wh_tag2 . ')) ';
}
$currentsort = processDBParam("sort",'currenttextsort','1',1);
$sorts = array('TxTitle','TxID desc','TxID');
$lsorts = count($sorts);
if ($currentsort < 1) $currentsort = 1;
if ($currentsort > $lsorts) $currentsort = $lsorts;
if ($onlyann)
$sql = 'select TxID from ((' . $tbpref . 'texts left JOIN ' . $tbpref . 'texttags ON TxID = TtTxID) left join ' . $tbpref . 'tags2 on T2ID = TtT2ID), ' . $tbpref . 'languages where LgID = TxLgID AND LENGTH(TxAnnotatedText) > 0 ' . $wh_lang . $wh_query . ' group by TxID ' . $wh_tag . ' order by ' . $sorts[$currentsort-1];
else
$sql = 'select TxID from ((' . $tbpref . 'texts left JOIN ' . $tbpref . 'texttags ON TxID = TtTxID) left join ' . $tbpref . 'tags2 on T2ID = TtT2ID), ' . $tbpref . 'languages where LgID = TxLgID ' . $wh_lang . $wh_query . ' group by TxID ' . $wh_tag . ' order by ' . $sorts[$currentsort-1];
$list = array(0);
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
array_push($list, ($record['TxID']+0));
}
mysqli_free_result($res);
array_push($list, 0);
$listlen = count($list);
for ($i=1; $i < $listlen-1; $i++) {
if($list[$i] == $textid) {
if ($list[$i-1] !== 0) {
$title = tohtml(getTextTitle($list[$i-1]));
$prev = '<a href="' . $url . $list[$i-1] . '" target="_top"><img src="icn/navigation-180-button.png" title="Previous Text: ' . $title . '" alt="Previous Text: ' . $title . '" /></a>';
}
else
$prev = '<img src="icn/navigation-180-button-light.png" title="No Previous Text" alt="No Previous Text" />';
if ($list[$i+1] !== 0) {
$title = tohtml(getTextTitle($list[$i+1]));
$next = '<a href="' . $url . $list[$i+1] . '" target="_top"><img src="icn/navigation-000-button.png" title="Next Text: ' . $title . '" alt="Next Text: ' . $title . '" /></a>';
}
else
$next = '<img src="icn/navigation-000-button-light.png" title="No Next Text" alt="No Next Text" />';
return $add . $prev . ' ' . $next;
}
}
return $add . '<img src="icn/navigation-180-button-light.png" title="No Previous Text" alt="No Previous Text" /> <img src="icn/navigation-000-button-light.png" title="No Next Text" alt="No Next Text" />';
}
// -------------------------------------------------------------
function get_tags($refresh = 0) {
global $tbpref;
if (isset($_SESSION['TAGS'])) {
if (is_array($_SESSION['TAGS'])) {
if (isset($_SESSION['TBPREF_TAGS'])) {
if($_SESSION['TBPREF_TAGS'] == $tbpref . url_base()) {
if ($refresh == 0) return $_SESSION['TAGS'];
}
}
}
}
$tags = array();
$sql = 'select TgText from ' . $tbpref . 'tags order by TgText';
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$tags[] = $record["TgText"];
}
mysqli_free_result($res);
$_SESSION['TAGS'] = $tags;
$_SESSION['TBPREF_TAGS'] = $tbpref . url_base();
return $_SESSION['TAGS'];
}
// -------------------------------------------------------------
function get_texttags($refresh = 0) {
global $tbpref;
if (isset($_SESSION['TEXTTAGS'])) {
if (is_array($_SESSION['TEXTTAGS'])) {
if (isset($_SESSION['TBPREF_TEXTTAGS'])) {
if($_SESSION['TBPREF_TEXTTAGS'] == $tbpref . url_base()) {
if ($refresh == 0) return $_SESSION['TEXTTAGS'];
}
}
}
}
$tags = array();
$sql = 'select T2Text from ' . $tbpref . 'tags2 order by T2Text';
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$tags[] = $record["T2Text"];
}
mysqli_free_result($res);
$_SESSION['TEXTTAGS'] = $tags;
$_SESSION['TBPREF_TEXTTAGS'] = $tbpref . url_base();
return $_SESSION['TEXTTAGS'];
}
// -------------------------------------------------------------
function getTextTitle ($textid) {
global $tbpref;
$text = get_first_value("select TxTitle as value from " . $tbpref . "texts where TxID=" . $textid);
if (! isset($text)) $text = "?";
return $text;
}
// -------------------------------------------------------------
function get_tag_selectoptions($v,$l) {
global $tbpref;
if ( ! isset($v) ) $v = '';
$r = "<option value=\"\"" . get_selected($v,'');
$r .= ">[Filter off]</option>";
if ($l == '')
$sql = "select TgID, TgText from " . $tbpref . "words, " . $tbpref . "tags, " . $tbpref . "wordtags where TgID = WtTgID and WtWoID = WoID group by TgID order by TgText";
else
$sql = "select TgID, TgText from " . $tbpref . "words, " . $tbpref . "tags, " . $tbpref . "wordtags where TgID = WtTgID and WtWoID = WoID and WoLgID = " . $l . " group by TgID order by TgText";
$res = do_mysqli_query($sql);
$cnt = 0;
while ($record = mysqli_fetch_assoc($res)) {
$d = $record["TgText"];
$cnt++;
$r .= "<option value=\"" . $record["TgID"] . "\"" . get_selected($v,$record["TgID"]) . ">" . tohtml($d) . "</option>";
}
mysqli_free_result($res);
if ($cnt > 0) {
$r .= "<option disabled=\"disabled\">--------</option>";
$r .= "<option value=\"-1\"" . get_selected($v,-1) . ">UNTAGGED</option>";
}
return $r;
}
// -------------------------------------------------------------
function get_texttag_selectoptions($v,$l) {
global $tbpref;
if ( ! isset($v) ) $v = '';
$r = "<option value=\"\"" . get_selected($v,'');
$r .= ">[Filter off]</option>";
if ($l == '')
$sql = "select T2ID, T2Text from " . $tbpref . "texts, " . $tbpref . "tags2, " . $tbpref . "texttags where T2ID = TtT2ID and TtTxID = TxID group by T2ID order by T2Text";
else
$sql = "select T2ID, T2Text from " . $tbpref . "texts, " . $tbpref . "tags2, " . $tbpref . "texttags where T2ID = TtT2ID and TtTxID = TxID and TxLgID = " . $l . " group by T2ID order by T2Text";
$res = do_mysqli_query($sql);
$cnt = 0;
while ($record = mysqli_fetch_assoc($res)) {
$d = $record["T2Text"];
$cnt++;
$r .= "<option value=\"" . $record["T2ID"] . "\"" . get_selected($v,$record["T2ID"]) . ">" . tohtml($d) . "</option>";
}
mysqli_free_result($res);
if ($cnt > 0) {
$r .= "<option disabled=\"disabled\">--------</option>";
$r .= "<option value=\"-1\"" . get_selected($v,-1) . ">UNTAGGED</option>";
}
return $r;
}
// -------------------------------------------------------------
function get_archivedtexttag_selectoptions($v,$l) {
global $tbpref;
if ( ! isset($v) ) $v = '';
$r = "<option value=\"\"" . get_selected($v,'');
$r .= ">[Filter off]</option>";
if ($l == '')
$sql = "select T2ID, T2Text from " . $tbpref . "archivedtexts, " . $tbpref . "tags2, " . $tbpref . "archtexttags where T2ID = AgT2ID and AgAtID = AtID group by T2ID order by T2Text";
else
$sql = "select T2ID, T2Text from " . $tbpref . "archivedtexts, " . $tbpref . "tags2, " . $tbpref . "archtexttags where T2ID = AgT2ID and AgAtID = AtID and AtLgID = " . $l . " group by T2ID order by T2Text";
$res = do_mysqli_query($sql);
$cnt = 0;
while ($record = mysqli_fetch_assoc($res)) {
$d = $record["T2Text"];
$cnt++;
$r .= "<option value=\"" . $record["T2ID"] . "\"" . get_selected($v,$record["T2ID"]) . ">" . tohtml($d) . "</option>";
}
mysqli_free_result($res);
if ($cnt > 0) {
$r .= "<option disabled=\"disabled\">--------</option>";
$r .= "<option value=\"-1\"" . get_selected($v,-1) . ">UNTAGGED</option>";
}
return $r;
}
// -------------------------------------------------------------
function saveWordTags($wid) {
global $tbpref;
runsql("DELETE from " . $tbpref . "wordtags WHERE WtWoID =" . $wid,'');
if (isset($_REQUEST['TermTags'])) {
if (is_array($_REQUEST['TermTags'])) {
if (isset($_REQUEST['TermTags']['TagList'])) {
if (is_array($_REQUEST['TermTags']['TagList'])) {
$cnt = count($_REQUEST['TermTags']['TagList']);
if ($cnt > 0 ) {
for ($i=0; $i<$cnt; $i++) {
$tag = $_REQUEST['TermTags']['TagList'][$i];
if(! in_array($tag, $_SESSION['TAGS'])) {
runsql('insert into ' . $tbpref . 'tags (TgText) values(' .
convert_string_to_sqlsyntax($tag) . ')', "");
}
runsql('insert into ' . $tbpref . 'wordtags (WtWoID, WtTgID) select ' . $wid . ', TgID from ' . $tbpref . 'tags where TgText = ' . convert_string_to_sqlsyntax($tag), "");
}
get_tags($refresh = 1); // refresh tags cache
}
}
}
}
}
}
// -------------------------------------------------------------
function saveTextTags($tid) {
global $tbpref;
runsql("DELETE from " . $tbpref . "texttags WHERE TtTxID =" . $tid,'');
if (isset($_REQUEST['TextTags'])) {
if (is_array($_REQUEST['TextTags'])) {
if (isset($_REQUEST['TextTags']['TagList'])) {
if (is_array($_REQUEST['TextTags']['TagList'])) {
$cnt = count($_REQUEST['TextTags']['TagList']);
if ($cnt > 0 ) {
for ($i=0; $i<$cnt; $i++) {
$tag = $_REQUEST['TextTags']['TagList'][$i];
if(! in_array($tag, $_SESSION['TEXTTAGS'])) {
runsql('insert into ' . $tbpref . 'tags2 (T2Text) values(' .
convert_string_to_sqlsyntax($tag) . ')', "");
}
runsql('insert into ' . $tbpref . 'texttags (TtTxID, TtT2ID) select ' . $tid . ', T2ID from ' . $tbpref . 'tags2 where T2Text = ' . convert_string_to_sqlsyntax($tag), "");
}
get_texttags($refresh = 1); // refresh tags cache
}
}
}
}
}
}
// -------------------------------------------------------------
function saveArchivedTextTags($tid) {
global $tbpref;
runsql("DELETE from " . $tbpref . "archtexttags WHERE AgAtID =" . $tid,'');
if (isset($_REQUEST['TextTags'])) {
if (is_array($_REQUEST['TextTags'])) {
if (isset($_REQUEST['TextTags']['TagList'])) {
if (is_array($_REQUEST['TextTags']['TagList'])) {
$cnt = count($_REQUEST['TextTags']['TagList']);
if ($cnt > 0 ) {
for ($i=0; $i<$cnt; $i++) {
$tag = $_REQUEST['TextTags']['TagList'][$i];
if(! in_array($tag, $_SESSION['TEXTTAGS'])) {
runsql('insert into ' . $tbpref . 'tags2 (T2Text) values(' .
convert_string_to_sqlsyntax($tag) . ')', "");
}
runsql('insert into ' . $tbpref . 'archtexttags (AgAtID, AgT2ID) select ' . $tid . ', T2ID from ' . $tbpref . 'tags2 where T2Text = ' . convert_string_to_sqlsyntax($tag), "");
}
get_texttags($refresh = 1); // refresh tags cache
}
}
}
}
}
}
// -------------------------------------------------------------
function getWordTags($wid) {
global $tbpref;
$r = '<ul id="termtags">';
if ($wid > 0) {
$sql = 'select TgText from ' . $tbpref . 'wordtags, ' . $tbpref . 'tags where TgID = WtTgID and WtWoID = ' . $wid . ' order by TgText';
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$r .= '<li>' . tohtml($record["TgText"]) . '</li>';
}
mysqli_free_result($res);
}
$r .= '</ul>';
return $r;
}
// -------------------------------------------------------------
function getTextTags($tid) {
global $tbpref;
$r = '<ul id="texttags">';
if ($tid > 0) {
$sql = 'select T2Text from ' . $tbpref . 'texttags, ' . $tbpref . 'tags2 where T2ID = TtT2ID and TtTxID = ' . $tid . ' order by T2Text';
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$r .= '<li>' . tohtml($record["T2Text"]) . '</li>';
}
mysqli_free_result($res);
}
$r .= '</ul>';
return $r;
}
// -------------------------------------------------------------
function getArchivedTextTags($tid) {
global $tbpref;
$r = '<ul id="texttags">';
if ($tid > 0) {
$sql = 'select T2Text from ' . $tbpref . 'archtexttags, ' . $tbpref . 'tags2 where T2ID = AgT2ID and AgAtID = ' . $tid . ' order by T2Text';
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$r .= '<li>' . tohtml($record["T2Text"]) . '</li>';
}
mysqli_free_result($res);
}
$r .= '</ul>';
return $r;
}
// -------------------------------------------------------------
function addtaglist ($item, $list) {
global $tbpref;
$tagid = get_first_value('select TgID as value from ' . $tbpref . 'tags where TgText = ' . convert_string_to_sqlsyntax($item));
if (! isset($tagid)) {
runsql('insert into ' . $tbpref . 'tags (TgText) values(' . convert_string_to_sqlsyntax($item) . ')', "");
$tagid = get_first_value('select TgID as value from ' . $tbpref . 'tags where TgText = ' . convert_string_to_sqlsyntax($item));
}
$sql = 'select WoID from ' . $tbpref . 'words where WoID in ' . $list;
$res = do_mysqli_query($sql);
$cnt = 0;
while ($record = mysqli_fetch_assoc($res)) {
$cnt += runsql('insert ignore into ' . $tbpref . 'wordtags (WtWoID, WtTgID) values(' . $record['WoID'] . ', ' . $tagid . ')', "");
}
mysqli_free_result($res);
get_tags($refresh = 1);
return "Tag added in $cnt Terms";
}
// -------------------------------------------------------------
function addarchtexttaglist ($item, $list) {
global $tbpref;
$tagid = get_first_value('select T2ID as value from ' . $tbpref . 'tags2 where T2Text = ' . convert_string_to_sqlsyntax($item));
if (! isset($tagid)) {
runsql('insert into ' . $tbpref . 'tags2 (T2Text) values(' . convert_string_to_sqlsyntax($item) . ')', "");
$tagid = get_first_value('select T2ID as value from ' . $tbpref . 'tags2 where T2Text = ' . convert_string_to_sqlsyntax($item));
}
$sql = 'select AtID from ' . $tbpref . 'archivedtexts where AtID in ' . $list;
$res = do_mysqli_query($sql);
$cnt = 0;
while ($record = mysqli_fetch_assoc($res)) {
$cnt += runsql('insert ignore into ' . $tbpref . 'archtexttags (AgAtID, AgT2ID) values(' . $record['AtID'] . ', ' . $tagid . ')', "");
}
mysqli_free_result($res);
get_texttags($refresh = 1);
return "Tag added in $cnt Texts";
}
// -------------------------------------------------------------
function addtexttaglist ($item, $list) {
global $tbpref;
$tagid = get_first_value('select T2ID as value from ' . $tbpref . 'tags2 where T2Text = ' . convert_string_to_sqlsyntax($item));
if (! isset($tagid)) {
runsql('insert into ' . $tbpref . 'tags2 (T2Text) values(' . convert_string_to_sqlsyntax($item) . ')', "");
$tagid = get_first_value('select T2ID as value from ' . $tbpref . 'tags2 where T2Text = ' . convert_string_to_sqlsyntax($item));
}
$sql = 'select TxID from ' . $tbpref . 'texts where TxID in ' . $list;
$res = do_mysqli_query($sql);
$cnt = 0;
while ($record = mysqli_fetch_assoc($res)) {
$cnt += runsql('insert ignore into ' . $tbpref . 'texttags (TtTxID, TtT2ID) values(' . $record['TxID'] . ', ' . $tagid . ')', "");
}
mysqli_free_result($res);
get_texttags($refresh = 1);
return "Tag added in $cnt Texts";
}
// -------------------------------------------------------------
function removetaglist ($item, $list) {
global $tbpref;
$tagid = get_first_value('select TgID as value from ' . $tbpref . 'tags where TgText = ' . convert_string_to_sqlsyntax($item));
if (! isset($tagid)) return "Tag " . $item . " not found";
$sql = 'select WoID from ' . $tbpref . 'words where WoID in ' . $list;
$res = do_mysqli_query($sql);
$cnt = 0;
while ($record = mysqli_fetch_assoc($res)) {
$cnt++;
runsql('delete from ' . $tbpref . 'wordtags where WtWoID = ' . $record['WoID'] . ' and WtTgID = ' . $tagid, "");
}
mysqli_free_result($res);
return "Tag removed in $cnt Terms";
}
// -------------------------------------------------------------
function removearchtexttaglist ($item, $list) {
global $tbpref;
$tagid = get_first_value('select T2ID as value from ' . $tbpref . 'tags2 where T2Text = ' . convert_string_to_sqlsyntax($item));
if (! isset($tagid)) return "Tag " . $item . " not found";
$sql = 'select AtID from ' . $tbpref . 'archivedtexts where AtID in ' . $list;
$res = do_mysqli_query($sql);
$cnt = 0;
while ($record = mysqli_fetch_assoc($res)) {
$cnt++;
runsql('delete from ' . $tbpref . 'archtexttags where AgAtID = ' . $record['AtID'] . ' and AgT2ID = ' . $tagid, "");
}
mysqli_free_result($res);
return "Tag removed in $cnt Texts";
}
// -------------------------------------------------------------
function removetexttaglist ($item, $list) {
global $tbpref;
$tagid = get_first_value('select T2ID as value from ' . $tbpref . 'tags2 where T2Text = ' . convert_string_to_sqlsyntax($item));
if (! isset($tagid)) return "Tag " . $item . " not found";
$sql = 'select TxID from ' . $tbpref . 'texts where TxID in ' . $list;
$res = do_mysqli_query($sql);
$cnt = 0;
while ($record = mysqli_fetch_assoc($res)) {
$cnt++;
runsql('delete from ' . $tbpref . 'texttags where TtTxID = ' . $record['TxID'] . ' and TtT2ID = ' . $tagid, "");
}
mysqli_free_result($res);
return "Tag removed in $cnt Texts";
}
// -------------------------------------------------------------
function framesetheader($title) {
@header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
@header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
@header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
@header( 'Pragma: no-cache' );
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!-- ***********************************************************
"Learning with Texts" (LWT) is free and unencumbered software
released into the PUBLIC DOMAIN.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a
compiled binary, for any purpose, commercial or non-commercial,
and by any means.
In jurisdictions that recognize copyright laws, the author or
authors of this software dedicate any and all copyright
interest in the software to the public domain. We make this
dedication for the benefit of the public at large and to the
detriment of our heirs and successors. We intend this
dedication to be an overt act of relinquishment in perpetuity
of all present and future rights to this software under
copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
For more information, please refer to [http://unlicense.org/].
************************************************************ -->
<title>LWT :: <?php echo tohtml($title); ?></title>
</head>
<?php
}
// -------------------------------------------------------------
function pagestart_nobody($titletext, $addcss='') {
global $debug;
global $tbpref;
@header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
@header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
@header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
@header( 'Pragma: no-cache' );
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!-- ***********************************************************
"Learning with Texts" (LWT) is free and unencumbered software
released into the PUBLIC DOMAIN.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a
compiled binary, for any purpose, commercial or non-commercial,
and by any means.
In jurisdictions that recognize copyright laws, the author or
authors of this software dedicate any and all copyright
interest in the software to the public domain. We make this
dedication for the benefit of the public at large and to the
detriment of our heirs and successors. We intend this
dedication to be an overt act of relinquishment in perpetuity
of all present and future rights to this software under
copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
For more information, please refer to [http://unlicense.org/].
************************************************************ -->
<meta name="viewport" content="width=900" />
<link rel="apple-touch-icon" href="img/apple-touch-icon-57x57.png" />
<link rel="apple-touch-icon" sizes="72x72" href="img/apple-touch-icon-72x72.png" />
<link rel="apple-touch-icon" sizes="114x114" href="img/apple-touch-icon-114x114.png" />
<link rel="apple-touch-startup-image" href="img/apple-touch-startup.png">
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="css/jquery.tagit.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<style type="text/css">
<?php echo $addcss . "\n"; ?>
</style>
<script type="text/javascript" src="js/jquery.js" charset="utf-8"></script>
<script type="text/javascript" src="js/jquery.scrollTo.min.js" charset="utf-8"></script>
<script type="text/javascript" src="js/jquery-ui.min.js" charset="utf-8"></script>
<script type="text/javascript" src="js/tag-it.js" charset="utf-8"></script>
<script type="text/javascript" src="js/jquery.jeditable.mini.js" charset="utf-8"></script>
<script type="text/javascript" src="js/sorttable/sorttable.js" charset="utf-8"></script>
<script type="text/javascript" src="js/countuptimer.js" charset="utf-8"></script>
<script type="text/javascript" src="js/overlib/overlib_mini.js" charset="utf-8"></script>
<!-- URLBASE : "<?php echo tohtml(url_base()); ?>" -->
<!-- TBPREF : "<?php echo tohtml($tbpref); ?>" -->
<script type="text/javascript">
//<![CDATA[
<?php echo "var STATUSES = " . json_encode(get_statuses()) . ";\n"; ?>
<?php echo "var TAGS = " . json_encode(get_tags()) . ";\n"; ?>
<?php echo "var TEXTTAGS = " . json_encode(get_texttags()) . ";\n"; ?>
//]]>
</script>
<script type="text/javascript" src="js/pgm.js" charset="utf-8"></script>
<script type="text/javascript" src="js/jq_pgm.js" charset="utf-8"></script>
<title>LWT :: <?php echo $titletext; ?></title>
</head>
<body>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<?php
if ($debug) showRequest();
}
// -------------------------------------------------------------
function pagestart($titletext,$close) {
global $debug;
pagestart_nobody($titletext);
echo '<h4>';
if ($close) echo '<a href="index.php" target="_top">';
echo_lwt_logo();
echo "LWT";
if ($close) {
echo '</a> | ';
quickMenu();
}
echo '</h4><h3>' . $titletext . ($debug ? ' <span class="red">DEBUG</span>' : '') . '</h3>';
echo "<p> </p>";
}
// -------------------------------------------------------------
function url_base() {
$url = parse_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
$r = $url["scheme"] . "://" . $url["host"];
if(isset($url["port"])) $r .= ":" . $url["port"];
if(isset($url["path"])) {
$b = basename($url["path"]);
if (substr($b,-4) == ".php" || substr($b,-4) == ".htm" || substr($b,-5) == ".html")
$r .= dirname($url["path"]);
else
$r .= $url["path"];
}
if(substr($r,-1) !== "/") $r .= "/";
return $r;
}
// -------------------------------------------------------------
function pageend() {
global $debug, $dspltime;
if ($debug) showRequest();
if ($dspltime) echo "\n<p class=\"smallgray2\">" .
round(get_execution_time(),5) . " secs</p>\n";
?></body></html><?php
}
// -------------------------------------------------------------
function echo_lwt_logo() {
global $tbpref;
$pref = substr($tbpref,0,-1);
if($pref == '') $pref = 'Default Table Set';
echo '<img class="lwtlogo" src="img/lwt_icon.png" title="LWT - Current Table Set: ' . tohtml($pref) . '" alt="LWT - Current Table Set: ' . tohtml($pref) . '" />';
}
// -------------------------------------------------------------
function get_execution_time()
{
static $microtime_start = null;
if($microtime_start === null)
{
$microtime_start = microtime(true);
return 0.0;
}
return microtime(true) - $microtime_start;
}
// -------------------------------------------------------------
function getprefixes() {
$prefix = array();
$res = do_mysqli_query(str_replace('_',"\\_","SHOW TABLES LIKE " . convert_string_to_sqlsyntax_nonull('%_settings')));
while ($row = mysqli_fetch_row($res))
$prefix[] = substr($row[0], 0, -9);
mysqli_free_result($res);
return $prefix;
}
// -------------------------------------------------------------
function selectmediapath($f) {
$exists = file_exists('media');
if ($exists) {
if (is_dir ('media')) $msg = '';
else $msg = '<br />[Error: ".../' . basename(getcwd()) . '/media" exists, but it is not a directory.]';
} else {
$msg = '<br />[Directory ".../' . basename(getcwd()) . '/media" does not yet exist.]';
}
$r = '<br /> or choose a file in ".../' . basename(getcwd()) . '/media" (only mp3, ogg, wav files shown): ' . $msg;
if ($msg == '') {
$r .= '<br /><select name="Dir" onchange="{val=this.form.Dir.options[this.form.Dir.selectedIndex].value; if (val != \'\') this.form.' . $f . '.value = val; this.form.Dir.value=\'\';}">';
$r .= '<option value="">[Choose...]</option>';
$r .= selectmediapathoptions('media');
$r .= '</select> ';
}
$r .= ' <span class="click" onclick="do_ajax_update_media_select();"><img src="icn/arrow-circle-135.png" title="Refresh Media Selection" alt="Refresh Media Selection" /> Refresh</span>';
return $r;
}
// -------------------------------------------------------------
function selectmediapathoptions($dir) {
$is_windows = ("WIN" == strtoupper(substr(PHP_OS, 0, 3)));
$mediadir = scandir($dir);
$r = '<option disabled="disabled">-- Directory: ' . tohtml($dir) . ' --</option>';
foreach ($mediadir as $entry) {
if ($is_windows) $entry = mb_convert_encoding ($entry,'UTF-8','ISO-8859-1');
if (substr($entry,0,1) != '.') {
if (! is_dir($dir . '/' . $entry)) {
$ex = substr($entry,-4);
if ( (strcasecmp($ex, '.mp3') == 0) ||
(strcasecmp($ex, '.ogg') == 0) ||
(strcasecmp($ex, '.wav') == 0))
$r .= '<option value="' . tohtml($dir . '/' . $entry) . '">' . tohtml($dir . '/' . $entry) . '</option>';
}
}
}
foreach ($mediadir as $entry) {
if (substr($entry,0,1) != '.') {
if (is_dir($dir . '/' . $entry)) $r .= selectmediapathoptions($dir . '/' . $entry);
}
}
return $r;
}
// -------------------------------------------------------------
function get_seconds_selectoptions($v) {
if ( ! isset($v) ) $v = 5;
$r = '';
for ($i=1; $i <= 10; $i++) {
$r .= "<option value=\"" . $i . "\"" . get_selected($v,$i);
$r .= ">" . $i . " sec</option>";
}
return $r;
}
// -------------------------------------------------------------
function get_playbackrate_selectoptions($v) {
if ( ! isset($v) ) $v = '10';
$r = '';
for ($i=5; $i <= 15; $i++) {
$text = ($i<10 ? (' 0.' . $i . ' x ') : (' 1.' . ($i-10) . ' x ') );
$r .= "<option value=\"" . $i . "\"" . get_selected($v,$i);
$r .= "> " . $text . " </option>";
}
return $r;
}
// -------------------------------------------------------------
function quickMenu() {
?><select id="quickmenu" onchange="{var qm = document.getElementById('quickmenu'); var val=qm.options[qm.selectedIndex].value; qm.selectedIndex=0; if (val != '') { if (val == 'INFO') {top.location.href='info.htm';} else {top.location.href = val + '.php';}}}">
<option value="" selected="selected">[Menu]</option>
<option value="index">Home</option>
<option value="edit_texts">Texts</option>
<option value="edit_archivedtexts">Text Archive</option>
<option value="edit_texttags">Text Tags</option>
<option value="edit_languages">Languages</option>
<option value="edit_words">Terms</option>
<option value="edit_tags">Term Tags</option>
<option value="statistics">Statistics</option>
<option value="check_text">Text Check</option>
<option value="long_text_import">Long Text Import</option>
<option value="upload_words">Term Import</option>
<option value="backup_restore">Backup/Restore</option>
<option value="settings">Settings</option>
<option value="INFO">Help</option>
</select><?php
}
// -------------------------------------------------------------
function error_message_with_hide($msg,$noback) {
if (trim($msg) == '') return '';
if (substr($msg,0,5) == "Error" )
return '<p class="red">*** ' . tohtml($msg) . ' ***' .
($noback ?
'' :
'<br /><input type="button" value="<< Go back and correct <<" onclick="history.back();" />' ) .
'</p>';
else
return '<p id="hide3" class="msgblue">+++ ' . tohtml($msg) . ' +++</p>';
}
// -------------------------------------------------------------
function errorbutton($msg) {
if (substr($msg,0,5) == "Error" )
return '<input type="button" value="<< Back" onclick="history.back();" />';
else
return '';
}
// -------------------------------------------------------------
function optimizedb() {
global $tbpref;
adjust_autoincr('archivedtexts','AtID');
adjust_autoincr('languages','LgID');
adjust_autoincr('sentences','SeID');
adjust_autoincr('textitems','TiID');
adjust_autoincr('texts','TxID');
adjust_autoincr('words','WoID');
adjust_autoincr('tags','TgID');
adjust_autoincr('tags2','T2ID');
$dummy = runsql('OPTIMIZE TABLE ' . $tbpref . 'archivedtexts,' . $tbpref . 'languages,' . $tbpref . 'sentences,' . $tbpref . 'textitems,' . $tbpref . 'texts,' . $tbpref . 'words,' . $tbpref . 'settings,' . $tbpref . 'tags,' . $tbpref . 'wordtags,' . $tbpref . 'tags2,' . $tbpref . 'texttags,' . $tbpref . 'archtexttags, _lwtgeneral', '');
}
// -------------------------------------------------------------
function remove_soft_hyphens($str) {
return str_replace('', '', $str); // first '..' contains Softhyphen 0xC2 0xAD
}
// -------------------------------------------------------------
function limitlength($s, $l) {
if (mb_strlen ($s, 'UTF-8') <= $l) return $s;
return mb_substr($s, 0, $l, 'UTF-8');
}
// -------------------------------------------------------------
function adjust_autoincr($table,$key) {
global $tbpref;
$val = get_first_value('select max(' . $key .')+1 as value from ' . $tbpref . $table);
if (! isset($val)) $val = 1;
$sql = 'alter table ' . $tbpref . $table . ' AUTO_INCREMENT = ' . $val;
$res = do_mysqli_query($sql);
}
// -------------------------------------------------------------
function replace_supp_unicode_planes_char($s) {
return preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xE2\x96\x88", $s);
/* U+2588 = UTF8: E2 96 88 = FULL BLOCK = ⬛︎ */
}
// -------------------------------------------------------------
function prepare_textdata($s) {
return str_replace("\r\n","\n", stripTheSlashesIfNeeded($s));
}
// -------------------------------------------------------------
function prepare_textdata_js($s) {
$s = convert_string_to_sqlsyntax($s);
if($s == "NULL") return "''";
return str_replace("''", "\\'", $s);
}
// -------------------------------------------------------------
function tohtml($s) {
if (isset($s)) return htmlspecialchars($s, ENT_COMPAT, "UTF-8");
else return '';
}
// -------------------------------------------------------------
function makeCounterWithTotal ($max, $num) {
if ($max == 1) return '';
if ($max < 10) return $num . "/" . $max;
return substr(
str_repeat("0", strlen($max)) . $num,
-strlen($max)) .
"/" . $max;
}
// -------------------------------------------------------------
function encodeURI($url) {
$reserved = array(
'%2D'=>'-','%5F'=>'_','%2E'=>'.','%21'=>'!',
'%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')'
);
$unescaped = array(
'%3B'=>';','%2C'=>',','%2F'=>'/','%3F'=>'?','%3A'=>':',
'%40'=>'@','%26'=>'&','%3D'=>'=','%2B'=>'+','%24'=>'$'
);
$score = array(
'%23'=>'#'
);
return strtr(rawurlencode($url), array_merge($reserved,$unescaped,$score));
}
// -------------------------------------------------------------
function showRequest() {
$olderr = error_reporting(0);
echo "<pre>** DEBUGGING **********************************\n";
echo '$GLOBALS...'; print_r($GLOBALS);
echo 'get_version_number()...'; echo get_version_number() . "\n";
echo 'get_magic_quotes_gpc()...'; echo get_magic_quotes_gpc() . "\n";
echo "********************************** DEBUGGING **</pre>";
error_reporting($olderr);
}
// -------------------------------------------------------------
function convert_string_to_sqlsyntax($data) {
$result = "NULL";
$data = trim(prepare_textdata($data));
if($data != "") $result = "'" . mysqli_real_escape_string($GLOBALS['DBCONNECTION'], $data) . "'";
return $result;
}
// -------------------------------------------------------------
function convert_string_to_sqlsyntax_nonull($data) {
$data = trim(prepare_textdata($data));
return "'" . mysqli_real_escape_string($GLOBALS['DBCONNECTION'], $data) . "'";
}
// -------------------------------------------------------------
function convert_string_to_sqlsyntax_notrim_nonull($data) {
return "'" . mysqli_real_escape_string($GLOBALS['DBCONNECTION'], prepare_textdata($data)) . "'";
}
// -------------------------------------------------------------
function remove_spaces($s,$remove) {
if ($remove)
return preg_replace('/\s{1,}/u', '', $s); // '' enthält ​
else
return $s;
}