예제 #1
0
 /**
  * Changes the clickmenu Items for the Commerce Records
  *
  * @param ClickMenu $clickMenu Clickenu object
  * @param array $menuItems Current menu Items
  * @param string $table Table
  * @param int $uid Uid
  *
  * @return array Menu Items Array
  */
 public function main(ClickMenu &$clickMenu, array $menuItems, $table, $uid)
 {
     // Only modify the menu Items if we have the correct table
     if (!in_array($table, $this->commerceTables)) {
         return $menuItems;
     }
     $backendUser = $this->getBackendUser();
     // Check for List allow
     if (!$backendUser->check('tables_select', $table)) {
         if (TYPO3_DLOG) {
             GeneralUtility::devLog('Clickmenu not allowed for user.', COMMERCE_EXTKEY, 1);
         }
         return '';
     }
     // Configure the parent clickmenu
     $this->clickMenu = $clickMenu;
     $this->ajax = $this->clickMenu->ajax;
     $this->listFrame = $this->clickMenu->listFrame;
     $this->alwaysContentFrame = $this->clickMenu->alwaysContentFrame;
     $this->clipObj = $this->clickMenu->clipObj;
     $this->disabledItems = $this->clickMenu->disabledItems;
     $this->clickMenu->backPath = $this->backPath;
     $this->additionalParameter = GeneralUtility::explodeUrl2Array(urldecode(GeneralUtility::_GET('addParams')));
     $this->newWizardAddParams = '&parentCategory=' . $this->additionalParameter['parentCategory'];
     $this->rec = BackendUtility::getRecordWSOL($table, $this->additionalParameter['control[' . $table . '][uid]']);
     // Initialize the rights-variables
     $rights = array('delete' => FALSE, 'edit' => FALSE, 'new' => FALSE, 'editLock' => FALSE, 'DBmount' => FALSE, 'copy' => FALSE, 'paste' => FALSE, 'overwrite' => FALSE, 'version' => FALSE, 'review' => FALSE, 'l10nOverlay' => FALSE, 'root' => 0, 'copyType' => 'after');
     // used to hide cut,copy icons for l10n-records
     // should only be performed for overlay-records within the same table
     if (BackendUtility::isTableLocalizable($table) && !isset($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable'])) {
         $rights['l10nOverlay'] = intval($this->rec[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']]) != 0;
     }
     // get rights based on the table
     switch ($table) {
         case 'tx_commerce_categories':
             $rights = $this->calculateCategoryRights($this->rec['uid'], $rights);
             break;
         case 'tx_commerce_products':
             $rights = $this->calculateProductRights($this->rec['uid'], $rights);
             break;
         case 'tx_commerce_articles':
             $rights = $this->calculateArticleRights($this->rec['uid'], $rights);
             break;
         default:
     }
     $menuItems = array();
     // If record found, go ahead and fill the $menuItems array which will contain
     // data for the elements to render.
     if (is_array($this->rec)) {
         // Edit:
         if (!$rights['root'] && !$rights['editLock'] && $rights['edit']) {
             if (!in_array('hide', $this->disabledItems) && is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']) && $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']) {
                 $menuItems['hide'] = $this->DB_hideUnhide($table, $this->rec, $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']);
             }
             if (!in_array('edit', $this->disabledItems)) {
                 $menuItems['edit'] = $this->DB_edit($table, $uid);
             }
             $this->clickMenu->editOK = 1;
         }
         // fix: always give the UID of the products page to create any commerce object
         if (!in_array('new', $this->disabledItems) && $rights['new']) {
             $menuItems['new'] = $this->DB_new($table, $uid);
         }
         // Info:
         if (!in_array('info', $this->disabledItems) && !$rights['root']) {
             $menuItems['info'] = $this->DB_info($table, $uid);
         }
         $menuItems['spacer1'] = 'spacer';
         // Cut not included
         // Copy:
         if (!in_array('copy', $this->disabledItems) && !$rights['root'] && !$rights['DBmount'] && !$rights['l10nOverlay'] && $rights['copy']) {
             $clipboardUid = $uid;
             if ($this->additionalParameter['category']) {
                 $clipboardUid .= '|' . $this->additionalParameter['category'];
             }
             $menuItems['copy'] = $this->DB_copycut($table, $clipboardUid, 'copy');
         }
         // Cut:
         if (!in_array('cut', $this->disabledItems) && !$rights['root'] && !$rights['DBmount'] && !$rights['l10nOverlay'] && $rights['copy']) {
             $menuItems['cut'] = $this->DB_copycut($table, $uid, 'cut');
         }
         // Paste
         $elFromAllTables = count($this->clickMenu->clipObj->elFromTable(''));
         if (!in_array('paste', $this->disabledItems) && $elFromAllTables && $rights['paste']) {
             $selItem = $this->clipObj->getSelectedRecord();
             $elInfo = array(GeneralUtility::fixed_lgd_cs($selItem['_RECORD_TITLE'], $backendUser->uc['titleLen']), $rights['root'] ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] : GeneralUtility::fixed_lgd_cs(BackendUtility::getRecordTitle($table, $this->rec), $backendUser->uc['titleLen']), $this->clipObj->currentMode());
             $pasteUid = $uid;
             if ($this->additionalParameter['category']) {
                 $pasteUid .= '|' . $this->additionalParameter['category'];
             }
             $elFromTable = count($this->clipObj->elFromTable($table));
             if ($table == 'tx_commerce_products' && $rights['overwrite'] && $elFromTable) {
                 // overwrite product with product
                 $menuItems['overwrite'] = $this->DB_overwrite($table, $pasteUid, $elInfo);
             }
             if ($table == 'tx_commerce_categories') {
                 $pasteIntoUid = $this->rec['pid'];
                 if ($this->additionalParameter['category']) {
                     $pasteIntoUid .= '|' . $this->additionalParameter['category'];
                 }
                 if ($elFromAllTables) {
                     $menuItems['pasteinto'] = $this->DB_paste('', $pasteIntoUid, 'into', $elInfo);
                 }
             }
             if (!$rights['root'] && !$rights['DBmount'] && $elFromTable && $GLOBALS['TCA'][$table]['ctrl']['sortby']) {
                 $menuItems['pasteafter'] = $this->DB_paste($table, '-' . $pasteUid, 'after', $elInfo);
             }
         }
         // Delete:
         $elInfo = array(GeneralUtility::fixed_lgd_cs(BackendUtility::getRecordTitle($table, $this->rec), $backendUser->uc['titleLen']));
         if (!$rights['editLock'] && !in_array('delete', $this->disabledItems) && !$rights['root'] && !$rights['DBmount'] && $rights['delete']) {
             $menuItems['spacer2'] = 'spacer';
             $menuItems['delete'] = $this->DB_delete($table, $uid, $elInfo);
         }
         if (!in_array('history', $this->disabledItems)) {
             $menuItems['history'] = $this->DB_history($table, $uid);
         }
     } else {
         // if no item was found we clicked the top most node
         if (!in_array('new', $this->disabledItems) && $rights['new']) {
             $menuItems = array();
             $menuItems['new'] = $this->DB_new($table, $uid);
         }
     }
     return $menuItems;
 }