/**
  * constructor
  *
  * @param	TYPO3backend	TYPO3 backend object reference
  */
 public function __construct(TYPO3backend &$backendReference = null)
 {
     $this->backendReference = $backendReference;
     $this->cacheActions = array();
     $this->optionValues = array('all', 'pages');
     // Clear cache for ALL tables!
     if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.all')) {
         $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_all', true);
         $this->cacheActions[] = array('id' => 'all', 'title' => $title, 'href' => $this->backPath . 'tce_db.php?vC=' . $GLOBALS['BE_USER']->veriCode() . '&cacheCmd=all', 'icon' => t3lib_iconWorks::getSpriteIcon('actions-system-cache-clear-impact-high'));
     }
     // Clear cache for either ALL pages
     if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.pages')) {
         $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_pages', true);
         $this->cacheActions[] = array('id' => 'pages', 'title' => $title, 'href' => $this->backPath . 'tce_db.php?vC=' . $GLOBALS['BE_USER']->veriCode() . '&cacheCmd=pages', 'icon' => t3lib_iconWorks::getSpriteIcon('actions-system-cache-clear-impact-medium'));
     }
     // Clearing of cache-files in typo3conf/ + menu
     if ($GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache']) {
         $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_allTypo3Conf', true);
         $this->cacheActions[] = array('id' => 'temp_CACHED', 'title' => $title, 'href' => $this->backPath . 'tce_db.php?vC=' . $GLOBALS['BE_USER']->veriCode() . '&cacheCmd=temp_CACHED', 'icon' => t3lib_iconWorks::getSpriteIcon('actions-system-cache-clear-impact-low'));
     }
     // hook for manipulate cacheActions
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'] as $cacheAction) {
             $hookObject = t3lib_div::getUserObj($cacheAction);
             if (!$hookObject instanceof backend_cacheActionsHook) {
                 throw new UnexpectedValueException('$hookObject must implement interface backend_cacheActionsHook', 1228262000);
             }
             $hookObject->manipulateCacheActions($this->cacheActions, $this->optionValues);
         }
     }
 }
 /**
  * Evaluates the captcha word
  */
 public function evalValues($theTable, $dataArray, $origArray, $markContentArray, $cmdKey, $requiredArray, $theField, $cmdParts, $bInternal, &$test, $dataObject)
 {
     $errorField = '';
     // Must be set to FALSE if it is not a test
     $test = FALSE;
     if (trim($cmdParts[0]) == 'freecap' && t3lib_extMgm::isLoaded('sr_freecap') && isset($dataArray[$theField])) {
         $freeCap = t3lib_div::getUserObj('&tx_srfreecap_pi2');
         if (isset($GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['sr_freecap_EidDispatcher'])) {
             $sessionNameSpace = 'tx_srfreecap';
         } else {
             // Old version of sr_freecap
             $sessionNameSpace = 'tx_' . $freeCap->extKey;
         }
         // Save the sr_freecap word_hash
         // sr_freecap will invalidate the word_hash after calling checkWord
         $sessionData = $GLOBALS['TSFE']->fe_user->getKey('ses', $sessionNameSpace);
         if (!$freeCap->checkWord($dataArray[$theField])) {
             $errorField = $theField;
         } else {
             // Restore sr_freecap word_hash
             $GLOBALS['TSFE']->fe_user->setKey('ses', $sessionNameSpace, $sessionData);
             $GLOBALS['TSFE']->storeSessionData();
         }
     }
     return $errorField;
 }
 /**
  * Initializes this object
  *
  * @param tx_kesearch_lib $pObj
  * @return void
  */
 public function initialize(tx_kesearch_lib $pObj)
 {
     $this->pObj = $pObj;
     $this->cObj = $pObj->cObj;
     if (TYPO3_VERSION_INTEGER >= 6002000) {
         $this->db = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_kesearch_db');
     } else {
         $this->db = t3lib_div::makeInstance('tx_kesearch_db');
     }
     $this->conf = $this->pObj->conf;
     $this->piVars = $this->pObj->piVars;
     $this->startingPoints = $this->pObj->startingPoints;
     $this->tagChar = $this->pObj->extConf['prePostTagChar'];
     // get filters and filter options
     $this->filters = $this->getFiltersFromUidList($this->combineLists($this->conf['filters'], $this->conf['hiddenfilters']));
     // hook to modify filters
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFilters'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFilters'] as $_classRef) {
             if (TYPO3_VERSION_INTEGER >= 7000000) {
                 $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef);
             } else {
                 $_procObj =& t3lib_div::getUserObj($_classRef);
             }
             $_procObj->modifyFilters($this->filters, $this);
         }
     }
     // get list of selected filter options (via frontend or backend)
     foreach ($this->filters as $filter) {
         $this->filters[$filter['uid']]['selectedOptions'] = $this->getSelectedFilterOptions($filter);
     }
 }
 /**
  * Main function, rendering the element browser in RTE mode.
  *
  * @return	void
  */
 function main()
 {
     // Setting alternative browsing mounts (ONLY local to browse_links.php this script so they stay "read-only")
     $altMountPoints = trim($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.altElementBrowserMountPoints'));
     if ($altMountPoints) {
         $altMountPoints = t3lib_div::trimExplode(',', $altMountPoints);
         foreach ($altMountPoints as $filePathRelativeToFileadmindir) {
             $GLOBALS['BE_USER']->addFileMount('', $filePathRelativeToFileadmindir, $filePathRelativeToFileadmindir, 1, 'readonly');
         }
         $GLOBALS['FILEMOUNTS'] = $GLOBALS['BE_USER']->returnFilemounts();
     }
     // Rendering type by user function
     $browserRendered = false;
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'] as $classRef) {
             $browserRenderObj = t3lib_div::getUserObj($classRef);
             if (is_object($browserRenderObj) && method_exists($browserRenderObj, 'isValid') && method_exists($browserRenderObj, 'render')) {
                 if ($browserRenderObj->isValid($this->mode, $this)) {
                     $this->content .= $browserRenderObj->render($this->mode, $this);
                     $browserRendered = true;
                     break;
                 }
             }
         }
     }
     // If type was not rendered, use default rendering functions
     if (!$browserRendered) {
         $GLOBALS['SOBE']->browser = t3lib_div::makeInstance('tx_rtehtmlarea_select_image');
         $GLOBALS['SOBE']->browser->init();
         $modData = $GLOBALS['BE_USER']->getModuleData('select_image.php', 'ses');
         list($modData, $store) = $GLOBALS['SOBE']->browser->processSessionData($modData);
         $GLOBALS['BE_USER']->pushModuleData('select_image.php', $modData);
         $this->content = $GLOBALS['SOBE']->browser->main_rte();
     }
 }
 public function main($content, $conf)
 {
     $pibaseObj = t3lib_div::getUserObj('&tx_srfeuserregister_pi1_base');
     $pibaseObj->cObj = $this->cObj;
     $content = $pibaseObj->main($content, $conf);
     return $content;
 }
 /**
  * Obtains a storage. This function will return a non-abstract class, which
  * is derieved from the tx_rsaauth_abstract_storage. Applications should
  * not use anoy methods that are not declared in the tx_rsaauth_abstract_storage.
  *
  * @return	tx_rsaauth_abstract_storage	A storage
  */
 public static function getStorage()
 {
     if (is_null(self::$storageInstance)) {
         self::$storageInstance = t3lib_div::getUserObj(self::$preferredStorage);
     }
     return self::$storageInstance;
 }
 /**
  * Fill hookObjectsArr with different link types and possible XClasses.
  */
 public function __construct()
 {
     // Hook to handle own checks
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'] as $key => $classRef) {
             $this->hookObjectsArr[$key] =& t3lib_div::getUserObj($classRef);
         }
     }
 }
 /**
  * Load extra predefined media params if they exist
  *
  * @param	array		$params: Existing types by reference
  * @param 	array		$conf: config array
  */
 public function customMediaParams(&$params, $conf)
 {
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['customMediaParams'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/hooks/class.tx_cms_mediaitems.php']['customMediaParams'] as $classRef) {
             $hookObj = t3lib_div::getUserObj($classRef);
             $hookObj->customMediaParams($params, $conf);
         }
     }
 }
 function init($conf)
 {
     $this->conf = $conf;
     $this->pi_setPiVarDefaults();
     $this->pi_loadLL();
     $this->pi_initPIflexForm();
     // Init FlexForm configuration for plugin
     $this->hooks = array();
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ods_domaincheck']['tx_odsdomaincheck_pi1'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ods_domaincheck']['tx_odsdomaincheck_pi1'] as $classRef) {
             $this->hooks[] =& t3lib_div::getUserObj($classRef);
         }
     }
     /* --------------------------------------------------
     			Configuration (order of priority)
     			- FlexForm
     			- TypoScript
     		-------------------------------------------------- */
     $flex = array();
     $options = array('tlds', 'show_form', 'show_default', 'page_buy', 'buy_params', 'page_transfer', 'transfer_params', 'template');
     foreach ($options as $option) {
         $value = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], $option, 'sDEF');
         switch ($option) {
             case 'template':
                 if ($value) {
                     $flex[$option] = 'uploads/tx_odsdomaincheck/' . $value;
                 }
                 break;
             case 'tlds':
                 if ($value) {
                     $tlds2 = array();
                     $tlds = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,tld', 'tx_odsdomaincheck_tlds', 'uid IN (' . $GLOBALS['TYPO3_DB']->cleanIntList($value) . ')', '', '', '', 'uid');
                     foreach (explode(',', $value) as $tld) {
                         $tlds2[] = $tlds[$tld]['tld'];
                     }
                     $flex[$option] = implode(',', $tlds2);
                 }
                 break;
             default:
                 if ($value) {
                     $flex[$option] = $value;
                 }
                 break;
         }
     }
     $this->config = array_merge($conf, $flex);
     $this->tlds = explode(',', $this->config['tlds']);
     // Hook to manipulate init
     foreach ($this->hooks as $hook) {
         if (method_exists($hook, 'afterInit')) {
             $hook->afterInit($this);
         }
     }
 }
 /**
  * The __constructor is private because the dispatcher is a singleton
  *
  * @param void
  * @return void
  */
 protected function __construct()
 {
     $this->observers = array();
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['crawler/domain/events/class.tx_crawler_domain_events_dispatcher.php']['registerObservers'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['crawler/domain/events/class.tx_crawler_domain_events_dispatcher.php']['registerObservers'] as $classRef) {
             $hookObj =& t3lib_div::getUserObj($classRef);
             if (method_exists($hookObj, 'registerObservers')) {
                 $hookObj->registerObservers($this);
             }
         }
     }
 }
 /**
  * Get defined views for dropdown (from hook)
  * @return array
  */
 public function getViews($config, $item)
 {
     $optionList = array();
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['jfmulticontent']['getViews'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['jfmulticontent']['getViews'] as $_classRef) {
             $_procObj =& t3lib_div::getUserObj($_classRef);
             if (!method_exists($_procObj, 'isActive') || method_exists($_procObj, 'isActive') && $_procObj->isActive()) {
                 $optionList[] = array(trim($_procObj->getname()), trim($_procObj->getIdentifier()));
             }
         }
     }
     $config['items'] = array_merge($config['items'], $optionList);
     return $config;
 }
 public function fillIndexerConfig(&$params, $pObj)
 {
     // hook for custom registration of further indexerConfigurations
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['registerIndexerConfiguration'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['registerIndexerConfiguration'] as $_classRef) {
             if (TYPO3_VERSION_INTEGER >= 7000000) {
                 $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef);
             } else {
                 $_procObj =& t3lib_div::getUserObj($_classRef);
             }
             $_procObj->registerIndexerConfiguration($params, $pObj);
         }
     }
 }
示例#13
0
 /**
  * Provides the values for the markers in the simple form template
  *
  * @return array An array containing values for markers in the simple form template
  * @throws InvalidArgumentException if an registered form modifier fails to implement the required interface Tx_Solr_FormModifier
  */
 public function execute()
 {
     $url = $this->cObj->getTypoLink_URL($this->parentPlugin->conf['search.']['targetPage']);
     $marker = array('action' => htmlspecialchars($url), 'action_id' => intval($this->parentPlugin->conf['search.']['targetPage']), 'action_language' => intval($GLOBALS['TSFE']->sys_page->sys_language_uid), 'action_language_parameter' => 'L', 'accept-charset' => $GLOBALS['TSFE']->metaCharset, 'q' => $this->parentPlugin->getCleanUserQuery());
     // hook to modify the search form
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifySearchForm'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifySearchForm'] as $classReference) {
             $formModifier = t3lib_div::getUserObj($classReference);
             if ($formModifier instanceof Tx_Solr_FormModifier) {
                 if ($formModifier instanceof Tx_Solr_CommandPluginAware) {
                     $formModifier->setParentPlugin($this->parentPlugin);
                 }
                 $marker = $formModifier->modifyForm($marker, $this->parentPlugin->getTemplate());
             } else {
                 throw new InvalidArgumentException('Form modifier "' . $classReference . '" must implement the Tx_Solr_FormModifier interface.', 1262864703);
             }
         }
     }
     return $marker;
 }
 /**
  * Obtains a backend. This function will return a non-abstract class, which
  * is derieved from the tx_rsaauth_abstract_backend. Applications should
  * not use anoy methods that are not declared in the tx_rsaauth_abstract_backend.
  *
  * @return	tx_rsaauth_abstract_backend	A backend
  */
 public static function getBackend()
 {
     if (!self::$initialized) {
         // Backend does not exist yet. Create it.
         foreach (self::$availableBackends as $backend) {
             $backendObject = t3lib_div::getUserObj($backend);
             // Check that it is derieved from the proper base class
             if ($backendObject instanceof tx_rsaauth_abstract_backend) {
                 /* @var $backendObject tx_rsaauth_abstract_backend */
                 if ($backendObject->isAvailable()) {
                     // The backend is available, save it and stop the loop
                     self::$selectedBackend = $backendObject;
                     self::$initialized = true;
                     break;
                 }
                 // Attempt to force destruction of the object
                 unset($backend);
             }
         }
     }
     return self::$selectedBackend;
 }
 /**
  * Save the translation
  *
  * @param tx_l10nmgr_l10nConfiguration $l10ncfgObj
  * @param tx_l10nmgr_translationData $translationObj
  * @return void
  */
 function saveTranslation(tx_l10nmgr_l10nConfiguration $l10ncfgObj, tx_l10nmgr_translationData $translationObj)
 {
     // Provide a hook for specific manipulations before saving
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['l10nmgr']['savePreProcess'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['l10nmgr']['savePreProcess'] as $classReference) {
             $processingObject = t3lib_div::getUserObj($classReference);
             $processingObject->processBeforeSaving($l10ncfgObj, $translationObj, $this);
         }
     }
     $sysLang = $translationObj->getLanguage();
     $accumObj = $l10ncfgObj->getL10nAccumulatedInformationsObjectForLanguage($sysLang);
     $flexFormDiffArray = $this->_submitContentAndGetFlexFormDiff($accumObj->getInfoArray($sysLang), $translationObj->getTranslationData());
     if ($flexFormDiffArray !== FALSE) {
         $l10ncfgObj->updateFlexFormDiff($sysLang, $flexFormDiffArray);
     }
     // Provide a hook for specific manipulations after saving
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['l10nmgr']['savePostProcess'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['l10nmgr']['savePostProcess'] as $classReference) {
             $processingObject = t3lib_div::getUserObj($classReference);
             $processingObject->processAfterSaving($l10ncfgObj, $translationObj, $flexFormDiffArray, $this);
         }
     }
 }
 /**
  * init static info tables to use with this view helper
  * 
  * @return null
  */
 protected static function init()
 {
     // check if class was already initialized
     if (!is_null(self::$staticInfoObject)) {
         return;
     }
     // check if static_info_tables is installed
     if (!t3lib_extMgm::isLoaded('static_info_tables')) {
         self::$staticInfoObject = false;
         t3lib_div::devLog('static_info_tables needs to be installed to use ' . get_class(self), get_class(self), 1);
         return;
     }
     require_once t3lib_extMgm::extPath('static_info_tables') . 'pi1/class.tx_staticinfotables_pi1.php';
     // init class
     // code taken from the documentation
     self::$staticInfoObject =& t3lib_div::getUserObj('&tx_staticinfotables_pi1');
     if (!self::$staticInfoObject) {
         self::$staticInfoObject = false;
         return null;
     }
     if (self::$staticInfoObject->needsInit()) {
         self::$staticInfoObject->init();
     }
 }
 /**
  * Class constructor.
  * Well, it has to be called manually since it is not a real constructor function.
  * So after making an instance of the class, call this function and pass to it a database record and the tablename from where the record is from. That will then become the "current" record loaded into memory and accessed by the .fields property found in eg. stdWrap.
  *
  * @param	array		$data	the record data that is rendered.
  * @param	string		$table	the table that the data record is from.
  * @return	void
  */
 function start($data, $table = '')
 {
     global $TYPO3_CONF_VARS;
     $this->data = $data;
     ### backport start ###
     $this->table = $table;
     ### backport end ###
     $this->currentRecord = $table ? $table . ':' . $this->data['uid'] : '';
     $this->parameters = array();
     if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClass'])) {
         foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClass'] as $classArr) {
             $this->cObjHookObjectsArr[$classArr[0]] = t3lib_div::getUserObj($classArr[1]);
         }
     }
     $this->stdWrapHookObjects = array();
     if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['stdWrap'])) {
         foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['stdWrap'] as $classData) {
             $hookObject = t3lib_div::getUserObj($classData);
             if (!$hookObject instanceof tslib_content_stdWrapHook) {
                 throw new UnexpectedValueException('$hookObject must implement interface tslib_content_stdWrapHook', 1195043965);
             }
             $this->stdWrapHookObjects[] = $hookObject;
         }
     }
     ### backported hook start ###
     if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['postInit'])) {
         foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['postInit'] as $classData) {
             $postInitializationProcessor = t3lib_div::getUserObj($classData);
             if (!$postInitializationProcessor instanceof tslib_content_PostInitHook) {
                 throw new UnexpectedValueException($postInitializationProcessor . ' must implement interface tslib_content_PostInitHook', 1274563549);
             }
             $postInitializationProcessor->postProcessContentObjectInitialization($this);
         }
     }
     ### backported hook end ###
 }
 /**
  * Load all active notificationServices into static array which are active and of correct type
  *
  * @return void
  */
 protected static function loadAllCaretakerNotificationServices()
 {
     self::$notificationServiceInstances = array();
     foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['caretaker']['notificationServices'] as $serviceKey => $notificationService) {
         $instance = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['caretaker']['notificationServices'][$serviceKey]);
         if ($instance instanceof tx_caretaker_NotificationServiceInterface && $instance->isEnabled()) {
             self::$notificationServiceInstances[$serviceKey] = $instance;
         }
     }
 }
    /**
     * Create visual difference view of two records. Using t3lib_diff library
     *
     * @param	string		Table name
     * @param	array		New version record (green)
     * @param	array		Old version record (red)
     * @return	array		Array with two keys (0/1) with HTML content / percentage integer (if -1, then it means N/A) indicating amount of change
     */
    function createDiffView($table, $diff_1_record, $diff_2_record)
    {
        global $TCA, $LANG;
        // Initialize:
        $pctChange = 'N/A';
        // Check that records are arrays:
        if (is_array($diff_1_record) && is_array($diff_2_record)) {
            // Load full table description and initialize diff-object:
            t3lib_div::loadTCA($table);
            $t3lib_diff_Obj = t3lib_div::makeInstance('t3lib_diff');
            // Add header row:
            $tRows = array();
            $tRows[] = '
				<tr class="bgColor5 tableheader">
					<td>' . $LANG->getLL('diffview_label_field_name') . '</td>
					<td width="98%" nowrap="nowrap">' . $LANG->getLL('diffview_label_colored_diff_view') . '</td>
				</tr>
			';
            // Initialize variables to pick up string lengths in:
            $allStrLen = 0;
            $diffStrLen = 0;
            // Traversing the first record and process all fields which are editable:
            foreach ($diff_1_record as $fN => $fV) {
                if ($TCA[$table]['columns'][$fN] && $TCA[$table]['columns'][$fN]['config']['type'] != 'passthrough' && !t3lib_div::inList('t3ver_label', $fN)) {
                    // Check if it is files:
                    $isFiles = FALSE;
                    if (strcmp(trim($diff_1_record[$fN]), trim($diff_2_record[$fN])) && $TCA[$table]['columns'][$fN]['config']['type'] == 'group' && $TCA[$table]['columns'][$fN]['config']['internal_type'] == 'file') {
                        // Initialize:
                        $uploadFolder = $TCA[$table]['columns'][$fN]['config']['uploadfolder'];
                        $files1 = array_flip(t3lib_div::trimExplode(',', $diff_1_record[$fN], 1));
                        $files2 = array_flip(t3lib_div::trimExplode(',', $diff_2_record[$fN], 1));
                        // Traverse filenames and read their md5 sum:
                        foreach ($files1 as $filename => $tmp) {
                            $files1[$filename] = @is_file(PATH_site . $uploadFolder . '/' . $filename) ? md5(t3lib_div::getUrl(PATH_site . $uploadFolder . '/' . $filename)) : $filename;
                        }
                        foreach ($files2 as $filename => $tmp) {
                            $files2[$filename] = @is_file(PATH_site . $uploadFolder . '/' . $filename) ? md5(t3lib_div::getUrl(PATH_site . $uploadFolder . '/' . $filename)) : $filename;
                        }
                        // Implode MD5 sums and set flag:
                        $diff_1_record[$fN] = implode(' ', $files1);
                        $diff_2_record[$fN] = implode(' ', $files2);
                        $isFiles = TRUE;
                    }
                    // If there is a change of value:
                    if (strcmp(trim($diff_1_record[$fN]), trim($diff_2_record[$fN]))) {
                        // Get the best visual presentation of the value and present that:
                        $val1 = t3lib_BEfunc::getProcessedValue($table, $fN, $diff_2_record[$fN], 0, 1);
                        $val2 = t3lib_BEfunc::getProcessedValue($table, $fN, $diff_1_record[$fN], 0, 1);
                        // Make diff result and record string lenghts:
                        $diffres = $t3lib_diff_Obj->makeDiffDisplay($val1, $val2, $isFiles ? 'div' : 'span');
                        $diffStrLen .= $t3lib_diff_Obj->differenceLgd;
                        $allStrLen .= strlen($val1 . $val2);
                        // If the compared values were files, substituted MD5 hashes:
                        if ($isFiles) {
                            $allFiles = array_merge($files1, $files2);
                            foreach ($allFiles as $filename => $token) {
                                if (strlen($token) == 32 && strstr($diffres, $token)) {
                                    $filename = t3lib_BEfunc::thumbCode(array($fN => $filename), $table, $fN, $this->doc->backPath) . $filename;
                                    $diffres = str_replace($token, $filename, $diffres);
                                }
                            }
                        }
                        ############# new hook for post processing of DAM images
                        if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/mod/user/ws/class.wslib_gui.php']['postProcessDiffView'])) {
                            foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/mod/user/ws/class.wslib_gui.php']['postProcessDiffView'] as $classRef) {
                                $hookObject =& t3lib_div::getUserObj($classRef);
                                if (method_exists($hookObject, 'postProcessDiffView')) {
                                    $diffres = $hookObject->postProcessDiffView($table, $fN, $diff_2_record, $diff_1_record, $diffres, $this);
                                }
                            }
                        }
                        #############
                        // Add table row with result:
                        $tRows[] = '
							<tr class="bgColor4">
								<td>' . htmlspecialchars($GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel($table, $fN))) . '</td>
								<td width="98%">' . $diffres . '</td>
							</tr>
						';
                    } else {
                        // Add string lengths even if value matched - in this was the change percentage is not high if only a single field is changed:
                        $allStrLen += strlen($diff_1_record[$fN] . $diff_2_record[$fN]);
                    }
                }
            }
            // Calculate final change percentage:
            $pctChange = $allStrLen ? ceil($diffStrLen * 100 / $allStrLen) : -1;
            // Create visual representation of result:
            if (count($tRows) > 1) {
                $content .= '<table border="0" cellpadding="1" cellspacing="1" class="diffTable">' . implode('', $tRows) . '</table>';
            } else {
                $content .= '<span class="nobr">' . $this->doc->icons(1) . $LANG->getLL('diffview_complete_match') . '</span>';
            }
        } else {
            $content .= $this->doc->icons(3) . $LANG->getLL('diffview_cannot_find_records');
        }
        // Return value:
        return array($content, $pctChange);
    }
示例#20
0
 /**
  * Determines a page ID's URL.
  *
  * Tries to find a domain record to use to build an URL for a given page ID
  * and then actually build and return the page URL.
  *
  * @param Tx_Solr_IndexQueue_Item $item Item to index
  * @param integer $language The language id
  * @return string URL to send the index request to
  */
 protected function getDataUrl(Tx_Solr_IndexQueue_Item $item, $language = 0)
 {
     $scheme = 'http';
     $host = $item->getSite()->getDomain();
     $path = '/';
     $pageId = $item->getRecordUid();
     // deprecated
     if (!empty($this->options['scheme'])) {
         t3lib_div::devLog('Using deprecated option "scheme" to set the scheme (http / https) for the page indexer frontend helper. Use plugin.tx_solr.index.queue.pages.indexer.frontendDataHelper.scheme instead', 'solr', 2);
         $scheme = $this->options['scheme'];
     }
     // check whether we should use ssl / https
     if (!empty($this->options['frontendDataHelper.']['scheme'])) {
         $scheme = $this->options['frontendDataHelper.']['scheme'];
     }
     // overwriting the host
     if (!empty($this->options['frontendDataHelper.']['host'])) {
         $host = $this->options['frontendDataHelper.']['host'];
     }
     // setting a path if TYPO3 is installed in a sub directory
     if (!empty($this->options['frontendDataHelper.']['path'])) {
         $path = $this->options['frontendDataHelper.']['path'];
     }
     $dataUrl = $scheme . '://' . $host . $path . 'index.php?id=' . $pageId;
     $dataUrl .= $this->getMountPageDataUrlParameter($item);
     $dataUrl .= '&L=' . $language;
     if (!t3lib_div::isValidUrl($dataUrl)) {
         t3lib_div::devLog('Could not create a valid URL to get frontend data while trying to index a page.', 'solr', 3, array('item' => (array) $item, 'constructed URL' => $dataUrl, 'scheme' => $scheme, 'host' => $host, 'path' => $path, 'page ID' => $pageId, 'indexer options' => $this->options));
         throw new RuntimeException('Could not create a valid URL to get frontend data while trying to index a page. Created URL: ' . $dataUrl, 1311080805);
     }
     if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueuePageIndexer']['dataUrlModifier']) {
         $dataUrlModifier = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueuePageIndexer']['dataUrlModifier']);
         if ($dataUrlModifier instanceof Tx_Solr_IndexQueuePageIndexerDataUrlModifier) {
             $dataUrl = $dataUrlModifier->modifyDataUrl($dataUrl, array('item' => $item, 'scheme' => $scheme, 'host' => $host, 'path' => $path, 'pageId' => $pageId, 'language' => $language));
         } else {
             throw new RuntimeException($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueuePageIndexer']['dataUrlModifier'] . ' is not an implementation of Tx_Solr_IndexQueuePageIndexerDataUrlModifier', 1290523345);
         }
     }
     return $dataUrl;
 }
 /**
  * Returns the BE location of the RTE
  *
  * @param	string		The table name
  * @param	array		The current row from which field is being rendered
  * @return	array		Config order!
  */
 function getConfigOrder($table, $row, $PA = array())
 {
     // Initial location is set to: Default config, then the table name
     $where = array('default.lang.' . $row['ISOcode'], $table, $table . '.lang.' . $row['ISOcode']);
     // Custom location based on table name
     switch ($table) {
         case 'tt_content':
             // location based on tablename + tt_content Ctype
             $where[] = $table . '.ctype.' . $row['CType'];
             $where[] = $table . '.ctype.' . $row['CType'] . '.lang.' . $row['ISOcode'];
             // location based on tablename + tt_content column position is added
             $where[] = $table . '.field.colPos' . $row['colPos'];
             $where[] = $table . '.field.colPos' . $row['colPos'] . '.lang.' . $row['ISOcode'];
             $where[] = $table . '.field.colPos' . $row['colPos'] . '.ctype.' . $row['CType'];
             $where[] = $table . '.field.colPos' . $row['colPos'] . '.ctype.' . $row['CType'] . '.lang.' . $row['ISOcode'];
             // TemplaVoila is installed
             if (t3lib_extMgm::isLoaded('templavoila')) {
                 require_once t3lib_extMgm::extPath('templavoila') . 'class.tx_templavoila_api.php';
                 $tvAPI = t3lib_div::makeInstance('tx_templavoila_api');
                 // Add all nested TV fields to location
                 $tmp = array();
                 $uid = $row['uid'];
                 if ($row['t3_origuid'] > 0) {
                     $uid = $row['t3_origuid'];
                 }
                 $flex = array('table' => $table, 'uid' => $uid);
                 while ($flex['table'] == $table) {
                     $flex = array_shift($tvAPI->flexform_getPointersByRecord($flex['uid'], $row['pid']));
                     // location based on tablename + TV field name is added
                     $tmp[] = $table . '.field.' . $flex['field'] . '.ctype.' . $row['CType'] . '.lang.' . $row['ISOcode'];
                     $tmp[] = $table . '.field.' . $flex['field'] . '.ctype.' . $row['CType'];
                     $tmp[] = $table . '.field.' . $flex['field'] . '.lang.' . $row['ISOcode'];
                     $tmp[] = $table . '.field.' . $flex['field'];
                 }
                 $where = array_merge($where, array_reverse($tmp));
             }
             break;
         default:
             $fieldStr = $PA['itemFormElName'];
             $fieldStrLength = strlen($fieldStr) - 6;
             $fieldStr = substr($fieldStr, 5, $fieldStrLength);
             $fields = explode('][', $fieldStr);
             $where[] = $fields[0] . '.' . $fields[2];
             break;
     }
     // A hook  to allow pre-processing of custom tables
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['tinymce_rte']['processTableConfiguration'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['tinymce_rte']['processTableConfiguration'] as $_classRef) {
             $_procObj =& t3lib_div::getUserObj($_classRef);
             $tmp = array();
             $tmp = $_procObj->process_table_configuration($table, $row);
             $where = array_merge($where, $tmp);
         }
     }
     return $where;
 }
 /**
  * @return tx_caretakerinstance_OperationManager
  */
 public function getOperationManager()
 {
     if ($this->operationManager == null) {
         $this->operationManager = new tx_caretakerinstance_OperationManager();
         if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['caretaker_instance']['operations'])) {
             foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['caretaker_instance']['operations'] as $key => $operationRef) {
                 if (is_string($operationRef)) {
                     $operation = t3lib_div::getUserObj($operationRef);
                 } elseif ($operationRef instanceof tx_caretakerinstance_IOperation) {
                     $operation = $operationRef;
                 } else {
                     // TODO log error if some strange value is registered
                 }
                 $this->operationManager->registerOperation($key, $operation);
             }
         }
     }
     return $this->operationManager;
 }
示例#23
0
 /**
  * Gets the hooks for the single view.
  *
  * @throws t3lib_exception
  *         if there are registered hook classes that do not implement the
  *         tx_seminars_Interface_Hook_EventSingleView interface
  *
  * @return tx_seminars_Interface_Hook_EventSingleView[]
  *         the hook objects, will be empty if no hooks have been set
  */
 protected function getSingleViewHooks()
 {
     if (!$this->singleViewHooksHaveBeenRetrieved) {
         $hookClasses = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['seminars']['singleView'];
         if (is_array($hookClasses)) {
             foreach ($hookClasses as $hookClass) {
                 $hookInstance = t3lib_div::getUserObj($hookClass);
                 if (!$hookInstance instanceof tx_seminars_Interface_Hook_EventSingleView) {
                     throw new t3lib_exception('The class ' . get_class($hookInstance) . ' is used for the event single view hook, ' . 'but does not implement the tx_seminars_Interface_Hook_EventSingleView interface.', 1306432026);
                 }
                 $this->singleViewHooks[] = $hookInstance;
             }
         }
         $this->singleViewHooksHaveBeenRetrieved = TRUE;
     }
     return $this->singleViewHooks;
 }
    /**
     * Renders header table row with media type and previewer
     *
     * @param	array		$PA An array with additional configuration options.
     * @param	object		$fobj TCEForms object reference
     * @return	string		The HTML code for the TCEform field
     */
    function tx_dam_mediaType($PA, &$fobj)
    {
        global $TCA;
        $this->tceforms =& $PA['pObj'];
        $config = $PA['fieldConf']['config'];
        $row = $PA['row'];
        $table = $PA['table'];
        // TODO overlay all fields to be safe
        foreach (array('media_type', 'file_name', 'file_path', 'file_size', 'hpixels', 'vpixels') as $field) {
            $row[$field] = $this->tceforms->getLanguageOverlayRawValue($table, $row, $field, $TCA[$table]['columns'][$field]);
        }
        $itemMediaInfo = '';
        $itemMediaInfo .= '<div class="tableRow">' . $this->tceforms->sL('LLL:EXT:lang/locallang_general.xml:LGL.title', true) . '<br />' . '<strong>' . htmlspecialchars($row['title']) . '</strong></div>';
        $itemMediaInfo .= '<div class="tableRow">' . $this->tceforms->sL('LLL:EXT:dam/locallang_db.xml:tx_dam_item.file_name', true) . '<br />' . '<strong>' . htmlspecialchars($row['file_name']) . '</strong></div>';
        $itemMediaInfo .= '<div class="tableRow">' . $this->tceforms->sL('LLL:EXT:dam/locallang_db.xml:tx_dam_item.file_path', true) . '<br />' . '<strong>' . htmlspecialchars($row['file_path']) . '</strong></div>';
        if ($row['media_type'] == TXDAM_mtype_image) {
            $out = '';
            $out .= $row['hpixels'] ? $row['hpixels'] . 'x' . $row['vpixels'] . ' px, ' : '';
            $out .= t3lib_div::formatSize($row['file_size']);
            $out .= $row['color_space'] ? ', ' . $this->tceforms->sL(t3lib_befunc::getLabelFromItemlist($PA['table'], 'color_space', $row['color_space']), true) : '';
            $itemMediaInfo .= '<div class="tableRow"><nobr>' . htmlspecialchars($out) . '</nobr></div>';
        }
        $itemMediaTypeIcon = tx_dam_guiFunc::getMediaTypeIconBox($row);
        $itemMediaInfoTable = '
			<table border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td valign="top">' . $itemMediaTypeIcon . '</td>
					<td valign="top" align="left" style="padding-left:25px;">' . $itemMediaInfo . '
					</td>
				</tr>
			</table>';
        $fieldTemplate = '
			<tr>
				<td colspan="2"><img src="clear.gif" width="1" height="5" alt="" /></td>
			</tr>
			<tr>
				<td nowrap="nowrap"><img name="req_###FIELD_TABLE###_###FIELD_ID###_###FIELD_FIELD###" src="clear.gif" width="10" height="10" alt="" /><img name="cm_###FIELD_TABLE###_###FIELD_ID###_###FIELD_FIELD###" src="clear.gif" width="7" height="10" alt="" /></td>
				<td valign="top">###FIELD_ITEM######FIELD_PAL_LINK_ICON###</td>
			</tr>
			<tr>
				<td colspan="2"><img src="clear.gif" width="1" height="15" alt="" /></td>
			</tr>
			';
        $itemMediaInfoTable = $this->tceforms->intoTemplate(array('NAME' => '', 'ID' => $row['uid'], 'FIELD' => $PA['field'], 'TABLE' => $PA['table'], 'ITEM' => $itemMediaInfoTable, 'HELP_ICON' => ''), $fieldTemplate);
        //
        // previewer
        //
        $itemPreviewer = '';
        $headerCode = '';
        $previewer = NULL;
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dam']['previewerClasses'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dam']['previewerClasses'] as $idName => $classRessource) {
                if (is_object($previewer = t3lib_div::getUserObj($classRessource))) {
                    if ($previewer->isValid($row, '200', 'topright')) {
                        $outArr = $previewer->render($row, '200', 'topright');
                        $itemPreviewer = $outArr['htmlCode'];
                        $headerCode = $outArr['headerCode'];
                        break;
                    }
                }
            }
            unset($previewer);
            $previewer = NULL;
        }
        // todo: header code should go into header - really - but how
        //
        // all together now
        //
        $out = '
			<tr>
				<td colspan="2">
					<table border="0" cellpadding="0" cellspacing="0" width="100%">
						<tr>
							<td valign="top">
								<table border="0" cellpadding="0" cellspacing="0">' . $itemMediaInfoTable . '
								</table>
							</td>
							<td width="1%" valign="top" align="center" style="padding: 0px 10px 0px 10px">' . $headerCode . $itemPreviewer . '</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td colspan="2"><img src="clear.gif" width="1" height="5" alt="" /></td>
			</tr>';
        return $out;
    }
 /**
  * This function was called from indexer object and saves content to index table
  *
  * @return string content which will be displayed in backend
  */
 public function startIndexing()
 {
     // get all address records from pid set in indexerConfig
     $fields = '*';
     $table = 'tt_address';
     $indexPids = $this->getPidList($this->indexerConfig['startingpoints_recursive'], $this->indexerConfig['sysfolder'], $table);
     if ($this->indexerConfig['index_use_page_tags']) {
         // add the tags of each page to the global page array
         $this->pageRecords = $this->getPageRecords($indexPids);
         $this->addTagsToRecords($indexPids);
     }
     $where = 'pid IN (' . implode(',', $indexPids) . ') ';
     if (TYPO3_VERSION_INTEGER >= 7000000) {
         $where .= TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields($table);
         $where .= TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table);
     } else {
         $where .= t3lib_befunc::BEenableFields($table);
         $where .= t3lib_befunc::deleteClause($table);
     }
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where);
     $resCount = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
     // no address records found
     if (!$resCount) {
         $content = '<p>No address records found!</p>';
         return $content;
     }
     // if records found: process them
     while ($addressRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         $abstract = '';
         $content = '';
         // set title, use company if set, otherwise name
         $title = !empty($addressRow['company']) ? $addressRow['company'] : (!empty($addressRow['name']) ? $addressRow['name'] : $addressRow['first_name'] . ' ' . $addressRow['last_name']);
         // use description as abstract if set
         if (!empty($addressRow['description'])) {
             $abstract = $addressRow['description'];
         }
         // build content
         if (!empty($addressRow['company'])) {
             $content .= $addressRow['company'] . "\n";
         }
         if (!empty($addressRow['title'])) {
             $content .= $addressRow['title'] . ' ';
         }
         if (!empty($addressRow['name'])) {
             $content .= $addressRow['name'] . "\n";
             // name
         } else {
             if (!empty($addressRow['first_name'])) {
                 $content .= $addressRow['first_name'] . ' ';
             }
             if (!empty($addressRow['middle_name'])) {
                 $content .= $addressRow['middle_name'] . ' ';
             }
             if (!empty($addressRow['last_name'])) {
                 $content .= $addressRow['last_name'] . ' ';
             }
             if (!empty($addressRow['last_name']) || !empty($addressRow['middle_name']) || !empty($addressRow['middle_name'])) {
                 $content .= "\n";
             }
         }
         if (!empty($addressRow['address'])) {
             $content .= $addressRow['address'] . "\n";
         }
         if (!empty($addressRow['zip'])) {
             $content .= $addressRow['zip'] . "\n";
         }
         if (!empty($addressRow['city'])) {
             $content .= $addressRow['city'] . "\n";
         }
         if (!empty($addressRow['country'])) {
             $content .= $addressRow['country'] . "\n";
         }
         if (!empty($addressRow['region'])) {
             $content .= $addressRow['region'] . "\n";
         }
         if (!empty($addressRow['email'])) {
             $content .= $addressRow['email'] . "\n";
         }
         if (!empty($addressRow['phone'])) {
             $content .= $addressRow['phone'] . "\n";
         }
         if (!empty($addressRow['fax'])) {
             $content .= $addressRow['fax'] . "\n";
         }
         if (!empty($addressRow['mobile'])) {
             $content .= $addressRow['mobile'] . "\n";
         }
         if (!empty($addressRow['www'])) {
             $content .= $addressRow['www'];
         }
         // put content together
         $fullContent = $abstract . "\n" . $content;
         // there is no tt_address default param like this; you have to modify this by hook to fit your needs
         $params = '&tt_address[showUid]=' . $addressRow['uid'];
         // no tags yet
         if ($this->indexerConfig['index_use_page_tags']) {
             $tagContent = $this->pageRecords[intval($addressRow['pid'])]['tags'];
         } else {
             $tagContent = '';
         }
         // set additional fields for sorting
         $additionalFields = array('sortdate' => $addressRow['tstamp']);
         // fill orig_uid
         if (isset($addressRow['uid']) && $addressRow['uid'] > 0) {
             $additionalFields['orig_uid'] = $addressRow['uid'];
         }
         // fill orig_pid
         if (isset($addressRow['pid']) && $addressRow['pid'] > 0) {
             $additionalFields['orig_pid'] = $addressRow['pid'];
         }
         // make it possible to modify the indexerConfig via hook
         $indexerConfig = $this->indexerConfig;
         // add some fields which you may set in your own hook
         $customfields = array('sys_language_uid' => 0, 'starttime' => 0, 'endtime' => 0, 'fe_group' => '');
         // hook for custom modifications of the indexed data, e. g. the tags
         if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyAddressIndexEntry'])) {
             foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyAddressIndexEntry'] as $_classRef) {
                 if (TYPO3_VERSION_INTEGER >= 7000000) {
                     $_procObj =& TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef);
                 } else {
                     $_procObj =& t3lib_div::getUserObj($_classRef);
                 }
                 $_procObj->modifyAddressIndexEntry($title, $abstract, $fullContent, $params, $tagContent, $addressRow, $additionalFields, $indexerConfig, $customfields);
             }
         }
         // store in index
         $this->pObj->storeInIndex($indexerConfig['storagepid'], $title, 'tt_address', $indexerConfig['targetpid'], $fullContent, $tagContent, $params, $abstract, $customfields['sys_language_uid'], $customfields['starttime'], $customfields['endtime'], $customfields['fe_group'], false, $additionalFields);
     }
     $content = '<p><b>Indexer "' . $this->indexerConfig['title'] . '": ' . $resCount . ' address records have been indexed.</b></p>' . "\n";
     $content .= $this->showErrors();
     $content .= $this->showTime();
     return $content;
 }
 /**
  * Initialize an object by it's idName
  *
  * @param	string		$idName
  * @return	boolean
  */
 function makeObject($idName)
 {
     if (!isset($this->objects[$idName]) and isset($this->classes[$idName])) {
         if (!is_object($this->objects[$idName] = t3lib_div::getUserObj($this->classes[$idName]))) {
             unset($this->objects[$idName]);
         }
     }
     return is_object($this->objects[$idName]);
 }
 /**
  * Gets all facets with their fields, options, and counts.
  *
  * @return
  */
 public function getFacetCounts()
 {
     static $facetCountsModified = FALSE;
     static $facetCounts = NULL;
     $unmodifiedFacetCounts = $this->solr->getResponse()->facet_counts;
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifyFacets'])) {
         if (!$facetCountsModified) {
             $facetCounts = $unmodifiedFacetCounts;
             foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifyFacets'] as $classReference) {
                 $facetsModifier = t3lib_div::getUserObj($classReference);
                 if ($facetsModifier instanceof tx_solr_FacetsModifier) {
                     $facetCounts = $facetsModifier->modifyFacets($facetCounts);
                     $facetCountsModified = TRUE;
                 } else {
                     // TODO throw exception
                 }
             }
         }
     } else {
         $facetCounts = $unmodifiedFacetCounts;
     }
     return $facetCounts;
 }
 /**
  * puts the fields of an address in markers
  *
  * @param	array	$address: an address record
  * @return	array	a marker array with filled markers acording to the
  * address given
  */
 function getItemMarkerArray($address)
 {
     $markerArray = array();
     //local configuration and local cObj
     $lConf = $this->conf['templates.'][$this->conf['templateName'] . '.'];
     $lcObj = t3lib_div::makeInstance('tslib_cObj');
     $lcObj->data = $address;
     $markerArray['###UID###'] = $address['uid'];
     $markerArray['###GENDER###'] = $lcObj->stdWrap($address['gender'], $lConf['gender.']);
     $markerArray['###FIRSTNAME###'] = $lcObj->stdWrap($address['first_name'], $lConf['first_name.']);
     $markerArray['###MIDDLENAME###'] = $lcObj->stdWrap($address['middle_name'], $lConf['middle_name.']);
     $markerArray['###LASTNAME###'] = $lcObj->stdWrap($address['last_name'], $lConf['last_name.']);
     $markerArray['###TITLE###'] = $lcObj->stdWrap($address['title'], $lConf['title.']);
     $markerArray['###EMAIL###'] = $lcObj->stdWrap($address['email'], $lConf['email.']);
     $markerArray['###PHONE###'] = $lcObj->stdWrap($address['phone'], $lConf['phone.']);
     $markerArray['###MOBILE###'] = $lcObj->stdWrap($address['mobile'], $lConf['mobile.']);
     $markerArray['###WWW###'] = $lcObj->stdWrap($address['www'], $lConf['www.']);
     $markerArray['###ADDRESS###'] = $lcObj->stdWrap($address['address'], $lConf['address.']);
     $markerArray['###BUILDING###'] = $lcObj->stdWrap($address['building'], $lConf['building.']);
     $markerArray['###ROOM###'] = $lcObj->stdWrap($address['room'], $lConf['room.']);
     $markerArray['###BIRTHDAY###'] = $lcObj->stdWrap($address['birthday'], $lConf['birthday.']);
     $markerArray['###ORGANIZATION###'] = $lcObj->stdWrap($address['company'], $lConf['organization.']);
     $markerArray['###COMPANY###'] = $markerArray['###ORGANIZATION###'];
     // alias
     $markerArray['###CITY###'] = $lcObj->stdWrap($address['city'], $lConf['city.']);
     $markerArray['###ZIP###'] = $lcObj->stdWrap($address['zip'], $lConf['zip.']);
     $markerArray['###REGION###'] = $lcObj->stdWrap($address['region'], $lConf['region.']);
     $markerArray['###COUNTRY###'] = $lcObj->stdWrap($address['country'], $lConf['country.']);
     $markerArray['###FAX###'] = $lcObj->stdWrap($address['fax'], $lConf['fax.']);
     $markerArray['###DESCRIPTION###'] = $lcObj->stdWrap($address['description'], $lConf['description.']);
     $markerArray['###MAINGROUP###'] = $lcObj->stdWrap($address['groups'][0]['title'], $lConf['mainGroup.']);
     $markerArray['###GROUPLIST###'] = $lcObj->stdWrap($address['groupList'], $lConf['groupList.']);
     // the image
     $markerArray['###IMAGE###'] = '';
     if (!empty($address['image'])) {
         $iConf = $lConf['image.'];
         $images = explode(',', $address['image']);
         // somehow (at least on my dev machine) the TT_ADDRESS_MAX_IMAGES constant doesn't work here
         for ($i = 0; $i < 6; $i++) {
             $iConf['file'] = 'uploads/pics/' . $images[$i];
             $iConf['altText'] = !empty($iConf['altText']) ? $iConf['altText'] : $address['name'];
             $iConf['titleText'] = !empty($iConf['titleText']) ? $iConf['titleText'] : $address['name'];
             // ensuring compatibility with the ###IMAGE### marker
             $markerArray['###IMAGE' . ($i == 0 ? '' : $i) . '###'] = $lcObj->IMAGE($iConf);
         }
     } elseif (!empty($lConf['placeholderImage'])) {
         // we have no image, but a default image
         $iConf = $lConf['image.'];
         $iConf['file'] = $lcObj->stdWrap($lConf['placeholderImage'], $lConf['placeholderImage.']);
         $iConf['altText'] = !empty($iConf['altText']) ? $iConf['altText'] : $address['name'];
         $iConf['titleText'] = !empty($iConf['titleText']) ? $iConf['titleText'] : $address['name'];
         $markerArray['###IMAGE###'] = $lcObj->IMAGE($iConf);
     }
     // adds hook for processing of extra item markers
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['tt_address']['extraItemMarkerHook'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['tt_address']['extraItemMarkerHook'] as $_classRef) {
             $_procObj =& t3lib_div::getUserObj($_classRef);
             $markerArray = $_procObj->extraItemMarkerProcessor($markerArray, $address, $lConf, $this);
         }
     }
     return $markerArray;
 }
示例#29
0
 /**
  * @param $singlePid
  * @param $row
  * @param $piVarsArray
  * @param bool $urlOnly
  * @return array|string
  */
 function getSingleViewLink(&$singlePid, &$row, $piVarsArray, $urlOnly = false)
 {
     $tmpY = false;
     $tmpM = false;
     $tmpD = false;
     if ($this->conf['useHRDates']) {
         $piVarsArray['pS'] = null;
         $piVarsArray['pL'] = null;
         $piVarsArray['arc'] = null;
         if ($this->conf['useHRDatesSingle']) {
             $tmpY = $this->piVars['year'];
             $tmpM = $this->piVars['month'];
             $tmpD = $this->piVars['day'];
             $this->getHrDateSingle($row['datetime']);
             $piVarsArray['year'] = $this->piVars['year'];
             $piVarsArray['month'] = $this->piVars['month'];
             $piVarsArray['day'] = $this->piVars['day'] ? $this->piVars['day'] : null;
         }
     } else {
         $piVarsArray['year'] = null;
         $piVarsArray['month'] = null;
     }
     $piVarsArray['tt_news'] = $row['uid'];
     $linkWrap = explode($this->token, $this->pi_linkTP_keepPIvars($this->token, $piVarsArray, $this->allowCaching, $this->conf['dontUseBackPid'], $singlePid));
     $url = $this->cObj->lastTypoLinkUrl;
     // hook for processing of links
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['tt_news']['getSingleViewLinkHook'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['tt_news']['getSingleViewLinkHook'] as $_classRef) {
             $_procObj =& t3lib_div::getUserObj($_classRef);
             $params = array('singlePid' => &$singlePid, 'row' => &$row, 'piVarsArray' => $piVarsArray);
             $_procObj->processSingleViewLink($linkWrap, $url, $params, $this);
         }
     }
     $this->local_cObj->LOAD_REGISTER(array('newsMoreLink' => $linkWrap[0] . $this->pi_getLL('more') . $linkWrap[1], 'newsMoreLink_url' => $url), '');
     if ($this->conf['useHRDates'] && $this->conf['useHRDatesSingle']) {
         $this->piVars['year'] = $tmpY;
         $this->piVars['month'] = $tmpM;
         $this->piVars['day'] = $tmpD;
     }
     if ($urlOnly) {
         return $url;
     } else {
         return $linkWrap;
     }
 }
   /**
    * Main method of your PlugIn
    *
    * @param    string    $content: The content of the PlugIn
    * @param    array    $conf: The PlugIn Configuration
    * @return    string    The content that should be displayed on the website
    */
   function main($content, $conf)
   {
       $this->conf = $conf;
       $this->pi_setPiVarDefaults();
       $this->pi_initPIflexForm();
       // Init FlexForm configuration for plugin
       $this->pi_loadLL();
       $this->pi_USER_INT_obj = 1;
       // Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object!
       $thePID = 0;
       // PID of the sysfolder with questions
       $resPID = 0;
       // PID of the sysfolder with results
       $nextPID = 0;
       // PID for forms
       $finalPID = 0;
       // PID for the final page
       $listPID = 0;
       // PID for highscore or poll result
       $startPID = 0;
       // PID of the startpage
       $uid = 0;
       // quiz taker UID?!
       //$firsttime = 0;            // start time of the quiz
       $elapseTime = 0;
       // intval($this->conf['quizTimeMinutes'])*60;            // Verflossene Zeit in Sekunden
       $joker1 = 0;
       // Joker used?
       $joker2 = 0;
       $joker3 = 0;
       $startPage = false;
       // start page which asks only for user data?
       $questionPage = false;
       // question page?
       $answerPage = false;
       // answer page?
       $finalPage = false;
       // final page reached?
       $noQuestions = false;
       // no more questions?
       $secondVisit = false;
       // quiz already solved?
       $sendMail = false;
       // email should be send?
       $error = false;
       // was there an error?
       $nextCat = '';
       // global next category
       $catArray = array();
       // array with category names
       $oldLoaded = false;
       // old data loaded
       // global $TSFE;
       $this->lang = intval($GLOBALS['TSFE']->config['config']['sys_language_uid']);
       $this->copyFlex();
       // copy Felxform-Variables to this->conf
       $this->tableAnswers = $this->conf['tableAnswers'] == 'tx_myquizpoll_voting' ? 'tx_myquizpoll_voting' : 'tx_myquizpoll_result';
       if ($this->conf['enableCaptcha'] && t3lib_extMgm::isLoaded('sr_freecap')) {
           // load Captcha: Anti-Spam-Tool ??? only if enabled (16.10.2009)
           require_once t3lib_extMgm::extPath('sr_freecap') . 'pi2/class.tx_srfreecap_pi2.php';
           $this->freeCap = t3lib_div::makeInstance('tx_srfreecap_pi2');
       }
       // TODO: Rekursiv-Flag berücksichtigen!
       if (!($this->cObj->data['pages'] == '')) {
           // PID (eine oder mehrere)
           $thePID = $this->cObj->data['pages'];
       } elseif (!($this->conf['sysPID'] == '')) {
           $thePID = preg_replace('/[^0-9,]/', '', $this->conf['sysPID']);
       } else {
           $thePID = $GLOBALS["TSFE"]->id;
       }
       $resPID = $this->conf['resultsPID'] ? intval($this->conf['resultsPID']) : $thePID;
       $resPIDs = preg_replace('/[^0-9,]/', '', $resPID);
       // für den Highscore werden ggf. alle PIDs gebraucht
       if (strstr($resPID, ',')) {
           // wenn mehrere Ordner ausgewählt, nimm den ersten
           $tmp = explode(",", $resPID);
           $resPID = intval(trim($tmp[0]));
       }
       $nextPID = $this->conf['nextPID'] ? intval($this->conf['nextPID']) : $GLOBALS['TSFE']->id;
       $finalPID = $this->conf['finalPID'] ? intval($this->conf['finalPID']) : $GLOBALS['TSFE']->id;
       // oder $nextPID;
       $listPID = $this->conf['listPID'] ? intval($this->conf['listPID']) : $GLOBALS['TSFE']->id;
       // oder $finalPID;
       $startPID = intval($this->conf['startPID']);
       if ($this->conf['answerChoiceMax']) {
           // antworten pro fragen
           $this->answerChoiceMax = intval($this->conf['answerChoiceMax']);
       }
       if (!$this->conf['myVars.']['separator']) {
           // separator bei den myVars
           $this->conf['myVars.']['separator'] = ',';
       }
       mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff);
       // Seed random number generator
       //$this->local_cObj = t3lib_div::makeInstance("tslib_cObj");    // Local cObj
       // Get post parameters: Submited Quiz-data
       if ($this->conf['CMD'] == 'archive') {
           $this->conf['ignoreSubmit'] = true;
       }
       // submits in diesen Fällen igonieren
       $quizData = array();
       if (is_array(t3lib_div::_GP($this->prefixId)) && !$this->conf['ignoreSubmit']) {
           if (is_array(t3lib_div::_POST($this->prefixId))) {
               $quizData = t3lib_div::_POST($this->prefixId);
           } else {
               $quizData = t3lib_div::_GET($this->prefixId);
           }
           //$quizData = t3lib_div::slashArray(t3lib_div::GPvar($this->prefixId),"strip"); // deprecated
           if ($quizData['cmd'] == '') {
               $quizData['cmd'] = $this->conf['CMD'];
           } elseif ($quizData['cmd'] == 'allanswers') {
               // or $quizData['cmd']=='score' or $quizData['cmd']=='list'
               $quizData['cmd'] = '';
               // for security reasons we want that users can´t see everything
           }
       } else {
           $quizData['cmd'] = $this->conf['CMD'];
           // get the CMD from the backend
       }
       if ($quizData["name"]) {
           $quizData["name"] = htmlspecialchars($quizData["name"]);
       }
       if ($quizData["email"]) {
           $quizData["email"] = htmlspecialchars($quizData["email"]);
       }
       if ($quizData["homepage"]) {
           $quizData["homepage"] = htmlspecialchars($quizData["homepage"]);
       }
       // Zurück navigieren?
       $back = intval($quizData["back"]);
       $back_hit = intval($quizData["back-hit"]);
       if ($back_hit) {
           $quizData['cmd'] = '';
       }
       $seite = 0;
       if ($this->tableAnswers == 'tx_myquizpoll_voting') {
           $this->conf['allowBack'] = 0;
       }
       // Load template
       $tempPath = $this->initTemplate();
       // Marker values
       $statisticsArray = array();
       $markerArray = array();
       $subpartArray = array();
       $wrappedSubpartArray = array();
       $markerArrayP = array();
       $markerArrayQ = array();
       $markerArrayP["###REF_HIGHSCORE###"] = '';
       $markerArrayP["###REF_HIGHSCORE_URL###"] = '';
       $markerArrayP["###REF_POLLRESULT_URL###"] = '';
       $markerArrayP["###REF_QUIZ_ANALYSIS###"] = '';
       $markerArrayP["###REF_NO_MORE###"] = '';
       $markerArrayP["###REF_ERRORS###"] = '';
       $markerArrayP["###REF_RES_ERRORS###"] = '';
       $markerArrayP["###REF_JOKERS###"] = '';
       $markerArrayP["###REF_QUESTIONS###"] = '';
       $markerArrayP["###REF_QRESULT###"] = '';
       $markerArrayP["###REF_INTRODUCTION###"] = '';
       $markerArrayP["###REF_QPOINTS###"] = '';
       $markerArrayP["###REF_SKIPPED###"] = '';
       $markerArrayP["###REF_NEXT###"] = '';
       $markerArrayP["###REF_POLLRESULT###"] = '';
       $markerArrayP["###SUBMIT_JSC###"] = '';
       $markerArrayP["###PREFIX###"] = $this->prefixId;
       $markerArrayP["###FORM_URL###"] = $this->pi_getPageLink($nextPID);
       $markerArrayP["###NO_NEGATIVE###"] = intval($this->conf['noNegativePoints']);
       $markerArrayP["###REMOTE_IP###"] = intval($this->conf['remoteIP']);
       $markerArrayP["###BLOCK_IP###"] = $this->conf['blockIP'];
       $markerArrayQ["###PREFIX###"] = $this->prefixId;
       $markerArray["###PREFIX###"] = $this->prefixId;
       $markerArray["###FORM_URL###"] = $markerArrayP["###FORM_URL###"];
       $markerArrayP["###VAR_RESPID###"] = $resPID;
       $markerArrayP["###VAR_LANG###"] = $this->lang;
       $markerArrayP["###VAR_NOW###"] = $markerArray["###VAR_NOW###"] = time() + 1;
       // kleiner Zeitvorsprung (Seite muss ja geladen werden)
       $markerArray["###NAME###"] = $this->pi_getLL('name', 'name');
       $markerArray["###EMAIL###"] = $this->pi_getLL('email', 'email');
       $markerArray["###HOMEPAGE###"] = $this->pi_getLL('homepage', 'homepage');
       $markerArray["###GO_ON###"] = $this->pi_getLL('go_on', 'go_on');
       $markerArray["###SUBMIT###"] = $this->pi_getLL('submit', 'submit');
       $markerArray["###RESET###"] = $this->pi_getLL('reset', 'reset');
       $markerArray["###GO_BACK###"] = $this->pi_getLL('back', 'back');
       $markerArray["###CORRECT_ANSWERS###"] = $this->pi_getLL('correct_answers', 'correct_answers');
       $markerArray["###EXPLANATION###"] = $this->pi_getLL('listFieldHeader_explanation', 'listFieldHeader_explanation');
       //$markerArray["###VAR_ADDRESS_UID###"] = $quizData["address_uid"] = 0;
       $markerArray["###VAR_CATEGORY###"] = '';
       $markerArray["###VAR_NEXT_CATEGORY###"] = '';
       $markerArray["###VAR_TOTAL_POINTS###"] = '';
       $markerArray["###VAR_QUESTIONS_CORRECT###"] = '';
       $markerArray["###VAR_QUESTIONS_FALSE###"] = '';
       $markerArray["###VAR_QUESTIONS_ANSWERED###"] = 0;
       //if ($this->conf['enforceSelection']) {
       $markerArrayP["###QUESTION###"] = $this->pi_getLL('listFieldHeader_name', 'listFieldHeader_name');
       $markerArrayP["###MISSING_ANSWER###"] = $this->pi_getLL('missing_answer', 'missing_answer');
       //}
       if ($this->conf['pageTimeSeconds'] || $this->conf['quizTimeMinutes']) {
           $markerArray["###TIME_UP1###"] = $this->pi_getLL('time_up1', 'time_up1');
           $markerArray["###LIMIT1A###"] = $this->pi_getLL('limit1a', 'limit1a');
           $markerArray["###LIMIT1B###"] = $this->pi_getLL('limit1b', 'limit1b');
           $markerArray["###TIME_UP2###"] = $this->pi_getLL('time_up2', 'time_up2');
           $markerArray["###LIMIT2A###"] = $this->pi_getLL('limit2a', 'limit2a');
           $markerArray["###LIMIT2B###"] = $this->pi_getLL('limit2b', 'limit2b');
           $markerArray["###SECONDS###"] = $this->pi_getLL('seconds', 'seconds');
           $markerArray["###MINUTES###"] = $this->pi_getLL('minutes', 'minutes');
       }
       // Link to the Highscore list
       $urlParameters = array("tx_myquizpoll_pi1[cmd]" => "score", "tx_myquizpoll_pi1[qtuid]" => intval($quizData['qtuid']), "no_cache" => "1");
       $markerArray["###HIGHSCORE_URL###"] = $this->pi_linkToPage($this->pi_getLL('highscore_url', 'highscore_url'), $listPID, $target = '', $urlParameters);
       // Jokers and Details
       if ($this->conf['useJokers'] && $this->conf['pageQuestions'] == 1 || $this->conf['showDetailAnswers']) {
           /*
            *  Instantiate the xajax object and configure it
            */
           require_once t3lib_extMgm::extPath('xajax') . 'class.tx_xajax.php';
           // Include xaJax
           $this->xajax = t3lib_div::makeInstance('tx_xajax');
           // Make the instance
           # $this->xajax->setRequestURI('xxx');         // nothing to set, we send to the same URI
           # $this->xajax->decodeUTF8InputOn(); // Decode form vars from utf8 ???
           # $this->xajax->setCharEncoding('utf-8'); // Encode of the response to utf-8 ???
           $this->xajax->setWrapperPrefix($this->prefixId);
           // To prevent conflicts, prepend the extension prefix
           $this->xajax->statusMessagesOff();
           // messages in the status bar?
           $this->xajax->debugOff();
           // Turn only on during testing
           if ($this->conf['useJokers']) {
               $this->xajax->registerFunction(array('getAjaxData', &$this, 'getAjaxData'));
           }
           // Register the names of the PHP functions you want to be able to call through xajax - $xajax->registerFunction(array('functionNameInJavascript', &$object, 'methodName'));
           if ($this->conf['showDetailAnswers']) {
               $this->xajax->registerFunction(array('getAjaxDetails', &$this, 'getAjaxDetails'));
           }
           $this->xajax->processRequests();
           // If this is an xajax request, call our registered function, send output and exit
           $GLOBALS['TSFE']->additionalHeaderData[$this->prefixId . '_2'] = $this->xajax->getJavascript(t3lib_extMgm::siteRelPath('xajax'));
           // Else create javascript and add it to the header output
           $markerArrayJ = array();
           $markerArrayJ["###PREFIX###"] = $this->prefixId;
           $markerArrayJ["###USE_JOKERS###"] = $this->pi_getLL('use_jokers', 'use_jokers');
           $markerArrayJ["###ANSWER_JOKER###"] = $this->pi_getLL('answer_joker', 'answer_joker');
       }
       // Init
       $no_rights = 0;
       // second entry of the quiz taker or not logged in if requiered?
       $captchaError = false;
       // wrong Captcha?
       //        $leftQuestions = 0;        // no. of questions to be shown
       $whereAnswered = '';
       // questions that have been allready answered (UIDs)
       $whereSkipped = '';
       // questions that have been skipped (UIDs)
       $content = '';
       // content to be shown
       $this->helperObj = t3lib_div::makeInstance('tx_myquizpoll_helper', $thePID, $this->lang, $this->answerChoiceMax, $this->tableQuestions, $this->tableAnswers, $this->tableRelation, $this->conf);
       // enable dev logging if set
       if (TYPO3_DLOG || $this->conf['debug']) {
           $this->helperObj->writeDevLog = TRUE;
           t3lib_div::devLog('UID: ' . $this->cObj->data['uid'] . '; language: ' . $this->lang . '; use cookies: ' . $this->conf['useCookiesInDays'] . '; use ip-check: ' . $this->conf['doubleEntryCheck'] . '; path to template: ' . $tempPath, $this->extKey, 0);
       }
       // set some session-variables
       if (!$this->conf['isPoll'] && $quizData['cmd'] == '' && !$quizData['qtuid']) {
           $this->helperObj->setQuestionsVars();
       }
       // what to display?
       switch ($quizData['cmd']) {
           case 'archive':
               if ($this->conf['isPoll']) {
                   /* Display only a list of old polls	*/
                   return $this->pi_wrapInBaseClass($this->showPollArchive($listPID, $thePID, $resPID));
               }
           case 'list':
               if (is_numeric($quizData['qid'])) {
                   /* Display an old poll	*/
                   return $this->pi_wrapInBaseClass($this->showPollResult('', $quizData, $thePID, $resPID));
               }
               // Andere Fälle später entscheiden
       }
       // get the startPID of a solved quiz
       if (!$startPID) {
           $startPID = $this->helperObj->getStartUid($quizData['qtuid']);
       }
       $quiz_name = $this->conf['quizName'];
       if (!$quiz_name) {
           $quiz_name = $this->helperObj->getPageTitle($startPID);
       }
       $markerArrayP["###QUIZ_NAME###"] = $markerArray["###QUIZ_NAME###"] = $quiz_name;
       //if ($this->conf['startCategory']) {        // Kategorie-Namen zwischenspeichern
       $res6 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,name,celement,pagetime', $this->tableCategory, 'pid IN (' . $thePID . ')');
       $catCount = $GLOBALS['TYPO3_DB']->sql_num_rows($res6);
       if ($catCount > 0) {
           while ($row6 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res6)) {
               $catUID = $row6['uid'];
               $this->catArray[$catUID] = array();
               $this->catArray[$catUID]['name'] = $row6['name'];
               $this->catArray[$catUID]['celement'] = $row6['celement'];
               $this->catArray[$catUID]['pagetime'] = $row6['pagetime'];
           }
           if ($this->helperObj->writeDevLog) {
               t3lib_div::devLog($catCount . ' categories found.', $this->extKey, 0);
           }
       }
       $GLOBALS['TYPO3_DB']->sql_free_result($res6);
       //}
       // check, if logged in
       if ($this->conf['loggedInCheck'] && ($quizData['cmd'] != 'score' && $quizData['cmd'] != 'list') && !$GLOBALS['TSFE']->loginUser) {
           $no_rights = 1;
           // noname user is (b)locked now
           $markerArray["###NOT_LOGGEDIN###"] = $this->pi_getLL('not_loggedin', 'not_loggedin');
           $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_NOT_LOGGEDIN###");
           $content .= $this->cObj->substituteMarkerArray($template, $markerArray);
           // Sonderfall !!!
           if ($this->helperObj->writeDevLog) {
               t3lib_div::devLog('Loggin check failes!', $this->extKey, 0);
           }
       }
       $quiz_taker_ip_address = preg_replace('/[^0-9\\.]/', '', $this->helperObj->getRealIpAddr());
       // Ignore all sumbits and old data?
       if (!$this->conf['ignoreSubmit']) {
           // check for second entry ( based on the ip-address )
           if ($this->conf['doubleEntryCheck'] && ($quizData['cmd'] != 'score' && $quizData['cmd'] != 'list') && !$quizData['qtuid'] && $no_rights == 0) {
               $res5 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp, uid', $this->tableAnswers, 'pid=' . $resPID . " AND ip='" . $quiz_taker_ip_address . "' AND sys_language_uid=" . $this->lang, '', 'tstamp DESC', '1');
               $rows = $GLOBALS['TYPO3_DB']->sql_num_rows($res5);
               if ($rows > 0) {
                   // DB entry found for current user?
                   $fetchedRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res5);
                   $dateOld = $fetchedRow['tstamp'];
                   if ($this->helperObj->writeDevLog) {
                       t3lib_div::devLog('Entry found for IP ' . $quiz_taker_ip_address . ': ' . $fetchedRow['uid'], $this->extKey, 0);
                   }
                   $period = intval($this->conf['doubleEntryCheck']);
                   // seconds
                   if ($period < 10000) {
                       $period *= 60 * 60 * 24;
                   }
                   // days
                   //if ($period==1) $period = 50000;        // approx. a half day is the quiz blocked for the same ip-address
                   if (time() - $dateOld < $period) {
                       if ($this->conf['doubleCheckMode'] || $this->conf['secondPollMode']) {
                           $quizData['qtuid'] = intval($fetchedRow['uid']);
                           $quizData['cmd'] = 'next';
                           $quizData['secondVisit'] = 1;
                           $secondVisit = true;
                           if ($this->helperObj->writeDevLog) {
                               t3lib_div::devLog('IP-check: cmd to next changed, because doubleCheckMode=' . $this->conf['doubleCheckMode'] . ', secondPollMode=' . $this->conf['secondPollMode'], $this->extKey, 0);
                           }
                       } else {
                           $no_rights = 1;
                           // user is (b)locked now
                           $markerArray["###DOUBLE_ENTRY###"] = $this->pi_getLL('double_entry', 'double_entry');
                           $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_DOUBLE_ENTRY###");
                           $content .= $this->cObj->substituteMarkerArray($template, $markerArray);
                           // Sonderfall !!!
                           if ($this->helperObj->writeDevLog) {
                               t3lib_div::devLog('User is blocked (ip-check), because doubleCheckMode=' . $this->conf['doubleCheckMode'] . ', secondPollMode=' . $this->conf['secondPollMode'], $this->extKey, 0);
                           }
                       }
                   }
                   $GLOBALS['TYPO3_DB']->sql_free_result($res5);
                   //$oldLoaded = true;
               }
               if ($this->helperObj->writeDevLog) {
                   t3lib_div::devLog('IP check for qtuid=' . $quizData['qtuid'], $this->extKey, 0);
               }
           }
           // check for second entry ( based on the fe_users-id )
           if ($this->conf['loggedInMode'] && ($quizData['cmd'] != 'score' && $quizData['cmd'] != 'list') && !$quizData['qtuid'] && $GLOBALS['TSFE']->loginUser && $this->tableAnswers == 'tx_myquizpoll_result' && $no_rights == 0) {
               $fe_uid = intval($GLOBALS['TSFE']->fe_user->user['uid']);
               $res5 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid, tstamp', $this->tableAnswers, 'pid=' . $resPID . " AND fe_uid={$fe_uid} AND sys_language_uid=" . $this->lang, '', 'tstamp DESC', '1');
               $rows = $GLOBALS['TYPO3_DB']->sql_num_rows($res5);
               if ($rows > 0) {
                   // DB entry found for current user?
                   $fetchedRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res5);
                   if ($this->conf['doubleCheckMode'] || $this->conf['secondPollMode']) {
                       $quizData['qtuid'] = intval($fetchedRow['uid']);
                       $quizData['cmd'] = 'next';
                       $secondVisit = true;
                   } else {
                       $no_rights = 1;
                       // user is (b)locked now
                       $markerArray["###DOUBLE_ENTRY###"] = $this->pi_getLL('double_entry', 'double_entry');
                       $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_DOUBLE_ENTRY###");
                       $content .= $this->cObj->substituteMarkerArray($template, $markerArray);
                       // Sonderfall !!!
                   }
                   $GLOBALS['TYPO3_DB']->sql_free_result($res5);
                   //$oldLoaded = true;
               }
               if ($this->helperObj->writeDevLog) {
                   t3lib_div::devLog('fe_users check for qtuid=' . $quizData['qtuid'], $this->extKey, 0);
               }
           }
           // check if the captcha is OK
           if (($quizData['cmd'] == 'submit' && $this->helperObj->getAskAtQ($quizData['qtuid']) || $quizData["fromStart"] && $this->conf['userData.']['askAtStart'] || $quizData["fromFinal"] && $this->conf['userData.']['askAtFinal']) && is_object($this->freeCap) && $this->conf['enableCaptcha'] && !$this->freeCap->checkWord($quizData['captcha_response']) && $no_rights == 0) {
               if ($quizData["fromStart"] && $startPID != $GLOBALS["TSFE"]->id) {
                   // Weiterleitung zurueck zur Extra-Startseite
                   $this->redirectUrl($startPID, array($this->prefixId . '[name]' => $quizData["name"], $this->prefixId . '[email]' => $quizData["email"], $this->prefixId . '[homepage]' => $quizData["homepage"], $this->prefixId . '[captchaError]' => '1'));
                   break;
                   // hier kommt man eh nie hin...
               }
               if ($quizData["fromFinal"] && $finalPID != $GLOBALS["TSFE"]->id) {
                   // Weiterleitung zurueck zur Extra-Endseite
                   $this->redirectUrl($finalPID, array($this->prefixId . '[qtuid]' => intval($quizData["qtuid"]), $this->prefixId . '[cmd]' => 'next', $this->prefixId . '[name]' => $quizData["name"], $this->prefixId . '[email]' => $quizData["email"], $this->prefixId . '[homepage]' => $quizData["homepage"], $this->prefixId . '[captchaError]' => '1'));
                   break;
                   // hier kommt man eh nie hin...
               }
               $quizData['cmd'] = $quizData["fromStart"] ? '' : 'next';
               // "nochmal" simulieren
               //$quizData['qtuid'] = '';        // wieso wohl???
               $markerArray["###CAPTCHA_NOT_OK###"] = $this->pi_getLL('captcha_not_ok', 'captcha_not_ok');
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_CAPTCHA_NOT_OK###");
               $markerArrayP["###REF_ERRORS###"] .= $this->cObj->substituteMarkerArray($template, $markerArray);
               // instead of $content
               //if ($quizData["fromStart"])
               $quizData["fromStart"] = 0;
               // nichts wurde getan simulieren
               $quizData["fromFinal"] = 0;
               if ($this->helperObj->writeDevLog) {
                   t3lib_div::devLog('captcha check 1 not ok.', $this->extKey, 0);
               }
               $error = true;
               $captchaError = true;
           } else {
               if ($quizData["captchaError"]) {
                   $markerArray["###CAPTCHA_NOT_OK###"] = $this->pi_getLL('captcha_not_ok', 'captcha_not_ok');
                   $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_CAPTCHA_NOT_OK###");
                   $markerArrayP["###REF_ERRORS###"] .= $this->cObj->substituteMarkerArray($template, $markerArray);
                   // instead of $content
                   if ($this->helperObj->writeDevLog) {
                       t3lib_div::devLog('captcha check 2 not ok.', $this->extKey, 0);
                   }
                   $error = true;
                   $captchaError = true;
               }
           }
           // check if used IP is blocked
           if ($quizData['cmd'] == 'submit' && $this->conf['blockIP']) {
               $ips = explode(',', $this->conf['blockIP']);
               foreach ($ips as $aip) {
                   $len = strlen(trim($aip));
                   if (substr($quiz_taker_ip_address, 0, $len) == trim($aip)) {
                       //$markerArray["###IP_BLOCKED###"] = $this->pi_getLL('ip_blocked','ip_blocked');
                       //$template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_IP_BLOCKED###");
                       $markerArrayP["###REF_ERRORS###"] .= 'Your IP is blocked!';
                       //$this->cObj->substituteMarkerArray($template, $markerArray);
                       if ($this->helperObj->writeDevLog) {
                           t3lib_div::devLog('IP ' . $quiz_taker_ip_address . ' blocked!', $this->extKey, 0);
                       }
                       $error = true;
                       $no_rights = 1;
                   }
               }
           }
           // read quiz takers old data
           $answeredQuestions = '';
           // prev. answered Question(s)
           $skipped = '';
           $cids = '';
           $fids = '';
           if (($this->conf['useCookiesInDays'] && !$quizData['qtuid'] || $quizData['cmd'] == 'next' || $quizData['cmd'] == 'submit' && !$this->conf['isPoll'] && ($this->conf['dontShowPoints'] != 1 || $this->conf['quizTimeMinutes'])) && $no_rights == 0) {
               $cookieRead = false;
               if (!$quizData['qtuid'] && $this->conf['useCookiesInDays']) {
                   // !($quizData['cmd']  == 'next' || $quizData['cmd']  == 'submit')) warum das nur? auskommentiert am 27.12.2009
                   $cookieName = $this->getCookieMode($resPID, $thePID);
                   if ($this->conf['allowCookieReset'] && $quizData["resetcookie"]) {
                       setcookie($cookieName, "", time() - 3600);
                       if ($this->helperObj->writeDevLog) {
                           t3lib_div::devLog('Cookie reseted: ' . $cookieName, $this->extKey, 0);
                       }
                   } else {
                       if ($this->conf['useCookiesInDays']) {
                           $quizData['qtuid'] = intval($_COOKIE[$cookieName]);
                           // read quiz taker UID from a cookie
                           if ($quizData['qtuid']) {
                               $cookieRead = true;
                           }
                           if ($this->helperObj->writeDevLog) {
                               t3lib_div::devLog('Cookie read: ' . $cookieName . '=' . $quizData['qtuid'], $this->extKey, 0);
                           }
                           // oder? $HTTP_COOKIE_VARS["myquizpoll".$resPID];    oder?  $GLOBALS["TSFE"]->fe_user->getKey("ses","myquizpoll".$resPID);
                       }
                   }
               }
               if ($quizData['qtuid'] && $this->tableAnswers == 'tx_myquizpoll_result') {
                   // load solved questions and quiz takers name, email, homepage, old points and last time
                   $uid = intval($quizData['qtuid']);
                   $res5 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('name, email, homepage, qids,sids,cids,fids, p_or_a, p_max, percent, o_max, o_percent, firsttime, joker1,joker2,joker3, lastcat,nextcat', $this->tableAnswers, 'uid=' . $uid . ' AND sys_language_uid=' . $this->lang);
                   //.' '.$this->cObj->enableFields($this->tableAnswers), auskommentiert am 7.11.10
                   $rows = $GLOBALS['TYPO3_DB']->sql_num_rows($res5);
                   if ($rows > 0) {
                       // DB entry found for current user?
                       $fetchedRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res5);
                       $answeredQuestions = $fetchedRow['qids'];
                       if (!$this->conf["isPoll"]) {
                           $skipped = $fetchedRow['sids'];
                           $joker1 = $fetchedRow['joker1'];
                           $joker2 = $fetchedRow['joker2'];
                           $joker3 = $fetchedRow['joker3'];
                           $firsttime = intval($fetchedRow['firsttime']);
                           $this->helperObj->setFirstTime($uid, $firsttime);
                           if ($answeredQuestions) {
                               // 2.9.10: beantwortete poll-frage muss man auch speichern???
                               if ($fetchedRow['nextcat']) {
                                   $nextCat = $fetchedRow['nextcat'];
                                   if ($this->conf['startCategory']) {
                                       $this->conf['startCategory'] = $nextCat;
                                   }
                                   // kategorie der naechsten frage...
                               }
                               if ($quizData['cmd'] != 'submit') {
                                   // namen nicht ueberschreiben
                                   $whereAnswered = ' AND uid NOT IN (' . preg_replace('/[^0-9,]/', '', $answeredQuestions) . ')';
                                   // exclude answered questions next time
                                   if (!($quizData["name"] || $quizData["email"] || $quizData["homepage"])) {
                                       $quizData["name"] = $fetchedRow['name'];
                                       // abgesendete daten nicht mit default-werten ueberschreiben!
                                       $quizData["email"] = $fetchedRow['email'];
                                       $quizData["homepage"] = $fetchedRow['homepage'];
                                   }
                                   //$markerArray["###VAR_ADDRESS_UID###"] = $quizData["address_uid"] = $fetchedRow['address_uid'];
                               }
                               $markerArray["###VAR_TOTAL_POINTS###"] = intval($fetchedRow['p_or_a']);
                               // save total points for the case there are no more questions
                               $markerArray["###VAR_TMAX_POINTS###"] = intval($fetchedRow['p_max']);
                               $markerArray["###VAR_TMISSING_POINTS###"] = intval($fetchedRow['p_max']) - intval($fetchedRow['p_or_a']);
                               $markerArray["###VAR_PERCENT###"] = intval($fetchedRow['percent']);
                               $markerArray["###VAR_OMAX_POINTS###"] = intval($fetchedRow['o_max']);
                               $markerArray["###VAR_OVERALL_PERCENT###"] = intval($fetchedRow['o_percent']);
                               $markerArray["###VAR_QUESTIONS_ANSWERED###"] = $fetchedRow['qids'] ? substr_count($fetchedRow['qids'], ',') + 1 : 0;
                               if ($fetchedRow['cids'] || $fetchedRow['fids']) {
                                   // if weglassen?
                                   $markerArray["###VAR_QUESTIONS_CORRECT###"] = $fetchedRow['cids'] ? substr_count($fetchedRow['cids'], ',') + 1 : 0;
                                   $markerArray["###VAR_QUESTIONS_FALSE###"] = $fetchedRow['fids'] ? substr_count($fetchedRow['fids'], ',') + 1 : 0;
                               }
                               $markerArray["###VAR_CATEGORY###"] = $this->catArray[$row['lastcat']]['name'];
                               $markerArray["###VAR_NEXT_CATEGORY###"] = $this->catArray[$row['nextcat']]['name'];
                               $elapseTime = time() - $firsttime;
                           }
                           if ($skipped && $quizData['cmd'] != 'submit') {
                               $whereSkipped = ' AND uid NOT IN (' . preg_replace('/[^0-9,]/', '', $skipped) . ')';
                               // exclude skipped questions next time
                           }
                       }
                       if ($cookieRead) {
                           $secondVisit = true;
                       }
                       // es wurde erfolgreich ein cookie gelesen
                   }
                   $GLOBALS['TYPO3_DB']->sql_free_result($res5);
               } else {
                   if ($quizData['qtuid']) {
                       // load solved poll question from voting-table
                       $uid = intval($quizData['qtuid']);
                       $res5 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('question_id', $this->tableAnswers, 'uid=' . $uid . ' AND sys_language_uid=' . $this->lang);
                       if ($GLOBALS['TYPO3_DB']->sql_num_rows($res5) > 0) {
                           $fetchedRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res5);
                           $answeredQuestions = $fetchedRow['question_id'];
                           if ($cookieRead) {
                               $secondVisit = true;
                           }
                       }
                       $GLOBALS['TYPO3_DB']->sql_free_result($res5);
                   } else {
                       if ($this->conf['quizTimeMinutes'] && $quizData["time"]) {
                           $elapseTime = time() - intval($quizData["time"]);
                           // before saving data
                       }
                   }
               }
               if ($quizData['qtuid'] && $this->conf["isPoll"] && $this->conf["secondPollMode"] == 1) {
                   $quizData['cmd'] = 'list';
                   if ($this->helperObj->writeDevLog) {
                       t3lib_div::devLog("changing to list mode", $this->extKey, 0);
                   }
               }
               if ($quizData['qtuid']) {
                   $oldLoaded = true;
               }
               if ($this->helperObj->writeDevLog) {
                   t3lib_div::devLog("Old data loaded with uid {$uid}: {$answeredQuestions} / {$whereAnswered} / {$whereSkipped}", $this->extKey, 0);
               }
           }
       }
       $markerArrayP["###QTUID###"] = intval($quizData['qtuid']);
       // check, if quiz is cancled
       if ($this->conf['quizTimeMinutes'] && intval($this->conf['quizTimeMinutes']) * 60 - $elapseTime <= 0) {
           // oder $quizData['cancel'] == 1 ) {
           $markerArray["###REACHED1###"] = $this->pi_getLL('reached1', 'reached1');
           $markerArray["###REACHED2###"] = $this->pi_getLL('reached2', 'reached2');
           $markerArray["###SO_FAR_REACHED1###"] = $this->pi_getLL('so_far_reached1', 'so_far_reached1');
           $markerArray["###SO_FAR_REACHED2###"] = $this->pi_getLL('so_far_reached2', 'so_far_reached2');
           $markerArray["###QUIZ_END###"] = $this->pi_getLL('quiz_end', 'quiz_end');
           $markerArray["###RESTART_QUIZ###"] = $this->pi_linkToPage($this->pi_getLL('restart_quiz', 'restart_quiz'), $startPID, $target = '', array());
           $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_END###");
           $content .= $this->cObj->substituteMarkerArray($template, $markerArray);
           // sonderfall !!!
           if ($this->conf['finalWhenCancel']) {
               $noQuestions = true;
           } else {
               if ($this->conf['highscore.']['showAtFinal']) {
                   $quizData['cmd'] = 'score';
                   // show highscore
               } else {
                   $quizData['cmd'] = 'exit';
                   // display no more questions
               }
               $no_rights = 1;
               // cancel all
           }
           if ($this->helperObj->writeDevLog) {
               t3lib_div::devLog("cancel check: {$no_rights}/" . $quizData['cmd'], $this->extKey, 0);
           }
       }
       // show only a start page?
       if ($this->conf['userData.']['askAtStart'] && !$quizData['qtuid'] && !$quizData['cmd'] && !$quizData["fromStart"]) {
           // show only "ask for user data"?
           $startPage = true;
           $quizData['cmd'] = 'start';
       }
       // next page is a page with questions...
       if ($quizData['cmd'] == 'next') {
           $quizData['cmd'] = '';
       }
       if ($quizData['cmd'] == 'submit' && !$this->conf['ignoreSubmit'] && $no_rights == 0) {
           /* ***************************************************** */
           /*
            * Display result page: answers and points
            */
           if (!$this->conf["isPoll"]) {
               // neu seit 20.2.2011
               // Check quiz taker name and email
               if (trim($quizData["name"]) == "") {
                   $quizData["name"] = $this->pi_getLL('no_name', 'no_name');
               }
               if (!t3lib_div::validEmail(trim($quizData["email"]))) {
                   $quizData["email"] = $this->pi_getLL('no_email', 'no_email');
               }
               // Avoid bad characters in database request
               $quiz_taker_name = $GLOBALS['TYPO3_DB']->quoteStr($quizData['name'], $this->tableAnswers);
               $quiz_taker_email = $GLOBALS['TYPO3_DB']->quoteStr($quizData['email'], $this->tableAnswers);
               $quiz_taker_homepage = $GLOBALS['TYPO3_DB']->quoteStr($quizData['homepage'], $this->tableAnswers);
               $markerArray["###REAL_NAME###"] = $quiz_taker_name;
               $markerArray["###REAL_EMAIL###"] = $quiz_taker_email;
               $markerArray["###REAL_HOMEPAGE###"] = $quiz_taker_homepage;
               $markerArray["###RESULT_FOR###"] = $this->pi_getLL('result_for', 'result_for');
               if ($quiz_taker_email == $this->pi_getLL('no_email', 'no_email')) {
                   $quiz_taker_email = '';
               }
               if ($quiz_taker_homepage == $this->pi_getLL('no_homepage', 'no_homepage')) {
                   $quiz_taker_homepage = '';
               }
           }
           $markerArray["###THANK_YOU###"] = $this->pi_getLL('thank_you', 'thank_you');
           if (!$this->conf['isPoll']) {
               $markerArray["###RES_QUESTION_POINTS###"] = $this->pi_getLL('result_question_points', 'result_question_points');
               $markerArray["###VAR_QUESTIONS###"] = $this->helperObj->getQuestionsNo();
               if ($whereAnswered) {
                   $markerArray["###VAR_QUESTION###"] = $this->helperObj->getQuestionNo($whereAnswered);
               } else {
                   $markerArray["###VAR_QUESTION###"] = $this->helperObj->getQuestionNo('-');
               }
           }
           // Begin HTML output
           $template_qr = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QRESULT###");
           // full template
           if (!$this->conf["isPoll"]) {
               // neu seit 20.2.2011
               $template_answer = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QR_CORR###");
               $template_okok = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QR_CORR_ANSW###");
               $template_oknot = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QR_CORR_NOTANSW###");
               $template_notok = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QR_NOTCORR_ANSW###");
               $template_notnot = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QR_NOTCORR_NOTANSW###");
               $template_qr_points = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QR_POINTS###");
               $template_expl = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_EXPLANATION###");
           }
           $template_delimiter = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_DELIMITER###");
           $template_image_begin = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUESTION_IMAGE_BEGIN###");
           $template_image_end = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUESTION_IMAGE_END###");
           // Get the answers from the user
           $answerArray = array();
           $questionNumber = 1;
           $lastUIDs = '';
           $whereUIDs = '';
           $whereCat = '';
           if ($this->conf['onlyCategories']) {
               $whereCat = " AND category IN (" . preg_replace('/[^0-9,]/', '', $this->conf['onlyCategories']) . ")";
           }
           while ($quizData['uid' . $questionNumber]) {
               $answerArray[$questionNumber] = $quizData['uid' . $questionNumber];
               $lastUIDs .= ',' . intval($quizData['uid' . $questionNumber]);
               $questionNumber++;
           }
           $maxQuestions = $questionNumber - 1;
           if ($lastUIDs) {
               $whereUIDs = ' AND uid IN (' . substr($lastUIDs, 1) . ')';
               //}    // kgb: geaendert am 6.9.2010
               // Get questions from the database
               $questionsArray = array();
               $tempNumber = 0;
               $res5 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->tableQuestions, 'pid IN (' . $thePID . ')' . $whereUIDs . $whereCat . ' AND sys_language_uid=' . $this->lang . ' ' . $this->cObj->enableFields($this->tableQuestions));
               $rows = $GLOBALS['TYPO3_DB']->sql_num_rows($res5);
               if ($rows > 0) {
                   while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res5)) {
                       $tempNumber = $row['uid'];
                       // save the uid for each question
                       $questionsArray[$tempNumber] = $row;
                       // save each question
                   }
               }
               $GLOBALS['TYPO3_DB']->sql_free_result($res5);
           }
           $points = 0;
           // points from the user (quiz taker)
           $maxPoints = 0;
           // maximum points reachable per page
           $maxTotal = 0;
           // maximum total points reachable
           $percent = 0;
           // 100 * reached points / total points
           $overallMaximum = 0;
           // overall points of all questions
           $overallPercent = 0;
           // overall percent
           $questionUID = 0;
           // uid of a question
           $answered = '';
           // uids of answered questions
           $skipped = '';
           // uids of skipped questions
           $correctAnsw = '';
           // uids of correct answered question
           $falseAnsw = '';
           // uids of false answered question
           $skippedCount = 0;
           // no. of skipped questions at this page
           $imgTSConfig = array();
           // image values
           if (is_array($this->conf['jokers.'])) {
               $halvePoints = $this->conf['jokers.']['halvePoints'];
           } else {
               $halvePoints = 0;
           }
           // Old questions and answers
           for ($questionNumber = 1; $questionNumber < $maxQuestions + 1; $questionNumber++) {
               $questionUID = intval($answerArray[$questionNumber]);
               $row = $questionsArray[$questionUID];
               $markerArray["###VAR_QUESTION_NUMBER###"] = $questionNumber;
               if ($this->conf['isPoll']) {
                   // link to the result page
                   $urlParameters = array("tx_myquizpoll_pi1[cmd]" => "list", "tx_myquizpoll_pi1[qid]" => $questionUID, "no_cache" => "1");
                   $markerArray["###POLLRESULT_URL###"] = $this->pi_linkToPage($this->pi_getLL('poll_url', 'poll_url'), $listPID, $target = '', $urlParameters);
               } else {
                   if ($quizData['answer' . $questionNumber] == -1) {
                       $skipped .= ',' . $questionUID;
                       $skippedCount++;
                       continue;
                   }
               }
               //$answerPointsBool = false;
               $answered .= ',' . $questionUID;
               // nach unten geschoben...
               $questionPoints = 0;
               $maxQuestionPoints = 0;
               $markerArray["###VAR_QUESTION###"]++;
               $nextCat = '';
               $lastCat = $row['category'];
               if ($this->catArray[$lastCat]) {
                   $markerArray["###VAR_CATEGORY###"] = $this->catArray[$lastCat]['name'];
               }
               // Output the result/explanations
               if (!($this->conf['dontShowCorrectAnswers'] && $this->conf['dontShowPoints'] == 1) || $this->conf['startCategory'] || $this->conf['advancedStatistics'] || $this->conf['showAllCorrectAnswers'] || $this->conf['isPoll']) {
                   if ($row['image']) {
                       // && (substr_count($template_qr, 'REF_QUESTION_IMAGE_BEGIN')>0)) {
                       $markerArray["###VAR_QUESTION_IMAGE###"] = $this->helperObj->getImage($row['image'], $row["alt_text"]);
                       $markerArray["###REF_QUESTION_IMAGE_BEGIN###"] = $this->cObj->substituteMarkerArray($template_image_begin, $markerArray);
                       $markerArray["###REF_QUESTION_IMAGE_END###"] = $template_image_end;
                   } else {
                       $markerArray["###REF_QUESTION_IMAGE_BEGIN###"] = '';
                       $markerArray["###REF_QUESTION_IMAGE_END###"] = '';
                   }
                   $markerArray["###TITLE_HIDE###"] = $row['title_hide'] ? '-hide' : '';
                   $markerArray["###VAR_QUESTION_TITLE###"] = $row['title'];
                   $markerArray["###VAR_QUESTION_NAME###"] = $this->formatStr($row['name']);
                   // $this->pi_RTEcssText($row['name']);
                   $markerArray["###VAR_ANSWER_POINTS###"] = '';
                   $markerArray["###REF_QR_ANSWER_ALL###"] = '';
                   $markerArray["###REF_QR_ANSWER_CORR###"] = '';
                   $markerArray["###REF_QR_ANSWER_CORR_ANSW###"] = '';
                   $markerArray["###REF_QR_ANSWER_CORR_NOTANSW###"] = '';
                   $markerArray["###REF_QR_ANSWER_NOTCORR_ANSW###"] = '';
                   $markerArray["###REF_QR_ANSWER_NOTCORR_NOTANSW###"] = '';
                   $markerArray["###REF_QR_POINTS###"] = '';
                   $markerArray["###VAR_QUESTION_ANSWER###"] = '';
                   $markerArray["###REF_QR_EXPLANATION###"] = '';
                   $markerArray["###REF_DELIMITER###"] = '';
                   $markerArray["###P1###"] = '';
                   $markerArray["###P2###"] = '';
                   if ($this->conf['dontShowPoints']) {
                       $markerArray["###NO_POINTS###"] = '';
                   } else {
                       $markerArray["###NO_POINTS###"] = '0';
                   }
                   if (!$this->conf['isPoll']) {
                       if (!$this->conf['dontShowPoints'] && $row['qtype'] < 5) {
                           $markerArray["###P1###"] = $this->pi_getLL('p1', 'p1');
                           $markerArray["###P2###"] = $this->pi_getLL('p2', 'p2');
                       }
                       /*    if ($this->conf['noNegativePoints']<3) {        // 20.01.10: wenn alle antworten richtig sein muessen, antwort-punkte ignorieren!
                                 for ($currentValue=1; $currentValue <= $this->answerChoiceMax; $currentValue++) {
                                     if (intval($row['points'.$currentValue])>0 ) {
                                         $answerPointsBool = true;
                                         break;        // Punkte bei Antworten gefunden...
                                     }
                                 }
                             }  am 21.01.10 auskommentiert! */
                   } else {
                       $points = $quizData['answer' . $questionNumber];
                       // points = SELECTED ANSWER !!!
                       $markerArray["###VAR_USER_ANSWER###"] = $row['answer' . $points];
                       if ($points > 0 && $row['category' . $points]) {
                           // NEU && $this->conf['startCategory']
                           $nextCat = $row['category' . $points];
                           // next category from an answer
                       }
                       break;
                       // mehr braucht man nicht bei Umfragen !!!
                   }
                   // myVars for questions
                   $markerArray = array_merge($markerArray, $this->helperObj->setQuestionVars($questionNumber));
                   $allAnswersOK = true;
                   // alle Antworten richtig beantwortet?
                   //$correctBool = false;    // gibt es ueberhaupt korrekte antworten?
                   $realCorrectBool = false;
                   // wurden ueberhaupt korrekte Antworten markiert?
                   $withAnswer = $this->conf['noAnswer'];
                   // gab es eine Antwort vom Benutzer?
                   $lastSelected = 0;
                   for ($answerNumber = 1; $answerNumber < $this->answerChoiceMax + 1; $answerNumber++) {
                       if ($row['answer' . $answerNumber] || $row['answer' . $answerNumber] === '0' || in_array($row['qtype'], $this->textType)) {
                           // was a answer set in the backend?
                           $selected = 0;
                           // was the answer selected by the quiz taker?
                           $tempAnswer = '';
                           // text for answer $answerNumber
                           // myVars for answers
                           $markerArray = array_merge($markerArray, $this->helperObj->setAnswerVars($answerNumber, $row['qtype']));
                           //if ( !$this->conf['isPoll'] ) {    // show correct answers. Bug fixed: dontShowCorrectAnswers doesnt matter here
                           if (!$this->conf['dontShowCorrectAnswers']) {
                               $markerArray["###VAR_QUESTION_ANSWER###"] = $row['answer' . $answerNumber];
                           }
                           $thisCat = $row['category' . $answerNumber];
                           if ($this->catArray[$thisCat]) {
                               $markerArray['###VAR_QA_CATEGORY###'] = $this->catArray[$thisCat]['name'];
                           }
                           if ($row['correct' . $answerNumber]) {
                               // es gibt richtige Antworten
                               $realCorrectBool = true;
                           }
                           $answerPoints = 0;
                           // answer points from the DB
                           if (!$this->conf['dontShowPoints']) {
                               //if ($answerPointsBool) {         // hier interessiert es nicht, ob eine Antwort als korrekt markiert wurde!
                               if ($this->conf['noNegativePoints'] < 3) {
                                   // das ganze Verhalten am 21.01.10 geaendert...
                                   $answerPoints = intval($row['points' . $answerNumber]);
                               }
                               if ($answerPoints > 0) {
                                   $row['correct' . $answerNumber] = true;
                                   // ACHTUNG: falls Punkte zu einer Antwort gesetzt sind, dann wird die Antwort als RICHTIG bewertet!
                               } else {
                                   $answerPoints = intval($row['points']);
                               }
                               if ($row['correct' . $answerNumber] || $row['qtype'] == 3) {
                                   if (($row['qtype'] == 0 || $row['qtype'] == 4) && $this->conf['noNegativePoints'] < 3) {
                                       // KGB, 20.01.10: weg: !$answerPointsBool || $row['qtype'] >= 3, neu: $this->conf['noNegativePoints']<3
                                       $maxQuestionPoints += $answerPoints;
                                   } else {
                                       if ($answerPoints > $maxQuestionPoints) {
                                           $maxQuestionPoints = $answerPoints;
                                       }
                                   }
                                   // bei punkten pro antwort ODER wenn nicht addiert werden soll
                               }
                               if ($row['qtype'] < 5) {
                                   $markerArray["###VAR_ANSWER_POINTS###"] = $answerPoints;
                               }
                           }
                           if ($quizData['answer' . $questionNumber . '_' . $answerNumber]) {
                               // !='') {    // type 0 und 4
                               $selected = $answerNumber;
                           } else {
                               if (($row['qtype'] > 0 && $row['qtype'] < 3 || $row['qtype'] == 7) && $quizData['answer' . $questionNumber] == $answerNumber) {
                                   $selected = $answerNumber;
                               } else {
                                   if ($row['qtype'] == 3 && $quizData['answer' . $questionNumber] != '' || $row['qtype'] == 5) {
                                       // type 3 und 5
                                       $selected = $answerNumber;
                                       // sollte 1 sein
                                   }
                               }
                           }
                           //}
                           $wrongText = 0;
                           // wrong text input?
                           /*                            if ($this->conf['isPoll']) {    // wurde aus der Schleife genommen!
                                                           $points=$quizData['answer'.$questionNumber];                        // points = SELECTED ANSWER !!!
                                                           $markerArray["###VAR_USER_ANSWER###"] .= $row['answer'.$points];
                                                       } else */
                           if ($row['qtype'] == 5 && !$this->conf['dontShowCorrectAnswers']) {
                               $markerArray["###VAR_QUESTION_ANSWER###"] = nl2br(htmlspecialchars($quizData['answer' . $questionNumber]));
                               $tempAnswer = $this->cObj->substituteMarkerArray($template_okok, $markerArray);
                               $markerArray["###REF_QR_ANSWER_CORR_ANSW###"] .= $tempAnswer;
                               // welches template soll man hier wohl nehmen?
                               if ($quizData['answer' . $questionNumber] || $quizData['answer' . $questionNumber] === 0) {
                                   $withAnswer = true;
                               }
                               if ($this->helperObj->writeDevLog) {
                                   t3lib_div::devLog($questionUID . '-' . $answerNumber . '=CORR_ANSW5->', $this->extKey, 0);
                               }
                           } else {
                               if ($selected > 0 && ($row['qtype'] == 3 && strtolower($row['answer' . $answerNumber]) == strtolower($quizData['answer' . $questionNumber]) || $row['qtype'] != 3 && $row['correct' . $answerNumber])) {
                                   // korrekte Antwort
                                   $questionPoints = $questionPoints + $answerPoints;
                                   // $row['points']; geaendert am 16.9.2009
                                   if (!$this->conf['dontShowCorrectAnswers']) {
                                       $tempAnswer = $this->cObj->substituteMarkerArray($template_okok, $markerArray);
                                       $markerArray["###REF_QR_ANSWER_CORR_ANSW###"] .= $tempAnswer;
                                   }
                                   //$correctBool = true;
                                   $withAnswer = true;
                                   if ($this->helperObj->writeDevLog) {
                                       t3lib_div::devLog($questionUID . '-' . $answerNumber . '=CORR_ANSW->' . $questionPoints, $this->extKey, 0);
                                   }
                               } else {
                                   if ($selected > 0) {
                                       // falsche Antwort
                                       $allAnswersOK = false;
                                       if ($this->conf['noNegativePoints'] != 2) {
                                           $questionPoints = $questionPoints - $answerPoints;
                                       }
                                       // $row['points']; geaendert am 16.9.2009
                                       if (!$this->conf['dontShowCorrectAnswers']) {
                                           // { added 8.8.09
                                           if ($row['qtype'] == 3) {
                                               // since 0.1.8: falsche und richtige antwort ausgeben
                                               $tempAnswer = $this->cObj->substituteMarkerArray($template_oknot, $markerArray);
                                               $markerArray["###REF_QR_ANSWER_CORR_NOTANSW###"] .= $tempAnswer;
                                               $markerArray["###VAR_QUESTION_ANSWER###"] = htmlspecialchars($quizData['answer' . $questionNumber]);
                                           }
                                           $tempAnswer2 = $this->cObj->substituteMarkerArray($template_notok, $markerArray);
                                           $markerArray["###REF_QR_ANSWER_NOTCORR_ANSW###"] .= $tempAnswer2;
                                           $tempAnswer .= $tempAnswer2;
                                           // hier gibt es 2 antworten !!!
                                       }
                                       if ($row['qtype'] == 3 && ($row['answer1'] || $row['answer1'] === '0')) {
                                           $wrongText = 1;
                                       }
                                       // for statistics: a2 statt a1 bei falscher antwort
                                       $withAnswer = true;
                                       if ($this->helperObj->writeDevLog) {
                                           t3lib_div::devLog($questionUID . '-' . $answerNumber . '=NOTCORR_ANSW->' . $questionPoints, $this->extKey, 0);
                                       }
                                   } else {
                                       if ($row['correct' . $answerNumber]) {
                                           // nicht beantwortet, waere aber richtig gewesen
                                           $allAnswersOK = false;
                                           if (!$this->conf['dontShowCorrectAnswers']) {
                                               // hierhin verschoben am 24.1.10
                                               $tempAnswer = $this->cObj->substituteMarkerArray($template_oknot, $markerArray);
                                               $markerArray["###REF_QR_ANSWER_CORR_NOTANSW###"] .= $tempAnswer;
                                           }
                                           if ($row['qtype'] == 3 && ($row['answer1'] || $row['answer1'] === '0')) {
                                               $wrongText = 1;
                                               // for statistics: a2 statt a1 bei falscher antwort
                                               $selected = 2;
                                               // statistics: no answer = false answer !
                                           }
                                           //$correctBool = true;
                                           if ($this->helperObj->writeDevLog) {
                                               t3lib_div::devLog($questionUID . '-' . $answerNumber . '=CORR_NOTANSW->', $this->extKey, 0);
                                           }
                                       } else {
                                           if (!$this->conf['dontShowCorrectAnswers']) {
                                               $tempAnswer = $this->cObj->substituteMarkerArray($template_notnot, $markerArray);
                                               $markerArray["###REF_QR_ANSWER_NOTCORR_NOTANSW###"] .= $tempAnswer;
                                               if ($this->helperObj->writeDevLog) {
                                                   t3lib_div::devLog($questionUID . '-' . $answerNumber . '=NOTCORR_NOTANSW->', $this->extKey, 0);
                                               }
                                           }
                                       }
                                   }
                               }
                           }
                           if (!$this->conf['dontShowCorrectAnswers']) {
                               // !$this->conf['isPoll'] &&
                               $markerArray["###REF_QR_ANSWER_ALL###"] .= $tempAnswer;
                               // all answers in correct order
                               if ($row['correct' . $answerNumber] || $row['qtype'] == 3 || $row['qtype'] == 5) {
                                   // all correct answers
                                   $markerArray["###REF_QR_ANSWER_CORR###"] .= $this->cObj->substituteMarkerArray($template_answer, $markerArray);
                               }
                           }
                           if ($this->conf['advancedStatistics'] && $withAnswer) {
                               // for more statistics  && !$this->conf['isPoll']
                               $statisticsArray[$questionUID]['a' . ($answerNumber + $wrongText)] = $selected > 0 ? 1 : 0;
                               if (($row['qtype'] == 3 || $row['qtype'] == 5) && ($quizData['answer' . $questionNumber] || $quizData['answer' . $questionNumber] === '0')) {
                                   $statisticsArray[$questionUID]['text'] = $GLOBALS['TYPO3_DB']->quoteStr($quizData['answer' . $questionNumber], $this->tableRelation);
                               } else {
                                   $statisticsArray[$questionUID]['text'] = '';
                               }
                           }
                           if ($selected > 0 && $row['category' . $selected]) {
                               // && $this->conf['startCategory']
                               $nextCat = $row['category' . $selected];
                               // next category from an answer
                           }
                           if ($selected > 0) {
                               $lastSelected = $selected;
                           }
                       }
                       if (in_array($row['qtype'], $this->textType)) {
                           break 1;
                       }
                       // nur erste Antwort ist hier moeglich
                   }
                   if ($catCount > 0) {
                       // $this->conf['startCategory']
                       if (!$nextCat) {
                           $nextCat = $row['category_next'];
                       }
                       // next category of this question
                       if ($this->conf['advancedStatistics'] && $withAnswer) {
                           $statisticsArray[$questionUID]['nextCat'] = $nextCat;
                       }
                   }
                   if (!$this->conf['dontShowPoints']) {
                       // Bug fixed: dontShowCorrectAnswers doesnt matter here  && !$this->conf['isPoll']
                       if ($questionPoints < 0 && $this->conf['noNegativePoints']) {
                           $questionPoints = 0;
                       }
                       // keine neg. Punkte
                       if ($questionPoints > 0 && $this->conf['noNegativePoints'] == 3) {
                           if (!$allAnswersOK) {
                               $questionPoints = 0;
                           } else {
                               $questionPoints = $answerPoints;
                           }
                           // KGB, 19.01.10: nur maximale Punkte vergeben, nicht pro Antwort
                       }
                       if ($this->conf['noNegativePoints'] == 4) {
                           // Punkte nur, wenn alles OK war
                           if ($allAnswersOK) {
                               $questionPoints = 0;
                           } else {
                               $questionPoints = $answerPoints;
                           }
                       }
                       if ($questionPoints > 0 && $halvePoints && ($quizData["joker1"] || $quizData["joker2"] || $quizData["joker3"])) {
                           $questionPoints = intval($questionPoints / 2);
                       }
                       // halbe Punkte nach Joker-Benutzung
                       $points += $questionPoints;
                       $maxPoints += $maxQuestionPoints;
                       if ($this->conf['advancedStatistics'] && $withAnswer) {
                           $statisticsArray[$questionUID]['points'] = $questionPoints;
                       }
                   } else {
                       if ($this->conf['advancedStatistics'] && $withAnswer) {
                           $statisticsArray[$questionUID]['points'] = 0;
                       }
                       /*    if ($this->conf['dontShowPoints']==2){    // TODO: eine unausgereifte Idee
                                 $cat = ($allAnswersOK) ? $nextCat : $row['category'];
                                 $points=intval('/,|\./', '', $this->catArray[$cat]['name']);    // katgorie in punkte umwandeln
                             } */
                   }
                   // 20.4.10: $correctBool ersetzt durch:
                   if ($realCorrectBool && $withAnswer) {
                       // falls es richtige antworten gibt, merken welche man richtig/falsch beantwortet hat
                       if ($allAnswersOK) {
                           $correctAnsw .= ',' . $questionUID;
                           if ($this->helperObj->writeDevLog) {
                               t3lib_div::devLog($questionUID . ' correct.', $this->extKey, 0);
                           }
                       } else {
                           $falseAnsw .= ',' . $questionUID;
                           if ($this->helperObj->writeDevLog) {
                               t3lib_div::devLog($questionUID . ' not correct.', $this->extKey, 0);
                           }
                       }
                   } else {
                       if ($this->helperObj->writeDevLog) {
                           t3lib_div::devLog($questionUID . ' not counted.', $this->extKey, 0);
                       }
                   }
                   if (!$this->conf['dontShowCorrectAnswers']) {
                       //  && !$this->conf['isPoll']
                       if (!$this->conf['dontShowPoints'] && $row['qtype'] < 5) {
                           $markerArray["###VAR_QUESTION_POINTS###"] = $questionPoints;
                           $markerArray["###VAR_MAX_QUESTION_POINTS###"] = $maxQuestionPoints;
                           $markerArray["###REF_QR_POINTS###"] = $this->cObj->substituteMarkerArray($template_qr_points, $markerArray);
                       } else {
                           $markerArray["###VAR_QUESTION_POINTS###"] = '';
                           $markerArray["###VAR_MAX_QUESTION_POINTS###"] = '';
                       }
                       if ($row['explanation'] != '' || $row['explanation1'] != '' || $row['explanation2'] != '') {
                           // Explanation
                           $markerArray["###VAR_EXPLANATION###"] = '';
                           if ($row['explanation1'] != '') {
                               // Nur wenn das addon myquizpoll_expl2 installiert ist
                               $markerArray["###VAR_EXPLANATION###"] = $lastSelected && $row['explanation' . $lastSelected] ? $this->formatStr($row['explanation' . $lastSelected]) : $this->formatStr($row['explanation']);
                           } else {
                               if ($row['explanation2'] != '') {
                                   // Nur wenn das addon myquizpoll_expl installiert ist
                                   $markerArray["###VAR_EXPLANATION###"] = $allAnswersOK ? $this->formatStr($row['explanation']) : $this->formatStr($row['explanation2']);
                               } else {
                                   $markerArray["###VAR_EXPLANATION###"] = $this->formatStr($row['explanation']);
                               }
                           }
                           if ($markerArray["###VAR_EXPLANATION###"]) {
                               $markerArray["###REF_QR_EXPLANATION###"] = $this->cObj->substituteMarkerArray($template_expl, $markerArray);
                           } else {
                               $markerArray["###REF_QR_EXPLANATION###"] = '';
                           }
                       }
                       $markerArray["###REF_DELIMITER###"] = $this->cObj->substituteMarkerArray($template_delimiter, $markerArray);
                   }
               }
               if (!$this->conf['dontShowCorrectAnswers']) {
                   // bug fixed: points dont even matter  && !$this->conf['isPoll']
                   $markerArrayP["###REF_QRESULT###"] .= $this->cObj->substituteMarkerArray($template_qr, $markerArray);
               }
           }
           // hier wurde mal REF_INTRODUCTION befüllt
           if ($answered) {
               $answered = substr($answered, 1);
           }
           // now answered questions (UIDs)
           if ($skipped) {
               $skipped = substr($skipped, 1);
           }
           // now skipped questions (UIDs)
           if ($correctAnsw) {
               $correctAnsw = substr($correctAnsw, 1);
           }
           if ($falseAnsw) {
               $falseAnsw = substr($falseAnsw, 1);
           }
           $doUpdate = 0;
           // insert or update?
           $pointsTotal = $points;
           // total points, reached
           $maxTotal = $maxPoints;
           // total points, maximum
           $markerArray["###VAR_NEXT_CATEGORY###"] = $this->catArray[$nextCat]['name'];
           //if ($this->conf['pageQuestions'] > 0 && !$this->conf['isPoll']) {    // more questions aviable? // auskommentiert am 27.12.2009, denn der Cheat-Test muss immer kommen!
           if (!$this->conf['showAnswersSeparate']) {
               $quizData['cmd'] = '';
           }
           // show more/next questions!
           // Seek for old answered questions
           if ($quizData['qtuid'] && !$this->conf['isPoll']) {
               $uid = intval($quizData['qtuid']);
               $res5 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('qids,cids,fids,sids, p_or_a, p_max, joker1,joker2,joker3', $this->tableAnswers, 'uid=' . $uid . ' AND sys_language_uid=' . $this->lang);
               //.' '.$this->cObj->enableFields($this->tableAnswers), auskommentiert am 7.11.10
               $rows = $GLOBALS['TYPO3_DB']->sql_num_rows($res5);
               if ($rows > 0) {
                   // DB entry found for current user?
                   $fetchedRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res5);
                   $answeredOld = $fetchedRow['qids'];
                   $correctOld = $fetchedRow['cids'];
                   $falseOld = $fetchedRow['fids'];
                   $skippedOld = $fetchedRow['sids'];
                   $pointsOld = $fetchedRow['p_or_a'];
                   $maxPointsOld = $fetchedRow['p_max'];
                   $joker1 = $fetchedRow['joker1'];
                   $joker2 = $fetchedRow['joker2'];
                   $joker3 = $fetchedRow['joker3'];
                   if ($correctOld && $correctAnsw) {
                       $correctAnsw = $correctOld . ',' . $correctAnsw;
                   } else {
                       if ($correctOld) {
                           $correctAnsw = $correctOld;
                       }
                   }
                   if ($falseOld && $falseAnsw) {
                       $falseAnsw = $falseOld . ',' . $falseAnsw;
                   } else {
                       if ($falseOld) {
                           $falseAnsw = $falseOld;
                       }
                   }
                   if (!$answered) {
                       // all questions skipped  # Fall 1: bisher nur geskipped
                       $answered = $answeredOld;
                       // all answered questions
                       if ($skippedOld && $skipped) {
                           $skipped = $skippedOld . ',' . $skipped;
                       } else {
                           if ($skippedOld) {
                               $skipped = $skippedOld;
                           }
                       }
                       $pointsTotal = $pointsOld;
                       // total points
                       $maxTotal = $maxPointsOld;
                       //if ($answeredOld) $doUpdate=1;
                       $doUpdate = 3;
                       if ($this->helperObj->writeDevLog) {
                           t3lib_div::devLog("do=3, points={$pointsTotal}, max={$maxTotal}", $this->extKey, 0);
                       }
                   } else {
                       if (stristr(',' . $answeredOld . ',', ',' . $answered . ',')) {
                           // Fall 2: somebody tries to cheat!
                           $answered = $answeredOld;
                           // all answered questions
                           $skipped = $skippedOld;
                           // all skipped questions
                           $pointsTotal = $pointsOld;
                           // total points
                           $maxTotal = $maxPointsOld;
                           if ($back > 0) {
                               $doUpdate = 1;
                               // back-seite: update mit alten daten
                           } else {
                               $doUpdate = 2;
                               $error = true;
                               $markerArray["###CHEATING###"] = $this->pi_getLL('cheating', 'cheating');
                               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_CHEATING###");
                               $markerArrayP["###REF_RES_ERRORS###"] .= $this->cObj->substituteMarkerArray($template, $markerArray);
                               if ($this->helperObj->writeDevLog) {
                                   t3lib_div::devLog("Cheating error!", $this->extKey, 0);
                               }
                               /*$tempTime = $this->helperObj->getPageTime($quizData['qtuid']);
                                 if ($tempTime) {
                                     $markerArrayP["###VAR_NOW###"] = $markerArray["###VAR_NOW###"] = $tempTime;
                                 }*/
                           }
                           if ($this->helperObj->writeDevLog) {
                               t3lib_div::devLog("do=2, points={$pointsTotal}, max={$maxTotal}", $this->extKey, 0);
                           }
                       } else {
                           if ($answeredOld) {
                               // Fall 3: man hat schon was beantwortet
                               $answered = $answeredOld . ',' . $answered;
                               // all answered questions
                               if ($skippedOld && $skipped) {
                                   $skipped = $skippedOld . ',' . $skipped;
                               } else {
                                   if ($skippedOld) {
                                       $skipped = $skippedOld;
                                   }
                               }
                               $pointsTotal = $points + $pointsOld;
                               // total points
                               //$maxTotal = $maxPoints;
                               if ($maxPointsOld > 0) {
                                   $maxTotal += $maxPointsOld;
                               }
                               $doUpdate = 1;
                               if ($this->helperObj->writeDevLog) {
                                   t3lib_div::devLog("do=1, points={$pointsTotal}, max={$maxTotal}", $this->extKey, 0);
                               }
                           } else {
                               if ($skippedOld) {
                                   // Fall 4: skipped, dann beantwortet
                                   if ($skippedOld && $skipped) {
                                       $skipped = $skippedOld . ',' . $skipped;
                                   } else {
                                       $skipped = $skippedOld;
                                   }
                                   $pointsTotal = $points;
                                   // total points
                                   $doUpdate = 1;
                               }
                           }
                       }
                   }
               }
           }
           $whereAnswered = '';
           if ($answered) {
               $whereAnswered = ' AND uid NOT IN (' . preg_replace('/[^0-9,]/', '', $answered) . ')';
           }
           // exclude answered questions next time
           $whereSkipped = '';
           if ($skipped) {
               $whereSkipped = ' AND uid NOT IN (' . preg_replace('/[^0-9,]/', '', $skipped) . ')';
           }
           // exclude skipped questions next time
           if ($skippedCount > 0) {
               $markerArray["###VAR_NO###"] = $skippedCount;
               $markerArray["###SKIPPED###"] = $this->pi_getLL('skipped', 'skipped');
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_SKIPPED###");
               $markerArrayP["###REF_SKIPPED###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
               // instead $content
           }
           //} else
           if (!$this->conf['pageQuestions']) {
               if ($this->conf['highscore.']['showAtFinal']) {
                   $quizData['cmd'] = 'score';
               } else {
                   $quizData['cmd'] = 'nix';
               }
               // keine neuen Fragen...
           } else {
               if ($this->conf['isPoll'] && !$nextCat) {
                   $quizData['cmd'] = 'list';
               }
           }
           $markerArray["###VAR_QUESTIONS_ANSWERED###"] = $answered ? substr_count($answered, ',') + 1 : 0;
           if ($falseAnsw || $correctAnsw) {
               $markerArray["###VAR_QUESTIONS_CORRECT###"] = $correctAnsw ? substr_count($correctAnsw, ',') + 1 : 0;
               $markerArray["###VAR_QUESTIONS_FALSE###"] = $falseAnsw ? substr_count($falseAnsw, ',') + 1 : 0;
           }
           if ($this->conf['dontShowPoints'] != 1 && !$this->conf['isPoll']) {
               // Total points yet. && !$this->conf['dontShowCorrectAnswers'] ??
               $markerArray["###RESULT_POINTS###"] = $this->pi_getLL('result_points', 'result_points');
               $markerArray["###TOTAL_POINTS###"] = $this->pi_getLL('total_points', 'total_points');
               $markerArray["###SO_FAR_REACHED1###"] = $this->pi_getLL('so_far_reached1', 'so_far_reached1');
               $markerArray["###SO_FAR_REACHED2###"] = $this->pi_getLL('so_far_reached2', 'so_far_reached2');
               $markerArray["###VAR_RESULT_POINTS###"] = $points;
               $markerArray["###VAR_MAX_POINTS###"] = $maxPoints;
               $markerArray["###VAR_MISSING_POINTS###"] = $maxPoints - $points;
               $markerArray["###VAR_TOTAL_POINTS###"] = $pointsTotal;
               $markerArray["###VAR_TMAX_POINTS###"] = $maxTotal;
               $markerArray["###VAR_TMISSING_POINTS###"] = $maxTotal - $pointsTotal;
               if ($maxTotal > 0) {
                   $percent = intval(round(100 * $pointsTotal / $maxTotal));
               }
               $markerArray["###VAR_PERCENT###"] = $percent;
               $overallMaximum = $markerArray["###VAR_OMAX_POINTS###"];
               if ($overallMaximum) {
                   $overallPercent = 100 * $pointsTotal / $overallMaximum;
                   $markerArray["###VAR_OVERALL_PERCENT###"] = intval(round($overallPercent));
                   //$markerArray["###VAR_OMAX_POINTS###"] = $overallMaximum;
               }
               if ($doUpdate == 0) {
                   $overallMaximum = $this->helperObj->getQuestionsMaxPoints();
                   // maximum points of all questions
                   if ($overallMaximum > 0) {
                       $overallPercent = 100 * $markerArray["###VAR_TOTAL_POINTS###"] / $overallMaximum;
                   }
                   $markerArray["###VAR_OVERALL_PERCENT###"] = intval(round($overallPercent));
                   $markerArray["###VAR_OMAX_POINTS###"] = $overallMaximum;
                   $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_RESULT_POINTS###");
               } else {
                   $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_RESULT_POINTS_TOTAL###");
               }
               $markerArrayP["###REF_QPOINTS###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
               // instead $content
           }
           if ($this->conf['startCategory'] && $nextCat) {
               //  && $this->conf['pageQuestions']==1
               $this->conf['startCategory'] = $nextCat;
               // kategorie der naechsten frage
           }
           // myVars for page
           $markerArrayP = array_merge($markerArrayP, $this->helperObj->setPageVars());
           if ($points == '') {
               $points = 0;
           }
           if ($pointsTotal == '') {
               $pointsTotal = 0;
           }
           $hidden = intval($quizData["hidden"]);
           if ($doUpdate == 0 && ($points > 0 || !$this->conf['isPoll'])) {
               // Insert new results into database
               $timestamp = time();
               $firsttime = intval($quizData["time"]);
               $insert = array('pid' => $resPID, 'tstamp' => $timestamp, 'crdate' => $timestamp, 'hidden' => $hidden, 'ip' => $quiz_taker_ip_address, 'sys_language_uid' => $this->lang);
               if (!$this->conf['isPoll']) {
                   $insert['joker1'] = $joker1 = intval($quizData["joker1"]);
                   $insert['joker2'] = $joker2 = intval($quizData["joker2"]);
                   $insert['joker3'] = $joker3 = intval($quizData["joker3"]);
                   $insert['name'] = $quiz_taker_name;
                   $insert['email'] = $quiz_taker_email;
                   $insert['homepage'] = $quiz_taker_homepage;
                   $insert['p_max'] = $maxPoints;
                   $insert['percent'] = $percent;
                   $insert['o_max'] = $overallMaximum;
                   $insert['o_percent'] = $overallPercent;
                   $insert['cids'] = $correctAnsw;
                   $insert['fids'] = $falseAnsw;
                   $insert['sids'] = $skipped;
                   // Hook for tt_address
                   if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['setAdrHook']) && $this->conf['userData.']['tt_address_pid']) {
                       foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['setAdrHook'] as $_classRef) {
                           $_procObj =& t3lib_div::getUserObj($_classRef);
                           $markerArray["###VAR_ADDRESS_UID###"] = $quizData["address_uid"] = intval($_procObj->setAdr($quizData, $this->conf['userData.']['tt_address_pid'], $this->conf['userData.']['tt_address_groups']));
                       }
                       $insert['address_uid'] = $quizData["address_uid"];
                   }
               }
               if ($this->tableAnswers == 'tx_myquizpoll_result') {
                   $insert['p_or_a'] = $points;
                   $insert['qids'] = $answered;
                   $insert['firsttime'] = $firsttime;
                   $insert['lasttime'] = $timestamp;
                   $insert['lastcat'] = $lastCat;
                   $insert['nextcat'] = $nextCat;
                   $insert['fe_uid'] = intval($GLOBALS['TSFE']->fe_user->user['uid']);
                   $insert['start_uid'] = intval($quizData["start_uid"]);
               } else {
                   $insert['answer_no'] = $points;
                   $insert['question_id'] = $answered;
               }
               $success = $GLOBALS['TYPO3_DB']->exec_INSERTquery($this->tableAnswers, $insert);
               if ($success) {
                   $quizData['qtuid'] = $GLOBALS['TYPO3_DB']->sql_insert_id();
                   if ($this->tableAnswers == 'tx_myquizpoll_result') {
                       $this->helperObj->setStartUid($quizData['qtuid'], intval($quizData["start_uid"]));
                   }
                   if ($this->conf['useCookiesInDays']) {
                       // save quiz takers UID as cookie?
                       $cookieName = $this->getCookieMode($resPID, $thePID);
                       //if (!($this->conf['isPoll'] && $_COOKIE[$cookieName])) {    // bein Umfragen Cookie nicht ueberschreiben...
                       if (intval($this->conf['useCookiesInDays']) == -1) {
                           $periode = 0;
                       } else {
                           $periode = time() + 3600 * 24 * intval($this->conf['useCookiesInDays']);
                       }
                       setcookie($cookieName, $quizData['qtuid'], $periode);
                       /* cookie for x days */
                       if ($this->helperObj->writeDevLog) {
                           t3lib_div::devLog('Storing Cookie: ' . $cookieName . '=' . $quizData['qtuid'] . ', period=' . $periode, $this->extKey, 0);
                       }
                       //}
                   }
                   $this->helperObj->setFirstTime($quizData['qtuid'], $firsttime);
               } else {
                   $content .= "<p>MySQL Insert-Error for table " . $this->tableAnswers . " :-(</p>";
               }
           } else {
               if ($doUpdate == 1) {
                   // update current user entry
                   $uid = intval($quizData['qtuid']);
                   $timestamp = time();
                   $update = array('tstamp' => $timestamp, 'hidden' => $hidden, 'name' => $quiz_taker_name, 'email' => $quiz_taker_email, 'homepage' => $quiz_taker_homepage, 'p_or_a' => $pointsTotal, 'p_max' => $maxTotal, 'percent' => $percent, 'o_percent' => $overallPercent, 'qids' => $answered, 'cids' => $correctAnsw, 'fids' => $falseAnsw, 'sids' => $skipped, 'lastcat' => $lastCat, 'nextcat' => $nextCat, 'lasttime' => $timestamp);
                   $success = $GLOBALS['TYPO3_DB']->exec_UPDATEquery($this->tableAnswers, 'uid=' . $uid . ' AND sys_language_uid=' . $this->lang, $update);
                   if (!$success) {
                       $content .= "<p>MySQL Update-Error :-(</p>";
                   }
               } else {
                   if ($doUpdate == 3) {
                       // update current skipped entry (only skipped questions?!?!)
                       $uid = intval($quizData['qtuid']);
                       $timestamp = time();
                       $update = array('tstamp' => $timestamp, 'hidden' => $hidden, 'sids' => $skipped, 'lasttime' => $timestamp);
                       $success = $GLOBALS['TYPO3_DB']->exec_UPDATEquery($this->tableAnswers, 'uid=' . $uid . ' AND sys_language_uid=' . $this->lang, $update);
                       if (!$success) {
                           $content .= "<p>MySQL Update-Error :-(</p>";
                       }
                   }
               }
           }
           $markerArray["###QTUID###"] = intval($quizData["qtuid"]);
           if ($this->conf['isPoll']) {
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_POLL_SUBMITED###");
               // Output thank you
               $markerArray['###QUESTION_NAME###'] = $this->pi_getLL('poll_question', 'poll_question');
               $markerArray['###USER_ANSWER###'] = $this->pi_getLL('poll_answer', 'poll_answer');
               $markerArrayP["###REF_INTRODUCTION###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
               // instead $content
           } else {
               if ($this->conf['userData.']['showAtAnswer']) {
                   $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_USER_SUBMITED###");
                   // Output the user name
                   $markerArrayP["###REF_INTRODUCTION###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
                   // instead $content
               }
           }
           if ($this->conf['advancedStatistics'] && $doUpdate < 2) {
               // write advanced Statistics to database
               $uid = intval($quizData['qtuid']);
               $timestamp = time();
               $firsttime = $this->helperObj->getFirstTime($uid);
               if ($this->conf['requireSession']) {
                   $where_time = ' AND crdate=' . $firsttime;
               } else {
                   $where_time = '';
               }
               if (is_array($statisticsArray)) {
                   foreach ($statisticsArray as $type => $element) {
                       // delete old entry in back-mode
                       if ($back > 0) {
                           $GLOBALS['TYPO3_DB']->exec_DELETEquery($this->tableRelation, "pid={$resPID} AND user_id={$uid} AND question_id={$type} {$where_time} AND sys_language_uid=" . $this->lang);
                       }
                       $insert = array('pid' => $resPID, 'tstamp' => $timestamp, 'crdate' => $firsttime, 'hidden' => $hidden, 'user_id' => $uid, 'question_id' => $type, 'textinput' => $element['text'], 'points' => $element['points'] ? $element['points'] : 0, 'nextcat' => $element['nextCat'] ? $element['nextCat'] : 0, 'sys_language_uid' => $this->lang);
                       //$array2=array();
                       for ($answerNumber = 1; $answerNumber < $this->answerChoiceMax + 1; $answerNumber++) {
                           $insert['checked' . $answerNumber] = $element['a' . $answerNumber] ? 1 : 0;
                       }
                       //$insert = array_merge($array1, $array2);
                       $GLOBALS['TYPO3_DB']->exec_INSERTquery($this->tableRelation, $insert);
                   }
               }
           }
           if (!$this->conf['pageQuestions'] && !$this->conf['isPoll']) {
               $finalPage = true;
           }
           $answerPage = true;
           if ($back) {
               $back--;
           }
       }
       if ($this->conf['finishedMinPercent'] && $this->conf['pageQuestions'] > 0 && $markerArray["###VAR_TOTAL_POINTS###"] !== '' && (!$this->conf['showAnswersSeparate'] || !$quizData['cmd']) && $no_rights == 0) {
           /* ***************************************************** */
           /*
            * Display positive cancel page: quiz taker has reached finishedMinPercent percent???
            */
           if ($markerArray["###VAR_OMAX_POINTS###"]) {
               $myPercent = 100 * $markerArray["###VAR_TOTAL_POINTS###"] / $markerArray["###VAR_OMAX_POINTS###"];
           } else {
               $myPercent = 0;
           }
           $uidP = 0;
           $finishedMinPercent = $this->conf['finishedMinPercent'];
           if (strpos($finishedMinPercent, ':') !== false) {
               list($finishedMinPercent, $uidP) = explode(":", $finishedMinPercent);
           }
           if (intval($finishedMinPercent) <= $myPercent) {
               // do we have enough points???
               if ($uidP) {
                   // redirect to a URL with that UID?
                   $this->redirectUrl($uidP, array());
               }
               $markerArray["###REACHED1###"] = $this->pi_getLL('reached1', 'reached1');
               $markerArray["###REACHED2###"] = $this->pi_getLL('reached2', 'reached2');
               $markerArray["###SO_FAR_REACHED1###"] = $this->pi_getLL('so_far_reached1', 'so_far_reached1');
               $markerArray["###SO_FAR_REACHED2###"] = $this->pi_getLL('so_far_reached2', 'so_far_reached2');
               //$markerArray["###VAR_OVERALL_PERCENT###"] = intval($myPercent);
               //$markerArray["###VAR_OMAX_POINTS###"] = $overallMaximum;
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_FINISHEDMINPERCENT###");
               if ($template == '') {
                   // if it is not in the template
                   $template = $this->cObj->getSubpart($this->origTemplateCode, "###TEMPLATE_QUIZ_FINISHEDMINPERCENT###");
               }
               $content .= $this->cObj->substituteMarkerArray($template, $markerArray);
               // sonderfall !!!!!!!!!
               $answerPage = false;
               if ($this->conf['highscore.']['showAtFinal']) {
                   $quizData['cmd'] = 'score';
                   // show highscore
               } else {
                   $quizData['cmd'] = 'exit';
                   // display no more questions
               }
           }
       }
       if ($this->conf['cancelWhenWrong'] && $this->conf['pageQuestions'] > 0 && $markerArray["###VAR_TOTAL_POINTS###"] !== '' && (!$this->conf['showAnswersSeparate'] || !$quizData['cmd']) && $no_rights == 0) {
           /* ***************************************************** */
           /*
            * Display negative cancel page: quiz taker has given a wrong answer???
            */
           if ($markerArray["###VAR_TOTAL_POINTS###"] < $markerArray["###VAR_TMAX_POINTS###"]) {
               $markerArray["###REACHED1###"] = $this->pi_getLL('reached1', 'reached1');
               $markerArray["###REACHED2###"] = $this->pi_getLL('reached2', 'reached2');
               $markerArray["###SO_FAR_REACHED1###"] = $this->pi_getLL('so_far_reached1', 'so_far_reached1');
               $markerArray["###SO_FAR_REACHED2###"] = $this->pi_getLL('so_far_reached2', 'so_far_reached2');
               $markerArray["###QUIZ_END###"] = $this->pi_getLL('quiz_end', 'quiz_end');
               $markerArray["###RESTART_QUIZ###"] = $this->pi_linkToPage($this->pi_getLL('restart_quiz', 'restart_quiz'), $startPID, $target = '', array());
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_END###");
               if ($template == '') {
                   // if it is not in the template
                   $template = $this->cObj->getSubpart($this->origTemplateCode, "###TEMPLATE_QUIZ_END###");
               }
               $content .= $this->cObj->substituteMarkerArray($template, $markerArray);
               // sonderfall !!!
               $answerPage = false;
               // show no answers
               if ($this->conf['finalWhenCancel']) {
                   $noQuestions = true;
               } else {
                   if ($this->conf['highscore.']['showAtFinal']) {
                       $quizData['cmd'] = 'score';
                       // show highscore
                   } else {
                       $quizData['cmd'] = 'exit';
                       // display no more questions
                   }
                   $no_rights = 1;
                   // cancel all
               }
           }
       }
       // Pre-fill quiz taker name and email if FE user logged in
       if ($GLOBALS['TSFE']->loginUser) {
           if (!$quizData["name"]) {
               $field = $this->conf['fe_usersName'];
               if (!$field) {
                   $field = 'name';
               }
               $quizData["name"] = $GLOBALS['TSFE']->fe_user->user[$field];
           }
           if (!$quizData["email"]) {
               $quizData["email"] = $GLOBALS['TSFE']->fe_user->user['email'];
           }
           if (!$quizData["homepage"]) {
               $quizData["homepage"] = $GLOBALS['TSFE']->fe_user->user['www'];
           }
       }
       if ($quizData["name"]) {
           $markerArray["###DEFAULT_NAME###"] = htmlspecialchars($quizData["name"]);
       } else {
           $markerArray["###DEFAULT_NAME###"] = $this->pi_getLL('no_name', 'no_name');
       }
       if ($quizData["email"]) {
           $markerArray["###DEFAULT_EMAIL###"] = htmlspecialchars($quizData["email"]);
       } else {
           $markerArray["###DEFAULT_EMAIL###"] = $this->pi_getLL('no_email', 'no_email');
       }
       if ($quizData["homepage"]) {
           $markerArray["###DEFAULT_HOMEPAGE###"] = htmlspecialchars($quizData["homepage"]);
       } else {
           $markerArray["###DEFAULT_HOMEPAGE###"] = $this->pi_getLL('no_homepage', 'no_homepage');
       }
       $markerArray["###HIDE_ME###"] = $this->pi_getLL('hide_me', 'hide_me');
       $markerArray["###VISIBILITY###"] = $this->pi_getLL('visibility', 'visibility');
       // TODO: warum nur?
       // UID loeschen bei Umfragen
       if ($this->conf['isPoll']) {
           $quizData['qtuid'] = '';
       }
       if ($this->helperObj->writeDevLog) {
           t3lib_div::devLog('Next cmd: ' . $quizData['cmd'] . ', answer-page: ' . $answerPage . ', final-page: ' . $finalPage, $this->extKey, 0);
       }
       if ($quizData['cmd'] == '' && $no_rights == 0) {
           /* ***************************************************** */
           /*
            * Display initial page: questions and quiz taker name fields
            */
           $oldRelData = array();
           if ($this->conf['allowBack'] && $this->conf['pageQuestions'] && $quizData['qtuid'] && $back > 0) {
               $where = '';
               $where_rel = '';
               $where_time = '';
               $uid = intval($quizData['qtuid']);
               if ($this->conf['requireSession']) {
                   $where_time = ' AND firsttime=' . $this->helperObj->getFirstTime($uid);
               }
               $res5 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('name,email,homepage,qids', $this->tableAnswers, "uid={$uid} {$where_time} AND sys_language_uid=" . $this->lang);
               //.' '.$this->cObj->enableFields($this->tableAnswers));
               $rows = $GLOBALS['TYPO3_DB']->sql_num_rows($res5);
               if ($rows > 0) {
                   $fetchedRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res5);
                   $qids = explode(',', $fetchedRow['qids']);
                   $bisher = count($qids);
                   $seiten = round($bisher / $this->conf['pageQuestions']);
                   $seite = $seiten - $back + 1;
                   for ($k = 0; $k < $bisher; $k++) {
                       if (ceil(($k + 1) / $this->conf['pageQuestions']) == $seite) {
                           $where .= $qids[$k] . ',';
                       }
                   }
                   if ($where) {
                       $where = ' AND uid IN (' . preg_replace('/[^0-9,]/', '', rtrim($where, ',')) . ')';
                       $where_rel = ' AND user_id IN (' . preg_replace('/[^0-9,]/', '', rtrim($where, ',')) . ')';
                   }
                   $quizData["name"] = $fetchedRow['name'];
                   $quizData["email"] = $fetchedRow['email'];
                   $quizData["homepage"] = $fetchedRow['homepage'];
                   if ($quizData["name"]) {
                       $markerArray["###DEFAULT_NAME###"] = htmlspecialchars($quizData["name"]);
                   } else {
                       $markerArray["###DEFAULT_NAME###"] = $this->pi_getLL('no_name', 'no_name');
                   }
                   if ($quizData["email"]) {
                       $markerArray["###DEFAULT_EMAIL###"] = htmlspecialchars($quizData["email"]);
                   } else {
                       $markerArray["###DEFAULT_EMAIL###"] = $this->pi_getLL('no_email', 'no_email');
                   }
                   if ($quizData["homepage"]) {
                       $markerArray["###DEFAULT_HOMEPAGE###"] = htmlspecialchars($quizData["homepage"]);
                   } else {
                       $markerArray["###DEFAULT_HOMEPAGE###"] = $this->pi_getLL('no_homepage', 'no_homepage');
                   }
               }
               $GLOBALS['TYPO3_DB']->sql_free_result($res5);
               $sortBy = $this->getSortBy();
               $questionsArray = array();
               $questionNumber = 0;
               if ($where) {
                   $res5 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->tableQuestions, 'pid IN (' . $thePID . ')' . $where . ' AND sys_language_uid=' . $this->lang . ' ' . $this->cObj->enableFields($this->tableQuestions), '', $sortBy);
                   $rows = $GLOBALS['TYPO3_DB']->sql_num_rows($res5);
                   if ($this->helperObj->writeDevLog) {
                       t3lib_div::devLog($rows . ' rows selected with: pid IN (' . $thePID . ')' . $where . ' AND sys_language_uid=' . $this->lang, $this->extKey, 0);
                   }
                   if ($rows > 0) {
                       while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res5)) {
                           $questionNumber++;
                           $questionsArray[$questionNumber] = $row;
                       }
                   }
                   $GLOBALS['TYPO3_DB']->sql_free_result($res5);
               }
               $numOfQuestions = $questionNumber;
               $maxQuestions = $numOfQuestions;
               // bisherige Antworten noch holen
               if ($where_rel) {
                   if ($this->conf['requireSession']) {
                       $where_time = ' AND crdate=' . $this->helperObj->getFirstTime($uid);
                   }
                   $res5 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->tableRelation, "pid={$resPID} AND user_id={$uid} {$where_time} AND sys_language_uid=" . $this->lang);
                   $rows = $GLOBALS['TYPO3_DB']->sql_num_rows($res5);
                   if ($rows > 0) {
                       while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res5)) {
                           $temp_qid = $row['question_id'];
                           $oldRelData[$temp_qid] = array();
                           $oldRelData[$temp_qid]['textinput'] = $row['textinput'];
                           for ($j = 1; $j <= $this->answerChoiceMax; $j++) {
                               $oldRelData[$temp_qid]['checked' . $j] = $row['checked' . $j];
                           }
                       }
                   }
                   $GLOBALS['TYPO3_DB']->sql_free_result($res5);
               }
               //print_r($oldRelData);
           } elseif (!$noQuestions) {
               // Order questions by & and limit to
               $limitTo = '';
               $whereCat = '';
               $sortBy = $this->getSortBy();
               // Limit questions?
               if ($this->conf['pageQuestions'] > 0 && $this->conf['sortBy'] != 'random') {
                   $limitTo = preg_replace('/[^0-9,]/', '', $this->conf['pageQuestions']);
               }
               // category
               if ($this->conf['startCategory']) {
                   $whereCat = " AND category=" . intval($this->conf['startCategory']);
               } else {
                   if ($this->conf['onlyCategories']) {
                       $whereCat = " AND category IN (" . preg_replace('/[^0-9,]/', '', $this->conf['onlyCategories']) . ")";
                   }
               }
               // Get questions from the database
               $questionsArray = array();
               $questionNumber = 0;
               $res5 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->tableQuestions, 'pid IN (' . $thePID . ')' . $whereCat . $whereAnswered . $whereSkipped . ' AND sys_language_uid=' . $this->lang . ' ' . $this->cObj->enableFields($this->tableQuestions), '', $sortBy, $limitTo);
               $rows = $GLOBALS['TYPO3_DB']->sql_num_rows($res5);
               if (!$rows && $whereSkipped) {
                   // now ignore the skipped questions
                   $res5 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->tableQuestions, 'pid IN (' . $thePID . ')' . $whereCat . $whereAnswered . ' AND sys_language_uid=' . $this->lang . ' ' . $this->cObj->enableFields($this->tableQuestions), '', $sortBy, $limitTo);
                   $rows = $GLOBALS['TYPO3_DB']->sql_num_rows($res5);
               }
               if ($this->helperObj->writeDevLog) {
                   t3lib_div::devLog($rows . ' rows selected with: pid IN (' . $thePID . ')' . $whereCat . $whereAnswered . ' AND sys_language_uid=' . $this->lang, $this->extKey, 0);
               }
               if ($rows > 0) {
                   while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res5)) {
                       $questionNumber++;
                       $questionsArray[$questionNumber] = $row;
                   }
               }
               $numOfQuestions = $questionNumber;
               // real questions
               $maxQuestions = $this->conf['pageQuestions'];
               // should be questions
               if ($this->conf['isPoll']) {
                   $maxQuestions = 1;
                   // only max. 1 poll-question
               } else {
                   if (!$maxQuestions) {
                       $maxQuestions = $numOfQuestions;
                   } else {
                       if ($numOfQuestions < $maxQuestions) {
                           $maxQuestions = $numOfQuestions;
                           // no. of maximum question = no. of questions in the DB
                       }
                   }
               }
               if ($numOfQuestions > 0 and $this->conf['sortBy'] == 'random') {
                   // any questions out there???    Random questions???
                   $randomQuestionsArray = array();
                   $questionNumber = 0;
                   $versuche = 0;
                   // Not very fast random method
                   while ($questionNumber < $maxQuestions) {
                       // alle Fragen durchgehen
                       $random = mt_rand(1, $numOfQuestions);
                       $randomQuestionsArray[$questionNumber + 1] = $questionsArray[$random];
                       // eine Frage uebernehmen
                       $duplicate = 0;
                       for ($i = 1; $i < $questionNumber + 1; $i++) {
                           if ($randomQuestionsArray[$questionNumber + 1]['uid'] == $randomQuestionsArray[$i]['uid']) {
                               $duplicate = 1;
                               // doch nicht uebernehmen
                           }
                           if (!$duplicate && $this->conf['randomCategories'] && $versuche < 5 * $maxQuestions && $randomQuestionsArray[$questionNumber + 1]['category'] == $randomQuestionsArray[$i]['category']) {
                               $duplicate = 1;
                               // doch nicht uebernehmen
                           }
                       }
                       if (!$duplicate) {
                           $questionNumber++;
                       }
                       $versuche++;
                   }
                   // rearange questions Array
                   for ($questionNumber = 1; $questionNumber < $maxQuestions + 1; $questionNumber++) {
                       $questionsArray[$questionNumber] = $randomQuestionsArray[$questionNumber];
                   }
               }
               if ($this->conf['finishAfterQuestions']) {
                   // finish after X questions?
                   $numOfQuestions = intval($this->conf['finishAfterQuestions']) - $this->helperObj->getQuestionNo($whereAnswered);
                   if ($numOfQuestions < $maxQuestions) {
                       $maxQuestions = $numOfQuestions;
                       // no. of maximum question = no. of questions in the DB
                   }
               }
           } else {
               $numOfQuestions = 0;
           }
           if ($numOfQuestions > 0) {
               // any questions out there???
               // Start des Output
               $lastUID = 0;
               // remember the last question ID
               $pageTimeCat = 0;
               // time per page from a category
               $questTillNow = 0;
               // no. of questions answered till now
               $imgTSConfig = array();
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUESTION###");
               $template_image_begin = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUESTION_IMAGE_BEGIN###");
               $template_image_end = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUESTION_IMAGE_END###");
               $template_answer = $this->cObj->getSubpart($template, "###TEMPLATE_QUESTION_ANSWER###");
               $template_delimiter = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_DELIMITER###");
               if (!$this->conf['isPoll']) {
                   $markerArray["###VAR_QUESTIONS###"] = $this->helperObj->getQuestionsNo();
                   if ($back && $seite) {
                       $markerArray["###VAR_QUESTION###"] = $questTillNow = ($seite - 1) * $this->conf['pageQuestions'];
                   } else {
                       $markerArray["###VAR_QUESTION###"] = $questTillNow = $this->helperObj->getQuestionNo($whereAnswered);
                   }
               }
               // Questions and answers
               for ($questionNumber = 1; $questionNumber < $maxQuestions + 1; $questionNumber++) {
                   $row = $questionsArray[$questionNumber];
                   $quid = $row['uid'];
                   $markerArray["###VAR_QUESTION_NUMBER###"] = $questionNumber;
                   $answerPointsBool = false;
                   // gibt es punkte bei einzelnen antworten?
                   $markerArray["###VAR_QUESTION###"]++;
                   if ($row['image']) {
                       $markerArray["###VAR_QUESTION_IMAGE###"] = $this->helperObj->getImage($row['image'], $row["alt_text"]);
                       $markerArray["###REF_QUESTION_IMAGE_BEGIN###"] = $this->cObj->substituteMarkerArray($template_image_begin, $markerArray);
                       $markerArray["###REF_QUESTION_IMAGE_END###"] = $template_image_end;
                   } else {
                       $markerArray["###REF_QUESTION_IMAGE_BEGIN###"] = '';
                       $markerArray["###REF_QUESTION_IMAGE_END###"] = '';
                   }
                   $markerArray["###VAR_QUESTION_TYPE###"] = $row['qtype'];
                   $markerArray["###TITLE_HIDE###"] = $row['title_hide'] ? '-hide' : '';
                   $markerArray["###VAR_QUESTION_TITLE###"] = $row['title'];
                   $markerArray["###VAR_QUESTION_NAME###"] = $this->formatStr($row['name']);
                   //$this->formatStr($this->local_cObj->stdWrap($row['name'],$this->conf["general_stdWrap."])); //$this->pi_RTEcssText($row['name']);
                   if (!$this->conf['dontShowPoints'] && !$this->conf['isPoll'] && $row['qtype'] < 5) {
                       $markerArray["###VAR_QUESTION_POINTS###"] = 0;
                       if ($markerArray["###VAR_TOTAL_POINTS###"]) {
                           $markerArray["###VAR_NEXT_POINTS###"] = $markerArray["###VAR_TOTAL_POINTS###"];
                       } else {
                           $markerArray["###VAR_NEXT_POINTS###"] = 0;
                       }
                       for ($currentValue = 1; $currentValue <= $this->answerChoiceMax; $currentValue++) {
                           if (intval($row['points' . $currentValue]) > 0) {
                               $answerPointsBool = true;
                               break;
                           }
                       }
                       if ($answerPointsBool) {
                           $markerArray["###VAR_ANSWER_POINTS###"] = $this->pi_getLL('different_number_of', 'different_number_of');
                       } else {
                           if (($row['qtype'] == 0 || $row['qtype'] == 4) && $this->conf['noNegativePoints'] < 3) {
                               $markerArray["###VAR_ANSWER_POINTS###"] = $this->pi_getLL('each', 'each') . ' ' . $row['points'];
                           } else {
                               $markerArray["###VAR_ANSWER_POINTS###"] = $row['points'];
                           }
                       }
                       $markerArray["###P1###"] = $this->pi_getLL('p1', 'p1');
                       $markerArray["###P2###"] = $this->pi_getLL('p2', 'p2');
                   } else {
                       $markerArray["###VAR_ANSWER_POINTS###"] = '';
                       $markerArray["###VAR_QUESTION_POINTS###"] = '';
                       $markerArray["###VAR_NEXT_POINTS###"] = '';
                       $markerArray["###P1###"] = '';
                       $markerArray["###P2###"] = '';
                   }
                   $markerArray["###REF_QUESTION_ANSWER###"] = '';
                   if ($row['qtype'] == 2) {
                       $input_id = $this->conf['myVars.']['answers.']['input_id'] ? ' id="answer' . $questionNumber . '"' : '';
                       if ($markerArrayQ["###MY_INPUT_LABEL###"] == 5) {
                           $input_id .= ' class="form-control"';
                       }
                       $markerArrayQ["###VAR_QUESTION_ANSWER###"] = '<select name="tx_myquizpoll_pi1[answer' . $questionNumber . ']" ###MY_SELECT###' . $input_id . '>' . "\n";
                       //  class="'.$this->prefixId.'-answer"
                   }
                   // my Variables of questions
                   $markerArray["###MY_SELECT###"] = '';
                   $markerArray = array_merge($markerArray, $this->helperObj->setQuestionVars($questionNumber));
                   // Jokers
                   if ($this->conf['useJokers'] && $this->conf['pageQuestions'] == 1) {
                       $temp_uid = intval($quizData['qtuid']);
                       $markerArrayJ["###JAVASCRIPT###"] = '';
                       $markerArrayJ["###JOKER_50###"] = $this->pi_getLL('joker_50', 'joker_50');
                       $markerArrayJ["###JOKER_AUDIENCE###"] = $this->pi_getLL('joker_audience', 'joker_audience');
                       $markerArrayJ["###JOKER_PHONE###"] = $this->pi_getLL('joker_phone', 'joker_phone');
                       if (is_array($this->conf['jokers.'])) {
                           $unlimited = $this->conf['jokers.']['unlimited'];
                       } else {
                           $unlimited = 0;
                       }
                       if ($joker1 && !$unlimited) {
                           $markerArrayJ["###JOKER_50_LINK###"] = '';
                           $markerArrayJ["###JAVASCRIPT###"] .= "document.getElementById('" . $this->prefixId . "-joker_50').style.display = 'none';\n";
                       } else {
                           $markerArrayJ["###JOKER_50_LINK###"] = $this->prefixId . 'getAjaxData(' . $quid . ',' . $temp_uid . ',1,\'joker_50\');';
                       }
                       if ($joker2 && !$unlimited) {
                           $markerArrayJ["###JOKER_AUDIENCE_LINK###"] = '';
                           $markerArrayJ["###JAVASCRIPT###"] .= "document.getElementById('" . $this->prefixId . "-joker_audience').style.display = 'none';\n";
                       } else {
                           $markerArrayJ["###JOKER_AUDIENCE_LINK###"] = $this->prefixId . 'getAjaxData(' . $quid . ',' . $temp_uid . ',2,\'joker_audience\');';
                       }
                       if ($joker3 && !$unlimited) {
                           $markerArrayJ["###JOKER_PHONE_LINK###"] = '';
                           $markerArrayJ["###JAVASCRIPT###"] .= "document.getElementById('" . $this->prefixId . "-joker_phone').style.display = 'none';\n";
                       } else {
                           $markerArrayJ["###JOKER_PHONE_LINK###"] = $this->prefixId . 'getAjaxData(' . $quid . ',' . $temp_uid . ',3,\'joker_phone\');';
                       }
                       $template_jokers = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_JOKERS###");
                       $markerArrayP["###REF_JOKERS###"] = $this->cObj->substituteMarkerArray($template_jokers, $markerArrayJ);
                   }
                   // Daten zur aktuellen und nächsten Kategorie
                   $thisCat = $row['category'];
                   if ($this->catArray[$thisCat]) {
                       $markerArray["###VAR_CATEGORY###"] = $this->catArray[$thisCat]['name'];
                       $pageTimeCat = $this->catArray[$thisCat]['pagetime'];
                   }
                   $thisCat = $row['category_next'];
                   if ($this->catArray[$thisCat]) {
                       $markerArray["###VAR_NEXT_CATEGORY###"] = $this->catArray[$thisCat]['name'];
                   }
                   // Display answers
                   $answers = 0;
                   $radmonArray = array();
                   for ($answerNumber = 1; $answerNumber <= $this->answerChoiceMax; $answerNumber++) {
                       $text_type = in_array($row['qtype'], $this->textType);
                       // Answers in random order?
                       if ($this->conf['mixAnswers'] && !$text_type) {
                           $currentValue = 0;
                           $leer = 0;
                           while ($currentValue == 0 && $leer < 33) {
                               $random = mt_rand(1, $this->answerChoiceMax);
                               if (($row['answer' . $random] || $row['answer' . $random] === '0') && !in_array($random, $radmonArray)) {
                                   $radmonArray[] = $random;
                                   $currentValue = $random;
                               } else {
                                   $leer++;
                               }
                           }
                       } else {
                           $currentValue = $answerNumber;
                       }
                       if (!$text_type && ($row['answer' . $currentValue] || $row['answer' . $currentValue] === '0') || $text_type && $answerNumber == 1) {
                           $answers++;
                           $input_id = '';
                           $input_label1 = '';
                           $input_label2 = '';
                           // my Variables for answers
                           $markerArrayQ["###MY_OPTION###"] = '';
                           $markerArrayQ["###MY_INPUT_RADIO###"] = '';
                           $markerArrayQ["###MY_INPUT_CHECKBOX###"] = '';
                           $markerArrayQ["###MY_INPUT_TEXT###"] = '';
                           $markerArrayQ["###MY_INPUT_AREA###"] = '';
                           $markerArrayQ["###MY_INPUT_WRAP###"] = '';
                           $markerArrayQ = array_merge($markerArrayQ, $this->helperObj->setAnswerVars($answerNumber, $row['qtype']));
                           $markerArrayQ["###VAR_QA_NR###"] = $currentValue;
                           if ($row['qtype'] < 3 || $row['qtype'] == 4 || $row['qtype'] == 7) {
                               //$answer_choice = $this->formatStr($row['answer'.$currentValue]);    // Problem: <tt> geht hier verloren!
                               $answer_choice = $this->conf['general_stdWrap.']['notForAnswers'] ? $row['answer' . $currentValue] : $this->formatStr($row['answer' . $currentValue]);
                               if ($row['qtype'] != 2 && !(strpos($markerArrayQ["###MY_INPUT_WRAP###"], '|') === false)) {
                                   $answer_choice = str_replace('|', $answer_choice, $markerArrayQ["###MY_INPUT_WRAP###"]);
                               }
                           }
                           // Questtion type
                           if ($row['qtype'] == 1) {
                               // radio-button
                               if ($markerArrayQ["###MY_INPUT_ID###"]) {
                                   $input_id = 'id="answer' . $questionNumber . '_' . $answerNumber . '"';
                               }
                               if ($markerArrayQ["###MY_INPUT_LABEL###"]) {
                                   if ($markerArrayQ["###MY_INPUT_LABEL###"] == 3) {
                                       $class_label = ' class="radio"';
                                   } elseif ($markerArrayQ["###MY_INPUT_LABEL###"] == 4) {
                                       $class_label = ' class="radio inline"';
                                   } elseif ($markerArrayQ["###MY_INPUT_LABEL###"] == 6) {
                                       $class_label = ' class="radio-inline"';
                                   } else {
                                       $class_label = '';
                                   }
                                   if ($markerArrayQ["###MY_INPUT_LABEL###"] == 5) {
                                       $label_wrap1 = '<div class="radio">';
                                       $label_wrap2 = '</div>';
                                   } else {
                                       $label_wrap1 = '';
                                       $label_wrap2 = '';
                                   }
                                   $input_label1 = $label_wrap1 . '<label for="answer' . $questionNumber . '_' . $answerNumber . '"' . $class_label . '>';
                                   $input_label2 = '</label>' . $label_wrap2;
                               }
                               $answer_content = '<input type="radio" name="tx_myquizpoll_pi1[answer' . $questionNumber . ']" value="' . $currentValue . '" ' . $input_id . ' ###MY_INPUT_RADIO###';
                               if (is_array($oldRelData[$quid]) && $oldRelData[$quid]['checked' . $currentValue]) {
                                   $answer_content .= ' checked="checked"';
                               } elseif ($captchaError && $quizData['answer' . $questionNumber] == $currentValue) {
                                   $answer_content .= ' checked="checked"';
                               }
                               $answer_content .= ' /> ';
                           } else {
                               if ($row['qtype'] == 2) {
                                   // select-box
                                   $answer_content = '<option value="' . $currentValue . '" ###MY_OPTION###';
                                   if (is_array($oldRelData[$quid]) && $oldRelData[$quid]['checked' . $currentValue]) {
                                       $answer_content .= ' selected="selected"';
                                   } elseif ($captchaError && $quizData['answer' . $questionNumber] == $currentValue) {
                                       $answer_content .= ' selected="selected"';
                                   }
                                   $answer_content .= '> ';
                               } else {
                                   if ($row['qtype'] == 3) {
                                       // input-text
                                       if ($markerArrayQ["###MY_INPUT_ID###"]) {
                                           $input_id = 'id="answer' . $questionNumber . '"';
                                       }
                                       if ($markerArrayQ["###MY_INPUT_LABEL###"] == 5) {
                                           $input_id .= ' class="form-control"';
                                       }
                                       if (is_array($oldRelData[$quid])) {
                                           $value = $oldRelData[$quid]['textinput'];
                                       } else {
                                           if ($captchaError) {
                                               $value = $quizData['answer' . $questionNumber];
                                           } else {
                                               if ($row['answer2'] || $row['answer2'] === '0') {
                                                   $value = $row['answer2'];
                                               } else {
                                                   $value = '';
                                               }
                                           }
                                       }
                                       $answer_content = '<input type="text" name="tx_myquizpoll_pi1[answer' . $questionNumber . ']" value="' . $value . '" ' . $input_id . ' ###MY_INPUT_TEXT### /> ';
                                   } else {
                                       if ($row['qtype'] == 4) {
                                           // ja/nein
                                           $answer_content = $answer_choice;
                                           if ($markerArrayQ["###MY_INPUT_ID###"]) {
                                               $input_id = 'id="answer' . $questionNumber . '_' . $answerNumber . '_1"';
                                           }
                                           if ($markerArrayQ["###MY_INPUT_LABEL###"]) {
                                               if ($markerArrayQ["###MY_INPUT_LABEL###"] == 3) {
                                                   $class_label = ' class="radio"';
                                               } elseif ($markerArrayQ["###MY_INPUT_LABEL###"] == 4) {
                                                   $class_label = ' class="radio inline"';
                                               } elseif ($markerArrayQ["###MY_INPUT_LABEL###"] == 6) {
                                                   $class_label = ' class="radio-inline"';
                                               } else {
                                                   $class_label = '';
                                               }
                                               if ($markerArrayQ["###MY_INPUT_LABEL###"] == 5) {
                                                   $label_wrap1 = '<div class="radio">';
                                                   $label_wrap2 = '</div>';
                                               } else {
                                                   $label_wrap1 = '';
                                                   $label_wrap2 = '';
                                               }
                                               $input_label1 = $label_wrap1 . '<label for="answer' . $questionNumber . '_' . $answerNumber . '_1"' . $class_label . '>';
                                               $input_label2 = '</label>' . $label_wrap2;
                                           }
                                           $answer_content .= ' <span class="' . $this->prefixId . '-yesno"><span class="' . $this->prefixId . '-yes">';
                                           if ($markerArrayQ["###MY_INPUT_LABEL###"] > 1) {
                                               $answer_content .= $input_label1;
                                           }
                                           $answer_content .= '<input type="radio" name="tx_myquizpoll_pi1[answer' . $questionNumber . '_' . $currentValue . ']" ' . $input_id . ' value="' . $currentValue . '" ###MY_INPUT_RADIO###';
                                           if (is_array($oldRelData[$quid]) && $oldRelData[$quid]['checked' . $currentValue]) {
                                               $answer_content .= ' checked="checked"';
                                           } elseif ($captchaError && $quizData['answer' . $questionNumber . '_' . $currentValue] == $currentValue) {
                                               $answer_content .= ' checked="checked"';
                                           }
                                           $answer_content .= ' /> ';
                                           if ($markerArrayQ["###MY_INPUT_LABEL###"] == 1) {
                                               $answer_content .= $input_label1;
                                           }
                                           $answer_content .= $this->pi_getLL('yes', 'yes') . $input_label2 . '</span>';
                                           if ($markerArrayQ["###MY_INPUT_ID###"]) {
                                               $input_id = 'id="answer' . $questionNumber . '_' . $answerNumber . '_0"';
                                           }
                                           if ($markerArrayQ["###MY_INPUT_LABEL###"]) {
                                               if ($markerArrayQ["###MY_INPUT_LABEL###"] == 3) {
                                                   $class_label = ' class="radio"';
                                               } elseif ($markerArrayQ["###MY_INPUT_LABEL###"] == 4) {
                                                   $class_label = ' class="radio inline"';
                                               } elseif ($markerArrayQ["###MY_INPUT_LABEL###"] == 6) {
                                                   $class_label = ' class="radio-inline"';
                                               } else {
                                                   $class_label = '';
                                               }
                                               if ($markerArrayQ["###MY_INPUT_LABEL###"] == 5) {
                                                   $label_wrap1 = '<div class="radio">';
                                                   $label_wrap2 = '</div>';
                                               } else {
                                                   $label_wrap1 = '';
                                                   $label_wrap2 = '';
                                               }
                                               $input_label1 = $label_wrap1 . '<label for="answer' . $questionNumber . '_' . $answerNumber . '_0"' . $class_label . '>';
                                               $input_label2 = '</label>' . $label_wrap2;
                                           }
                                           $answer_content .= ' <span class="' . $this->prefixId . '-no">';
                                           if ($markerArrayQ["###MY_INPUT_LABEL###"] > 1) {
                                               $answer_content .= $input_label1;
                                           }
                                           $answer_content .= '<input type="radio" name="tx_myquizpoll_pi1[answer' . $questionNumber . '_' . $currentValue . ']" ' . $input_id . ' value="0" ###MY_INPUT_RADIO###';
                                           if (is_array($oldRelData[$quid]) && !$oldRelData[$quid]['checked' . $currentValue]) {
                                               $answer_content .= ' checked="checked"';
                                           } elseif ($captchaError && $quizData['answer' . $questionNumber . '_' . $currentValue] == 0) {
                                               $answer_content .= ' checked="checked"';
                                           }
                                           $answer_content .= ' /> ';
                                           if ($markerArrayQ["###MY_INPUT_LABEL###"] == 1) {
                                               $answer_content .= $input_label1;
                                           }
                                           $answer_content .= $this->pi_getLL('no', 'no') . $input_label2 . '</span></span>';
                                       } else {
                                           if ($row['qtype'] == 5) {
                                               // textarea
                                               if ($markerArrayQ["###MY_INPUT_ID###"]) {
                                                   $input_id = 'id="answer' . $questionNumber . '"';
                                               }
                                               if ($markerArrayQ["###MY_INPUT_LABEL###"] == 5) {
                                                   $input_id .= ' class="form-control"';
                                               }
                                               if (is_array($oldRelData[$quid])) {
                                                   $value = str_replace('\\r\\n', "\r\n", $oldRelData[$quid]['textinput']);
                                               } else {
                                                   if ($captchaError) {
                                                       $value = $quizData['answer' . $questionNumber];
                                                   } else {
                                                       if ($row['answer2'] || $row['answer2'] === '0') {
                                                           $value = $row['answer2'];
                                                       } else {
                                                           $value = '';
                                                       }
                                                   }
                                               }
                                               $answer_content = '<textarea name="tx_myquizpoll_pi1[answer' . $questionNumber . ']" ' . $input_id . ' ###MY_INPUT_AREA###>' . $value . '</textarea> ';
                                           } else {
                                               if ($row['qtype'] == 7) {
                                                   // star-rating
                                                   if ($markerArrayQ["###MY_INPUT_ID###"]) {
                                                       $input_id = 'id="answer' . $questionNumber . '_' . $answerNumber . '"';
                                                   }
                                                   if ($markerArrayQ["###MY_INPUT_LABEL###"]) {
                                                       $input_label1 = '<label for="answer' . $questionNumber . '_' . $answerNumber . '">';
                                                       $input_label2 = '</label>';
                                                   }
                                                   $answer_content = '<input type="radio" class="star" name="tx_myquizpoll_pi1[answer' . $questionNumber . ']" value="' . $currentValue . '" ' . $input_id;
                                                   if (is_array($oldRelData[$quid]) && $oldRelData[$quid]['checked' . $currentValue]) {
                                                       $answer_content .= ' checked="checked"';
                                                   } elseif ($captchaError && $quizData['answer' . $questionNumber] == $currentValue) {
                                                       $answer_content .= ' checked="checked"';
                                                   }
                                                   $answer_content .= ' title="' . $answer_choice . '" /> ';
                                               } else {
                                                   // checkbox
                                                   if ($markerArrayQ["###MY_INPUT_ID###"]) {
                                                       $input_id = 'id="answer' . $questionNumber . '_' . $answerNumber . '"';
                                                   }
                                                   if ($markerArrayQ["###MY_INPUT_LABEL###"]) {
                                                       if ($markerArrayQ["###MY_INPUT_LABEL###"] == 3) {
                                                           $class_label = ' class="checkbox"';
                                                       } elseif ($markerArrayQ["###MY_INPUT_LABEL###"] == 4) {
                                                           $class_label = ' class="checkbox inline"';
                                                       } elseif ($markerArrayQ["###MY_INPUT_LABEL###"] == 6) {
                                                           $class_label = ' class="checkbox-inline"';
                                                       } else {
                                                           $class_label = '';
                                                       }
                                                       if ($markerArrayQ["###MY_INPUT_LABEL###"] == 5) {
                                                           $label_wrap1 = '<div class="checkbox">';
                                                           $label_wrap2 = '</div>';
                                                       } else {
                                                           $label_wrap1 = '';
                                                           $label_wrap2 = '';
                                                       }
                                                       $input_label1 = $label_wrap1 . '<label for="answer' . $questionNumber . '_' . $answerNumber . '"' . $class_label . '>';
                                                       $input_label2 = '</label>' . $label_wrap2;
                                                   }
                                                   $answer_content = '<input type="checkbox" name="tx_myquizpoll_pi1[answer' . $questionNumber . '_' . $currentValue . ']" value="' . $currentValue . '" ' . $input_id . ' ###MY_INPUT_CHECKBOX###';
                                                   if (is_array($oldRelData[$quid]) && $oldRelData[$quid]['checked' . $currentValue]) {
                                                       $answer_content .= ' checked="checked"';
                                                   } elseif ($captchaError && $quizData['answer' . $questionNumber . '_' . $currentValue] == $currentValue) {
                                                       $answer_content .= ' checked="checked"';
                                                   }
                                                   $answer_content .= ' /> ';
                                               }
                                           }
                                       }
                                   }
                               }
                           }
                           if (!$this->conf['dontShowPoints'] && !$this->conf['isPoll'] && $row['qtype'] < 5) {
                               $tmpPoints = 0;
                               if ($this->conf['noNegativePoints'] < 3 && $answerPointsBool) {
                                   $tmpPoints = intval($row['points' . $currentValue]);
                               }
                               if ($tmpPoints > 0) {
                                   $row['correct' . $currentValue] = true;
                               } else {
                                   $tmpPoints = intval($row['points']);
                               }
                               if ($row['correct' . $currentValue] || $row['qtype'] == 3) {
                                   if (($row['qtype'] == 0 || $row['qtype'] == 4) && $this->conf['noNegativePoints'] < 3) {
                                       $markerArray["###VAR_QUESTION_POINTS###"] += $tmpPoints;
                                       // points for each answer
                                   } else {
                                       if ($tmpPoints > $markerArray["###VAR_QUESTION_POINTS###"]) {
                                           $markerArray["###VAR_QUESTION_POINTS###"] = $tmpPoints;
                                           // points for each answer
                                       }
                                   }
                               }
                           }
                           $thisCat = $row['category' . $currentValue];
                           if ($this->catArray[$thisCat]) {
                               $markerArrayQ['###VAR_QA_CATEGORY###'] = $this->catArray[$thisCat]['name'];
                           }
                           if ($row['qtype'] < 3) {
                               if ($markerArrayQ["###MY_INPUT_LABEL###"] > 1) {
                                   $answer_content = $input_label1 . $answer_content . $answer_choice . $input_label2;
                               } else {
                                   $answer_content .= $input_label1 . $answer_choice . $input_label2;
                               }
                           }
                           if ($row['qtype'] == 2) {
                               $answer_content .= "</option>\n";
                               $markerArrayQ["###VAR_QUESTION_ANSWER###"] .= $this->cObj->substituteMarkerArray($answer_content, $markerArrayQ);
                           } else {
                               $markerArrayQ['###VAR_QUESTION_ANSWER###'] = $this->cObj->substituteMarkerArray($answer_content, $markerArrayQ);
                               $markerArray["###REF_QUESTION_ANSWER###"] .= $this->cObj->substituteMarkerArray($template_answer, $markerArrayQ);
                           }
                       }
                   }
                   if (!$this->conf['dontShowPoints'] && !$this->conf['isPoll'] && $row['qtype'] < 5) {
                       $markerArray["###VAR_NEXT_POINTS###"] += $markerArray["###VAR_QUESTION_POINTS###"];
                   }
                   $markerArray["###VAR_QUESTION_ANSWERS###"] = $answers;
                   if ($this->conf['allowSkipping']) {
                       // skip answers
                       $markerArrayQ["###VAR_QA_NR###"] = -1;
                       // Questtion type
                       if ($row['qtype'] == 1) {
                           if ($markerArrayQ["###MY_INPUT_ID###"]) {
                               $input_id = ' id="answer' . $questionNumber . '_x"';
                           }
                           if ($markerArrayQ["###MY_INPUT_LABEL###"]) {
                               if ($markerArrayQ["###MY_INPUT_LABEL###"] == 3) {
                                   $class_label = ' class="radio"';
                               } elseif ($markerArrayQ["###MY_INPUT_LABEL###"] == 4) {
                                   $class_label = ' class="radio inline"';
                               } elseif ($markerArrayQ["###MY_INPUT_LABEL###"] == 6) {
                                   $class_label = ' class="radio-inline"';
                               } else {
                                   $class_label = '';
                               }
                               if ($markerArrayQ["###MY_INPUT_LABEL###"] == 5) {
                                   $label_wrap1 = '<div class="radio">';
                                   $label_wrap2 = '</div>';
                               } else {
                                   $label_wrap1 = '';
                                   $label_wrap2 = '';
                               }
                               $input_label1 = $label_wrap1 . '<label for="answer' . $questionNumber . '_x"' . $class_label . '>';
                               $input_label2 = '</label>' . $label_wrap2;
                           }
                           $answer_content = '<input type="radio" name="tx_myquizpoll_pi1[answer' . $questionNumber . ']" value="-1"' . $input_id . ' /> ';
                           if ($markerArrayQ["###MY_INPUT_LABEL###"] > 1) {
                               $answer_content = $input_label1 . $answer_content . $this->pi_getLL('skip', 'skip') . $input_label2;
                           } else {
                               $answer_content .= $input_label1 . $this->pi_getLL('skip', 'skip') . $input_label2;
                           }
                       } else {
                           if ($row['qtype'] == 2) {
                               $answer_content = '<option value="-1"> ' . $this->pi_getLL('skip', 'skip') . '</option>';
                           } else {
                               if ($row['qtype'] < 6) {
                                   if ($markerArrayQ["###MY_INPUT_ID###"]) {
                                       $input_id = ' id="answer' . $questionNumber . '_x"';
                                   }
                                   if ($markerArrayQ["###MY_INPUT_LABEL###"]) {
                                       if ($markerArrayQ["###MY_INPUT_LABEL###"] == 3) {
                                           $class_label = ' class="checkbox"';
                                       } elseif ($markerArrayQ["###MY_INPUT_LABEL###"] == 4) {
                                           $class_label = ' class="checkbox inline"';
                                       } elseif ($markerArrayQ["###MY_INPUT_LABEL###"] == 6) {
                                           $class_label = ' class="checkbox-inline"';
                                       } else {
                                           $class_label = '';
                                       }
                                       if ($markerArrayQ["###MY_INPUT_LABEL###"] == 5) {
                                           $label_wrap1 = '<div class="checkbox">';
                                           $label_wrap2 = '</div>';
                                       } else {
                                           $label_wrap1 = '';
                                           $label_wrap2 = '';
                                       }
                                       $input_label1 = $label_wrap1 . '<label for="answer' . $questionNumber . '_x"' . $class_label . '>';
                                       $input_label2 = '</label>' . $label_wrap2;
                                   }
                                   $answer_content = '<input type="checkbox" name="tx_myquizpoll_pi1[answer' . $questionNumber . ']" value="-1"' . $input_id . ' /> ';
                                   if ($markerArrayQ["###MY_INPUT_LABEL###"] > 1) {
                                       $answer_content = $input_label1 . $answer_content . $this->pi_getLL('skip', 'skip') . $input_label2;
                                   } else {
                                       $answer_content .= $input_label1 . $this->pi_getLL('skip', 'skip') . $input_label2;
                                   }
                               }
                           }
                       }
                       $markerArrayQ['###VAR_QA_CATEGORY###'] = '';
                       if ($row['qtype'] == 2) {
                           $markerArrayQ['###VAR_QUESTION_ANSWER###'] .= $answer_content;
                       } else {
                           $markerArrayQ['###VAR_QUESTION_ANSWER###'] = $answer_content;
                           $markerArray["###REF_QUESTION_ANSWER###"] .= $this->cObj->substituteMarkerArray($template_answer, $markerArrayQ);
                       }
                   }
                   if ($row['qtype'] == 2) {
                       $markerArrayQ["###VAR_QUESTION_ANSWER###"] .= "</select>\n";
                       $markerArray["###REF_QUESTION_ANSWER###"] .= $this->cObj->substituteMarkerArray($template_answer, $markerArrayQ);
                   }
                   if (($this->helperObj->getAskAtQ($quizData['qtuid']) || $questionNumber < $maxQuestions) && !$this->conf['isPoll']) {
                       $markerArray["###REF_DELIMITER###"] = $this->cObj->substituteMarkerArray($template_delimiter, $markerArray);
                   } else {
                       $markerArray["###REF_DELIMITER###"] = '';
                   }
                   if ($this->conf['enforceSelection']) {
                       // 25.1.10: antwort erzwingen?
                       $this->helperObj->addEnforceJsc($questionNumber, $answers, $row['qtype']);
                   }
                   //$this->subpart = $template;
                   $template2 = $this->cObj->substituteSubpart($template, '###TEMPLATE_QUESTION_ANSWER###', $markerArray["###REF_QUESTION_ANSWER###"], 0);
                   $markerArrayP["###REF_QUESTIONS###"] .= $this->cObj->substituteMarkerArray($template2, $markerArray);
                   // statt $content .= since 0.1.8
                   $markerArrayP["###REF_QUESTIONS###"] .= '<input type="hidden" name="tx_myquizpoll_pi1[uid' . $questionNumber . ']" value="' . $quid . '" class="input_hidden" />';
                   if ($this->conf['isPoll']) {
                       // link to the result page
                       $urlParameters = array("tx_myquizpoll_pi1[cmd]" => "list", "tx_myquizpoll_pi1[qid]" => $quid, "no_cache" => "1");
                       $markerArray["###POLLRESULT_URL###"] = $this->pi_linkToPage($this->pi_getLL('poll_url', 'poll_url'), $listPID, $target = '', $urlParameters);
                   }
                   $lastUID = $quid;
               }
               $markerArrayP["###REF_SUBMIT_FIELDS###"] = '';
               $markerArrayP["###HIDDENFIELDS###"] = '';
               $markerArrayP["###VAR_QID###"] = $lastUID;
               // last question uid, added on 23.1.2011
               if ($this->conf['isPoll']) {
                   $markerArrayP["###VAR_FID###"] = '';
                   $markerArrayP["###POLLRESULT###"] = $this->pi_getLL('poll_url', 'poll_url');
                   $markerArrayP["###NUM_VOTES###"] = $this->pi_getLL('num_votes', 'num_votes');
                   if ($this->conf['rating.']['parameter']) {
                       // rating
                       $markerArrayP["###VAR_FID###"] = $this->helperObj->getForeignId();
                       // a foreign uid, added on 23.1.2011
                   }
               }
               if ($this->helperObj->writeDevLog) {
                   t3lib_div::devLog('last question: ' . $lastUID, $this->extKey, 0);
               }
               // back-button
               if ($this->conf['allowBack'] && $this->conf['pageQuestions'] && $quizData['qtuid']) {
                   $markerArrayP["###HIDDENFIELDS###"] .= '  <input type="hidden" name="' . $this->prefixId . '[back]" value="' . $back . '" />';
                   $markerArrayP["###HIDDENFIELDS###"] .= '  <input type="hidden" name="' . $this->prefixId . '[back-hit]" value="0" />';
                   $markerArray['###BACK_STYLE###'] = $seite == 1 ? ' style="display:none;"' : '';
               } else {
                   $markerArray['###BACK_STYLE###'] = ' style="display:none;"';
               }
               // Submit/User-Data Template
               if ($this->helperObj->getAskAtQ($quizData['qtuid']) && !$this->conf['isPoll']) {
                   $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_USER_TO_SUBMIT###");
                   if (is_object($this->freeCap) && $this->conf['enableCaptcha']) {
                       $markerArray = array_merge($markerArray, $this->freeCap->makeCaptcha());
                   } else {
                       $subpartArray['###CAPTCHA_INSERT###'] = '';
                   }
                   $markerArrayP["###REF_SUBMIT_FIELDS###"] = $this->cObj->substituteMarkerArrayCached($template, $markerArray, $subpartArray, $wrappedSubpartArray);
               } else {
                   if (!($answeredQuestions == $lastUID && $this->conf["isPoll"])) {
                       $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_SUBMIT###");
                       $markerArrayP["###REF_SUBMIT_FIELDS###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
                       $markerArrayP["###HIDDENFIELDS###"] .= '  <input type="hidden" name="name" value="' . $markerArray["###DEFAULT_NAME###"] . '" /> ';
                       // fürs Template?
                       $markerArrayP["###HIDDENFIELDS###"] .= '  <input type="hidden" name="' . $this->prefixId . '[name]" value="' . htmlspecialchars($quizData["name"]) . '" />';
                       $markerArrayP["###HIDDENFIELDS###"] .= '  <input type="hidden" name="' . $this->prefixId . '[email]" value="' . htmlspecialchars($quizData["email"]) . '" />';
                       $markerArrayP["###HIDDENFIELDS###"] .= '  <input type="hidden" name="' . $this->prefixId . '[homepage]" value="' . htmlspecialchars($quizData["homepage"]) . '" />';
                   } else {
                       $markerArray["###NO_SUBMIT###"] = $this->pi_getLL('no_submit', 'no_submit');
                       $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_NO_SUBMIT###");
                       $markerArrayP["###REF_SUBMIT_FIELDS###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
                       // new in 0.1.8
                   }
               }
               if (!$this->conf['isPoll']) {
                   // when is Poll, do not update result-table
                   $markerArrayP["###HIDDENFIELDS###"] .= '  <input type="hidden" name="' . $this->prefixId . '[qtuid]" value="' . intval($quizData["qtuid"]) . '" />';
               }
               if ($this->conf['hideByDefault']) {
                   $markerArrayP["###HIDDENFIELDS###"] .= '  <input type="hidden" name="' . $this->prefixId . '[hidden]" value="1" />';
               }
               if (!$quizData['qtuid']) {
                   $markerArrayP["###HIDDENFIELDS###"] .= '
 <input type="hidden" name="' . $this->prefixId . '[start_uid]" value="' . $GLOBALS['TSFE']->id . '" />
 <input type="hidden" name="' . $this->prefixId . '[time]" value="' . time() . '" />';
               }
               $markerArrayP["###HIDDENFIELDS###"] .= '
 <input type="hidden" name="' . $this->prefixId . '[cmd]" value="submit" />';
               //  <input type="hidden" name="no_cache" value="1" />		KGB: auskommentiert am 30.5.2015
               if ($this->conf['useJokers'] && $this->conf['pageQuestions'] == 1) {
                   $markerArrayP["###HIDDENFIELDS###"] .= '
 <input type="hidden" name="' . $this->prefixId . '[joker1]" value="0" />
 <input type="hidden" name="' . $this->prefixId . '[joker2]" value="0" />
 <input type="hidden" name="' . $this->prefixId . '[joker3]" value="0" />';
               }
               $markerArrayP["###MAX_PAGES###"] = $this->helperObj->getMaxPages();
               $markerArrayP["###PAGE###"] = $this->helperObj->getPage($questTillNow);
               $markerArrayP["###FE_USER_UID###"] = intval($GLOBALS['TSFE']->fe_user->user['uid']);
               $markerArrayP["###SUBMIT_JSC###"] = $this->helperObj->getSubmitJsc();
               $questionPage = true;
           } else {
               // final page: no more questions left, if pageQuestions > 0
               if ($this->helperObj->writeDevLog) {
                   t3lib_div::devLog('0 questions found. Entering final page...', $this->extKey, 0);
               }
               // if ($oldLoaded) $secondVisit = true;	// Keine Email schicken, wenn alle Fragen schon beantwortet wurden: NE, so einfach ist das nicht :-(
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_NO_MORE###");
               $markerArray["###NO_MORE###"] = $this->pi_getLL('no_more', 'no_more');
               $markerArray['###YOUR_EVALUATION###'] = $this->pi_getLL('your_evaluation', 'your_evaluation');
               $markerArray['###REACHED1###'] = $this->pi_getLL('reached1', 'reached1');
               $markerArray['###REACHED2###'] = $this->pi_getLL('reached2', 'reached2');
               $markerArray['###POINTS###'] = $this->pi_getLL('points', 'points');
               /*    if ($this->conf['startPID'])        // wir sind nicht auf der Startseite, also parent holen...
                         $restart_id = $this->conf['startPID']; // $GLOBALS['TSFE']->page['pid'];
                     else 
                         $restart_id = $GLOBALS['TSFE']->id;    */
               $markerArray["###RESTART_QUIZ###"] = $this->pi_linkToPage($this->pi_getLL('restart_quiz', 'restart_quiz'), $startPID, $target = '', array());
               if ($this->conf['allowCookieReset']) {
                   $markerArray["###RESET_COOKIE###"] = $this->pi_linkToPage($this->pi_getLL('reset_cookie', 'reset_cookie'), $startPID, $target = '', array($this->prefixId . '[resetcookie]' => 1));
               } else {
                   $markerArray["###RESET_COOKIE###"] = '';
               }
               $questions = '';
               if ($this->conf['showAllCorrectAnswers'] && !$this->conf['isPoll']) {
                   // show all answers...
                   /*if ($this->conf['finishAfterQuestions'])
                         $fragen = intval($this->conf['finishAfterQuestions']);
                     else
                         $fragen = $this->helperObj->getQuestionsNo();*/
                   $questions = $this->showAllAnswers($quizData, $thePID, $resPID, false, 0);
                   // 24.01.10: 0 statt $fragen
               }
               $subpart = $template;
               $template = $this->cObj->substituteSubpart($subpart, '###QUIZ_ANSWERS###', $questions);
               $markerArrayP["###REF_NO_MORE###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
               $markerArrayP["###RESTART_QUIZ###"] = $markerArray["###RESTART_QUIZ###"];
               $markerArrayP["###RESET_COOKIE###"] = $markerArray["###RESET_COOKIE###"];
               if ($this->conf['highscore.']['showAtFinal']) {
                   $quizData['cmd'] = 'score';
               }
               $finalPage = true;
           }
           // myVars for page
           $markerArrayP = array_merge($markerArrayP, $this->helperObj->setPageVars());
       } else {
           if ($this->conf['showAnswersSeparate'] && $quizData['cmd'] == 'submit' && !$this->conf['isPoll'] && $no_rights == 0) {
               /* ***************************************************** */
               /*
                * Display only a next button
                */
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_NEXT###");
               $markerArray["###HIDDENFIELDS###"] = '';
               // back-button
               if ($this->conf['allowBack'] && $this->conf['pageQuestions'] && $quizData['qtuid']) {
                   $markerArray['###BACK_STYLE###'] = '';
                   $markerArray["###HIDDENFIELDS###"] .= '<input type="hidden" name="' . $this->prefixId . '[back]" value="' . $back . '" />
   <input type="hidden" name="' . $this->prefixId . '[back-hit]" value="0" />';
               } else {
                   $markerArray['###BACK_STYLE###'] = ' style="display:none;"';
               }
               if ($template == '') {
                   // if it is not in the template
                   $template = $this->cObj->getSubpart($this->origTemplateCode, "###TEMPLATE_NEXT###");
               }
               $markerArrayP["###REF_NEXT###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
               // instead $content
           }
       }
       /** Redirect to the final page? **/
       if ($finalPage && $quizData['cmd'] != 'exit' && $this->conf['finalPID'] && $finalPID != intval($GLOBALS["TSFE"]->id)) {
           $this->redirectUrl($finalPID, array($this->prefixId . '[qtuid]' => intval($quizData["qtuid"]), $this->prefixId . '[cmd]' => 'next'));
           break;
           // unnoetig...
       }
       /** Poll result? **/
       if ($answerPage && $this->conf['isPoll']) {
           $quizData['cmd'] = 'list';
       }
       // Make a page-layout
       if ($quizData['cmd'] == 'allanswers' && !$this->conf['isPoll']) {
           /* ***************************************************** */
           /*
            * Display all questions and correct answers
            */
           if ($this->helperObj->writeDevLog) {
               t3lib_div::devLog("show answers of: {$thePID},{$resPID}", $this->extKey, 0);
           }
           $content .= $this->showAllAnswers($quizData, $thePID, $resPID, false, 0);
           // 24.01.10: 0 statt $this->helperObj->getQuestionsNo()
       }
       if ($quizData['cmd'] == 'score' && !$this->conf['isPoll']) {
           /* ***************************************************** */
           /*
            * Display highscore page: top 10 table
            */
           if ($quizData["setUserData"] && $quizData['qtuid'] && $quizData["name"]) {
               // ggf. erst Benutzerdaten in der DB setzen...
               $uid = intval($quizData['qtuid']);
               $firsttime = $this->helperObj->getFirstTime($uid);
               if ($firsttime == intval($quizData["setUserData"])) {
                   // Security test bestanden?
                   // update current user entry
                   $timestamp = time();
                   // Avoid bad characters in database request
                   $quiz_taker_name = $GLOBALS['TYPO3_DB']->quoteStr($quizData["name"], $this->tableAnswers);
                   $quiz_taker_email = $GLOBALS['TYPO3_DB']->quoteStr($quizData["email"], $this->tableAnswers);
                   $quiz_taker_homepage = $GLOBALS['TYPO3_DB']->quoteStr($quizData["homepage"], $this->tableAnswers);
                   $hidden = intval($quizData["hidden"]);
                   $update = array('tstamp' => $timestamp, 'name' => $quiz_taker_name, 'email' => $quiz_taker_email, 'homepage' => $quiz_taker_homepage, 'hidden' => $hidden);
                   // Hook for tt_address
                   if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['setAdrHook']) && $this->conf['userData.']['tt_address_pid']) {
                       foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['setAdrHook'] as $_classRef) {
                           $_procObj =& t3lib_div::getUserObj($_classRef);
                           $update['address_uid'] = intval($_procObj->setAdr($quizData, $this->conf['userData.']['tt_address_pid'], $this->conf['userData.']['tt_address_groups']));
                       }
                   }
                   $success = $GLOBALS['TYPO3_DB']->exec_UPDATEquery($this->tableAnswers, 'uid=' . $uid . ' AND sys_language_uid=' . $this->lang, $update);
                   if (!$success) {
                       $content .= "<p>MySQL Update-Error :-(</p>";
                   }
               }
               if ($this->conf['email.']['send_admin'] == 2 || $this->conf['email.']['send_user'] == 2) {
                   $sendMail = true;
               }
           }
           if ($finalPage) {
               $markerArrayP["###REF_HIGHSCORE###"] = $this->showHighscoreList($quizData, $resPIDs, $listPID);
           } else {
               $content .= $this->showHighscoreList($quizData, $resPIDs, $listPID);
           }
       } else {
           if ($quizData['cmd'] == 'list' && $this->conf['isPoll']) {
               /* ***************************************************** */
               /*
                * Display poll result
                */
               if ($this->helperObj->writeDevLog) {
                   t3lib_div::devLog('Poll result: searching question in ' . $thePID . ' and results in ' . $resPID, $this->extKey, 0);
               }
               if ($answerPage) {
                   $markerArrayP["###REF_POLLRESULT###"] = $this->showPollResult($answered, $quizData, $thePID, $resPID);
               } else {
                   $content .= $this->showPollResult($answered, $quizData, $thePID, $resPID);
               }
           }
       }
       if (!$this->conf['isPoll'] && $quizData['cmd'] != 'score') {
           // show highscore link?
           $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_HIGHSCORE_URL###");
           $markerArrayP["###REF_HIGHSCORE_URL###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
       }
       if ($this->conf['isPoll'] && $quizData['cmd'] != 'list') {
           // show poll result link?
           $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_POLLRESULT_URL###");
           $markerArrayP["###REF_POLLRESULT_URL###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
       }
       /** Layout for the start page **/
       if ($startPage) {
           $markerArrayP["###REF_PAGE_LIMIT###"] = '';
           $markerArrayP["###REF_QUIZ_LIMIT###"] = '';
           $markerArrayP["###HIDDENFIELDS###"] = '<input type="hidden" name="' . $this->prefixId . '[fromStart]" value="1" />';
           $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_USER_TO_SUBMIT###");
           $markerArray['###BACK_STYLE###'] = ' style="display:none;"';
           if (is_object($this->freeCap) && $this->conf['enableCaptcha']) {
               $markerArray = array_merge($markerArray, $this->freeCap->makeCaptcha());
           } else {
               $subpartArray['###CAPTCHA_INSERT###'] = '';
           }
           $markerArrayP["###REF_SUBMIT_FIELDS###"] = $this->cObj->substituteMarkerArrayCached($template, $markerArray, $subpartArray, $wrappedSubpartArray);
           $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUESTION_PAGE###");
           if ($template == '') {
               // if it is not in the template
               $template = $this->cObj->getSubpart($this->origTemplateCode, "###TEMPLATE_QUESTION_PAGE###");
           }
           $content .= $this->cObj->substituteMarkerArray($template, $markerArrayP);
       }
       /** Layout for a result page **/
       if ($answerPage && $quizData['cmd'] != 'exit') {
           if ($this->conf['quizTimeMinutes']) {
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_TIME_LIMIT###");
               if (!$quizData['qtuid']) {
                   $markerArray["###VAR_SECS###"] = intval($this->conf['quizTimeMinutes']) * 60;
                   $markerArray["###VAR_MIN###"] = $this->conf['quizTimeMinutes'];
               } else {
                   $markerArray["###VAR_SECS###"] = intval($this->conf['quizTimeMinutes']) * 60 - $elapseTime;
                   $markerArray["###VAR_MIN###"] = round($markerArray["###VAR_SECS###"] / 60);
               }
               $markerArrayP["###REF_QUIZ_LIMIT###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
           } else {
               $markerArrayP["###REF_QUIZ_LIMIT###"] = '';
           }
           if ($this->helperObj->writeDevLog) {
               t3lib_div::devLog('Displaying result-page...', $this->extKey, 0);
           }
           $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_RESULT_PAGE###");
           if ($template == '') {
               // if it is not in the (old custom) template
               $template = $this->cObj->getSubpart($this->origTemplateCode, "###TEMPLATE_RESULT_PAGE###");
           }
           $content .= $this->cObj->substituteMarkerArray($template, $markerArrayP);
           if ($this->conf['isPoll'] && $this->conf['email.']['send_admin']) {
               $sendMail = true;
           }
       }
       /** Layout for a questions page **/
       if ($questionPage && $quizData['cmd'] != 'exit') {
           if ($this->conf['pageTimeSeconds']) {
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_PAGE_TIME_LIMIT###");
               $markerArray["###VAR_SECS###"] = $pageTimeCat ? $pageTimeCat : $this->conf['pageTimeSeconds'];
               $markerArrayP["###REF_PAGE_LIMIT###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
           } else {
               $markerArrayP["###REF_PAGE_LIMIT###"] = '';
           }
           if ($this->conf['quizTimeMinutes']) {
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_TIME_LIMIT###");
               if (!$quizData['qtuid']) {
                   $markerArray["###VAR_SECS###"] = intval($this->conf['quizTimeMinutes']) * 60;
                   $markerArray["###VAR_MIN###"] = $this->conf['quizTimeMinutes'];
               } else {
                   $markerArray["###VAR_SECS###"] = intval($this->conf['quizTimeMinutes']) * 60 - $elapseTime;
                   $markerArray["###VAR_MIN###"] = round($markerArray["###VAR_SECS###"] / 60);
               }
               $markerArrayP["###REF_QUIZ_LIMIT###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
           } else {
               $markerArrayP["###REF_QUIZ_LIMIT###"] = '';
           }
           $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUESTION_PAGE###");
           if ($template == '') {
               // if it is not in the template
               $template = $this->cObj->getSubpart($this->origTemplateCode, "###TEMPLATE_QUESTION_PAGE###");
           }
           $content .= $this->cObj->substituteMarkerArray($template, $markerArrayP);
       }
       /** Layout for the last/final page **/
       $uidP = 0;
       // page UID
       $uidC = 0;
       // content UID
       if ($finalPage && $quizData['cmd'] != 'exit') {
           // nicht noetig: && !$this->conf['isPoll']) {
           if (($this->conf['showAnalysis'] || $this->conf['showEvaluation']) && !$this->conf['dontShowPoints']) {
               // Analysis depends on points
               if ($this->helperObj->writeDevLog) {
                   t3lib_div::devLog('Displaying Analysis: ' . $this->conf['showAnalysis'] . ' or Evaluation: ' . $this->conf['showEvaluation'], $this->extKey, 0);
               }
               if (!$markerArray["###VAR_TMAX_POINTS###"]) {
                   $this->helperObj->setQuestionsVars();
                   $markerArray["###VAR_TMAX_POINTS###"] = $this->helperObj->getQuestionsMaxPoints();
                   // omax und tmax sollten hier gleich sein
                   if (!$markerArray["###VAR_TMAX_POINTS###"]) {
                       $markerArray["###VAR_TMAX_POINTS###"] = 100000;
                   }
                   // notfalls halt irgendein wert
               }
               $points = $markerArray["###VAR_TOTAL_POINTS###"];
               $percent = 100 * $points / $markerArray["###VAR_TMAX_POINTS###"];
               // genauerer wert...
               $markerArray["###VAR_PERCENT###"] = intval($percent);
               $markerArray["###REACHED1###"] = $this->pi_getLL('reached1', 'reached1');
               $markerArray["###REACHED2###"] = $this->pi_getLL('reached2', 'reached2');
               if ($this->helperObj->writeDevLog) {
                   t3lib_div::devLog('Total points=' . $markerArray["###VAR_TOTAL_POINTS###"] . ' tmax points=' . $markerArray["###VAR_TMAX_POINTS###"] . ' percent=' . $markerArray["###VAR_PERCENT###"], $this->extKey, 0);
               }
               if ($this->conf['showAnalysis']) {
                   $dataArray = explode(',', $this->conf['showAnalysis']);
               } else {
                   $dataArray = explode(',', $this->conf['showEvaluation']);
               }
               $templateNo = '';
               $p = 0;
               while ($p < count($dataArray)) {
                   $templateNo = $dataArray[$p];
                   if (strpos($templateNo, ':') !== false) {
                       if ($this->conf['showAnalysis']) {
                           list($templateNo, $uidP) = explode(":", $templateNo);
                       } else {
                           list($templateNo, $uidC) = explode(":", $templateNo);
                       }
                   }
                   if ($this->conf['showAnalysis']) {
                       if ($percent <= floatval($templateNo)) {
                           // wann abbrechen?
                           //    if ($uidP) ...    // redirect to a URL with that UID  -> weiter nach unten verschoben (nach email Versendung!!)
                           break;
                       }
                   } else {
                       if ($points <= floatval($templateNo)) {
                           // wann abbrechen?
                           break;
                       }
                   }
                   $p++;
               }
               if (!($uidP || $uidC)) {
                   $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_ANALYSIS_{$templateNo}###");
                   $markerArrayP["###REF_QUIZ_ANALYSIS###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
               } else {
                   if ($uidC) {
                       $confC = array('tables' => 'tt_content', 'source' => $uidC, 'dontCheckPid' => 1);
                       $markerArrayP["###REF_QUIZ_ANALYSIS###"] = $this->cObj->RECORDS($confC);
                   }
               }
           } else {
               if ($this->conf['showCategoryElement']) {
                   $showCategoryElement = intval($this->conf['showCategoryElement']);
                   if ($this->helperObj->writeDevLog) {
                       t3lib_div::devLog('Displaying category element: ' . $showCategoryElement . ' nextcat: ' . $nextCat, $this->extKey, 0);
                   }
                   if ($showCategoryElement == 1 && $nextCat > 0 && $this->catArray[$nextCat]['celement']) {
                       $uidC = $this->catArray[$nextCat]['celement'];
                       $confC = array('tables' => 'tt_content', 'source' => $uidC, 'dontCheckPid' => 1);
                       $markerArrayP["###REF_QUIZ_ANALYSIS###"] = $this->cObj->RECORDS($confC);
                       // last category element
                   } else {
                       if ($showCategoryElement > 1 && $this->conf['advancedStatistics']) {
                           $tmpCat = '';
                           $usedCatArray = array();
                           $catCount = 0;
                           $res5 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('DISTINCT nextcat, COUNT(nextcat) anzahl', $this->tableRelation, 'nextcat>0 AND user_id=' . intval($quizData['qtuid']) . ' AND sys_language_uid=' . $this->lang, 'nextcat', 'anzahl DESC', '');
                           $rows = $GLOBALS['TYPO3_DB']->sql_num_rows($res5);
                           if ($rows > 0) {
                               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res5)) {
                                   $tmpCat = $row['nextcat'];
                                   if ($catCount == 0) {
                                       $firstCount = $row['anzahl'];
                                   }
                                   if ($tmpCat && $this->catArray[$tmpCat]['celement'] && ($showCategoryElement == 4 || $showCategoryElement == 3 && $firstCount == $row['anzahl'] || $catCount == 0)) {
                                       $usedCatArray[$tmpCat] = $row['anzahl'];
                                   }
                                   $catCount += $row['anzahl'];
                               }
                           }
                           if (count($usedCatArray) > 0) {
                               $markerArrayC = array();
                               $markerArrayC['###PREFIX###'] = $markerArrayP['###PREFIX###'];
                               $markerArrayC['###ANSWERS###'] = $this->pi_getLL('answers', 'answers');
                               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_CATEGORY_ELEMENT###");
                               foreach ($usedCatArray as $key => $value) {
                                   $uidC = $this->catArray[$key]['celement'];
                                   $confC = array('tables' => 'tt_content', 'source' => $uidC, 'dontCheckPid' => 1);
                                   $markerArrayC['###CATEGORY###'] = $this->catArray[$key]['name'];
                                   $markerArrayC['###CONTENT###'] = $this->cObj->RECORDS($confC);
                                   // most category element
                                   $markerArrayC['###VAR_COUNT###'] = $value;
                                   $markerArrayC['###VAR_PERCENT###'] = round(100 * $value / $catCount);
                                   $markerArrayP["###REF_QUIZ_ANALYSIS###"] .= $this->cObj->substituteMarkerArray($template, $markerArrayC);
                               }
                           }
                           $GLOBALS['TYPO3_DB']->sql_free_result($res5);
                       }
                   }
               }
           }
           if (!$uidP) {
               // no redirect
               $markerArrayP["###FORM_URL###"] = $this->pi_getPageLink($listPID);
               // zur endgueltig letzten seite wechseln
               $markerArrayP["###REF_SUBMIT_FIELDS###"] = '';
               $markerArrayP["###HIDDENFIELDS###"] = '';
               $markerArrayP["###FE_USER_UID###"] = intval($GLOBALS['TSFE']->fe_user->user['uid']);
               if ($this->conf['userData.']['showAtFinal']) {
                   $quiz_taker_name = $GLOBALS['TYPO3_DB']->quoteStr($quizData["name"], $this->tableAnswers);
                   $quiz_taker_email = $GLOBALS['TYPO3_DB']->quoteStr($quizData["email"], $this->tableAnswers);
                   $quiz_taker_homepage = $GLOBALS['TYPO3_DB']->quoteStr($quizData["homepage"], $this->tableAnswers);
                   $markerArray["###REAL_NAME###"] = $quiz_taker_name;
                   $markerArray["###REAL_EMAIL###"] = $quiz_taker_email;
                   $markerArray["###REAL_HOMEPAGE###"] = $quiz_taker_homepage;
                   $markerArray["###RESULT_FOR###"] = $this->pi_getLL('result_for', 'result_for');
                   $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_USER_SUBMITED###");
                   // Output the user name
                   $markerArrayP["###REF_INTRODUCTION###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
               }
               // User-Data Template
               if ($this->conf['userData.']['askAtFinal'] && $quizData['qtuid']) {
                   $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_USER_TO_SUBMIT###");
                   $markerArray['###BACK_STYLE###'] = ' style="display:none;"';
                   if (is_object($this->freeCap) && $this->conf['enableCaptcha']) {
                       $markerArray = array_merge($markerArray, $this->freeCap->makeCaptcha());
                   } else {
                       $subpartArray['###CAPTCHA_INSERT###'] = '';
                   }
                   $firsttime = $this->helperObj->getFirstTime($quizData['qtuid']);
                   $markerArrayP["###REF_SUBMIT_FIELDS###"] = $this->cObj->substituteMarkerArrayCached($template, $markerArray, $subpartArray, $wrappedSubpartArray);
                   $markerArrayP["###HIDDENFIELDS###"] = "\n" . '  <input type="hidden" name="' . $this->prefixId . '[qtuid]" value="' . intval($quizData["qtuid"]) . '" />' . "\n";
                   $markerArrayP["###HIDDENFIELDS###"] .= '  <input type="hidden" name="' . $this->prefixId . '[setUserData]" value="' . $firsttime . '" />' . "\n";
                   $markerArrayP["###HIDDENFIELDS###"] .= '  <input type="hidden" name="' . $this->prefixId . '[fromFinal]" value="1" />';
               }
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_FINAL_PAGE###");
               if ($template == '') {
                   // if it is not in the template
                   $template = $this->cObj->getSubpart($this->origTemplateCode, "###TEMPLATE_QUIZ_FINAL_PAGE###");
               }
               $content .= $this->cObj->substituteMarkerArray($template, $markerArrayP);
           }
           if ($this->conf['email.']['send_admin'] == 1 || $this->conf['email.']['send_user'] == 1) {
               $sendMail = true;
           }
       }
       /** Send an/two email(s)? **/
       if ($sendMail && !$error && !$secondVisit) {
           if ($this->helperObj->writeDevLog) {
               t3lib_div::devLog('Entering "send emails"...', $this->extKey, 0);
           }
           $markerArrayP["###EMAIL_TAKEN###"] = $this->pi_getLL('email_taken', 'email_taken');
           if (!$markerArrayP["###REF_INTRODUCTION###"] && !$this->conf['isPoll']) {
               if (!$markerArray["###RESULT_FOR###"]) {
                   $markerArray["###REAL_NAME###"] = htmlspecialchars($quizData['name']);
                   $markerArray["###REAL_EMAIL###"] = htmlspecialchars($quizData['email']);
                   $markerArray["###REAL_HOMEPAGE###"] = htmlspecialchars($quizData['homepage']);
                   $markerArray["###RESULT_FOR###"] = $this->pi_getLL('result_for', 'result_for');
               }
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_QUIZ_USER_SUBMITED###");
               // Output the user name
               $markerArrayP["###REF_INTRODUCTION###"] = $this->cObj->substituteMarkerArray($template, $markerArray);
           }
           if ($this->conf['showAllCorrectAnswers'] && !$this->conf['isPoll']) {
               // show all answers...
               $quizData['sendEmailNow'] = true;
               // noetig um zu wissen, welches Template genommen werden soll
               $markerArrayP["###REF_EMAIL_ALLANSWERS###"] = $this->showAllAnswers($quizData, $thePID, $resPID, true, 0);
           } else {
               $markerArrayP["###REF_EMAIL_ALLANSWERS###"] = '';
           }
           if ($this->conf['email.']['send_admin'] && t3lib_div::validEmail($this->conf['email.']['admin_mail']) && $this->conf['email.']['admin_subject']) {
               if ($this->helperObj->writeDevLog) {
                   t3lib_div::devLog('Sending email to admin: ' . $this->conf['email.']['admin_mail'], $this->extKey, 0);
               }
               $markerArrayP["###SUBJECT###"] = $this->conf['email.']['admin_subject'];
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_ADMIN_EMAIL###");
               if ($template == '') {
                   // if it is not in the template
                   $template = $this->cObj->getSubpart($this->origTemplateCode, "###TEMPLATE_ADMIN_EMAIL###");
               }
               $mailcontent = $this->cObj->substituteMarkerArray($template, $markerArrayP);
               $this->helperObj->sendEmail($mailcontent, '', $this->conf['email.']['admin_mail'], $this->conf['email.']['admin_name'], $this->conf['email.']['admin_subject']);
           }
           if ($this->conf['email.']['send_user'] && t3lib_div::validEmail($quizData["email"]) && $this->conf['email.']['user_subject']) {
               if ($this->helperObj->writeDevLog) {
                   t3lib_div::devLog('Sending email to user: '******'email.']['user_subject'];
               $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_USER_EMAIL###");
               if ($template == '') {
                   // if it is not in the template
                   $template = $this->cObj->getSubpart($this->origTemplateCode, "###TEMPLATE_USER_EMAIL###");
               }
               $mailcontent = $this->cObj->substituteMarkerArray($template, $markerArrayP);
               $this->helperObj->sendEmail($mailcontent, '', $quizData["email"], $quizData["name"], $this->conf['email.']['user_subject']);
           }
       }
       /** Delete user result at the end of the quiz? **/
       if ($finalPage && $this->conf['deleteResults']) {
           // 60*60*24 = 86400 = 1 tag
           $loesche = '';
           $counter = 0;
           $where = 'pid=' . $resPID;
           $where .= ' AND (crdate<' . (time() - 86400) . ' OR uid=' . intval($quizData['qtuid']) . ')';
           if ($this->conf['deleteResults'] == 2) {
               $where .= ' AND fe_uid=0';
           }
           if ($this->conf['deleteResults'] == 3) {
               $where .= " AND name='" . $GLOBALS['TYPO3_DB']->quoteStr($this->pi_getLL('no_name', 'no_name'), $this->tableAnswers) . "'";
           }
           $res5 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $this->tableAnswers, $where, '', 'crdate DESC', '255');
           if ($GLOBALS['TYPO3_DB']->sql_num_rows($res5) > 0) {
               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res5)) {
                   $loesche .= ', ' . $row['uid'];
                   $counter++;
               }
               $loesche = substr($loesche, 1);
           }
           $GLOBALS['TYPO3_DB']->sql_free_result($res5);
           if ($this->conf['deleteDouble'] && $counter < 250) {
               // mehrfache eintraege eines users zu einem quiz loeschen
               $where2 = '';
               $fe_uid = intval($GLOBALS['TSFE']->fe_user->user['uid']);
               if ($this->conf['deleteResults'] == 2 && $fe_uid > 0) {
                   $where2 = ' AND fe_uid=' . $fe_uid;
               } else {
                   if ($this->conf['deleteResults'] == 3 && $quizData["name"] != $this->pi_getLL('no_name', 'no_name') && $quizData["name"]) {
                       $where2 = " AND name='" . $GLOBALS['TYPO3_DB']->quoteStr($quizData["name"], $this->tableAnswers) . "'";
                   }
               }
               if ($where2) {
                   $start_uid = $this->helperObj->getStartUid($quizData['qtuid']);
                   $res5 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid, o_percent, crdate', $this->tableAnswers, 'pid=' . $resPID . ' AND sys_language_uid=' . $this->lang . ' AND start_uid=' . $start_uid . $where2, '', 'o_percent DESC, crdate DESC', '200');
                   $rows = $GLOBALS['TYPO3_DB']->sql_num_rows($res5);
                   if ($rows > 0) {
                       $counter = 0;
                       while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res5)) {
                           $counter++;
                           if ($counter > 1) {
                               $loesche .= $loesche ? ',' . $row['uid'] : $row['uid'];
                           }
                       }
                   }
                   $GLOBALS['TYPO3_DB']->sql_free_result($res5);
               }
           }
           if ($this->helperObj->writeDevLog) {
               t3lib_div::devLog('Deleting result data with: ' . $where . $where2 . ' => ' . $loesche, $this->extKey, 0);
           }
           if ($loesche) {
               $res = $GLOBALS['TYPO3_DB']->exec_DELETEquery($this->tableRelation, 'user_id IN (' . preg_replace('/[^0-9,]/', '', $loesche) . ')');
               $res = $GLOBALS['TYPO3_DB']->exec_DELETEquery($this->tableAnswers, 'uid IN (' . preg_replace('/[^0-9,]/', '', $loesche) . ')');
           }
       }
       /** Redirect at the end of the quiz? **/
       if ($finalPage && $uidP) {
           // redirect to a URL with that UID
           $this->redirectUrl($uidP, array($this->prefixId . '[name]' => $quizData["name"], $this->prefixId . '[email]' => $quizData["email"], $this->prefixId . '[homepage]' => $quizData["homepage"]));
       }
       if ($this->helperObj->writeDevLog) {
           t3lib_div::devLog('return the content to the Typo3 core', $this->extKey, 0);
       }
       return $this->pi_wrapInBaseClass($content);
   }