-
Notifications
You must be signed in to change notification settings - Fork 87
/
utilities.inc.php
2539 lines (2222 loc) · 94.3 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 released into the Public Domain.
This applies worldwide.
In case this is not legally possible, any entity is granted the
right to use this work for any purpose, without any conditions,
unless such conditions are required by law.
Developed by J. Pierre in 2011.
***************************************************************/
/**************************************************************
PHP Utility Functions
Plus (at end): Database Connect, .. Select, .. Update
***************************************************************/
// -------------------------------------------------------------
function get_version() {
global $debug;
return '1.4.5 (October 01 2011)' .
($debug ? ' <span class="red">DEBUG</span>' : '');
}
// -------------------------------------------------------------
function get_version_number() {
$r = 'v';
$v = get_version();
$pos = strpos($v,' ',0);
if ($pos === false) die ('wrong version:'. $v);
$vn = preg_split ("/[.]/", substr($v,0,$pos));
if (count($vn) < 3) 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 stripTheSlashesIfNeeded($s) {
if(get_magic_quotes_gpc())
return stripslashes($s);
else
return $s;
}
// -------------------------------------------------------------
function get_tags($refresh = 0) {
if (isset($_SESSION['TAGS'])) {
if (is_array($_SESSION['TAGS'])) {
if ($refresh == 0) return $_SESSION['TAGS'];
}
}
$tags = array();
$sql = 'select TgText from tags order by TgText';
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
while ($record = mysql_fetch_assoc($res)) {
$tags[] = $record["TgText"];
}
mysql_free_result($res);
$_SESSION['TAGS'] = $tags;
return $_SESSION['TAGS'];
}
// -------------------------------------------------------------
function get_texttags($refresh = 0) {
if (isset($_SESSION['TEXTTAGS'])) {
if (is_array($_SESSION['TEXTTAGS'])) {
if ($refresh == 0) return $_SESSION['TEXTTAGS'];
}
}
$tags = array();
$sql = 'select T2Text from tags2 order by T2Text';
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
while ($record = mysql_fetch_assoc($res)) {
$tags[] = $record["T2Text"];
}
mysql_free_result($res);
$_SESSION['TEXTTAGS'] = $tags;
return $_SESSION['TEXTTAGS'];
}
// -------------------------------------------------------------
function get_tag_selectoptions($v,$l) {
if ( ! isset($v) ) $v = '';
$r = "<option value=\"\"" . get_selected($v,'');
$r .= ">[Filter off]</option>";
if ($l == '')
$sql = "select TgID, TgText from words, tags, wordtags where TgID = WtTgID and WtWoID = WoID group by TgID order by TgText";
else
$sql = "select TgID, TgText from words, tags, wordtags where TgID = WtTgID and WtWoID = WoID and WoLgID = " . $l . " group by TgID order by TgText";
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
$cnt = 0;
while ($record = mysql_fetch_assoc($res)) {
$d = $record["TgText"];
$cnt++;
$r .= "<option value=\"" . $record["TgID"] . "\"" . get_selected($v,$record["TgID"]) . ">" . tohtml($d) . "</option>";
}
mysql_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) {
if ( ! isset($v) ) $v = '';
$r = "<option value=\"\"" . get_selected($v,'');
$r .= ">[Filter off]</option>";
if ($l == '')
$sql = "select T2ID, T2Text from texts, tags2, texttags where T2ID = TtT2ID and TtTxID = TxID group by T2ID order by T2Text";
else
$sql = "select T2ID, T2Text from texts, tags2, texttags where T2ID = TtT2ID and TtTxID = TxID and TxLgID = " . $l . " group by T2ID order by T2Text";
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
$cnt = 0;
while ($record = mysql_fetch_assoc($res)) {
$d = $record["T2Text"];
$cnt++;
$r .= "<option value=\"" . $record["T2ID"] . "\"" . get_selected($v,$record["T2ID"]) . ">" . tohtml($d) . "</option>";
}
mysql_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) {
if ( ! isset($v) ) $v = '';
$r = "<option value=\"\"" . get_selected($v,'');
$r .= ">[Filter off]</option>";
if ($l == '')
$sql = "select T2ID, T2Text from archivedtexts, tags2, archtexttags where T2ID = AgT2ID and AgAtID = AtID group by T2ID order by T2Text";
else
$sql = "select T2ID, T2Text from archivedtexts, tags2, archtexttags where T2ID = AgT2ID and AgAtID = AtID and AtLgID = " . $l . " group by T2ID order by T2Text";
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
$cnt = 0;
while ($record = mysql_fetch_assoc($res)) {
$d = $record["T2Text"];
$cnt++;
$r .= "<option value=\"" . $record["T2ID"] . "\"" . get_selected($v,$record["T2ID"]) . ">" . tohtml($d) . "</option>";
}
mysql_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) {
runsql("DELETE from 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 tags (TgText) values(' .
convert_string_to_sqlsyntax($tag) . ')', "");
}
runsql('insert into wordtags (WtWoID, WtTgID) select ' . $wid . ', TgID from tags where TgText = ' . convert_string_to_sqlsyntax($tag), "");
}
get_tags(1); // refresh tags cache
}
}
}
}
}
}
// -------------------------------------------------------------
function saveTextTags($tid) {
runsql("DELETE from 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 tags2 (T2Text) values(' .
convert_string_to_sqlsyntax($tag) . ')', "");
}
runsql('insert into texttags (TtTxID, TtT2ID) select ' . $tid . ', T2ID from tags2 where T2Text = ' . convert_string_to_sqlsyntax($tag), "");
}
get_texttags(1); // refresh tags cache
}
}
}
}
}
}
// -------------------------------------------------------------
function saveArchivedTextTags($tid) {
runsql("DELETE from 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 tags2 (T2Text) values(' .
convert_string_to_sqlsyntax($tag) . ')', "");
}
runsql('insert into archtexttags (AgAtID, AgT2ID) select ' . $tid . ', T2ID from tags2 where T2Text = ' . convert_string_to_sqlsyntax($tag), "");
}
get_texttags(1); // refresh tags cache
}
}
}
}
}
}
// -------------------------------------------------------------
function getWordTags($wid) {
$r = '<ul id="termtags">';
if ($wid > 0) {
$sql = 'select TgText from wordtags, tags where TgID = WtTgID and WtWoID = ' . $wid . ' order by TgText';
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
while ($record = mysql_fetch_assoc($res)) {
$r .= '<li>' . tohtml($record["TgText"]) . '</li>';
}
mysql_free_result($res);
}
$r .= '</ul>';
return $r;
}
// -------------------------------------------------------------
function getTextTags($tid) {
$r = '<ul id="texttags">';
if ($tid > 0) {
$sql = 'select T2Text from texttags, tags2 where T2ID = TtT2ID and TtTxID = ' . $tid . ' order by T2Text';
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
while ($record = mysql_fetch_assoc($res)) {
$r .= '<li>' . tohtml($record["T2Text"]) . '</li>';
}
mysql_free_result($res);
}
$r .= '</ul>';
return $r;
}
// -------------------------------------------------------------
function getArchivedTextTags($tid) {
$r = '<ul id="texttags">';
if ($tid > 0) {
$sql = 'select T2Text from archtexttags, tags2 where T2ID = AgT2ID and AgAtID = ' . $tid . ' order by T2Text';
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
while ($record = mysql_fetch_assoc($res)) {
$r .= '<li>' . tohtml($record["T2Text"]) . '</li>';
}
mysql_free_result($res);
}
$r .= '</ul>';
return $r;
}
// -------------------------------------------------------------
function addtaglist ($item, $list) {
$tagid = get_first_value('select TgID as value from tags where TgText = ' . convert_string_to_sqlsyntax($item));
if (! isset($tagid)) {
runsql('insert into tags (TgText) values(' . convert_string_to_sqlsyntax($item) . ')', "");
$tagid = get_first_value('select TgID as value from tags where TgText = ' . convert_string_to_sqlsyntax($item));
}
$sql = 'select WoID from words where WoID in ' . $list;
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
$cnt = 0;
while ($record = mysql_fetch_assoc($res)) {
$cnt++;
runsql('insert into wordtags (WtWoID, WtTgID) values(' . $record['WoID'] . ', ' . $tagid . ')', "");
}
mysql_free_result($res);
return "Tag added in $cnt Terms";
}
// -------------------------------------------------------------
function addarchtexttaglist ($item, $list) {
$tagid = get_first_value('select T2ID as value from tags2 where T2Text = ' . convert_string_to_sqlsyntax($item));
if (! isset($tagid)) {
runsql('insert into tags2 (T2Text) values(' . convert_string_to_sqlsyntax($item) . ')', "");
$tagid = get_first_value('select T2ID as value from tags2 where T2Text = ' . convert_string_to_sqlsyntax($item));
}
$sql = 'select AtID from archivedtexts where AtID in ' . $list;
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
$cnt = 0;
while ($record = mysql_fetch_assoc($res)) {
$cnt++;
runsql('insert into archtexttags (AgAtID, AgT2ID) values(' . $record['AtID'] . ', ' . $tagid . ')', "");
}
mysql_free_result($res);
return "Tag added in $cnt Texts";
}
// -------------------------------------------------------------
function addtexttaglist ($item, $list) {
$tagid = get_first_value('select T2ID as value from tags2 where T2Text = ' . convert_string_to_sqlsyntax($item));
if (! isset($tagid)) {
runsql('insert into tags2 (T2Text) values(' . convert_string_to_sqlsyntax($item) . ')', "");
$tagid = get_first_value('select T2ID as value from tags2 where T2Text = ' . convert_string_to_sqlsyntax($item));
}
$sql = 'select TxID from texts where TxID in ' . $list;
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
$cnt = 0;
while ($record = mysql_fetch_assoc($res)) {
$cnt++;
runsql('insert into texttags (TtTxID, TtT2ID) values(' . $record['TxID'] . ', ' . $tagid . ')', "");
}
mysql_free_result($res);
return "Tag added in $cnt Texts";
}
// -------------------------------------------------------------
function removetaglist ($item, $list) {
$tagid = get_first_value('select TgID as value from tags where TgText = ' . convert_string_to_sqlsyntax($item));
if (! isset($tagid)) return "Tag " . $ítem . " not found";
$sql = 'select WoID from words where WoID in ' . $list;
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
$cnt = 0;
while ($record = mysql_fetch_assoc($res)) {
$cnt++;
runsql('delete from wordtags where WtWoID = ' . $record['WoID'] . ' and WtTgID = ' . $tagid, "");
}
mysql_free_result($res);
return "Tag removed in $cnt Terms";
}
// -------------------------------------------------------------
function removearchtexttaglist ($item, $list) {
$tagid = get_first_value('select T2ID as value from tags2 where T2Text = ' . convert_string_to_sqlsyntax($item));
if (! isset($tagid)) return "Tag " . $ítem . " not found";
$sql = 'select AtID from archivedtexts where AtID in ' . $list;
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
$cnt = 0;
while ($record = mysql_fetch_assoc($res)) {
$cnt++;
runsql('delete from archtexttags where AgAtID = ' . $record['AtID'] . ' and AgT2ID = ' . $tagid, "");
}
mysql_free_result($res);
return "Tag removed in $cnt Texts";
}
// -------------------------------------------------------------
function removetexttaglist ($item, $list) {
$tagid = get_first_value('select T2ID as value from tags2 where T2Text = ' . convert_string_to_sqlsyntax($item));
if (! isset($tagid)) return "Tag " . $ítem . " not found";
$sql = 'select TxID from texts where TxID in ' . $list;
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
$cnt = 0;
while ($record = mysql_fetch_assoc($res)) {
$cnt++;
runsql('delete from texttags where TtTxID = ' . $record['TxID'] . ' and TtT2ID = ' . $tagid, "");
}
mysql_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">
<!-- ***********************************************************
"Learning with Texts" (LWT) is released into the Public Domain.
This applies worldwide.
In case this is not legally possible, any entity is granted the
right to use this work for any purpose, without any conditions,
unless such conditions are required by law.
Developed by J. Pierre in 2011.
************************************************************ -->
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Learning with Texts :: <?php echo tohtml($title); ?></title>
</head>
<?php
}
// -------------------------------------------------------------
function pagestart_nobody($titeltext, $addcss='') {
global $debug;
@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">
<!-- ***********************************************************
"Learning with Texts" (LWT) is released into the Public Domain.
This applies worldwide.
In case this is not legally possible, any entity is granted the
right to use this work for any purpose, without any conditions,
unless such conditions are required by law.
Developed by J. Pierre in 2011.
************************************************************ -->
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<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/tagit.ui-zendesk.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/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>
<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>Learning with Texts :: <?php echo $titeltext; ?></title>
</head>
<body>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<?php
}
// -------------------------------------------------------------
function pagestart($titeltext,$close) {
global $debug;
pagestart_nobody($titeltext);
echo '<h4>';
if ($close) echo '<a href="index.php" target="_top">';
echo '<img class="lwtlogo" src="img/lwt_icon.png" alt="Logo" />Learning with Texts';
if ($close) {
echo '</a> | ';
quickMenu();
}
echo '</h4><h3>' . $titeltext . ($debug ? ' <span class="red">DEBUG</span>' : '') . '</h3>';
echo "<p> </p>";
}
// -------------------------------------------------------------
function pageend() {
global $debug;
if ($debug) showRequest();
?></body></html><?php
}
// -------------------------------------------------------------
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 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">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="upload_words">Import</option>
<option value="backup_restore">Backup</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 ?
'' :
' <input type="button" value="<< Back" 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 runsql($sql, $m) {
$res = mysql_query($sql);
if ($res == FALSE) {
$message = "Error: " . mysql_error();
} else {
$num = mysql_affected_rows();
$message = (($m == '') ? $num : ($m . ": " . $num));
}
return $message;
}
// -------------------------------------------------------------
function optimizedb() {
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 archivedtexts,languages,sentences,textitems,texts,words,settings,tags,wordtags,tags2,texttags,archtexttags', '');
}
// -------------------------------------------------------------
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) {
$val = get_first_value('select max(' . $key .')+1 as value from ' . $table);
if (! isset($val)) $val = 1;
$sql = 'alter table ' . $table . ' AUTO_INCREMENT = ' . $val;
$res = mysql_query($sql);
}
// -------------------------------------------------------------
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 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() {
echo "<pre>** DEBUGGING **********************************\n";
if (count($_REQUEST)) { echo '$_REQUEST...'; print_r($_REQUEST); }
if (count($_COOKIE)) { echo '$_COOKIE...'; print_r($_COOKIE); }
if (count($_FILES)) { echo '$_FILES...'; print_r($_FILES); }
if (count($_SESSION)) { echo '$_SESSION...'; print_r($_SESSION); }
echo 'get_version_number()...'; echo get_version_number() . "\n";
echo 'get_magic_quotes_gpc()...'; echo get_magic_quotes_gpc() . "\n";
echo "********************************** DEBUGGING **</pre>";
}
// -------------------------------------------------------------
function convert_string_to_sqlsyntax($data) {
$result = "NULL";
$data = trim(prepare_textdata($data));
if($data != "") $result = "'" . mysql_real_escape_string($data) . "'";
return $result;
}
// -------------------------------------------------------------
function convert_string_to_sqlsyntax_nonull($data) {
$data = trim(prepare_textdata($data));
return "'" . mysql_real_escape_string($data) . "'";
}
// -------------------------------------------------------------
function convert_string_to_sqlsyntax_notrim_nonull($data) {
return "'" . mysql_real_escape_string(prepare_textdata($data)) . "'";
}
// -------------------------------------------------------------
function remove_spaces($s,$remove) {
if ($remove)
return preg_replace('/\s{1,}/u', '', $s); // '' enthält ​
else
return $s;
}
// -------------------------------------------------------------
function getreq($s) {
if ( isset($_REQUEST[$s]) ) {
return trim($_REQUEST[$s]);
} else
return '';
}
// -------------------------------------------------------------
function getsess($s) {
if ( isset($_SESSION[$s]) ) {
return trim($_SESSION[$s]);
} else
return '';
}
// -------------------------------------------------------------
function getSetting($key) {
$val = get_first_value('select StValue as value from settings where StKey = ' . convert_string_to_sqlsyntax($key));
if ( isset($val) ) {
$val = trim($val);
if ($key == 'currentlanguage' ) $val = validateLang($val);
if ($key == 'currenttext' ) $val = validateText($val);
return $val;
}
else return '';
}
// -------------------------------------------------------------
function getSettingWithDefault($key) {
$dft = get_setting_data();
$val = get_first_value('select StValue as value from settings where StKey = ' . convert_string_to_sqlsyntax($key));
if ( isset($val) && $val != '' ) return trim($val);
else {
if (array_key_exists($key,$dft)) return $dft[$key]['dft'];
else return '';
}
}
// -------------------------------------------------------------
function get_audioplayer_selectoptions($v) {
if ( ! isset($v) ) $v = "jplayer.blue.monday.modified";
$r = "<option value=\"jplayer.blue.monday.modified\"" . get_selected($v,"jplayer.blue.monday.modified");
$r .= ">Blue Monday Small</option>";
$r .= "<option value=\"jplayer.blue.monday\"" . get_selected($v,"jplayer.blue.monday");
$r .= ">Blue Monday</option>";
$r .= "<option value=\"jplayer-black-and-yellow\"" . get_selected($v,"jplayer-black-and-yellow");
$r .= ">Black & Yellow</option>";
return $r;
}
// -------------------------------------------------------------
function get_sentence_count_selectoptions($v) {
if ( ! isset($v) ) $v = 1;
$r = "<option value=\"1\"" . get_selected($v,1);
$r .= ">Just ONE</option>";
$r .= "<option value=\"2\"" . get_selected($v,2);
$r .= ">TWO (+previous)</option>";
$r .= "<option value=\"3\"" . get_selected($v,3);
$r .= ">THREE (+previous,+next)</option>";
return $r;
}
// -------------------------------------------------------------
function saveSetting($k,$v) {
$dft = get_setting_data();
if (! isset($v)) $v ='';
$v = stripTheSlashesIfNeeded($v);
runsql('delete from settings where StKey = ' . convert_string_to_sqlsyntax($k), '');
if ($v !== '') {
if (array_key_exists($k,$dft)) {
if ($dft[$k]['num']) {
$v = (int) $v;
if ( $v < $dft[$k]['min'] ) $v = $dft[$k]['dft'];
if ( $v > $dft[$k]['max'] ) $v = $dft[$k]['dft'];
}
}
$dum = runsql('insert into settings (StKey, StValue) values(' .
convert_string_to_sqlsyntax($k) . ', ' .
convert_string_to_sqlsyntax($v) . ')', '');
}
}
// -------------------------------------------------------------
function processSessParam($reqkey,$sesskey,$default,$isnum) {
$result = '';
if(isset($_REQUEST[$reqkey])) {
$reqdata = stripTheSlashesIfNeeded(trim($_REQUEST[$reqkey]));
$_SESSION[$sesskey] = $reqdata;
$result = $reqdata;
}
elseif(isset($_SESSION[$sesskey])) {
$result = $_SESSION[$sesskey];
}
else {
$result = $default;
}
if($isnum) $result = (int)$result;
return $result;
}
// -------------------------------------------------------------
function processDBParam($reqkey,$dbkey,$default,$isnum) {
$result = '';
$dbdata = getSetting($dbkey);
if(isset($_REQUEST[$reqkey])) {
$reqdata = stripTheSlashesIfNeeded(trim($_REQUEST[$reqkey]));
saveSetting($dbkey,$reqdata);
$result = $reqdata;
}
elseif($dbdata != '') {
$result = $dbdata;
}
else {
$result = $default;
}
if($isnum) $result = (int)$result;
return $result;
}
// -------------------------------------------------------------
function validateLang($currentlang) {
if ($currentlang != '') {
if (
get_first_value(
'select count(LgID) as value from languages where LgID=' .
((int)$currentlang)
) == 0
) $currentlang = '';
}
return $currentlang;
}
// -------------------------------------------------------------
function validateText($currenttext) {
if ($currenttext != '') {
if (
get_first_value(
'select count(TxID) as value from texts where TxID=' .
((int)$currenttext)
) == 0
) $currenttext = '';
}
return $currenttext;
}
// -------------------------------------------------------------
function validateTag($currenttag,$currentlang) {
if ($currenttag != '' && $currenttag != -1) {
if ($currentlang == '')
$sql = "select (" . $currenttag . " in (select TgID from words, tags, wordtags where TgID = WtTgID and WtWoID = WoID group by TgID order by TgText)) as value";
else
$sql = "select (" . $currenttag . " in (select TgID from words, tags, wordtags where TgID = WtTgID and WtWoID = WoID and WoLgID = " . $currentlang . " group by TgID order by TgText)) as value";
$r = get_first_value($sql);
if ( $r == 0 ) $currenttag = '';
}
return $currenttag;
}
// -------------------------------------------------------------
function validateArchTextTag($currenttag,$currentlang) {
if ($currenttag != '' && $currenttag != -1) {
if ($currentlang == '')
$sql = "select (" . $currenttag . " in (select T2ID from archivedtexts, tags2, archtexttags where T2ID = AgT2ID and AgAtID = AtID group by T2ID order by T2Text)) as value";
else
$sql = "select (" . $currenttag . " in (select T2ID from archivedtexts, tags2, archtexttags where T2ID = AgT2ID and AgAtID = AtID and AtLgID = " . $currentlang . " group by T2ID order by T2Text)) as value";
$r = get_first_value($sql);
if ( $r == 0 ) $currenttag = '';
}
return $currenttag;
}
// -------------------------------------------------------------
function validateTextTag($currenttag,$currentlang) {
if ($currenttag != '' && $currenttag != -1) {
if ($currentlang == '')
$sql = "select (" . $currenttag . " in (select T2ID from texts, tags2, texttags where T2ID = TtT2ID and TtTxID = TxID group by T2ID order by T2Text)) as value";
else
$sql = "select (" . $currenttag . " in (select T2ID from texts, tags2, texttags where T2ID = TtT2ID and TtTxID = TxID and TxLgID = " . $currentlang . " group by T2ID order by T2Text)) as value";
$r = get_first_value($sql);
if ( $r == 0 ) $currenttag = '';
}
return $currenttag;
}
// -------------------------------------------------------------
function getWordTagList($wid, $before=' ', $brack=1, $tohtml=1) {
$r = get_first_value("select ifnull(" . ($brack ? "concat('['," : "") . "group_concat(distinct TgText order by TgText separator ', ')" . ($brack ? ",']')" : "") . ",'') as value from ((words left join wordtags on WoID = WtWoID) left join tags on TgID = WtTgID) where WoID = " . $wid);
if ($r != '') $r = $before . $r;
if ($tohtml) $r = tohtml($r);
return $r;
}
// -------------------------------------------------------------
function get_first_value($sql) {
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
$record = mysql_fetch_assoc($res);
if ($record)
$d = $record["value"];
else
$d = NULL;
mysql_free_result($res);
return $d;
}
// -------------------------------------------------------------
function get_last_key() {
return get_first_value('SELECT LAST_INSERT_ID() as value');
}
// -------------------------------------------------------------
function get_checked($value) {
if (! isset($value)) return '';
if ((int)$value != 0) return ' checked="checked" ';
return '';
}
// -------------------------------------------------------------
function get_selected($value,$selval) {
if (! isset($value)) return '';
if ($value == $selval) return ' selected="selected" ';
return '';
}
// -------------------------------------------------------------
function get_languages_selectoptions($v,$dt) {
$sql = "select LgID, LgName from languages order by LgName";
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid query: $sql");
if ( ! isset($v) || trim($v) == '' ) {