This repository has been archived by the owner on Nov 19, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.tx_metafeedit_sqlengine.php
1451 lines (1298 loc) · 57.5 KB
/
class.tx_metafeedit_sqlengine.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
/***************************************************************
* Copyright notice
*
* (c) 2006 Christophe BALISKY ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* This is a API for handling sql requests .
*
* @author Christophe BALISKY <[email protected]>
*/
// Necessary includes
class tx_metafeedit_sqlengine {
var $prefixId = 'tx_metafeedit';
var $feadminlib;
/**
* iniatialising Lib Object
*
* @param [type] $title: ...
* @param [type] $content: ...
* @param [type] $DEBUG: ...
* @return [type] ...
*/
function debug($title,$content,&$DEBUG) {
if (is_array($content)) $content=Tx_MetaFeedit_Lib_ViewArray::viewArray($content);
if (is_object($content)) {
//$content='';
ob_start();
print_r($content);
$content ='<pre>'. ob_get_contents().'</pre>';
ob_clean();
}
$DEBUG.=($title?"<br/><hr/><h3>$title</h3><br/>":'').$content;
}
/* Group By Field Break Footer ...
*/
function getGroupByFooterSums(&$conf,$prefix,&$GBMarkerArray,$fN,&$sql,&$row,$end,&$DEBUG) {
if ($conf['list.']['sumFields']) {
$sumFields = '';
$sumSQLFields = '';
$somme = 0;
$sumFields = explode(',', $conf['list.']['sumFields']);
foreach($sumFields as $fieldName) {
if ($conf['list.']['sqlcalcfields.'][$fieldName]) {
$calcField=$conf['list.']['sqlcalcfields.'][$fieldName]; // TO BE IMPROVED
if ($calcField) {
if (preg_match("/min\(|max\(|count\(|sum\(|avg\(/i",$calcField)) {
// we test for group by functions
$sumSQLFields.=$sumSQLFields?",$calcField as sum_$fieldName":"$calcField as sum_$fieldName";
} else {
$sumSQLFields.=$sumSQLFields?",sum($calcField) as sum_$fieldName":"sum($calcField) as sum_$fieldName";
}
}
}
else
{
$sumSQLFields.=$sumSQLFields?",sum($fieldName) as sum_$fieldName":"sum($fieldName) as sum_$fieldName";
}
}
$sumSQLFields.=', count(*) as metafeeditnbelts';
if ($sql['groupBy']) $sumSQLFields.=','.$conf['table'].'.*';
$WHERE=$sql['where'];
$fNA=t3lib_div::trimexplode(',',$conf['list.']['groupByFieldBreaks']);
$i=0;
$GBA=t3lib_div::trimexplode(',',$sql['gbFields']);
$GROUPBY=$sql['groupBy'];
$endgb=0;
foreach($fNA as $fNe) {
$fN2=t3lib_div::trimexplode(':',$fNe);
$fNi=$fN2[0];
if($fN2[2] || $endgb) {
//$WHERE.=" and $fN2[0]=".$row[$fNi];
/* See below
$calcField=$conf['list.']['sqlcalcfields.'][$fNi]; // TO BE IMPROVED
if ($calcField) {
$sumSQLFields.=$sumSQLFields?",$calcField as $fNi":"$calcField as $fNi";
}
*/
if (!$endgb) {
$GROUPBY=$GROUPBY?$GROUPBY.','.$fN2[0]:$fN2[0];
$HAVING=$HAVING?$HAVING." and $fN2[0]=".$row[$fNi]:" HAVING $fN2[0]=".$row[$fNi];
}
} else {
if (strpos($fNi,'.')===false && $row[$fNi]) {
//$table = $this->getForeignTableFromField($fNi, $conf);
$WHERE.=" and $conf[table].$fNi=".$row[$fNi];
$GROUPBY=$GROUPBY?$GROUPBY.','.$conf[table].'.'.$fNi:$conf[table].'.'.$fNi;
} else {
$WHERE.=$this->makeSQLJoinWhere($conf['table'],$fNi,$conf,$row[$fNi]);
}
}
// We stop at our depth level ...
if ($fNi==$fN) {
$endgb=1;
}
}
$GROUPBY=strpos($GROUPBY,"GROUP BY")?$GROUPBY:($GROUPBY?" GROUP BY ".$GROUPBY:'');
if ($conf['list.']['havingString']) $HAVING=$HAVING?$HAVING.' AND '.$conf['list.']['havingString']:' HAVING '.$conf['list.']['havingString'];
// Check group by fields for calculated fields ..
/*if (is_array($conf['list.']['sqlcalcfields.'])) foreach ($conf['list.']['sqlcalcfields.'] as $fn=>$calcField) {
$sumSQLFields.=$sumSQLFields?",$calcField as $fn":"$calcField as $fn";
}*/
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($sumSQLFields, $sql['fromTables'], '1 '.$WHERE.$GROUPBY.$HAVING);
if ($conf['debug.']['sql']) $this->debug('Group by footer',$GLOBALS['TYPO3_DB']->SELECTquery($sumSQLFields, $sql['fromTables'], '1 '.$WHERE.$GROUPBY.$HAVING),$DEBUG);
$value=array();
while($valueelt = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
foreach($valueelt as $key=>$val) {
$value[$key]+=$val;
if ($key=='metafeeditnbelts') break;
}
}
foreach ($sumFields as $fieldName){
// we handle a stdWrap on the Data..
$std=$conf[$conf['cmdmode'].'.']['stdWrap.']?$conf[$conf['cmdmode'].'.']['stdWrap.']:$conf['stdWrap.'];
if ($std[$fieldName.'.'] || $std[$table.'.'][$fieldName.'.']) {
if ($std[$fieldName.'.']) $stdConf = $std[$fieldName.'.'];
if ($std[$table.'.'][$fieldName.'.']) $stdConf = $std[$table.'.'][$fieldName.'.'];
//$dataArr['EVAL_'.$_fN] =
$value['sum_'.$fieldName]=$this->cObj->stdWrap($value['sum_'.$fieldName], $stdConf);
}
$GBMarkerArray["###".$prefix."_".$fN."_FIELD_$fieldName###"]= $value['sum_'.$fieldName];
//$i++;
}
$GBMarkerArray["###".$prefix."_".$fN."_FIELD_metafeeditnbelts###"]= $value['metafeeditnbelts'];
//$sumcontent=$this->cObj->stdWrap(trim($this->cObj->substituteMarkerArray($itemSumCode, $this->markerArray)),$conf['list.']['sumWrap.']);
//$content=$this->cObj->substituteSubpart($content,'###SUM_FIELDS###',$sumcontent);
}
return true;
}
/**
* *******************************************************************************************
* SQL FUNCTIONS
* *********************************************************************************************/
// this function handles Foreign table relations (level 1) , it allows us to get foreign table name from field
// it returns foreigntable name and name of field in foreign table
// Ex : if editing table fe_users, for relation usergroups.uid this function would return :
// $ret['table']='fe_groups'
// $ret['fNiD']='uid'
function getForeignTableFromField($fN, &$conf,$table='') {
$ret = array();
$fNA = t3lib_div::trimexplode('.', $fN);
$fNiD = $fN;
$table = $table?$table:$conf['table'];
if (count($fNA) == 2) {
// Foreign Table
$table = $conf['TCAN'][$table]['columns'][$fNA[0]]['config']['foreign_table'];
$fNiD = $fNA[1];
$ret['ft'] = 1;
} elseif (count($fNA) > 2) {
die("We don't handle more than one foreign table level !");
}
$ret['table'] = $table;
$ret['fNiD'] = $fNiD;
return $ret;
}
/**
* [Describe function...]
*
* @param [type] $table: ...
* @param [type] $relation: ...
* @param [type] $conf: ...
* @param [type] $Tables: ...
* @return [type] ...
*/
function makeSQLJoin($table,$relation,&$conf,$Tables) {
return "";
}
function makeSQLJoinWhere($table,$relation,&$conf,$val) {
$relA=t3lib_div::trimexplode('.',$relation);
$c=count($relA);
$c--;
foreach($relA as $rel) {
if ($c<=0) break;
$c--;
$table=$conf['TCAN'][$table]['columns'][$rel]["config"]["foreign_table"];
}
return " and $table.$rel=$val";
}
/**
* DBmayFEUserEditSelectMM
*
* @param [type] $table: ...
* @param [type] $fe_user: ...
* @param [type] $allowedGroups: ...
* @param [type] $fe_userEditSelf: ...
* @param [type] $mmTable: ...
* @return [type] ...
*/
function DBmayFEUserEditSelectMM($table,$fe_user,$allowedGroups,$fe_userEditSelf, &$mmTable,&$conf) {
$ret='';
if ($conf['debug']) echo Tx_MetaFeedit_Lib_ViewArray::viewArray(array('checkT3Rights'=>$conf['checkT3Rights']));
if ($conf['checkT3Rights']) {
$ret=$this->MetaDBmayFEUserEditSelect($table,$fe_user,$allowedGroups,$fe_userEditSelf,$mmTable,$conf);
} elseif ($conf['enableColumns']) {
$ret= $GLOBALS['TSFE']->sys_page->enableFields($table,$show_hidden?$show_hidden:($table=='pages' ? $GLOBALS['TSFE']->showHiddenPage : $GLOBALS['TSFE']->showHiddenRecords));
}
// multi_language
if ($conf['TCAN'][$table]['ctrl']['languageField'] && $conf['TCAN'][$table]['ctrl']['transOrigPointerField']) {
$ret .= ' AND '.$table.'.'.$conf['TCAN'][$table]['ctrl']['transOrigPointerField'].'=0';
}
return $ret;
}
/**
* MetaDBmayFEUserEditSelect
*
* @param [type] $table: ...
* @param [type] $feUserRow: ...
* @param [type] $allowedGroups: ...
* @param [type] $feEditSelf: ...
* @param [type] $mmTable: ...
* @param [type] $conf: ...
* @return [type] ...
*/
function MetaDBmayFEUserEditSelect($table,$feUserRow,$allowedGroups='',$feEditSelf=0, &$mmTable,&$conf) {
// Returns where-definition that selects user-editable records.
$groupList = $allowedGroups ? implode(',',array_intersect(t3lib_div::trimExplode(',',$feUserRow['usergroup'],1),t3lib_div::trimExplode(',',$allowedGroups,1))) : $feUserRow['usergroup'];
$OR_arr=array();
// points to the field (integer) that holds the fe_users-id of the creator fe_user
if ($conf['debug']) echo Tx_MetaFeedit_Lib_ViewArray::viewArray(array('fe_cruser_id'=>$conf['TCAN'][$table]['ctrl']['fe_cruser_id']));
if ($conf['TCAN'][$table]['ctrl']['fe_cruser_id']) {
$mmTable=$conf['TCAN'][$table]['columns'][$conf['TCAN'][$table]['ctrl']['fe_cruser_id']]['config']['MM'];
if ($mmTable) {
$OR_arr[]=$mmTable.'.uid_local='.$table.'.'.$conf['uidField'].' and '.$mmTable.'.uid_foreign='.$feUserRow['uid'];
} else {
$OR_arr[]=$table.'.'.$conf['TCAN'][$table]['ctrl']['fe_cruser_id'].'='.$feUserRow['uid'];
}
}
// points to the field (integer) that holds the fe_group-id of the creator fe_user's first group
if ($conf['TCAN'][$table]['ctrl']['fe_crgroup_id']) {
$values = t3lib_div::intExplode(',',$groupList);
while(list(,$theGroupUid)=each($values)) {
if ($theGroupUid) {$OR_arr[]=$table.'.'.$conf['TCAN'][$table]['ctrl']['fe_crgroup_id'].'='.$theGroupUid;}
}
}
if ($conf['debug']) echo Tx_MetaFeedit_Lib_ViewArray::viewArray(array('feEditSelf '=>$feEditSelf ));
// If $feEditSelf is set, fe_users may always edit them selves...
if ($feEditSelf && $table=='fe_users') {
$OR_arr[]=$table.'.uid='.intval($feUserRow['uid']);
}
//$whereDef=' AND 1=0';
if (count($OR_arr)) {
$whereDef=' AND ('.implode(' OR ',$OR_arr).')';
if ($conf['TCAN'][$table]['ctrl']['fe_admin_lock']) {
$whereDef.=' AND '.$conf['TCAN'][$table]['ctrl']['fe_admin_lock'].'=0';
}
}
// here we handle enable columns activation
if ($conf['enableColumns']) $whereDef.= $GLOBALS['TSFE']->sys_page->enableFields($table,$show_hidden?$show_hidden:($table=='pages' ? $GLOBALS['TSFE']->showHiddenPage : $GLOBALS['TSFE']->showHiddenRecords));
return $whereDef;
}
/**
* [Describe function...]
*
* @param [type] $table: ...
* @param [type] $uid: ...
* @param [type] $conf: ...
* @param [type] $fields: ...
* @param [type] $noWSOL: ...
* @return [type] ...
*/
function getRawRecord($table,$uid,&$conf,$fields='*',$noWSOL=FALSE) {
$uid = intval($uid);
if (is_array($conf['TCAN'][$table]) || $table=='pages') { // Excluding pages here so we can ask the function BEFORE TCA gets initialized. Support for this is followed up in deleteClause()...
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $conf['uidField'].'='.intval($uid).$GLOBALS['TSFE']->sys_page->deleteClause($table));
if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
if (!$noWSOL) {
$GLOBALS['TSFE']->sys_page->versionOL($table,$row);
}
}
}
if ($conf['TCAN'][$table]['ctrl']['languageField'] && $conf['TCAN'][$table]['ctrl']['transOrigPointerField'] && $GLOBALS['TSFE']->sys_language_uid ) {
$row=$GLOBALS['TSFE']->sys_page->getRecordOverlay($table,$row, $GLOBALS['TSFE']->sys_language_content,$GLOBALS['TSFE']->sys_language_contentOL);
}
if (is_array($row)) return $row;
}
/**
* [Describe function...]
*
* @param [type] $table: ...
* @param [type] $fe_user: ...
* @param [type] $allowedGroups: ...
* @param [type] $fe_userEditSelf: ...
* @param [type] $mmTable: ...
* @param [type] $conf: ...
* @return [type] ...
*/
function DBmayFEUserEditSelect($table,$fe_user,$allowedGroups,$fe_userEditSelf, &$mmTable,&$conf) {
$ret='';
if (!$conf['checkT3Rights']) return $ret;
// $ret=$this->cObj->DBmayFEUserEditSelect($table,$fe_user,$allowedGroups,$fe_userEditSelf);
// Returns where-definition that selects user-editable records.
$groupList = $allowedGroups ? implode(',',array_intersect(t3lib_div::trimExplode(',',$feUserRow['usergroup'],1),t3lib_div::trimExplode(',',$allowedGroups,1))) : $feUserRow['usergroup'];
$OR_arr=array();
// points to the field (integer) that holds the fe_users-id of the creator fe_user
if ($conf['TCAN'][$table]['ctrl']['fe_cruser_id']) {
$OR_arr[]=$conf['TCAN'][$table]['ctrl']['fe_cruser_id'].'='.$feUserRow['uid'];
}
// points to the field (integer) that holds the fe_group-id of the creator fe_user's first group
if ($conf['TCAN'][$table]['ctrl']['fe_crgroup_id']) {
$values = t3lib_div::intExplode(',',$groupList);
while(list(,$theGroupUid)=each($values)) {
if ($theGroupUid) {$OR_arr[]=$conf['TCAN'][$table]['ctrl']['fe_crgroup_id'].'='.$theGroupUid;}
}
}
// If $feEditSelf is set, fe_users may always edit them selves...
if ($feEditSelf && $table=='fe_users') {
$OR_arr[]='uid='.intval($feUserRow['uid']);
}
//$whereDef=' AND 1=0';
if (count($OR_arr)) {
$whereDef=' AND ('.implode(' OR ',$OR_arr).')';
if ($conf['TCAN'][$table]['ctrl']['fe_admin_lock']) {
$whereDef.=' AND '.$conf['TCAN'][$table]['ctrl']['fe_admin_lock'].'=0';
}
}
return $whereDef;
}
/**
* DBmayFEUserEdit
*
* @param [type] $table: ...
* @param [type] $origArr: ...
* @param [type] $fe_user: ...
* @param [type] $allowedGroups: ...
* @param [type] $fe_userEditSelf: ...
* @param [type] $conf: ...
* @return [type] ...
*/
function DBmayFEUserEdit($table,$origArr,$fe_user,$allowedGroups,$fe_userEditSelf,&$conf) {
$ok=1;
if ($conf['checkT3Rights']) {
//$ret=$this->cObj->DBmayFEUserEdit($table,$origArr,$fe_user,$allowedGroups,$fe_userEditSelf);
$groupList = $allowedGroups ? implode(',',array_intersect(t3lib_div::trimExplode(',',$fe_user['usergroup'],1),t3lib_div::trimExplode(',',$allowedGroups,1))) : $fe_user['usergroup'];
$ok=0;
// points to the field that allows further editing from frontend if not set. If set the record is locked.
if (!$GLOBALS['TCA'][$table]['ctrl']['fe_admin_lock'] || !$origArr[$GLOBALS['TCA'][$table]['ctrl']['fe_admin_lock']]) {
// points to the field (integer) that holds the fe_users-id of the creator fe_user
if ($GLOBALS['TCA'][$table]['ctrl']['fe_cruser_id']) {
$MMT = $GLOBALS['TCA'][$table]['columns'][$GLOBALS['TCA'][$table]['ctrl']['fe_cruser_id']]['config']['MM'];
if ($MMT) { //si on est dans une MM faut d'abord récup les id de la table MM
$FTUid=$fe_user['uid'];
$LTUid=$origArr['uid'];
$MMTreq = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*',$MMT,$MMT.'.uid_local='.$LTUid.' and '.$MMT.'.uid_foreign='.$FTUid);
$resu=$GLOBALS['TYPO3_DB']->sql_num_rows($MMTreq);
if ($resu>=1) {
$ok=1;
}
} else { // not a MM
$rowFEUser = intval($origArr[$GLOBALS['TCA'][$table]['ctrl']['fe_cruser_id']]);
if ($rowFEUser && $rowFEUser==$fe_user['uid']) {
$ok=1;
}
}
}
// If $fe_userEditSelf is set, fe_users may always edit themselves...
if ($fe_userEditSelf && $table=='fe_users' && !strcmp($fe_user['uid'],$origArr['uid'])) {
$ok=1;
}
// points to the field (integer) that holds the fe_group-id of the creator fe_user's first group
if ($GLOBALS['TCA'][$table]['ctrl']['fe_crgroup_id']) {
$rowFEUser = intval($row[$GLOBALS['TCA'][$table]['ctrl']['fe_crgroup_id']]);
if ($rowFEUser) {
if (t3lib_div::inList($groupList, $rowFEUser)) {
$ok=1;
}
}
}
}
}
return $ok;
}
// SQL Functions
/**
* getMMUids
*
* @param [type] $$conf: ...
* @param [type] $sql: ...
* @return [type] ...
*/
function getMMUids(&$conf,$table,$fN,$dataArr=0) {
$MMres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $conf['TCAN'][$table]['columns'][$fNiD]["config"]["MM"], 'uid_local=\''.$dataArr[$conf['uidField']].'\'', '');
if (mysql_error()) debug(array(mysql_error(), $query), 'processDataArray()::field='.$fN);
if ($conf['debug'] && mysql_num_rows($MMres) != $dataArr[$fN]) debug("Wrong number of selections reached");
while ($MMrow = mysql_fetch_assoc($MMres)) $uids[] = $MMrow["uid_foreign"];
return $uids;
}
/**
* getExtraFields
*
* @param [type] $$conf: ...
* @param [type] $sql: ...
* @return [type] ...
*/
function getExtraFields(&$conf,&$sql) {
if ($conf['list.']['extraFields']) {
$FTA=t3lib_div::trimexplode(',',$conf['list.']['extraFields']);
foreach($FTA as $FTi) {
if (strpos($FTi,'.')>0)
{
// foreign relations
$FTAA=t3lib_div::trimexplode('.',$FTi);
$FT=$FTAA[0];
$FN=$FTAA[1];
$FTT=$conf['TCAN'][$conf['table']]['columns'][$FT]['config']['foreign_table'];
$FTT=$this->getTableAlias($sql,$FTT,$FTi);
//$sql['fromTables'].=','.$FTT;
$sql['joinTables'][]=$FTT;
$sql['fields'].=','.$FTT.'.'.$FN;
$sql['fieldArray'][]=$FTT.'.'.$FN;
} else {
// master table fields ...
$sql['fields'].=','.$conf['table'].'.'.$FTi;
$sql['fieldArray'][]=$conf['table'].'.'.$FTi;
}
}
//$sql['extraFields']
}
}
/**
* getFieldJoin
*
* @param [type] $$conf: ...
* @param [type] $sql: ...
* @param [type] $masterTable: ...
* @param [type] $fN: ...
* @return [type] ...
*/
function getFieldJoin(&$conf,&$sql,$masterTable,$fN) {
$FT=$conf['TCAN'][$masterTable]['columns'][$fN]['config']['foreign_table'];
$ret=$fN;
if ($FT) {
$MM=$conf['TCAN'][$masterTable]['columns'][$fN]["config"]["MM"];
if (!$MM) {
$this->getTableAlias($sql,$FT,$fN);
if ($conf['TCAN'][$masterTable]['columns'][$fN]['config']['size']>1) {
$sql['where'].=' AND FIND_IN_SET('.$FT.'.uid,'.$masterTable.'.'.$fN.')>0 ';
} else {
$sql['where'].=' AND '.$FT.'.uid='.$masterTable.'.'.$fN.' ';
}
//$sql['fromTables'].=','.$FT;
$sql['joinTables'][]=$FT;
$this->getParentJoin($conf,$sql,$FT); //TOBEREMOVED ???
} else {
$this->getTableAlias($sql,$MM,$fN);
$uidLocal = isset($conf['TCAN'][$masterTable]['ctrl']['uidLocalField'])?$conf['TCAN'][$masterTable]['ctrl']['uidLocalField']:'uid';
$sql['where'].=" AND ".$masterTable.'.'.$uidLocal;
//$sql['where'].= ($uidLocal == "uid")?$fN:$uidLocal;
$sql['where'].= '='.$MM.'.uid_local';
//$sql['fromTables'].=','.$MM;
$sql['joinTables'][]=$MM;
$sql['addFields'].=$sql['addFields']?','.$MM.'.uid_foreign as '.$fN.'_uid_foreign':$MM.'.uid_foreign as '.$fN.'_uid_foreign';
$ret=$fN.'_uid_foreign';
}
}
return $ret;
}
/**
* Field Value Join : locks column value ????
*
* @param [type] $$conf: ...
* @param [type] $sql: ...
* @param [type] $masterTable: ...
* @param [type] $fN: ...
* @param [type] $val: ...
* @return [type] ...
*/
function getFieldValJoin(&$conf,&$sql,$masterTable,$fN,$val) {
$FT=$conf['TCAN'][$masterTable]['columns'][$fN]['config']['foreign_table'];
$ret=$fN;
if ($FT) {
$MM=$conf['TCAN'][$masterTable]['columns'][$fN]["config"]["MM"];
if (!$MM) { //modif by CMD - ajout du $
$this->getTableAlias($sql,$FT,$fN);
if ($conf['TCAN'][$masterTable]['columns'][$fN]['config']['size']>1) {
$sql['where'].=' AND FIND_IN_SET('.$FT.'.uid,'.$masterTable.'.'.$fN.')>0 ';
} else {
$sql['where'].=' AND '.$FT.'.uid='.$masterTable.'.'.$fN.' ';
}
} else {
$this->getTableAlias($sql,$MM,$fN);
$uidLocal = isset($conf['TCAN'][$masterTable]['ctrl']['uidLocalField'])?$conf['TCAN'][$masterTable]['ctrl']['uidLocalField']:'uid';
$sql['where'].=" AND ".$masterTable.'.'.$uidLocal;
//$sql['where'].= ($uidLocal == "uid")?$fN:$uidLocal;
$sql['where'].= '='.$MM.'.uid_local';
//$sql['fromTables'].=','.$MM;
$sql['addFields'].=$sql['addFields']?','.$MM.'.uid_foreign as '.$fN.'_uid_foreign':$MM.'.uid_foreign as '.$fN.'_uid_foreign';
$ret=$fN.'_uid_foreign';
}
}
return $ret;
}
/**
* Makes foreign table join for sql request
*
* @param [array] $conf: configuration array
* @param [array] $sql: sql array
*/
function getForeignJoin(&$conf,&$sql) {
if ($conf['foreignTables']) {
$table=$conf['table'];
$FTA=t3lib_div::trimexplode(',',$conf['foreignTables']);
foreach($FTA as $FT) {
$FTT=$conf['TCAN'][$table]['columns'][$FT]['config']['foreign_table'];
//$sql['fromTables'].= ','.$FTT;
$alias=$this->getTableAlias($sql,$FTT,$FT);
foreach(t3lib_div::trimexplode(',',$conf['list.'][show_fields]) as $sF) {
$rA=t3lib_div::trimexplode('.',$sF);
//modif by CMD - pour gérer le champ dans la table s'il nest pas la table étrangère
if ($rA[0]==$FT && isset($rA[1])) {
$sql['fields'].= ','.$alias.'.'.$rA[1]." as '$FT.$rA[1]'";
$sql['fieldArray'][]=$alias.'.'.$rA[1]." as '$FT.$rA[1]'";
}
}
if (!$conf['TCAN'][$table]['columns'][$FT]['config']['MM']) {
if ($conf['TCAN'][$table]['columns'][$FT]['config']['size']>1) {
$sql['where'].=' AND FIND_IN_SET('.$FTT.'.uid,'.$table.'.'.$FT.')>0 ';
//$sql['fromTables'].=$sql['fromTables']?','.$FTT:$FTT;
$sql['joinTables'][]=$FTT;
} else {
//$sql['where'].=' AND '.$FTT.'.uid='.$table.'.'.$FT.' ';
$sql['join'].=' LEFT JOIN '.$FTT.($sql['fields.'][$FT.'.']['alias']?' as '.$sql['fields.'][$FT.'.']['alias']:'').' ON '.$alias.'.uid='.$table.'.'.$FT.' ';
$sql['joinTables'][]=$FTT;
}
} else {
//ancienne version du lien
//$AND_arr.=" AND ".$table.'.'.$FT.'='.$FTT.'.uid';
//modif par CMD
//rajout de liaison pour les tables de meta_oscommerce
//on lie les tables en fonction du champ d'id de liaison
$MMTable=$conf['TCAN'][$table]['columns'][$FT]['config']['MM'];
$this->getTableAlias($sql,$MMTable,$FT);
$uidLocal = isset($conf['TCAN'][$FTT]['ctrl']['uidLocalField'])?$conf['TCAN'][$FTT]['ctrl']['uidLocalField']:'uid';
$sql['join'].=' JOIN '.$MMTable.' ON '.$MMTable.'.uid_local ='.$table.'.uid JOIN '.$FTT.' ON '.$FTT.'.uid='.$MMTable.'.uid_foreign';
$sql['joinTables'][]=$MMTable;
}
}
//TODO
//$sql['fromTables']=implode(',',array_diff(t3lib_div::trimexplode(',',$sql['fromTables']),t3lib_div::trimexplode(',',$sql['joinTables'])));
//$sql['fromTables'].= $sql['join'];
$sql['foreignWhere']=$sql['where'];
}
}
/**
* getTableAlias : get alias for foreign table of field
*
* @param [array] $sql: sql array
* @param [string] $table: name of master table
* @param [string] $field: field name as selected by user in flexform ..., filedname1.fieldname2 and so on ...
* @return [string] $alias : name of foreign table alias ...
*/
function getTableAlias(&$sql,$table,$field) {
$alias='';
// We replace '.' with '_' to generate alias name
// If Table already is in Table Array we must generate an alias for it ...
// Hmm normally we should only generate an alias if we haven't already used the table ...
// We look for foreign table (field name with a '.').
// get link id, link is relation to table ...
$FT='';
if (strpos($field,'.')>0) {
$FTAA=t3lib_div::trimexplode('.',$field);
$FT=$FTAA[0];
}
$link=$table.($FT?'_'.$FT:'');
// Table aliases
/*
if (!in_array($link,$sql['tablejoins'])) {
$sql['tablejoins'][]=$link;
$sql['tableArray.'][$link]['table']=$table;
$sql['tableArray.'][$link]['alias']=$link;
}
*/
$fieldalias=str_replace('.','_',$field).'_'.$link;
$sql['tableArray'][]=$link;
// field aliases
$sql['fields.'][$field.'.']['table']=$table;
$sql['fields.'][$field.'.']['tablealias']=$link;
$sql['fields.'][$field.'.']['fieldalias']=$fieldalias;
//$alias=$table;
return $link;
}
/**
* getSQLFields : deduct sql fields to select from conf array for request
*
* @param [array] $conf: configuration array
* @param [array] $sql: sql array
*/
function getSQLFields(&$conf,&$sql) {
// get fields shown in list mode ...
if ($conf['list.']['show_fields']) {
$FTA=t3lib_div::trimexplode(',',$conf['list.']['show_fields']);
foreach($FTA as $FTi) {
// check if field is a user calc field, if so it will be handled later ...
if (@array_key_exists($FTi,$conf['list.']['sqlcalcfields.'])) continue;
// check if field is a relation to a foreign table (it has a '.' in it's name).
if (strpos($FTi,'.')>0 )
{
// We get foreign table name ...
$FTAA=t3lib_div::trimexplode('.',$FTi);
$FT=$FTAA[0];
$FN=$FTAA[1];
$FTT=$conf['TCAN'][$conf['table']]['columns'][$FT]['config']['foreign_table'];
if (!$FTT) die ("ext:meta_feedit:class.txmetafeedit_lib.php:getSQLFields no foreugn table definition of relation !");
$FTT=$this->getTableAlias($sql,$FTT,$FTi);
//$sql['fromTables'].=','.$FTT;
$sql['joinTables'][]=$FTT;
//$sql['fields'].=','.$FTT.'.'.$FN;
$sql['fieldArray'][]=$FTT.'.'.$FN.' as '.$sql['fields.'][$FN.'.']['fieldalias'];
} else {
// These fields are form master table ($conf['table'])...
//$sql['fields'].=','.$conf['table'].'.'.$FTi;
$sql['fields.'][$FTi.'.']['table']=$conf['table'];
$sql['fieldArray'][]=$conf['table'].'.'.$FTi;
}
}
// special fields like uid field of master table ($conf['table']) must always be here ...
if (!in_array($conf['table'].'.'.$conf['uidField'],$sql['fieldArray'])) {
$sql['fields'].=','.$conf['table'].'.'.$conf['uidField'];
$sql['fields.'][$FTi.'.']['table']=$conf['table'];
$sql['fieldArray'][]=$conf['table'].'.'.$conf['uidField'];
}
}
}
/**
* Builds SQL Request for list displays ...
*
* @param [type] $$conf: ...
* @param [type] $sql: ...
* @return [type] ...
*/
function getListSQL($TABLES,$DBSELECT,&$conf,&$markerArray,&$DEBUG) {
$sql=array();
die($TABLES);
$sql['fromTables']=$TABLES;
$sql['tableArray']=t3lib_div::trimexplode(',',$TABLES);
$sql['joinTables']=array();
$sql['joinTables'][]=$TABLES;
$sql['DBSELECT']=$DBSELECT;
$sql['where']=$sql['DBSELECT'];
$this->getSQLFields($conf,$sql);
// Default is *
if (!$sql['fields']) {
$sql['fields']=$conf['table'].'.*'; // Field list (is * a field ???)
$sql['fieldArray'][]=$conf['table'].'.*';
$sql['fields.']['*.']['table']=$conf['table'];
}
/*
* $sql['tablearray'] : list of used tables
* $sql['tablejoinarray.'][$TABLE] : list of table joins
* $sql['fields.'][$FIELD.]['table'] : Table of data field
* $sql['fields.'][$FIELD.]['alias'] : Alias of field
*
* $sql['fields.']['FIELD.'][''] :
*/
//$sql['fieldArray'][]=$conf['table'].'.*';
//$sql['fields.']['*.']['table']=$conf['table'];
$this->getLockPidJoin($conf,$sql);
$this->getExtraFields($conf,$sql);
$this->getForeignJoin($conf,$sql);
$this->getOUJoin($conf,$sql);
$this->getFUJoin($conf,$sql);
$this->getRUJoin($conf,$sql);
$this->getParentJoin($conf,$sql);
$this->getCalcFields($conf,$sql);
if ($conf['list.']['searchBox']) $this->getFullTextSearchWhere($conf,$sql,$markerArray);
if ($conf['list.']['alphabeticalSearch']) $this->getAlphabeticalSearchWhere($conf,$sql);
if ($conf['list.']['advancedSearch']) $this->getAdvancedSearchWhere($conf,$sql,$markerArray);
if ($conf['list.']['calendarSearch']) $this->getCalendarSearchWhere($conf,$sql);
$this->getUserWhereString($conf,$sql);
// MODIF CBY
$this->getGroupBy($conf,$sql);
$this->getOrderBy($conf,$sql);
$this->getSum($conf,$sql);
// Clean up ..
$this->cleanSQL($conf,$sql);
$gbarr=t3lib_div::trimexplode(',',$sql['gbFields']);
$farr=$sql['fieldArray'];
foreach ($gbarr as $gb) {
if ( !@in_array($gb,$sql['calcfields']) && $gb) $farr[]=$gb;
}
//$farr=array_unique($farr);
$sql['fields']=implode(',',$farr);
// we make fromtable sql :
$sql['fromTables']=$conf['table']; // we add master table.
foreach($sql['joinTables'] as $jT) {
$sql['fromTables'].=$sql['join.'][$jT];
}
$sql['fields']=implode(',',$sql['fieldArray']);
$conf['list.']['sql']=&$sql;
//krumo($sql)
//die('proout');
if ($conf['debug.']['sql']) $DEBUG.="<br/>LIST 2SQL ARRAY <br/>".Tx_MetaFeedit_Lib_ViewArray::viewArray($sql);
return $sql;
}
/**
* Calculation fields : allows insertion of user defined sql fields (may creat ebugs as we have no control on whate the user outs in here)...
*
* @param [type] $$conf: ...
* @param [type] $sql: ...
* @return [type] ...
*/
function getCalcFields(&$conf,&$sql,$table='') {
if (is_array($conf['list.']['sqlcalcfields.'])) foreach($conf['list.']['sqlcalcfields.'] as $field=>$calcsql) {
$sql['fields'].=",$calcsql as $field";
$sql['fieldArray'][]="$calcsql as $field";
$sql['calcFieldsSql'].=",$calcsql as $field"; // to be removed
$sql['calcfields'][]=$field; // to be removed
}
}
/**
* Value join on column
*
* @param [type] $$conf: ...
* @param [type] $sql: ...
* @return [type] ...
*/
function getParentJoin(&$conf,&$sql,$table='') {
//TODO put plugin Id in here
if ($table=='') $table=$conf['table'];
$A=t3lib_div::_GP($table);
if (is_array($A) && $A['lV'] && $A['lField']) {
$lField=$conf['inputvar.']['lField.'][$table]=$A['lField'];
$lV=$conf['inputvar.']['lV.'][$table]=$A['lV'];
$GLOBALS["TSFE"]->fe_user->fetchSessionData();
$metafeeditvars=$GLOBALS["TSFE"]->fe_user->getKey('ses','metafeeditvars');
array_merge($metafeeditvars[$GLOBALS['TSFE']->id][$conf['pluginId']],$conf['inputvar.']);
// We make the join persistent by storing it in session.
$GLOBALS["TSFE"]->fe_user->setKey('ses','metafeeditvars',$metafeeditvars);
$GLOBALS["TSFE"]->fe_user->storeSessionData();
} else {
$lVa=$this->getMetaFeeditVar($conf,'lV.',true);
$lV=$conf['inputvar.']['lV.'][$table]=$lVa[$table];
$lFielda=$this->getMetaFeeditVar($conf,'lField.',true);
$lField=$conf['inputvar.']['lField.'][$table]=$lFielda[$table];
}
if ($lV && $lField) {
$mmTable=$conf['TCAN'][$table]['columns'][$lField]['config']['MM'];
if ($mmTable) {
$this->getTableAlias($sql,$mmTable,$lFIELD);
$AND_arr.=" AND ".$mmTable.'.uid_local='.$table.'.uid and '.$mmTable.'.uid_foreign=\''.$lV.'\'';
//TODO
$sql['fromTables'].=','.$mmTable;
$sql['joinTables'][]=$mmTable;
}
else {
$AND_arr.=" AND `".$table."`.`".$lField."`='".$lV."'";
}
$sql['parentWhere'].=$AND_arr;
$sql['where'].= $AND_arr;
}
}
// Front End User Join, Joins table Fields on Front End User Fields
function getFUJoin(&$conf,&$sql,$table='') {
$fUField = $conf['fUField']?$conf['fUField']:t3lib_div::_GP('fUField['.$conf['pluginId'].']');
$fUKeyField = $conf['fUKeyField']?$conf['fUKeyField']:t3lib_div::_GP('fUKeyField['.$conf['pluginId'].']');
$fU = $conf['fU']?$conf['fU']:t3lib_div::_GP('fU['.$conf['pluginId'].']');
//CBY MODIF
if (!$table) $table=$conf['table'];
$OR_arr='';
if ($fUField && $fUKeyField && ($GLOBALS['TSFE']->fe_user->user['uid'] || $fU)) {
$feUid=$fU?$fU:$GLOBALS['TSFE']->fe_user->user['uid'];
$mmTable=$conf['TCAN']['fe_users']['columns'][$fUField]['config']['MM'];
$mmTable=$conf['TCAN']['fe_users']['columns'][$fUField]['config']['MM'];
t3lib_div::devLog($feUid,"feUid2");
if ($mmTable) {
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'*',
$mmTable,
'uid_local='.$GLOBALS['TYPO3_DB']->fullQuoteStr($feUid, 'fe_users').$GLOBALS['TSFE']->sys_page->deleteClause($mmTable)
);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$OR_arr.= $OR_arr?' OR '.$table.'.'.$fUKeyField.'='.$row['uid_foreign']:$table.'.'.$fUKeyField.'='.$row['uid_foreign'];
}
if (!$OR_arr) $OR_arr="1=0";
} else {
$feVals=$GLOBALS['TSFE']->fe_user->user[$fUField];
if ($conf['TCAN']['fe_users']['columns'][$fUField]['config']['foreigntable']) {
foreach(t3lib_div::trimexplode(',',$feVals) as $feVal) {
if ($feVal) $OR_arr.= $OR_arr?' OR '.$table.'.'.$fUKeyField.'='.$feVal:$table.'.'.$fUKeyField.'='.$feVal;
}
} else {
if ($feVals) $OR_arr.= $OR_arr?' OR '.$table.'.'.$fUKeyField.'='.$feVals:$table.'.'.$fUKeyField.'='.$feVals;
}
//if (!$OR_arr) $OR_arr="1=0";
}
$sql['fUWhere']=$OR_arr;
$sql['where'].= $OR_arr?' AND (' . $OR_arr . ')':'';
}
}
// OUJoin Outer Table Join
function getOUJoin(&$conf,&$sql) {
$table=$conf['table'];
if ($conf['originUid']) {
$mmTable=$conf['TCAN'][$conf['originTable']]['columns'][$conf['originUidsField']]['config']['MM'];
if ($mmTable) {
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'*',
$mmTable,
'uid_local='.$GLOBALS['TYPO3_DB']->fullQuoteStr($conf['originUid'], $conf['originTable']).$GLOBALS['TSFE']->sys_page->deleteClause($table)
);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$OR_arr.= $OR_arr?' OR '.$table.'.'.$conf['uidField'].'='.$row['uid_foreign']:$table.'.'.$conf['uidField'].'='.$row['uid_foreign'];
}
} else {
$oUids="";
$origArr=array();
if ($conf['originKeyField']) {
$origArr = $GLOBALS['TSFE']->sys_page->getRecordsByField($conf['originTable'], $conf['originKeyField'], $conf['originUid']);
if (count($origArr)) {
foreach($origArr as $oRec) {
$oUids=$oUids?$oUids.','.$oRec[$conf['originUidsField']]:$oRec[$conf['originUidsField']];
}
};
} else {
$origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($conf['originTable'], $conf['originUid']);
$oUids=$origArr[$conf['originUidsField']];
}
foreach(t3lib_div::trimexplode(',',$oUids) as $oUid) {
if ($oUid) $OR_arr.= $OR_arr?' OR '.$table.'.'.$conf['uidField'].'='.$oUid:$table.'.'.$conf['uidField'].'='.$oUid;
}
if (!$OR_arr) $OR_arr="1=0";
}
$sql['oUWhere']=$OR_arr?' AND ('.$OR_arr.')':'';
$sql['where'].= $sql['oUWhere'];
}
}
// rUJoin
function getRUJoin(&$conf,&$sql) {
$table=$conf['table'];
if ( ($conf['inputvar.']['rU']|| t3lib_div::_GP($table.'-rU')) && $conf['list.']['rUJoinField']) {
$rF=$conf['list.']['rUJoinField'];
$mmTable=$conf['TCAN'][$table]['columns'][$rF]['config']['MM'];
$ruid=t3lib_div::_GP($table.'-rU')?t3lib_div::_GP($table.'-rU'):$conf['inputvar.']['rU'];
if ($mmTable) {
$this->getTableAlias($sql,$mmTable,$rF);
$sql['rUWhere'].=" AND ".$mmTable.'.uid_local='.$table.'.uid and '.$mmTable.'.uid_foreign='.$ruid;
//TODO
$sql['fromTables'].=','.$mmTable;
$sql['joinTables'][]=$mmTable;
} else {
$sql['rUWhere'].=" AND ".$table.'.'.$rF."='".$ruid."'";
}
//$sql['rUWhere']=$AND_arr;
$sql['where'].= $sql['rUWhere'];
}
}
// lockPidJoin
function getLockPidJoin(&$conf,&$sql) {
$table=$conf['table'];
// Initial variables
if ($conf['debug']) echo Tx_MetaFeedit_Lib_ViewArray::viewArray(array('pid'=>$conf['pid']));
$lockPid = ($conf['edit.']['menuLockPid'] && $conf['pid'])? ' AND '.$table.'.pid='.intval($conf['pid']) : '';
if ($conf['recursive']) {
$pid_list = $this->feadminlib->pi_getPidList($conf['pid'], $conf['recursive']);
$lockPid = ($conf['edit.']['menuLockPid'] && $conf['pid']) ? ' AND '.$table.'.pid in ('.$pid_list.')' : '';
}
$sql['lockPidWhere']=$lockPid;
$sql['where'].= $sql['lockPidWhere'];
}
// User Where String
function getUserWhereString(&$conf,&$sql) {
$conf['parentObj']=&$this->feadminlib;
if ($conf['list.']['userFunc_afterWhere']) t3lib_div::callUserFunction($conf['list.']['userFunc_afterWhere'],$conf,$this->feadminlib);
if ($conf [$conf['cmdmode'] . '.']['whereString']) $sql['userWhereString']=' AND '.$conf [$conf['cmdmode'] . '.']['whereString'];
$sql['where'].= $sql['userWhereString'];
}