/** * Action to create a new BE user * * @param array $record sys_action record * @return string form to create a new user */ protected function viewNewBackendUser($record) { $content = ''; $beRec = BackendUtility::getRecord('be_users', (int) $record['t1_copy_of_user']); // A record is need which is used as copy for the new user if (!is_array($beRec)) { $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('action_notReady', TRUE), $GLOBALS['LANG']->getLL('action_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR); $content .= $flashMessage->render(); return $content; } $vars = GeneralUtility::_POST('data'); $key = 'NEW'; if ($vars['sent'] == 1) { $errors = array(); // Basic error checks if (!empty($vars['email']) && !GeneralUtility::validEmail($vars['email'])) { $errors[] = $GLOBALS['LANG']->getLL('error-wrong-email'); } if (empty($vars['username'])) { $errors[] = $GLOBALS['LANG']->getLL('error-username-empty'); } if ($vars['key'] === 'NEW' && empty($vars['password'])) { $errors[] = $GLOBALS['LANG']->getLL('error-password-empty'); } if ($vars['key'] !== 'NEW' && !$this->isCreatedByUser($vars['key'], $record)) { $errors[] = $GLOBALS['LANG']->getLL('error-wrong-user'); } foreach ($this->hookObjects as $hookObject) { if (method_exists($hookObject, 'viewNewBackendUser_Error')) { $errors = $hookObject->viewNewBackendUser_Error($vars, $errors, $this); } } // Show errors if there are any if (count($errors) > 0) { $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', implode('<br />', $errors), $GLOBALS['LANG']->getLL('action_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR); $content .= $flashMessage->render() . '<br />'; } else { // Save user $key = $this->saveNewBackendUser($record, $vars); // Success message $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $vars['key'] === 'NEW' ? $GLOBALS['LANG']->getLL('success-user-created') : $GLOBALS['LANG']->getLL('success-user-updated'), $GLOBALS['LANG']->getLL('success'), \TYPO3\CMS\Core\Messaging\FlashMessage::OK); $content .= $flashMessage->render() . '<br />'; } } // Load BE user to edit if ((int) GeneralUtility::_GP('be_users_uid') > 0) { $tmpUserId = (int) GeneralUtility::_GP('be_users_uid'); // Check if the selected user is created by the current user $rawRecord = $this->isCreatedByUser($tmpUserId, $record); if ($rawRecord) { // Delete user if (GeneralUtility::_GP('delete') == 1) { $this->deleteUser($tmpUserId, $record['uid']); } $key = $tmpUserId; $vars = $rawRecord; } } $this->JScode(); $loadDB = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\RelationHandler'); $loadDB->start($vars['db_mountpoints'], 'pages'); $this->t3lib_TCEforms->printNeededJSFunctions(); $content .= '<form action="" method="post" enctype="multipart/form-data" name="' . $this->t3lib_TCEforms->formName . '"> <fieldset class="fields"> <legend>' . $GLOBALS['LANG']->getLL('action_t1_legend_generalFields') . '</legend> <div class="row"> <label for="field_disable">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.disable') . '</label> <input type="checkbox" id="field_disable" name="data[disable]" value="1" class="checkbox" ' . ($vars['disable'] == 1 ? ' checked="checked" ' : '') . ' /> </div> <div class="row"> <label for="field_realname">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.name') . '</label> <input type="text" id="field_realname" name="data[realName]" value="' . htmlspecialchars($vars['realName']) . '" /> </div> <div class="row"> <label for="field_username">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tca.xlf:be_users.username') . '</label> <input type="text" id="field_username" name="data[username]" value="' . htmlspecialchars($vars['username']) . '" /> </div> <div class="row"> <label for="field_password">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tca.xlf:be_users.password') . '</label> <input type="password" id="field_password" name="data[password]" value="" /> </div> <div class="row"> <label for="field_email">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.email') . '</label> <input type="text" id="field_email" name="data[email]" value="' . htmlspecialchars($vars['email']) . '" /> </div> </fieldset> <fieldset class="fields"> <legend>' . $GLOBALS['LANG']->getLL('action_t1_legend_configuration') . '</legend> <div class="row"> <label for="field_usergroup">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tca.xlf:be_users.usergroup') . '</label> <select id="field_usergroup" name="data[usergroup][]" multiple="multiple"> ' . $this->getUsergroups($record, $vars) . ' </select> </div> <div class="row"> <label for="field_db_mountpoints">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tca.xlf:be_users.options_db_mounts') . '</label> ' . $this->t3lib_TCEforms->dbFileIcons('data[db_mountpoints]', 'db', 'pages', $loadDB->itemArray, '', array('size' => 3)) . ' </div> <div class="row"> <input type="hidden" name="data[key]" value="' . $key . '" /> <input type="hidden" name="data[sent]" value="1" /> <input type="submit" value="' . ($key === 'NEW' ? $GLOBALS['LANG']->getLL('action_Create') : $GLOBALS['LANG']->getLL('action_Update')) . '" /> </div> </fieldset> </form>'; $content .= $this->getCreatedUsers($record, $key); return $content; }
/** * 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; }