forked from hans/lwt
-
Notifications
You must be signed in to change notification settings - Fork 9
/
edit_words.php
790 lines (714 loc) · 44.1 KB
/
edit_words.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
<?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/].
***************************************************************/
/**************************************************************
Call: edit_words.php?....
... markaction=[opcode] ... do actions on marked terms
... allaction=[opcode] ... do actions on all terms
... del=[wordid] ... do delete
... op=Save ... do insert new
... op=Change ... do update
... new=1&lang=[langid] ... display new term screen
... chg=[wordid] ... display edit screen
... filterlang=[langid] ... language filter
... sort=[sortcode] ... sort
... page=[pageno] ... page
... query=[termtextfilter] ... term text filter
... status=[statuscode] ... status filter
... text=[textid] ... text filter
... tag1=[tagid] ... tag filter 1
... tag2=[tagid] ... tag filter 2
... tag12=0/1 ... tag1-tag2 OR=0, AND=1
Manage terms
***************************************************************/
require_once( 'settings.inc.php' );
require_once( 'connect.inc.php' );
require_once( 'dbutils.inc.php' );
require_once( 'utilities.inc.php' );
require_once( 'simterms.inc.php' );
$currentlang = validateLang(processDBParam("filterlang",'currentlanguage','',0));
$currentsort = processDBParam("sort",'currentwordsort','1',1);
$currentpage = processSessParam("page","currentwordpage",'1',1);
$currentquery = processSessParam("query","currentwordquery",'',0);
$currentquerymode = processSessParam("query_mode","currentwordquerymode",'term,rom,transl',0);
$currentregexmode = getSettingWithDefault("set-regex-mode");
$currentstatus = processSessParam("status","currentwordstatus",'',0);
$currenttext = validateText(processSessParam("text","currentwordtext",'',0));
$currenttexttag = processSessParam("texttag","currentwordtexttag",'',0);
$currenttextmode = processSessParam("text_mode","currentwordtextmode",0,0);
$currenttag1 = validateTag(processSessParam("tag1","currentwordtag1",'',0),$currentlang);
$currenttag2 = validateTag(processSessParam("tag2","currentwordtag2",'',0),$currentlang);
$currenttag12 = processSessParam("tag12","currentwordtag12",'',0);
$wh_lang = ($currentlang != '') ? (' and WoLgID=' . $currentlang ) : '';
$wh_stat = ($currentstatus != '') ? (' and ' . makeStatusCondition('WoStatus', $currentstatus)) : '';
$wh_query = $currentregexmode . 'like ' . convert_string_to_sqlsyntax(($currentregexmode == '') ? (str_replace("*","%",mb_strtolower($currentquery, 'UTF-8'))) : ($currentquery));
switch($currentquerymode){
case 'term,rom,transl':
$wh_query=' and (WoText ' . $wh_query . ' or IFNULL(WoRomanization,\'*\') ' . $wh_query . ' or WoTranslation ' . $wh_query . ')';
break;
case 'term,rom':
$wh_query=' and (WoText ' . $wh_query . ' or IFNULL(WoRomanization,\'*\') ' . $wh_query . ')';
break;
case 'rom,transl':
$wh_query=' and (IFNULL(WoRomanization,\'*\') ' . $wh_query . ' or WoTranslation ' . $wh_query . ')';
break;
case 'term,transl':
$wh_query=' and (WoText ' . $wh_query . ' or WoTranslation ' . $wh_query . ')';
break;
case 'term':
$wh_query=' and (WoText ' . $wh_query . ')';
break;
case 'rom':
$wh_query=' and (IFNULL(WoRomanization,\'*\') ' . $wh_query . ')';
break;
case 'transl':
$wh_query=' and (WoTranslation ' . $wh_query . ')';
break;
}
if($currentquery!==''){
if($currentregexmode!==''){
if(@mysqli_query($GLOBALS["DBCONNECTION"], 'select "test" rlike ' . convert_string_to_sqlsyntax($currentquery))===false){
$currentquery='';
$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 = '';
if ($currenttag1 == '' && $currenttag2 == '')
$wh_tag = '';
else {
if ($currenttag1 != '') {
if ($currenttag1 == -1)
$wh_tag1 = "group_concat(WtTgID) IS NULL";
else
$wh_tag1 = "concat('/',group_concat(WtTgID separator '/'),'/') like '%/" . $currenttag1 . "/%'";
}
if ($currenttag2 != '') {
if ($currenttag2 == -1)
$wh_tag2 = "group_concat(WtTgID) IS NULL";
else
$wh_tag2 = "concat('/',group_concat(WtTgID 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 . ')) ';
}
$no_pagestart =
(getreq('markaction') == 'exp') ||
(getreq('markaction') == 'exp2') ||
(getreq('markaction') == 'exp3') ||
(getreq('markaction') == 'test') ||
(getreq('markaction') == 'deltag') ||
(getreq('allaction') == 'expall') ||
(getreq('allaction') == 'expall2') ||
(getreq('allaction') == 'expall3') ||
(getreq('allaction') == 'testall') ||
(getreq('allaction') == 'deltagall');
if (! $no_pagestart) {
pagestart('My ' . getLanguage($currentlang) . ' Terms (Words and Expressions)',true);
}
$message = '';
// MARK ACTIONS
if (isset($_REQUEST['markaction'])) {
$markaction = $_REQUEST['markaction'];
$actiondata = stripTheSlashesIfNeeded(getreq('data'));
$message = "Multiple Actions: 0";
if (isset($_REQUEST['marked'])) {
if (is_array($_REQUEST['marked'])) {
$l = count($_REQUEST['marked']);
if ($l > 0 ) {
$list = "(" . $_REQUEST['marked'][0];
for ($i=1; $i<$l; $i++) $list .= "," . $_REQUEST['marked'][$i];
$list .= ")";
if ($markaction == 'del') {
$message = runsql('delete from ' . $tbpref . 'words where WoID in ' . $list, "Deleted");
do_mysqli_query ('update ' . $tbpref . 'textitems2 set Ti2WoID = 0 where Ti2WordCount = 1 and Ti2WoID in ' . $list);
do_mysqli_query ('delete from ' . $tbpref . 'textitems2 where Ti2WoID in ' . $list);
adjust_autoincr('words','WoID');
runsql("DELETE " . $tbpref . "wordtags FROM (" . $tbpref . "wordtags LEFT JOIN " . $tbpref . "words on WtWoID = WoID) WHERE WoID IS NULL",'');
}
elseif ($markaction == 'addtag' ) {
$message = addtaglist($actiondata,$list);
}
elseif ($markaction == 'deltag' ) {
$message = removetaglist($actiondata,$list);
header("Location: edit_words.php");
exit();
}
elseif ($markaction == 'spl1' ) {
$message = runsql('update ' . $tbpref . 'words set WoStatus=WoStatus+1, WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . ' where WoStatus in (1,2,3,4) and WoID in ' . $list, "Updated Status (+1)");
}
elseif ($markaction == 'smi1' ) {
$message = runsql('update ' . $tbpref . 'words set WoStatus=WoStatus-1, WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . ' where WoStatus in (2,3,4,5) and WoID in ' . $list, "Updated Status (-1)");
}
elseif ($markaction == 's5' ) {
$message = runsql('update ' . $tbpref . 'words set WoStatus=5, WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . ' where WoID in ' . $list, "Updated Status (=5)");
}
elseif ($markaction == 's1' ) {
$message = runsql('update ' . $tbpref . 'words set WoStatus=1, WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . ' where WoID in ' . $list, "Updated Status (=1)");
}
elseif ($markaction == 's99' ) {
$message = runsql('update ' . $tbpref . 'words set WoStatus=99, WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . ' where WoID in ' . $list, "Updated Status (=99)");
}
elseif ($markaction == 's98' ) {
$message = runsql('update ' . $tbpref . 'words set WoStatus=98, WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . ' where WoID in ' . $list, "Updated Status (=98)");
}
elseif ($markaction == 'today' ) {
$message = runsql('update ' . $tbpref . 'words set WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . ' where WoID in ' . $list, "Updated Status Date (= Now)");
}
elseif ($markaction == 'delsent' ) {
$message = runsql('update ' . $tbpref . 'words set WoSentence = NULL where WoID in ' . $list, "Term Sentence(s) deleted");
}
elseif ($markaction == 'lower' ) {
$message = runsql('update ' . $tbpref . 'words set WoText = WoTextLC where WoID in ' . $list, "Term(s) set to lowercase");
}
elseif ($markaction == 'cap' ) {
$message = runsql('update ' . $tbpref . 'words set WoText = CONCAT(UPPER(LEFT(WoTextLC,1)),SUBSTRING(WoTextLC,2)) where WoID in ' . $list, "Term(s) capitalized");
}
elseif ($markaction == 'exp' ) {
anki_export('select distinct WoID, LgRightToLeft, LgRegexpWordCharacters, LgName, WoText, WoTranslation, WoRomanization, WoSentence, ifnull(group_concat(distinct TgText order by TgText separator \' \'),\'\') as taglist from ((' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) left join ' . $tbpref . 'tags on TgID = WtTgID), ' . $tbpref . 'languages where WoLgID = LgID AND WoTranslation != \'\' AND WoTranslation != \'*\' and WoSentence like concat(\'%{\',WoText,\'}%\') and WoID in ' . $list . ' group by WoID');
}
elseif ($markaction == 'exp2' ) {
tsv_export('select distinct WoID, LgName, WoText, WoTranslation, WoRomanization, WoSentence, WoStatus, ifnull(group_concat(distinct TgText order by TgText separator \' \'),\'\') as taglist from ((' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) left join ' . $tbpref . 'tags on TgID = WtTgID), ' . $tbpref . 'languages where WoLgID = LgID and WoID in ' . $list . ' group by WoID');
}
elseif ($markaction == 'exp3' ) {
flexible_export('select distinct WoID, LgName, LgExportTemplate, LgRightToLeft, WoText, WoTextLC, WoTranslation, WoRomanization, WoSentence, WoStatus, ifnull(group_concat(distinct TgText order by TgText separator \' \'),\'\') as taglist from ((' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) left join ' . $tbpref . 'tags on TgID = WtTgID), ' . $tbpref . 'languages where WoLgID = LgID and WoID in ' . $list . ' group by WoID');
}
elseif ($markaction == 'test' ) {
$_SESSION['testsql'] = ' ' . $tbpref . 'words where WoID in ' . $list . ' ';
header("Location: do_test.php?selection=1");
exit();
}
}
}
}
}
// ALL ACTIONS
if (isset($_REQUEST['allaction'])) {
$allaction = $_REQUEST['allaction'];
$actiondata = stripTheSlashesIfNeeded(getreq('data'));
if ($allaction == 'delall' || $allaction == 'spl1all' || $allaction == 'smi1all' || $allaction == 's5all' || $allaction == 's1all' || $allaction == 's99all' || $allaction == 's98all' || $allaction == 'todayall' || $allaction == 'addtagall' || $allaction == 'deltagall' || $allaction == 'delsentall' || $allaction == 'lowerall' || $allaction == 'capall') {
if ($currenttext == '') {
$sql = 'select distinct WoID from (' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) where (1=1) ' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag;
} else {
$sql = 'select distinct WoID from (' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID), ' . $tbpref . 'textitems2 where Ti2LgID = WoLgID and Ti2WoID = WoID and Ti2TxID in (' . $currenttext. ')' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag;
}
$cnt=0;
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$id = $record['WoID'];
$message='0';
if ($allaction == 'delall' ) {
$message = runsql('delete from ' . $tbpref . 'words where WoID = ' . $id, "");
do_mysqli_query ('update ' . $tbpref . 'textitems2 set Ti2WoID = 0 where Ti2WordCount = 1 and Ti2WoID = ' . $id);
do_mysqli_query ('delete from ' . $tbpref . 'textitems2 where Ti2WoID = ' . $id);
}
elseif ($allaction == 'addtagall' ) {
addtaglist($actiondata,'(' . $id . ')');
$message = 1;
}
elseif ($allaction == 'deltagall' ) {
removetaglist($actiondata,'(' . $id . ')');
$message = 1;
}
elseif ($allaction == 'spl1all' ) {
$message = runsql('update ' . $tbpref . 'words set WoStatus=WoStatus+1, WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . ' where WoStatus in (1,2,3,4) and WoID = ' . $id, "");
}
elseif ($allaction == 'smi1all' ) {
$message = runsql('update ' . $tbpref . 'words set WoStatus=WoStatus-1, WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . ' where WoStatus in (2,3,4,5) and WoID = ' . $id, "");
}
elseif ($allaction == 's5all' ) {
$message = runsql('update ' . $tbpref . 'words set WoStatus=5, WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . ' where WoID = ' . $id, "");
}
elseif ($allaction == 's1all' ) {
$message = runsql('update ' . $tbpref . 'words set WoStatus=1, WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . ' where WoID = ' . $id, "");
}
elseif ($allaction == 's99all' ) {
$message = runsql('update ' . $tbpref . 'words set WoStatus=99, WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . ' where WoID = ' . $id, "");
}
elseif ($allaction == 's98all' ) {
$message = runsql('update ' . $tbpref . 'words set WoStatus=98, WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . ' where WoID = ' . $id, "");
}
elseif ($allaction == 'todayall' ) {
$message = runsql('update ' . $tbpref . 'words set WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . ' where WoID = ' . $id, "");
}
elseif ($allaction == 'delsentall' ) {
$message = runsql('update ' . $tbpref . 'words set WoSentence = NULL where WoID = ' . $id, "");
}
elseif ($allaction == 'lowerall' ) {
$message = runsql('update ' . $tbpref . 'words set WoText = WoTextLC where WoID = ' . $id, "");
}
elseif ($allaction == 'capall' ) {
$message = runsql('update ' . $tbpref . 'words set WoText = CONCAT(UPPER(LEFT(WoTextLC,1)),SUBSTRING(WoTextLC,2)) where WoID = ' . $id, "");
}
$cnt += (int)$message;
}
mysqli_free_result($res);
if ($allaction == 'deltagall') {
header("Location: edit_words.php");
exit();
}
if ($allaction == 'addtagall') {
$message = "Tag added in $cnt Terms";
}
else if ($allaction == 'delall') {
$message = "Deleted: $cnt Terms";
adjust_autoincr('words','WoID');
runsql("DELETE " . $tbpref . "wordtags FROM (" . $tbpref . "wordtags LEFT JOIN " . $tbpref . "words on WtWoID = WoID) WHERE WoID IS NULL",'');
}
else {
$message = "$cnt Terms changed";
}
}
elseif ($allaction == 'expall' ) {
if ($currenttext == '') {
anki_export('select distinct WoID, LgRightToLeft, LgRegexpWordCharacters, LgName, WoText, WoTranslation, WoRomanization, WoSentence, ifnull(group_concat(distinct TgText order by TgText separator \' \'),\'\') as taglist from ((' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) left join ' . $tbpref . 'tags on TgID = WtTgID), ' . $tbpref . 'languages where WoLgID = LgID AND WoTranslation != \'*\' and WoSentence like concat(\'%{\',WoText,\'}%\') ' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag);
} else {
anki_export('select distinct WoID, LgRightToLeft, LgRegexpWordCharacters, LgName, WoText, WoTranslation, WoRomanization, WoSentence, ifnull(group_concat(distinct TgText order by TgText separator \' \'),\'\') as taglist from ((' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) left join ' . $tbpref . 'tags on TgID = WtTgID), ' . $tbpref . 'languages, ' . $tbpref . 'textitems2 where Ti2LgID = WoLgID and Ti2WoID = WoID and Ti2TxID in (' . $currenttext . ')' . ' and WoLgID = LgID AND WoTranslation != \'*\' and WoSentence like concat(\'%{\',WoText,\'}%\') ' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag);
}
}
elseif ($allaction == 'expall2' ) {
if ($currenttext == '') {
tsv_export('select distinct WoID, LgName, WoText, WoTranslation, WoRomanization, WoSentence, WoStatus, ifnull(group_concat(distinct TgText order by TgText separator \' \'),\'\') as taglist from ((' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) left join ' . $tbpref . 'tags on TgID = WtTgID), ' . $tbpref . 'languages where WoLgID = LgID ' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag);
} else {
tsv_export('select distinct WoID, LgName, WoText, WoTranslation, WoRomanization, WoSentence, WoStatus, ifnull(group_concat(distinct TgText order by TgText separator \' \'),\'\') as taglist from ((' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) left join ' . $tbpref . 'tags on TgID = WtTgID), ' . $tbpref . 'languages, ' . $tbpref . 'textitems2 where Ti2LgID = WoLgID and Ti2WoID = WoID and Ti2TxID in (' . $currenttext . ')' . ' and WoLgID = LgID ' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag);
}
}
elseif ($allaction == 'expall3' ) {
if ($currenttext == '') {
flexible_export('select distinct WoID, LgName, LgExportTemplate, LgRightToLeft, WoText, WoTextLC, WoTranslation, WoRomanization, WoSentence, WoStatus, ifnull(group_concat(distinct TgText order by TgText separator \' \'),\'\') as taglist from ((' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) left join ' . $tbpref . 'tags on TgID = WtTgID), ' . $tbpref . 'languages where WoLgID = LgID ' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag);
} else {
flexible_export('select distinct WoID, LgName, LgExportTemplate, LgRightToLeft, WoText, WoTextLC, WoTranslation, WoRomanization, WoSentence, WoStatus, ifnull(group_concat(distinct TgText order by TgText separator \' \'),\'\') as taglist from ((' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) left join ' . $tbpref . 'tags on TgID = WtTgID), ' . $tbpref . 'languages, ' . $tbpref . 'textitems2 where Ti2LgID = WoLgID and Ti2WoID = WoID and Ti2TxID in (' . $currenttext . ')' . ' and WoLgID = LgID ' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag);
}
}
elseif ($allaction == 'testall' ) {
if ($currenttext == '') {
$sql = 'select distinct WoID from (' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) where (1=1) ' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag;
} else {
$sql = 'select distinct WoID from (' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID), ' . $tbpref . 'textitems2 where Ti2LgID = WoLgID and Ti2WoID = WoID and Ti2TxID in (' . $currenttext . ')' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag;
}
$cnt = 0;
$list = '(';
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$cnt++;
$id = $record['WoID'];
$list .= ($cnt==1 ? '' : ',') . $id;
}
$list .= ")";
mysqli_free_result($res);
$_SESSION['testsql'] = ' ' . $tbpref . 'words where WoID in ' . $list . ' ';
header("Location: do_test.php?selection=1");
exit();
}
}
// DEL
elseif (isset($_REQUEST['del'])) {
$message = runsql('delete from ' . $tbpref . 'words where WoID = ' . $_REQUEST['del'], "Deleted");
adjust_autoincr('words','WoID');
do_mysqli_query ('update ' . $tbpref . 'textitems2 set Ti2WoID = 0 where Ti2WordCount = 1 and Ti2WoID = ' . $_REQUEST['del']);
do_mysqli_query ('delete from ' . $tbpref . 'textitems2 where Ti2WoID = ' . $_REQUEST['del']);
runsql("DELETE " . $tbpref . "wordtags FROM (" . $tbpref . "wordtags LEFT JOIN " . $tbpref . "words on WtWoID = WoID) WHERE WoID IS NULL",'');
}
// INS/UPD
elseif (isset($_REQUEST['op'])) {
$translation_raw = repl_tab_nl(getreq("WoTranslation"));
if ( $translation_raw == '' ) $translation = '*';
else $translation = $translation_raw;
// INSERT
if ($_REQUEST['op'] == 'Save') {
$message = runsql('insert into ' . $tbpref . 'words (WoLgID, WoTextLC, WoText, ' .
'WoStatus, WoTranslation, WoSentence, WoRomanization, WoStatusChanged,' . make_score_random_insert_update('iv') . ') values( ' .
$_REQUEST["WoLgID"] . ', ' .
convert_string_to_sqlsyntax(mb_strtolower($_REQUEST["WoText"], 'UTF-8')) . ', ' .
convert_string_to_sqlsyntax($_REQUEST["WoText"]) . ', ' .
$_REQUEST["WoStatus"] . ', ' .
convert_string_to_sqlsyntax($translation) . ', ' .
convert_string_to_sqlsyntax(repl_tab_nl($_REQUEST["WoSentence"])) . ', ' .
convert_string_to_sqlsyntax($_REQUEST["WoRomanization"]) . ', NOW(), ' .
make_score_random_insert_update('id') . ')', "Saved", $sqlerrdie = FALSE);
$wid = get_last_key();
set_word_count();
$len = get_first_value('select WoWordCount as value from ' . $tbpref . 'words where WoID = ' . $wid);
$textlc = mb_strtolower($_REQUEST["WoText"], 'UTF-8');
if($len > 1){
insertExpressions ($textlc,$_REQUEST["WoLgID"],$wid,$len,1);
}
else {
do_mysqli_query ('UPDATE ' . $tbpref . 'textitems2 SET Ti2WoID = ' . $wid . ' WHERE Ti2LgID = ' . $_REQUEST["WoLgID"] . ' AND LOWER(Ti2Text) = ' . convert_string_to_sqlsyntax_notrim_nonull($textlc));
}
}
// UPDATE
else {
$oldstatus = $_REQUEST["WoOldStatus"];
$newstatus = $_REQUEST["WoStatus"];
$xx = '';
if ($oldstatus != $newstatus) $xx = ', WoStatus = ' . $newstatus . ', WoStatusChanged = NOW()';
$wid = $_REQUEST["WoID"] + 0;
$message = runsql('update ' . $tbpref . 'words set WoText = ' .
convert_string_to_sqlsyntax($_REQUEST["WoText"]) . ', WoTextLC = ' .
convert_string_to_sqlsyntax(mb_strtolower($_REQUEST["WoText"], 'UTF-8')) . ', WoTranslation = ' .
convert_string_to_sqlsyntax($translation) . ', WoSentence = ' .
convert_string_to_sqlsyntax(repl_tab_nl($_REQUEST["WoSentence"])) . ', WoRomanization = ' .
convert_string_to_sqlsyntax($_REQUEST["WoRomanization"]) . $xx . ',' . make_score_random_insert_update('u') . ' where WoID = ' . $_REQUEST["WoID"],
"Updated", $sqlerrdie = FALSE);
}
saveWordTags($wid);
}
// NEW
if (isset($_REQUEST['new']) && isset($_REQUEST['lang'])) {
$scrdir = getScriptDirectionTag($_REQUEST['lang']);
?>
<h4>New Term</h4>
<script type="text/javascript" src="js/unloadformcheck.js" charset="utf-8"></script>
<form name="newword" class="validate" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="WoLgID" id="langfield" value="<?php echo $_REQUEST['lang']; ?>" />
<table class="tab3" cellspacing="0" cellpadding="5">
<tr>
<td class="td1 right">Language:</td>
<td class="td1"><?php echo tohtml(getLanguage($_REQUEST['lang'])); ?></td>
</tr>
<tr>
<td class="td1 right">Term:</td>
<td class="td1"><input <?php echo $scrdir; ?> class="notempty setfocus" type="text" name="WoText" id="wordfield" value="" maxlength="250" size="40" /> <img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" /></td>
</tr>
<?php print_similar_terms_tabrow(); ?>
<tr>
<td class="td1 right">Translation:</td>
<td class="td1"><textarea class="textarea-noreturn checklength" data_maxlength="500" data_info="Translation" name="WoTranslation" cols="40" rows="3"></textarea></td>
</tr>
<tr>
<td class="td1 right">Tags:</td>
<td class="td1">
<?php echo getWordTags(0); ?>
</td>
</tr>
<tr>
<td class="td1 right">Romaniz.:</td>
<td class="td1"><input type="text" name="WoRomanization" value="" maxlength="100" size="40" /></td>
</tr>
<tr>
<td class="td1 right">Sentence<br />Term in {...}:</td>
<td class="td1"><textarea <?php echo $scrdir; ?> name="WoSentence" cols="40" rows="3" class="textarea-noreturn checklength" data_maxlength="1000" data_info="Sentence"></textarea></td>
</tr>
<tr>
<td class="td1 right">Status:</td>
<td class="td1">
<?php echo get_wordstatus_radiooptions(1); ?>
</td>
</tr>
<tr>
<td class="td1 right" colspan="2">
<?php echo createDictLinksInEditWin2($_REQUEST['lang'],'document.forms[\'newword\'].WoSentence','document.forms[\'newword\'].WoText'); ?>
<input type="button" value="Cancel" onclick="{resetDirty(); location.href='edit_words.php';}" />
<input type="submit" name="op" value="Save" /></td>
</tr>
</table>
</form>
<?php
}
// CHG
elseif (isset($_REQUEST['chg'])) {
$sql = 'select * from ' . $tbpref . 'words, ' . $tbpref . 'languages where LgID = WoLgID and WoID = ' . $_REQUEST['chg'];
$res = do_mysqli_query($sql);
if ($record = mysqli_fetch_assoc($res)) {
$wordlc = $record['WoTextLC'];
$transl = repl_tab_nl($record['WoTranslation']);
if($transl == '*') $transl='';
$scrdir = ($record['LgRightToLeft'] ? ' dir="rtl" ' : '');
?>
<h4>Edit Term</h4>
<script type="text/javascript" src="js/unloadformcheck.js" charset="utf-8"></script>
<form name="editword" class="validate" action="<?php echo $_SERVER['PHP_SELF']; ?>#rec<?php echo $_REQUEST['chg']; ?>" method="post">
<input type="hidden" name="WoID" value="<?php echo $record['WoID']; ?>" />
<input type="hidden" name="WoLgID" id="langfield" value="<?php echo $record['WoLgID']; ?>" />
<input type="hidden" name="WoOldStatus" value="<?php echo $record['WoStatus']; ?>" />
<table class="tab3" cellspacing="0" cellpadding="5">
<tr>
<td class="td1 right">Language:</td>
<td class="td1"><?php echo tohtml($record['LgName']); ?></td>
</tr>
<tr title="Normally only change uppercase/lowercase here!">
<td class="td1 right">Term:</td>
<td class="td1"><input <?php echo $scrdir; ?> class="notempty setfocus" type="text" name="WoText" id="wordfield" value="<?php echo tohtml($record['WoText']); ?>" maxlength="250" size="40" /> <img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" />
</td></tr>
<?php print_similar_terms_tabrow(); ?>
<tr>
<td class="td1 right">Translation:</td>
<td class="td1"><textarea class="textarea-noreturn checklength" data_maxlength="500" data_info="Translation" name="WoTranslation" cols="40" rows="3"><?php echo tohtml($transl); ?></textarea></td>
</tr>
<tr>
<td class="td1 right">Tags:</td>
<td class="td1">
<?php echo getWordTags($record['WoID']); ?>
</td>
</tr>
<tr>
<td class="td1 right">Romaniz.:</td>
<td class="td1"><input type="text" name="WoRomanization" maxlength="100" size="40"
value="<?php echo tohtml($record['WoRomanization']); ?>" /></td>
</tr>
<tr>
<td class="td1 right">Sentence<br />Term in {...}:</td>
<td class="td1"><textarea <?php echo $scrdir; ?> class="textarea-noreturn checklength" data_maxlength="1000" data_info="Sentence" name="WoSentence" cols="40" rows="3"><?php echo tohtml(repl_tab_nl($record['WoSentence'])); ?></textarea></td>
</tr>
<tr>
<td class="td1 right">Status:</td>
<td class="td1">
<?php echo get_wordstatus_radiooptions($record['WoStatus']); ?>
</td>
</tr>
<tr>
<td class="td1 right" colspan="2">
<?php echo createDictLinksInEditWin2($record['WoLgID'],'document.forms[\'editword\'].WoSentence','document.forms[\'editword\'].WoText'); ?>
<input type="button" value="Cancel" onclick="{resetDirty(); location.href='edit_words.php#rec<?php echo $_REQUEST['chg']; ?>';}" />
<input type="submit" name="op" value="Change" /></td>
</tr>
</table>
</form>
<div id="exsent"><span class="click" onclick="do_ajax_show_sentences(<?php echo $record['LgID']; ?>, <?php echo prepare_textdata_js($wordlc) . ', ' . prepare_textdata_js("document.forms['editword'].WoSentence") . ', ' . $_REQUEST['chg']; ?>);"><img src="icn/sticky-notes-stack.png" title="Show Sentences" alt="Show Sentences" /> Show Sentences</span></div>
<?php
}
mysqli_free_result($res);
}
// DISPLAY
else {
if (substr($message,0,24) == "Error: Duplicate entry '" &&
substr($message,-24) == "' for key 'WoLgIDTextLC'") {
$lgID = $_REQUEST["WoLgID"] . "-";
$message = substr($message,24+strlen($lgID));
$message = substr($message,0,strlen($message)-24);
$message = "Error: Term '" . $message . "' already exists. Please go back and correct this!";
}
echo error_message_with_hide($message,0);
if ($currenttext == '') {
$sql = 'select count(*) as value from (select WoID from (' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) where (1=1) ' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag .') as dummy';
} else {
$sql = 'select count(*) as value from (select WoID from (' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID), ' . $tbpref . 'textitems2 where Ti2LgID = WoLgID and Ti2WoID = WoID and Ti2TxID in (' . $currenttext . ')' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag .') as dummy';
}
$recno = get_first_value($sql);
if ($debug) echo $sql . ' ===> ' . $recno;
$maxperpage = getSettingWithDefault('set-terms-per-page');
$pages = $recno == 0 ? 0 : (intval(($recno-1) / $maxperpage) + 1);
if ($currentpage < 1) $currentpage = 1;
if ($currentpage > $pages) $currentpage = $pages;
$limit = 'LIMIT ' . (($currentpage-1) * $maxperpage) . ',' . $maxperpage;
$sorts = array('WoTextLC','lower(WoTranslation)','WoID desc','WoID asc','WoStatus, WoTextLC','WoTodayScore','textswordcount desc, WoTextLC asc');
$lsorts = count($sorts);
if ($currentsort < 1) $currentsort = 1;
if ($currentsort > $lsorts) $currentsort = $lsorts;
if ($currentlang != '') {
?>
<p><a href="<?php echo $_SERVER['PHP_SELF']; ?>?new=1&lang=<?php echo $currentlang; ?>"><img src="icn/plus-button.png" title="New" alt="New" /> New <?php echo tohtml(getLanguage($currentlang)); ?> Term ...</a></p>
<?php
} else {
?>
<p><img src="icn/plus-button.png" title="New" alt="New" /> New Term? - Set Language Filter first ...</p>
<?php
}
?>
<form name="form1" action="#" onsubmit="document.form1.querybutton.click(); return false;">
<table class="tab1" 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_words.php');" /></th>
</tr>
<tr>
<td class="td1 center" colspan="2">
Language:
<select name="filterlang" onchange="{setLang(document.form1.filterlang,'edit_words.php');}"><?php echo get_languages_selectoptions($currentlang,'[Filter off]'); ?></select>
</td>
<td class="td1 center" colspan="2">
<select name="text_mode" onchange="{val=document.form1.text_mode.value; location.href='edit_words.php?page=1&texttag=&text=&text_mode=' + val;}">
<option value="0"<?php if($currenttextmode=="0")echo ' selected="selected"'; ?>>Text:</option>
<option value="1"<?php if($currenttextmode=="1")echo ' selected="selected"'; ?>>Text Tag:</option>
</select>
<select name="text" onchange="{val=document.form1.text.options[document.form1.text.selectedIndex].value; location.href='edit_words.php?page=1&text=' + val;}"><?php echo ($currenttextmode!=1)?(get_texts_selectoptions($currentlang,$currenttext)):(get_txtag_selectoptions($currentlang,$currenttexttag)); ?></select>
</td>
</tr>
<tr>
<td class="td1 center" colspan="2" nowrap="nowrap">
Status:
<select name="status" onchange="{val=document.form1.status.options[document.form1.status.selectedIndex].value; location.href='edit_words.php?page=1&status=' + val;}"><?php echo get_wordstatus_selectoptions($currentstatus,true,false); ?></select>
</td>
<td class="td1 center" colspan="2" nowrap="nowrap"><select name="query_mode" onchange="{val=document.form1.query.value;mode=document.form1.query_mode.value; location.href='edit_words.php?page=1&query=' + val + '&query_mode=' + mode;}">
<option value="term,rom,transl"<?php if($currentquerymode=="term,rom,transl")echo ' selected="selected"'; ?>>Term, Rom., Transl.</option>
<option disabled="disabled">------------</option>
<option value="term"<?php if($currentquerymode=="term")echo ' selected="selected"'; ?>>Term</option>
<option value="rom"<?php if($currentquerymode=="rom")echo ' selected="selected"'; ?>>Romanization</option>
<option value="transl"<?php if($currentquerymode=="transl")echo ' selected="selected"'; ?>>Translation</option>
<option disabled="disabled">------------</option>
<option value="term,rom"<?php if($currentquerymode=="term,rom")echo ' selected="selected"'; ?>>Term, Rom.</option>
<option value="term,transl"<?php if($currentquerymode=="term,transl")echo ' selected="selected"'; ?>>Term, Transl.</option>
<option value="rom,transl"<?php if($currentquerymode=="rom,transl")echo ' selected="selected"'; ?>>Rom., Transl.</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);mode=document.form1.query_mode.value; location.href='edit_words.php?page=1&query=' + val + '&query_mode=' + mode;}" />
<input type="button" value="Clear" onclick="{location.href='edit_words.php?page=1&query=';}" />
</td>
</tr>
<tr>
<td class="td1 center" colspan="2" nowrap="nowrap">
Tag #1:
<select name="tag1" onchange="{val=document.form1.tag1.options[document.form1.tag1.selectedIndex].value; location.href='edit_words.php?page=1&tag1=' + val;}"><?php echo get_tag_selectoptions($currenttag1,$currentlang); ?></select>
</td>
<td class="td1 center" nowrap="nowrap">
Tag #1 .. <select name="tag12" onchange="{val=document.form1.tag12.options[document.form1.tag12.selectedIndex].value; location.href='edit_words.php?page=1&tag12=' + val;}"><?php echo get_andor_selectoptions($currenttag12); ?></select> .. Tag #2
</td>
<td class="td1 center" nowrap="nowrap">
Tag #2:
<select name="tag2" onchange="{val=document.form1.tag2.options[document.form1.tag2.selectedIndex].value; location.href='edit_words.php?page=1&tag2=' + val;}"><?php echo get_tag_selectoptions($currenttag2,$currentlang); ?></select>
</td>
</tr>
<?php if($recno > 0) { ?>
<tr>
<th class="th1" colspan="2" nowrap="nowrap">
<?php echo $recno; ?> Term<?php echo ($recno==1?'':'s'); ?>
</th><th class="th1" colspan="1" nowrap="nowrap">
<?php makePager ($currentpage, $pages, 'edit_words.php', 'form1'); ?>
</th><th class="th1" nowrap="nowrap">
Sort Order:
<select name="sort" onchange="{val=document.form1.sort.options[document.form1.sort.selectedIndex].value; location.href='edit_words.php?page=1&sort=' + val;}"><?php echo get_wordssort_selectoptions($currentsort); ?></select>
</th></tr>
<?php } ?>
</table>
</form>
<?php
if ($recno==0) {
?>
<p>No terms found.</p>
<?php
} else {
?>
<form name="form2" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="data" value="" />
<table class="tab1" cellspacing="0" cellpadding="5">
<tr><th class="th1 center" colspan="2">
Multi Actions <img src="icn/lightning.png" title="Multi Actions" alt="Multi Actions" />
</th></tr>
<tr><td class="td1 center" colspan="2">
<b>ALL</b> <?php echo ($recno == 1 ? '1 Term' : $recno . ' Terms'); ?>:
<select name="allaction" onchange="allActionGo(document.form2, document.form2.allaction,<?php echo $recno; ?>);"><?php echo get_allwordsactions_selectoptions(); ?></select>
</td></tr>
<tr><td class="td1 center">
<input type="button" value="Mark All" onclick="selectToggle(true,'form2');" />
<input type="button" value="Mark None" onclick="selectToggle(false,'form2');" />
</td>
<td class="td1 center">Marked Terms:
<select name="markaction" id="markaction" disabled="disabled" onchange="multiActionGo(document.form2, document.form2.markaction);"><?php echo get_multiplewordsactions_selectoptions(); ?></select>
</td></tr></table>
<table class="sortable tab1" cellspacing="0" cellpadding="5">
<tr>
<th class="th1 sorttable_nosort">Mark</th>
<th class="th1 sorttable_nosort">Act.</th>
<?php if ($currentlang == '') echo '<th class="th1 clickable">Lang.</th>'; ?>
<th class="th1 clickable">Term /<br />Romanization</th>
<th class="th1 clickable">Translation [Tags]<br /><span id="waitinfo">Please <img src="<?php print_file_path('icn/waiting2.gif'); ?>" /> wait ...</span></th>
<th class="th1 sorttable_nosort">Se.<br />?</th>
<th class="th1 sorttable_numeric clickable">Stat./<br />Days</th>
<th class="th1 sorttable_numeric clickable">Score<br />%</th>
<?php
if ($currentsort == 7) {
?>
<th class="th1 sorttable_numeric clickable" title="Word Count in Active Texts">WCnt<br />Txts</th>
<?php
}
?>
</tr>
<?php
if ($currentsort == 7) {
if ($currenttext != '')
$sql = '';
else
$sql = 'select WoID, 0 AS textswordcount, WoText, WoTranslation, WoRomanization, WoSentence, ifnull(WoSentence,\'\') like concat(\'%{\',WoText,\'}%\') as SentOK, WoStatus, LgName, LgRightToLeft, LgGoogleTranslateURI, DATEDIFF( NOW( ) , WoStatusChanged ) AS Days, WoTodayScore AS Score, WoTomorrowScore AS Score2, ifnull(concat(\'[\',group_concat(distinct TgText order by TgText separator \', \'),\']\'),\'\') as taglist, WoTextLC, WoTodayScore from ((' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) left join ' . $tbpref . 'tags on TgID = WtTgID), ' . $tbpref . 'languages where WoLgID = LgID and WoID NOT IN (SELECT DISTINCT Ti2WoID from ' . $tbpref . 'textitems2 where Ti2LgID = LgID) ' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag . ' UNION ';
$sql .= 'select WoID, count(WoID) AS textswordcount, WoText, WoTranslation, WoRomanization, WoSentence, ifnull(WoSentence,\'\') like concat(\'%{\',WoText,\'}%\') as SentOK, WoStatus, LgName, LgRightToLeft, LgGoogleTranslateURI, DATEDIFF( NOW( ) , WoStatusChanged ) AS Days, WoTodayScore AS Score, WoTomorrowScore AS Score2, ifnull(concat(\'[\',group_concat(distinct TgText order by TgText separator \', \'),\']\'),\'\') as taglist, WoTextLC, WoTodayScore from ((' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) left join ' . $tbpref . 'tags on TgID = WtTgID), ' . $tbpref . 'languages, ' . $tbpref . 'textitems2 where Ti2LgID = WoLgID and Ti2WoID = WoID and WoLgID = LgID ';
if ($currenttext != '') $sql .= 'and Ti2TxID in (' . $currenttext . ')' . ' ';
$sql .= $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag . ' order by ' . $sorts[$currentsort-1] . ' ' . $limit;
} else {
if ($currenttext == '') {if($wh_tag=='')
$sql = 'select WoID, WoText, WoTranslation, WoRomanization, WoSentence, SentOK, WoStatus, LgName, LgRightToLeft, LgGoogleTranslateURI, Days, WoTodayScore AS Score, WoTomorrowScore AS Score2, ifnull(concat(\'[\',group_concat(distinct TgText order by TgText separator \', \'),\']\'),\'\') as taglist from (select WoID, WoTextLC, WoText, WoTranslation, WoRomanization, WoSentence, ifnull(WoSentence,\'\') like concat(\'%{\',WoText,\'}%\') as SentOK, WoStatus, LgName, LgRightToLeft, LgGoogleTranslateURI, DATEDIFF( NOW( ) , WoStatusChanged ) AS Days, WoTodayScore, WoTomorrowScore from ' . $tbpref . 'words, ' . $tbpref . 'languages where WoLgID = LgID ' . $wh_lang . $wh_stat . $wh_query . ' group by WoID order by ' . $sorts[$currentsort-1] . ' ' . $limit . ') AS AA left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID left join ' . $tbpref . 'tags on TgID = WtTgID group by WoID order by ' . $sorts[$currentsort-1];else
$sql = 'select WoID, WoText, WoTranslation, WoRomanization, WoSentence, ifnull(WoSentence,\'\') like concat(\'%{\',WoText,\'}%\') as SentOK, WoStatus, LgName, LgRightToLeft, LgGoogleTranslateURI, DATEDIFF( NOW( ) , WoStatusChanged ) AS Days, WoTodayScore AS Score, WoTomorrowScore AS Score2, ifnull(concat(\'[\',group_concat(distinct TgText order by TgText separator \', \'),\']\'),\'\') as taglist from ((' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) left join ' . $tbpref . 'tags on TgID = WtTgID), ' . $tbpref . 'languages where WoLgID = LgID ' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag . ' order by ' . $sorts[$currentsort-1] . ' ' . $limit;
} else {
$sql = 'select distinct WoID, WoText, WoTranslation, WoRomanization, WoSentence, ifnull(WoSentence,\'\') like \'%{%}%\' as SentOK, WoStatus, LgName, LgRightToLeft, LgGoogleTranslateURI, DATEDIFF( NOW( ) , WoStatusChanged ) AS Days, WoTodayScore AS Score, WoTomorrowScore AS Score2, ifnull(concat(\'[\',group_concat(distinct TgText order by TgText separator \', \'),\']\'),\'\') as taglist from ((' . $tbpref . 'words left JOIN ' . $tbpref . 'wordtags ON WoID = WtWoID) left join ' . $tbpref . 'tags on TgID = WtTgID), ' . $tbpref . 'languages, ' . $tbpref . 'textitems2 where Ti2LgID = WoLgID and Ti2WoID = WoID and Ti2TxID in (' . $currenttext . ') and WoLgID = LgID ' . $wh_lang . $wh_stat . $wh_query . ' group by WoID ' . $wh_tag . ' order by ' . $sorts[$currentsort-1] . ' ' . $limit;
}
}
if ($debug) echo $sql;
flush();
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$days = $record['Days'];
if ( $record['WoStatus'] > 5 ) $days="-";
$score = $record['Score'];
if ( $score < 0 ) $score='<span class="scorered">0 <img src="icn/status-busy.png" title="Test today!" alt="Test today!" /></span>';
else $score='<span class="scoregreen">' . floor($score) . ($record['Score2'] < 0 ? ' <img src="icn/status-away.png" title="Test tomorrow!" alt="Test tomorrow!" />' : ' <img src="icn/status.png" title="-" alt="-" />') . '</span>';
echo '<tr>';
echo '<td class="td1 center"><a name="rec' . $record['WoID'] . '"><input name="marked[]" type="checkbox" class="markcheck" value="' . $record['WoID'] . '" ' . checkTest($record['WoID'], 'marked') . ' /></a></td>';
echo '<td class="td1 center" nowrap="nowrap"> <a href="' . $_SERVER['PHP_SELF'] . '?chg=' . $record['WoID'] . '"><img src="icn/sticky-note--pencil.png" title="Edit" alt="Edit" /></a> <a href="' . $_SERVER['PHP_SELF'] . '?del=' . $record['WoID'] . '"><img src="icn/minus-button.png" title="Delete" alt="Delete" /></a> </td>';
if ($currentlang == '') echo '<td class="td1 center">' . tohtml($record['LgName']) . '</td>';
echo '<td class="td1"><span';
if(!empty($record['LgGoogleTranslateURI']) && strpos($record['LgGoogleTranslateURI'],'&sl=') !== false) echo ' class="tts_' . preg_replace('/.*[?&]sl=([a-zA-Z\-]*)(&.*)*$/','$1',$record['LgGoogleTranslateURI']) . '"';
echo ($record['LgRightToLeft'] ? ' dir="rtl" ' : '') . '>' . tohtml($record['WoText']) . '</span>' . ($record['WoRomanization'] != '' ? (' / <span id="roman' . $record['WoID'] . '" class="edit_area clickedit">' . tohtml(repl_tab_nl($record['WoRomanization'])) . '</span>') : (' / <span id="roman' . $record['WoID'] . '" class="edit_area clickedit">*</span>')) . '</td>';
echo '<td class="td1"><span id="trans' . $record['WoID'] . '" class="edit_area clickedit">' . tohtml(repl_tab_nl($record['WoTranslation'])) . '</span> <span class="smallgray2">' . tohtml($record['taglist']) . '</span></td>';
echo '<td class="td1 center"><b>' . ($record['SentOK']!=0 ? '<img src="icn/status.png" title="' . tohtml($record['WoSentence']) . '" alt="Yes" />' : '<img src="icn/status-busy.png" title="(No valid sentence)" alt="No" />') . '</b></td>';
echo '<td class="td1 center" title="' . tohtml(get_status_name($record['WoStatus'])) . '">' . tohtml(get_status_abbr($record['WoStatus'])) . ($record['WoStatus'] < 98 ? '/' . $days : '') . '</td>';
echo '<td class="td1 center" nowrap="nowrap">' . $score . '</td>';
if ($currentsort == 7) {
echo '<td class="td1 center" nowrap="nowrap">' . $record['textswordcount'] . '</td>';
}
echo "</tr>\n";
}
mysqli_free_result($res);
?>
</table>
<script type="text/javascript">
//<![CDATA[
$('#waitinfo').addClass('hide');
//]]>
</script>
<?php if( $pages > 1) { ?>
<table class="tab1" cellspacing="0" cellpadding="5">
<tr>
<th class="th1" nowrap="nowrap">
<?php echo $recno; ?> Term<?php echo ($recno==1?'':'s'); ?>
</th><th class="th1" nowrap="nowrap">
<?php makePager ($currentpage, $pages, 'edit_words.php', 'form2'); ?>
</th></tr></table></form>
<?php } ?>
<?php
}
}
pageend();
?>