/**
  * Determine record to use. Current or workspace record?
  *
  * @param	array			$row current tt_content record
  * @return	array			$record to use
  */
 protected function determineRecord(array $row)
 {
     if ($GLOBALS['BE_USER']->workspace !== 0) {
         $workspaceRecord = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, 'tt_content', intval($row['uid']));
         if ($workspaceRecord) {
             $row = $workspaceRecord;
         }
     }
     return $row;
 }
Esempio n. 2
0
    /**
     * Main function, rendering the document with the iframe with the RTE in.
     *
     * @return	void
     */
    function main()
    {
        global $BE_USER, $LANG;
        // translate id to the workspace version:
        if ($versionRec = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $this->P['table'], $this->P['uid'], 'uid')) {
            $this->P['uid'] = $versionRec['uid'];
        }
        // If all parameters are available:
        if ($this->P['table'] && $this->P['field'] && $this->P['uid'] && $this->checkEditAccess($this->P['table'], $this->P['uid'])) {
            // Getting the raw record (we need only the pid-value from here...)
            $rawRec = t3lib_BEfunc::getRecord($this->P['table'], $this->P['uid']);
            t3lib_BEfunc::fixVersioningPid($this->P['table'], $rawRec);
            // Setting JavaScript, including the pid value for viewing:
            $this->doc->JScode = $this->doc->wrapScriptTags('
					function jumpToUrl(URL,formEl)	{	//
						if (document.editform)	{
							if (!TBE_EDITOR.isFormChanged())	{
								window.location.href = URL;
							} else if (formEl) {
								if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
							}
						} else window.location.href = URL;
					}
				' . ($this->popView ? t3lib_BEfunc::viewOnClick($rawRec['pid'], '', t3lib_BEfunc::BEgetRootLine($rawRec['pid'])) : '') . '
			');
            // Initialize TCeforms - for rendering the field:
            $tceforms = t3lib_div::makeInstance('t3lib_TCEforms');
            $tceforms->initDefaultBEMode();
            // Init...
            $tceforms->disableWizards = 1;
            // SPECIAL: Disables all wizards - we are NOT going to need them.
            $tceforms->colorScheme[0] = $this->doc->bgColor;
            // SPECIAL: Setting background color of the RTE to ordinary background
            // Initialize style for RTE object:
            $RTEobj = t3lib_BEfunc::RTEgetObj();
            // Getting reference to the RTE object used to render the field!
            if ($RTEobj->ID == 'rte') {
                $RTEobj->RTEdivStyle = 'position:relative; left:0px; top:0px; height:100%; width:100%; border:solid 0px;';
                // SPECIAL: Setting style for the RTE <DIV> layer containing the IFRAME
            }
            // Fetching content of record:
            $trData = t3lib_div::makeInstance('t3lib_transferData');
            $trData->lockRecords = 1;
            $trData->fetchRecord($this->P['table'], $this->P['uid'], '');
            // Getting the processed record content out:
            reset($trData->regTableItems_data);
            $rec = current($trData->regTableItems_data);
            $rec['uid'] = $this->P['uid'];
            $rec['pid'] = $rawRec['pid'];
            // TSconfig, setting width:
            $fieldTSConfig = $tceforms->setTSconfig($this->P['table'], $rec, $this->P['field']);
            if (strcmp($fieldTSConfig['RTEfullScreenWidth'], '')) {
                $width = $fieldTSConfig['RTEfullScreenWidth'];
            } else {
                $width = '100%';
            }
            // Get the form field and wrap it in the table with the buttons:
            $formContent = $tceforms->getSoloField($this->P['table'], $rec, $this->P['field']);
            $formContent = '


			<!--
				RTE wizard:
			-->
				<table border="0" cellpadding="0" cellspacing="0" width="' . $width . '" id="typo3-rtewizard">
					<tr>
						<td width="' . $width . '" colspan="2" id="c-formContent">' . $formContent . '</td>
						<td></td>
					</tr>
				</table>';
            // Adding hidden fields:
            $formContent .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($this->R_URI) . '" />
						<input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />' . t3lib_TCEforms::getHiddenTokenField('tceAction');
            // Finally, add the whole setup:
            $this->content .= $tceforms->printNeededJSFunctions_top() . $formContent . $tceforms->printNeededJSFunctions();
        } else {
            // ERROR:
            $this->content .= $this->doc->section($LANG->getLL('forms_title'), '<span class="typo3-red">' . $LANG->getLL('table_noData', 1) . '</span>', 0, 1);
        }
        // Setting up the buttons and markers for docheader
        $docHeaderButtons = $this->getButtons();
        $markers['CONTENT'] = $this->content;
        // Build the <body> for the module
        $this->content = $this->doc->startPage('');
        $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
        $this->content .= $this->doc->endPage();
        $this->content = $this->doc->insertStylesAndJS($this->content);
    }
Esempio n. 3
0
    /**
     * Creates the version selector for the page id inputted.
     * Requires the core version management extension, "version" to be loaded.
     *
     * @param	integer		Page id to create selector for.
     * @param	boolean		If set, there will be no button for swapping page.
     * @return	void
     */
    function getVersionSelector($id, $noAction = FALSE)
    {
        if ($id > 0) {
            if (t3lib_extMgm::isLoaded('version') && $GLOBALS['BE_USER']->workspace == 0) {
                // Get Current page record:
                $curPage = t3lib_BEfunc::getRecord('pages', $id);
                // If the selected page is not online, find the right ID
                $onlineId = $curPage['pid'] == -1 ? $curPage['t3ver_oid'] : $id;
                // Select all versions of online version:
                $versions = t3lib_BEfunc::selectVersionsOfRecord('pages', $onlineId, 'uid,pid,t3ver_label,t3ver_oid,t3ver_wsid,t3ver_id');
                // If more than one was found...:
                if (count($versions) > 1) {
                    $selectorLabel = '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.label', TRUE) . '</strong>';
                    // Create selector box entries:
                    $opt = array();
                    foreach ($versions as $vRow) {
                        if ($vRow['uid'] == $onlineId) {
                            //Live version
                            $label = '[' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.live', TRUE) . ']';
                        } else {
                            $label = $vRow['t3ver_label'] . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionId', TRUE) . ' ' . $vRow['t3ver_id'] . ($vRow['t3ver_wsid'] != 0 ? ' ' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:workspaceId', TRUE) . ' ' . $vRow['t3ver_wsid'] : '') . ')';
                        }
                        $opt[] = '<option value="' . htmlspecialchars(t3lib_div::linkThisScript(array('id' => $vRow['uid']))) . '"' . ($id == $vRow['uid'] ? ' selected="selected"' : '') . '>' . htmlspecialchars($label) . '</option>';
                    }
                    // Add management link:
                    $management = '<input type="button" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.mgm', TRUE) . '" onclick="window.location.href=\'' . htmlspecialchars($this->backPath . t3lib_extMgm::extRelPath('version') . 'cm1/index.php?table=pages&uid=' . $onlineId) . '\';" />';
                    // Create onchange handler:
                    $onChange = "window.location.href=this.options[this.selectedIndex].value;";
                    // Controls:
                    if ($id == $onlineId) {
                        $controls .= '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/blinkarrow_left.gif', 'width="5" height="9"') . ' class="absmiddle" alt="" /> <strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.online', TRUE) . '</strong>';
                    } elseif (!$noAction) {
                        $controls .= '<a href="' . $this->issueCommand('&cmd[pages][' . $onlineId . '][version][swapWith]=' . $id . '&cmd[pages][' . $onlineId . '][version][action]=swap', t3lib_div::linkThisScript(array('id' => $onlineId))) . '" class="nobr">' . t3lib_iconWorks::getSpriteIcon('actions-version-swap-version', array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.swapPage', TRUE), 'style' => 'margin-left:5px;vertical-align:bottom;')) . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.swap', TRUE) . '</strong></a>';
                    }
                    // Write out HTML code:
                    return '

						<!--
							Version selector:
						-->
						<table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
							<tr>
								<td>' . $selectorLabel . '</td>
								<td>
									<select onchange="' . htmlspecialchars($onChange) . '">
										' . implode('', $opt) . '
									</select></td>
								<td>' . $controls . '</td>
								<td>' . $management . '</td>
							</tr>
						</table>
					';
                }
            } elseif ($GLOBALS['BE_USER']->workspace !== 0) {
                // Write out HTML code:
                switch ($GLOBALS['BE_USER']->workspace) {
                    case 0:
                        $wsTitle = $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:live', TRUE);
                        break;
                    case -1:
                        $wsTitle = $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:draft', TRUE);
                        break;
                    default:
                        $wsTitle = $GLOBALS['BE_USER']->workspaceRec['title'];
                        break;
                }
                if (t3lib_BEfunc::isPidInVersionizedBranch($id) == 'branchpoint') {
                    return '

						<!--
							Version selector:
						-->
						<table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
							<tr>
								<td>' . $selectorLabel . '</td>
								<td>Workspace: "' . htmlspecialchars($wsTitle) . '"</td>
								<td><em>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.inBranch', TRUE) . '</em></td>
							</tr>
						</table>
					';
                } else {
                    // Get Current page record:
                    $curPage = t3lib_BEfunc::getRecord('pages', $id);
                    // If the selected page is not online, find the right ID
                    $onlineId = $curPage['pid'] == -1 ? $curPage['t3ver_oid'] : $id;
                    // The version of page:
                    $verPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, 'pages', $onlineId);
                    if (!$verPage) {
                        if (!count(t3lib_BEfunc::countVersionsOfRecordsOnPage($GLOBALS['BE_USER']->workspace, $onlineId))) {
                            if ($GLOBALS['BE_USER']->workspaceVersioningTypeAccess(0)) {
                                $onClick = $this->issueCommand('&cmd[pages][' . $onlineId . '][version][action]=new&cmd[pages][' . $onlineId . '][version][treeLevels]=0', t3lib_div::linkThisScript(array('id' => $onlineId)));
                                $onClick = 'window.location.href=\'' . $onClick . '\'; return false;';
                                // Write out HTML code:
                                return '

									<!--
										No version yet, create one?
									-->
									<table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
										<tr>
											<td>' . $selectorLabel . '</td>
											<td>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:workspace', TRUE) . ': "' . htmlspecialchars($wsTitle) . '"</td>
											<td>
												<input type="button" value="New version of page" name="_" onclick="' . htmlspecialchars($onClick) . '" /></td>
										</tr>
									</table>
								';
                            }
                        } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['elementVersioningOnly'] == FALSE && $GLOBALS['TYPO3_CONF_VARS']['BE']['newPagesVersioningType'] == 0) {
                            // only add this info if old/deprecated newPagesVersioning is allowed
                            return '

								<!--
									Version selector:
								-->
								<table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
									<tr>
										<td>' . $selectorLabel . '</td>
										<td>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:workspace', TRUE) . ': "' . htmlspecialchars($wsTitle) . '"</td>
										<td><em>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.versionsFound', TRUE) . '</em></td>
									</tr>
								</table>
							';
                        }
                    } elseif ($verPage['t3ver_swapmode'] == 0) {
                        $onClick = $this->issueCommand('&cmd[pages][' . $onlineId . '][version][action]=swap&cmd[pages][' . $onlineId . '][version][swapWith]=' . $verPage['uid'], t3lib_div::linkThisScript(array('id' => $onlineId)));
                        $onClick = 'window.location.href=\'' . $onClick . '\'; return false;';
                        // Write out HTML code:
                        return '

							<!--
								Version selector:
							-->
							<table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
								<tr>
									<td>' . $selectorLabel . '</td>
									<td>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:workspace', TRUE) . ': "' . htmlspecialchars($wsTitle) . '"</td>
									<td>
										<input type="button" value="' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.publish', TRUE) . '" onclick="' . htmlspecialchars($onClick) . '" /></td>
								</tr>
							</table>
						';
                    }
                }
            }
        }
    }
Esempio n. 4
0
 /**
  * [Describe function...]
  *
  * @param	[type]		$label: ...
  * @param	[type]		$table: ...
  * @param	[type]		$uid: ...
  * @param	[type]		$hidden: ...
  * @param	[type]		$forced: ...
  * @param	integer			$usePid: ...
  * @return	[type]		...
  */
 function link_hide($label, $table, $uid, $hidden, $forced = FALSE, $usePid = 0)
 {
     if ($label) {
         $pid = $table == 'pages' ? $uid : $usePid;
         $calcPerms = $pid == 0 ? $this->calcPerms : $this->getCalcPerms($pid);
         if (($table == 'pages' && $calcPerms & 2 || $table != 'pages' && $calcPerms & 16) && (!$this->translatorMode || $forced)) {
             $workspaceRec = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $table, $uid);
             $workspaceId = $workspaceRec['uid'] > 0 ? $workspaceRec['uid'] : $uid;
             if ($table == "pages" && $this->currentLanguageUid) {
                 $params = '&data[' . $table . '][' . $workspaceId . '][hidden]=' . (1 - $hidden);
                 //	return '<a href="#" onclick="' . htmlspecialchars('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');') . '">'.$label.'</a>';
             } else {
                 $params = '&data[' . $table . '][' . $workspaceId . '][hidden]=' . (1 - $hidden);
                 //	return '<a href="#" onclick="' . htmlspecialchars('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');') . '">'.$label.'</a>';
                 /* the commands are indipendent of the position,
                  * so sortable doesn't need to update these and we
                  * can safely use '#'
                  */
                 if ($hidden) {
                     return '<a href="#" class="tpm-hide" onclick="sortable_unhideRecord(this, \'' . htmlspecialchars($GLOBALS['SOBE']->doc->issueCommand($params, -1)) . '\');">' . $label . '</a>';
                 } else {
                     return '<a href="#" class="tpm-hide" onclick="sortable_hideRecord(this, \'' . htmlspecialchars($GLOBALS['SOBE']->doc->issueCommand($params, -1)) . '\');">' . $label . '</a>';
                 }
             }
         } else {
             return $label;
         }
     }
     return '';
 }
 /**
  * Find orphan records
  * VERY CPU and memory intensive since it will look up the whole page tree!
  *
  * @return	array
  */
 function main()
 {
     global $TYPO3_DB;
     // Initialize result array:
     $resultArray = array('message' => $this->cli_help['name'] . LF . LF . $this->cli_help['description'], 'headers' => array('versions' => array('All versions', 'Showing all versions of records found', 0), 'versions_published' => array('All published versions', 'This is all records that has been published and can therefore be removed permanently', 1), 'versions_liveWS' => array('All versions in Live workspace', 'This is all records that are offline versions in the Live workspace. You may wish to flush these if you only use workspaces for versioning since then you might find lots of versions piling up in the live workspace which have simply been disconnected from the workspace before they were published.', 1), 'versions_lost_workspace' => array('Versions outside a workspace', 'Versions that has lost their connection to a workspace in TYPO3.', 3), 'versions_inside_versioned_page' => array('Versions in versions', 'Versions inside an already versioned page. Something that is confusing to users and therefore should not happen but is technically possible.', 2), 'versions_unused_placeholders' => array('Unused placeholder records', 'Placeholder records which are not used anymore by offline versions.', 2), 'versions_move_placeholders_ok' => array('Move placeholders', 'Move-to placeholder records which has good integrity', 0), 'versions_move_placeholders_bad' => array('Move placeholders with bad integrity', 'Move-to placeholder records which has bad integrity', 2), 'versions_move_id_check' => array('Checking if t3ver_move_id is correct', 't3ver_move_id must only be set with online records having t3ver_state=3.', 2)), 'versions' => array());
     $startingPoint = $this->cli_isArg('--pid') ? t3lib_div::intInRange($this->cli_argValue('--pid'), 0) : 0;
     $depth = $this->cli_isArg('--depth') ? t3lib_div::intInRange($this->cli_argValue('--depth'), 0) : 1000;
     $this->genTree($startingPoint, $depth, (int) $this->cli_argValue('--echotree'));
     $resultArray['versions'] = $this->recStats['versions'];
     $resultArray['versions_published'] = $this->recStats['versions_published'];
     $resultArray['versions_liveWS'] = $this->recStats['versions_liveWS'];
     $resultArray['versions_lost_workspace'] = $this->recStats['versions_lost_workspace'];
     $resultArray['versions_inside_versioned_page'] = $this->recStats['versions_inside_versioned_page'];
     // Finding all placeholders with no records attached!
     $resultArray['versions_unused_placeholders'] = array();
     foreach ($GLOBALS['TCA'] as $table => $cfg) {
         if ($cfg['ctrl']['versioningWS']) {
             $placeHolders = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,pid', $table, 't3ver_state=1 AND pid>=0' . t3lib_BEfunc::deleteClause($table));
             foreach ($placeHolders as $phrec) {
                 if (count(t3lib_BEfunc::selectVersionsOfRecord($table, $phrec['uid'], 'uid')) <= 1) {
                     $resultArray['versions_unused_placeholders'][t3lib_div::shortmd5($table . ':' . $phrec['uid'])] = $table . ':' . $phrec['uid'];
                 }
             }
         }
     }
     asort($resultArray['versions_unused_placeholders']);
     // Finding all move placeholders with inconsistencies:
     $resultArray['versions_move_placeholders_ok'] = array();
     $resultArray['versions_move_placeholders_bad'] = array();
     foreach ($GLOBALS['TCA'] as $table => $cfg) {
         if ((int) $cfg['ctrl']['versioningWS'] >= 2) {
             $placeHolders = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,pid,t3ver_move_id,t3ver_wsid,t3ver_state', $table, 't3ver_state=3 AND pid>=0' . t3lib_BEfunc::deleteClause($table));
             foreach ($placeHolders as $phrec) {
                 $shortID = t3lib_div::shortmd5($table . ':' . $phrec['uid']);
                 if ((int) $phrec['t3ver_wsid'] != 0) {
                     $phrecCopy = $phrec;
                     if (t3lib_BEfunc::movePlhOL($table, $phrec)) {
                         if ($wsAlt = t3lib_BEfunc::getWorkspaceVersionOfRecord($phrecCopy['t3ver_wsid'], $table, $phrec['uid'], 'uid,pid,t3ver_state')) {
                             if ($wsAlt['t3ver_state'] != 4) {
                                 $resultArray['versions_move_placeholders_bad'][$shortID] = array($table . ':' . $phrec['uid'], 'State for version was not "4" as it should be!', $phrecCopy);
                             } else {
                                 $resultArray['versions_move_placeholders_ok'][$shortID] = array($table . ':' . $phrec['uid'], 'PLH' => $phrecCopy, 'online' => $phrec, 'PNT' => $wsAlt);
                             }
                         } else {
                             $resultArray['versions_move_placeholders_bad'][$shortID] = array($table . ':' . $phrec['uid'], 'No version was found for online record to be moved. A version must exist.', $phrecCopy);
                         }
                     } else {
                         $resultArray['versions_move_placeholders_bad'][$shortID] = array($table . ':' . $phrec['uid'], 'Did not find online record for "t3ver_move_id" value ' . $phrec['t3ver_move_id'], $phrec);
                     }
                 } else {
                     $resultArray['versions_move_placeholders_bad'][$shortID] = array($table . ':' . $phrec['uid'], 'Placeholder was not assigned a workspace value in t3ver_wsid.', $phrec);
                 }
             }
         }
     }
     ksort($resultArray['versions_move_placeholders_ok']);
     ksort($resultArray['versions_move_placeholders_bad']);
     // Finding move_id_check inconsistencies:
     $resultArray['versions_move_id_check'] = array();
     foreach ($GLOBALS['TCA'] as $table => $cfg) {
         if ((int) $cfg['ctrl']['versioningWS'] >= 2) {
             $placeHolders = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,pid,t3ver_move_id,t3ver_wsid,t3ver_state', $table, 't3ver_move_id!=0' . t3lib_BEfunc::deleteClause($table));
             foreach ($placeHolders as $phrec) {
                 if ((int) $phrec['t3ver_state'] == 3) {
                     if ($phrec['pid'] != -1) {
                         // OK
                     } else {
                         $resultArray['versions_move_id_check'][] = array($table . ':' . $phrec['uid'], 'Record was offline, must not be!', $phrec);
                     }
                 } else {
                     $resultArray['versions_move_id_check'][] = array($table . ':' . $phrec['uid'], 'Record had t3ver_move_id set to "' . $phrec['t3ver_move_id'] . '" while having t3ver_state=' . $phrec['t3ver_state'], $phrec);
                 }
             }
         }
     }
     return $resultArray;
 }
 /**
  * This method is used to initialize new Elements with the default
  *
  * @param unknown_type $status
  * @param unknown_type $table
  * @param unknown_type $id
  * @param unknown_type $fieldArray
  * @param unknown_type $reference
  */
 public function processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, &$reference)
 {
     if (in_array($table, tx_languagevisibility_visibilityService::getSupportedTables())) {
         /**
          * Now we set the default visibility for elements which did not get a defaultvisibility array.
          * This can happen, if a user creates a new element AND the user has no access for the languagevisibility_field
          */
         if ($status == 'new') {
             $row['uid'] = $reference->substNEWwithIDs[$id];
             if ($fieldArray['pid'] == '-1') {
                 $row = t3lib_BEfunc::getWorkspaceVersionOfRecord($fieldArray['t3ver_wsid'], $table, $row['uid'], $fields = '*');
             }
             require_once t3lib_extMgm::extPath("languagevisibility") . 'class.tx_languagevisibility_beservices.php';
             $newdata = array('tx_languagevisibility_visibility' => serialize(tx_languagevisibility_beservices::getDefaultVisibilityArray()));
             $where = "tx_languagevisibility_visibility = '' AND uid=" . $row['uid'];
             $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, $where, $newdata);
         }
         tx_languagevisibility_cacheManager::getInstance()->flushAllCaches();
     }
 }
 /**
  * Get the final pid based on $table and $pid ($destPid type... pos/neg)
  *
  * @param	string		Table name
  * @param	integer		"Destination pid" : If the value is >= 0 it's just returned directly (through intval() though) but if the value is <0 then the method looks up the record with the uid equal to abs($pid) (positive number) and returns the PID of that record! The idea is that negative numbers point to the record AFTER WHICH the position is supposed to be!
  * @return	integer
  */
 function resolvePid($table, $pid)
 {
     global $TCA;
     $pid = intval($pid);
     if ($pid < 0) {
         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pid', $table, 'uid=' . abs($pid));
         $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
         // Look, if the record UID happens to be an offline record. If so, find its live version. Offline uids will be used when a page is versionized as "branch" so this is when we must correct - otherwise a pid of "-1" and a wrong sort-row number is returned which we don't want.
         if ($lookForLiveVersion = t3lib_BEfunc::getLiveVersionOfRecord($table, abs($pid), 'pid')) {
             $row = $lookForLiveVersion;
         }
         $pid = intval($row['pid']);
     } elseif ($this->BE_USER->workspace !== 0 && $TCA[$table]['ctrl']['versioning_followPages']) {
         // PID points to page, the workspace is an offline space and the table follows page during versioning: This means we must check if the PID page has a version in the workspace with swapmode set to 0 (zero = page+content) and if so, change the pid to the uid of that version.
         if ($WSdestPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, 'pages', $pid, 'uid,t3ver_swapmode')) {
             // Looks for workspace version of page.
             if ($WSdestPage['t3ver_swapmode'] == 0) {
                 // if swapmode is zero, then change pid value.
                 $pid = $WSdestPage['uid'];
             }
         }
     }
     return $pid;
 }
Esempio n. 8
0
 /**
  * Get record for editing.
  *
  * @param	string		Table name
  * @param	integer		Record UID
  * @return	array		Returns record to edit, false if none
  */
 function getRecordForEdit($table, $theUid)
 {
     global $TCA;
     // Fetch requested record:
     $reqRecord = t3lib_BEfunc::getRecord($table, $theUid, 'uid,pid');
     if (is_array($reqRecord)) {
         // If workspace is OFFLINE:
         if ($GLOBALS['BE_USER']->workspace != 0) {
             // Check for versioning support of the table:
             if ($TCA[$table] && $TCA[$table]['ctrl']['versioningWS']) {
                 // If the record is already a version of "something" pass it by.
                 if ($reqRecord['pid'] == -1) {
                     // (If it turns out not to be a version of the current workspace there will be trouble, but that is handled inside TCEmain then and in the interface it would clearly be an error of links if the user accesses such a scenario)
                     return $reqRecord;
                 } else {
                     // The input record was online and an offline version must be found or made:
                     // Look for version of this workspace:
                     $versionRec = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $table, $reqRecord['uid'], 'uid,pid,t3ver_oid');
                     return is_array($versionRec) ? $versionRec : $reqRecord;
                 }
             } else {
                 return FALSE;
             }
             // This means that editing cannot occur on this record because it was not supporting versioning which is required inside an offline workspace.
         } else {
             return $reqRecord;
         }
         // In ONLINE workspace, just return the originally requested record:
     } else {
         return FALSE;
     }
     // Return false because the table/uid was not found anyway.
 }
 /**
  * Split reference
  * FIXME Should also verify the integrity of the reference string since the rest of the application does NOT check it further.
  * NOTE: This function is deprecated. Use the newer class tx_templavoila_api instead.
  *
  * @param	string		Reference to a tt_content element in a flexform field of references to tt_content elements. Syntax is: [table]:[uid]:[sheet]:[lLanguage]:[FlexForm field name]:[vLanguage]:[index of reference position in field value]. Example: 'pages:78:sDEF:lDEF:field_contentarea:vDEF:0/tt_content:60'
  * @return	array		Array with each part between ':' in a value with numeric key (exploded)
  * @access	protected
  * @deprecated version - 1.0.0
  */
 function _splitAndValidateReference($string)
 {
     $refArr = explode(':', $string);
     if ($version = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $refArr[0], $refArr[1], 'uid')) {
         $refArr[1] = $version['uid'];
     }
     return $refArr;
 }
 /**
  * hook for t3lib_TCEmain::moveRecord that cares about moving records that
  * are *not* in the live workspace
  *
  * @param string $table the table of the record
  * @param integer $id the ID of the record
  * @param integer $destPid Position to move to: $destPid: >=0 then it points to
  * 				a page-id on which to insert the record (as the first element).
  * 				<0 then it points to a uid from its own table after which to insert it
  * @param array $propArr Record properties, like header and pid (includes workspace overlay)
  * @param array $moveRec Record properties, like header and pid (without workspace overlay)
  * @param integer $resolvedPid The final page ID of the record
  * 				(workspaces and negative values are resolved)
  * @param boolean $recordWasMoved can be set so that other hooks or
  * 				TCEmain knows that the default move action doesn't have to be called
  * @param	$table	the table
  */
 public function moveRecord($table, $uid, $destPid, array $propArr, array $moveRec, $resolvedPid, &$recordWasMoved, t3lib_TCEmain $tcemainObj)
 {
     global $TCA;
     // Only do something in Draft workspace
     if ($tcemainObj->BE_USER->workspace !== 0) {
         $recordWasMoved = TRUE;
         // Get workspace version of the source record, if any:
         $WSversion = t3lib_BEfunc::getWorkspaceVersionOfRecord($tcemainObj->BE_USER->workspace, $table, $uid, 'uid,t3ver_oid');
         // If no version exists and versioningWS is in version 2, a new placeholder is made automatically:
         if (!$WSversion['uid'] && (int) $TCA[$table]['ctrl']['versioningWS'] >= 2 && (int) $moveRec['t3ver_state'] != 3) {
             $tcemainObj->versionizeRecord($table, $uid, 'Placeholder version for moving record');
             $WSversion = t3lib_BEfunc::getWorkspaceVersionOfRecord($tcemainObj->BE_USER->workspace, $table, $uid, 'uid,t3ver_oid');
             // Will not create new versions in live workspace though...
         }
         // Check workspace permissions:
         $workspaceAccessBlocked = array();
         // Element was in "New/Deleted/Moved" so it can be moved...
         $recIsNewVersion = (int) $moveRec['t3ver_state'] > 0;
         $destRes = $tcemainObj->BE_USER->workspaceAllowLiveRecordsInPID($resolvedPid, $table);
         $canMoveRecord = $recIsNewVersion || (int) $TCA[$table]['ctrl']['versioningWS'] >= 2;
         // Workspace source check:
         if (!$recIsNewVersion) {
             $errorCode = $tcemainObj->BE_USER->workspaceCannotEditRecord($table, $WSversion['uid'] ? $WSversion['uid'] : $uid);
             if ($errorCode) {
                 $workspaceAccessBlocked['src1'] = 'Record could not be edited in workspace: ' . $errorCode . ' ';
             } elseif (!$canMoveRecord && $tcemainObj->BE_USER->workspaceAllowLiveRecordsInPID($moveRec['pid'], $table) <= 0) {
                 $workspaceAccessBlocked['src2'] = 'Could not remove record from table "' . $table . '" from its page "' . $moveRec['pid'] . '" ';
             }
         }
         // Workspace destination check:
         // All records can be inserted if $destRes is greater than zero.
         // Only new versions can be inserted if $destRes is false.
         // NO RECORDS can be inserted if $destRes is negative which indicates a stage
         //  not allowed for use. If "versioningWS" is version 2, moving can take place of versions.
         if (!($destRes > 0 || $canMoveRecord && !$destRes)) {
             $workspaceAccessBlocked['dest1'] = 'Could not insert record from table "' . $table . '" in destination PID "' . $resolvedPid . '" ';
         } elseif ($destRes == 1 && $WSversion['uid']) {
             $workspaceAccessBlocked['dest2'] = 'Could not insert other versions in destination PID ';
         }
         if (!count($workspaceAccessBlocked)) {
             // If the move operation is done on a versioned record, which is
             // NOT new/deleted placeholder and versioningWS is in version 2, then...
             if ($WSversion['uid'] && !$recIsNewVersion && (int) $TCA[$table]['ctrl']['versioningWS'] >= 2) {
                 $this->moveRecord_wsPlaceholders($table, $uid, $destPid, $WSversion['uid'], $tcemainObj);
             } else {
                 // moving not needed, just behave like in live workspace
                 $recordWasMoved = FALSE;
             }
         } else {
             $tcemainObj->newlog("Move attempt failed due to workspace restrictions: " . implode(' // ', $workspaceAccessBlocked), 1);
         }
     }
 }
 /**
  * Evaluates if auto creation of a version of a record is allowed.
  *
  * @param	string		Table of the record
  * @param	integer		UID of record
  * @param	integer		PID of record
  * @return	boolean		TRUE if ok.
  */
 function workspaceAllowAutoCreation($table, $id, $recpid)
 {
     // Auto-creation of version: In offline workspace, test if versioning is enabled and look for workspace version of input record. If there is no versionized record found we will create one and save to that.
     if ($this->workspace !== 0 && !$this->workspaceRec['disable_autocreate'] && $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] && $recpid >= 0 && !t3lib_BEfunc::getWorkspaceVersionOfRecord($this->workspace, $table, $id, 'uid') && !t3lib_BEfunc::isPidInVersionizedBranch($recpid, $table)) {
         // PID must NOT be in a versionized branch either
         return TRUE;
     }
 }
	/**
	 * Finds data source value for the current template object and sets it to the
	 * $incomingFieldArray.
	 *
	 * @param	array	$incomingFieldArray	Array with fields
	 * @param	string	$dsField	Data source field name in the $incomingFieldArray
	 * @param	string	$toField	Template object field name in the $incomingFieldArray
	 * @param	t3lib_beUserAuth	$beUser	Current backend user for this operation
	 * @return	void
	 */
	protected function updateDataSourceFieldFromTemplateObjectField(array &$incomingFieldArray, $dsField, $toField, t3lib_beUserAuth &$beUser) {
		$toId = $incomingFieldArray[$toField];
		if (intval($toId) == 0) {
			$incomingFieldArray[$dsField] = '';
		}
		else {
			if ($beUser->workspace) {
				$record = t3lib_BEfunc::getWorkspaceVersionOfRecord($beUser->workspace, 'tx_templavoila_tmplobj', $toId, 'datastructure');
				if (!is_array($record)) {
					$record = t3lib_BEfunc::getRecord('tx_templavoila_tmplobj', $toId, 'datastructure');
				}
			}
			else {
				$record = t3lib_BEfunc::getRecord('tx_templavoila_tmplobj', $toId, 'datastructure');
			}
			if (is_array($record) && isset($record['datastructure'])) {
				$incomingFieldArray[$dsField] = $record['datastructure'];
			}
		}
	}
    /**
     * Draws the preview content for a content element
     *
     * @param	string		Content element
     * @param	boolean		Set if the RTE link can be created.
     * @return	string		HTML
     */
    function tt_content_drawItem($row, $isRTE = FALSE)
    {
        global $TCA;
        $out = '';
        $outHeader = '';
        // Make header:
        if ($row['header'] && $row['header_layout'] != 100) {
            $infoArr = array();
            $this->getProcessedValue('tt_content', 'header_position,header_layout,header_link', $row, $infoArr);
            $outHeader = ($row['date'] ? htmlspecialchars($this->itemLabels['date'] . ' ' . t3lib_BEfunc::date($row['date'])) . '<br />' : '') . $this->infoGif($infoArr) . '<b>' . $this->linkEditContent($this->renderText($row['header']), $row) . '</b><br />';
        }
        // Make content:
        $infoArr = array();
        switch ($row['CType']) {
            case 'header':
                if ($row['subheader']) {
                    $this->getProcessedValue('tt_content', 'layout', $row, $infoArr);
                    $out .= $this->infoGif($infoArr) . $this->linkEditContent($this->renderText($row['subheader']), $row) . '<br />';
                }
                break;
            case 'text':
            case 'textpic':
            case 'image':
                if ($row['CType'] == 'text' || $row['CType'] == 'textpic') {
                    if ($row['bodytext']) {
                        $this->getProcessedValue('tt_content', 'text_align,text_face,text_size,text_color,text_properties', $row, $infoArr);
                        $out .= $this->infoGif($infoArr) . $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
                    }
                }
                if ($row['CType'] == 'textpic' || $row['CType'] == 'image') {
                    if ($row['image']) {
                        $infoArr = array();
                        $this->getProcessedValue('tt_content', 'imageorient,imagecols,image_noRows,imageborder,imageheight,image_link,image_zoom,image_compression,image_effects,image_frames', $row, $infoArr);
                        $out .= $this->infoGif($infoArr) . $this->thumbCode($row, 'tt_content', 'image') . '<br />';
                        if ($row['imagecaption']) {
                            $infoArr = array();
                            $this->getProcessedValue('tt_content', 'imagecaption_position', $row, $infoArr);
                            $out .= $this->infoGif($infoArr) . $this->linkEditContent($this->renderText($row['imagecaption']), $row) . '<br />';
                        }
                    }
                    ###########
                    if ($row['tx_damttcontent_files']) {
                        require_once PATH_txdam . 'lib/class.tx_dam_image.php';
                        require_once PATH_txdam . 'lib/class.tx_dam_tcefunc.php';
                        require_once PATH_txdam . 'lib/class.tx_dam_guifunc.php';
                        $config = $TCA['tt_content']['columns']['tx_damttcontent_files']['config'];
                        if ($GLOBALS['BE_USER']->workspace !== 0) {
                            $workspaceRecord = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, 'tt_content', $row['uid']);
                            if ($workspaceRecord) {
                                $row = $workspaceRecord;
                            }
                        }
                        $filesArray = tx_dam_db::getReferencedFiles('tt_content', $row['uid'], $config['MM_match_fields'], $config['MM'], 'tx_dam.*');
                        foreach ($filesArray['rows'] as $rowDAM) {
                            $caption = tx_dam_guiFunc::meta_compileInfoData($rowDAM, '_caption:truncate:100', 'value-string');
                            #$imgAttributes['title'] = tx_dam_guiFunc::meta_compileHoverText($rowDAM);
                            #$thumb = tx_dam_image::previewImgTag($rowDAM, '', $imgAttributes);
                            $thumb = tx_dam_guiFunc::thumbnail($rowDAM);
                            $thumb = '<div style="float:left;width:56px; overflow:auto; margin: 2px 5px 2px 0; padding: 5px; background-color:#fff; border:solid 1px #ccc;">' . $thumb . '</div>';
                            $thumb = '<div>' . $thumb . $caption . '</div><div style="clear:both"></div>';
                            $out .= $thumb;
                        }
                    }
                    #############
                }
                break;
            case 'bullets':
                if ($row['bodytext']) {
                    $this->getProcessedValue('tt_content', 'layout,text_align,text_face,text_size,text_color,text_properties', $row, $infoArr);
                    $out .= $this->infoGif($infoArr) . $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
                }
                break;
            case 'table':
                if ($row['bodytext']) {
                    $this->getProcessedValue('tt_content', 'table_bgColor,table_border,table_cellspacing,cols,layout,text_align,text_face,text_size,text_color,text_properties', $row, $infoArr);
                    $out .= $this->infoGif($infoArr) . $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
                }
                break;
            case 'uploads':
                if ($row['media']) {
                    $this->getProcessedValue('tt_content', 'media,select_key,layout,filelink_size,table_bgColor,table_border,table_cellspacing', $row, $infoArr);
                    $out .= $this->infoGif($infoArr) . $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
                }
                break;
            case 'multimedia':
                if ($row['multimedia']) {
                    $out .= $this->renderText($row['multimedia']) . '<br />';
                    $out .= $this->renderText($row['parameters']) . '<br />';
                }
                break;
            case 'mailform':
                if ($row['bodytext']) {
                    $this->getProcessedValue('tt_content', 'pages,subheader', $row, $infoArr);
                    $out .= $this->infoGif($infoArr) . $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
                }
                break;
            case 'splash':
                if ($row['bodytext']) {
                    $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
                }
                if ($row['image']) {
                    $infoArr = array();
                    $this->getProcessedValue('tt_content', 'imagewidth', $row, $infoArr);
                    $out .= $this->infoGif($infoArr) . $this->thumbCode($row, 'tt_content', 'image') . '<br />';
                }
                break;
            case 'menu':
                if ($row['pages']) {
                    $this->getProcessedValue('tt_content', 'menu_type', $row, $infoArr);
                    $out .= $this->infoGif($infoArr) . $this->linkEditContent($row['pages'], $row) . '<br />';
                }
                break;
            case 'shortcut':
                if ($row['records']) {
                    $this->getProcessedValue('tt_content', 'layout', $row, $infoArr);
                    $out .= $this->infoGif($infoArr) . $this->linkEditContent($row['shortcut'], $row) . '<br />';
                }
                break;
            case 'list':
                $this->getProcessedValue('tt_content', 'layout', $row, $infoArr);
                $out .= $this->infoGif($infoArr) . $GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel('tt_content', 'list_type'), 1) . ' ' . $GLOBALS['LANG']->sL(t3lib_BEfunc::getLabelFromItemlist('tt_content', 'list_type', $row['list_type']), 1) . '<br />';
                $out .= $GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel('tt_content', 'select_key'), 1) . ' ' . $row['select_key'] . '<br />';
                $infoArr = array();
                $this->getProcessedValue('tt_content', 'recursive', $row, $infoArr);
                $out .= $this->infoGif($infoArr) . $GLOBALS['LANG']->sL(t3lib_BEfunc::getLabelFromItemlist('tt_content', 'pages', $row['pages']), 1) . '<br />';
                break;
            case 'script':
                $out .= $GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel('tt_content', 'select_key'), 1) . ' ' . $row['select_key'] . '<br />';
                $out .= '<br />' . $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
                $out .= '<br />' . $this->linkEditContent($this->renderText($row['imagecaption']), $row) . '<br />';
                break;
            default:
                if ($row['bodytext']) {
                    $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
                }
                break;
        }
        // Wrap span-tags:
        $out = '
			<span class="exampleContent">' . $out . '</span>';
        // Add header:
        $out = $outHeader . $out;
        // Add RTE button:
        if ($isRTE) {
            $out .= $this->linkRTEbutton($row);
        }
        // Return values:
        if ($this->isDisabled('tt_content', $row)) {
            return $GLOBALS['TBE_TEMPLATE']->dfw($out);
        } else {
            return $out;
        }
    }
 /**
  * Evaluates if auto creation of a version of a record is allowed.
  *
  * @param string $table Table of the record
  * @param integer $id UID of record
  * @param integer $recpid PID of record
  * @return boolean TRUE if ok.
  * @todo Define visibility
  */
 public function workspaceAllowAutoCreation($table, $id, $recpid)
 {
     // Auto-creation of version: In offline workspace, test if versioning is
     // enabled and look for workspace version of input record.
     // If there is no versionized record found we will create one and save to that.
     if ($this->workspace !== 0 && !$this->workspaceRec['disable_autocreate'] && $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] && $recpid >= 0 && !t3lib_BEfunc::getWorkspaceVersionOfRecord($this->workspace, $table, $id, 'uid')) {
         // There must be no existing version of this record in workspace.
         return TRUE;
     } elseif ($this->workspaceRec['disable_autocreate']) {
         t3lib_div::deprecationLog('Usage of disable_autocreate feature is deprecated since 4.5.');
     }
 }
Esempio n. 15
0
    /**
     * Rendering the quick-edit view.
     *
     * @return	void
     */
    function renderQuickEdit()
    {
        global $LANG, $BE_USER, $BACK_PATH;
        // Alternative template
        $this->doc->setModuleTemplate('templates/db_layout_quickedit.html');
        // Alternative form tag; Quick Edit submits its content to tce_db.php.
        $this->doc->form = '<form action="' . htmlspecialchars($BACK_PATH . 'tce_db.php?&prErr=1&uPT=1') . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '" name="editform" onsubmit="return TBE_EDITOR.checkSubmit(1);">';
        // Setting up the context sensitive menu:
        $this->doc->getContextMenuCode();
        // Set the edit_record value for internal use in this function:
        $edit_record = $this->edit_record;
        // If a command to edit all records in a column is issue, then select all those elements, and redirect to alt_doc.php:
        if (substr($edit_record, 0, 9) == '_EDIT_COL') {
            $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_content', 'pid=' . intval($this->id) . ' AND colPos=' . intval(substr($edit_record, 10)) . ' AND sys_language_uid=' . intval($this->current_sys_language) . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : t3lib_BEfunc::BEenableFields('tt_content')) . t3lib_BEfunc::deleteClause('tt_content') . t3lib_BEfunc::versioningPlaceholderClause('tt_content'), '', 'sorting');
            $idListA = array();
            while ($cRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                $idListA[] = $cRow['uid'];
            }
            $url = $BACK_PATH . 'alt_doc.php?edit[tt_content][' . implode(',', $idListA) . ']=edit&returnUrl=' . rawurlencode($this->local_linkThisScript(array('edit_record' => '')));
            t3lib_utility_Http::redirect($url);
        }
        // If the former record edited was the creation of a NEW record, this will look up the created records uid:
        if ($this->new_unique_uid) {
            $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_log', 'userid=' . intval($BE_USER->user['uid']) . ' AND NEWid=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->new_unique_uid, 'sys_log'));
            $sys_log_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
            if (is_array($sys_log_row)) {
                $edit_record = $sys_log_row['tablename'] . ':' . $sys_log_row['recuid'];
            }
        }
        // Creating the selector box, allowing the user to select which element to edit:
        $opt = array();
        $is_selected = 0;
        $languageOverlayRecord = '';
        if ($this->current_sys_language) {
            list($languageOverlayRecord) = t3lib_BEfunc::getRecordsByField('pages_language_overlay', 'pid', $this->id, 'AND sys_language_uid=' . intval($this->current_sys_language));
        }
        if (is_array($languageOverlayRecord)) {
            $inValue = 'pages_language_overlay:' . $languageOverlayRecord['uid'];
            $is_selected += intval($edit_record == $inValue);
            $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $LANG->getLL('editLanguageHeader', 1) . ' ]</option>';
        } else {
            $inValue = 'pages:' . $this->id;
            $is_selected += intval($edit_record == $inValue);
            $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $LANG->getLL('editPageProperties', 1) . ' ]</option>';
        }
        // Selecting all content elements from this language and allowed colPos:
        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_content', 'pid=' . intval($this->id) . ' AND sys_language_uid=' . intval($this->current_sys_language) . ' AND colPos IN (' . $this->colPosList . ')' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : t3lib_BEfunc::BEenableFields('tt_content')) . t3lib_Befunc::deleteClause('tt_content') . t3lib_BEfunc::versioningPlaceholderClause('tt_content'), '', 'colPos,sorting');
        $colPos = '';
        $first = 1;
        $prev = $this->id;
        // Page is the pid if no record to put this after.
        while ($cRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
            t3lib_BEfunc::workspaceOL('tt_content', $cRow);
            if (is_array($cRow)) {
                if ($first) {
                    if (!$edit_record) {
                        $edit_record = 'tt_content:' . $cRow['uid'];
                    }
                    $first = 0;
                }
                if (strcmp($cRow['colPos'], $colPos)) {
                    $colPos = $cRow['colPos'];
                    $opt[] = '<option value=""></option>';
                    $opt[] = '<option value="_EDIT_COL:' . $colPos . '">__' . $LANG->sL(t3lib_BEfunc::getLabelFromItemlist('tt_content', 'colPos', $colPos), 1) . ':__</option>';
                }
                $inValue = 'tt_content:' . $cRow['uid'];
                $is_selected += intval($edit_record == $inValue);
                $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>' . htmlspecialchars(t3lib_div::fixed_lgd_cs($cRow['header'] ? $cRow['header'] : '[' . $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.no_title') . '] ' . strip_tags($cRow['bodytext']), $BE_USER->uc['titleLen'])) . '</option>';
                $prev = -$cRow['uid'];
            }
        }
        // If edit_record is not set (meaning, no content elements was found for this language) we simply set it to create a new element:
        if (!$edit_record) {
            $edit_record = 'tt_content:new/' . $prev . '/' . $colPos;
            $inValue = 'tt_content:new/' . $prev . '/' . $colPos;
            $is_selected += intval($edit_record == $inValue);
            $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $LANG->getLL('newLabel', 1) . ' ]</option>';
        }
        // If none is yet selected...
        if (!$is_selected) {
            $opt[] = '<option value=""></option>';
            $opt[] = '<option value="' . $edit_record . '"  selected="selected">[ ' . $LANG->getLL('newLabel', 1) . ' ]</option>';
        }
        // Splitting the edit-record cmd value into table/uid:
        $this->eRParts = explode(':', $edit_record);
        // Delete-button flag?
        $this->deleteButton = t3lib_div::testInt($this->eRParts[1]) && $edit_record && ($this->eRParts[0] != 'pages' && $this->EDIT_CONTENT || $this->eRParts[0] == 'pages' && $this->CALC_PERMS & 4);
        // If undo-button should be rendered (depends on available items in sys_history)
        $this->undoButton = 0;
        $undoRes = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->eRParts[0], 'sys_history') . ' AND recuid=' . intval($this->eRParts[1]), '', 'tstamp DESC', '1');
        if ($this->undoButtonR = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($undoRes)) {
            $this->undoButton = 1;
        }
        // Setting up the Return URL for coming back to THIS script (if links take the user to another script)
        $R_URL_parts = parse_url(t3lib_div::getIndpEnv('REQUEST_URI'));
        $R_URL_getvars = t3lib_div::_GET();
        unset($R_URL_getvars['popView']);
        unset($R_URL_getvars['new_unique_uid']);
        $R_URL_getvars['edit_record'] = $edit_record;
        $this->R_URI = $R_URL_parts['path'] . '?' . t3lib_div::implodeArrayForUrl('', $R_URL_getvars);
        // Setting close url/return url for exiting this script:
        $this->closeUrl = $this->local_linkThisScript(array('SET' => array('function' => 1)));
        // Goes to 'Columns' view if close is pressed (default)
        if ($BE_USER->uc['condensedMode']) {
            $this->closeUrl = $BACK_PATH . 'alt_db_navframe.php';
        }
        if ($this->returnUrl) {
            $this->closeUrl = $this->returnUrl;
        }
        // Return-url for JavaScript:
        $retUrlStr = $this->returnUrl ? "+'&returnUrl='+'" . rawurlencode($this->returnUrl) . "'" : '';
        // Drawing the edit record selectbox
        $this->editSelect = '<select name="edit_record" onchange="' . htmlspecialchars('jumpToUrl(\'db_layout.php?id=' . $this->id . '&edit_record=\'+escape(this.options[this.selectedIndex].value)' . $retUrlStr . ',this);') . '">' . implode('', $opt) . '</select>';
        // Creating editing form:
        if ($BE_USER->check('tables_modify', $this->eRParts[0]) && $edit_record && ($this->eRParts[0] != 'pages' && $this->EDIT_CONTENT || $this->eRParts[0] == 'pages' && $this->CALC_PERMS & 1)) {
            // Splitting uid parts for special features, if new:
            list($uidVal, $ex_pid, $ex_colPos) = explode('/', $this->eRParts[1]);
            // Convert $uidVal to workspace version if any:
            if ($uidVal != 'new') {
                if ($draftRecord = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $this->eRParts[0], $uidVal, 'uid')) {
                    $uidVal = $draftRecord['uid'];
                }
            }
            // Initializing transfer-data object:
            $trData = t3lib_div::makeInstance('t3lib_transferData');
            $trData->addRawData = TRUE;
            $trData->defVals[$this->eRParts[0]] = array('colPos' => intval($ex_colPos), 'sys_language_uid' => intval($this->current_sys_language));
            $trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];
            $trData->lockRecords = 1;
            $trData->fetchRecord($this->eRParts[0], $uidVal == 'new' ? $this->id : $uidVal, $uidVal);
            // 'new'
            // Getting/Making the record:
            reset($trData->regTableItems_data);
            $rec = current($trData->regTableItems_data);
            if ($uidVal == 'new') {
                $new_unique_uid = uniqid('NEW');
                $rec['uid'] = $new_unique_uid;
                $rec['pid'] = intval($ex_pid) ? intval($ex_pid) : $this->id;
                $recordAccess = TRUE;
            } else {
                $rec['uid'] = $uidVal;
                // Checking internals access:
                $recordAccess = $BE_USER->recordEditAccessInternals($this->eRParts[0], $uidVal);
            }
            if (!$recordAccess) {
                // If no edit access, print error message:
                $content .= $this->doc->section($LANG->getLL('noAccess'), $LANG->getLL('noAccess_msg') . '<br /><br />' . ($BE_USER->errorMsg ? 'Reason: ' . $BE_USER->errorMsg . '<br /><br />' : ''), 0, 1);
            } elseif (is_array($rec)) {
                // If the record is an array (which it will always be... :-)
                // Create instance of TCEforms, setting defaults:
                $tceforms = t3lib_div::makeInstance('t3lib_TCEforms');
                $tceforms->backPath = $BACK_PATH;
                $tceforms->initDefaultBEMode();
                $tceforms->fieldOrder = $this->modTSconfig['properties']['tt_content.']['fieldOrder'];
                $tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes'];
                $tceforms->disableRTE = $this->MOD_SETTINGS['disableRTE'];
                $tceforms->enableClickMenu = TRUE;
                // Clipboard is initialized:
                $tceforms->clipObj = t3lib_div::makeInstance('t3lib_clipboard');
                // Start clipboard
                $tceforms->clipObj->initializeClipboard();
                // Initialize - reads the clipboard content from the user session
                if ($BE_USER->uc['edit_showFieldHelp'] != 'text' && $this->MOD_SETTINGS['showDescriptions']) {
                    $tceforms->edit_showFieldHelp = 'text';
                }
                // Render form, wrap it:
                $panel = '';
                $panel .= $tceforms->getMainFields($this->eRParts[0], $rec);
                $panel = $tceforms->wrapTotal($panel, $rec, $this->eRParts[0]);
                // Add hidden fields:
                $theCode = $panel;
                if ($uidVal == 'new') {
                    $theCode .= '<input type="hidden" name="data[' . $this->eRParts[0] . '][' . $rec['uid'] . '][pid]" value="' . $rec['pid'] . '" />';
                }
                $theCode .= '
					<input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
					<input type="hidden" name="_disableRTE" value="' . $tceforms->disableRTE . '" />
					<input type="hidden" name="edit_record" value="' . $edit_record . '" />
					<input type="hidden" name="redirect" value="' . htmlspecialchars($uidVal == 'new' ? t3lib_extMgm::extRelPath('cms') . 'layout/db_layout.php?id=' . $this->id . '&new_unique_uid=' . $new_unique_uid . '&returnUrl=' . rawurlencode($this->returnUrl) : $this->R_URI) . '" />
					' . t3lib_TCEforms::getHiddenTokenField('tceAction');
                // Add JavaScript as needed around the form:
                $theCode = $tceforms->printNeededJSFunctions_top() . $theCode . $tceforms->printNeededJSFunctions();
                // Add warning sign if record was "locked":
                if ($lockInfo = t3lib_BEfunc::isRecordLocked($this->eRParts[0], $rec['uid'])) {
                    $lockedMessage = t3lib_div::makeInstance('t3lib_FlashMessage', htmlspecialchars($lockInfo['msg']), '', t3lib_FlashMessage::WARNING);
                    t3lib_FlashMessageQueue::addMessage($lockedMessage);
                }
                // Add whole form as a document section:
                $content .= $this->doc->section('', $theCode);
            }
        } else {
            // If no edit access, print error message:
            $content .= $this->doc->section($LANG->getLL('noAccess'), $LANG->getLL('noAccess_msg') . '<br /><br />', 0, 1);
        }
        // Bottom controls (function menus):
        $q_count = $this->getNumberOfHiddenElements();
        $h_func_b = t3lib_BEfunc::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], 'db_layout.php', '', 'id="checkTt_content_showHidden"') . '<label for="checkTt_content_showHidden">' . (!$q_count ? $GLOBALS['TBE_TEMPLATE']->dfw($LANG->getLL('hiddenCE', 1)) : $LANG->getLL('hiddenCE', 1) . ' (' . $q_count . ')') . '</label>';
        $h_func_b .= '<br />' . t3lib_BEfunc::getFuncCheck($this->id, 'SET[showPalettes]', $this->MOD_SETTINGS['showPalettes'], 'db_layout.php', '', 'id="checkShowPalettes"') . '<label for="checkShowPalettes">' . $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.showPalettes', 1) . '</label>';
        if (t3lib_extMgm::isLoaded('context_help') && $BE_USER->uc['edit_showFieldHelp'] != 'text') {
            $h_func_b .= '<br />' . t3lib_BEfunc::getFuncCheck($this->id, 'SET[showDescriptions]', $this->MOD_SETTINGS['showDescriptions'], 'db_layout.php', '', 'id="checkShowDescriptions"') . '<label for="checkShowDescriptions">' . $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.showDescriptions', 1) . '</label>';
        }
        if ($BE_USER->isRTE()) {
            $h_func_b .= '<br />' . t3lib_BEfunc::getFuncCheck($this->id, 'SET[disableRTE]', $this->MOD_SETTINGS['disableRTE'], 'db_layout.php', '', 'id="checkDisableRTE"') . '<label for="checkDisableRTE">' . $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.disableRTE', 1) . '</label>';
        }
        // Add the function menus to bottom:
        $content .= $this->doc->section('', $h_func_b, 0, 0);
        $content .= $this->doc->spacer(10);
        // Select element matrix:
        if ($this->eRParts[0] == 'tt_content' && t3lib_div::testInt($this->eRParts[1])) {
            $posMap = t3lib_div::makeInstance('ext_posMap');
            $posMap->backPath = $BACK_PATH;
            $posMap->cur_sys_language = $this->current_sys_language;
            $HTMLcode = '';
            // CSH:
            $HTMLcode .= t3lib_BEfunc::cshItem($this->descrTable, 'quickEdit_selElement', $BACK_PATH, '|<br />');
            $HTMLcode .= $posMap->printContentElementColumns($this->id, $this->eRParts[1], $this->colPosList, $this->MOD_SETTINGS['tt_content_showHidden'], $this->R_URI);
            $content .= $this->doc->spacer(20);
            $content .= $this->doc->section($LANG->getLL('CEonThisPage'), $HTMLcode, 0, 1);
            $content .= $this->doc->spacer(20);
        }
        // Finally, if comments were generated in TCEforms object, print these as a HTML comment:
        if (count($tceforms->commentMessages)) {
            $content .= '
	<!-- TCEFORM messages
	' . htmlspecialchars(implode(LF, $tceforms->commentMessages)) . '
	-->
	';
        }
        return $content;
    }
 /**
  * Get a single record row for a TCA table from the database.
  * t3lib_transferData is used for "upgrading" the values, especially the relations.
  *
  * @param	integer		$pid: The pid of the page the record should be stored (only relevant for NEW records)
  * @param	string		$table: The table to fetch data from (= foreign_table)
  * @param	string		$uid: The uid of the record to fetch, or the pid if a new record should be created
  * @param	string		$cmd: The command to perform, empty or 'new'
  * @return	array		A record row from the database post-processed by t3lib_transferData
  */
 function getRecord($pid, $table, $uid, $cmd = '')
 {
     // Fetch workspace version of a record (if any):
     if ($cmd !== 'new' && $GLOBALS['BE_USER']->workspace !== 0) {
         $workspaceVersion = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $table, $uid, 'uid');
         if ($workspaceVersion !== FALSE) {
             $uid = $workspaceVersion['uid'];
         }
     }
     $trData = t3lib_div::makeInstance('t3lib_transferData');
     $trData->addRawData = TRUE;
     $trData->lockRecords = 1;
     $trData->disableRTE = $GLOBALS['SOBE']->MOD_SETTINGS['disableRTE'];
     // if a new record should be created
     $trData->fetchRecord($table, $uid, $cmd === 'new' ? 'new' : '');
     reset($trData->regTableItems_data);
     $rec = current($trData->regTableItems_data);
     return $rec;
 }