/**
     * Prints the selector box form-field for the db/file/select elements (multiple)
     *
     * @param	string		Form element name
     * @param	string		Mode "db", "file" (internal_type for the "group" type) OR blank (then for the "select" type)
     * @param	string		Commalist of "allowed"
     * @param	array		The array of items. For "select" and "group"/"file" this is just a set of value. For "db" its an array of arrays with table/uid pairs.
     * @param	string		Alternative selector box.
     * @param	array		An array of additional parameters, eg: "size", "info", "headers" (array with "selector" and "items"), "noBrowser", "thumbnails"
     * @param	string		On focus attribute string
     * @param	string		$table: (optional) Table name processing for
     * @param	string		$field: (optional) Field of table name processing for
     * @param	string		$uid:	(optional) uid of table record processing for
     * @return	string		The form fields for the selection.
     */
    function dbFileIcons($fName, $mode, $allowed, $itemArray, $selector = '', $params = array(), $onFocus = '', $table = '', $field = '', $uid = '')
    {
        $disabled = '';
        if ($this->renderReadonly || $params['readOnly']) {
            $disabled = ' disabled="disabled"';
        }
        // Sets a flag which means some JavaScript is included on the page to support this element.
        $this->printNeededJS['dbFileIcons'] = 1;
        // INIT
        $uidList = array();
        $opt = array();
        $itemArrayC = 0;
        // Creating <option> elements:
        if (is_array($itemArray)) {
            $itemArrayC = count($itemArray);
            switch ($mode) {
                case 'db':
                    foreach ($itemArray as $pp) {
                        $pRec = t3lib_BEfunc::getRecordWSOL($pp['table'], $pp['id']);
                        if (is_array($pRec)) {
                            $pTitle = t3lib_BEfunc::getRecordTitle($pp['table'], $pRec, FALSE, TRUE);
                            $pUid = $pp['table'] . '_' . $pp['id'];
                            $uidList[] = $pUid;
                            $opt[] = '<option value="' . htmlspecialchars($pUid) . '">' . htmlspecialchars($pTitle) . '</option>';
                        }
                    }
                    break;
                case 'file_reference':
                case 'file':
                    foreach ($itemArray as $item) {
                        $itemParts = explode('|', $item);
                        $uidList[] = $pUid = $pTitle = $itemParts[0];
                        $opt[] = '<option value="' . htmlspecialchars(rawurldecode($itemParts[0])) . '">' . htmlspecialchars(basename(rawurldecode($itemParts[0]))) . '</option>';
                    }
                    break;
                case 'folder':
                    foreach ($itemArray as $pp) {
                        $pParts = explode('|', $pp);
                        $uidList[] = $pUid = $pTitle = $pParts[0];
                        $opt[] = '<option value="' . htmlspecialchars(rawurldecode($pParts[0])) . '">' . htmlspecialchars(rawurldecode($pParts[0])) . '</option>';
                    }
                    break;
                default:
                    foreach ($itemArray as $pp) {
                        $pParts = explode('|', $pp, 2);
                        $uidList[] = $pUid = $pParts[0];
                        $pTitle = $pParts[1];
                        $opt[] = '<option value="' . htmlspecialchars(rawurldecode($pUid)) . '">' . htmlspecialchars(rawurldecode($pTitle)) . '</option>';
                    }
                    break;
            }
        }
        // Create selector box of the options
        $sSize = $params['autoSizeMax'] ? t3lib_div::intInRange($itemArrayC + 1, t3lib_div::intInRange($params['size'], 1), $params['autoSizeMax']) : $params['size'];
        if (!$selector) {
            $selector = '<select id="' . uniqid('tceforms-multiselect-') . '" ' . ($params['noList'] ? 'style="display: none"' : 'size="' . $sSize . '"' . $this->insertDefStyle('group', 'tceforms-multiselect')) . ' multiple="multiple" name="' . $fName . '_list" ' . $onFocus . $params['style'] . $disabled . '>' . implode('', $opt) . '</select>';
        }
        $icons = array('L' => array(), 'R' => array());
        if (!$params['readOnly'] && !$params['noList']) {
            if (!$params['noBrowser']) {
                // check against inline uniqueness
                $inlineParent = $this->inline->getStructureLevel(-1);
                if (is_array($inlineParent) && $inlineParent['uid']) {
                    if ($inlineParent['config']['foreign_table'] == $table && $inlineParent['config']['foreign_unique'] == $field) {
                        $objectPrefix = $this->inline->inlineNames['object'] . '[' . $table . ']';
                        $aOnClickInline = $objectPrefix . '|inline.checkUniqueElement|inline.setUniqueElement';
                        $rOnClickInline = 'inline.revertUnique(\'' . $objectPrefix . '\',null,\'' . $uid . '\');';
                    }
                }
                $aOnClick = 'setFormValueOpenBrowser(\'' . $mode . '\',\'' . ($fName . '|||' . $allowed . '|' . $aOnClickInline) . '\'); return false;';
                $icons['R'][] = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . t3lib_iconWorks::getSpriteIcon('actions-insert-record', array('title' => htmlspecialchars($this->getLL('l_browse_' . ($mode == 'db' ? 'db' : 'file'))))) . '</a>';
            }
            if (!$params['dontShowMoveIcons']) {
                if ($sSize >= 5) {
                    $icons['L'][] = '<a href="#" onclick="setFormValueManipulate(\'' . $fName . '\',\'Top\'); return false;">' . t3lib_iconWorks::getSpriteIcon('actions-move-to-top', array('title' => htmlspecialchars($this->getLL('l_move_to_top')))) . '</a>';
                }
                $icons['L'][] = '<a href="#" onclick="setFormValueManipulate(\'' . $fName . '\',\'Up\'); return false;">' . t3lib_iconWorks::getSpriteIcon('actions-move-up', array('title' => htmlspecialchars($this->getLL('l_move_up')))) . '</a>';
                $icons['L'][] = '<a href="#" onclick="setFormValueManipulate(\'' . $fName . '\',\'Down\'); return false;">' . t3lib_iconWorks::getSpriteIcon('actions-move-down', array('title' => htmlspecialchars($this->getLL('l_move_down')))) . '</a>';
                if ($sSize >= 5) {
                    $icons['L'][] = '<a href="#" onclick="setFormValueManipulate(\'' . $fName . '\',\'Bottom\'); return false;">' . t3lib_iconWorks::getSpriteIcon('actions-move-to-bottom', array('title' => htmlspecialchars($this->getLL('l_move_to_bottom')))) . '</a>';
                }
            }
            $clipElements = $this->getClipboardElements($allowed, $mode);
            if (count($clipElements)) {
                $aOnClick = '';
                foreach ($clipElements as $elValue) {
                    if ($mode == 'db') {
                        list($itemTable, $itemUid) = explode('|', $elValue);
                        $itemTitle = $GLOBALS['LANG']->JScharCode(t3lib_BEfunc::getRecordTitle($itemTable, t3lib_BEfunc::getRecordWSOL($itemTable, $itemUid)));
                        $elValue = $itemTable . '_' . $itemUid;
                    } else {
                        // 'file', 'file_reference' and 'folder' mode
                        $itemTitle = 'unescape(\'' . rawurlencode(basename($elValue)) . '\')';
                    }
                    $aOnClick .= 'setFormValueFromBrowseWin(\'' . $fName . '\',unescape(\'' . rawurlencode(str_replace('%20', ' ', $elValue)) . '\'),' . $itemTitle . ');';
                }
                $aOnClick .= 'return false;';
                $icons['R'][] = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . t3lib_iconWorks::getSpriteIcon('actions-document-paste-into', array('title' => htmlspecialchars(sprintf($this->getLL('l_clipInsert_' . ($mode == 'db' ? 'db' : 'file')), count($clipElements))))) . '</a>';
            }
            $rOnClick = $rOnClickInline . 'setFormValueManipulate(\'' . $fName . '\',\'Remove\'); return false';
            $icons['L'][] = '<a href="#" onclick="' . htmlspecialchars($rOnClick) . '">' . t3lib_iconWorks::getSpriteIcon('actions-selection-delete', array('title' => htmlspecialchars($this->getLL('l_remove_selected')))) . '</a>';
        }
        $imagesOnly = FALSE;
        if ($params['thumbnails'] && $params['info']) {
            // In case we have thumbnails, check if only images are allowed.
            // In this case, render them below the field, instead of to the right
            $allowedExtensionList = t3lib_div::trimExplode(' ', strtolower($params['info']), TRUE);
            $imageExtensionList = t3lib_div::trimExplode(',', strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), TRUE);
            $imagesOnly = TRUE;
            foreach ($allowedExtensionList as $allowedExtension) {
                if (!t3lib_div::inArray($imageExtensionList, $allowedExtension)) {
                    $imagesOnly = FALSE;
                    break;
                }
            }
        }
        if ($imagesOnly) {
            $rightbox = '';
            $thumbnails = '<div class="imagethumbs">' . $this->wrapLabels($params['thumbnails']) . '</div>';
        } else {
            $rightbox = $this->wrapLabels($params['thumbnails']);
            $thumbnails = '';
        }
        // Hook: dbFileIcons_postProcess (requested by FAL-team for use with the "fal" extension)
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['dbFileIcons'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['dbFileIcons'] as $classRef) {
                $hookObject = t3lib_div::getUserObj($classRef);
                if (!$hookObject instanceof t3lib_TCEforms_dbFileIconsHook) {
                    throw new UnexpectedValueException('$hookObject must implement interface t3lib_TCEforms_dbFileIconsHook', 1290167704);
                }
                $additionalParams = array('mode' => $mode, 'allowed' => $allowed, 'itemArray' => $itemArray, 'onFocus' => $onFocus, 'table' => $table, 'field' => $field, 'uid' => $uid);
                $hookObject->dbFileIcons_postProcess($params, $selector, $thumbnails, $icons, $rightbox, $fName, $uidList, $additionalParams, $this);
            }
        }
        $str = '<table border="0" cellpadding="0" cellspacing="0" width="1">
			' . ($params['headers'] ? '
				<tr>
					<td>' . $this->wrapLabels($params['headers']['selector']) . '</td>
					<td></td>
					<td></td>
					<td>' . ($params['thumbnails'] ? $this->wrapLabels($params['headers']['items']) : '') . '</td>
				</tr>' : '') . '
			<tr>
				<td valign="top">' . $selector . $thumbnails . ($params['noList'] ? '' : '<span class="filetypes">' . $this->wrapLabels($params['info'])) . '</span></td>
				<td valign="top" class="icons">' . implode('<br />', $icons['L']) . '</td>
				<td valign="top" class="icons">' . implode('<br />', $icons['R']) . '</td>
				<td valign="top" class="thumbnails">' . $rightbox . '</td>
			</tr>
		</table>';
        // Creating the hidden field which contains the actual value as a comma list.
        $str .= '<input type="hidden" name="' . $fName . '" value="' . htmlspecialchars(implode(',', $uidList)) . '" />';
        return $str;
    }