Index: t3lib/class.t3lib_tceforms_inline.php
===================================================================
--- t3lib/class.t3lib_tceforms_inline.php	(Revision 3399)
+++ t3lib/class.t3lib_tceforms_inline.php	(Arbeitskopie)
@@ -327,26 +327,29 @@
 		$combination = $this->renderCombinationTable($rec, $appendFormFieldNames, $config);
 		$fields = $this->renderMainFields($foreign_table, $rec);
 		$fields = $this->wrapFormsSection($fields);
+			// Get configuration:
+		$collapseAll = (isset($config['appearance']['collapseAll']) && $config['appearance']['collapseAll']);
 
 		if ($isNewRecord) {
 				// show this record expanded or collapsed
-			$isExpanded = is_array($config['appearance']) && $config['appearance']['collapseAll'] ? 1 : 0;
+			$isExpanded = (!$collapseAll ? 1 : 0);
 				// get the top parent table
 			$top = $this->getStructureLevel(0);
-			$ucFieldName = 'uc['.$top['table'].']['.$top['uid'].']'.$appendFormFieldNames;
+			$ucFieldName = 'uc[inlineView]['.$top['table'].']['.$top['uid'].']'.$appendFormFieldNames;
 				// set additional fields for processing for saving
 			$fields .= '<input type="hidden" name="'.$this->prependFormFieldNames.$appendFormFieldNames.'[pid]" value="'.$rec['pid'].'"/>';
 			$fields .= '<input type="hidden" name="'.$ucFieldName.'" value="'.$isExpanded.'" />';
-
 		} else {
 				// show this record expanded or collapsed
-			$isExpanded = $this->getExpandedCollapsedState($foreign_table, $rec['uid']);
+			$isExpanded = (!$collapseAll && $this->getExpandedCollapsedState($foreign_table, $rec['uid']));
 				// set additional field for processing for saving
 			$fields .= '<input type="hidden" name="'.$this->prependCmdFieldNames.$appendFormFieldNames.'[delete]" value="1" disabled="disabled" />';
 		}
 
 			// if this record should be shown collapsed
-		if (!$isExpanded) $appearanceStyleFields = ' style="display: none;"';
+		if (!$isExpanded) {
+			$appearanceStyleFields = ' style="display: none;"';
+		}
 
 			// set the record container with data for output
 		$out = '<div id="'.$formFieldNames.'_header">'.$header.'</div>';
@@ -855,6 +858,8 @@
 		$parent = $this->getStructureLevel(-1);
 			// get TCA 'config' of the parent table
 		$config = $parent['config'];
+		$collapseAll = (isset($config['appearance']['collapseAll']) && $config['appearance']['collapseAll']);
+		$expandSingle = (isset($config['appearance']['expandSingle']) && $config['appearance']['expandSingle']); 
 
 			// Put the current level also to the dynNestedStack of TCEforms:
 		$this->fObj->pushToDynNestedStack('inline', $this->inlineNames['object']);
@@ -924,11 +929,17 @@
 			// Add the JavaScript data that would have been added at the bottom of a regular TCEforms call:
 		$jsonArray['scriptCall'][] = $this->fObj->JSbottom($this->fObj->formName, true);
 			// if script.aculo.us Sortable is used, update the Observer to know the the record
-		if ($config['appearance']['useSortable'])
+		if ($config['appearance']['useSortable']) {
 			$jsonArray['scriptCall'][] = "inline.createDragAndDropSorting('".$this->inlineNames['object']."_records');";
+		}
 			// if TCEforms has some JavaScript code to be executed, just do it
-		if ($this->fObj->extJSCODE)
+		if ($this->fObj->extJSCODE) {
 			$jsonArray['scriptCall'][] = $this->fObj->extJSCODE;
+		}
+ 			// Collapse all other records if requested:
+ 		if (!$collapseAll && $expandSingle) {
+ 			$jsonArray['scriptCall'][] = "inline.collapseAllRecords('$objectId', '$objectPrefix', '".$record['uid']."');";
+ 		}
 			// tell the browser to scroll to the newly created record
 		$jsonArray['scriptCall'][] = "Element.scrollTo('".$objectId."_div');";
 			// fade out and fade in the new record in the browser view to catch the user's eye
@@ -960,7 +971,7 @@
 
 			// only do some action if the top record and the current record were saved before
 		if (t3lib_div::testInt($top['uid'])) {
-			$inlineView = unserialize($GLOBALS['BE_USER']->uc['inlineView']);
+			$inlineView = (array)unserialize($GLOBALS['BE_USER']->uc['inlineView']);
 			$inlineViewCurrent =& $inlineView[$top['table']][$top['uid']];
 
 			$expandUids = t3lib_div::trimExplode(',', $expand);
@@ -977,6 +988,7 @@
 
 				// save states back to database
 			if (is_array($inlineViewCurrent[$current['table']])) {
+				$inlineViewCurrent = array_unique($inlineViewCurrent);
 				$GLOBALS['BE_USER']->uc['inlineView'] = serialize($inlineView);
 				$GLOBALS['BE_USER']->writeUC();
 			}
@@ -1780,8 +1792,10 @@
 	 * @return	boolean		true=expand, false=collapse
 	 */
 	function getExpandedCollapsedState($table, $uid) {
-		if (is_array($this->inlineView) && is_array($this->inlineView[$table])) {
-			if (in_array($uid, $this->inlineView[$table]) !== false) return true;
+		if (isset($this->inlineView[$table]) && is_array($this->inlineView[$table])) {
+			if (in_array($uid, $this->inlineView[$table]) !== false) {
+				return true;
+			}
 		}
 		return false;
 	}
@@ -1795,20 +1809,22 @@
 	 * @return	void
 	 */
 	function updateInlineView(&$uc, &$tce) {
-		if (is_array($uc) && $uc['inlineView']) {
-			$inlineView = unserialize($GLOBALS['BE_USER']->uc['inlineView']);
+		if (isset($uc['inlineView']) && is_array($uc['inlineView'])) {
+			$inlineView = (array)unserialize($GLOBALS['BE_USER']->uc['inlineView']);
 
 			foreach ($uc['inlineView'] as $topTable => $topRecords) {
 				foreach ($topRecords as $topUid => $childElements) {
 					foreach ($childElements as $childTable => $childRecords) {
 						$uids = array_keys($tce->substNEWwithIDs_table, $childTable);
+						$inlineViewCurrent =& $inlineView[$topTable][$topUid][$childTable];
 						if (count($uids)) {
 							foreach ($childRecords as $childUid => $state) {
 								if ($state && in_array($childUid, $uids)) {
 									$newChildUid = $tce->substNEWwithIDs[$childUid];
-									$inlineView[$topTable][$topUid][$childTable][$newChildUid] = 1;
+									$inlineViewCurrent[] = $newChildUid;
 								}
 							}
+							$inlineViewCurrent = array_unique($inlineViewCurrent);
 						}
 					}
 				}
