/** * Main method of the dispatcher. This method is called as a user function. * * @return string rendered view * @param string $content * @param array $setup The TypoScript config */ public function main($content, $setup) { $this->pi_USER_INT_obj = 1; try { //init flexform $this->pi_initPIflexForm(); /* * Parse values from flexform: * - Template file * - Translation file * - Predefined form * - E-mail settings * - Required fields * - Redirect page */ $templateFile = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template_file', 'sDEF'); $langFile = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'lang_file', 'sDEF'); $predef = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'predefined', 'sDEF'); Tx_Formhandler_Globals::$predef = $predef; Tx_Formhandler_Globals::$cObj = $this->cObj; Tx_Formhandler_Globals::$overrideSettings = $setup; $this->componentManager = Tx_Formhandler_Component_Manager::getInstance(); /* * set controller: * 1. Default controller * 2. TypoScript */ $controller = 'Tx_Formhandler_Controller_Form'; if ($setup['controller']) { $controller = $setup['controller']; } $controller = Tx_Formhandler_StaticFuncs::prepareClassName($controller); $controller = $this->componentManager->getComponent($controller); if (isset($content)) { $controller->setContent($this->componentManager->getComponent('Tx_Formhandler_Content', $content)); } if (strlen($templateFile) > 0) { $controller->setTemplateFile($templateFile); } if (strlen($langFile) > 0) { $controller->setLangFiles(array($langFile)); } if (strlen($predef) > 0) { $controller->setPredefined($predef); } $result = $controller->process(); } catch (Exception $e) { $result = '<div style="color:red; font-weight: bold">Caught exception: ' . $e->getMessage() . '</div>'; $result .= '<div style="color:red; font-weight: bold">File: ' . $e->getFile() . '(' . $e->getLine() . ')</div>'; } if (Tx_Formhandler_Globals::$session && Tx_Formhandler_Globals::$session->get('debug')) { foreach (Tx_Formhandler_Globals::$debuggers as $idx => $debugger) { $debugger->outputDebugLog(); } } return $result; }
protected function initializeDebuggers() { $this->addFormhandlerClass($this->settings['debuggers.'], 'Tx_Formhandler_Debugger_Print'); foreach ($this->settings['debuggers.'] as $idx => $options) { if (intval($options['disable']) !== 1) { $debuggerClass = $options['class']; $debuggerClass = Tx_Formhandler_StaticFuncs::prepareClassName($debuggerClass); $debugger = $this->componentManager->getComponent($debuggerClass); $debugger->init($this->gp, $options['config.']); $debugger->validateConfig(); Tx_Formhandler_Globals::$debuggers[] = $debugger; } } }
/** * Function to generate a PDF file from submitted form values. This function is called by Tx_Formhandler_Controller_Backend * * @param array $records The records to export to PDF * @param array $exportFields A list of fields to export. If not set all fields are exported * @see Tx_Formhandler_Controller_Backend::generatePDF() * @return void */ function generateModulePDF($records, $exportFields = array()) { //init pdf object $this->pdf = $this->componentManager->getComponent('Tx_Formhandler_Template_TCPDF'); $addedOneRecord = FALSE; //for all records, //check if the record is valid. //a valid record has at least one param to export //if no valid record is found render an error message in pdf file foreach ($records as $data) { $valid = FALSE; if (isset($data['params']) && is_array($data['params'])) { foreach ($data['params'] as $key => $value) { if (count($exportFields) == 0 || in_array($key, $exportFields)) { $valid = TRUE; } } } if ($valid) { $addedOneRecord = TRUE; $this->pdf->AliasNbPages(); $this->pdf->AddPage(); $this->pdf->SetFont('Helvetica', '', 12); $standardWidth = 100; $nameWidth = 70; $valueWidth = 70; $feedWidth = 30; if (count($exportFields) == 0 || in_array('pid', $exportFields)) { $this->pdf->Cell($standardWidth, '15', 'Page-ID:', 0, 0); $this->pdf->Cell($standardWidth, '15', $data['pid'], 0, 1); } if (count($exportFields) == 0 || in_array('submission_date', $exportFields)) { $this->pdf->Cell($standardWidth, '15', 'Submission date:', 0, 0); $this->pdf->Cell($standardWidth, '15', date('d.m.Y H:i:s', $data['crdate']), 0, 1); } if (count($exportFields) == 0 || in_array('ip', $exportFields)) { $this->pdf->Cell($standardWidth, '15', 'IP address:', 0, 0); $this->pdf->Cell($standardWidth, '15', $data['ip'], 0, 1); } $this->pdf->Cell($standardWidth, '15', 'Submitted values:', 0, 1); $this->pdf->SetLineWidth(0.3); $this->pdf->Cell($feedWidth); $this->pdf->SetFillColor(255, 255, 255); $this->pdf->Cell($nameWidth, '6', 'Name', 'B', 0, 'C', TRUE); $this->pdf->Cell($valueWidth, '6', 'Value', 'B', 0, 'C', TRUE); $this->pdf->Ln(); $this->pdf->SetFillColor(200, 200, 200); $fill = FALSE; foreach ($exportFields as $key => $field) { if (strcmp($field, 'pid') == FALSE || strcmp($field, 'submission_date') == FALSE || strcmp($field, 'ip') == FALSE) { unset($exportFields[$key]); } } if (count($exportFields) == 0) { $exportFields = array_keys($data['params']); } foreach ($exportFields as $idx => $key) { if (isset($data['params'][$key])) { $value = $data['params'][$key]; if (is_array($value)) { $this->pdf->Cell($feedWidth); $this->pdf->Cell($nameWidth, '6', $key, 0, 0, 'L', $fill); $this->pdf->Cell($valueWidth, '6', array_shift($value), 0, 0, 'L', $fill); $this->pdf->Ln(); foreach ($value as $v) { $this->pdf->Cell($feedWidth); $this->pdf->Cell($nameWidth, '6', '', 0, 0, 'L', $fill); $this->pdf->Cell($valueWidth, '6', $v, 0, 0, 'L', $fill); $this->pdf->Ln(); } $fill = !$fill; } else { $this->pdf->Cell($feedWidth); $this->pdf->Cell($nameWidth, '6', $key, 0, 0, 'L', $fill); $this->pdf->Cell($valueWidth, '6', $value, 0, 0, 'L', $fill); $this->pdf->Ln(); $fill = !$fill; } } } } } //if no valid record was found, render an error message if (!$addedOneRecord) { $this->pdf->AliasNbPages(); $this->pdf->AddPage(); $this->pdf->SetFont('Helvetica', '', 12); $this->pdf->Cell(300, 100, 'No valid records found! Try to select more fields to export!', 0, 0, 'L'); } $this->pdf->Output('formhandler.pdf', 'D'); exit; }
/** * Main method of the dispatcher. This method is called as a user function. * * @return string rendered view * @param string $content * @param array $setup The TypoScript config */ public function main($content, $setup) { $this->pi_USER_INT_obj = 1; $this->globals = Tx_Formhandler_Globals::getInstance(); $this->utilityFuncs = Tx_Formhandler_UtilityFuncs::getInstance(); try { //init flexform $this->pi_initPIflexForm(); /* * Parse values from flexform: * - Template file * - Translation file * - Predefined form * - E-mail settings * - Required fields * - Redirect page */ $templateFile = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template_file', 'sDEF'); $langFile = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'lang_file', 'sDEF'); $predef = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'predefined', 'sDEF'); $this->globals->setCObj($this->cObj); if ($setup['usePredef']) { $predef = $this->utilityFuncs->getSingle($setup, 'usePredef'); } $this->globals->getCObj()->setCurrentVal($predef); $this->globals->setPredef($predef); $this->globals->setOverrideSettings($setup); $this->componentManager = Tx_Formhandler_Component_Manager::getInstance(); /* * set controller: * 1. Default controller * 2. TypoScript */ $controller = 'Tx_Formhandler_Controller_Form'; if ($setup['controller']) { $controller = $setup['controller']; } $controller = $this->utilityFuncs->prepareClassName($controller); $controller = $this->componentManager->getComponent($controller); if (isset($content)) { $controller->setContent($this->componentManager->getComponent('Tx_Formhandler_Content', $content)); } if (strlen($templateFile) > 0) { $controller->setTemplateFile($templateFile); } if (strlen($langFile) > 0) { $controller->setLangFiles(array($langFile)); } if (strlen($predef) > 0) { $controller->setPredefined($predef); } $result = $controller->process(); } catch (Exception $e) { \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($e->getFile() . '(' . $e->getLine() . ')' . ' ' . $e->getMessage(), 'formhandler', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR); $result = $this->utilityFuncs->getTranslatedMessage($this->globals->getLangFiles(), 'fe-exception'); if (!$result) { $result = '<div style="color:red; font-weight: bold">' . $this->utilityFuncs->getExceptionMessage('fe-exception') . '</div>'; } if ($this->globals->getSession() && $this->globals->getSession()->get('debug')) { $result = '<div style="color:red; font-weight: bold">' . $e->getMessage() . '</div>'; $result .= '<div style="color:red; font-weight: bold">File: ' . $e->getFile() . '(' . $e->getLine() . ')</div>'; $result .= '<div style="color:red; font-weight: bold">' . $e->getTraceAsString() . '</div>'; } } if ($this->globals->getSession() && $this->globals->getSession()->get('debug')) { $debuggers = $this->globals->getDebuggers(); foreach ($debuggers as $idx => $debugger) { $debugger->outputDebugLog(); } } return $result; }
/** * Function to handle the generation of a CSV file. * Before the data gets exported, the data is checked and the user gets informed about different formats of the data. * Each format has to be exported in an own file. After the format selection, the user is able to select which fields to export in a selection view. * This enables the user to get rid of fields like submitted or mp-step. * * @param misc $detailId The record uids to export to csv * @return void/string selection view * @author Reinhard Führicht <*****@*****.**> */ protected function generateCSV($detailId) { $where = ''; if (!$detailId) { $where = '1=1'; } elseif (!is_array($detailId)) { $where = 'uid=' . $detailId; } else { $where = 'uid IN (' . implode(',', $detailId) . ')'; } //init gp params $params = t3lib_div::_GP('formhandler'); //select the records to export $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid,crdate,ip,params,key_hash', $this->logTable, $where); //if record were found if ($res && $GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) { $records = array(); $count = 0; $hashes = array(); $availableFormats = array(); //loop through records while (FALSE !== ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) { //unserialize the params array $row['params'] = unserialize($row['params']); //find the amount of different formats to inform the user. if (!in_array($row['key_hash'], $hashes)) { $hashes[] = $row['key_hash']; $availableFormats[] = $row['params']; } $records[] = $row; } $GLOBALS['TYPO3_DB']->sql_free_result($res); $availableFormatsCount = count($availableFormats); //only one format found if ($availableFormatsCount === 1) { $tsconfig = t3lib_BEfunc::getModTSconfig($this->id, 'tx_formhandler_mod1'); $configParams = array(); // check if TSconfig filter is set if ($tsconfig['properties']['config.']['csv'] != "") { $configParams = t3lib_div::trimExplode(',', $tsconfig['properties']['config.']['csv'], 1); $generator = $this->componentManager->getComponent('Tx_Formhandler_Generator_CSV'); $generator->generateModuleCSV($records, $configParams); } elseif (isset($params['exportParams'])) { //if fields were chosen in the selection view, perform the export $generator = $this->componentManager->getComponent('Tx_Formhandler_Generator_CSV'); $generator->generateModuleCSV($records, $params['exportParams']); //no fields chosen, show selection view. } else { return $this->generateCSVExportFieldsSelector($records[0]['params']); } //more than one format and user has chosen a format to export } elseif (isset($params['csvFormat'])) { $renderRecords = array(); if ($params['csvFormat'] === '*') { $renderRecords = $records; } else { //select the format $format = $hashes[$params['csvFormat']]; $renderRecords = array(); //find out which records belong to this format foreach ($records as $record) { if (!strcmp($record['key_hash'], $format)) { $renderRecords[] = $record; } } } $tsconfig = t3lib_BEfunc::getModTSconfig($this->id, 'tx_formhandler_mod1'); $configParams = array(); // check if TSconfig filter is set if ($tsconfig['properties']['config.']['csv'] != "") { $configParams = t3lib_div::trimExplode(',', $tsconfig['properties']['config.']['csv'], 1); $generator = $this->componentManager->getComponent('Tx_Formhandler_Generator_CSV'); $generator->generateModuleCSV($renderRecords, $configParams); } elseif (isset($params['exportParams'])) { //if fields were chosen in the selection view, perform the export $generator = $this->componentManager->getComponent('Tx_Formhandler_Generator_CSV'); $generator->generateModuleCSV($renderRecords, $params['exportParams']); //no fields chosen, show selection view. } else { $fields = $renderRecords[0]['params']; if ($params['csvFormat'] === '*') { $exportParams = array(); foreach ($renderRecords as $record) { foreach ($record['params'] as $key => $value) { if (!array_key_exists($key, $exportParams)) { $exportParams[$key] = $value; } } } $fields = $exportParams; } return $this->generateCSVExportFieldsSelector($fields); } //more than one format and none chosen by now, show format selection view. } else { return $this->generateFormatsSelector($availableFormats, $detailId); } } }