Bug #16518 ยป mmtables_v2.patch

Administrator Admin, 2006-09-03 20:29

View differences:

C:/apache/typo3/typo3_src-trunk/t3lib/class.t3lib_admin.php (working copy)
535 535
									if ($fieldConf['internal_type']=='db')	{
536 536
										// dbs - group
537 537
										$dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
538
										$dbAnalysis->start($row[$field],$fieldConf['allowed'],$fieldConf['MM'],$row['uid']);
538
										$dbAnalysis->start($row[$field],$fieldConf['allowed'],$fieldConf['MM'],$row['uid'], $table, $fieldConf);
539 539
										reset($dbAnalysis->itemArray);
540 540
										while (list(,$tempArr)=each($dbAnalysis->itemArray))	{
541 541
											$this->checkGroupDBRefs[$tempArr['table']][$tempArr['id']]+=1;
......
545 545
								if ($fieldConf['type']=='select' && $fieldConf['foreign_table'])	{
546 546
									// dbs - select
547 547
									$dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
548
									$dbAnalysis->start($row[$field],$fieldConf['foreign_table'],$fieldConf['MM'],$row['uid']);
548
									$dbAnalysis->start($row[$field],$fieldConf['foreign_table'],$fieldConf['MM'],$row['uid'], $table, $fieldConf);
549 549
									reset($dbAnalysis->itemArray);
550 550
									while (list(,$tempArr)=each($dbAnalysis->itemArray))	{
551 551
										if ($tempArr['id']>0)	{
......
673 673
				$allowedTables = ($fieldConf['type']=='group') ? $fieldConf['allowed'] : $fieldConf['foreign_table'];
674 674

  
675 675
				$dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
676
				$dbAnalysis->start($row[$field],$allowedTables,$fieldConf['MM'],$row['uid']);
676
				$dbAnalysis->start($row[$field],$allowedTables,$fieldConf['MM'],$row['uid'], $table, $fieldConf);
677 677
				reset($dbAnalysis->itemArray);
678 678
				while (list(,$tempArr)=each($dbAnalysis->itemArray))	{
679 679
					if ($tempArr['table']==$searchTable && $tempArr['id']==$id)	{
C:/apache/typo3/typo3_src-trunk/t3lib/class.t3lib_befunc.php (working copy)
171 171
 *
172 172
 */
173 173

  
174
require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
174 175

  
176

  
175 177
/**
176 178
 * Standard functions available for the TYPO3 backend.
177 179
 * Don't instantiate - call functions with "t3lib_BEfunc::" prefixed the function name.
......
1872 1874
							}
1873 1875
							$MMfield = join(',',$MMfields);
1874 1876
						}
1875
						$MMres = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
1876
							$MMfield,
1877
							($table!=$theColConf['foreign_table']?$table:''),
1878
							$theColConf['MM'],
1879
							$theColConf['foreign_table'],
1880
							'AND '.$theColConf['MM'].'.uid_local ='.intval($uid).t3lib_BEfunc::deleteClause($theColConf['foreign_table'])
1881
						);
1882
						if ($MMres) {
1877

  
1878
						$dbGroup = t3lib_div::makeInstance('t3lib_loadDBGroup');
1879
						$dbGroup->start($value, $theColConf['foreign_table'], $theColConf['MM'], $uid, $table, $theColConf);
1880
						$selectUids = $dbGroup->tableArray[$theColConf['foreign_table']];
1881

  
1882
						if (is_array($selectUids) && count($selectUids)>0) {
1883
							$MMres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1884
								'uid, '.$MMfield,
1885
								$theColConf['foreign_table'],
1886
								'uid IN ('.implode(',', $selectUids).')'
1887
							);
1883 1888
							while($MMrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($MMres))	{
1884 1889
								$mmlA[] = ($noRecordLookup?$MMrow['uid']:t3lib_BEfunc::getRecordTitle($theColConf['foreign_table'], $MMrow));
1885 1890
							}
C:/apache/typo3/typo3_src-trunk/t3lib/class.t3lib_loaddbgroup.php (working copy)
83 83
	var $dbPaths=Array();
84 84
	var $firstTable = '';				// Will contain the first table name in the $tablelist (for positive ids)
85 85
	var $secondTable = '';				// Will contain the second table name in the $tablelist (for negative ids)
86
		// private
87
	var $MM_is_foreign = 0;		// boolean - if 1, uid_local and uid_foreign are switched, and the current table is inserted as tablename - this means you display a foreign relation "from the opposite side"
88
	var $MM_oppositeField = '';	// field name at the "local" side of the MM relation
89
	var $MM_oppositeTable = ''; // only set if MM_is_foreign is set
90
	var $MM_oppositeFieldConf = ''; // only set if MM_is_foreign is set
91
	var $MM_isMultiTableRelationship = 0;	// is empty by default; if MM_is_foreign is set and there is more than one table allowed (on the "local" side), then it contains the first table (as a fallback)
92
	var $currentTable;	// current table => Only needed for reverse relations
86 93

  
87 94

  
88

  
89

  
90 95
	/**
91 96
	 * Initialization of the class.
92 97
	 *
......
94 99
	 * @param	string		Comma list of tables, first table takes priority if no table is set for an entry in the list.
95 100
	 * @param	string		Name of a MM table.
96 101
	 * @param	integer		Local UID for MM lookup
102
	 * @param	string		current table name
103
	 * @param	integer		TCA configuration for current field
97 104
	 * @return	void
98 105
	 */
99
	function start($itemlist,$tablelist, $MMtable='',$MMuid=0)	{
106
	function start($itemlist, $tablelist, $MMtable='', $MMuid=0, $currentTable='', $conf=array())	{
107
			// SECTION: MM reverse relations
108
		$this->MM_is_foreign = ($conf['MM_opposite_field']?1:0);
109
		$this->MM_oppositeField = $conf['MM_opposite_field'];
110
		$this->currentTable = $currentTable;
111
		if ($this->MM_is_foreign)	{
112
			$tmp = ($conf['type']==='group'?$conf['allowed']:$conf['foreign_table']);
113
				// normally, $conf['allowed'] can contain a list of tables, but as we are looking at a MM relation from the foreign side, it only makes sense to allow one one table in $conf['allowed']
114
			$tmp = t3lib_div::trimExplode(',', $tmp);
115
			$this->MM_oppositeTable = $tmp[0];
116
			unset($tmp);
117

  
118
				// only add the current table name if there is more than one allowed field
119
			$this->MM_oppositeFieldConf = $GLOBALS['TCA'][$this->MM_oppositeTable]['columns'][$this->MM_oppositeField]['config'];
120

  
121
			if ($this->MM_oppositeFieldConf['allowed'])	{
122
				$oppositeFieldConf_allowed = explode(',', $this->MM_oppositeFieldConf['allowed']);
123
				if (count($oppositeFieldConf_allowed) > 1)	{
124
					$this->MM_isMultiTableRelationship = $oppositeFieldConf_allowed[0];
125
				}
126
			}
127
		}
128

  
129
			// SECTION:	normal MM relations
130

  
100 131
			// If the table list is "*" then all tables are used in the list:
101 132
		if (!strcmp(trim($tablelist),'*'))	{
102 133
			$tablelist = implode(',',array_keys($GLOBALS['TCA']));
......
185 216
	 */
186 217
	function readMM($tableName,$uid)	{
187 218
		$key=0;
219
		if ($this->MM_is_foreign)	{	// in case of a reverse relation
220
			$uidLocal_field = 'uid_foreign';
221
			$uidForeign_field = 'uid_local';
222
			$sorting_field = 'sorting_foreign';
188 223

  
224
			if ($this->MM_isMultiTableRelationship)	{
225
				$additionalWhere = ' AND ( tablenames="'.$this->currentTable.'"';
226
				if ($this->currentTable == $this->MM_isMultiTableRelationship)	{	// be backwards compatible! When allowing more than one table after having previously allowed only one table, this case applies.
227
					$additionalWhere .= ' OR tablenames=""';
228
				}
229
				$additionalWhere .= ' ) ';
230
			}
231
			$theTable = $this->MM_oppositeTable;
232
		} else {	// default
233
			$uidLocal_field = 'uid_local';
234
			$uidForeign_field = 'uid_foreign';
235
			$additionalWhere = '';
236
			$sorting_field = 'sorting';
237
		}
238

  
189 239
			// Select all MM relations:
190
		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $tableName, 'uid_local='.intval($uid), '', 'sorting');
240
		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $tableName, $uidLocal_field.'='.intval($uid).$additionalWhere, '', $sorting_field);
191 241
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{
192
			$theTable = $row['tablenames'] ? $row['tablenames'] : $this->firstTable;		// If tablesnames columns exists and contain a name, then this value is the table, else it's the firstTable...
193
			if (($row['uid_foreign'] || $theTable=='pages') && $theTable && isset($this->tableArray[$theTable]))	{
194
				$this->itemArray[$key]['id'] = $row['uid_foreign'];
242
			if (!$this->MM_is_foreign) {	// default
243
				$theTable = $row['tablenames'] ? $row['tablenames'] : $this->firstTable;		// If tablesnames columns exists and contain a name, then this value is the table, else it's the firstTable...
244
			}
245
			if (($row[$uidForeign_field] || $theTable=='pages') && $theTable && isset($this->tableArray[$theTable]))	{
246

  
247
				$this->itemArray[$key]['id'] = $row[$uidForeign_field];
195 248
				$this->itemArray[$key]['table'] = $theTable;
196
				$this->tableArray[$theTable][]= $row['uid_foreign'];
249
				$this->tableArray[$theTable][]= $row[$uidForeign_field];
197 250
			} elseif ($this->registerNonTableValues)	{
198
				$this->itemArray[$key]['id'] = $row['uid_foreign'];
251
				$this->itemArray[$key]['id'] = $row[$uidForeign_field];
199 252
				$this->itemArray[$key]['table'] = '_NO_TABLE';
200
				$this->nonTableArray[] = $row['uid_foreign'];
253
				$this->nonTableArray[] = $row[$uidForeign_field];
201 254
			}
202 255
			$key++;
203 256
		}
......
214 267
	 */
215 268
	function writeMM($tableName,$uid,$prependTableName=0)	{
216 269

  
217
			// Delete all relations:
218
		$GLOBALS['TYPO3_DB']->exec_DELETEquery($tableName, 'uid_local='.intval($uid));
270
		if ($this->MM_is_foreign)	{	// in case of a reverse relation
271
			$uidLocal_field = 'uid_foreign';
272
			$uidForeign_field = 'uid_local';
273
			$sorting_field = 'sorting_foreign';
274
		} else {	// default
275
			$uidLocal_field = 'uid_local';
276
			$uidForeign_field = 'uid_foreign';
277
			$sorting_field = 'sorting';
278
		}	// TODO: SORTING!
219 279

  
220 280
			// If there are tables...
221 281
		$tableC = count($this->tableArray);
222 282
		if ($tableC)	{
223
			$prep = ($tableC>1||$prependTableName) ? 1 : 0;
283
			$prep = ($tableC>1||$prependTableName||$this->MM_isMultiTableRelationship) ? 1 : 0;	// boolean: does the field "tablename" need to be filled?
224 284
			$c=0;
225
			$tName=array();
226 285

  
286
			$additionalWhere_tablenames = '';
287
			if ($this->MM_is_foreign && $prep)	{
288
				$additionalWhere_tablenames = ' AND tablenames="'.$this->currentTable.'"';
289
			}
290
			$existingMMs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($uidForeign_field, $tableName, $uidLocal_field.'='.$uid.$additionalWhere_tablenames, '', '', '', $uidForeign_field);
291

  
292

  
227 293
				// For each item, insert it:
294
			$uidList = array();
228 295
			foreach($this->itemArray as $val)	{
229 296
				$c++;
230 297

  
231
				$insertFields = array(
232
					'uid_local' => $uid,
233
					'uid_foreign' => $val['id'],
234
					'sorting' => $c
235
				);
298
				$uidList[] = $val['id'];
299

  
236 300
				if ($prep || $val['table']=='_NO_TABLE')	{
237
					$insertFields['tablenames'] = $val['table'];
301
					if ($this->MM_is_foreign)	{	// insert current table if needed
302
						$tablename = $this->currentTable;
303
					} else {
304
						$tablename = $val['table'];
305
					}
306
				} else {
307
					$tablename = '';
238 308
				}
239 309

  
240
				$GLOBALS['TYPO3_DB']->exec_INSERTquery($tableName, $insertFields);
310
				if (isset($existingMMs[$val['id']]))	{
311
					$whereClause = $uidLocal_field.'='.$uid.' AND '.$uidForeign_field.'='.$val['id'];
312
					if ($tablename)
313
						$whereClause .= ' AND tablenames="'.$tablename.'"';
314
					$GLOBALS['TYPO3_DB']->exec_UPDATEquery($tableName, $whereClause, array($sorting_field => $c));
315
				} else {
316
					$GLOBALS['TYPO3_DB']->exec_INSERTquery($tableName, array(
317
						$uidLocal_field => $uid,
318
						$uidForeign_field => $val['id'],
319
						$sorting_field => $c,
320
						'tablenames' => $tablename
321
					));
322
				}
241 323
			}
324

  
325
				// Delete all not-used relations:
326
			$additionalWhere = '';
327
			if (count($uidList))	{
328
				$additionalWhere = ' AND '.$uidForeign_field.' NOT IN ( '.implode(',', $uidList).' ) ';
329
			}
330

  
331
			$GLOBALS['TYPO3_DB']->exec_DELETEquery($tableName, $uidLocal_field.'='.intval($uid).$additionalWhere.$additionalWhere_tablenames);
332

  
242 333
		}
243 334
	}
244 335

  
C:/apache/typo3/typo3_src-trunk/t3lib/class.t3lib_refindex.php (working copy)
570 570
			$allowedTables = $conf['type']=='group' ? $conf['allowed'] : $conf['foreign_table'].','.$conf['neg_foreign_table'];
571 571
			$prependName = $conf['type']=='group' ? $conf['prepend_tname'] : $conf['neg_foreign_table'];
572 572

  
573
			if($conf['MM_opposite_field']) {
574
				return array();
575
			}
576

  
573 577
			$dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
574 578
			$dbAnalysis->start($value,$allowedTables,$conf['MM'],$uid);
575 579

  
C:/apache/typo3/typo3_src-trunk/t3lib/class.t3lib_tcemain.php (working copy)
579 579
							$fieldArray = $this->newFieldArray($table);	// Get a fieldArray with default values
580 580
							if (isset($incomingFieldArray['pid']))	{	// A pid must be set for new records.
581 581
									// $value = the pid
582
		 						$pid_value = $incomingFieldArray['pid'];
582
								$pid_value = $incomingFieldArray['pid'];
583 583

  
584 584
									// Checking and finding numerical pid, it may be a string-reference to another value
585 585
								$OK = 1;
......
1328 1328
					);
1329 1329
				break;
1330 1330
				case 'db':
1331
					$valueArray = $this->checkValue_group_select_processDBdata($valueArray,$tcaFieldConf,$id,$status,'group');
1331
					$valueArray = $this->checkValue_group_select_processDBdata($valueArray,$tcaFieldConf,$id,$status,'group', $table);
1332 1332
				break;
1333 1333
			}
1334 1334
		}
1335 1335
			// For select types which has a foreign table attached:
1336 1336
		if ($tcaFieldConf['type']=='select' && $tcaFieldConf['foreign_table'])	{
1337
			$valueArray = $this->checkValue_group_select_processDBdata($valueArray,$tcaFieldConf,$id,$status,'select');
1337
			$valueArray = $this->checkValue_group_select_processDBdata($valueArray,$tcaFieldConf,$id,$status,'select', $table);
1338 1338
		}
1339 1339

  
1340 1340
// BTW, checking for min and max items here does NOT make any sense when MM is used because the above function calls will just return an array with a single item (the count) if MM is used... Why didn't I perform the check before? Probably because we could not evaluate the validity of record uids etc... Hmm...
......
1845 1845
	 * @param	integer		Record id, used for look-up of MM relations (local_uid)
1846 1846
	 * @param	string		Status string ('update' or 'new')
1847 1847
	 * @param	string		The type, either 'select' or 'group'
1848
	 * @param	string		Table name, needs to be passed to t3lib_loadDBGroup
1848 1849
	 * @return	array		Modified value array
1849 1850
	 */
1850
	function checkValue_group_select_processDBdata($valueArray,$tcaFieldConf,$id,$status,$type)	{
1851
	function checkValue_group_select_processDBdata($valueArray,$tcaFieldConf,$id,$status,$type,$currentTable)	{
1851 1852
		$tables = $type=='group'?$tcaFieldConf['allowed']:$tcaFieldConf['foreign_table'].','.$tcaFieldConf['neg_foreign_table'];
1852 1853
		$prep = $type=='group'?$tcaFieldConf['prepend_tname']:$tcaFieldConf['neg_foreign_table'];
1853 1854

  
1854 1855
		$dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
1855 1856
		$dbAnalysis->registerNonTableValues=$tcaFieldConf['allowNonIdValues'] ? 1 : 0;
1856
		$dbAnalysis->start(implode(',',$valueArray),$tables);
1857
		$dbAnalysis->start(implode(',',$valueArray),$tables, '', 0, $currentTable, $tcaFieldConf);
1857 1858

  
1858 1859
		if ($tcaFieldConf['MM'])	{
1859 1860
			if ($status=='update')	{
......
2591 2592
			$prependName = $conf['type']=='group' ? $conf['prepend_tname'] : $conf['neg_foreign_table'];
2592 2593
			if ($conf['MM'])	{
2593 2594
				$dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
2594
				$dbAnalysis->start('',$allowedTables,$conf['MM'],$uid);
2595
				$dbAnalysis->start('', $allowedTables, $conf['MM'], $uid, $table, $conf);
2595 2596
				$value = implode(',',$dbAnalysis->getValueArray($prependName));
2596 2597
			}
2597 2598
			if ($value)	{	// Setting the value in this array will notify the remapListedDBRecords() function that this field MAY need references to be corrected
......
3427 3428

  
3428 3429
		/*
3429 3430
		Version ID swapping principles:
3430
		  - Version from archive (future/past, called "swap version") will get the uid of the "t3ver_oid", the official element with uid = "t3ver_oid" will get the new versions old uid. PIDs are swapped also
3431
			- Version from archive (future/past, called "swap version") will get the uid of the "t3ver_oid", the official element with uid = "t3ver_oid" will get the new versions old uid. PIDs are swapped also
3431 3432

  
3432 3433
			uid		pid			uid		t3ver_oid	pid
3433 3434
		1:	13		123	 -->	-13		247			123		(Original has negated UID, and sets t3ver_oid to the final UID (which is nice to know for recovery). PID is unchanged at this point)
......
3691 3692
						switch($conf['type'])	{
3692 3693
							case 'group':
3693 3694
							case 'select':
3694
								$vArray = $this->remapListedDBRecords_procDBRefs($conf, $value, $theUidToUpdate);
3695
								$vArray = $this->remapListedDBRecords_procDBRefs($conf, $value, $theUidToUpdate, $table);
3695 3696
								if (is_array($vArray))	{
3696 3697
									$newData[$fieldName] = implode(',',$vArray);
3697 3698
								}
......
3757 3758

  
3758 3759
			// If references are set for this field, set flag so they can be corrected later:
3759 3760
		if ($this->isReferenceField($dsConf) && strlen($dataValue)) {
3760
			$vArray = $this->remapListedDBRecords_procDBRefs($dsConf, $dataValue, $uid);
3761
			$vArray = $this->remapListedDBRecords_procDBRefs($dsConf, $dataValue, $uid, $table);
3761 3762
			if (is_array($vArray))	{
3762 3763
				$dataValue = implode(',',$vArray);
3763 3764
			}
......
3773 3774
	 * @param	array		TCA field config
3774 3775
	 * @param	string		Field value
3775 3776
	 * @param	integer		UID of local record (for MM relations - might need to change if support for FlexForms should be done!)
3777
	 * @param	string		Table name
3776 3778
	 * @return	array		Returns array of items ready to implode for field content.
3777 3779
	 * @see remapListedDBRecords()
3778 3780
	 */
3779
	function remapListedDBRecords_procDBRefs($conf, $value, $MM_localUid)	{
3781
	function remapListedDBRecords_procDBRefs($conf, $value, $MM_localUid, $table)	{
3780 3782

  
3781 3783
			// Initialize variables
3782 3784
		$set = FALSE;	// Will be set true if an upgrade should be done...
......
3787 3789
			// Convert value to list of references:
3788 3790
		$dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
3789 3791
		$dbAnalysis->registerNonTableValues = ($conf['type']=='select' && $conf['allowNonIdValues']) ? 1 : 0;
3790
		$dbAnalysis->start($value, $allowedTables, $conf['MM'], $MM_localUid);
3792
		$dbAnalysis->start($value, $allowedTables, $conf['MM'], $MM_localUid, $table, $conf);
3791 3793

  
3792 3794
			// Traverse those references and map IDs:
3793 3795
		foreach($dbAnalysis->itemArray as $k => $v)	{
......
4964 4966
	function int_pageTreeInfo($CPtable,$pid,$counter, $rootID)	{
4965 4967
		if ($counter)	{
4966 4968
			$addW =  !$this->admin ? ' AND '.$this->BE_USER->getPagePermsClause($this->pMap['show']) : '';
4967
	 		$mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'pid='.intval($pid).$this->deleteClause('pages').$addW, '', 'sorting DESC');
4968
	 		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres))	{
4969
			$mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'pid='.intval($pid).$this->deleteClause('pages').$addW, '', 'sorting DESC');
4970
			while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres))	{
4969 4971
				if ($row['uid']!=$rootID)	{
4970
		 			$CPtable[$row['uid']] = $pid;
4971
		 			if ($counter-1)	{	// If the uid is NOT the rootID of the copyaction and if we are supposed to walk further down
4972
		 				$CPtable = $this->int_pageTreeInfo($CPtable,$row['uid'],$counter-1, $rootID);
4973
		 			}
4972
					$CPtable[$row['uid']] = $pid;
4973
					if ($counter-1)	{	// If the uid is NOT the rootID of the copyaction and if we are supposed to walk further down
4974
						$CPtable = $this->int_pageTreeInfo($CPtable,$row['uid'],$counter-1, $rootID);
4975
					}
4974 4976
				}
4975
	 		}
4977
			}
4976 4978
		}
4977
	 	return $CPtable;
4979
		return $CPtable;
4978 4980
	}
4979 4981

  
4980 4982
	/**
......
5310 5312
						case 0:
5311 5313
							$emails = $this->notifyStageChange_getEmails($workspaceRec['members']);
5312 5314
						break;
5313
 						default:
5315
						default:
5314 5316
							$emails = $this->notifyStageChange_getEmails($workspaceRec['adminusers'], TRUE);
5315 5317
						break;
5316 5318
					}
C:/apache/typo3/typo3_src-trunk/t3lib/class.t3lib_transferdata.php (working copy)
382 382
			break;
383 383
			case 'db':
384 384
				$loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
385
				$loadDB->start($data, $fieldConfig['config']['allowed'], $fieldConfig['config']['MM'], $row['uid']);
385
				$loadDB->start($data, $fieldConfig['config']['allowed'], $fieldConfig['config']['MM'], $row['uid'], $table, $fieldConfig['config']);
386 386
				$loadDB->getFromDB();
387 387
				$data = $loadDB->readyForInterface();
388 388
			break;
......
433 433

  
434 434
				// Add "foreign table" stuff:
435 435
			if ($TCA[$fieldConfig['config']['foreign_table']])	{
436
				$dataAcc = $this->selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row);
436
				$dataAcc = $this->selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row, $table);
437 437
			}
438 438

  
439 439
				// Always keep the native order for display in interface:
......
441 441
		} else {	// Normal, <= 1 -> value without title on it
442 442
			if ($TCA[$fieldConfig['config']['foreign_table']])	{
443 443
				// Getting the data
444
				$dataIds = $this->getDataIdList($elements, $fieldConfig, $row);
444
				$dataIds = $this->getDataIdList($elements, $fieldConfig, $row, $table);
445 445

  
446 446
				if (!count($dataIds))	$dataIds = array(0);
447 447
				$dataAcc[]=$dataIds[0];
......
780 780
	 * @param	string		The field name
781 781
	 * @param	array		TSconfig for the record
782 782
	 * @param	array		The record
783
	 * @param	array		The current table
783 784
	 * @return	array		Modified $dataAcc array
784 785
	 * @access private
785 786
	 * @see renderRecord_selectProc()
786 787
	 */
787
	function selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row)	{
788
	function selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row, $table)	{
788 789
		global $TCA;
789 790

  
790 791
			// Init:
......
806 807

  
807 808
			// At this point all records that CAN be selected is found in $recordList
808 809
			// Now, get the data from loadDBgroup based on the input list of values.
809
		$dataIds = $this->getDataIdList($elements, $fieldConfig, $row);
810
		$dataIds = $this->getDataIdList($elements, $fieldConfig, $row, $table);
810 811
		if ($fieldConfig['config']['MM'])	$dataAcc=array();	// Reset, if MM (which cannot bear anything but real relations!)
811 812

  
812 813
			// After this we can traverse the loadDBgroup values and match values with the list of possible values in $recordList:
......
834 835
	 * @param	array		The array of original elements - basically the field value exploded by ","
835 836
	 * @param	array		Field configuration from TCA
836 837
	 * @param	array		The data array, currently. Used to set the "local_uid" for selecting MM relation records.
838
	 * @param	string		Current table name. passed on to t3lib_loadDBGroup
837 839
	 * @return	array		An array with ids of the records from the input elements array.
838 840
	 * @access private
839 841
	 */
840
	function getDataIdList($elements, $fieldConfig, $row)	{
842
	function getDataIdList($elements, $fieldConfig, $row, $table)	{
841 843
		$loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
842 844
		$loadDB->registerNonTableValues=$fieldConfig['config']['allowNonIdValues'] ? 1 : 0;
843
		$loadDB->start(implode(',',$elements), $fieldConfig['config']['foreign_table'].','.$fieldConfig['config']['neg_foreign_table'], $fieldConfig['config']['MM'], $row['uid']);
845
		$loadDB->start(implode(',',$elements),
846
			$fieldConfig['config']['foreign_table'].','.$fieldConfig['config']['neg_foreign_table'],
847
			$fieldConfig['config']['MM'],
848
			$row['uid'],
849
			$table,
850
			$fieldConfig['config']
851
		);
844 852

  
845 853
		$idList = $loadDB->convertPosNeg($loadDB->getValueArray(),$fieldConfig['config']['foreign_table'],$fieldConfig['config']['neg_foreign_table']);
846 854

  
C:/apache/typo3/typo3_src-trunk/typo3/mod/user/ws/workspaceforms.php (working copy)
484 484
		$config = &$GLOBALS['TCA']['sys_workspace']['columns']['adminusers']['config'];
485 485
		// Notice: $config['MM'] is not set in the current version of $TCA but
486 486
		// we still pass it to ensure compatibility with feature versions!
487
		$loadDB->start($GLOBALS['BE_USER']->user['uid'], $config['allowed'], $config['MM'], $uid);
487
		$loadDB->start($GLOBALS['BE_USER']->user['uid'], $config['allowed'], $config['MM'], $uid, 'sys_workspace', $config);
488 488
		$loadDB->getFromDB();
489 489
		return $loadDB->readyForInterface();
490 490
	}
    (1-1/1)