/**
     * Do the file indexing
     * Read files from a directory index them and output a result table
     *
     * @return	string		HTML content
     */
    function checkUploads($indexSessionID)
    {
        global $LANG, $TYPO3_CONF_VARS;
        // makes sense? Was a hint on php.net
        ob_end_flush();
        // get session data - which might have left files stored
        $indexSession = $this->indexSessionFetch();
        $where = array();
        if ($age = intval($this->pObj->MOD_SETTINGS['tx_dam_tools_indexupdate.age'])) {
            $where['tstamp'] = 'tstamp<' . (time() - $age);
        }
        if ($indexSessionID == '' or !isset($indexSession['ID']) or !($indexSession['ID'] == $indexSessionID) or $indexSession['currentCount'] == 0) {
            $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dam_file_tracking', '');
            $files = array();
            $files = $this->getFilesInDir(PATH_site . 'uploads/', true, $files);
            $countTotal = count($files);
            $indexSession = $this->indexSessionNew($countTotal, $files);
        }
        if (is_array($indexSession['data'])) {
            $damIndexing = t3lib_div::makeInstance('tx_dam_indexing');
            $damIndexing->init();
            $damIndexing->dryRun = TRUE;
            foreach ($indexSession['data'] as $key => $file) {
                // increase progress bar
                $indexSession['currentCount']++;
                $fileHash = tx_dam::file_calcHash($file);
                $fileInfo = tx_dam::file_compileInfo($file);
                $fields_values = array('tstamp' => time(), 'file_name' => $fileInfo['file_name'], 'file_path' => $fileInfo['file_path'], 'file_size' => $fileInfo['file_size'], 'file_ctime' => min($fileInfo['file_ctime'], $fileInfo['file_mtime']), 'file_hash' => $fileHash);
                $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_dam_file_tracking', $fields_values);
                $fileInfo = array_merge($fileInfo, $damIndexing->getFileMimeType($file));
                $fileInfo['media_type'] = tx_dam::convert_mediaType($fileInfo['file_mime_type']);
                $ctable = array();
                $ctable[] = '&nbsp;';
                $ctable[] = tx_dam::icon_getFileTypeImgTag($fileInfo, 'align="top"') . '&nbsp;' . htmlspecialchars(t3lib_div::fixed_lgd_cs($fileInfo['file_name'], 30));
                $ctable[] = htmlspecialchars(t3lib_div::fixed_lgd_cs($fileInfo['file_path'], -30));
                $this->indexing_addTableRow($ctable);
                $msg = $LANG->getLL('tx_dam_tools_indexupdate.updatedMessage', 1);
                $code = sprintf($msg, $indexSession['currentCount'], $indexSession['totalFilesCount']);
                $this->indexing_setMessage($code);
                $this->indexing_progressBar($indexSession['currentCount'], $indexSession['totalFilesCount']);
                $this->indexing_flushNow();
                $this->indexSessionWrite($indexSession);
                if ($this->indexEndtime < time() and $indexSession['currentCount'] < $indexSession['totalFilesCount']) {
                    $params = $this->pObj->addParams;
                    $params['indexSessionID'] = $indexSession['ID'];
                    echo '
						<script type="text/javascript">  window.location.href = unescape("' . t3lib_div::rawUrlEncodeJS(tx_dam_SCbase::linkThisScriptStraight($params)) . '"); </script>';
                    exit;
                }
            }
        } elseif ($indexSession['totalFilesCount'] == 0) {
            $code = $LANG->getLL('tx_dam_tools_indexupdate.no_files');
            $this->indexing_setMessage($code);
        }
        $this->indexing_finished();
        // finished - clear session
        $this->indexSessionClear();
    }
    /**
     *
     */
    function doIndexingCallback($type, $meta, $absFile, $fileArrKey, $pObj)
    {
        global $LANG, $TYPO3_CONF_VARS;
        // get session data
        $indexSession = $this->indexSessionFetch();
        // increase progress bar
        $indexSession['currentCount']++;
        if (is_array($meta) and is_array($meta['fields'])) {
            if (tx_dam::config_getValue('setup.devel')) {
                t3lib_div::print_array(array('file_name' => $meta['fields']['file_name'], 'indexExist' => $meta['indexExist'], 'reindexed' => $meta['reindexed'], 'isIndexed' => $meta['isIndexed']));
            }
            if ($meta['isIndexed']) {
                $failure = '';
                $openRecPopup = '';
                if ($meta['failure']) {
                    $failure .= '<br /><img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/icon_fatalerror.gif', 'width="18" height="16"') . ' class="absmiddle" alt="" />';
                    $failure .= ' ' . htmlspecialchars($meta['failure']);
                } else {
                    $openRecPopup = $GLOBALS['SOBE']->btn_editRec_inNewWindow('tx_dam', $meta['fields']['uid']);
                }
                $ctable = array();
                $ctable[] = $openRecPopup;
                $ctable[] = '<span style="white-space:nowrap;">' . tx_dam::icon_getFileTypeImgTag($meta['fields'], 'align="top"') . '&nbsp;' . htmlspecialchars(t3lib_div::fixed_lgd_cs($meta['fields']['file_name'], 23)) . '</span>' . $failure;
                $ctable[] = strtoupper($meta['fields']['file_type']);
                $ctable[] = '<span style="white-space:nowrap;">' . htmlspecialchars(str_replace("\n", ' ', t3lib_div::fixed_lgd_cs($meta['fields']['abstract'], 14))) . '</span>';
                $ctable[] = htmlspecialchars(t3lib_div::fixed_lgd_cs($meta['fields']['file_path'], -15));
                $this->indexing_addTableRow($ctable);
                $msg = $LANG->getLL('tx_damindex_index.indexed_message', 1);
                $code = sprintf($msg, $this->index->stat['totalCount'], max(1, ceil($this->index->stat['totalTime'] / 1000)));
                $this->indexing_setMessage($code);
            }
        }
        $this->indexing_progressBar($indexSession['currentCount'], $indexSession['totalFilesCount']);
        $this->indexing_flushNow();
        // one step further - save session data
        unset($indexSession['filesTodo'][$fileArrKey]);
        $indexSession['indexStat'] = $this->index->stat;
        $indexSession['infoList'] = $this->index->infoList;
        $this->indexSessionWrite($indexSession);
        if ($this->indexEndtime < time() and $indexSession['currentCount'] < $indexSession['totalFilesCount']) {
            $params = $this->pObj->addParams;
            $params['indexSessionID'] = $indexSession['ID'];
            echo '
				<script type="text/javascript">  window.location.href = unescape("' . t3lib_div::rawUrlEncodeJS(tx_dam_SCbase::linkThisScriptStraight($params)) . '"); </script>';
            exit;
        }
    }