/** * Creates the editing form with TCEforms, based on the input from GPvars. * * @return string HTML form elements wrapped in tables */ function makeEditForm() { global $BE_USER, $LANG, $TCA; // Initialize variables: $this->elementsData = array(); $this->errorC = 0; $this->newC = 0; $thePrevUid = ''; $editForm = ''; $trData = NULL; // Traverse the GPvar edit array foreach ($this->editconf as $table => $conf) { // Tables: if (is_array($conf) && $TCA[$table] && $BE_USER->check('tables_modify', $table)) { // Traverse the keys/comments of each table (keys can be a commalist of uids) foreach ($conf as $cKey => $cmd) { if ($cmd == 'edit' || $cmd == 'new') { // Get the ids: $ids = t3lib_div::trimExplode(',', $cKey, 1); // Traverse the ids: foreach ($ids as $theUid) { // Checking if the user has permissions? (Only working as a precaution, because the final permission check is always down in TCE. But it's good to notify the user on beforehand...) // First, resetting flags. $hasAccess = 1; $deniedAccessReason = ''; $deleteAccess = 0; $this->viewId = 0; // If the command is to create a NEW record...: if ($cmd == 'new') { if (intval($theUid)) { // NOTICE: the id values in this case points to the page uid onto which the record should be create OR (if the id is negativ) to a record from the same table AFTER which to create the record. // Find parent page on which the new record reside if ($theUid < 0) { // Less than zero - find parent page $calcPRec = t3lib_BEfunc::getRecord($table, abs($theUid)); $calcPRec = t3lib_BEfunc::getRecord('pages', $calcPRec['pid']); } else { // always a page $calcPRec = t3lib_BEfunc::getRecord('pages', abs($theUid)); } // Now, calculate whether the user has access to creating new records on this position: if (is_array($calcPRec)) { $CALC_PERMS = $BE_USER->calcPerms($calcPRec); // Permissions for the parent page if ($table == 'pages') { // If pages: $hasAccess = $CALC_PERMS & 8 ? 1 : 0; #$this->viewId = $calcPRec['pid']; $this->viewId = 0; } else { $hasAccess = $CALC_PERMS & 16 ? 1 : 0; $this->viewId = $calcPRec['uid']; } } } $this->dontStoreDocumentRef = 1; // Don't save this document title in the document selector if the document is new. } else { // Edit: $calcPRec = t3lib_BEfunc::getRecord($table, $theUid); t3lib_BEfunc::fixVersioningPid($table, $calcPRec); if (is_array($calcPRec)) { if ($table == 'pages') { // If pages: $CALC_PERMS = $BE_USER->calcPerms($calcPRec); $hasAccess = $CALC_PERMS & 2 ? 1 : 0; $deleteAccess = $CALC_PERMS & 4 ? 1 : 0; $this->viewId = $calcPRec['uid']; } else { $CALC_PERMS = $BE_USER->calcPerms(t3lib_BEfunc::getRecord('pages', $calcPRec['pid'])); // Fetching pid-record first. $hasAccess = $CALC_PERMS & 16 ? 1 : 0; $deleteAccess = $CALC_PERMS & 16 ? 1 : 0; $this->viewId = $calcPRec['pid']; // Adding "&L=xx" if the record being edited has a languageField with a value larger than zero! if ($TCA[$table]['ctrl']['languageField'] && $calcPRec[$TCA[$table]['ctrl']['languageField']] > 0) { $this->viewId_addParams = '&L=' . $calcPRec[$TCA[$table]['ctrl']['languageField']]; } } // Check internals regarding access: if ($hasAccess) { $hasAccess = $BE_USER->recordEditAccessInternals($table, $calcPRec); $deniedAccessReason = $BE_USER->errorMsg; } } else { $hasAccess = 0; } } if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/alt_doc.php']['makeEditForm_accessCheck'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/alt_doc.php']['makeEditForm_accessCheck'] as $_funcRef) { $_params = array('table' => $table, 'uid' => $theUid, 'cmd' => $cmd, 'hasAccess' => $hasAccess); $hasAccess = t3lib_div::callUserFunction($_funcRef, $_params, $this); } } // AT THIS POINT we have checked the access status of the editing/creation of records and we can now proceed with creating the form elements: if ($hasAccess) { $prevPageID = is_object($trData) ? $trData->prevPageID : ''; $trData = t3lib_div::makeInstance('t3lib_transferData'); $trData->addRawData = TRUE; $trData->defVals = $this->defVals; $trData->lockRecords = 1; $trData->disableRTE = !$BE_USER->isRTE(); $trData->prevPageID = $prevPageID; $trData->fetchRecord($table, $theUid, $cmd == 'new' ? 'new' : ''); // 'new' reset($trData->regTableItems_data); $rec = current($trData->regTableItems_data); $rec['uid'] = $cmd == 'new' ? uniqid('NEW') : $theUid; if ($cmd == 'new') { $rec['pid'] = $theUid == 'prev' ? $thePrevUid : $theUid; } $this->elementsData[] = array('table' => $table, 'uid' => $rec['uid'], 'pid' => $rec['pid'], 'cmd' => $cmd, 'deleteAccess' => $deleteAccess); // Now, render the form: if (is_array($rec)) { // Setting visual path / title of form: $this->generalPathOfForm = $this->tceforms->getRecordPath($table, $rec); if (!$this->storeTitle) { $this->storeTitle = $this->recTitle ? htmlspecialchars($this->recTitle) : t3lib_BEfunc::getRecordTitle($table, $rec, TRUE); } // Setting variables in TCEforms object: $this->tceforms->hiddenFieldList = ''; $this->tceforms->globalShowHelp = $this->disHelp ? 0 : 1; if (is_array($this->overrideVals[$table])) { $this->tceforms->hiddenFieldListArr = array_keys($this->overrideVals[$table]); } // Register default language labels, if any: $this->tceforms->registerDefaultLanguageData($table, $rec); // Create form for the record (either specific list of fields or the whole record): $panel = ''; if ($this->columnsOnly) { if (is_array($this->columnsOnly)) { $panel .= $this->tceforms->getListedFields($table, $rec, $this->columnsOnly[$table]); } else { $panel .= $this->tceforms->getListedFields($table, $rec, $this->columnsOnly); } } else { $panel .= $this->tceforms->getMainFields($table, $rec); } $panel = $this->tceforms->wrapTotal($panel, $rec, $table); // Setting the pid value for new records: if ($cmd == 'new') { $panel .= '<input type="hidden" name="data[' . $table . '][' . $rec['uid'] . '][pid]" value="' . $rec['pid'] . '" />'; $this->newC++; } // Display "is-locked" message: if ($lockInfo = t3lib_BEfunc::isRecordLocked($table, $rec['uid'])) { $lockedMessage = t3lib_div::makeInstance('t3lib_FlashMessage', htmlspecialchars($lockInfo['msg']), '', t3lib_FlashMessage::WARNING); t3lib_FlashMessageQueue::addMessage($lockedMessage); } // Combine it all: $editForm .= $panel; } $thePrevUid = $rec['uid']; } else { $this->errorC++; $editForm .= $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.noEditPermission', 1) . '<br /><br />' . ($deniedAccessReason ? 'Reason: ' . htmlspecialchars($deniedAccessReason) . '<br /><br />' : ''); } } } } } } return $editForm; }
/** * Creates a form for new workspace. Parts are adopted from <code>alt_doc.php</code>. * * @return string Generated form */ function buildNewForm() { $content = ''; $table = 'sys_workspace'; $prevPageID = ''; $trData = t3lib_div::makeInstance('t3lib_transferData'); $trData->addRawData = TRUE; $trData->defVals = $this->defVals; $trData->lockRecords = 1; $trData->disableRTE = $this->MOD_SETTINGS['disableRTE']; $trData->prevPageID = $prevPageID; $trData->fetchRecord($table, 0, 'new'); reset($trData->regTableItems_data); $rec = current($trData->regTableItems_data); $rec['uid'] = uniqid('NEW'); $rec['pid'] = 0; $rec['adminusers'] = $this->getOwnerUser($rec['uid']); // Setting variables in TCEforms object: $this->tceforms->hiddenFieldList = ''; // Register default language labels, if any: $this->tceforms->registerDefaultLanguageData($table, $rec); $this->fixVariousTCAFields(); if (!$GLOBALS['BE_USER']->isAdmin()) { // Non-admins cannot select users from the root. We "fix" it for them. $this->fixTCAUserField('adminusers'); $this->fixTCAUserField('members'); $this->fixTCAUserField('reviewers'); } // Create form for the record (either specific list of fields or the whole record): $form = ''; $form .= $this->doc->spacer(5); $form .= $this->tceforms->getMainFields($table, $rec); $form .= '<input type="hidden" name="workspace_form_submited" value="1" />'; $form .= '<input type="hidden" name="data[' . $table . '][' . $rec['uid'] . '][pid]" value="' . $rec['pid'] . '" />'; $form .= '<input type="hidden" name="returnUrl" value="index.php" />'; $form .= '<input type="hidden" name="action" value="new" />'; $form .= '<input type="hidden" name="closeDoc" value="0" />'; $form .= '<input type="hidden" name="doSave" value="0" />'; $form .= '<input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />'; $form .= '<input type="hidden" name="_disableRTE" value="' . $this->tceforms->disableRTE . '" />'; $form = $this->tceforms->wrapTotal($form, $rec, $table); // Combine it all: $content .= $form; return $content; }
/** * Render the form-fields of a related (foreign) record. * * @param string $parentUid: The uid of the parent (embedding) record (uid or NEW...) * @param array $rec: The table record of the child/embedded table (normaly post-processed by t3lib_transferData) * @param array $config: content of $PA['fieldConf']['config'] * @return string The HTML code for this "foreign record" */ function renderForeignRecord($parentUid, $rec, $config = array()) { $foreign_table = $config['foreign_table']; $foreign_field = $config['foreign_field']; $foreign_selector = $config['foreign_selector']; // Register default localization content: $parent = $this->getStructureLevel(-1); if (isset($parent['localizationMode']) && $parent['localizationMode'] != false) { $this->fObj->registerDefaultLanguageData($foreign_table, $rec); } // Send a mapping information to the browser via JSON: // e.g. data[<curTable>][<curId>][<curField>] => data-<pid>-<parentTable>-<parentId>-<parentField>-<curTable>-<curId>-<curField> $this->inlineData['map'][$this->inlineNames['form']] = $this->inlineNames['object']; // Set this variable if we handle a brand new unsaved record: $isNewRecord = t3lib_div::testInt($rec['uid']) ? false : true; // Set this variable if the record is virtual and only show with header and not editable fields: $isVirtualRecord = isset($rec['__virtual']) && $rec['__virtual']; // If there is a selector field, normalize it: if ($foreign_selector) { $rec[$foreign_selector] = $this->normalizeUid($rec[$foreign_selector]); } if (!$this->checkAccess($isNewRecord ? 'new' : 'edit', $foreign_table, $rec['uid'])) { return false; } // Get the current naming scheme for DOM name/id attributes: $nameObject = $this->inlineNames['object']; $appendFormFieldNames = '[' . $foreign_table . '][' . $rec['uid'] . ']'; $objectId = $nameObject . self::Structure_Separator . $foreign_table . self::Structure_Separator . $rec['uid']; // Put the current level also to the dynNestedStack of TCEforms: $this->fObj->pushToDynNestedStack('inline', $objectId); if (!$isVirtualRecord) { // Get configuration: $collapseAll = isset($config['appearance']['collapseAll']) && $config['appearance']['collapseAll']; $ajaxLoad = isset($config['appearance']['ajaxLoad']) && !$config['appearance']['ajaxLoad'] ? false : true; if ($isNewRecord) { // show this record expanded or collapsed $isExpanded = !$collapseAll ? 1 : 0; } else { $isExpanded = $config['renderFieldsOnly'] || !$collapseAll && $this->getExpandedCollapsedState($foreign_table, $rec['uid']); } // Render full content ONLY IF this is a AJAX-request, a new record, the record is not collapsed or AJAX-loading is explicitly turned off if ($isNewRecord || $isExpanded || !$ajaxLoad) { $combination = $this->renderCombinationTable($rec, $appendFormFieldNames, $config); $fields = $this->renderMainFields($foreign_table, $rec); $fields = $this->wrapFormsSection($fields); // Replace returnUrl in Wizard-Code, if this is an AJAX call $ajaxArguments = t3lib_div::_GP('ajax'); if (isset($ajaxArguments[2]) && trim($ajaxArguments[2]) != '') { $fields = str_replace('P[returnUrl]=%2F' . rawurlencode(TYPO3_mainDir) . '%2Fajax.php', 'P[returnUrl]=' . rawurlencode($ajaxArguments[2]), $fields); } } else { $combination = ''; // This string is the marker for the JS-function to check if the full content has already been loaded $fields = '<!--notloaded-->'; } if ($isNewRecord) { // get the top parent table $top = $this->getStructureLevel(0); $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 { // 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 ($config['renderFieldsOnly']) { $out = $fields . $combination; } else { // set the record container with data for output $out = '<div class="t3-form-field-record-inline" id="' . $objectId . '_fields"' . $appearanceStyleFields . '>' . $fields . $combination . '</div>'; $header = $this->renderForeignRecordHeader($parentUid, $foreign_table, $rec, $config, $isVirtualRecord); $out = '<div class="t3-form-field-header-inline" id="' . $objectId . '_header">' . $header . '</div>' . $out; // wrap the header, fields and combination part of a child record with a div container $classMSIE = $this->fObj->clientInfo['BROWSER'] == 'msie' && $this->fObj->clientInfo['VERSION'] < 8 ? 'MSIE' : ''; $class = 'inlineDiv' . $classMSIE . ($isNewRecord ? ' inlineIsNewRecord' : ''); $out = '<div id="' . $objectId . '_div" class="t3-form-field-container-inline ' . $class . '">' . $out . '</div>'; } // Remove the current level also from the dynNestedStack of TCEforms: $this->fObj->popFromDynNestedStack(); return $out; }