/** * Get possible records. * Copied from TCEform and modified. * * @param string $table The table name of the record * @param string $field The field name which this element is supposed to edit * @param array $row The record data array where the value(s) for the field can be found * @param array $conf An array with additional configuration options. * @param string $checkForConfField For which field in the foreign_table the possible records should be fetched * @return mixed Array of possible record items; FALSE if type is "group/db", then everything could be "possible * @todo Define visibility */ public function getPossibleRecords($table, $field, $row, $conf, $checkForConfField = 'foreign_selector') { // ctrl configuration from TCA: $tcaTableCtrl = $GLOBALS['TCA'][$table]['ctrl']; // Field configuration from TCA: $foreign_table = $conf['foreign_table']; $foreign_check = $conf[$checkForConfField]; $foreignConfig = $this->getPossibleRecordsSelectorConfig($conf, $foreign_check); $PA = $foreignConfig['PA']; $config = $PA['fieldConf']['config']; if ($foreignConfig['type'] == 'select') { // Getting the selector box items from the system $selItems = $this->fObj->addSelectOptionsToItemArray($this->fObj->initItemArray($PA['fieldConf']), $PA['fieldConf'], $this->fObj->setTSconfig($table, $row), $field); // Possibly filter some items: $selItems = GeneralUtility::keepItemsInArray($selItems, $PA['fieldTSConfig']['keepItems'], function ($value) { return $value[1]; }); // Possibly add some items: $selItems = $this->fObj->addItems($selItems, $PA['fieldTSConfig']['addItems.']); if (isset($config['itemsProcFunc']) && $config['itemsProcFunc']) { $selItems = $this->fObj->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field); } // Possibly remove some items: $removeItems = GeneralUtility::trimExplode(',', $PA['fieldTSConfig']['removeItems'], TRUE); foreach ($selItems as $tk => $p) { // Checking languages and authMode: $languageDeny = $tcaTableCtrl['languageField'] && (string) $tcaTableCtrl['languageField'] === $field && !$GLOBALS['BE_USER']->checkLanguageAccess($p[1]); $authModeDeny = $config['form_type'] == 'select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table, $field, $p[1], $config['authMode']); if (in_array($p[1], $removeItems) || $languageDeny || $authModeDeny) { unset($selItems[$tk]); } elseif (isset($PA['fieldTSConfig']['altLabels.'][$p[1]])) { $selItems[$tk][0] = htmlspecialchars($this->fObj->sL($PA['fieldTSConfig']['altLabels.'][$p[1]])); } // Removing doktypes with no access: if (($table === 'pages' || $table === 'pages_language_overlay') && $field === 'doktype') { if (!($GLOBALS['BE_USER']->isAdmin() || GeneralUtility::inList($GLOBALS['BE_USER']->groupData['pagetypes_select'], $p[1]))) { unset($selItems[$tk]); } } } } else { $selItems = FALSE; } return $selItems; }
/** * Render Form Field in typo3 backend * @param array $PA * @param \TYPO3\CMS\Backend\Form\FormEngine $fob */ public function renderInput(array $PA, \TYPO3\CMS\Backend\Form\FormEngine $fob) { $content = file_get_contents(dirname(__FILE__) . '/../Resources/Private/Templates/formField.php'); $content = str_replace('###UID###', $PA['row']['uid'], $content); $content = str_replace('###TABLE###', $PA['table'], $content); $content = str_replace('###ID###', uniqid(), $content); $result = $this->getOverwriteprotectionRepository()->findByProtectedUidAndTableName($PA['row']['uid'], $PA['table']); $value = ''; $overwriteMode = ''; $conflictMode = ''; foreach ($result as $overwriteprotection) { /* @var $overwriteprotection Tx_AoeDbsequenzer_Domain_Model_Overwriteprotection */ $value = $overwriteprotection->getProtectedTime(); $value = date('H:i d-m-Y', $value); if ($overwriteprotection->getProtectedMode() === 0) { $conflictMode = 'selected="selected"'; } else { $overwriteMode = 'selected="selected"'; } } $content = str_replace('###VALUE###', $value, $content); $content = str_replace('###OVERWIRTE_MODE###', $overwriteMode, $content); $content = str_replace('###CONFLICT_MODE###', $conflictMode, $content); $content = str_replace('###LABEL_MODE###', $fob->sL('LLL:EXT:aoe_dbsequenzer/Resources/Private/Language/locallang_db.xml:protected_mode'), $content); $content = str_replace('###LABEL_MODE_CONFLICT###', $fob->sL('LLL:EXT:aoe_dbsequenzer/Resources/Private/Language/locallang_db.xml:mode_conflict'), $content); $content = str_replace('###LABEL_MODE_OVERWIRTE###', $fob->sL('LLL:EXT:aoe_dbsequenzer/Resources/Private/Language/locallang_db.xml:mode_overwrite'), $content); return $content; }
/** * Create a matrix of producible articles * * @param array $parameter Parameter * @param FormEngine $fObj Form engine * * @return string A HTML-table with checkboxes and all needed stuff */ public function producibleArticles(array $parameter, FormEngine $fObj) { $this->uid = (int) $parameter['row']['uid']; $this->pid = (int) $parameter['row']['pid']; // get existing articles for this product, if they where not fetched yet if ($this->existingArticles == NULL) { $this->existingArticles = $this->belib->getArticlesOfProduct($this->uid); } // get all attributes for this product, if they where not fetched yet if ($this->attributes == NULL) { $this->attributes = $this->belib->getAttributesForProduct($this->uid, TRUE, TRUE, TRUE); } $rowCount = $this->calculateRowCount(); if ($rowCount > 1000) { return sprintf($fObj->sL('LLL:EXT:commerce/Resources/Private/Language/locallang_db.xml:tx_commerce_products.to_many_articles'), $rowCount); } // create the headrow from the product attributes, select attributes without // valuelist and normal select attributes $colCount = 0; $headRow = $this->getHeadRow($colCount, array(' ')); $valueMatrix = (array) $this->getValues(); $counter = 0; $resultRows = ''; $resultRows .= $fObj->sL('LLL:EXT:commerce/Resources/Private/Language/locallang_db.xml:tx_commerce_products.create_warning'); $this->getRows($valueMatrix, $resultRows, $counter, $headRow); $emptyRow = '<tr><td><input type="checkbox" name="createList[empty]" /></td>'; $emptyRow .= '<td colspan="' . ($colCount - 1) . '">' . $fObj->sL('LLL:EXT:commerce/Resources/Private/Language/locallang_db.xml:tx_commerce_products.empty_article') . '</td></tr>'; // create a checkbox for selecting all articles $selectJs = '<script language="JavaScript"> function updateArticleList() { var sourceSB = document.getElementById("selectAllArticles"); for (var i = 1; i <= ' . $rowCount . '; i++) { document.getElementById("createRow_" +i).checked = sourceSB.checked; } } </script>'; $selectAllRow = ''; if (count($valueMatrix) > 0) { $selectAllRow = '<tr><td><input type="checkbox" id="selectAllArticles" onclick="updateArticleList()" /></td>'; $selectAllRow .= '<td colspan="' . ($colCount - 1) . '">' . $fObj->sL('LLL:EXT:commerce/Resources/Private/Language/locallang_db.xml:tx_commerce_products.select_all_articles') . '</td></tr>'; } $result = '<table border="0">' . $selectJs . $headRow . $emptyRow . $selectAllRow . $resultRows . '</table>'; return $result; }
/** * This will render a selector box element for selecting elements * of (category) trees. * Depending on the tree it display full trees or root elements only. * * @param array $parameter An array with additional configuration options. * @param FormEngine $fObj TCEForms object reference * * @return string The HTML code for the TCEform field */ public function getSingleField_selectCategories(array $parameter, FormEngine &$fObj) { $this->tceForms =& $parameter['pObj']; $table = $parameter['table']; $field = $parameter['field']; $row = $parameter['row']; $config = $parameter['fieldConf']['config']; $disabled = ''; if ($this->tceForms->renderReadonly || $config['readOnly']) { $disabled = ' disabled="disabled"'; } // @todo it seems TCE has a bug and do not work correctly with '1' $config['maxitems'] = $config['maxitems'] == 2 ? 1 : $config['maxitems']; // read the permissions we are restricting the tree to, depending on the table $perms = 'show'; switch ($table) { case 'tx_commerce_categories': $perms = 'new'; break; case 'tx_commerce_products': $perms = 'editcontent'; break; case 'tt_content': // fall through // fall through case 'be_groups': // fall through // fall through case 'be_users': $perms = 'show'; break; default: } /** * Category tree. * * @var \CommerceTeam\Commerce\Tree\CategoryTree $categoryTree */ $categoryTree = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Tree\\CategoryTree'); // disabled clickmenu $categoryTree->noClickmenu(); // set the minimum permissions $categoryTree->setMinCategoryPerms($perms); if ($config['allowProducts']) { $categoryTree->setBare(false); } if ($config['substituteRealValues']) { // @todo fix me $categoryTree->substituteRealValues(); } /* * Disallows clicks on certain leafs * Values is a comma-separated list of leaf names * (e.g. \CommerceTeam\Commerce\Tree\Leaf\Category) */ $categoryTree->disallowClick($config['disallowClick']); $categoryTree->init(); /** * Browse tree. * * @var \CommerceTeam\Commerce\ViewHelpers\TreelibTceforms $renderBrowseTrees */ $renderBrowseTrees = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\ViewHelpers\\TreelibTceforms'); $renderBrowseTrees->init($parameter); // Render the tree $renderBrowseTrees->renderBrowsableMountTrees($categoryTree); $thumbnails = ''; if (!$disabled) { // tree frame <div> $thumbnails = $renderBrowseTrees->renderDivBox(); } // get selected processed items - depending on the table we want to insert // into (tx_commerce_products, tx_commerce_categories, be_users) // if row['uid'] is defined and is an int we do display an existing record // otherwise it's a new record, so get default values $itemArray = array(); if ((int) $row['uid']) { // existing Record switch ($table) { case 'tx_commerce_categories': $itemArray = $renderBrowseTrees->processItemArrayForBrowseableTreePCategory($categoryTree, $row['uid']); break; case 'tx_commerce_products': $itemArray = $renderBrowseTrees->processItemArrayForBrowseableTreeProduct($categoryTree, $row['uid']); break; case 'be_users': $itemArray = $renderBrowseTrees->processItemArrayForBrowseableTree($categoryTree, $row['uid']); break; case 'be_groups': $itemArray = $renderBrowseTrees->processItemArrayForBrowseableTreeGroups($categoryTree, $row['uid']); break; case 'tt_content': // Perform modification of the selected items array: $itemArray = GeneralUtility::trimExplode(',', $parameter['itemFormElValue'], 1); $itemArray = $renderBrowseTrees->processItemArrayForBrowseableTreeCategory($categoryTree, $itemArray[0]); break; default: $itemArray = $renderBrowseTrees->processItemArrayForBrowseableTreeDefault($parameter['itemFormElValue']); } } else { // New record $defVals = GeneralUtility::_GP('defVals'); switch ($table) { case 'tx_commerce_categories': /** * Category. * * @var \CommerceTeam\Commerce\Domain\Model\Category $category */ $category = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Model\\Category', $defVals['tx_commerce_categories']['parent_category']); $category->loadData(); $itemArray = array($category->getUid() . '|' . $category->getTitle()); break; case 'tx_commerce_products': /** * Category. * * @var \CommerceTeam\Commerce\Domain\Model\Category $category */ $category = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Model\\Category', $defVals['tx_commerce_products']['categories']); $category->loadData(); if ($category->getUid() > 0) { $itemArray = array($category->getUid() . '|' . $category->getTitle()); } break; default: } } // process selected values // Creating the label for the "No Matching Value" entry. $noMatchingValueLabel = isset($parameter['fieldTSConfig']['noMatchingValue_label']) ? $this->tceForms->sL($parameter['fieldTSConfig']['noMatchingValue_label']) : '[ ' . $this->tceForms->getLL('l_noMatchingValue') . ' ]'; $noMatchingValueLabel = @sprintf($noMatchingValueLabel, $parameter['itemFormElValue']); // Possibly remove some items: $removeItems = GeneralUtility::trimExplode(',', $parameter['fieldTSConfig']['removeItems'], true); foreach ($itemArray as $tk => $tv) { $tvP = explode('|', $tv, 2); if (in_array($tvP[0], $removeItems) && !$parameter['fieldTSConfig']['disableNoMatchingValueElement']) { $tvP[1] = rawurlencode($noMatchingValueLabel); } elseif (isset($parameter['fieldTSConfig']['altLabels.'][$tvP[0]])) { $tvP[1] = rawurlencode($this->tceForms->sL($parameter['fieldTSConfig']['altLabels.'][$tvP[0]])); } $itemArray[$tk] = implode('|', $tvP); } // Rendering and output $minitems = max($config['minitems'], 0); $maxitems = max($config['maxitems'], 0); if (!$maxitems) { $maxitems = 100000; } $this->tceForms->requiredElements[$parameter['itemFormElName']] = array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field); $item = '<input type="hidden" name="' . $parameter['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '"' . $disabled . ' />'; $params = array('size' => $config['size'], 'autoSizeMax' => \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($config['autoSizeMax'], 0), 'style' => ' style="width:200px;"', 'dontShowMoveIcons' => $maxitems <= 1, 'maxitems' => $maxitems, 'info' => '', 'headers' => array('selector' => $this->tceForms->getLL('l_selected') . ':<br />', 'items' => $disabled ? '' : $this->tceForms->getLL('l_items') . ':<br />'), 'noBrowser' => true, 'readOnly' => $disabled, 'thumbnails' => $thumbnails); $item .= ' <style type="text/css"> .x-tree-root-ct ul { padding: 0 0 0 19px; margin: 0; } .x-tree-root-ct { padding-left: 0; } tr:hover .x-tree-root-ct a { text-decoration: none; } .x-tree-root-ct li { list-style: none; margin: 0; padding: 0; } .x-tree-root-ct ul li.expanded ul { background: url("' . $this->tceForms->backPath . 'sysext/t3skin/icons/gfx/ol/line.gif") repeat-y scroll left top transparent; } .x-tree-root-ct ul li.expanded.last ul { background: none; } .x-tree-root-ct li { clear: left; margin-bottom: 0; } </style> '; $item .= $this->tceForms->dbFileIcons($parameter['itemFormElName'], $config['internal_type'], $config['allowed'], $itemArray, '', $params, $parameter['onFocus']); // Wizards: if (!$disabled) { $specConf = $this->tceForms->getSpecConfFromString($parameter['extra'], $parameter['fieldConf']['defaultExtras']); $altItem = '<input type="hidden" name="' . $parameter['itemFormElName'] . '" value="' . htmlspecialchars($parameter['itemFormElValue']) . '" />'; $item = $this->tceForms->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $parameter, $parameter['itemFormElName'], $specConf); } return $item; }
/** * This will render a selector box element for selecting elements * of (category) trees. * Depending on the tree it display full trees or root elements only * * @param array $parameter An array with additional configuration options. * @param FormEngine $fObj TCEForms object reference * * @return string The HTML code for the TCEform field */ public function getSingleField_selectCategories(array $parameter, FormEngine &$fObj) { $this->tceForms =& $parameter['pObj']; $table = $parameter['table']; $field = $parameter['field']; $row = $parameter['row']; $config = $parameter['fieldConf']['config']; $disabled = ''; if ($this->tceForms->renderReadonly || $config['readOnly']) { $disabled = ' disabled="disabled"'; } // @todo it seems TCE has a bug and do not work correctly with '1' $config['maxitems'] = $config['maxitems'] == 2 ? 1 : $config['maxitems']; // read the permissions we are restricting the tree to, depending on the table $perms = 'show'; switch ($table) { case 'tx_commerce_categories': $perms = 'new'; break; case 'tx_commerce_products': $perms = 'editcontent'; break; case 'tt_content': // fall through // fall through case 'be_groups': // fall through // fall through case 'be_users': $perms = 'show'; break; default: } /** * Category tree * * @var Tx_Commerce_Tree_CategoryTree $browseTrees */ $browseTrees = GeneralUtility::makeInstance('Tx_Commerce_Tree_CategoryTree'); // disabled clickmenu $browseTrees->noClickmenu(); // set the minimum permissions $browseTrees->setMinCategoryPerms($perms); if ($config['allowProducts']) { $browseTrees->setBare(FALSE); } if ($config['substituteRealValues']) { $browseTrees->substituteRealValues(); } /** * Disallows clicks on certain leafs * Values is a comma-separated list of leaf names * (e.g. Tx_Commerce_Tree_Leaf_Category) */ $browseTrees->disallowClick($config['disallowClick']); $browseTrees->init(); /** * Browse tree * * @var Tx_Commerce_ViewHelpers_TreelibTceforms $renderBrowseTrees */ $renderBrowseTrees = GeneralUtility::makeInstance('Tx_Commerce_ViewHelpers_TreelibTceforms'); $renderBrowseTrees->init($parameter); $renderBrowseTrees->setIframeTreeBrowserScript($this->tceForms->backPath . PATH_TXCOMMERCE_REL . 'Classes/ViewHelpers/IframeTreeBrowser.php'); // Render the tree $renderBrowseTrees->renderBrowsableMountTrees($browseTrees); $thumbnails = ''; if (!$disabled) { // @todo remove iframe part. only div rendering is sufficent enough if ($renderBrowseTrees->isIframeContentRendering()) { // just the trees are needed - we're inside of an iframe! return $renderBrowseTrees->getTreeContent(); } elseif ($renderBrowseTrees->isIframeRendering()) { // If we want to display a browseable tree, we need to run the tree in an iframe // element. In the logic of tceforms the iframe is displayed in the "thumbnails" // position. In consequence this means that the current function is both // responsible for displaying the iframe // and displaying the tree. It will be called twice then. Once from alt_doc.php // and from dam/mod_treebrowser/index.php // Within this if-condition the iframe is written // The source of the iframe is dam/mod_treebrowser/index.php which will be // called with the current _GET variables. In the configuration of the TCA // treeViewBrowseable is set to TRUE. The value 'iframeContent' for // treeViewBrowseable will be set in dam/mod_treebrowser/index.php as // internal configuration logic $thumbnails = $renderBrowseTrees->renderIframe(); } else { // tree frame <div> $thumbnails = $renderBrowseTrees->renderDivBox(); } } // get selected processed items - depending on the table we want to insert // into (tx_commerce_products, tx_commerce_categories, be_users) // if row['uid'] is defined and is an int we do display an existing record // otherwise it's a new record, so get default values $itemArray = array(); if ((int) $row['uid']) { // existing Record switch ($table) { case 'tx_commerce_categories': $itemArray = $renderBrowseTrees->processItemArrayForBrowseableTreePCategory($browseTrees, $row['uid']); break; case 'tx_commerce_products': $itemArray = $renderBrowseTrees->processItemArrayForBrowseableTreeProduct($browseTrees, $row['uid']); break; case 'be_users': $itemArray = $renderBrowseTrees->processItemArrayForBrowseableTree($browseTrees, $row['uid']); break; case 'be_groups': $itemArray = $renderBrowseTrees->processItemArrayForBrowseableTreeGroups($browseTrees, $row['uid']); break; case 'tt_content': // Perform modification of the selected items array: $itemArray = GeneralUtility::trimExplode(',', $parameter['itemFormElValue'], 1); $itemArray = $renderBrowseTrees->processItemArrayForBrowseableTreeCategory($browseTrees, $itemArray[0]); break; default: $itemArray = $renderBrowseTrees->processItemArrayForBrowseableTreeDefault($parameter['itemFormElValue']); } } else { // New record $defVals = GeneralUtility::_GP('defVals'); switch ($table) { case 'tx_commerce_categories': /** * Category * * @var Tx_Commerce_Domain_Model_Category $category */ $category = GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Category', $defVals['tx_commerce_categories']['parent_category']); $category->loadData(); $itemArray = array($category->getUid() . '|' . $category->getTitle()); break; case 'tx_commerce_products': /** * Category * * @var Tx_Commerce_Domain_Model_Category $category */ $category = GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Category', $defVals['tx_commerce_products']['categories']); $category->loadData(); $itemArray = array($category->getUid() . '|' . $category->getTitle()); break; default: } } // process selected values // Creating the label for the "No Matching Value" entry. $noMatchingValueLabel = isset($parameter['fieldTSConfig']['noMatchingValue_label']) ? $this->tceForms->sL($parameter['fieldTSConfig']['noMatchingValue_label']) : '[ ' . $this->tceForms->getLL('l_noMatchingValue') . ' ]'; $noMatchingValueLabel = @sprintf($noMatchingValueLabel, $parameter['itemFormElValue']); // Possibly remove some items: $removeItems = GeneralUtility::trimExplode(',', $parameter['fieldTSConfig']['removeItems'], TRUE); foreach ($itemArray as $tk => $tv) { $tvP = explode('|', $tv, 2); if (in_array($tvP[0], $removeItems) && !$parameter['fieldTSConfig']['disableNoMatchingValueElement']) { $tvP[1] = rawurlencode($noMatchingValueLabel); } elseif (isset($parameter['fieldTSConfig']['altLabels.'][$tvP[0]])) { $tvP[1] = rawurlencode($this->tceForms->sL($parameter['fieldTSConfig']['altLabels.'][$tvP[0]])); } $itemArray[$tk] = implode('|', $tvP); } // Rendering and output $minitems = max($config['minitems'], 0); $maxitems = max($config['maxitems'], 0); if (!$maxitems) { $maxitems = 100000; } $this->tceForms->requiredElements[$parameter['itemFormElName']] = array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field); $item = '<input type="hidden" name="' . $parameter['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '"' . $disabled . ' />'; $params = array('size' => $config['size'], 'autoSizeMax' => \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($config['autoSizeMax'], 0), 'style' => ' style="width:200px;"', 'dontShowMoveIcons' => $maxitems <= 1, 'maxitems' => $maxitems, 'info' => '', 'headers' => array('selector' => $this->tceForms->getLL('l_selected') . ':<br />', 'items' => $disabled ? '' : $this->tceForms->getLL('l_items') . ':<br />'), 'noBrowser' => TRUE, 'readOnly' => $disabled, 'thumbnails' => $thumbnails); $item .= ' <style type="text/css"> .x-tree-root-ct ul { padding: 0 0 0 19px; margin: 0; } .x-tree-root-ct { padding-left: 0; } tr:hover .x-tree-root-ct a { text-decoration: none; } .x-tree-root-ct li { list-style: none; margin: 0; padding: 0; } .x-tree-root-ct ul li.expanded ul { background: url("/' . TYPO3_mainDir . '/sysext/t3skin/icons/gfx/ol/line.gif") repeat-y scroll left top transparent; } .x-tree-root-ct ul li.expanded.last ul { background: none; } .x-tree-root-ct li { clear: left; margin-bottom: 0; } </style> '; $item .= $this->tceForms->dbFileIcons($parameter['itemFormElName'], $config['internal_type'], $config['allowed'], $itemArray, '', $params, $parameter['onFocus']); // Wizards: if (!$disabled) { $specConf = $this->tceForms->getSpecConfFromString($parameter['extra'], $parameter['fieldConf']['defaultExtras']); $altItem = '<input type="hidden" name="' . $parameter['itemFormElName'] . '" value="' . htmlspecialchars($parameter['itemFormElValue']) . '" />'; $item = $this->tceForms->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $parameter, $parameter['itemFormElName'], $specConf); } return $item; }