/** * Moves uploaded files from temporary upload folder to a specified new folder. * This enables you to move the files from a successful submission to another folder and clean the files in temporary upload folder from time to time. * * TypoScript example: * * 1. Set the temporary upload folder * <code> * plugin.Tx_Formhandler.settings.files.tmpUploadFolder = uploads/formhandler/tmp * </code> * * 2. Set the folder to move the files to after submission * <code> * plugin.Tx_Formhandler.settings.finishers.1.class = Tx_Formhandler_Finisher_StoreUploadedFiles * plugin.Tx_Formhandler.settings.finishers.1.config.finishedUploadFolder = uploads/formhandler/finishedFiles/ * plugin.Tx_Formhandler.settings.finishers.1.config.renameScheme = [filename]_[md5]_[time] * </code> * * @return void */ protected function moveUploadedFiles() { $newFolder = $this->settings['finishedUploadFolder']; $newFolder = Tx_Formhandler_StaticFuncs::sanitizePath($newFolder); $uploadPath = Tx_Formhandler_StaticFuncs::getDocumentRoot() . $newFolder; $sessionFiles = Tx_Formhandler_Globals::$session->get('files'); if (is_array($sessionFiles) && !empty($sessionFiles) && strlen($newFolder) > 0) { foreach ($sessionFiles as $field => $files) { $this->gp[$field] = array(); foreach ($files as $key => $file) { if ($file['uploaded_path'] != $uploadPath) { $newFilename = $this->getNewFilename($file['uploaded_name']); Tx_Formhandler_StaticFuncs::debugMessage('copy_file', array($file['uploaded_path'] . $file['uploaded_name'], $uploadPath . $newFilename)); copy($file['uploaded_path'] . $file['uploaded_name'], $uploadPath . $newFilename); t3lib_div::fixPermissions($uploadPath . $newFilename); unlink($file['uploaded_path'] . $file['uploaded_name']); $sessionFiles[$field][$key]['uploaded_path'] = $uploadPath; $sessionFiles[$field][$key]['uploaded_name'] = $newFilename; $sessionFiles[$field][$key]['uploaded_folder'] = $newFolder; $sessionFiles[$field][$key]['uploaded_url'] = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . $newFolder . $newFilename; if (!is_array($this->gp[$field])) { $this->gp[$field] = array(); } array_push($this->gp[$field], $newFilename); } } } Tx_Formhandler_Globals::$session->set('files', $sessionFiles); } }
/** * Logs the given values. * * @return void */ public function process() { //set params $table = "tx_formhandler_log"; $fields['ip'] = t3lib_div::getIndpEnv('REMOTE_ADDR'); if (isset($this->settings['disableIPlog']) && intval($this->settings['disableIPlog']) == 1) { $fields['ip'] = NULL; } $fields['tstamp'] = time(); $fields['crdate'] = time(); $fields['pid'] = Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'pid'); if (!$fields['pid']) { $fields['pid'] = $GLOBALS['TSFE']->id; } ksort($this->gp); $keys = array_keys($this->gp); $serialized = serialize($this->gp); $hash = md5(serialize($keys)); $fields['params'] = $serialized; $fields['key_hash'] = $hash; if (intval($this->settings['markAsSpam']) == 1) { $fields['is_spam'] = 1; } //query the database $res = $GLOBALS['TYPO3_DB']->exec_INSERTquery($table, $fields); $insertedUID = $GLOBALS['TYPO3_DB']->sql_insert_id(); $sessionValues = array('inserted_uid' => $insertedUID, 'inserted_tstamp' => $fields['tstamp'], 'key_hash' => $hash); Tx_Formhandler_Globals::$session->setMultiple($sessionValues); if (!$this->settings['nodebug']) { Tx_Formhandler_StaticFuncs::debugMessage('logging', array($table, implode(',', $fields))); if (strlen($GLOBALS['TYPO3_DB']->sql_error()) > 0) { Tx_Formhandler_StaticFuncs::debugMessage('error', array($GLOBALS['TYPO3_DB']->sql_error()), 3); } } }
public function process() { if (Tx_Formhandler_Globals::$session->get('originalLanguage') !== NULL) { $GLOBALS['TSFE']->lang = Tx_Formhandler_Globals::$session->get('originalLanguage'); Tx_Formhandler_Globals::$session->set('originalLanguage', NULL); Tx_Formhandler_StaticFuncs::debugMessage('Language restored to "' . $GLOBALS['TSFE']->lang . '"!', array(), 1); } else { Tx_Formhandler_StaticFuncs::debugMessage('Unable to restore language! No original language found!', array(), 2); } return $this->gp; }
/** * The main method called by the controller * * @return array The probably modified GET/POST parameters */ public function process() { $cacheCmd = Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'cacheCmd'); if (empty($cacheCmd)) { $cacheCmd = $GLOBALS['TSFE']->id; } Tx_Formhandler_StaticFuncs::debugMessage('cacheCmd', array($cacheCmd)); $tce = t3lib_div::makeInstance('t3lib_tcemain'); $tce->clear_cacheCmd($cacheCmd); return $this->gp; }
/** * The main method called by the controller * * @return array The probably modified GET/POST parameters */ public function process() { if (is_array($this->settings['combineFields.'])) { foreach ($this->settings['combineFields.'] as $newField => $options) { $newField = str_replace('.', '', $newField); if (is_array($options['fields.'])) { $this->gp[$newField] = $this->combineFields($options); Tx_Formhandler_StaticFuncs::debugMessage('combined', array($newField, $this->gp[$newField])); } } } return $this->gp; }
/** * The main method called by the controller * * @return array The probably modified GET/POST parameters */ public function process() { $this->langFiles = Tx_Formhandler_Globals::$langFiles; if (is_array($this->settings['translateFields.'])) { foreach ($this->settings['translateFields.'] as $newField => $options) { $newField = str_replace('.', '', $newField); if (isset($options['langKey'])) { $this->gp[$newField] = $this->translateFields($options); Tx_Formhandler_StaticFuncs::debugMessage('translated', array($newField, $this->gp[$newField])); } } } return $this->gp; }
public function process() { if (Tx_Formhandler_Globals::$session->get('originalLanguage') === NULL) { Tx_Formhandler_Globals::$session->set('originalLanguage', $GLOBALS['TSFE']->lang); } $languageCode = Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'languageCode'); if ($languageCode) { $GLOBALS['TSFE']->lang = strtolower($languageCode); Tx_Formhandler_StaticFuncs::debugMessage('Language set to "' . $GLOBALS['TSFE']->lang . '"!', array(), 1); } else { Tx_Formhandler_StaticFuncs::debugMessage('Unable to set language! Language code set in TypoScript is empty!', array(), 2); } return $this->gp; }
/** * The main method called by the controller * * @return array The probably modified GET/POST parameters */ public function process() { //read template file $this->templateFile = Tx_Formhandler_Globals::$templateCode; //set view $view = $this->componentManager->getComponent('Tx_Formhandler_View_SubmittedOK'); //show TEMPLATE_SUBMITTEDOK $view->setTemplate($this->templateFile, 'SUBMITTEDOK' . Tx_Formhandler_Globals::$templateSuffix); if (!$view->hasTemplate()) { $view->setTemplate($this->templateFile, 'SUBMITTEDOK'); if (!$view->hasTemplate()) { Tx_Formhandler_StaticFuncs::debugMessage('no_submittedok_template', array(), 3); } } $view->setSettings(Tx_Formhandler_Globals::$session->get('settings')); $view->setComponentSettings($this->settings); return $view->render($this->gp, array()); }
/** * Validates that a specified field's value is found in a specified db table * * @param array &$check The TypoScript settings for this error check * @param string $name The field name * @param array &$gp The current GET/POST parameters * @return string The error string */ public function check(&$check, $name, &$gp) { $checkFailed = ''; if (isset($gp[$name]) && strlen(trim($gp[$name])) > 0) { $checkTable = Tx_Formhandler_StaticFuncs::getSingle($check['params'], 'table'); $checkField = Tx_Formhandler_StaticFuncs::getSingle($check['params'], 'field'); $additionalWhere = Tx_Formhandler_StaticFuncs::getSingle($check['params'], 'additionalWhere'); if (!empty($checkTable) && !empty($checkField)) { $where = $checkField . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($gp[$name], $checkTable) . ' ' . $additionalWhere; $showHidden = intval($check['params']['showHidden']) === 1 ? 1 : 0; $where .= $GLOBALS['TSFE']->sys_page->enableFields($checkTable, $showHidden); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($checkField, $checkTable, $where); if ($res && !$GLOBALS['TYPO3_DB']->sql_num_rows($res)) { $checkFailed = $this->getCheckFailed($check); } elseif (!$res) { Tx_Formhandler_StaticFuncs::debugMessage('error', array($GLOBALS['TYPO3_DB']->sql_error()), 3); } $GLOBALS['TYPO3_DB']->sql_free_result($res); } } return $checkFailed; }
/** * Sends mail according to given type. * * @param string $type (admin|user) * @return void */ protected function sendMail($type) { $doSend = TRUE; if (intval($this->settings[$type]['disable']) === 1) { Tx_Formhandler_StaticFuncs::debugMessage('mail_disabled', array($type)); $doSend = FALSE; } $mailSettings = $this->settings[$type]; $plain = $this->parseTemplate($type, 'plain'); if (strlen(trim($plain)) > 0) { $template['plain'] = $plain; } $html = $this->parseTemplate($type, 'html'); if (strlen(trim($html)) > 0) { $template['html'] = $html; } //init mailer object $emailClass = $this->settings['mailer.']['class']; if (!$emailClass) { $emailClass = 'Tx_Formhandler_Mailer_HtmlMail'; } $emailClass = Tx_Formhandler_StaticFuncs::prepareClassName($emailClass); $emailObj = $this->componentManager->getComponent($emailClass); $emailObj->init($this->gp, $this->settings['mailer.']['config.']); //set e-mail options $emailObj->setSubject($mailSettings['subject']); $sender = $mailSettings['sender_email']; if (isset($mailSettings['sender_email']) && is_array($mailSettings['sender_email'])) { $sender = implode(',', $mailSettings['sender_email']); } $senderName = $mailSettings['sender_name']; if (isset($mailSettings['sender_name']) && is_array($mailSettings['sender_name'])) { $senderName = implode(',', $mailSettings['sender_name']); } $emailObj->setSender($sender, $senderName); $replyto = $mailSettings['replyto_email']; if (isset($mailSettings['replyto_email']) && is_array($mailSettings['replyto_email'])) { $replyto = implode(',', $mailSettings['replyto_email']); } $replytoName = $mailSettings['replyto_name']; if (isset($mailSettings['replyto_name']) && is_array($mailSettings['replyto_name'])) { $replytoName = implode(',', $mailSettings['replyto_name']); } $emailObj->setReplyTo($replyto, $replytoName); $cc = $mailSettings['cc_email']; if (!is_array($cc)) { $cc = array($cc); } $ccName = $mailSettings['cc_name']; if (!is_array($ccName)) { $ccName = array($ccName); } foreach ($cc as $key => $email) { $name = ''; if (isset($ccName[$key])) { $name = $ccName[$key]; } if (strlen($email) > 0) { $emailObj->addCc($email, $name); } } $bcc = $mailSettings['bcc_email']; if (!is_array($bcc)) { $bcc = array($bcc); } $bccName = $mailSettings['bcc_name']; if (!is_array($bccName)) { $bccName = array($bccName); } foreach ($bcc as $key => $email) { $name = ''; if (isset($bccName[$key])) { $name = $bccName[$key]; } if (strlen($email) > 0) { $emailObj->addBcc($email, $name); } } $returnPath = $mailSettings['return_path']; if (isset($mailSettings['return_path']) && is_array($mailSettings['return_path'])) { $returnPath = implode(',', $mailSettings['return_path']); } $emailObj->setReturnPath($returnPath); if ($mailSettings['email_header']) { $emailObj->addHeader($mailSettings['header']); } if (strlen(trim($template['plain'])) > 0) { $emailObj->setPlain($template['plain']); } else { $emailObj->setPlain(NULL); } if (strlen(trim($template['html'])) > 0) { if ($mailSettings['htmlEmailAsAttachment']) { $prefix = 'formhandler_'; if (isset($mailSettings['filePrefix.']['html'])) { $prefix = $mailSettings['filePrefix.']['html']; } elseif (isset($mailSettings['filePrefix'])) { $prefix = $mailSettings['filePrefix']; } $tmphtml = tempnam('typo3temp/', '/' . $prefix) . '.html'; $tmphtml = str_replace('.tmp', '', $tmphtml); $tmphandle = fopen($tmphtml, 'wb'); if ($tmphandle) { fwrite($tmphandle, $template['html']); fclose($tmphandle); Tx_Formhandler_StaticFuncs::debugMessage('adding_html', array(), 1, array($template['html'])); $emailObj->addAttachment($tmphtml); } } else { $emailObj->setHtml($template['html']); } } if (!is_array($mailSettings['attachment'])) { $mailSettings['attachment'] = array($mailSettings['attachment']); } foreach ($mailSettings['attachment'] as $idx => $attachment) { if (strlen($attachment) > 0) { $emailObj->addAttachment($attachment); } } if ($mailSettings['attachPDF']) { Tx_Formhandler_StaticFuncs::debugMessage('adding_pdf', array(), 1, array($mailSettings['attachPDF'])); $emailObj->addAttachment($mailSettings['attachPDF']); } //parse max count of mails to send $count = 0; $max = $this->settings['limitMailsToUser']; if (!$max) { $max = 2; } if (!is_array($mailSettings['to_email'])) { $mailSettings['to_email'] = array($mailSettings['to_email']); } reset($mailSettings['to_email']); //send e-mails foreach ($mailSettings['to_email'] as $idx => $mailto) { $sent = FALSE; if ($count < $max) { if (strpos($mailto, '@') && $doSend) { $sent = $emailObj->send($mailto); } $count++; } if ($sent) { Tx_Formhandler_StaticFuncs::debugMessage('mail_sent', array($mailto)); } else { Tx_Formhandler_StaticFuncs::debugMessage('mail_not_sent', array($mailto), 2); } Tx_Formhandler_StaticFuncs::debugMessage('mail_subject', array($emailObj->getSubject())); Tx_Formhandler_StaticFuncs::debugMessage('mail_sender', array($emailObj->getSender())); Tx_Formhandler_StaticFuncs::debugMessage('mail_replyto', array($emailObj->getReplyTo())); Tx_Formhandler_StaticFuncs::debugMessage('mail_returnpath', array($emailObj->returnPath)); Tx_Formhandler_StaticFuncs::debugMessage('mail_cc', array(implode('<br />', $emailObj->getCc()))); Tx_Formhandler_StaticFuncs::debugMessage('mail_bcc', array(implode('<br />', $emailObj->getBcc()))); Tx_Formhandler_StaticFuncs::debugMessage('mail_plain', array(), 1, array($template['plain'])); Tx_Formhandler_StaticFuncs::debugMessage('mail_html', array(), 1, array($template['html'])); } if ($tmphtml) { unlink($tmphtml); } }
/** * Runs the class by calling process() method. * * @author Reinhard Führicht <*****@*****.**> * @param array $classesArray: the configuration array * @return void */ protected function runClasses($classesArray) { $output = ''; if (isset($classesArray) && is_array($classesArray) && intval($classesArray['disable']) !== 1) { foreach ($classesArray as $idx => $tsConfig) { if (is_array($tsConfig) && isset($tsConfig['class']) && !empty($tsConfig['class'])) { if (intval($tsConfig['disable']) !== 1) { $className = Tx_Formhandler_StaticFuncs::prepareClassName($tsConfig['class']); Tx_Formhandler_StaticFuncs::debugMessage('calling_class', array($className)); $obj = $this->componentManager->getComponent($className); $tsConfig['config.'] = $this->addDefaultComponentConfig($tsConfig['config.']); $obj->init($this->gp, $tsConfig['config.']); $obj->validateConfig(); $return = $obj->process(); if (is_array($return)) { //return value is an array. Treat it as the probably modified get/post parameters $this->gp = $return; Tx_Formhandler_Globals::$gp = $this->gp; } else { //return value is no array. treat this return value as output. return $return; } } } else { Tx_Formhandler_StaticFuncs::throwException('classesarray_error'); } } } }
/** * Searches for upload folder settings in TypoScript setup. * If no settings is found, the default upload folder is set. * * Here is an example: * <code> * plugin.Tx_Formhandler.settings.files.tmpUploadFolder = uploads/formhandler/tmp * </code> * * The default upload folder is: '/uploads/formhandler/tmp/' * * @return void * @static * @author Reinhard Führicht <*****@*****.**> */ public static function getTempUploadFolder() { //set default upload folder $uploadFolder = '/uploads/formhandler/tmp/'; //if temp upload folder set in TypoScript, take that setting $settings = Tx_Formhandler_Globals::$session->get('settings'); if ($settings['files.']['uploadFolder']) { $uploadFolder = Tx_Formhandler_StaticFuncs::getSingle($settings['files.'], 'uploadFolder'); $uploadFolder = Tx_Formhandler_StaticFuncs::sanitizePath($uploadFolder); } //if the set directory doesn't exist, print a message and try to create if (!is_dir(Tx_Formhandler_StaticFuncs::getTYPO3Root() . $uploadFolder)) { Tx_Formhandler_StaticFuncs::debugMessage('folder_doesnt_exist', array(Tx_Formhandler_StaticFuncs::getTYPO3Root() . '/' . $uploadFolder), 2); t3lib_div::mkdir_deep(Tx_Formhandler_StaticFuncs::getTYPO3Root() . '/', $uploadFolder); } return $uploadFolder; }
/** * Deletes all files older than a specific time in a temporary upload folder. * Settings for the threshold time and the folder are made in TypoScript. * * Here is an example: * <code> * plugin.Tx_Formhandler.settings.files.clearTempFilesOlderThanHours = 24 * plugin.Tx_Formhandler.settings.files.tmpUploadFolder = uploads/formhandler/tmp * </code> * * @param integer $olderThan Delete files older than $olderThan hours. * @return void * @author Reinhard Führicht <*****@*****.**> */ protected function clearTempFiles($uploadFolder, $olderThanValue, $olderThanUnit) { if (!$olderThanValue) { return; } //build absolute path to upload folder $path = Tx_Formhandler_StaticFuncs::getDocumentRoot() . $uploadFolder; //read files in directory $tmpFiles = t3lib_div::getFilesInDir($path); Tx_Formhandler_StaticFuncs::debugMessage('cleaning_temp_files', array($path)); //calculate threshold timestamp //hours * 60 * 60 = millseconds $threshold = Tx_Formhandler_StaticFuncs::getTimestamp($olderThanValue, $olderThanUnit); //for all files in temp upload folder foreach ($tmpFiles as $idx => $file) { //if creation timestamp is lower than threshold timestamp //delete the file $creationTime = filemtime($path . $file); //fix for different timezones $creationTime += date('O') / 100 * 60; if ($creationTime < $threshold) { unlink($path . $file); Tx_Formhandler_StaticFuncs::debugMessage('deleting_file', array($file)); } } }
protected function doUpdate($uid, $queryFields) { $uid = $GLOBALS['TYPO3_DB']->fullQuoteStr($uid, $this->table); $query = $GLOBALS['TYPO3_DB']->UPDATEquery($this->table, $this->key . '=' . $uid, $queryFields); Tx_Formhandler_StaticFuncs::debugMessage('sql_request', array($query)); $res = $GLOBALS['TYPO3_DB']->sql_query($query); }
/** * Recursively calls the configured errorChecks. It's possible to setup * errorChecks for each key in multidimensional arrays: * * <code title="errorChecks for arrays"> * <input type="text" name="birthdate[day]"/> * <input type="text" name="birthdate[month]"/> * <input type="text" name="birthdate[year]"/> * <input type="text" name="name"/> * * validators.1.config.fieldConf { * birthdate { * day.errorCheck { * 1 = betweenValue * 1.minValue = 1 * 1.maxValue = 31 * } * month.errorCheck { * 1 = betweenValue * 1.minValue = 1 * 1.maxValue = 12 * } * year.errorCheck { * 1 = minValue * 1.minValue = 45 * } * } * birthdate.errorCheck.1 = maxItems * birthdate.errorCheck.1.value = 3 * name.errorCheck.1 = required * } * </code> * * @param array $errors * @param array $gp * @param array $fieldConf * @param string $rootField * @return array The error array */ protected function validateRecursive($errors, $gp, $fieldConf, $rootField = null) { //foreach configured form field foreach ($fieldConf as $key => $fieldSettings) { $fieldName = trim($key, '.'); $errorFieldName = $rootField === null ? $fieldName : $rootField; if (in_array($errorFieldName, $this->disableErrorCheckFields)) { continue; } $tempSettings = $fieldSettings; unset($tempSettings['errorCheck.']); if (count($tempSettings)) { // Nested field-confs - do recursion: $errors = $this->validateRecursive($errors, (array) $gp[$fieldName], $tempSettings, $errorFieldName); } if (!is_array($fieldSettings['errorCheck.'])) { continue; } $counter = 0; $errorChecks = array(); //set required to first position if set foreach ($fieldSettings['errorCheck.'] as $key => $check) { if (!strstr($key, '.')) { if (!strcmp($check, 'required') || !strcmp($check, 'file_required')) { $errorChecks[$counter]['check'] = $check; unset($fieldSettings['errorCheck.'][$key]); $counter++; } } } //set other errorChecks foreach ($fieldSettings['errorCheck.'] as $key => $check) { if (!strstr($key, '.')) { $errorChecks[$counter]['check'] = $check; if (is_array($fieldSettings['errorCheck.'][$key . '.'])) { $errorChecks[$counter]['params'] = $fieldSettings['errorCheck.'][$key . '.']; } $counter++; } } $checkFailed = ''; //foreach error checks foreach ($errorChecks as $check) { $classNameFix = ucfirst($check['check']); $errorCheckObject = $this->componentManager->getComponent('Tx_Formhandler_ErrorCheck_' . $classNameFix); if (!$errorCheckObject) { Tx_Formhandler_StaticFuncs::debugMessage('check_not_found', array('Tx_Formhandler_ErrorCheck_' . $classNameFix), 2); } if (empty($this->restrictErrorChecks) || in_array($check['check'], $this->restrictErrorChecks)) { Tx_Formhandler_StaticFuncs::debugMessage('calling_class', array('Tx_Formhandler_ErrorCheck_' . $classNameFix)); $checkFailed = $errorCheckObject->check($check, $fieldName, $gp); if (strlen($checkFailed) > 0) { if (!is_array($errors[$errorFieldName])) { $errors[$errorFieldName] = array(); } $errors[$errorFieldName][] = $checkFailed; } } else { Tx_Formhandler_StaticFuncs::debugMessage('check_skipped', array($check['check'])); } } } return $errors; }
/** * Sends a report mail to recipients set in TypoScript. * * @param string (ip|global) Defines the message sent * @param array The select rows of log table * @return void */ private function sendReport($type, &$rows) { $email = t3lib_div::trimExplode(',', $this->settings['report.']['email']); $sender = $this->settings['report.']['sender']; $subject = $this->settings['report.']['subject']; $message = ''; if ($type == 'ip') { $message = 'IP address "' . t3lib_div::getIndpEnv('REMOTE_ADDR') . '" has submitted a form too many times!'; } else { $message = 'A form got submitted too many times!'; } $message .= "\n\n" . 'This is the URL to the form: ' . t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'); if (is_array($rows)) { $message .= "\n\n" . 'These are the submitted values:' . "\n\n"; foreach ($rows as $idx => $row) { $message .= date('Y/m/d h:i:s', $row['crdate']) . ":\n"; $message .= 'IP: ' . $row['ip'] . "\n"; $message .= 'Params:' . "\n"; $params = unserialize($row['params']); foreach ($params as $key => $value) { if (is_array($value)) { $value = implode(',', $value); } $message .= "\t" . $key . ': ' . $value . "\n"; } $message .= '---------------------------------------' . "\n"; } } //init mailer object require_once PATH_t3lib . 'class.t3lib_htmlmail.php'; $emailObj = t3lib_div::makeInstance('t3lib_htmlmail'); $emailObj->start(); //set e-mail options $emailObj->subject = $subject; $emailObj->from_email = $sender; $emailObj->setPlain($message); //send e-mails foreach ($email as $idx => $mailto) { $sent = $emailObj->send($mailto); if ($sent) { Tx_Formhandler_StaticFuncs::debugMessage('mail_sent', array($mailto)); Tx_Formhandler_StaticFuncs::debugMessage('mail_sender', array($emailObj->from_email)); Tx_Formhandler_StaticFuncs::debugMessage('mail_subject', array($emailObj->subject)); Tx_Formhandler_StaticFuncs::debugMessage('mail_message', array(), 1, array($message)); } else { Tx_Formhandler_StaticFuncs::debugMessage('mail_not_sent', array($mailto), 2); Tx_Formhandler_StaticFuncs::debugMessage('mail_sender', array($emailObj->from_email)); Tx_Formhandler_StaticFuncs::debugMessage('mail_subject', array($emailObj->subject)); Tx_Formhandler_StaticFuncs::debugMessage('mail_message', array(), 1, array($message)); } } }
/** * Looks if the specified table exists and if not create it with the key- * field (uid). Then it syncs the DB-fields with the fields found in the form * with help of template parser */ protected function createTable() { $fields = $this->getFormFields(); if ($this->settings['excludeFields']) { $excludes = t3lib_div::trimExplode(',', $this->settings['excludeFields']); foreach ($excludes as $exclude) { unset($fields[$exclude]); } } if (Tx_Formhandler_Globals::$settings['debug']) { $this->db->debugOutput = 1; } $res = $this->db->sql_query("SHOW TABLES LIKE '" . $this->table . "'"); if (!$this->db->sql_num_rows($res)) { $query = "CREATE TABLE `" . $this->table . "` (\n\t\t\t\t`" . $this->key . "` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY\n\t\t\t)"; $this->db->sql_query($query); Tx_Formhandler_StaticFuncs::debugMessage('sql_request', array($query)); $dbFields = array($this->key); } else { $dbFields = array_keys($this->db->admin_get_fields($this->table)); } $createFields = array_diff($fields, $dbFields); if (count($createFields)) { $sql = 'ALTER TABLE ' . $this->table . ' ADD `'; $sql .= implode('` ' . $this->newFieldsSqlAttribs . ', ADD `', $createFields); $sql .= '` ' . $this->newFieldsSqlAttribs . ''; $this->db->sql_query($sql); Tx_Formhandler_StaticFuncs::debugMessage('sql_request', array($sql)); if ($this->db->sql_error()) { Tx_Formhandler_StaticFuncs::debugMessage('error', array($this->db->sql_error()), 3); } } }
/** * Substitutes markers * ###error_[fieldname]### * ###ERROR### * in $this->template * * @return void */ protected function fillErrorMarkers(&$errors) { $markers = array(); $singleWrap = $this->settings['singleErrorTemplate.']['singleWrap']; foreach ($errors as $field => $types) { $errorMessages = array(); $clearErrorMessages = array(); $temp = Tx_Formhandler_StaticFuncs::getTranslatedMessage($this->langFiles, 'error_' . $field); if (strlen($temp) > 0) { $errorMessage = $temp; if (strlen($singleWrap) > 0 && strstr($singleWrap, '|')) { $errorMessage = str_replace('|', $errorMessage, $singleWrap); } $errorMessages[] = $errorMessage; } if (!is_array($types)) { $types = array($types); } foreach ($types as $idx => $type) { $temp = t3lib_div::trimExplode(';', $type); $type = array_shift($temp); foreach ($temp as $subIdx => $item) { $item = t3lib_div::trimExplode('::', $item); $values[$item[0]] = $item[1]; } //try to load specific error message with key like error_fieldname_integer $errorMessage = Tx_Formhandler_StaticFuncs::getTranslatedMessage($this->langFiles, 'error_' . $field . '_' . $type); if (strlen($errorMessage) === 0) { $type = strtolower($type); $errorMessage = Tx_Formhandler_StaticFuncs::getTranslatedMessage($this->langFiles, 'error_' . $field . '_' . $type); } if ($errorMessage) { if (is_array($values)) { foreach ($values as $key => $value) { $errorMessage = str_replace('###' . $key . '###', $value, $errorMessage); } } if (strlen($singleWrap) > 0 && strstr($singleWrap, '|')) { $errorMessage = str_replace('|', $errorMessage, $singleWrap); } $errorMessages[] = $errorMessage; } else { Tx_Formhandler_StaticFuncs::debugMessage('no_error_message', array('error_' . $field . '_' . $type), 2); } } $errorMessage = implode('', $errorMessages); $totalWrap = $this->settings['singleErrorTemplate.']['totalWrap']; if (strlen($totalWrap) > 0 && strstr($totalWrap, '|')) { $errorMessage = str_replace('|', $errorMessage, $totalWrap); } $clearErrorMessage = $errorMessage; if ($this->settings['addErrorAnchors']) { $errorMessage = '<a name="' . $field . '">' . $errorMessage . '</a>'; } $langMarkers = Tx_Formhandler_StaticFuncs::getFilledLangMarkers($errorMessage, $this->langFiles); $errorMessage = $this->cObj->substituteMarkerArray($errorMessage, $langMarkers); $markers['###error_' . $field . '###'] = $errorMessage; $markers['###ERROR_' . strtoupper($field) . '###'] = $errorMessage; $errorMessage = $clearErrorMessage; if ($this->settings['addErrorAnchors']) { $errorMessage = '<a href="' . t3lib_div::getIndpEnv('REQUEST_URI') . '#' . $field . '">' . $errorMessage . '</a>'; } //list settings $listSingleWrap = $this->settings['errorListTemplate.']['singleWrap']; if (strlen($listSingleWrap) > 0 && strstr($listSingleWrap, '|')) { $errorMessage = str_replace('|', $errorMessage, $listSingleWrap); } $markers['###ERROR###'] .= $errorMessage; } $totalWrap = $this->settings['errorListTemplate.']['totalWrap']; if (strlen($totalWrap) > 0 && strstr($totalWrap, '|')) { $markers['###ERROR###'] = str_replace('|', $markers['###ERROR###'], $totalWrap); } $langMarkers = Tx_Formhandler_StaticFuncs::getFilledLangMarkers($markers['###ERROR###'], $this->langFiles); $markers['###ERROR###'] = $this->cObj->substituteMarkerArray($markers['###ERROR###'], $langMarkers); $markers['###error###'] = $markers['###ERROR###']; $this->template = $this->cObj->substituteMarkerArray($this->template, $markers); }
/** * Loads data from DB * * @return Array of row data * @param Array $settings * @param int $step */ protected function loadDB($settings) { $selectFields = Tx_Formhandler_StaticFuncs::getSingle($settings, 'selectFields'); if (strlen($selectFields) === 0) { $selectFields = '*'; } $sql = $GLOBALS['TYPO3_DB']->SELECTquery($selectFields, Tx_Formhandler_StaticFuncs::getSingle($settings, 'table'), Tx_Formhandler_StaticFuncs::getSingle($settings, 'where'), Tx_Formhandler_StaticFuncs::getSingle($settings, 'groupBy'), Tx_Formhandler_StaticFuncs::getSingle($settings, 'orderBy'), Tx_Formhandler_StaticFuncs::getSingle($settings, 'limit')); Tx_Formhandler_StaticFuncs::debugMessage($sql); $res = $GLOBALS['TYPO3_DB']->sql_query($sql); if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); $GLOBALS['TYPO3_DB']->sql_free_result($res); return $row; } return array(); }