|
<?php
|
|
/***************************************************************
|
|
* Copyright notice
|
|
*
|
|
* (c) 2003 Peter Luser (dev@typoheads.at)
|
|
* All rights reserved
|
|
*
|
|
* This script is part of the Typo3 project. The Typo3 project is
|
|
* free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* The GNU General Public License can be found at
|
|
* http://www.gnu.org/copyleft/gpl.html.
|
|
*
|
|
* This script is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* This copyright notice MUST APPEAR in all copies of the script!
|
|
***************************************************************/
|
|
/**
|
|
* Plugin 'mailformplus' for the 'th_mailformplus' extension.
|
|
*
|
|
* @author Peter Luser <netdog@typoheads.com>
|
|
*/
|
|
|
|
|
|
require_once(PATH_tslib."class.tslib_pibase.php");
|
|
|
|
class tx_thmailformplus_pi1 extends tslib_pibase {
|
|
|
|
// Same as class name
|
|
var $prefixId = "tx_thmailformplus_pi1";
|
|
|
|
// Path to this script relative to the extension dir.
|
|
var $scriptRelPath = "pi1/class.tx_thmailformplus_pi1.php";
|
|
|
|
// The extension key.
|
|
var $extKey = "th_mailformplus";
|
|
|
|
#############################
|
|
# Changes made by Reinhard
|
|
#############################
|
|
|
|
var $pi_checkCHash = true;
|
|
|
|
// Ralf Hettinger: global multistep vars
|
|
// enable | disable multistep form (defaut: false)
|
|
var $multipage = false;
|
|
|
|
// current step
|
|
var $multipageStep;
|
|
|
|
// last step that has been shown (taken if an error occures)
|
|
var $multipageLastStep;
|
|
|
|
// number of steps
|
|
var $multipageCount;
|
|
|
|
// realize multistep with JavaScript (default: true)
|
|
var $multipageJS = true;
|
|
|
|
// output all multistep forms and hide inactive forms by css:
|
|
// by doing this, there is no need for putting in hidden fields for each
|
|
// inactive form (default: true)
|
|
var $multipageAutoHidden = true;
|
|
|
|
//Array to temporary store the alternative templates
|
|
var $alt_templCode = array();
|
|
|
|
//Path to custom language file
|
|
var $langPath = '';
|
|
|
|
##############################
|
|
|
|
/**
|
|
* main function - called by the tt_content plugin with mailformplus
|
|
*
|
|
* @param string $content not used
|
|
* @param array $conf TS conf of main instance
|
|
* @return string the plugin's output
|
|
*/
|
|
function main($content,$conf) {
|
|
|
|
global $TSFE;
|
|
|
|
################################
|
|
# changes made by Reinhard
|
|
################################
|
|
# old version:
|
|
################################
|
|
# $TSFE->set_no_cache();
|
|
################################
|
|
# new:
|
|
################################
|
|
|
|
// Ralf Hettinger: only disable caching for the plugin, if nothing is submitted
|
|
$this->pi_USER_INT_obj = 1;
|
|
################################
|
|
$this->conf = $conf;
|
|
|
|
################################
|
|
# begin changes made by Claudio
|
|
#
|
|
# Adding a pre-processing user function that can handle
|
|
# form data before processing (through $_POST array, for
|
|
# instance). It's a sort of saveUserFunc, but it is run
|
|
# before processing the form instead of after that.
|
|
################################
|
|
if ($this->conf['preprocUserFunc']) {
|
|
$pre_params['config'] = $this->conf['preprocUserFunc.'];
|
|
$this->get_post_pre = array_merge(t3lib_div::_GET(), t3lib_div::_POST());
|
|
$this->get_post_pre = $this->sanitizeValues($this->get_post_pre);
|
|
$pre_params['data'] = $this->get_post_pre;
|
|
t3lib_div::callUserFunction($this->conf['preprocUserFunc'],$pre_params,$this,"");
|
|
}
|
|
################################
|
|
# end changes made by Claudio
|
|
################################
|
|
|
|
$this->get_post = array_merge(t3lib_div::_GET(), t3lib_div::_POST());
|
|
$this->get_post = $this->sanitizeValues($this->get_post);
|
|
|
|
#############################################
|
|
# by Reinhard
|
|
#############################################
|
|
# initialize $this->get_post as empty array to
|
|
# ensure that foreach loops do not crash.
|
|
#############################################
|
|
if(!is_array($this->get_post)) {
|
|
$this->get_post = array();
|
|
}
|
|
#############################################
|
|
|
|
$this->debug = $this->conf['debug'];
|
|
##############################################
|
|
# inserted by Reinhard <rf(at)typoheads.at>
|
|
##############################################
|
|
# patch using flexforms provided by Marcel Alburg <alb(at)weeaar.com>
|
|
##############################################
|
|
$this->pi_setPiVarDefaults();
|
|
$this->pi_initPIflexForm();
|
|
##############################################
|
|
|
|
$this->pi_loadLL();
|
|
|
|
$predef = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'predefined', 'sDEFAULT');
|
|
if ($predef && is_array($this->conf['predef.'][$predef])) {
|
|
$this->conf = $this->conf['predef.'][$predef];
|
|
}
|
|
|
|
###############################################
|
|
# Changes by Reinhard
|
|
###############################################
|
|
# moving loadDefaultValues() after $this->conf has been set.
|
|
# thx to Martin F?nning <fuenning(at)jakota.de>
|
|
###############################################
|
|
$this->loadDefaultValues();
|
|
###############################################
|
|
|
|
# check if md5_hash is set in session to ensure that form doesnt get submitted more than once
|
|
if ($this->get_post['SUBMITTED'] || $this->get_post['submitted']) {
|
|
$current_md5 = md5(serialize($this->get_post));
|
|
$session_md5 = $_SESSION['th_mailformplus'][$GLOBALS["TSFE"]->id]['md5_submitted'];
|
|
if (strcmp($current_md5,$session_md5) == 0) {
|
|
unset($this->get_post['submitted']);
|
|
unset($this->get_post['SUBMITTED']);
|
|
}
|
|
}
|
|
|
|
# set stylesheet file path
|
|
$stylesheetFile = $this->conf['stylesheetFile'];
|
|
|
|
if ($stylesheetFile != "") {
|
|
# set stylesheet
|
|
$GLOBALS['TSFE']->additionalHeaderData['special_css'] .=
|
|
'<link rel="stylesheet" href="'.$stylesheetFile.'" type="text/css" media="screen" />';
|
|
}
|
|
|
|
if ($this->debug == 1) {
|
|
print "These are the current GET/POST parameters: <br>\n";
|
|
#$gp = $this->sanitizeValues($this->get_post);
|
|
print_r($this->get_post);
|
|
}
|
|
switch((string)$this->conf["CMD"]) {
|
|
case "singleView":
|
|
list($t) = explode(":",$this->cObj->currentRecord);
|
|
$this->internal["currentTable"]=$t;
|
|
$this->internal["currentRow"]=$this->cObj->data;
|
|
return $this->pi_wrapInBaseClass($this->singleView($content,$this->conf));
|
|
break;
|
|
default:
|
|
|
|
################
|
|
# initialize freecap object if extension loaded and field defined in TS
|
|
################
|
|
if (t3lib_extMgm::isLoaded('sr_freecap') && $this->conf['freecapFieldname']) {
|
|
require_once(t3lib_extMgm::extPath('sr_freecap').'pi2/class.tx_srfreecap_pi2.php');
|
|
$this->freeCap = t3lib_div::makeInstance('tx_srfreecap_pi2');
|
|
}
|
|
|
|
################
|
|
# initialize recaptcha object if extension loaded and field defined in TS
|
|
################
|
|
if (t3lib_extMgm::isLoaded('jm_recaptcha') && $this->conf['useRecaptcha']) {
|
|
require_once(t3lib_extMgm::extPath('jm_recaptcha')."class.tx_jmrecaptcha.php");
|
|
$this->recaptcha = new tx_jmrecaptcha();
|
|
}
|
|
$this->langFile = '';
|
|
if (isset($this->conf['langFile']) && $this->conf['langFile'] != '') {
|
|
$this->langFile = $this->conf['langFile'];
|
|
}
|
|
$mailformplus_id = $this->cObj->data['pages'];
|
|
|
|
// default: display the form from the page where the plugin is inserted
|
|
if (!$mailformplus_id) {
|
|
$mailformplus_id = $this->cObj->data['pid'];
|
|
}
|
|
|
|
// or take the current page id
|
|
if (!$mailformplus_id) {
|
|
$mailformplus_id = $GLOBALS['TSFE']->id;
|
|
}
|
|
|
|
// Initializing the query parameters:
|
|
$query = "SELECT tx_thmailformplus_main.* FROM tx_thmailformplus_main WHERE pid IN (".$mailformplus_id.") LIMIT 0,1";
|
|
$res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $query);
|
|
if ($GLOBALS['TYPO3_DB']->sql_error()) {
|
|
debug(array($GLOBALS['TYPO3_DB']->sql_error(),$query));
|
|
}
|
|
$this->internal["currentTable"] = "tx_thmailformplus_main";
|
|
$this->internal["currentRow"] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
|
|
|
|
#############
|
|
# template
|
|
#############
|
|
t3lib_div::loadTCA('tx_thmailformplus_main');
|
|
$config = $GLOBALS['TCA']['tx_thmailformplus_main'];
|
|
|
|
// old version: copy of template file in upload folder
|
|
|
|
##############################################
|
|
# changes by Reinhard <rf(at)typoheads.at>
|
|
##############################################
|
|
# patch using flexforms provided by Marcel Alburg <alb(at)weeaar.com>
|
|
##############################################
|
|
# old version:
|
|
##############################################
|
|
#if ($config[columns][email_htmltemplate][config][uploadfolder]) $template_folder = $config[columns][email_htmltemplate][config][uploadfolder].'/';
|
|
#else $template_folder = '';
|
|
#$this->templateCode_orig = t3lib_div::getURL($template_folder.$this->getFieldContent("email_htmltemplate"));
|
|
#
|
|
## compatibility reasons: look for copy of template in uploads directory
|
|
#if (!$this->templateCode_orig) {
|
|
#$template_folder = "uploads/tx_thmailformplus/";
|
|
#$this->templateCode_orig = t3lib_div::getURL($template_folder.$this->getFieldContent("email_htmltemplate"));
|
|
#}
|
|
##############################################
|
|
# new version:
|
|
##############################################
|
|
if ($config[columns][email_htmltemplate][config][uploadfolder]) {
|
|
$template_folder = $config[columns][email_htmltemplate][config][uploadfolder].'/';
|
|
} else {
|
|
$template_folder = '';
|
|
}
|
|
|
|
#########################################################
|
|
# Changes by Reinhard
|
|
#########################################################
|
|
# Did changes to be able to
|
|
# dynamically load template, instead from file.
|
|
#
|
|
# Content element should be "HTML".
|
|
#
|
|
# If email_htmltemplate variable is integer, your ext will fetch template from
|
|
# page with that id. If this variable is omitted, it will try to fetch from
|
|
# the current page.
|
|
#
|
|
# Thanks to John Angel <johnange(at)gmail.com> for providing the patch
|
|
#########################################################
|
|
# old version:
|
|
#########################################################
|
|
#//read complete template file
|
|
#$this->templateCode_orig = t3lib_div::getURL($template_folder.$templateFile);
|
|
#
|
|
#// compatibility reasons: look for copy of template in uploads directory
|
|
#if (!$this->templateCode_orig) {
|
|
# $template_folder = "uploads/tx_thmailformplus/";
|
|
# $this->templateCode_orig = t3lib_div::getURL($template_folder.$templateFile);
|
|
#}
|
|
########################################################
|
|
# new version:
|
|
########################################################
|
|
|
|
#$email_htmltemplate_id = $this->getFieldContent("email_htmltemplate");
|
|
$email_htmltemplate_id = $this->getFieldContent("email_htmltemplate");
|
|
// If email_htmltemplate is empty, look for the page where the plugin is inserted
|
|
#if(empty($email_htmltemplate_id)) {
|
|
# $email_htmltemplate_id = $mailformplus_id;
|
|
#}
|
|
|
|
// If email_htmltemplate field is a numeric value, fetch template saved as plain HTML content element using that value as page ID
|
|
if(is_numeric($email_htmltemplate_id)) {
|
|
$content_record = $GLOBALS['TSFE']->sys_page->getRecordsByField('tt_content', 'pid', $email_htmltemplate_id, "AND CType='html' AND sys_language_uid=" . $GLOBALS['TSFE']->sys_language_uid, '', '', '0,1');
|
|
$this->templateCode_orig = $content_record[0]['bodytext'];
|
|
} else {
|
|
// get the template
|
|
$templateFile = $this->getFieldContent("email_htmltemplate");
|
|
|
|
// content_field
|
|
$templateFile = ($this->getFieldContent("email_htmltemplate")) ? $this->getFieldContent("email_htmltemplate") : $templateFile;
|
|
|
|
// TS entry
|
|
$templateFile = ($this->conf["email_htmltemplate"] != '') ? $this->conf["email_htmltemplate"] : $templateFile;
|
|
|
|
// FlexForm entry
|
|
if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template_file', 'sDEFAULT')) {
|
|
$templateFile = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template_file', 'sDEFAULT');
|
|
}
|
|
|
|
# bugfix for absolut paths
|
|
if (strstr($templateFile, 'fileadmin/')) {
|
|
list(,$templateFile) = explode('fileadmin/', $templateFile);
|
|
$templateFile = 'fileadmin/'.$templateFile;
|
|
}
|
|
|
|
//read complete template file
|
|
if (!$this->conf['default.']['email_htmltemplate.']) {
|
|
$this->templateCode_orig = t3lib_div::getURL($template_folder.$templateFile);
|
|
} else {
|
|
$this->templateCode_orig = $templateFile;
|
|
}
|
|
|
|
|
|
|
|
// try without template_folder
|
|
if ($this->templateCode_orig == '') {
|
|
$this->templateCode_orig = t3lib_div::getURL($templateFile);
|
|
}
|
|
|
|
// compatibility reasons: look for copy of template in uploads directory
|
|
if (!$this->templateCode_orig) {
|
|
$template_folder = "uploads/tx_thmailformplus/";
|
|
$this->templateCode_orig = t3lib_div::getURL($template_folder.$templateFile);
|
|
|
|
}
|
|
}
|
|
########################################################
|
|
|
|
##############################
|
|
# multipage forms?
|
|
##############################
|
|
|
|
##############################
|
|
# changes made by Reinhard
|
|
##############################
|
|
# old:
|
|
##############################
|
|
# $this->multipage = 0;
|
|
# # step that should be shown (not so sure here because of error check)
|
|
# $this->multipageStep = t3lib_div::_GP('mp_step');
|
|
##############################
|
|
# new:
|
|
##############################
|
|
// Ralf Hettinger: mailformplus multipages without JavaScript
|
|
if ($this->conf['multipage_without_js']) {
|
|
$this->multipageJS = false;
|
|
}
|
|
|
|
// Ralf Hettinger: mailformplus multipages without auto-hidden fields
|
|
if ($this->conf['multipage_without_auto_hidden']) {
|
|
$this->multipageAutoHidden = false;
|
|
}
|
|
|
|
// step that should be shown (not so sure here because of error check)
|
|
if ($this->multipageJS) {
|
|
$this->multipageStep = t3lib_div::_GP('mp_step');
|
|
} else {
|
|
// Ralf Hettinger: get requested step for multipages without JavaScript
|
|
foreach ($this->get_post as $pname => $pvalue) {
|
|
if (substr($pname,0,24)=='th_mailformplus-mp_step-') {
|
|
$mpPage = substr($pname,24);
|
|
if (strpos ($mpPage, '-')) {
|
|
$mpPage = substr($mpPage,0,strpos ($mpPage, '-'));
|
|
} //if end
|
|
$this->multipageStep = intval($mpPage);
|
|
} // if end
|
|
|
|
} // foreach end
|
|
} // else end
|
|
|
|
// last step that has been shown (taken if an error occures)
|
|
$this->multipageLastStep = $this->get_post['mp_last_step'];
|
|
if (!$this->multipageLastStep) {
|
|
$this->multipageLastStep = 1;
|
|
}
|
|
if (strstr($this->templateCode_orig,'###TEMPLATE_FORM1###')) {
|
|
//fill array with alternative templates
|
|
$this->alt_templCode = $this->readCorrectTemplateCode($this->conf,'TEMPLATE_FORM',1,$this->multipageStep);
|
|
$this->multipage = 1;
|
|
|
|
// first call -> start with 1st form
|
|
if (!$this->multipageStep) {
|
|
$this->multipageStep = 1;
|
|
}
|
|
|
|
$i = 1;
|
|
|
|
//fill array with normal templates
|
|
while(strstr($this->templateCode_orig,'###TEMPLATE_FORM'.$i.'###')) {
|
|
$this->templateCode_multipage[$i] = $this->cObj->getSubpart($this->templateCode_orig,'###TEMPLATE_FORM'.$i.'###');
|
|
|
|
#####################
|
|
# step1
|
|
# cut out subtemplate for STARTBLOCK and ENDBLOCK markers
|
|
#####################
|
|
if ($i==1) {
|
|
$tempArray = array();
|
|
$this->startEndBlockArray['###STARTBLOCK###'] = $this->cObj->getSubpart($this->templateCode_multipage[$i], '###FORM_STARTBLOCK###');
|
|
$this->startEndBlockArray['###ENDBLOCK###'] = $this->cObj->getSubpart($this->templateCode_multipage[$i], '###FORM_ENDBLOCK###');
|
|
|
|
// replace subpart with start/endblocks
|
|
$this->startEndBlockSubpartArray = array();
|
|
$this->startEndBlockSubpartArray['###FORM_STARTBLOCK###'] = $this->startEndBlockArray['###STARTBLOCK###'];
|
|
$this->startEndBlockSubpartArray['###FORM_ENDBLOCK###'] = $this->startEndBlockArray['###ENDBLOCK###'];
|
|
$this->templateCode_multipage[$i] = $this->cObj->substituteMarkerArray($this->templateCode_multipage[$i], array(), $this->startEndBlockSubpartArray);
|
|
}
|
|
|
|
// step incrementer
|
|
$i++;
|
|
}
|
|
$i--;
|
|
//after step 1: merge normal template array with alternative template array
|
|
if ($this->multipageStep > 1) {
|
|
//overwrite normal template at step $key if alternative template is set for this step
|
|
foreach ($this->templateCode_multipage as $key=>$value) {
|
|
if (isset($this->alt_templCode[$key])) {
|
|
$this->templateCode_multipage[$key] = $this->alt_templCode[$key];
|
|
}
|
|
}
|
|
|
|
//find highest index in alternative template array.
|
|
//needed if alternative route is longer than normal route
|
|
$last_key = 0;
|
|
if (is_array($this->alt_templCode)) {
|
|
foreach ($this->alt_templCode as $key=>$val) {
|
|
if ($key > $last_key) {
|
|
$last_key = $key;
|
|
}
|
|
}
|
|
}
|
|
|
|
//extend template code array with the additional alternative templates
|
|
for ($k = count($this->templateCode_multipage);$k<=$last_key;$k++) {
|
|
$this->templateCode_multipage[$k] = $this->alt_templCode[$k];
|
|
}
|
|
}
|
|
$this->multipageCount = count($this->templateCode_multipage);
|
|
if ($this->debug == 1) {
|
|
print "This is the current template code array for this route: <br>\n";
|
|
print_r($this->templateCode_multipage);
|
|
}
|
|
} // if multipageform end
|
|
// load TS settings
|
|
$this->loadMapping($this->conf);
|
|
|
|
// form was submitted
|
|
if ($this->get_post['SUBMITTED'] || $this->get_post['submitted']) {
|
|
|
|
############################
|
|
# changes made by Reinhard
|
|
############################
|
|
# if submitted, do not cache pages.
|
|
# credits to Ralf Hettinger
|
|
############################
|
|
$TSFE->set_no_cache();
|
|
############################
|
|
$this->templateCode_error = $this->cObj->getSubpart($this->templateCode_orig,"###TEMPLATE_ERROR###");
|
|
|
|
$error = $this->check_form($content,$this->conf);
|
|
#print "<br><br>ads<br><br>";
|
|
# discard errors if
|
|
# - it's a multipage page form AND
|
|
# - it's the previous step and not the next one
|
|
if ($this->multipage == '1' && $this->multipageLastStep > $this->multipageStep) {
|
|
$error = '';
|
|
}
|
|
|
|
if ($error) {
|
|
$this->multipageStep--;
|
|
|
|
#######################
|
|
# removed by Reinhard #
|
|
#######################
|
|
#$langMarkers = $this->substituteLangMarkers($error);
|
|
#$error = $this->cObj->substituteMarkerArray($error,$langMarkers);
|
|
# self defined error message start
|
|
$temp = $GLOBALS["TSFE"]->cObj->getSubpart($this->templateCode_error, "ERROR_START");
|
|
if ($temp) {
|
|
$error = $temp.$error;
|
|
} else {
|
|
// Fallback error message if no subpart ERROR_START is defined:
|
|
$error = 'Please fill out the following fields: <ul>'.$error.'</ul>';
|
|
}
|
|
|
|
# self defined error message end
|
|
$temp = $GLOBALS["TSFE"]->cObj->getSubpart($this->templateCode_error, "ERROR_END");
|
|
if ($temp) {
|
|
$error .= $temp;
|
|
}
|
|
|
|
########################
|
|
# Bugfix: makes it possible to use ts markers in error subparts
|
|
########################
|
|
$langMarkers = $this->substituteLangMarkers($error);
|
|
$error = $this->cObj->substituteMarkerArray($error,$langMarkers);
|
|
$error = $this->substituteTSMarkersTempl($error, $this->conf);
|
|
$this->error = $error;
|
|
|
|
if (!$this->multipage) {
|
|
$this->templateCode = $this->cObj->getSubpart($this->templateCode_orig,"###TEMPLATE_FORM###");
|
|
if ($this->templateCode == '') {
|
|
$this->templateCode = $this->templateCode_orig;
|
|
}
|
|
// substitute language markers with values according to current language
|
|
$langMarkers = $this->substituteLangMarkers($this->templateCode);
|
|
#####################
|
|
# Changed by Reinhard
|
|
#####################
|
|
# 3rd param has to be an array! Thx to Steffen Kamper <info(at)sk-typo3.de>
|
|
#####################
|
|
# $this->cObj->substituteMarkerArrayCached($this->templateCode, $langMarkers, '');
|
|
#####################
|
|
$this->templateCode = $this->cObj->substituteMarkerArrayCached($this->templateCode, $langMarkers, array());
|
|
} else {
|
|
|
|
############################################
|
|
# Changes made by Reinhard
|
|
############################################
|
|
# if multistep forms with dependencies, it's not possible to set $this->multipageLastStep.
|
|
# reset the templatecode array
|
|
############################################
|
|
# old version:
|
|
############################################
|
|
# $this->templateCode = $this->getCorrectFormTemplate($this->multipageLastStep);
|
|
############################################
|
|
# new version:
|
|
############################################
|
|
|
|
//fill array with alternative templates
|
|
$this->alt_templCode = $this->readCorrectTemplateCode($this->conf,'TEMPLATE_FORM',1,$this->multipageStep);
|
|
$this->multipage = 1;
|
|
|
|
// first call -> start with 1st form
|
|
if (!$this->multipageStep) {
|
|
$this->multipageStep = 1;
|
|
}
|
|
$i = 1;
|
|
|
|
//fill array with normal templates
|
|
while(strstr($this->templateCode_orig,'###TEMPLATE_FORM'.$i.'###')) {
|
|
$this->templateCode_multipage[$i] = $this->cObj->getSubpart($this->templateCode_orig,'###TEMPLATE_FORM'.$i.'###');
|
|
|
|
#####################
|
|
# step1
|
|
# cut out subtemplate for STARTBLOCK and ENDBLOCK markers
|
|
#####################
|
|
if ($i==1) {
|
|
$tempArray = array();
|
|
$this->startEndBlockArray['###STARTBLOCK###'] = $this->cObj->getSubpart($this->templateCode_multipage[$i], '###FORM_STARTBLOCK###');
|
|
$this->startEndBlockArray['###ENDBLOCK###'] = $this->cObj->getSubpart($this->templateCode_multipage[$i], '###FORM_ENDBLOCK###');
|
|
|
|
// replace subpart with start/endblocks
|
|
$this->startEndBlockSubpartArray = array();
|
|
$this->startEndBlockSubpartArray['###FORM_STARTBLOCK###'] = $this->startEndBlockArray['###STARTBLOCK###'];
|
|
$this->startEndBlockSubpartArray['###FORM_ENDBLOCK###'] = $this->startEndBlockArray['###ENDBLOCK###'];
|
|
$this->templateCode_multipage[$i] = $this->cObj->substituteMarkerArray($this->templateCode_multipage[$i], array(), $this->startEndBlockSubpartArray);
|
|
}
|
|
|
|
// step incrementer
|
|
$i++;
|
|
}
|
|
$i--;
|
|
|
|
//overwrite normal template at step $key if alternative template is set for this step
|
|
foreach ($this->templateCode_multipage as $key=>$value) {
|
|
if (isset($this->alt_templCode[$key])) {
|
|
$this->templateCode_multipage[$key] = $this->alt_templCode[$key];
|
|
}
|
|
}
|
|
|
|
//find highest index in alternative template array.
|
|
//needed if alternative route is longer than normal route
|
|
$last_key = 0;
|
|
if (is_array($this->alt_templCode)) {
|
|
foreach ($this->alt_templCode as $key=>$val) {
|
|
if ($key > $last_key) {
|
|
$last_key = $key;
|
|
}
|
|
}
|
|
}
|
|
|
|
//extend template code array with the additional alternative templates
|
|
for ($k = count($this->templateCode_multipage);$k<=$last_key;$k++) {
|
|
$this->templateCode_multipage[$k] = $this->alt_templCode[$k];
|
|
}
|
|
|
|
//find current active template and set others inactive
|
|
$this->templateCode = $this->getCorrectFormTemplate($this->multipageStep);
|
|
#############################################
|
|
}
|
|
|
|
####### Hettinger start #############
|
|
return (($this->conf['noWrapInBaseClass'])?
|
|
$this->show_form($content,$this->conf):
|
|
$this->pi_wrapInBaseClass($this->show_form($content,$this->conf))
|
|
);
|
|
####### hettinger end ###############
|
|
} else {
|
|
#print "no error";
|
|
# not a multipage form OR
|
|
# end of multipage forms
|
|
|
|
#if ($this->multipageCount == 1 || !$this->multipage || ($this->multipageStep >= ($this->multipageCount+1) &&
|
|
# (!isset($this->alt_templCode[$this->multipageStep]) || $this->alt_templCode[$this->multipageStep] == ''))) {
|
|
if (!$this->multipage || ($this->multipageStep >= ($this->multipageCount+1) &&
|
|
(!isset($this->alt_templCode[$this->multipageStep]) || $this->alt_templCode[$this->multipageStep] == ''))) {
|
|
|
|
$this->templateCode = $this->cObj->getSubpart($this->templateCode_orig,"###TEMPLATE_SUBMITTED_OK###");
|
|
|
|
/*
|
|
* Inserted/Modified by: Andreas Westermaier <aw(at)overturn.de>
|
|
* Adding new template distinction between HTML and plaintext.
|
|
*/
|
|
################################################################
|
|
# Reinhard: added new possibility to define different email template according to
|
|
# the route the user has chosen.
|
|
################################################################
|
|
# old version:
|
|
################################################################
|
|
#$this->templateCode_useremail_PlainText = $this->cObj->getSubpart($this->templateCode_orig,"###TEMPLATE_EMAIL_USER###");
|
|
#$this->templateCode_useremail_Html = $this->cObj->getSubpart($this->templateCode_orig,"###TEMPLATE_EMAIL_USER_HTML###");
|
|
#$this->templateCode_receiver_PlainText = $this->cObj->getSubpart($this->templateCode_orig,"###TEMPLATE_EMAIL_RECEIVER###");
|
|
#$this->templateCode_receiver_Html = $this->cObj->getSubpart($this->templateCode_orig,"###TEMPLATE_EMAIL_RECEIVER_HTML###");
|
|
#$this->templateCode_printversion = $this->cObj->getSubpart($this->templateCode_orig,"###TEMPLATE_PRINT###");
|
|
################################################################
|
|
# new version:
|
|
################################################################
|
|
$this->templateCode_useremail_PlainText = $this->readCorrectTemplateCode($this->conf,'TEMPLATE_EMAIL_USER',0,$this->multipageStep);
|
|
$this->templateCode_useremail_Html = $this->readCorrectTemplateCode($this->conf,'TEMPLATE_EMAIL_USER_HTML',0,$this->multipageStep);
|
|
$this->templateCode_receiver_PlainText = $this->readCorrectTemplateCode($this->conf,'TEMPLATE_EMAIL_RECEIVER',0,$this->multipageStep);
|
|
$this->templateCode_receiver_Html = $this->readCorrectTemplateCode($this->conf,'TEMPLATE_EMAIL_RECEIVER_HTML',0,$this->multipageStep);
|
|
$this->templateCode_printversion = $this->readCorrectTemplateCode($this->conf,'TEMPLATE_PRINT',0,$this->multipageStep);
|
|
|
|
|
|
################################################################
|
|
// -----------------------------------------------------------
|
|
|
|
$this->send_form($content,$this->conf);
|
|
|
|
########### hettinger start ##############
|
|
# old: return $this->pi_wrapInBaseClass($this->templateCode);
|
|
return (($this->conf['noWrapInBaseClass'])?
|
|
$this->templateCode:
|
|
$this->pi_wrapInBaseClass($this->templateCode)
|
|
);
|
|
########### hettinger end ################
|
|
}
|
|
}
|
|
} else {
|
|
|
|
# form was not submitted -> called first -> reset session variable for multipage file uploads
|
|
# clear uploaded files array
|
|
session_start();
|
|
$_SESSION['mp_uploadedFiles'] = array();
|
|
|
|
# clear print-template stored in session
|
|
$id = $GLOBALS["TSFE"]->id;
|
|
$GLOBALS["TSFE"]->fe_user->setKey("ses","th_mailformplus".$id, '');
|
|
$GLOBALS["TSFE"]->fe_user->storeSessionData();
|
|
}
|
|
if (!$this->multipage) {
|
|
$this->templateCode = $this->cObj->getSubpart($this->templateCode_orig,"###TEMPLATE_FORM###");
|
|
|
|
// substitute language markers with values according to current language
|
|
$langMarkers = $this->substituteLangMarkers($this->templateCode);
|
|
#####################
|
|
# Changed by Reinhard
|
|
#####################
|
|
# 3rd param has to be an array! Thx to Steffen Kamper <info(at)sk-typo3.de>
|
|
#####################
|
|
$this->templateCode = $this->cObj->substituteMarkerArrayCached($this->templateCode, $langMarkers, array());
|
|
} else {
|
|
|
|
# set $this->multipageLastStep to new value
|
|
$this->multipageLastStep = $this->multipageStep;
|
|
$this->templateCode = $this->getCorrectFormTemplate($this->multipageStep);
|
|
}
|
|
|
|
# compatibility to old version (no placeholder specified)
|
|
if (!$this->templateCode) {
|
|
$this->templateCode = $this->templateCode_orig;
|
|
}
|
|
return (($this->conf['noWrapInBaseClass'])?
|
|
$this->show_form($content,$this->conf):
|
|
$this->pi_wrapInBaseClass($this->show_form($content,$this->conf))
|
|
);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/*try utf16 decoding*/
|
|
function utf16_decode($str) {
|
|
if( strlen($str) < 2 ) return $str;
|
|
$bom_be = true;
|
|
$c0 = ord($str{0});
|
|
$c1 = ord($str{1});
|
|
if( $c0 == 0xfe && $c1 == 0xff ) { $str = substr($str,2); }
|
|
elseif( $c0 == 0xff && $c1 == 0xfe ) { $str = substr($str,2); $bom_be = false; }
|
|
$len = strlen($str);
|
|
$newstr = '';
|
|
for($i=0;$i<$len;$i+=2) {
|
|
if( $bom_be ) { $val = ord($str{$i}) << 4; $val += ord($str{$i+1}); }
|
|
else { $val = ord($str{$i+1}) << 4; $val += ord($str{$i}); }
|
|
$newstr .= ($val == 0x228) ? "\n" : chr($val);
|
|
}
|
|
return $newstr;
|
|
}
|
|
|
|
function utf8win1251($s){
|
|
$out="";$c1="";$byte2=false;
|
|
for ($c=0;$c<strlen($s);$c++){
|
|
$i=ord($s[$c]);
|
|
if ($i<=127) $out.=$s[$c];
|
|
if ($byte2){
|
|
$new_c2=($c1&3)*64+($i&63);
|
|
$new_c1=($c1>>2)&5;
|
|
$new_i=$new_c1*256+$new_c2;
|
|
if ($new_i==1025) $out_i=168; else
|
|
if ($new_i==1105) $out_i=184; else $out_i=$new_i-848;
|
|
$out.=chr($out_i);
|
|
$byte2=false;}
|
|
if (($i>>5)==6) {$c1=$i;$byte2=true;}
|
|
}
|
|
return $out;}
|
|
|
|
function utf2html($utf2html_string)
|
|
{
|
|
//global $utf2html_string;
|
|
|
|
$utf2html_retstr = "";
|
|
for ($utf2html_p=0; $utf2html_p<strlen($utf2html_string); $utf2html_p++) {
|
|
$utf2html_c = substr ($utf2html_string, $utf2html_p, 1);
|
|
$utf2html_c1 = ord ($utf2html_c);
|
|
if ($utf2html_c1>>5 == 6) {// 110x xxxx, 110 prefix for 2 bytes unicode
|
|
$utf2html_p++;
|
|
$utf2html_t = substr ($utf2html_string, $utf2html_p, 1);
|
|
$utf2html_c2 = ord ($utf2html_t);
|
|
$utf2html_c1 &= 31; // remove the 3 bit two bytes prefix
|
|
$utf2html_c2 &= 63; // remove the 2 bit trailing byte prefix
|
|
$utf2html_c2 |= (($utf2html_c1 & 3) << 6); // last 2 bits of c1 become first 2 of c2
|
|
$utf2html_c1 >>= 2; // c1 shifts 2 to the right
|
|
$a = dechex($utf2html_c1);
|
|
$a = str_pad($a, 2, "0", STR_PAD_LEFT);
|
|
$b = dechex($utf2html_c2);
|
|
$b = str_pad($b, 2, "0", STR_PAD_LEFT);
|
|
|
|
$utf2html_n_neu = $a.$b;
|
|
$utf2html_n_neu_speicher = $utf2html_n_neu;
|
|
$utf2html_n_neu = "&#x".$utf2html_n_neu.";";
|
|
|
|
|
|
$utf2html_retstr .= $utf2html_n_neu;
|
|
|
|
}
|
|
else {
|
|
$utf2html_retstr .= $utf2html_c;
|
|
}
|
|
}
|
|
//echo $utf2html_retstr;
|
|
return $utf2html_retstr;
|
|
|
|
}
|
|
|
|
/**
|
|
* only used for multipage forms
|
|
* returns array with field names that were used/shown
|
|
* on the last submitted page
|
|
* used in function check_form
|
|
*
|
|
* @param array $array_check
|
|
* @return array
|
|
*/
|
|
function getArrayCheck($array_check) {
|
|
|
|
if (!is_array($array_check) || sizeof($array_check) == 0) {
|
|
return $array_check;
|
|
}
|
|
if ($this->multipage == 0) {
|
|
$lastTemplate = $this->cObj->getSubpart($this->templateCode_orig,"###TEMPLATE_FORM###");
|
|
} else {
|
|
$lastTemplate = $this->templateCode_multipage[$this->multipageLastStep];
|
|
}
|
|
$lastTemplate = $this->substituteTSMarkersTempl($lastTemplate, $this->conf);
|
|
$returnArray = array();
|
|
foreach ($array_check as $fieldName) {
|
|
####################################
|
|
# is this fieldname used in the last submitted form?
|
|
####################################
|
|
# example: fieldName = email
|
|
# does "email" or 'email' exist in the form template?
|
|
####################################
|
|
preg_match('/["\']'.$fieldName.'["\']/', $lastTemplate, $found);
|
|
####################################
|
|
# look also for 'email[]' (array)
|
|
####################################
|
|
preg_match('/["\']'.$fieldName.'\[[^\]]*\]["\']/', $lastTemplate, $foundArray);
|
|
if ((sizeof($found) > 0) || (sizeof($foundArray) > 0)) {
|
|
$returnArray[] = $fieldName;
|
|
}
|
|
}
|
|
return $returnArray;
|
|
}
|
|
|
|
/**
|
|
* only used for multipage forms
|
|
* other pages are hidden by CSS or not rendered at all depending on
|
|
* $this->multipageAutoHidden
|
|
*
|
|
* @param string $activeStep current multipage step
|
|
* @return string
|
|
*/
|
|
function getCorrectFormTemplate($activeStep) {
|
|
$activeTemplate = '';
|
|
$inactiveTemplate = '';
|
|
foreach ($this->templateCode_multipage as $i=>$tempTemplate) {
|
|
|
|
# current template should be shown
|
|
if ($i == $activeStep) {
|
|
$activeTemplate .= $tempTemplate;
|
|
} else { # hide this template
|
|
$inactiveTemplate .= $tempTemplate;
|
|
}
|
|
}
|
|
|
|
|
|
$activeTemplate = $this->cObj->substituteMarkerArrayCached($activeTemplate, $this->startEndBlockArray, $this->startEndBlockSubpartArray);
|
|
|
|
// substitute language markers with values according to current language
|
|
$langMarkers = $this->substituteLangMarkers($activeTemplate);
|
|
#####################
|
|
# Changed by Reinhard
|
|
#####################
|
|
# 3rd param has to be an array! Thx to Steffen Kamper <info(at)sk-typo3.de>
|
|
#####################
|
|
$activeTemplate = $this->cObj->substituteMarkerArrayCached($activeTemplate, $langMarkers, array());
|
|
####################
|
|
# fill markers that can be used in template
|
|
####################
|
|
|
|
# default additional javascript defined in TS (multiPage.js)
|
|
$additionalJS = $this->conf['multiPage.']['js'];
|
|
|
|
# this step additional javascript defined in TS (multiPage.[step].js)
|
|
if ($this->conf['multiPage.'][$activeStep.'.']['js']) {
|
|
$additionalJS = $this->conf['multiPage.'][$activeStep.'.']['js'];
|
|
}
|
|
|
|
$tempMarkerArray = array();
|
|
|
|
#####################
|
|
# Ralf Hettinger: this switch is configured by TS
|
|
# multipage_without_js = boolean (default false)
|
|
#####################
|
|
# if true, the multipages aren't realized by JavaScript links, but by named
|
|
# form submit buttons. Those buttons will have to be set within the template, e.g.:
|
|
# <input type="submit" value="next step" ###submit_nextStep### />
|
|
#
|
|
# the submit_[] markers will add the name="" attribute which triggers a multipage form
|
|
# backwards or forwards
|
|
#####################
|
|
if ($this->multipageJS) {
|
|
|
|
############################
|
|
# changes by reinhard
|
|
############################
|
|
# bugfixed usage of mailformplus and realURL
|
|
# thx to Ralf Merz <ralf.merz(at)heindl.de
|
|
############################
|
|
$request_uri = t3lib_div::getIndpEnv('REQUEST_URI').'#';
|
|
|
|
# link for next page (start/stop)
|
|
$tempMarkerArray['###link_nextStep_start###'] = '<a href="'.$request_uri.'" onclick="'.$additionalJS.'set_step('.($activeStep+1).');">';
|
|
$tempMarkerArray['###link_nextStep_stop###'] = '</a>';
|
|
$tempMarkerArray['###submit_nextStep###'] = '';
|
|
|
|
# link for previous page (start/stop)
|
|
$tempMarkerArray['###link_prevStep_start###'] = '<a href="'.$request_uri.'" onclick="'.$additionalJS.'set_step('.($activeStep-1).')">';
|
|
$tempMarkerArray['###link_prevStep_stop###'] = '</a>';
|
|
$tempMarkerArray['###submit_prevStep###'] = '';
|
|
|
|
# link for reloading the same page/step
|
|
$tempMarkerArray['###link_reload_start###'] = '<a href="'.$request_uri.'" onclick="'.$additionalJS.'set_step('.$activeStep.')">';
|
|
$tempMarkerArray['###link_reload_stop###'] = '</a>';
|
|
$tempMarkerArray['###submit_reload###'] = '';
|
|
#############################
|
|
|
|
# hidden field for step
|
|
# value for this field will be set by javascript depending on clicking on "next" or "back" link
|
|
$autoHiddenFields .= '<input type="hidden" name="mp_step" id="mp_step" value="" />';
|
|
|
|
# hidden field for deleting uploaded file
|
|
$autoHiddenFields .= '<input type="hidden" name="mp_delete_uploaded_file" value="" />';
|
|
|
|
# javascript functions
|
|
$jsFunctions =<<<END
|
|
<script type="text/javascript">
|
|
function set_step(step) {
|
|
if (document.getElementById('mp_step')) {
|
|
document.getElementById('mp_step').value = step;
|
|
document.getElementById('form_mp').submit();
|
|
} else {
|
|
alert('getElementById not working');
|
|
}
|
|
}
|
|
|
|
function delete_file(filename) {
|
|
if (document.getElementById('mp_delete_uploaded_file')) {
|
|
document.getElementById('mp_delete_uploaded_file').value = filename;
|
|
}
|
|
}
|
|
</script>
|
|
END;
|
|
} else {
|
|
|
|
# submit name for next page
|
|
$tempMarkerArray['###submit_nextStep###'] = ' name="th_mailformplus-mp_step-'.($activeStep+1).'"';
|
|
$tempMarkerArray['###link_nextStep_start###'] = '';
|
|
$tempMarkerArray['###link_nextStep_stop###'] = '';
|
|
|
|
# submit name for previous page
|
|
$tempMarkerArray['###submit_prevStep###'] = ' name="th_mailformplus-mp_step-'.($activeStep-1).'"';
|
|
$tempMarkerArray['###link_prevStep_start###'] = '';
|
|
$tempMarkerArray['###link_prevStep_stop###'] = '';
|
|
|
|
# submit name for reloading the same page/step
|
|
$tempMarkerArray['###submit_reload###'] = ' name="th_mailformplus-mp_step-'.($activeStep).'"';
|
|
$tempMarkerArray['###link_reload_start###'] = '';
|
|
$tempMarkerArray['###link_reload_stop###'] = '';
|
|
$jsFunctions = '';
|
|
}
|
|
|
|
# current step
|
|
$tempMarkerArray['###curStep###'] = $activeStep;
|
|
|
|
# maximum step/number of steps
|
|
$tempMarkerArray['###maxStep###'] = $this->multipageCount;
|
|
|
|
|
|
# hidden field with last step
|
|
$autoHiddenFields .= '<input type="hidden" name="mp_last_step" value="'.$this->multipageLastStep.'" />';
|
|
|
|
#####################
|
|
# Ralf Hettinger: this switch is configured by TS
|
|
# multipage_without_auto_hidden = boolean (default false)
|
|
#####################
|
|
# if true, the ###ADDITIONAL_MULTIPAGE### marker will not contain the
|
|
# inactive steps and therefore, the values from other pages will have to be
|
|
# set manually in the step-templates.
|
|
# this will result in more work for creating the HTML template,
|
|
# but removes CSS dependancy and renders a cleaner HTML (no xform tags)
|
|
#####################
|
|
if ($this->multipageAutoHidden) {
|
|
|
|
#####################
|
|
# hide inactive steps/forms with CSS
|
|
#####################
|
|
$inactiveTemplate = '<div style="display:none;">'.$inactiveTemplate.'</div>';
|
|
$inactiveTemplate = str_replace('alt=', 'disabled_alt=', $inactiveTemplate);
|
|
#####################
|
|
# disable all <form> tags in hidden forms
|
|
#####################
|
|
$inactiveTemplate = eregi_replace('<form', '<xform_disabled_by_mailformplus', $inactiveTemplate);
|
|
$inactiveTemplate = eregi_replace('</form', '</xform_disabled_by_mailformplus', $inactiveTemplate);
|
|
}
|
|
|
|
|
|
|
|
#####################
|
|
# put inactiveTemplate code plus automatic generated hidden fields within <form> tag
|
|
# by filling the marker ###ADDITIONAL_MULTIPAGE###
|
|
#####################
|
|
$tempMarkerArray['###ADDITIONAL_MULTIPAGE###'] = $jsFunctions.$inactiveTemplate.$autoHiddenFields;
|
|
|
|
#####################
|
|
# add id to <form> tag so that it can be addressed by js
|
|
#####################
|
|
if ($this->multipageJS) {
|
|
$activeTemplate = eregi_replace('<form', '<form id="form_mp"', $activeTemplate);
|
|
}
|
|
$activeTemplate = $this->cObj->substituteMarkerArray($activeTemplate, $tempMarkerArray);
|
|
|
|
return $activeTemplate;
|
|
}
|
|
|
|
/**
|
|
* Pre-Set Form Fields by TypoScript
|
|
* added by roland(at)robelix.com
|
|
*
|
|
* example usage (TS):
|
|
* plugin.tx_thmailformplus_pi1.fieldConf.[fieldname].defaultValue. = [predefined value]
|
|
* plugin.tx_thmailformplus_pi1.fieldConf.[fieldname].defaultValue {
|
|
* day.data = date : U
|
|
* day.strftime = %d
|
|
* month.data = date : U
|
|
* month.strftime = %b
|
|
* }
|
|
*/
|
|
########CHANGED###########
|
|
# getSingle() f?r defaultValue. Thx to Michael Greiner <Michael.Greiner(at)web.de>
|
|
############################
|
|
function loadDefaultValues() {
|
|
if (is_array($this->conf['fieldConf.'])) {
|
|
foreach (array_keys($this->conf['fieldConf.']) as $fN) {
|
|
$fN = preg_replace('/\.$/', '', $fN);
|
|
if (!isset($this->get_post[$fN])) {
|
|
if($this->conf['fieldConf.'][$fN.'.']['defaultValue'] && $this->conf['fieldConf.'][$fN.'.']['defaultValue.']) {
|
|
$this->get_post[$fN] = $this->cObj->getSingle($this->conf['fieldConf.'][$fN.'.']['defaultValue'],$this->conf['fieldConf.'][$fN.'.']['defaultValue.']);
|
|
} elseif($this->conf['fieldConf.'][$fN.'.']['defaultValue.']) {
|
|
$this->get_post[$fN] = $this->cObj->TEXT($this->conf['fieldConf.'][$fN.'.']['defaultValue.']);
|
|
} elseif ($this->conf['fieldConf.'][$fN.'.']['defaultValue']) {
|
|
$this->get_post[$fN] = $this->conf['fieldConf.'][$fN.'.']['defaultValue'];
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* markerArray for uploaded files.
|
|
*
|
|
* @param array $tempMarkerArray reference to the markerArray to be used
|
|
* @param string $activeStep current Step for multipage forms
|
|
*/
|
|
function fillUploadedFilesMarkerArray(&$tempMarkerArray, $activeStep = '1') {
|
|
|
|
#####################
|
|
# replace markers of upload fields (uploaded files are stored in session)
|
|
#####################
|
|
session_start();
|
|
if (is_array($_SESSION['mp_uploadedFiles']) && sizeof($_SESSION['mp_uploadedFiles']) > 0) {
|
|
foreach ($_SESSION['mp_uploadedFiles'] as $fieldname => $uploadedFiles) {
|
|
$fileCounter=0;
|
|
|
|
#####################
|
|
# general file upload markers for each upload-field
|
|
#####################
|
|
if (is_array($this->conf['fieldConf'][$fieldname.'.'])) {
|
|
$tempMarkerArray['###'.$fieldname.'_numberOfUploadedFiles###'] = sizeof($uploadedFiles);
|
|
$tempMarkerArray['###'.$fieldname.'_numberOfRemainingFiles###'] = ($tempMarkerArray['###'.$fieldname.'_numberOfAllowedFiles###']-$tempMarkerArray['###'.$fieldname.'_numberOfUploadedFiles###']);
|
|
}
|
|
|
|
# multi-upload (user can upload multiple files with one input field)
|
|
# mini-template for layout of uploaded files
|
|
# default:
|
|
$tmplUploadedFields = '###fileName###<br />';
|
|
|
|
# defined via TS for all steps:
|
|
# fieldConf.[name of inputfield].uploadedFiles.template
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['template']) {
|
|
$tmplUploadedFields = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['template'];
|
|
}
|
|
|
|
# defined via TS for current step:
|
|
# fieldConf.[name of inputfield].uploadedFiles.[step].template
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.'][$this->multipageStep.'.']['template']) {
|
|
$tmplUploadedFields = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.'][$this->multipageStep.'.']['template'];
|
|
}
|
|
|
|
$outputString = '';
|
|
foreach ($uploadedFiles as $file) {
|
|
|
|
#####################
|
|
# Ralf Hettinger: this switch is configured by TS
|
|
# multipage_without_js = boolean (default false)
|
|
#####################
|
|
# if true, the file deletion triggers aren't realized by JavaScript links,
|
|
# but by named form submit buttons. Those buttons will have to be set
|
|
# within the mini-template:
|
|
# <input type="submit" value="delete ###filename###" ###submitDelete### />
|
|
# ###submitDeleteHidden###
|
|
#
|
|
# the submitDelete markers will add the name="" attribute
|
|
# which triggers a file deletion
|
|
#####################
|
|
if ($this->multipageJS) {
|
|
$tempArray = array(
|
|
'###fileName###' => $file['name'],
|
|
'###fileSize###' => t3lib_div::formatSize($file['size']),
|
|
'###linkDelete_start###' => '<a href="#" onclick="delete_file(\''.$file['name'].'\');set_step('.$activeStep.')">',
|
|
'###linkDelete_stop###' => '</a>',
|
|
'###submitDelete###' => '',
|
|
'###submitDeleteHidden###' => '',
|
|
);
|
|
} else {
|
|
$fileCounter++;
|
|
$tempArray = array(
|
|
'###fileName###' => $file['name'],
|
|
'###fileSize###' => t3lib_div::formatSize($file['size']),
|
|
'###linkDelete_start###' => '',
|
|
'###linkDelete_stop###' => '',
|
|
'###submitDelete###' => ' name="th_mailformplus-mp_step-'.$activeStep.'-delete_file-'.$fileCounter.'"',
|
|
'###submitDeleteHidden###' => '<input type="hidden" name="mp_delete_uploaded_file_'.$fileCounter.'" value="'.$file['name'].'">',
|
|
);
|
|
}
|
|
$outputString .= $this->cObj->substituteMarkerArray($tmplUploadedFields, $tempArray);
|
|
}
|
|
$wrap = '';
|
|
|
|
# wrap for all steps:
|
|
# fieldConf.[name of inputfield].uploadedFiles.wrap
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['wrap']) {
|
|
$wrap = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['wrap'];
|
|
}
|
|
|
|
# wrap for current step:
|
|
# fieldConf.[name of inputfield].uploadedFiles.[step].wrap
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.'][$this->multipageStep.'.']['wrap']) {
|
|
$wrap = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.'][$this->multipageStep.'.']['wrap'];
|
|
}
|
|
|
|
# wrap defined for uploaded files?
|
|
if ($wrap) {
|
|
$outputString = $this->cObj->wrap($outputString, $wrap);
|
|
}
|
|
$tempMarkerArray['###'.$fieldname.'###'] = $outputString;
|
|
$tempMarkerArray['###value_'.$fieldname.'###'] = $outputString;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
/**
|
|
* database mapping: stores values submitted through a form to a database table
|
|
* configuration by TS in saveDB. respectively multipage.saveDb.
|
|
*
|
|
* @param array $conf copy of TS conf of main instance
|
|
*/
|
|
function loadMapping($conf) {
|
|
|
|
##################### corrected by Robert start #############
|
|
$this->conf['saveDB'] = array ();
|
|
##################### corrected by Robert end #############
|
|
|
|
|
|
######################################
|
|
# load all field specific configuration in $this->conf
|
|
# eg. plugin.tx_thmailformplus_pi1.fieldConf.[name of inputfield].numberOfAllowedFiles = 2
|
|
######################################
|
|
$this->conf['fieldConf'] = $conf['fieldConf.'];
|
|
|
|
# data is not configured to be saved in DB or
|
|
# no database table given or
|
|
# no mapping rules specified
|
|
if (($conf['saveDB'] != 1) || (!$conf['saveDB.']['dbTable'])) {
|
|
if ($this->debug == 1) {
|
|
print "no config for saving data in a user-table<br>";
|
|
}
|
|
return;
|
|
}
|
|
$this->conf['saveDB']['dbTable'] = $conf['saveDB.']['dbTable'];
|
|
$this->conf['saveDB']['uploadfolder'] = $conf['saveDB.']['fileUpload'];
|
|
|
|
# key for table specified?
|
|
##################### corrected by Robert start#############
|
|
if (isset($conf['saveDB.']['dbkey'])) {
|
|
$this->conf['saveDB']['dbkey'] = $conf['saveDB.']['dbkey'];
|
|
} else {
|
|
$this->conf['saveDB']['dbkey'] = 'uid';
|
|
}
|
|
##################### corrected by Robert end #############
|
|
|
|
if ($this->debug == 1) {
|
|
print "DB-key is set to: ".$this->conf['saveDB']['dbkey'].'<br>';
|
|
}
|
|
|
|
|
|
# only file of this type can be uploaded (fileTypes = jpg,gif,png,jpeg)
|
|
if ($conf['saveDB.']['fileTypes']) {
|
|
$this->conf['saveDB']['allowedTypes'] = explode(",", $conf['saveDB.']['fileTypes']);
|
|
if ($this->debug == 1) {
|
|
print "only some filetypes are allowed: ".$this->conf['saveDB']['allowedTypes'].'<br>';
|
|
}
|
|
}
|
|
|
|
# file size is limitted
|
|
if ($conf['saveDB.']['fileSize']) {
|
|
$this->conf['saveDB']['allowedSize'] = $conf['saveDB.']['fileSize'];
|
|
if ($this->debug == 1) {
|
|
print "file size is limitted to: ".$this->conf['saveDB']['allowedSize'].'<br>';
|
|
}
|
|
}
|
|
|
|
# fileupload: number of files that can be uploaded with one file-upload-field is limited
|
|
# default: only one file can be uploaded with one file-upload-field
|
|
$this->conf['saveDB']['numberOfAllowedFiles'] = 1;
|
|
if ($conf['saveDB.']['numberOfAllowedFiles']) {
|
|
$this->conf['saveDB']['numberOfAllowedFiles'] = $conf['saveDB.']['numberOfAllowedFiles'];
|
|
if ($this->debug == 1) {
|
|
print "number of allowed files that can be uploaded via one fileupload field, is limited to ".$this->conf['saveDB']['numberOfAllowedFiles'].'<br>';
|
|
}
|
|
}
|
|
|
|
|
|
######################################
|
|
# settings for multipage forms
|
|
######################################
|
|
$this->conf['multiPage'] = $conf['multiPage.'];
|
|
|
|
# fixed values should be inserted into DB
|
|
if ($conf['saveDB.']['dbinsert']) {
|
|
$temp = explode(",", $conf['saveDB.']['dbinsert']);
|
|
foreach ($temp as $temp2) {
|
|
list($dbfield,$value) = explode(":", $temp2);
|
|
$this->conf['saveDB']['dbinsert'][$dbfield] .= $value;
|
|
}
|
|
}
|
|
if ($this->debug == 1) {
|
|
print "fixed values should be inserted into DB. <br>\n";
|
|
print_r($this->conf['saveDB']['dbinsert']);
|
|
}
|
|
|
|
###########################
|
|
# changes made by Reinhard <rf(at)typoheads.at>
|
|
###########################
|
|
# saveDB TS options for mapping all form field values into one db field
|
|
###########################
|
|
if (is_array($conf['saveDB.']['allFields.'])) {
|
|
$excludeFields = array();
|
|
if($conf['saveDB.']['allFields.']['excludeFields'] != "") {
|
|
$excludeFields = t3lib_div::trimExplode(',',$conf['saveDB.']['allFields.']['excludeFields']);
|
|
}
|
|
$allFields = "";
|
|
$leaveEmpty = $conf['saveDB.']['allFields.']['leaveEmptyFields'];
|
|
foreach($this->get_post as $fieldname=>$value) {
|
|
if(!in_array($fieldname,$excludeFields)) {
|
|
if(($leaveEmpty && $value != "") || !$leaveEmpty) {
|
|
if (is_array($value)) {
|
|
for($i=0;$i<count($value);$i++) {
|
|
if(get_magic_quotes_gpc()) {
|
|
$value[$i] = stripslashes($this->reverse_htmlspecialchars($value[$i]));
|
|
} else {
|
|
$value[$i] = $this->reverse_htmlspecialchars($value[$i]);
|
|
}
|
|
}
|
|
$seperator = ',';
|
|
$val = implode($seperator,$value);
|
|
|
|
} elseif(get_magic_quotes_gpc()) {
|
|
$val = stripslashes($this->reverse_htmlspecialchars($value));
|
|
} else {
|
|
$val = $this->reverse_htmlspecialchars($value);
|
|
}
|
|
$label = $fieldname;
|
|
if($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'.$fieldname)) {
|
|
$label = $GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'.$fieldname);
|
|
}
|
|
$allFields[] = $label.' '.$val;
|
|
}
|
|
}
|
|
}
|
|
$fieldcontent = implode("\n",$allFields);
|
|
$dbField = trim($conf['saveDB.']['allFields.']['mapping']);
|
|
$this->conf['saveDB']['dbinsert'][$dbField] = $fieldcontent;
|
|
}
|
|
|
|
|
|
###########################
|
|
# changes made by Reinhard <rf(at)typoheads.at>
|
|
###########################
|
|
# provide new saveDB TS options for mapping and preprocessing
|
|
###########################
|
|
|
|
if (is_array($conf['saveDB.']['fields.'])) {
|
|
foreach ($conf['saveDB.']['fields.'] as $key=>$item) {
|
|
$inputField = str_replace('.','',$key);
|
|
$dbField = $item['mapping'];
|
|
if ($item['preProcessing.'] && $item['preProcessing']) {
|
|
$inputFieldValue = $this->cObj->cObjGetSingle($item['preProcessing'],$item['preProcessing.']);
|
|
} else if($item['postProcessing.'] && $item['postProcessing']) {
|
|
$item['postProcessing.']['value'] = t3lib_div::GPvar($inputField);
|
|
$inputFieldValue = $this->cObj->cObjGetSingle($item['postProcessing'],$item['postProcessing.']);
|
|
} else {
|
|
$inputFieldValue = t3lib_div::GPvar($inputField);
|
|
}
|
|
|
|
//save arrays as string, array items seperated by user defined seperator (default: ',')
|
|
//thanks to Christian M?ller <christian(at)kitsunet.de> for the hint
|
|
if (is_array($inputFieldValue)) {
|
|
for($i=0;$i<count($inputFieldValue);$i++) {
|
|
if(get_magic_quotes_gpc()) {
|
|
$inputFieldValue[$i] = stripslashes($this->reverse_htmlspecialchars($inputFieldValue[$i]));
|
|
} else {
|
|
$inputFieldValue[$i] = $this->reverse_htmlspecialchars($inputFieldValue[$i]);
|
|
}
|
|
}
|
|
# return serialized array instead of imploded array
|
|
if ($item['seperator'] && strcasecmp($item['seperator'],"array") == 0) {
|
|
$inputFieldValue = serialize($inputFieldValue);
|
|
} else { # implode array with use of defined seperator (TS)
|
|
$seperator = ',';
|
|
|
|
# seperator defined in TS
|
|
if ($item['seperator']) {
|
|
$seperator = $item['seperator'];
|
|
}
|
|
|
|
$val = implode($seperator,$inputFieldValue);
|
|
}
|
|
} elseif(get_magic_quotes_gpc()) {
|
|
$val = stripslashes($this->reverse_htmlspecialchars($inputFieldValue));
|
|
} else {
|
|
$val = $this->reverse_htmlspecialchars($inputFieldValue);
|
|
}
|
|
|
|
# if the submitted value is empty AND
|
|
# if_is_empty.[formfieldname] TS is defined for this field, take this value instead
|
|
if (!$val && $val != '0' && $item['if_is_empty']) {
|
|
$val = $item['if_is_empty'];
|
|
}
|
|
if ($dbField != '') {
|
|
$this->conf['saveDB']['dbinsert'][$dbField] .= $val;
|
|
}
|
|
}
|
|
}
|
|
|
|
#####################################################
|
|
# old db mappings (historical/compatibility reasons)
|
|
#####################################################
|
|
# prepare mapping from inputfields to DB fields
|
|
# saveDB.mapping = [inputfieldName]:[DBfieldName],....
|
|
#####################################################
|
|
$temp = explode(",", $conf['saveDB.']['mapping']);
|
|
foreach ($temp as $temp2) {
|
|
list($inputField,$dbField) = explode(":", $temp2);
|
|
|
|
# new mapping was not used for this inputfield -> do old mapping
|
|
if (!isset($conf['saveDB.']['fields.'][$inputField."."])) {
|
|
$this->conf['saveDB']['mapping'][$inputField] = $dbField;
|
|
|
|
###########################################################################
|
|
# Changes made by Reinhard <rf(at)typoheads.at>
|
|
###########################################################################
|
|
# Bug fixed, when calling reverse_htmlspecialchars() with wrong parameter.
|
|
# Thanks to Felix Gebhard <fgebhard(at)exinit.de>
|
|
###########################################################################
|
|
# Old version:
|
|
###########################################################################
|
|
# if(get_magic_quotes_gpc()) $val = stripslashes($this->reverse_htmlspecialchars(t3lib_div::GPvar($inputField)));
|
|
# else $this->reverse_htmlspecialchars($val);
|
|
###########################################################################
|
|
# New version:
|
|
###########################################################################
|
|
|
|
if(get_magic_quotes_gpc()) {
|
|
$val = stripslashes($this->reverse_htmlspecialchars(t3lib_div::GPvar($inputField)));
|
|
} else {
|
|
$val = $this->reverse_htmlspecialchars(t3lib_div::GPvar($inputField));
|
|
}
|
|
|
|
#########################################
|
|
# if the submitted value is empty AND
|
|
# if_is_empty.[formfieldname] TS is defined for this field, take this value instead
|
|
#########################################
|
|
if (!$val && $val != '0' && $conf['saveDB.']['if_is_empty.'][$inputField]) {
|
|
$val = $conf['saveDB.']['if_is_empty.'][$inputField];
|
|
}
|
|
$this->conf['saveDB']['dbinsert'][$dbField] .= $val;
|
|
|
|
} # end if
|
|
} // foreach end
|
|
#####################################################
|
|
# end old db mappings
|
|
#####################################################
|
|
|
|
if ($this->debug == 1) {
|
|
print "These fields are inserted into the DB:<br>\n"; print_r($this->conf['saveDB']['dbinsert']);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* reverse function for htmlspecialchars() function
|
|
* used when form is sent
|
|
*
|
|
* @param array $mixed
|
|
* @return array
|
|
*/
|
|
function reverse_htmlspecialchars($mixed) {
|
|
$htmltable = get_html_translation_table(HTML_ENTITIES);
|
|
foreach($htmltable as $key => $value) {
|
|
$mixed = ereg_replace(addslashes($value),$key,$mixed);
|
|
}
|
|
return $mixed;
|
|
}
|
|
|
|
/**
|
|
* sends emails to user/receiver
|
|
* used when form is sent
|
|
*
|
|
* @param string $content
|
|
* @param array $conf
|
|
*/
|
|
function send_form($content,$conf) {
|
|
|
|
|
|
|
|
# check referer to protect against spam
|
|
$checkReferer = 1;
|
|
|
|
#alowed referers defined via TS
|
|
if ($conf['allowedReferers']) {
|
|
$allowedReferers = explode(",",$conf['allowedReferers']);
|
|
}
|
|
|
|
#add server host to allowed referers in any case
|
|
$allowedReferers[] = $_SERVER['HTTP_HOST'];
|
|
|
|
# if defined in TS, do not check referer
|
|
if ($conf['doNotCheckReferer'] == 1) {
|
|
$checkReferer = 0;
|
|
}
|
|
|
|
#debug
|
|
if ($this->debug == 1) {
|
|
if ($checkReferer) {
|
|
print "referer is checked <br>\n";
|
|
print "allowed referers: <br>\n";
|
|
print_r($allowedReferers);
|
|
print "this is the referer, that gets checked: ".$_SERVER['HTTP_REFERER']."<br>\n";
|
|
print "these are the spam notification options set in TS: <br>\n";
|
|
print_r($this->conf['spamNotify.']);
|
|
} else {
|
|
print "referer is not checked";
|
|
}
|
|
}
|
|
|
|
# do referer check
|
|
if ($checkReferer) {
|
|
$foundAllowedReferer = 0;
|
|
foreach ($allowedReferers as $allowedReferer) {
|
|
if (strpos($_SERVER['HTTP_REFERER'], $allowedReferer) != 0) {
|
|
$foundAllowedReferer = 1;
|
|
}
|
|
}
|
|
|
|
# current referer could not be matched with an allowed referer
|
|
# send notification mail
|
|
if ($foundAllowedReferer == 0) {
|
|
if ($conf['spamNotify'] == 1) {
|
|
$email_to = "";
|
|
if ($conf['spamNotify.']['emailTo']) {
|
|
$email_to = $conf['spamNotify.']['emailTo'];
|
|
}
|
|
$email_from = "";
|
|
if ($conf['spamNotify.']['emailFrom']) {
|
|
$email_from = $conf['spamNotify.']['emailFrom'];
|
|
}
|
|
$subject = "spam notification";
|
|
if ($conf['spamNotify.']['subject']) {
|
|
$subject = $conf['spamNotify.']['subject'];
|
|
}
|
|
if($conf['spamNotify.']['sendInfo.']) {
|
|
foreach ($conf['spamNotify.']['sendInfo.'] as $infoParam=>$value) {
|
|
switch ($infoParam) {
|
|
case 'url':
|
|
if (t3lib_div::_GP("L")) {
|
|
$addparams["L"] = t3lib_div::_GP("L");
|
|
}
|
|
|
|
if (is_array($addparams)) {
|
|
$addparams = array_merge ($addparams,t3lib_div::_GET());
|
|
} else {
|
|
$addparams = t3lib_div::_GET();
|
|
}
|
|
$pid_path = $this->pi_getPageLink($GLOBALS['TSFE']->id,'',$addparams);
|
|
$infoParams['url'] = t3lib_div::locationHeaderUrl('').$pid_path;
|
|
break;
|
|
case 'referer':
|
|
$infoParams['referer'] = $_SERVER['HTTP_REFERER'];
|
|
break;
|
|
case 'submittedData':
|
|
$infoParams['submittedData'] = $this->get_post;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
$emailBody = 'Spam notification!\n';
|
|
if (isset($infoParams)) {
|
|
foreach($infoParams as $key=>$value) {
|
|
switch ($key) {
|
|
case 'url':
|
|
$emailBody .= "Page-URL: ".$value."\n";
|
|
break;
|
|
case 'referer':
|
|
$emailBody .= "Referer: ".$value."\n";
|
|
break;
|
|
case 'submittedData':
|
|
$emailBody .= "Submitted Data:\n";
|
|
foreach ($infoParams[$key] as $k=>$v) {
|
|
$emailBody .= $k." => ".$v."\n";
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
require_once(PATH_t3lib.'class.t3lib_htmlmail.php');
|
|
$emailObj = t3lib_div::makeInstance('t3lib_htmlmail');
|
|
$emailObj->subject = $subject;
|
|
$emailObj->from_email = $email_from;
|
|
$emailObj->from_name = '';
|
|
$emailObj->replyto_email = '';
|
|
$emailObj->replyto_name = '';
|
|
$emailObj->returnPath = '';
|
|
$emailObj->add_header('Content-Type: text/plain; charset="iso-8859-1"');
|
|
$emailObj->setPlain($emailBody);
|
|
if ($this->debug == 1) {
|
|
print "Notification mail sent to: ".$email_to."<br>";
|
|
print "Subject: ".$subject."<br>";
|
|
print "Notification mail sent from: ".$email_from."<br>";
|
|
print "Email-Text: <br>".$emailBody;
|
|
}
|
|
if ($email_to != '' && $email_from != "") {
|
|
$emailObj->send($email_to);
|
|
}
|
|
}
|
|
|
|
# if spam was detected, send notification mail and do not process further!
|
|
return;
|
|
}
|
|
}
|
|
|
|
# form is valid, referrer check ok and submitted for the first time.
|
|
# generate hash and send emails
|
|
if ($this->get_post['SUBMITTED'] || $this->get_post['submitted']) {
|
|
$_SESSION['th_mailformplus'][$GLOBALS["TSFE"]->id]['md5_submitted'] = md5(serialize($this->get_post));
|
|
}
|
|
|
|
$email_subject = $this->getFieldContent("email_subject");
|
|
$email_redirect = $this->getFieldContent("email_redirect");
|
|
$email_sender = $this->getFieldContent("email_sender");
|
|
|
|
|
|
$email_to = $this->getFieldContent("email_to");
|
|
$email_replyto = $this->getFieldContent("email_replyto");
|
|
|
|
################################
|
|
# begin changes made by Claudio
|
|
#
|
|
# Get the email_html_as_attachment config option: if set,
|
|
# the html version of the output will be included in the
|
|
# mail sent to the user as an attachment, instead of as an
|
|
# alternative to the plain text version.
|
|
################################
|
|
$email_html_as_attachment = $this->getFieldContent("email_html_as_attachment");
|
|
################################
|
|
# end changes made by Claudio
|
|
################################
|
|
|
|
# since 18.10.2005: prevent mail injection (reported by Joerg Schoppet - thx!)
|
|
if (eregi("\r",$email_sender) || eregi("\n",$email_sender)) {
|
|
$email_sender = '';
|
|
}
|
|
|
|
if (eregi("\r",$email_subject) || eregi("\n",$email_subject)) {
|
|
$email_subject = '';
|
|
}
|
|
|
|
# use the submitted email address of the specified inputfield as reply-to in the sent email
|
|
####################################
|
|
# Changed by Reinhard
|
|
####################################
|
|
# Add possibility to enter a comma seperated list for reply_to and use new TS settings email_replyto_email_sender to add the sender's address to reply_to
|
|
####################################
|
|
# Thx to Claudio Strizzolo <Claudio.Strizzolo(at)ts.infn.it>
|
|
####################################
|
|
$email_replyto = t3lib_div::trimExplode(",",$email_replyto);
|
|
if($this->getFieldContent("email_replyto_email_sender") == "1") {
|
|
$replyto = $email_sender.",";
|
|
} else {
|
|
$replyto = "";
|
|
}
|
|
foreach($email_replyto as $email) {
|
|
if ($email &&
|
|
$this->get_post[$email] &&
|
|
!eregi("\r",$this->get_post[$email]) &&
|
|
!eregi("\n",$this->get_post[$email]) &&
|
|
sizeof(explode('@', $this->get_post[$email])) == 2
|
|
) {
|
|
|
|
$replyto .= $this->get_post[$email].",";
|
|
} else {
|
|
$replyto .= $email.",";
|
|
}
|
|
}
|
|
$email_replyto = substr($replyto,0,strlen($replyto)-1);
|
|
|
|
# define MarkerArray for replacing emails
|
|
# $globalMarkerArray=array();
|
|
$globalMarkerArray = $this->substituteTSMarkers($globalMarkerArray,$conf);
|
|
|
|
|
|
if (is_array($this->get_post)) {
|
|
foreach($this->get_post as $k=>$v) {
|
|
if (!ereg('EMAIL_', $k)) {
|
|
if (is_array($v)) {
|
|
$v = implode(',', $v);
|
|
}
|
|
$v = trim($v);
|
|
if ($v != "") {
|
|
if(get_magic_quotes_gpc()) {
|
|
$globalMarkerArray['###value_'.$k.'###'] = stripslashes($this->reverse_htmlspecialchars($v));
|
|
} else {
|
|
$globalMarkerArray['###value_'.$k.'###'] = $this->reverse_htmlspecialchars($v);
|
|
}
|
|
} else {
|
|
$globalMarkerArray['###value_'.$k.'###'] = '';
|
|
}
|
|
$globalMarkerArray['###'.$k.'###'] = $globalMarkerArray['###value_'.$k.'###'];
|
|
|
|
# this is for log file in table tx_thmailformplus_log
|
|
# saving all submitted forms in CSV format
|
|
$csv_firstline .= $k.';';
|
|
$csv_line .= $globalMarkerArray['###value_'.$k.'###'].';~';
|
|
} //if end
|
|
} // foreach end
|
|
} // if end
|
|
|
|
############################
|
|
# write into log-table in specified order
|
|
# plugin.tx_thmailformplus_pi1.saveLog.order = [formular input name],[formular input name],...
|
|
#
|
|
# exclude the fields defined in
|
|
# plugin.tx_thmailformplus_pi1.saveLog.exclude = [formular input name],[formular input name],...
|
|
#
|
|
# if no value is specified, take '' as default value, or (if specified):
|
|
# plugin.tx_thmailformplus_pi1.saveLog.defaultValue = 0
|
|
############################
|
|
if ($conf['saveLog'] == 1) {
|
|
|
|
# an order is specified in which the fields should be saved
|
|
# else: take all fields
|
|
if ($conf['saveLog.']['order']) {
|
|
$saveFields = array_map("trim", explode(',', $conf['saveLog.']['order']));
|
|
} else {
|
|
$saveFields = array_keys($this->get_post);
|
|
}
|
|
|
|
# fields should be excluded
|
|
if ($conf['saveLog.']['exclude']) {
|
|
$excludeFields = array_map("trim", explode(',', $conf['saveLog.']['exclude']));
|
|
}
|
|
$csv_firstline = '';
|
|
$csv_line = '';
|
|
|
|
# set default value
|
|
$defaultValue = $conf['saveLog.']['defaultValue'];
|
|
if (!$defaultValue && $defaultValue != '0') {
|
|
$defaultValue = '';
|
|
}
|
|
|
|
# loop trough all specified fields that have to be saved
|
|
foreach ($saveFields as $k) {
|
|
|
|
# only save this field if it's not in the "exclude" list (TS) '
|
|
if (!is_array($excludeFields) || !in_array($k, $excludeFields)) {
|
|
$csv_firstline .= $k.';';
|
|
$v = $this->get_post[$k];
|
|
if(is_array($v)) {
|
|
$v = implode(',',$v);
|
|
}
|
|
if ($v != "") {
|
|
$csv_line .= $v.';~';
|
|
} else {
|
|
$csv_line .= $defaultValue.';~';
|
|
}
|
|
} // if end
|
|
} // foreach end
|
|
|
|
if($conf['saveLog.']['logIP']) {
|
|
$csv_firstline .= 'IP;';
|
|
$csv_line .= $_SERVER['REMOTE_ADDR'].';~';
|
|
}
|
|
if($conf['saveLog.']['logDateTime']) {
|
|
$csv_firstline .= 'submission_date;';
|
|
$csv_line .= date("Y-m-d H:i:s",time()).';~';
|
|
}
|
|
} // if end
|
|
|
|
############################
|
|
# post-process data with user func
|
|
# thx to Martin Kutschker
|
|
#
|
|
# example usage:
|
|
#
|
|
# class tx_myext {
|
|
# function doit(&$params, &$ref){
|
|
# ...
|
|
# }
|
|
# }
|
|
#
|
|
# plugin.tx_thmailformplus_pi1 {
|
|
# saveUserFunc = EXT:myext/class.tx_myext.php:tx_myext->doit
|
|
# saveUserFunc.dummy = hello
|
|
# }
|
|
#
|
|
############################
|
|
############################
|
|
# changes made by Reinhard
|
|
############################
|
|
# Adding a fourth parameter, which is the prefix a userFunc must have.
|
|
# Thanks to Maik Vlcek <maik.vl(at)web.de> for the report
|
|
############################
|
|
# Old version:
|
|
############################
|
|
#if ($this->conf['saveUserFunc']) {
|
|
# $params['config'] = $this->conf['saveUserFunc.'];
|
|
# $params['data'] = $this->get_post;
|
|
# t3lib_div::callUserFunction($this->conf['saveUserFunc'],$params,$this);
|
|
#}
|
|
############################
|
|
# New Version:
|
|
############################
|
|
if ($this->conf['saveUserFunc']) {
|
|
$params['config'] = $this->conf['saveUserFunc.'];
|
|
$params['data'] = $this->get_post;
|
|
t3lib_div::callUserFunction($this->conf['saveUserFunc'],$params,$this,"");
|
|
}
|
|
############################
|
|
|
|
############################
|
|
# insert into standard DB (access via th_mailformplus backend module)
|
|
############################
|
|
|
|
# Ralf Hettinger: Store reference to a saveDB database storage, if configured
|
|
if( $this->conf['saveDB.']['specialMapping']==1 && $this->conf['saveDB.']['specialMapping.']['storeuid'] && $this->conf['saveDB']['id']) {
|
|
$csv_firstline .= 'DB_uid;';
|
|
$csv_line .= $this->conf['saveDB']['id'].';~';
|
|
}
|
|
if($conf['saveLog'] != -1) {
|
|
$csv_firstline = substr($csv_firstline, 0, strlen($csv_firstline)-1)."\n";
|
|
$csv_line = substr($csv_line, 0, strlen($csv_line)-2);
|
|
$insertArray = array(
|
|
'pid' => $GLOBALS["TSFE"]->id,
|
|
'submittedfields' => $csv_firstline.$csv_line,
|
|
'logdate' => time()
|
|
);
|
|
$query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_thmailformplus_log', $insertArray);
|
|
$res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $query);
|
|
}
|
|
|
|
############################
|
|
# insert into user specified table
|
|
############################
|
|
if ($this->conf['saveDB']['dbTable']) {
|
|
|
|
#####################
|
|
# Ralf Hettinger: special mapping functions by TYPOSCRIPT for
|
|
# - submission date and time,
|
|
# - submission IP,
|
|
# - crdate,
|
|
# - reference to the saveDB id
|
|
#####################
|
|
|
|
# saveDB.specialMapping.sub_datetime = fieldname
|
|
# write the submission date and time in internationalized format into db-table
|
|
$insertionDate = date("Y-m-d H:i:s", time());
|
|
if( $this->conf['saveDB.']['specialMapping']==1 && $this->conf['saveDB.']['specialMapping.']['sub_datetime']) {
|
|
$this->conf['saveDB']['dbinsert'][$this->conf['saveDB.']['specialMapping.']['sub_datetime']] = $insertionDate;
|
|
}
|
|
|
|
# TS saveDB.specialMapping.logIP = fieldname
|
|
# write the IP address into db-table
|
|
if( $this->conf['saveDB.']['specialMapping']==1 && $this->conf['saveDB.']['specialMapping.']['logIP']) {
|
|
$this->conf['saveDB']['dbinsert'][$this->conf['saveDB.']['specialMapping.']['logIP']] = t3lib_div::getIndpEnv('REMOTE_ADDR');
|
|
}
|
|
|
|
# TS saveDB.specialMapping.crdate = boolean
|
|
# fill TYPO3's default field for creation time (crdate)
|
|
if( $this->conf['saveDB.']['specialMapping']==1 && $this->conf['saveDB.']['specialMapping.']['crdate']) {
|
|
$this->conf['saveDB']['dbinsert']['crdate'] = time();
|
|
}
|
|
|
|
# TS saveDB.specialMapping.tstamp = boolean
|
|
# fill TYPO3's default field for creation time (tstamp)
|
|
if( $this->conf['saveDB.']['specialMapping']==1 && $this->conf['saveDB.']['specialMapping.']['tstamp']) {
|
|
$this->conf['saveDB']['dbinsert']['tstamp'] = time();
|
|
}
|
|
|
|
$insertArray = $this->conf['saveDB']['dbinsert'];
|
|
foreach ($insertArray as $k=>$v) {
|
|
if ($k != '') {
|
|
$trimmedInsertArray[$k] = $v;
|
|
}
|
|
}
|
|
#$trimmedInsertArray = $this->sanitizeValues($trimmedInsertArray); "
|
|
|
|
################
|
|
# Possibility to save form data to different DB
|
|
################
|
|
if(($this->conf['saveDB.']['useDifferentDB'])) {
|
|
|
|
#read connection properties
|
|
$host = $this->conf['saveDB.']['useDifferentDB.']['host'];
|
|
$port = $this->conf['saveDB.']['useDifferentDB.']['port'];
|
|
if(!$host) {
|
|
$host = '';
|
|
} else if($port) {
|
|
$host = $host.':'.$port;
|
|
}
|
|
$driver = $this->conf['saveDB.']['useDifferentDB.']['driver'];
|
|
$dbname = $this->conf['saveDB.']['useDifferentDB.']['db'];
|
|
$user = $this->conf['saveDB.']['useDifferentDB.']['user'];
|
|
$password = $this->conf['saveDB.']['useDifferentDB.']['password'];
|
|
|
|
#if adodb is loaded
|
|
if(t3lib_extMgm::isLoaded('adodb')) {
|
|
require_once(t3lib_extMgm::extPath('adodb').'adodb/adodb.inc.php');
|
|
|
|
#read fields to map in different db
|
|
$fields = $this->conf['saveDB.']['useDifferentDB.']['saveFields'];
|
|
$fields = explode(',',$fields);
|
|
$otherDBinsertArray = array();
|
|
|
|
#run through generated insert array and only map set fields to different db insert array
|
|
foreach($trimmedInsertArray as $fieldname=>$value) {
|
|
if(in_array($fieldname,$fields)) {
|
|
$otherDBinsertArray[$fieldname] = "'".$value."'";
|
|
}
|
|
}
|
|
|
|
#read table
|
|
$table = $this->conf['saveDB']['dbTable'];
|
|
if($this->conf['saveDB.']['useDifferentDB.']['table']) {
|
|
$table = $this->conf['saveDB.']['useDifferentDB.']['table'];
|
|
}
|
|
|
|
#build sql
|
|
$sql = "INSERT INTO ".$table." (".(implode(',',array_keys($otherDBinsertArray))).") VALUES (".(implode(',',$otherDBinsertArray)).")";
|
|
|
|
#open connection
|
|
$db = &NewADOConnection($driver);
|
|
if($dbname) {
|
|
$db->Connect($host, $user, $password, $dbname);
|
|
} else {
|
|
$db->Connect($host, $user, $password);
|
|
}
|
|
|
|
#insert data
|
|
$db->Execute($sql);
|
|
|
|
#close connection
|
|
$db->Close();
|
|
}
|
|
|
|
}
|
|
|
|
##############################
|
|
# possibility to UPDATE an existing record instead of INSERTing a new one
|
|
# by Mike (BitCon); 19.2.2008
|
|
##############################
|
|
|
|
$madeUpdateInsteadOfInsert = false;
|
|
# UPDATE
|
|
if(isset($trimmedInsertArray[$this->conf['saveDB']['dbkey']]) && $this->conf['saveDB.']['updateInsteadOfInsert'] == 1) {
|
|
|
|
$query = $GLOBALS['TYPO3_DB']->UPDATEquery($this->conf['saveDB']['dbTable'],"uid=" . $trimmedInsertArray['uid'], $trimmedInsertArray);
|
|
$madeUpdateInsteadOfInsert = true;
|
|
$makequery = true;
|
|
|
|
$authCheckFailed = false;
|
|
$authCode = null;
|
|
if($this->conf['saveDB.']['checkAuth'] == 1) {
|
|
$TSConf = array(
|
|
'dbTable' => $this->conf['saveDB']['dbTable'],
|
|
'where' => 'uid="'.$trimmedInsertArray['uid'].'"',
|
|
);
|
|
$authCode = user_mailformplusAPI::user_authCode('',$TSConf);
|
|
$gpFieldname = $this->conf['saveDB.']['checkAuth.']['GPname'];
|
|
if (!$gpFieldname) $gpFieldname = 'md5';
|
|
if($authCode != null && isset($this->get_post[$gpFieldname]) && $this->get_post[$gpFieldname] == $authCode) {
|
|
$makequery = true;
|
|
} else {
|
|
$authCheckFailed = true;
|
|
}
|
|
}
|
|
|
|
}
|
|
# INSERT
|
|
else {
|
|
|
|
$query = $GLOBALS['TYPO3_DB']->INSERTquery($this->conf['saveDB']['dbTable'], $trimmedInsertArray);
|
|
$makequery = true;
|
|
|
|
}
|
|
|
|
if ($this->debug == 1) {
|
|
print "executing this query for saving data in user specified table:<br>".$query.'<br><br>';
|
|
}
|
|
|
|
|
|
|
|
|
|
if($makequery) $res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $query);
|
|
if ($res) {
|
|
|
|
if($madeUpdateInsteadOfInsert == true) {
|
|
$this->conf['saveDB']['id'] = $trimmedInsertArray['uid'];
|
|
} else {
|
|
# insert OK
|
|
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
|
|
'max('.$this->conf['saveDB']['dbkey'].') as max',
|
|
$this->conf['saveDB']['dbTable'],
|
|
''
|
|
);
|
|
if ($res && $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
|
|
$this->conf['saveDB']['id'] = $row['max'];
|
|
}
|
|
|
|
}
|
|
|
|
# Ralf Hettinger
|
|
# saveDB.specialMapping.storeuid = fieldname
|
|
# - store the saveDB id in a second db-field and
|
|
# - reference this id as first csv-field named DB_uid in the csv-table
|
|
# this is pretty handy if this id is used in emails to
|
|
# reference a record that is administered by the user db-table entries
|
|
if( $this->conf['saveDB.']['specialMapping']==1 && $this->conf['saveDB.']['specialMapping.']['storeuid']) {
|
|
$query = $GLOBALS['TYPO3_DB']->UPDATEquery (
|
|
$this->conf['saveDB']['dbTable'],
|
|
$this->conf['saveDB']['dbkey']."=".$this->conf['saveDB']['id'],
|
|
Array(
|
|
$this->conf['saveDB.']['specialMapping.']['storeuid'] => $this->conf['saveDB']['id']
|
|
)
|
|
);
|
|
if ($this->debug == 1) {
|
|
print "executing specialMapping update uid query for saving data in user specified table:<br>".$query.'<br><br>';
|
|
}
|
|
$res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $query);
|
|
}
|
|
|
|
# typoheads-dev-team:
|
|
# generate ###authCode### marker
|
|
if ($this->conf['saveDB']['id']){
|
|
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
|
|
'*',
|
|
$this->conf['saveDB']['dbTable'],
|
|
$this->conf['saveDB']['dbkey'].'="'.$this->conf['saveDB']['id'].'"' #"
|
|
);
|
|
if ($res && $row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
|
|
$authCode = t3lib_div::stdAuthCode($row2);
|
|
$globalMarkerArray['###authCode###'] = $authCode;
|
|
}
|
|
}
|
|
|
|
|
|
if ($this->debug == 1) {
|
|
if($madeUpdateInsteadOfInsert == true) {
|
|
print "update sucessfully! updated UID: ".$this->conf['saveDB']['id']."<br>\n";
|
|
} else {
|
|
print "insert sucessfully! generated UID: ".$row['max']."<br>\n";
|
|
}
|
|
}
|
|
|
|
} else {
|
|
if ($this->debug == 1) {
|
|
if($madeUpdateInsteadOfInsert == true) {
|
|
if($authCheckFailed) {
|
|
print "update FAILED because of auth/md5-check failure." . "<br>\n";
|
|
} else {
|
|
print "update FAILED: ".$GLOBALS['TYPO3_DB']->sql_error()."<br>\n";
|
|
}
|
|
} else {
|
|
print "insert FAILED: ".$GLOBALS['TYPO3_DB']->sql_error()."<br>\n";
|
|
}
|
|
}
|
|
}
|
|
} # end if $this->conf['saveDB']['dbTable']
|
|
|
|
#####################
|
|
# uploaded fields (stored in session)
|
|
#####################
|
|
session_start();
|
|
if (is_array($_SESSION['mp_uploadedFiles']) && sizeof($_SESSION['mp_uploadedFiles']) > 0) {
|
|
foreach ($_SESSION['mp_uploadedFiles'] as $fieldname => $uploadedFiles) {
|
|
|
|
# multi-upload supported (user can upload multiple files with one input field)
|
|
# mini-template for layout of uploaded files
|
|
|
|
# default:
|
|
$tmplUploadedFieldsReceiverPlain = "###fileName###\n";
|
|
$tmplUploadedFieldsReceiverHTML = "###fileName###<br>";
|
|
$tmplUploadedFieldsUserPlain = $tmplUploadedFieldsReceiverPlain;
|
|
$tmplUploadedFieldsUserHTML = $tmplUploadedFieldsReceiverHTML;
|
|
$tmplUploadedFieldsPrint = $tmplUploadedFieldsReceiverHTML;
|
|
|
|
##########################################
|
|
# template for user & receiver
|
|
##########################################
|
|
# Plaintext
|
|
# defined via TS for all mails (to receiver, to user) (fieldConf.[name of inputfield].uploadedFiles.mail.plainTemplate)
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mail.']['plainTemplate']) {
|
|
$tmplUploadedFieldsReceiverPlain = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mail.']['plainTemplate'];
|
|
$tmplUploadedFieldsUserPlain = $tmplUploadedFieldsReceiverPlain;
|
|
}
|
|
|
|
# HTML
|
|
# defined via TS for all mails (to receiver, to user) (fieldConf.[name of inputfield].uploadedFiles.mail.HTMLTemplate)
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mail.']['HTMLTemplate']) {
|
|
$tmplUploadedFieldsReceiverHTML = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mail.']['HTMLTemplate'];
|
|
$tmplUploadedFieldsUserHTML = $tmplUploadedFieldsReceiverHTML;
|
|
} else { # no HTML template defined -> take plain instead
|
|
$tmplUploadedFieldsReceiverHTML = $tmplUploadedFieldsReceiverPlain;
|
|
$tmplUploadedFieldsUserHTML = $tmplUploadedFieldsUserPlain;
|
|
}
|
|
|
|
##########################################
|
|
# template for receiver
|
|
##########################################
|
|
# defined via TS for mail to reciever (fieldConf.[name of inputfield].uploadedFiles.mailReceiver.plainTemplate)
|
|
# Plaintext
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailReceiver.']['plainTemplate']) {
|
|
$tmplUploadedFieldsReceiverPlain = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailReceiver.']['plainTemplate'];
|
|
}
|
|
|
|
# HTML
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailReceiver.']['HTMLTemplate']) {
|
|
$tmplUploadedFieldsReceiverHTML = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailReceiver.']['HTMLTemplate'];
|
|
} else if (!$tmplUploadedFieldsReceiverHTML) { # no HTML template defined -> take plain instead
|
|
$tmplUploadedFieldsReceiverHTML = $tmplUploadedFieldsReceiverPlain;
|
|
}
|
|
|
|
##########################################
|
|
# template for user
|
|
##########################################
|
|
# defined via TS for mail to user (fieldConf.[name of inputfield].uploadedFiles.mailUser.HTMLTemplate)
|
|
# Plaintext
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailUser.']['plainTemplate']) {
|
|
$tmplUploadedFieldsUserPlain = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailUser.']['plainTemplate'];
|
|
}
|
|
|
|
# HTML
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailUser.']['HTMLTemplate']) {
|
|
$tmplUploadedFieldsUserHTML = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailUser.']['HTMLTemplate'];
|
|
} elseif (!$tmplUploadedFieldsUserHTML) { # no HTML template defined -> take plain instead
|
|
$tmplUploadedFieldsUserHTML = $tmplUploadedFieldsUserPlain;
|
|
}
|
|
|
|
##########################################
|
|
# template for print-view
|
|
##########################################
|
|
# defined via TS for print-viw (fieldConf.[name of inputfield].uploadedFiles.print.template)
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['print.']['template']) {
|
|
$tmplUploadedFieldsPrint = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['print.']['template'];
|
|
}
|
|
|
|
$email_text_uploadsReceiverPlain = '';
|
|
$email_text_uploadsUserPlain = '';
|
|
$email_text_uploadsReceiverHTML = '';
|
|
$email_text_uploadsUserHTML = '';
|
|
$email_text_uploadsPrint = '';
|
|
|
|
######################################
|
|
# foreach file
|
|
######################################
|
|
foreach ($uploadedFiles as $file) {
|
|
|
|
################################
|
|
# move file from temp file to persistent stored file if it exists
|
|
################################
|
|
if (file_exists($file['uploadedFilename'])) {
|
|
$newFilename = $GLOBALS["TSFE"]->id.'_'.$this->conf['saveDB']['id'].'_'.$file['name'];
|
|
$newFilename = str_replace(" ","_",$newFilename);
|
|
$prefix = t3lib_div::shortMD5(rand().time()).'_';
|
|
while (file_exists($file['filePath'].$prefix.$newFilename)) {
|
|
$prefix = t3lib_div::shortMD5(rand().time()).'_';
|
|
}
|
|
|
|
# copy to new filename and
|
|
# delete old temporary filename
|
|
if (copy($file['uploadedFilename'], $file['filePath'].$prefix.$newFilename)) {
|
|
unlink($file['uploadedFilename']);
|
|
$file['uploadedFilename'] = $file['filePath'].$prefix.$newFilename;
|
|
$file['name'] = $prefix.$newFilename;
|
|
} elseif ($this->debug == 1) {
|
|
print "can not copy temporary file '".$file['uploadedFilename']."' to '".$file['filePath'].$prefix.$newFilename."' !<br>";
|
|
}
|
|
|
|
################################
|
|
# prepare update in DB for "saveDB." record
|
|
################################
|
|
$temp = '';
|
|
if ($updateArray[$this->conf['saveDB']['mapping'][$fieldname]]){
|
|
$temp = ',';
|
|
}
|
|
if ($this->conf['saveDB']['mapping'][$fieldname]) {
|
|
$updateArray[$this->conf['saveDB']['mapping'][$fieldname]] .= $temp.$prefix.$newFilename;
|
|
}
|
|
$tempArray = array(
|
|
'###fileName###' => $file['name'],
|
|
'###fileSize###' => t3lib_div::formatSize($file['size']),
|
|
'###filePath###' => 'http://'.$_SERVER["HTTP_HOST"].'/'.$file['filePath'],
|
|
);
|
|
|
|
$email_text_uploadsReceiverPlain .= $this->cObj->substituteMarkerArray($tmplUploadedFieldsReceiverPlain, $tempArray);
|
|
$email_text_uploadsUserPlain .= $this->cObj->substituteMarkerArray($tmplUploadedFieldsUserPlain, $tempArray);
|
|
$email_text_uploadsReceiverHTML .= $this->cObj->substituteMarkerArray($tmplUploadedFieldsReceiverHTML, $tempArray);
|
|
$email_text_uploadsUserHTML .= $this->cObj->substituteMarkerArray($tmplUploadedFieldsUserHTML, $tempArray);
|
|
$email_text_uploadsPrint .= $this->cObj->substituteMarkerArray($tmplUploadedFieldsPrint, $tempArray);
|
|
$this->uploadedFiles[$fieldname] = $email_text_uploadsReceiverPlain;
|
|
|
|
} # form has been already saved - all temporary files have already been deleted
|
|
} //foreach end
|
|
|
|
###################################
|
|
# wrap defined for uploaded files?
|
|
###################################
|
|
$wrapReceiverPlain = '';
|
|
$wrapUserPlain = '';
|
|
$wrapReceiverHTML = '';
|
|
$wrapUserHTML = '';
|
|
$wrapPrint = '';
|
|
|
|
#####################################
|
|
# wrap: receiver
|
|
#####################################
|
|
## defined for mail to receiver
|
|
|
|
# plain
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailReceiver.']['plainWrap']) {
|
|
$wrapReceiverPlain = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailReceiver.']['plainWrap'];
|
|
}
|
|
|
|
# HTML
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailReceiver.']['HTMLWrap']) {
|
|
$wrapReceiverHTML = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailReceiver.']['HTMLWrap'];
|
|
} else if ($wrapReceiverPlain) {
|
|
$wrapReceiverHTML = $wrapReceiverPlain;
|
|
}
|
|
|
|
## generally for mails
|
|
# plain
|
|
if (!$wrapReceiverPlain && $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mail.']['plainWrap']) {
|
|
$wrapReceiverPlain = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mail.']['plainWrap'];
|
|
}
|
|
|
|
# HTML
|
|
if (!$wrapReceiverHTML && $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mail.']['HTMLWrap']) {
|
|
$wrapReceiverHTML = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mail.']['HTMLWrap'];
|
|
} elseif (!$wrapReceiverHTML && $wrapReceiverPlain) {
|
|
$wrapReceiverHTML = $wrapReceiverPlain;
|
|
}
|
|
|
|
# do wrap for plaintext
|
|
if ($wrapReceiverPlain) {
|
|
$email_text_uploadsReceiverPlain = $this->cObj->wrap($email_text_uploadsReceiverPlain, $wrapReceiverPlain);
|
|
}
|
|
# do wrap for HTML
|
|
if ($wrapReceiverHTML) {
|
|
$email_text_uploadsReceiverHTML = $this->cObj->wrap($email_text_uploadsReceiverHTML, $wrapReceiverHTML);
|
|
}
|
|
|
|
#####################################
|
|
# wrap: user
|
|
#####################################
|
|
# defined for mail to user
|
|
# plain
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailUser.']['plainWrap']) {
|
|
$wrapUserPlain = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailUser.']['plainWrap'];
|
|
}
|
|
|
|
# HTML
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailUser.']['HTMLWrap']) {
|
|
$wrapUserHTML = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mailUser.']['HTMLWrap'];
|
|
} elseif ($wrapUserPlain) {
|
|
$wrapUserHTML = $wrapUserPlain;
|
|
}
|
|
|
|
# generally for mails
|
|
# plain
|
|
if (!$wrapUserPlain && $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mail.']['plainWrap']) {
|
|
$wrapUserPlain = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mail.']['plainWrap'];
|
|
}
|
|
|
|
# HTML
|
|
if (!$wrapUserHTML && $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mail.']['HTMLWrap']) {
|
|
$wrapUserHTML = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['mail.']['HTMLWrap'];
|
|
} elseif (!$wrapUserHTML && $wrapUserPlain) {
|
|
$wrapUserHTML = $wrapUserPlain;
|
|
}
|
|
|
|
# do wrap for plaintext
|
|
if ($wrapUserPlain) {
|
|
$email_text_uploadsUserPlain = $this->cObj->wrap($email_text_uploadsUserPlain, $wrapUserPlain);
|
|
}
|
|
|
|
# do wrap for HTML
|
|
if ($wrapUserHTML) {
|
|
$email_text_uploadsUserHTML = $this->cObj->wrap($email_text_uploadsUserHTML, $wrapUserHTML);
|
|
}
|
|
|
|
#####################################
|
|
# wrap: print
|
|
#####################################
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['print.']['wrap']) {
|
|
$wrapPrint = $this->conf['fieldConf'][$fieldname.'.']['uploadedFiles.']['print.']['wrap'];
|
|
}
|
|
|
|
###############################
|
|
# replace all \n within the template with real line breaks
|
|
###############################
|
|
$email_text_uploadsReceiverPlain = str_replace('\n', "\n", $email_text_uploadsReceiverPlain);
|
|
$email_text_uploadsUserPlain = str_replace('\n', "\n", $email_text_uploadsUserPlain);
|
|
$email_text_uploadsReceiverHTML = str_replace('\n', "\n", $email_text_uploadsReceiverHTML);
|
|
$email_text_uploadsUserHTML = str_replace('\n', "\n", $email_text_uploadsUserHTML);
|
|
$email_text_uploadsPrint = str_replace('\n', "\n", $email_text_uploadsPrint);
|
|
|
|
# plain
|
|
$plainReceiverMarkerArray['###'.$fieldname.'###'] = $email_text_uploadsReceiverPlain;
|
|
$plainUserMarkerArray['###'.$fieldname.'###'] = $email_text_uploadsUserPlain;
|
|
$plainReceiverMarkerArray['###value_'.$fieldname.'###'] = $email_text_uploadsReceiverPlain;
|
|
$plainUserMarkerArray['###value_'.$fieldname.'###'] = $email_text_uploadsUserPlain;
|
|
|
|
# HTML
|
|
$htmlReceiverMarkerArray['###'.$fieldname.'###'] = $email_text_uploadsReceiverHTML;
|
|
$htmlUserMarkerArray['###'.$fieldname.'###'] = $email_text_uploadsUserHTML;
|
|
$htmlReceiverMarkerArray['###value_'.$fieldname.'###'] = $email_text_uploadsReceiverHTML;
|
|
$htmlUserMarkerArray['###value_'.$fieldname.'###'] = $email_text_uploadsUserHTML;
|
|
|
|
# Print
|
|
$printMarkerArray['###'.$fieldname.'###'] = $email_text_uploadsPrint;
|
|
$printMarkerArray['###value_'.$fieldname.'###'] = $email_text_uploadsPrint;
|
|
|
|
# default-marker
|
|
$globalMarkerArray['###'.$fieldname.'###'] = $email_text_uploadsReceiverPlain;
|
|
$globalMarkerArray['###value_'.$fieldname.'###'] = $email_text_uploadsReceiverPlain;
|
|
} // foreach end
|
|
} // if end
|
|
|
|
# make update of record for uploaded files
|
|
# only if saveDB is activated (thx to Jose Antonio Guerra for reporting this bug)
|
|
if ($this->conf['saveDB']['dbTable'] && count($updateArray) > 0) {
|
|
$res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery($this->conf['saveDB']['dbTable'], $this->conf['saveDB']['dbkey'].'='.$this->conf['saveDB']['id'], $updateArray);
|
|
}
|
|
$globalMarkerArray["###EMAIL_SUBJ###"] = $this->getFieldContent("email_subject");
|
|
$globalMarkerArray["###EMAIL_SUBJ_USER###"] = $this->getFieldContent("email_subject_user");
|
|
$globalMarkerArray["###EMAIL_SUBJECT###"] = $this->getFieldContent("email_subject");
|
|
$globalMarkerArray["###EMAIL_SUBJECT_USER###"] = $this->getFieldContent("email_subject_user");
|
|
$globalMarkerArray["###EMAIL_REDIRECT###"] = $this->getFieldContent("email_redirect");
|
|
$globalMarkerArray["###EMAIL_SENDER###"] = $this->getFieldContent("email_sender");
|
|
$globalMarkerArray["###EMAIL_TO###"] = $this->getFieldContent("email_to");
|
|
$globalMarkerArray["###EMAIL_REQUIREDFIELDS###"] = $this->getFieldContent("email_requiredfields");
|
|
// $globalMarkerArray['###PID###'] = $this->get_post['id'];
|
|
|
|
##############################################
|
|
# inserted by Reinhard <rf(at)typoheads.at>
|
|
##############################################
|
|
# patch using flexforms provided by Marcel Alburg <alb(at)weeaar.com>
|
|
##############################################
|
|
$globalMarkerArray['###value_language_id###'] = $GLOBALS['TSFE']->sys_language_uid;
|
|
##############################################
|
|
|
|
$globalMarkerArray['###PID###'] = $GLOBALS["TSFE"]->id;
|
|
|
|
$globalMarkerArray['###ERROR###'] = $this->error;
|
|
if($conf['noDefaultErrorList'] && $this->error) {
|
|
$errorText = $GLOBALS["TSFE"]->cObj->getSubpart($this->templateCode_error, "ERROR_START");
|
|
$markers = $this->substituteLangMarkers($errorText);
|
|
$errorText = $this->cObj->substituteMarkerArray($errorText, $markers);
|
|
$globalMarkerArray['###ERROR###'] = $errorText;
|
|
}
|
|
|
|
# Ralf Hettinger: if DB_UID is available
|
|
# for referencing a record in the saveDB table:
|
|
# replace it in E-Mails with the marker
|
|
# ###DB_UID###
|
|
# changed by Typoheads-Dev-Team:
|
|
# always set the marker ###DB_UID###
|
|
# original: if ($this->conf['saveDB.']['specialMapping']==1 && $this->conf['saveDB.']['specialMapping.']['storeuid'] && $this->conf['saveDB']['id']) {
|
|
if ($this->conf['saveDB']['id']) {
|
|
$globalMarkerArray['###DB_UID###'] = $this->conf['saveDB']['id'];
|
|
}
|
|
|
|
# Ralf Hettinger: hook for individual email markers
|
|
# print $this->prefixId;
|
|
if (is_array ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey][$this->prefixId]['send_form'])) {
|
|
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey][$this->prefixId]['send_form'] as $classRef) {
|
|
$hookObj= &t3lib_div::getUserObj($classRef);
|
|
if (method_exists($hookObj, 'send_form_markers')) {
|
|
$hookObj->send_form_markers($globalMarkerArray, $this);
|
|
}
|
|
}
|
|
}
|
|
|
|
# Ralf Hettinger: reload $email_to
|
|
# with $globalMarkerArray['###EMAIL_TO###'],
|
|
# which gives the possibility to modify this by hook
|
|
$email_to = $globalMarkerArray['###EMAIL_TO###'];
|
|
|
|
# print "email_to:".$email_to.'<br />';
|
|
# send only if receiver is specified
|
|
if ($email_to) {
|
|
|
|
# Ralf Hettinger: $conf['emailHeader'] may be overloaded by
|
|
# $globalMarkerArray['###overload_email_header###'],
|
|
# which gives the possibility to modify this by hook
|
|
$conf['emailHeader'] = ($globalMarkerArray['###overload_email_header###'])?
|
|
$globalMarkerArray['###overload_email_header###']:
|
|
$conf['emailHeader'];
|
|
|
|
# additional header
|
|
# if no character set is specified, take default typo3 character set
|
|
$conf['emailHeader'] = str_replace('\r', "\r", str_replace('\n', "\n", $conf['emailHeader']));
|
|
if (!strstr($conf['emailHeader'], 'charset') && !strstr($conf['emailHeader'], 'content-type')) {
|
|
$charset = 'iso-8859-1';
|
|
if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) {
|
|
$charset = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];
|
|
}
|
|
$conf['emailHeader'] .= 'Content-Type: text/plain; charset='.$charset."\n";
|
|
}
|
|
|
|
# if no special TEMPLATE for the email to the mailformplus receiver is specified
|
|
# send mail with [fieldname]: [value]
|
|
|
|
###############################################
|
|
# Changes made by Reinhard <rf(at)typoheads.at>
|
|
###############################################
|
|
# Modify if-statement, so that default mail is only
|
|
# generated, if no plaintext AND no html template
|
|
# are found.
|
|
# Thanks to David Lanier <david(at)davidlanier.com> for the
|
|
# tip.
|
|
###############################################
|
|
# Old version:
|
|
###############################################
|
|
# if (!$this->templateCode_receiver_PlainText) {
|
|
###############################################
|
|
# New version:
|
|
###############################################
|
|
if (!$this->templateCode_receiver_PlainText && !$this->templateCode_receiver_Html) {
|
|
###############################################
|
|
|
|
if (is_array($this->get_post)) {
|
|
foreach($this->get_post as $k=>$v) {
|
|
# don't show hidden config values in email'
|
|
if (!ereg('EMAIL_.',$k) && $k!='id' && $k!='x' && $k!='y') {
|
|
if(is_array($v)) {
|
|
$v = implode(',',$v);
|
|
}
|
|
if(get_magic_quotes_gpc()) {
|
|
$v = stripslashes($this->reverse_htmlspecialchars($v));
|
|
} else {
|
|
$v = $this->reverse_htmlspecialchars($v);
|
|
}
|
|
$mail_text .= "$k: $v\n";
|
|
}
|
|
}
|
|
}
|
|
$mail_text .= $email_text_uploads;
|
|
} else {
|
|
|
|
/*
|
|
* Inserted/Modified by: Andreas Westermaier <aw(at)overturn.de>
|
|
* Distinction between Plaintext an HTML eMails.
|
|
*/
|
|
|
|
# plaintext
|
|
if (is_array($plainReceiverMarkerArray)) {
|
|
$markerArray = t3lib_div::array_merge($globalMarkerArray, $plainReceiverMarkerArray);
|
|
} else {
|
|
$markerArray = $globalMarkerArray;
|
|
}
|
|
|
|
$this->templateCode_receiver_PlainText = $this->substituteTSMarkersTempl($this->templateCode_receiver_PlainText,$conf,0);
|
|
$this->templateCode_receiver_PlainText = $this->substituteIssetSubparts($this->templateCode_receiver_PlainText,$markerArray);
|
|
$this->templateCode_receiver_PlainText = $this->cObj->substituteMarkerArray($this->templateCode_receiver_PlainText, $markerArray);
|
|
$langMarkers = $this->substituteLangMarkers($this->templateCode_receiver_PlainText);
|
|
#####################
|
|
# Changed by Reinhard
|
|
#####################
|
|
# 3rd param has to be an array! Thx to Steffen Kamper <info(at)sk-typo3.de>
|
|
#####################
|
|
$this->templateCode_receiver_PlainText = $this->cObj->substituteMarkerArrayCached($this->templateCode_receiver_PlainText, $langMarkers, array());
|
|
|
|
$this->templateCode_receiver_PlainText = $this->removeUnsetMarkers($this->templateCode_receiver_PlainText);
|
|
$mail_text = $this->templateCode_receiver_PlainText;
|
|
|
|
# HTML mail
|
|
if (is_array($htmlReceiverMarkerArray)) {
|
|
$markerArray = t3lib_div::array_merge($globalMarkerArray, $htmlReceiverMarkerArray);
|
|
} else {
|
|
$markerArray = $globalMarkerArray;
|
|
}
|
|
|
|
######################################
|
|
# Changes made by Reinhard #
|
|
######################################
|
|
# Substitute x'0a' with <br /> and #
|
|
# delete \\ in the markers the user #
|
|
# entered in typoscript. #
|
|
######################################
|
|
# thanks to Kurt Kunig for the patch #
|
|
# (<kurt.kunig(at)gmx.de>) #
|
|
######################################
|
|
$checkBinaryCrLf = $this->conf['checkBinaryCrLf'];
|
|
if ($checkBinaryCrLf != '') {
|
|
$markersToCheck = t3lib_div::trimexplode(',',$checkBinaryCrLf);
|
|
foreach($markersToCheck as $idx=>$val) {
|
|
if(substr($val,0,3) != '###') {
|
|
$val = '###'.$markersToCheck[$idx];
|
|
}
|
|
|
|
if(substr($val,-3) != '###') {
|
|
$val .= '###';
|
|
}
|
|
$iStr = $markerArray[$val];
|
|
$iStr = str_replace (chr(13),'<br />', $iStr);
|
|
$iStr = str_replace ('\\','', $iStr);
|
|
$markerArray[$val] = $iStr;
|
|
|
|
}
|
|
}
|
|
foreach($markerArray as $field=>$value) {
|
|
$markerArray[$field] = nl2br($value);
|
|
}
|
|
$this->templateCode_receiver_Html = $this->substituteTSMarkersTempl($this->templateCode_receiver_Html,$conf,0);
|
|
$this->templateCode_receiver_Html = $this->substituteIssetSubparts($this->templateCode_receiver_Html,$markerArray);
|
|
$this->templateCode_receiver_Html = $this->cObj->substituteMarkerArray($this->templateCode_receiver_Html, $markerArray);
|
|
$langMarkers = $this->substituteLangMarkers($this->templateCode_receiver_Html);
|
|
#####################
|
|
# Changed by Reinhard
|
|
#####################
|
|
# 3rd param has to be an array! Thx to Steffen Kamper <info(at)sk-typo3.de>
|
|
#####################
|
|
$this->templateCode_receiver_Html = $this->cObj->substituteMarkerArrayCached($this->templateCode_receiver_Html, $langMarkers, array());
|
|
$this->templateCode_receiver_Html = $this->removeUnsetMarkers($this->templateCode_receiver_Html);
|
|
$html_mail_text = $this->templateCode_receiver_Html;
|
|
|
|
// -------------------------------------------------
|
|
}
|
|
|
|
# send mail
|
|
$emailto = split(',', $email_to);
|
|
if (is_array($emailto)) {
|
|
|
|
# Ralf Hettinger: overload $mail_sender with
|
|
# $globalMarkerArray['###overload_email_sender###']
|
|
# if set and valid, which gives the possibility to modify this by hook
|
|
if ($globalMarkerArray['###overload_email_sender###'] && (strstr($globalMarkerArray['###overload_email_sender###'], '@') && !eregi("\r",$globalMarkerArray['###overload_email_sender###']) && !eregi("\n",$globalMarkerArray['###overload_email_sender###']))) {
|
|
$email_sender = $globalMarkerArray['###overload_email_sender###'];
|
|
}
|
|
|
|
# Ralf Hettinger: overload fifth parameter for mail with
|
|
# $globalMarkerArray['###overload_email_fifth_parameter###']
|
|
# if set, which gives the possibility to modify this by hook
|
|
if ($globalMarkerArray['###overload_email_fifth_parameter###']) {
|
|
$conf['emailParameter'] = $globalMarkerArray['###overload_email_fifth_parameter###'];
|
|
}
|
|
|
|
# Ralf Hettinger: overload subject for mail with
|
|
# $globalMarkerArray['###overload_email_subject###'] if set
|
|
# if set, which gives the possibility to modify this by hook
|
|
if ($globalMarkerArray['###overload_email_subject###']) {
|
|
$email_subject = $globalMarkerArray['###overload_email_subject###'];
|
|
}
|
|
|
|
# inserted by Reinhard
|
|
# configure attachment path or form field for attachment
|
|
if($this->conf['default.']['email_attachment'] != "") {
|
|
$fields = t3lib_div::trimExplode(',',$this->conf['default.']['email_attachment']);
|
|
$attachment = array();
|
|
foreach($fields as $field) {
|
|
if ($this->get_post[$field]) {
|
|
$files = explode('\n',$this->uploadedFiles[$field]);
|
|
foreach($files as $file) {
|
|
$attachment[] = $file;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Inserted by: Andreas Westermaier <aw(at)overturn.de>
|
|
* Replaces proprietary mail function with t3lib_htmlmail
|
|
*/
|
|
if($this->get_post[$email_subject]) {
|
|
$email_subject = $this->get_post[$email_subject];
|
|
}
|
|
if($this->get_post[$email_sender]) {
|
|
$email_sender = $this->get_post[$email_sender];
|
|
}
|
|
require_once(PATH_t3lib.'class.t3lib_htmlmail.php');
|
|
$emailObj = t3lib_div::makeInstance('t3lib_htmlmail');
|
|
$emailObj->start();
|
|
$emailObj->subject = $email_subject;
|
|
$emailObj->from_email = $email_sender;
|
|
$emailObj->from_name = '';
|
|
$emailObj->replyto_email = $email_replyto;
|
|
$emailObj->replyto_name = '';
|
|
$emailObj->returnPath = $email_replyto;
|
|
$emailObj->add_header($conf['emailHeader']);
|
|
if(is_array($attachment) && !empty($attachment)) {
|
|
foreach($attachment as $file) {
|
|
if($file != "") {
|
|
$emailObj->addAttachment($file);
|
|
}
|
|
}
|
|
}
|
|
if ($mail_text) {
|
|
|
|
###############################################
|
|
# Changes made by Reinhard <rf(at)typoheads.at>
|
|
###############################################
|
|
# Solving problems with encoding.
|
|
# Thanks to Stefan Fetsch <sfetsch(at)wollert-it.com
|
|
# for bug report.
|
|
###############################################
|
|
# Old version:
|
|
###############################################
|
|
# $emailObj->addPlain($mail_text);
|
|
###############################################
|
|
# New version:
|
|
###############################################
|
|
######################################
|
|
# removed because of "Umlaute" problem in function "quoted_printable"
|
|
# comment in t3lib_htmlmail:
|
|
# // This functions is buggy. It seems that in the part where the lines are breaked every 76th character, that it fails if the break happens right in a quoted_printable encode character!
|
|
# removed: $emailObj->addPlain($emailObj->encodeMsg($mail_text));
|
|
#######################################
|
|
$emailObj->addPlain($mail_text);
|
|
###############################################
|
|
}
|
|
if ($html_mail_text) {
|
|
################################
|
|
# begin changes made by Claudio
|
|
#
|
|
# If required, handle the HTML output
|
|
# as an attachment instead of as
|
|
# an alternative to plain text
|
|
################################
|
|
if ($email_html_as_attachment) {
|
|
$tmphtml=tempnam("typo3temp/","/mailformplus_").".html";
|
|
$tmphandle=fopen($tmphtml,"wb");
|
|
if ($tmphandle) {
|
|
fwrite($tmphandle,$html_mail_text);
|
|
fclose($tmphandle);
|
|
$emailObj->addAttachment($tmphtml);
|
|
}
|
|
} else {
|
|
$emailObj->setHTML($emailObj->encodeMsg($html_mail_text));
|
|
}
|
|
################################
|
|
# end changes made by Claudio
|
|
################################
|
|
#$emailObj->setHTML($emailObj->encodeMsg($html_mail_text));
|
|
}
|
|
$sent = 0;
|
|
foreach ($emailto as $mailto) {
|
|
if(isset($this->get_post[$mailto])) {
|
|
$mailto = $this->get_post[$mailto];
|
|
}
|
|
# since 18.10.2005: prevent mail injection (reported by Joerg Schoppet - thx!)
|
|
# subject and email_header are checked for mail injection as well before
|
|
if (strstr($mailto, '@') && !eregi("\r",$mailto) && !eregi("\n",$mailto)) {
|
|
$sent = $emailObj->send($mailto);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($this->debug == 1) {
|
|
if ($sent) {
|
|
print "receiver email was sent: <br>\n---------------<br>\n";
|
|
} else {
|
|
print "receiver email was NOT sent: <br>\n---------------<br>\n";
|
|
}
|
|
#print "EMAIL attachment: ".$attachment."<br>\n";
|
|
print "EMAIL sender: ".$email_sender."<br>\n";
|
|
print "EMAIL receiver: ".$email_to."<br>\n";
|
|
print "EMAIL subject: ".$email_subject."<br>\n";
|
|
print "EMAIL replyto: ".$email_replyto."<br>\n";
|
|
print "EMAIL plain-text: ".$mail_text."<br>\n";
|
|
print "EMAIL HTML-text: ".$html_mail_text."<br>\n";
|
|
#print "EMAIL header: ".$email_header."<br>\n";
|
|
print "EMAIL header: ".$conf['emailHeader']."<br>\n";
|
|
print "EMAIL parameters: ".$conf['emailParameter']."<br>\n------------------<br>\n";
|
|
}
|
|
|
|
}
|
|
|
|
# if an email should be sent to the user as well:
|
|
if ($this->get_post[$this->getFieldContent("email_sendtouser")] && (strstr($this->get_post[$this->getFieldContent("email_sendtouser")], '@'))) {
|
|
# special ###TEMPLATE_EMAIL_USER### specified: replace placeholders
|
|
|
|
/*
|
|
* Inserted/Modified by: Andreas Westermaier <aw(at)overturn.de>
|
|
* Distinction between PlainText and HTML eMails
|
|
*/
|
|
if ($this->templateCode_useremail_PlainText) {
|
|
|
|
# plaintextprint
|
|
if (is_array($plainUserMarkerArray)) {
|
|
$markerArray = t3lib_div::array_merge($globalMarkerArray, $plainUserMarkerArray);
|
|
} else {
|
|
$markerArray = $globalMarkerArray;
|
|
}
|
|
$this->templateCode_useremail_PlainText = $this->substituteTSMarkersTempl($this->templateCode_useremail_PlainText,$conf,0);
|
|
$this->templateCode_useremail_PlainText = $this->substituteIssetSubparts($this->templateCode_useremail_PlainText,$markerArray);
|
|
$this->templateCode_useremail_PlainText = $this->cObj->substituteMarkerArray($this->templateCode_useremail_PlainText, $markerArray);
|
|
$langMarkers = $this->substituteLangMarkers($this->templateCode_useremail_PlainText);
|
|
#####################
|
|
# Changed by Reinhard
|
|
#####################
|
|
# 3rd param has to be an array! Thx to Steffen Kamper <info(at)sk-typo3.de>
|
|
#####################
|
|
$this->templateCode_useremail_PlainText = $this->cObj->substituteMarkerArrayCached($this->templateCode_useremail_PlainText, $langMarkers, array());
|
|
$this->templateCode_useremail_PlainText = $this->removeUnsetMarkers($this->templateCode_useremail_PlainText);
|
|
|
|
$mail_text = $this->templateCode_useremail_PlainText;
|
|
}
|
|
|
|
if ($this->templateCode_useremail_Html) {
|
|
|
|
# HTML
|
|
if (is_array($htmlUserMarkerArray)) {
|
|
$markerArray = t3lib_div::array_merge($globalMarkerArray, $htmlUserMarkerArray);
|
|
} else {
|
|
$markerArray = $globalMarkerArray;
|
|
}
|
|
|
|
######################################
|
|
# Changes made by Reinhard #
|
|
######################################
|
|
# Substitute x'0a' with <br /> and #
|
|
# delete \\ in the markers the user #
|
|
# entered in typoscript. #
|
|
######################################
|
|
# thanks to Kurt Kunig for the patch #
|
|
# (<kurt.kunig(at)gmx.de>) #
|
|
######################################
|
|
$checkBinaryCrLf = $this->conf['checkBinaryCrLf'];
|
|
if ($checkBinaryCrLf != '') {
|
|
$markersToCheck = t3lib_div::trimexplode(',',$checkBinaryCrLf);
|
|
foreach($markersToCheck as $idx=>$val) {
|
|
if(substr($val,0,3) != '###') {
|
|
$val = '###'.$markersToCheck[$idx];
|
|
}
|
|
|
|
if(substr($val,-3) != '###') {
|
|
$val .= '###';
|
|
}
|
|
$iStr = $markerArray[$val];
|
|
$iStr = str_replace (chr(13),'<br />', $iStr);
|
|
$iStr = str_replace ('\\','', $iStr);
|
|
$markerArray[$val] = $iStr;
|
|
|
|
}
|
|
}
|
|
foreach($markerArray as $field=>$value) {
|
|
$markerArray[$field] = nl2br($value);
|
|
}
|
|
$this->templateCode_useremail_Html = $this->substituteTSMarkersTempl($this->templateCode_useremail_Html,$conf,0);
|
|
$this->templateCode_useremail_Html = $this->substituteIssetSubparts($this->templateCode_useremail_Html,$markerArray);
|
|
$this->templateCode_useremail_Html = $this->cObj->substituteMarkerArray($this->templateCode_useremail_Html, $markerArray);
|
|
$langMarkers = $this->substituteLangMarkers($this->templateCode_useremail_Html);
|
|
#####################
|
|
# Changed by Reinhard
|
|
#####################
|
|
# 3rd param has to be an array! Thx to Steffen Kamper <info(at)sk-typo3.de>
|
|
#####################
|
|
$this->templateCode_useremail_Html = $this->cObj->substituteMarkerArrayCached($this->templateCode_useremail_Html, $langMarkers, array());
|
|
$this->templateCode_useremail_Html = $this->removeUnsetMarkers($this->templateCode_useremail_Html);
|
|
$html_mail_text = $this->templateCode_useremail_Html;
|
|
}
|
|
// -------------------------------------------------
|
|
|
|
# Ralf Hettinger: overload $mail_sender with
|
|
# $globalMarkerArray['###overload_useremail_sender###']
|
|
# if set and valid, which gives the possibility to modify this by hook
|
|
if ($globalMarkerArray['###overload_useremail_sender###'] && (strstr($globalMarkerArray['###overload_useremail_sender###'], '@') && !eregi("\r",$globalMarkerArray['###overload_useremail_sender###']) && !eregi("\n",$globalMarkerArray['###overload_useremail_sender###']))) {
|
|
$email_sender = $globalMarkerArray['###overload_useremail_sender###'];
|
|
}
|
|
|
|
# Ralf Hettinger: overload fifth parameter for mail with
|
|
# $globalMarkerArray['###overload_email_fifth_parameter###']
|
|
# if set, which gives the possibility to modify this by hook
|
|
if ($globalMarkerArray['###overload_useremail_fifth_parameter###']) {
|
|
$conf['emailParameter'] = $globalMarkerArray['###overload_useremail_fifth_parameter###'];
|
|
}
|
|
|
|
|
|
# Ralf Hettinger: overload subject for mail with
|
|
# $globalMarkerArray['###overload_useremail_subject###']
|
|
# if set, which gives the possibility to modify this by hook
|
|
if ($globalMarkerArray['###overload_useremail_subject###']) {
|
|
$email_subject = $globalMarkerArray['###overload_useremail_subject###'];
|
|
}
|
|
|
|
# Ralf Hettinger: overload header with
|
|
# $globalMarkerArray['###overload_useremail_header###']
|
|
# if set, which gives the possibility to modify this by hook
|
|
$conf['emailHeader'] = ($globalMarkerArray['###overload_useremail_header###'])?
|
|
$globalMarkerArray['###overload_useremail_header###']:
|
|
$conf['emailHeader'];
|
|
|
|
$subject = $this->getFieldContent("email_subject_user");
|
|
if (eregi("\r",$subject) || eregi("\n",$subject)) {
|
|
$subject = '';
|
|
}
|
|
|
|
######################################
|
|
# send mail
|
|
# for security reasons limitted to 2 emails (who needs more?)
|
|
#######################################
|
|
$count = 0;
|
|
$maxCount = 2;
|
|
|
|
# limitMailsToUser defined in TS (tx_thmailformplus_pi1.limitMailsToUser = [integer])
|
|
if ($conf['limitMailsToUser'] && t3lib_div::testInt($conf['limitMailsToUser'])) {
|
|
$maxCount = $conf['limitMailsToUser'];
|
|
}
|
|
$emailto = split(',', $this->get_post[$this->getFieldContent("email_sendtouser")]);
|
|
if($this->get_post[$subject]) {
|
|
$subject = $this->get_post[$subject];
|
|
}
|
|
if (is_array($emailto)) {
|
|
|
|
/*
|
|
* Inserted by: Andreas Westermaier <aw(at)overturn.de>
|
|
* Replaces proprietary mail function with t3lib_htmlmail
|
|
*/
|
|
require_once(PATH_t3lib.'class.t3lib_htmlmail.php');
|
|
$emailObj = t3lib_div::makeInstance('t3lib_htmlmail');
|
|
$emailObj->start();
|
|
$emailObj->subject = $subject;
|
|
$emailObj->from_email = $email_sender;
|
|
$emailObj->from_name = '';
|
|
$emailObj->replyto_email = $email_sender;
|
|
$emailObj->replyto_name = '';
|
|
$emailObj->returnPath = '';
|
|
$emailObj->add_header($conf['emailHeader']);
|
|
if ($mail_text) {
|
|
|
|
|
|
######################################
|
|
# removed because of "Umlaute" problem in function "quoted_printable"
|
|
# comment in t3lib_htmlmail:
|
|
# // This functions is buggy. It seems that in the part where the lines are breaked every 76th character, that it fails if the break happens right in a quoted_printable encode character!
|
|
# removed: $emailObj->addPlain($emailObj->encodeMsg($mail_text));
|
|
#######################################
|
|
$emailObj->addPlain($mail_text);
|
|
}
|
|
if ($html_mail_text) {
|
|
################################
|
|
# begin changes made by Claudio
|
|
#
|
|
# If required, handle the HTML output
|
|
# as an attachment instead of as
|
|
# an alternative to plain text
|
|
################################
|
|
if ($email_html_as_attachment) {
|
|
$tmphtml=tempnam("typo3temp/","/mailformplus_").".html";
|
|
$tmphandle=fopen($tmphtml,"wb");
|
|
if ($tmphandle) {
|
|
fwrite($tmphandle,$html_mail_text);
|
|
fclose($tmphandle);
|
|
$emailObj->addAttachment($tmphtml);
|
|
}
|
|
} else {
|
|
$emailObj->setHTML($emailObj->encodeMsg($html_mail_text));
|
|
}
|
|
################################
|
|
# end changes made by Claudio
|
|
################################
|
|
}
|
|
$sent = 0;
|
|
foreach ($emailto as $mailto) {
|
|
$count++;
|
|
|
|
################################
|
|
# begin changes made by Claudio
|
|
#
|
|
# Here a patch by Reinhard F?hricht was
|
|
# added, that makes you able to add a
|
|
# comma separated list of fieldnames
|
|
# as email_to.
|
|
################################
|
|
if(isset($this->get_post[$mailto])) {
|
|
$mailto = $this->get_post[$mailto];
|
|
}
|
|
################################
|
|
# end changes made by Claudio
|
|
################################
|
|
|
|
# since 18.10.2005: prevent mail injection (reported by Joerg Schoppet - thx!)
|
|
# subject and email_header are checked for mail injection as well before
|
|
if (strstr($mailto, '@') && !eregi("\r",$mailto) && !eregi("\n",$mailto) && $count <= $maxCount) {
|
|
$sent = $emailObj->send($mailto);
|
|
}
|
|
}
|
|
|
|
if ($this->debug == 1) {
|
|
if ($sent) {
|
|
print "user email was sent: <br>\n---------------<br>\n";
|
|
} else {
|
|
print "user email was NOT sent: <br>\n---------------<br>\n";
|
|
}
|
|
print "EMAIL receiver: ".$this->get_post[$this->getFieldContent("email_sendtouser")]."<br>\n";
|
|
print "EMAIL subject: ".$subject."<br>\n";
|
|
print "EMAIL replyto: ".$email_replyto."<br>\n";
|
|
print "EMAIL plain-text: ".$mail_text."<br>\n";
|
|
print "EMAIL HTML-text: ".$html_mail_text."<br>\n";
|
|
print "EMAIL header: ".$email_header."<br>\n";
|
|
print "EMAIL parameters: ".$conf['emailParameter']."<br>\n------------------<br>\n";
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
# if a print-subtemplate exists:
|
|
# replace the markers and store it in SESSION variable
|
|
if ($this->templateCode_printversion) {
|
|
$id = $GLOBALS["TSFE"]->id;
|
|
if ($email_redirect) {
|
|
$id = $email_redirect;
|
|
}
|
|
if (is_array($printMarkerArray)) {
|
|
$markerArray = t3lib_div::array_merge($globalMarkerArray, $printMarkerArray);
|
|
} else {
|
|
$markerArray = $globalMarkerArray;
|
|
}
|
|
$printversion = $this->cObj->substituteMarkerArray($this->templateCode_printversion, $markerArray);
|
|
$printversion = $this->substituteTSMarkersTempl($printversion,$conf);
|
|
$printversion = $this->removeUnsetMarkers($printversion);
|
|
$GLOBALS["TSFE"]->fe_user->setKey("ses","th_mailformplus".$id, $printversion);
|
|
$GLOBALS["TSFE"]->fe_user->storeSessionData();
|
|
}
|
|
|
|
########################################
|
|
# Changed by Reinhard
|
|
########################################
|
|
# Fixed usage of redirects for users having realUrl enabled using config.baseURL instead of config.absRefPrefix .
|
|
# Thx to Benjamin Mack <benni(at)typo3.org>
|
|
if ($email_redirect) {
|
|
$this->redirectUrl($email_redirect);
|
|
}
|
|
###
|
|
# use all markers in ###TEMPLATE_SUBMITTED_OK### too
|
|
###
|
|
######################################
|
|
# Changes made by Reinhard #
|
|
######################################
|
|
# Substitute x'0a' with <br /> and #
|
|
# delete \\ in the markers the user #
|
|
# entered in typoscript. #
|
|
######################################
|
|
# thanks to Kurt Kunig for the patch #
|
|
# (<kurt.kunig(at)gmx.de>) #
|
|
######################################
|
|
|
|
|
|
$globalMarkerArray = $this->substituteTSMarkers($globalMarkerArray,$conf);
|
|
#$globalMarkerArray = $this->sanitizeValues($globalMarkerArray);
|
|
$this->templateCode = $this->cObj->substituteMarkerArray($this->templateCode, $globalMarkerArray);
|
|
$langMarkers = $this->substituteLangMarkers($this->templateCode);
|
|
$this->templateCode = $this->cObj->substituteMarkerArray($this->templateCode, $langMarkers);
|
|
$this->templateCode = $this->substituteTSMarkersTempl($this->templateCode, $this->conf);
|
|
$this->templateCode = $this->substituteIssetSubparts($this->templateCode,$globalMarkerArray);
|
|
$this->templateCode = $this->removeUnsetMarkers($this->templateCode);
|
|
$iStr = $this->templateCode;
|
|
$iStr = str_replace (chr(13),'<br />', $iStr);
|
|
$iStr = str_replace ('\\','', $iStr);
|
|
$this->templateCode = $iStr;
|
|
}
|
|
|
|
/**
|
|
* does a redirect to a URL specified in the parameter and exits the request
|
|
*
|
|
* @param mixed the URL to redirect to, if this is a numeric, it's supposed to be a
|
|
* page ID, we should substitute this process at some point with the typoLink function
|
|
* @return void
|
|
*/
|
|
function redirectUrl($url) {
|
|
|
|
if (is_numeric($url)) {
|
|
// these parameters have to be added to the redirect url
|
|
$addParams = array();
|
|
if (t3lib_div::_GP('L')) {
|
|
$addParams['L'] = t3lib_div::_GP('L');
|
|
}
|
|
|
|
$url = $this->pi_getPageLink($url, '', $addParams);
|
|
}
|
|
if ($this->conf['correctRedirectUrl']) {
|
|
$url = str_replace('&', '&', $url);
|
|
}
|
|
header('Location: ' . t3lib_div::locationHeaderUrl($url));
|
|
exit();
|
|
}
|
|
|
|
function removeUnsetMarkers($templateCode) {
|
|
|
|
$return = ereg_replace('#{3}[^#]+#{3}', '', $templateCode);
|
|
return $return;
|
|
}
|
|
|
|
/**
|
|
* check submissions for validity
|
|
*
|
|
* @param string $content
|
|
* @param array $conf copy of TS conf of main instance
|
|
*
|
|
* @return string $error error message(s)
|
|
*/
|
|
function check_form($content,$conf) {
|
|
t3lib_div::loadTCA('tx_thmailformplus_main');
|
|
$config = $GLOBALS['TCA']['tx_thmailformplus_main'];
|
|
|
|
###############################
|
|
# add uploaded files to array otherwise the error check might do something wrong
|
|
###############################
|
|
session_start();
|
|
if (is_array($_SESSION['mp_uploadedFiles'])) {
|
|
foreach ($_SESSION['mp_uploadedFiles'] as $fieldname => $files) {
|
|
if (is_array($files)) {
|
|
foreach ($files as $file) {
|
|
if (!$this->get_post[$fieldname]) {
|
|
$this->get_post[$fieldname] = $file['name'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
############################
|
|
# captcha check
|
|
############################
|
|
# is captcha configured to be used:
|
|
if ($this->conf['captchaFieldname']) {
|
|
|
|
# get captcha sting
|
|
session_start();
|
|
$captchaStr = $_SESSION['tx_captcha_string'];
|
|
$_SESSION['tx_captcha_string'] = '';
|
|
if ($captchaStr != $this->get_post[$this->conf['captchaFieldname']]) {
|
|
$temp = $GLOBALS["TSFE"]->cObj->getSubpart($this->templateCode_error, 'ERROR_'.$this->conf['captchaFieldname']);
|
|
|
|
##############################
|
|
# changes made by Reinhard
|
|
##############################
|
|
# Patch by John Angel
|
|
##############################
|
|
# Define Subpart ERROR_*
|
|
# for universal error texts
|
|
##############################
|
|
if(!$temp) {
|
|
$temp = $GLOBALS["TSFE"]->cObj->getSubpart($this->templateCode_error, 'ERROR_*');
|
|
}
|
|
##############################
|
|
if (trim($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'."error_".$this->conf['captchaFieldname'])) && !$temp) {
|
|
$temp .= trim($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'."error_".$this->conf['captchaFieldname']));
|
|
}
|
|
if ($temp) {
|
|
$error .= $temp;
|
|
$this->errors['###error_'.$this->conf['captchaFieldname'].'###'] = $temp;
|
|
} else {
|
|
$error .= "<li>".ucfirst($this->conf['captchaFieldname'])."</li>";
|
|
}
|
|
}
|
|
}
|
|
|
|
############################
|
|
# captcha check using sr_freecap
|
|
############################
|
|
# is freecap configured to be used:
|
|
if ($this->conf['freecapFieldname']) {
|
|
# get captcha sting
|
|
//session_start();
|
|
#print $this->conf['freecapFieldname'];
|
|
#print $this->get_post[$this->conf['freecapFieldname']];
|
|
#print $this->freeCap->checkWord($this->get_post[$this->conf['freecapFieldname']]);
|
|
if (is_object($this->freeCap) && !$this->freeCap->checkWord($this->get_post[$this->conf['freecapFieldname']])) {
|
|
$temp = $GLOBALS["TSFE"]->cObj->getSubpart($this->templateCode_error, 'ERROR_'.$this->conf['freecapFieldname']);
|
|
|
|
##############################
|
|
# changes made by Reinhard
|
|
##############################
|
|
# Patch by John Angel
|
|
##############################
|
|
# Define Subpart ERROR_*
|
|
# for universal error texts
|
|
##############################
|
|
if(!$temp) {
|
|
$temp = $GLOBALS["TSFE"]->cObj->getSubpart($this->templateCode_error, 'ERROR_*');
|
|
}
|
|
##############################
|
|
if (trim($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'."error_".$this->conf['freecapFieldname'])) && !$temp) {
|
|
$temp .= trim($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'."error_".$this->conf['freecapFieldname']));
|
|
}
|
|
if ($temp) {
|
|
$error .= $temp;
|
|
$this->errors['###error_'.$this->conf['freecapFieldname'].'###'] = $temp;
|
|
} else {
|
|
$error .= "<li>".ucfirst($this->conf['freecapFieldname'])."</li>";
|
|
}
|
|
}
|
|
}
|
|
|
|
############################
|
|
# captcha check for recaptcha
|
|
############################
|
|
# is recaptcha configured to be used:
|
|
if ($this->conf['useRecaptcha']) {
|
|
$p = t3lib_div::GPvar($this->prefixId);
|
|
#if (array_key_exists('submitted', $p)) {
|
|
$status = $this->recaptcha->validateReCaptcha();
|
|
#}
|
|
if (!$status['verified']) {
|
|
$temp = $GLOBALS["TSFE"]->cObj->getSubpart($this->templateCode_error, 'ERROR_'.$this->conf['recaptchaFieldname']);
|
|
|
|
##############################
|
|
# changes made by Reinhard
|
|
##############################
|
|
# Patch by John Angel
|
|
##############################
|
|
# Define Subpart ERROR_*
|
|
# for universal error texts
|
|
##############################
|
|
if(!$temp) {
|
|
$temp = $GLOBALS["TSFE"]->cObj->getSubpart($this->templateCode_error, 'ERROR_*');
|
|
}
|
|
##############################
|
|
if (trim($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'."error_".$this->conf['recaptchaFieldname'])) && !$temp) {
|
|
$temp .= trim($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'."error_".$this->conf['recaptchaFieldname']));
|
|
}
|
|
if ($temp) {
|
|
$error .= $temp;
|
|
$this->errors['###error_'.$this->conf['recaptchaFieldname'].'###'] = $temp;
|
|
} else {
|
|
$error .= "<li>".ucfirst($this->conf['recaptchaFieldname'])."</li>";
|
|
}
|
|
}
|
|
}
|
|
################################
|
|
# file uploads
|
|
################################
|
|
if (is_array($_FILES) && sizeof($_FILES) > 0) {
|
|
session_start();
|
|
$uploadedFiles = $_SESSION['mp_uploadedFiles'];
|
|
|
|
# collect all uploaded files so that we can check if this file has already been uploaded
|
|
$alreadyUploadedFiles = array();
|
|
if (is_array($uploadedFiles)) {
|
|
foreach ($uploadedFiles as $fieldname => $files) {
|
|
if (is_array($files)) {
|
|
foreach ($files as $file) {
|
|
$alreadyUploadedFiles[$fieldname][$file['name']] = $file;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
foreach (array_keys($_FILES) as $file) {
|
|
|
|
###########################
|
|
# error check
|
|
###########################
|
|
$fileError = '';
|
|
|
|
###########################
|
|
# bugfix (thx to Michael Wagner)
|
|
###########################
|
|
# allow file upload of files
|
|
# having . in filename
|
|
###########################
|
|
# example: datei.1.pdf was
|
|
# not possible before
|
|
###########################
|
|
$type = substr($_FILES[$file]['name'], strrpos($_FILES[$file]['name'], '.') + 1);
|
|
# find out file type
|
|
list(,$type)= explode('.', $_FILES[$file]['name']);
|
|
|
|
###########################
|
|
# fix by reinhard
|
|
# checking file type using the mime type too
|
|
###########################
|
|
# getting string like: image/png
|
|
###########################
|
|
#$mime_type = $_FILES[$file]['type'];
|
|
#print $mime_type;
|
|
#list(,$file_format) = explode('/',$mime_type);
|
|
#print $file_format;
|
|
|
|
###################
|
|
# filetypes
|
|
###################
|
|
# default setting for allowed Filetypes (saveDB.fileTypes)
|
|
$allowedTypes = $this->conf['saveDB']['allowedTypes'];
|
|
|
|
# allowed filetypes for this specific field defined (fieldConf.[name of inputfield].fileTypes)
|
|
if ($this->conf['fieldConf'][$file.'.']['fileTypes']) {
|
|
$allowedTypes = explode(",", $this->conf['fieldConf'][$file.'.']['fileTypes']);
|
|
}
|
|
if(count($allowedTypes) == 0) {
|
|
$allowedTypes = array(
|
|
'jpg',
|
|
'jpeg',
|
|
'gif',
|
|
'png',
|
|
'doc',
|
|
'xls',
|
|
'ppt',
|
|
'pdf'
|
|
);
|
|
}
|
|
|
|
###################
|
|
# filesize
|
|
###################
|
|
# default setting for allowed FileSize (saveDB.fileSize)
|
|
$allowedSize = $this->conf['saveDB']['allowedSize'];
|
|
|
|
# allowed filesize for this specific field defined (fieldConf.[name of inputfield].fileSize)
|
|
if ($this->conf['fieldConf'][$file.'.']['fileSize']) {
|
|
$allowedSize = $this->conf['fieldConf'][$file.'.']['fileSize'];
|
|
}
|
|
|
|
###################
|
|
# upload folder
|
|
###################
|
|
# default setting for upload folder (saveDB.uploadfolder)
|
|
$uploadFolder = $this->conf['saveDB']['uploadfolder'];
|
|
if (!$uploadFolder) {
|
|
$uploadFolder = 'uploads/tx_thmailformplus/';
|
|
}
|
|
|
|
# uploadfolder for this specific field defined (fieldConf.[name of inputfield].fileUpload)
|
|
if ($this->conf['fieldConf'][$file.'.']['fileUpload']) {
|
|
$uploadFolder = $this->conf['fieldConf'][$file.'.']['fileUpload'];
|
|
}
|
|
|
|
####################
|
|
# uploadfolder does not exist...
|
|
####################
|
|
if ($uploadFolder && !is_dir($uploadFolder)) {
|
|
t3lib_div::mkdir($uploadFolder);
|
|
if (!is_dir($uploadFolder) && $this->debug == 1) {
|
|
print "could not create upload folder: ".$uploadFolder."<br>\n";
|
|
} elseif ($this->debug == 1) {
|
|
print "upload folder created: ".$uploadFolder."<br>\n";
|
|
}
|
|
} elseif ($uploadFolder && $this->debug == 1) {
|
|
print "upload folder already exists: ".$uploadFolder."<br>\n";
|
|
}
|
|
|
|
#########################
|
|
# check allowed file types
|
|
#########################
|
|
#if (is_array($allowedTypes) && sizeof($allowedTypes) > 0 && $_FILES[$file]['name'] && !in_array($type, $allowedTypes)) {
|
|
if (is_array($allowedTypes) &&
|
|
sizeof($allowedTypes) > 0 &&
|
|
$_FILES[$file]['name'] &&
|
|
!in_array($type, $allowedTypes)
|
|
#!in_array($file_format, $allowedTypes) &&
|
|
|| preg_match('/\.php(\d)?$|\.php(\d)?\./i', $_FILES[$file]['name'])) {
|
|
|
|
$temp = $GLOBALS["TSFE"]->cObj->getSubpart($this->templateCode_error, "ERROR_FILETYPE");
|
|
if (trim($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'."error_filetype"))) {
|
|
$temp .= trim($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'."error_filetype"));
|
|
}
|
|
if ($temp) {
|
|
$fileError .= $temp;
|
|
|
|
# this marker is only set for compatibility reasons (v. <= 3.8.0)
|
|
$this->errors['###error_filetype###'] = $temp;
|
|
} else {
|
|
$fileError .= "<li>Filetype not allowed</li>";
|
|
}
|
|
if ($this->debug == 1) {
|
|
print "File '".$type."' not allowed in ".implode(',',$this->conf['saveDB']['allowedTypes'])."<br>\n";
|
|
}
|
|
}
|
|
|
|
########################
|
|
# check allowed size
|
|
########################
|
|
if ($allowedSize && ($_FILES[$file]['size'] > $allowedSize)) {
|
|
$temp = $GLOBALS["TSFE"]->cObj->getSubpart($this->templateCode_error, "ERROR_FILESIZE");
|
|
if (trim($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'."error_filesize"))) {
|
|
$temp .= trim($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'."error_filesize"));
|
|
}
|
|
if ($temp) {
|
|
$fileError .= $temp;
|
|
|
|
# this marker is only set for compatibility reasons (v. <= 3.8.0)
|
|
$this->errors['###error_filesize###'] = $temp;
|
|
} else {
|
|
$fileError .= "<li>File is too large</li>";
|
|
}
|
|
}
|
|
###########################
|
|
# used for multipage forms:
|
|
# no error found -> upload file
|
|
# and save uploaded filename in session variable
|
|
###########################
|
|
if (!$fileError) {
|
|
|
|
#####################################
|
|
# only if file size > 0
|
|
# and
|
|
# file has not been uploaded before
|
|
#####################################
|
|
|
|
#######################################
|
|
# number of allowed files that can be upload via one upload field
|
|
#######################################
|
|
# default value if nothing is defined via TS
|
|
$numberOfAllowedFiles = 1;
|
|
|
|
# default value is defined in TS (saveDB.numberOfAllowedFiles)
|
|
if ($this->conf['saveDB']['numberOfAllowedFiles']) {
|
|
$numberOfAllowedFiles = $this->conf['saveDB']['numberOfAllowedFiles'];
|
|
}
|
|
|
|
# number of allowed files is defined for this specific inputfield via TS (fieldConf.[name of inputfield].numberOfAllowedFiles)
|
|
if ($this->conf['fieldConf'][$file.'.']['numberOfAllowedFiles']) {
|
|
$numberOfAllowedFiles = $this->conf['fieldConf'][$file.'.']['numberOfAllowedFiles'];
|
|
}
|
|
##################
|
|
# Changed by Reinhard
|
|
##################
|
|
# Avoid some weird stuff with file uploads
|
|
##################
|
|
#if ($_FILES[$file]['size'] > 0 && !is_array($alreadyUploadedFiles[$file][$_FILES[$file]['name']])) {
|
|
if ($_FILES[$file]['size'] > 0 && (!is_array($alreadyUploadedFiles[$file][$_FILES[$file]['name']]) || (!file_exists($alreadyUploadedFiles[$file][$_FILES[$file]['name']])))) {
|
|
|
|
# limit uploaded/saved files to the number specified
|
|
while (sizeof($uploadedFiles[$file]) >= $numberOfAllowedFiles) {
|
|
array_shift($uploadedFiles[$file]);
|
|
}
|
|
$tempFilename = $uploadFolder.'multipagetemp_'.$_FILES[$file]['name'];
|
|
move_uploaded_file($_FILES[$file]['tmp_name'], $tempFilename);
|
|
$_FILES[$file]['uploadedFilename'] = $tempFilename;
|
|
$_FILES[$file]['filePath'] = $uploadFolder;
|
|
$uploadedFiles[$file][] = $_FILES[$file];
|
|
}
|
|
}
|
|
|
|
###########################
|
|
# error found -> add to errors
|
|
###########################
|
|
else {
|
|
$error .= $fileError;
|
|
$this->errors['###error_'.$file.'###'] = $fileError;
|
|
}
|
|
|
|
}
|
|
$_SESSION['mp_uploadedFiles'] = $uploadedFiles;
|
|
}
|
|
|
|
########################
|
|
# uploaded file should be deleted
|
|
########################
|
|
$deleteFileName = t3lib_div::_GP('mp_delete_uploaded_file');
|
|
|
|
# Ralf Hettinger: delete without JavaScript, TS configured by
|
|
# multipage_without_js = boolean (default false)
|
|
#
|
|
# if true, the filenames to delete are transfered by form names
|
|
if (!$this->multiPageJS && !$deleteFileName) {
|
|
foreach (t3lib_div::_POST() as $pname => $pvalue) {
|
|
if (substr($pname,0,37+strlen(strval($this->multipageStep)))=='th_mailformplus-mp_step-'.$this->multipageStep.'-delete_file-') {
|
|
$deleteFileName = t3lib_div::_GP (('mp_delete_uploaded_file_'.substr($pname,37+strlen(strval($this->multipageStep)))));
|
|
}
|
|
}
|
|
}
|
|
if ($deleteFileName) {
|
|
session_start();
|
|
$newUploadedFiles = array();
|
|
$count = 0;
|
|
foreach ($_SESSION['mp_uploadedFiles'] as $fieldname => $files) {
|
|
foreach($files as $file) {
|
|
if ($file['name'] != $fileName) {
|
|
$newUploadedFiles[$fieldname][] = $file;
|
|
$count++;
|
|
}
|
|
}
|
|
}
|
|
if ($count == 0) {
|
|
$_SESSION['mp_uploadedFiles'] = array();
|
|
} else {
|
|
$_SESSION['mp_uploadedFiles'] = $newUploadedFiles;
|
|
}
|
|
}
|
|
|
|
###############################
|
|
# add uploaded files to array otherwise the error check might do something wrong
|
|
###############################
|
|
if (is_array($_SESSION['mp_uploadedFiles'])) {
|
|
foreach ($_SESSION['mp_uploadedFiles'] as $fieldname => $files) {
|
|
if (is_array($files)) {
|
|
foreach ($files as $file) {
|
|
if (!$this->get_post[$fieldname]) {
|
|
$this->get_post[$fieldname] = $file['name'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
###########################################
|
|
# check all required fields
|
|
###########################################
|
|
if (strlen(trim($this->getFieldContent("email_requiredfields"))) > 0) {
|
|
$array_check = split(',', $this->getFieldContent("email_requiredfields"));
|
|
$array_check = array_map('trim', $array_check);
|
|
|
|
########################
|
|
# multipage forms:
|
|
# only check these fields that were shown on the last form-page
|
|
########################
|
|
if ($this->multipage == '1') {
|
|
$array_check = $this->getArrayCheck($array_check);
|
|
|
|
}
|
|
if (is_array($array_check)) {
|
|
foreach ($array_check as $check) {
|
|
$errorCheck = t3lib_div::trimExplode(',', $this->conf['fieldConf'][$check.'.']['errorCheck']);
|
|
if (is_array($errorCheck) && sizeof($errorCheck) > 0) {
|
|
$errorCheck = array_map('trim', $errorCheck);
|
|
}
|
|
|
|
##############################
|
|
# error if:
|
|
# - field is not filled out and
|
|
# - field is not optional
|
|
##############################
|
|
if ($this->get_post[$check] == '' && !in_array('optional', $errorCheck)) {
|
|
# fetch error message from template
|
|
$temp = $this->readCorrectTemplateCode($conf,'ERROR_'.$check,0,$this->multipageStep);
|
|
# error text defined in TS (fieldConf.[name of inputfield].errorText = fill out a correct value)
|
|
$langError = trim($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'."error_".$check));
|
|
if ($langError) {
|
|
$temp = trim($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'."error_".$check));
|
|
} elseif ($this->conf['fieldConf'][$check.'.']['errorText']) {
|
|
$temp = $this->conf['fieldConf'][$check.'.']['errorText'];
|
|
|
|
###################################################
|
|
# new patch for multilanguage error texts defined
|
|
# via typoscript
|
|
# (thx to Stano Paska <stanislav.paska(at)kios.sk>)
|
|
###################################################
|
|
|
|
if ($this->conf['fieldConf'][$check.'.']['errorText.']) {
|
|
$temp = $this->cObj->cObjGetSingle($this->conf['fieldConf'][$check.'.']['errorText'], $this->conf['fieldConf'][$check.'.']['errorText.']);
|
|
}
|
|
|
|
##############################
|
|
# changes made by Reinhard
|
|
##############################
|
|
# Patch by John Angel
|
|
##############################
|
|
# Define Subpart ERROR_*
|
|
# for universal error texts
|
|
##############################
|
|
if(!$temp) {
|
|
$temp = $GLOBALS["TSFE"]->cObj->getSubpart($this->templateCode_error, 'ERROR_*');
|
|
}
|
|
}
|
|
if ($temp) {
|
|
$error .= $temp;
|
|
$this->errors['###error_'.$check.'###'] = $temp;
|
|
} else {
|
|
$error .= "<li>".ucfirst($check)."</li>";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#######################################
|
|
# errorCheck defined in TS (.fieldConf.[name of inputfield].errorCheck = ...)
|
|
#######################################
|
|
if (is_array($this->conf['fieldConf'])) {
|
|
$temp = array_keys($this->conf['fieldConf']);
|
|
$checkFields = array();
|
|
foreach ($temp as $t) {
|
|
$checkFields[] = substr($t, 0, -1);
|
|
}
|
|
$checkFields = $this->getArrayCheck($checkFields);
|
|
$disabledFields = array();
|
|
|
|
if ($conf['disableErrorCheckFields']) {
|
|
$disabledFields = explode(',',$conf['disableErrorCheckFields']);
|
|
}
|
|
if ($this->debug == 1) {
|
|
if(!empty($disabledFields)) {
|
|
print "<br>These fields will not be error checked:<br>";
|
|
print_r($disabledFields);
|
|
print "<br>";
|
|
}
|
|
}
|
|
|
|
foreach ($checkFields as $fieldname) {
|
|
$errorFound = 0;
|
|
if (!in_array($fieldname,$disabledFields)) {
|
|
$errorCheck = t3lib_div::trimExplode(',', $this->conf['fieldConf'][$fieldname.'.']['errorCheck']);
|
|
if (is_array($this->conf['fieldConf'][$fieldname.'.']['errorCheck.'])) {
|
|
if($this->conf['fieldConf'][$fieldname.'.']['errorCheck.']['ereg'] != '') {
|
|
$add_check['ereg'] = $this->conf['fieldConf'][$fieldname.'.']['errorCheck.']['ereg'];
|
|
$errorCheck[] = "ereg";
|
|
}
|
|
if($this->conf['fieldConf'][$fieldname.'.']['errorCheck.']['eregi'] != '') {
|
|
$add_check['eregi'] = $this->conf['fieldConf'][$fieldname.'.']['errorCheck.']['eregi'];
|
|
$errorCheck[] = "eregi";
|
|
}
|
|
if(is_array($this->conf['fieldConf'][$fieldname.'.']['errorCheck.']['dateRange.'])) {
|
|
$add_check['dateRange'] = $this->conf['fieldConf'][$fieldname.'.']['errorCheck.']['dateRange.'];
|
|
$errorCheck[] = "dateRange";
|
|
}
|
|
}
|
|
|
|
|
|
# - field is not filled out AND
|
|
# - field is required
|
|
if ($this->get_post[$fieldname] == '' && in_array('required', $errorCheck)) {
|
|
$errorFound = 1;
|
|
} elseif (is_array($this->get_post[$fieldname]) && in_array('required', $errorCheck) && empty($this->get_post[$fieldname])) {
|
|
$errorFound = 1;
|
|
} elseif ($this->get_post[$fieldname] || in_array('userValidation',$errorCheck)) { # - field is filled out or has to get validated by userFunction
|
|
|
|
# check each of the defined errorChecks
|
|
foreach ($errorCheck as $check) {
|
|
|
|
# devide into [predefined errors]:[error parameter]
|
|
# example fieldConf.email.errorCheck = time:hh:mm
|
|
$temp = '';
|
|
list($temp) = explode(':', $check);
|
|
if ($temp) {
|
|
$parameter = trim(substr($check, strlen($temp)+1));
|
|
$check = $temp;
|
|
}
|
|
if($check == 'ereg') {
|
|
$parameter = $add_check['ereg'];
|
|
unset($add_check['ereg']);
|
|
}
|
|
if($check == 'eregi') {
|
|
$parameter = $add_check['eregi'];
|
|
unset($add_check['eregi']);
|
|
}
|
|
if($check == 'dateRange') {
|
|
|
|
$parameter['min'] = $add_check['dateRange']['min'];
|
|
$parameter['max'] = $add_check['dateRange']['max'];
|
|
foreach($errorCheck as $idx=>$search) {
|
|
if(strstr($search,"date") && !strstr($search,"dateRange")) {
|
|
$parameter['pattern'] = $errorCheck[$idx];
|
|
}
|
|
}
|
|
unset($add_check['dateRange']);
|
|
}
|
|
#print "Check: ".$check."<br />";
|
|
#print "Parameter: ".$parameter."<br/>";
|
|
$ereg = '';
|
|
$eregi = '';
|
|
switch($check) {
|
|
|
|
# check if field is differnet to the defined defaultValue (if set)
|
|
case "notDefaultValue":
|
|
$defaultValue = $this->conf['fieldConf.'][$fieldname."."]['defaultValue.']['value'];
|
|
if ($defaultValue != '') {
|
|
if (strcmp($defaultValue,$this->get_post[$fieldname]) == 0) {
|
|
$errorFound = 1;
|
|
}
|
|
}
|
|
break;
|
|
|
|
#############################
|
|
# Possibility to do errorCheck in defined userFunc.
|
|
# Thanks to Maik Vlcek <maik.vl(at)web.de>
|
|
// Hook for using an user function to validate fields
|
|
case "userValidation":
|
|
$params = array();
|
|
if(is_array($this->conf['fieldConf'][$fieldname.'.']['errorCheck.'])) {
|
|
$params = $this->conf['fieldConf'][$fieldname.'.']['errorCheck.'];
|
|
}
|
|
$params['value'] = $this->get_post[$fieldname];
|
|
$errorFound = t3lib_div::callUserFunction($this->conf['errorUserFunc'],$params,$this,"");
|
|
if(is_array($errorFound)) {
|
|
$errorUserFuncMessage = $errorFound['errorText'];
|
|
$errorFound= $errorFound['errorFound'];
|
|
}
|
|
break;
|
|
case "email":
|
|
if (!t3lib_div::validEmail($this->get_post[$fieldname])) {
|
|
$errorFound = 1;
|
|
}
|
|
break;
|
|
case "integer":
|
|
if (!t3lib_div::testInt($this->get_post[$fieldname])) {
|
|
$errorFound = 1;
|
|
}
|
|
break;
|
|
case "float":
|
|
$ereg = '^[+-]?[0-9]*[\.,]?[0-9]+$';
|
|
break;
|
|
case "date":
|
|
|
|
# find out separator
|
|
if (!$parameter) {
|
|
$parameter = 'dd.mm.yyyy';
|
|
}
|
|
eregi('^[d|m|y]*(.)[d|m|y]*', $parameter, $res);
|
|
$sep = $res[1];
|
|
|
|
# normalisation of format
|
|
$parameter = strtoupper($parameter);
|
|
$parameter = str_replace($sep, '', $parameter);
|
|
$parameter = str_replace('DD', 'd', $parameter);
|
|
$parameter = str_replace('D', 'd', $parameter);
|
|
$parameter = str_replace('MM', 'm', $parameter);
|
|
$parameter = str_replace('M', 'm', $parameter);
|
|
$parameter = str_replace('YYYY', 'y', $parameter);
|
|
$parameter = str_replace('YY', 'y', $parameter);
|
|
|
|
# find out correct positioins of "d","m","y"
|
|
$pos1 = strpos($parameter, 'd');
|
|
$pos2 = strpos($parameter, 'm');
|
|
$pos3 = strpos($parameter, 'y');
|
|
|
|
$dateCheck = explode($sep, $this->get_post[$fieldname]);
|
|
if (sizeof($dateCheck) != 3) {
|
|
$errorFound = 1;
|
|
} elseif (intval($dateCheck[0]) == 0 || intval($dateCheck[1]) == 0 || intval($dateCheck[2]) == 0) {
|
|
$errorFound = 1;
|
|
} elseif (sizeof($dateCheck) == 3 && checkdate($dateCheck[$pos2], $dateCheck[$pos1], $dateCheck[$pos3]) === false) {
|
|
$errorFound = 1;
|
|
} elseif (strlen($dateCheck[$pos3]) > 4) {
|
|
$errorFound = 1;
|
|
}
|
|
|
|
break;
|
|
case "time":
|
|
|
|
# find out separator
|
|
if (!$parameter) {
|
|
$parameter = 'hh:mm';
|
|
}
|
|
eregi('^[h|m]*(.)[h|m]*', $parameter, $res);
|
|
$sep = $res[1];
|
|
$timeCheck = explode($sep, $this->get_post[$fieldname]);
|
|
if (is_array($timeCheck)) {
|
|
$hours = $tc[0];
|
|
if (!is_numeric($hours) || $hours < 0 || $hours > 23) {
|
|
$errorFound = 1;
|
|
}
|
|
$minutes = $tc[1];
|
|
if (!is_numeric($minutes) || $minutes < 0 || $minutes > 59) {
|
|
$errorFound = 1;
|
|
}
|
|
}
|
|
break;
|
|
case "ereg":
|
|
$ereg = $parameter;
|
|
break;
|
|
case "eregi":
|
|
$eregi = $parameter;
|
|
break;
|
|
|
|
##################################################################
|
|
# Changes made by Reinhard <rf(at)typoheads.at>
|
|
##################################################################
|
|
# Additional error check, which ensures that specified form value
|
|
# does exist in Db.
|
|
# Thanks to Christian B?lter <buelter(at)kennziffer.com>
|
|
##################################################################
|
|
case "isInDBTable":
|
|
list($checkTable,$checkField,$additionalWhere) = explode('|',$parameter);
|
|
if (!empty($checkTable) && !empty($checkField)) {
|
|
$where = $checkField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->get_post[$fieldname],$checkTable).' '.$additionalWhere;
|
|
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*',$checkTable,$where);
|
|
if (!$GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
|
|
$errorFound = 1;
|
|
}
|
|
}
|
|
break;
|
|
|
|
##################################################################
|
|
# Changes made by Reinhard <rf(at)typoheads.at>
|
|
##################################################################
|
|
# Additional error check, which ensures that specified form value
|
|
# does NOT exist in Db.
|
|
# Modified the code provided by
|
|
# Christian B?lter <buelter(at)kennziffer.com>
|
|
##################################################################
|
|
case "isNotInDBTable":
|
|
list($checkTable,$checkField,$additionalWhere) = explode('|',$parameter);
|
|
if (!empty($checkTable) && !empty($checkField)) {
|
|
$where = $checkField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->get_post[$fieldname],$checkTable).' '.$additionalWhere;
|
|
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*',$checkTable,$where);
|
|
if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
|
|
$errorFound = 1;
|
|
}
|
|
}
|
|
break;
|
|
##################################################################
|
|
# Changes made by Reinhard <rf(at)typoheads.at>
|
|
##################################################################
|
|
# Additional error check, which ensures that at least a given number
|
|
# of elements of a checkbox array or similar are selected
|
|
##################################################################
|
|
case "min":
|
|
if(is_array($this->get_post[$fieldname])) {
|
|
if(count($this->get_post[$fieldname]) < $parameter) {
|
|
$errorFound = 1;
|
|
}
|
|
}
|
|
break;
|
|
##################################################################
|
|
# Changes made by Reinhard <rf(at)typoheads.at>
|
|
##################################################################
|
|
# Additional error check, which ensures that less than a given number
|
|
# of elements of a checkbox array or similar are selected
|
|
##################################################################
|
|
case "max":
|
|
if(is_array($this->get_post[$fieldname])) {
|
|
if(count($this->get_post[$fieldname]) > $parameter) {
|
|
$errorFound = 1;
|
|
}
|
|
}
|
|
break;
|
|
case "dateRange":
|
|
|
|
list(,$parameter['pattern']) = explode(':',$parameter['pattern']);
|
|
|
|
# find out separator
|
|
if (!$parameter['pattern']) {
|
|
$parameter['pattern'] = 'dd.mm.yyyy';
|
|
}
|
|
eregi('^[d|m|y]*(.)[d|m|y]*', $parameter['pattern'], $res);
|
|
$sep = $res[1];
|
|
|
|
# normalisation of format
|
|
$parameter['pattern'] = strtoupper($parameter['pattern']);
|
|
$parameter['pattern'] = str_replace($sep, '', $parameter['pattern']);
|
|
$parameter['pattern'] = str_replace('DD', 'd', $parameter['pattern']);
|
|
$parameter['pattern'] = str_replace('D', 'd', $parameter['pattern']);
|
|
$parameter['pattern'] = str_replace('MM', 'm', $parameter['pattern']);
|
|
$parameter['pattern'] = str_replace('M', 'm', $parameter['pattern']);
|
|
$parameter['pattern'] = str_replace('YYYY', 'y', $parameter['pattern']);
|
|
$parameter['pattern'] = str_replace('YY', 'y', $parameter['pattern']);
|
|
|
|
# find out correct positioins of "d","m","y"
|
|
$pos1 = strpos($parameter['pattern'], 'd');
|
|
$pos2 = strpos($parameter['pattern'], 'm');
|
|
$pos3 = strpos($parameter['pattern'], 'y');
|
|
$date = $this->get_post[$fieldname];
|
|
$checkdate = explode($sep,$date);
|
|
$check_day = $checkdate[$pos1];
|
|
$check_month = $checkdate[$pos2];
|
|
$check_year = $checkdate[$pos3];
|
|
if($parameter['min'] != "") {
|
|
$min_date = explode($sep,$parameter['min']);
|
|
$min_day = $min_date[$pos1];
|
|
$min_month = $min_date[$pos2];
|
|
$min_year = $min_date[$pos3];
|
|
if($check_year<$min_year) {
|
|
$errorFound = 1;
|
|
} elseif ($check_year == $min_year && $check_month < $min_month) {
|
|
$errorFound = 1;
|
|
} elseif ($check_year == $min_year && $check_month == $min_month && $check_day < $min_day) {
|
|
$errorFound = 1;
|
|
}
|
|
}
|
|
if($parameter['max'] != "") {
|
|
$max_date = explode($sep,$parameter['max']);
|
|
$max_day = $max_date[$pos1];
|
|
$max_month = $max_date[$pos2];
|
|
$max_year = $max_date[$pos3];
|
|
if($check_year > $max_year) {
|
|
$errorFound = 1;
|
|
} elseif ($check_year == $max_year && $check_month > $max_month) {
|
|
$errorFound = 1;
|
|
} elseif ($check_year == $max_year && $check_month == $max_month && $check_day > $max_day) {
|
|
$errorFound = 1;
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
if ($ereg && !ereg($ereg, $this->get_post[$fieldname])) {
|
|
$errorFound = 1;
|
|
}
|
|
if ($eregi && !eregi($eregi, $this->get_post[$fieldname])) {
|
|
$errorFound = 1;
|
|
}
|
|
}
|
|
}
|
|
if ($errorFound == 1) {
|
|
# get correct error template according to the the current route
|
|
if ($this->multipage == 1) {
|
|
$temp = $this->readCorrectTemplateCode($conf,'ERROR_'.$fieldname,0,$this->multipageStep);
|
|
} else {
|
|
$temp = $this->cObj->getSubpart($this->templateCode_orig,'###ERROR_'.$fieldname.'###');
|
|
}
|
|
|
|
# error text from user validation function
|
|
if($errorUserFuncMessage) {
|
|
$temp = $errorUserFuncMessage;
|
|
}
|
|
|
|
# error text defined in TS (fieldConf.[name of inputfield].errorText = fill out a correct value)
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['errorText']) {
|
|
$temp = $this->conf['fieldConf'][$fieldname.'.']['errorText'];
|
|
|
|
###################################################
|
|
# new patch for multilanguage error texts defined
|
|
# via typoscript
|
|
# (thx to Stano Paska <stanislav.paska(at)kios.sk>)
|
|
###################################################
|
|
if ($this->conf['fieldConf'][$fieldname.'.']['errorText.']) {
|
|
$temp = $this->cObj->cObjGetSingle($this->conf['fieldConf'][$fieldname.'.']['errorText'], $this->conf['fieldConf'][$fieldname.'.']['errorText.']);
|
|
}
|
|
|
|
##############################
|
|
# changes made by Reinhard
|
|
##############################
|
|
# Patch by John Angel
|
|
##############################
|
|
# Define Subpart ERROR_*
|
|
# for universal error texts
|
|
##############################
|
|
if(!$temp) {
|
|
$temp = $GLOBALS["TSFE"]->cObj->getSubpart($this->templateCode_error, 'ERROR_*');
|
|
}
|
|
}
|
|
if (trim($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'."error_".$fieldname)) != "") {
|
|
$temp = trim($GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'."error_".$fieldname));
|
|
}
|
|
if ($temp != "") {
|
|
if (!$this->errors['###error_'.$fieldname.'###']) {
|
|
$error .= $temp;
|
|
}
|
|
$this->errors['###error_'.$fieldname.'###'] = $temp;
|
|
} else {
|
|
$error .= "<li>".ucfirst($fieldname).'</li>';
|
|
$this->errors['###error_'.$fieldname.'###'] = ucfirst($fieldname);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
# Ralf Hettinger: hook for individual error evaluation and error markers
|
|
if (is_array ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey][$this->prefixId]['error_eval'])) {
|
|
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey][$this->prefixId]['error_eval'] as $classRef) {
|
|
$hookObj= &t3lib_div::getUserObj($classRef);
|
|
if (method_exists($hookObj, 'error_eval')) {
|
|
$hookObj->error_eval($error, $this);
|
|
}
|
|
}
|
|
}
|
|
|
|
return $error;
|
|
}
|
|
|
|
/**
|
|
* shows html-template
|
|
*
|
|
* @param string $content
|
|
* @param array $conf copy of TS conf of main instance
|
|
* @return string evaluated template
|
|
*/
|
|
function show_form($content,$conf) {
|
|
$globalMarkerArray=array();
|
|
|
|
# merge error-array with globalMarkerArray
|
|
if (is_array($this->errors)) {
|
|
$globalMarkerArray = $this->errors;
|
|
}
|
|
|
|
###############################
|
|
# add uploaded files to array otherwise the error check might do something wrong
|
|
###############################
|
|
session_start();
|
|
if (is_array($_SESSION['mp_uploadedFiles'])) {
|
|
foreach ($_SESSION['mp_uploadedFiles'] as $fieldname => $files) {
|
|
if (is_array($files)) {
|
|
foreach ($files as $file) {
|
|
if (!$this->get_post[$fieldname]) {
|
|
$this->get_post[$fieldname] = $file['name'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
##############################
|
|
# get markers for uploaded files
|
|
##############################
|
|
$this->fillUploadedFilesMarkerArray($globalMarkerArray);
|
|
|
|
#############################
|
|
# define markers
|
|
#############################
|
|
if (is_array($this->get_post)) {
|
|
|
|
#############################
|
|
# changes made by Reinhard
|
|
#############################
|
|
# Fixed bug, when calling mailformplus with get or post parameters
|
|
# from other extensions. Thanks to Fabian Fisahn <fisahn(at)its-immaterial.com>
|
|
# for report and solution.
|
|
#############################
|
|
# removed bugfix
|
|
# reason: also load if submitted in multistep forms
|
|
#############################
|
|
|
|
foreach($this->get_post as $k=>$v) {
|
|
if (!ereg('EMAIL_', $k) && !$globalMarkerArray['###value_'.$k.'###']) {
|
|
if (!is_array($v)) {
|
|
if(get_magic_quotes_gpc()) {
|
|
$globalMarkerArray['###value_'.$k.'###'] = trim(stripslashes(htmlspecialchars($v)));
|
|
} else {
|
|
$globalMarkerArray['###value_'.$k.'###'] = trim(htmlspecialchars($v));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (is_array($v)) {
|
|
foreach ($v as $field=>$value) {
|
|
$globalMarkerArray['###checked_'.$k.'_'.$value.'###'] = 'checked="checked"';
|
|
$globalMarkerArray['###selected_'.$k.'_'.$value.'###'] = 'selected="selected"';
|
|
}
|
|
} else {
|
|
# Substitute marker with checked="checked" to reach xhtml conformity
|
|
# (thanks to Maik Vlcek <maik.vl(at)web.de> for the hint.
|
|
|
|
$globalMarkerArray['###checked_'.$k.'_'.$v.'###'] = 'checked="checked"';
|
|
$globalMarkerArray['###selected_'.$k.'_'.$v.'###'] = 'selected="selected"';
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
#####################
|
|
# general file upload markers for each upload-field
|
|
#####################
|
|
if (is_array($this->conf['fieldConf'])) {
|
|
foreach (array_keys($this->conf['fieldConf']) as $fieldname) {
|
|
$fieldnameClean = str_replace('.', '', $fieldname);
|
|
$globalMarkerArray['###'.$fieldnameClean.'_fileTypes###'] = $this->conf['fieldConf'][$fieldname]['fileTypes'];
|
|
$globalMarkerArray['###'.$fieldnameClean.'_fileSize###'] = $this->conf['fieldConf'][$fieldname]['fileSize'];
|
|
$globalMarkerArray['###'.$fieldnameClean.'_numberOfAllowedFiles###'] = $this->conf['fieldConf'][$fieldname]['numberOfAllowedFiles'];
|
|
$globalMarkerArray['###'.$fieldnameClean.'_numberOfRemainingFiles###'] = ($globalMarkerArray['###'.$fieldnameClean.'_numberOfAllowedFiles###']-$globalMarkerArray['###'.$fieldnameClean.'_numberOfUploadedFiles###']);
|
|
}
|
|
}
|
|
$this->fillUploadedFilesMarkerArray($tempMarkerArray, $activeStep);
|
|
|
|
#############################
|
|
# if user is logged in - make user data accessible via "###FEUSER_[field]###"
|
|
#############################
|
|
if (is_array($GLOBALS["TSFE"]->fe_user->user)) {
|
|
foreach($GLOBALS["TSFE"]->fe_user->user as $k=>$v) {
|
|
$globalMarkerArray['###FEUSER_'.strtoupper($k).'###'] = $v;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$globalMarkerArray = $this->substituteTSMarkers($globalMarkerArray,$conf);
|
|
|
|
################################
|
|
# marker for captcha extension
|
|
################################
|
|
if (t3lib_extMgm::isLoaded('captcha')){
|
|
################################
|
|
# Markus Dreyer
|
|
# Edit for the captcha image to be displayed in configured size!!!
|
|
# start
|
|
#################################
|
|
$captchaImgHeight = intval($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['captcha']['imgHeight']);
|
|
$captchaImgWidth = intval($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['captcha']['imgWidth']);
|
|
$globalMarkerArray["###CAPTCHA###"] = '<img src="'.t3lib_extMgm::siteRelPath('captcha').'captcha/captcha.php" alt="" width="' . $captchaImgWidth . '" height="' . $captchaImgHeight . '" />';
|
|
################################
|
|
# Markus Dreyer
|
|
# Edit for the captcha image to be displayed in configured size!!!
|
|
# end
|
|
#################################
|
|
}
|
|
|
|
################################
|
|
# marker for freecap extension
|
|
################################
|
|
if (is_object($this->freeCap)) {
|
|
$globalMarkerArray = array_merge($globalMarkerArray, $this->freeCap->makeCaptcha());
|
|
}
|
|
|
|
################################
|
|
# marker for recaptcha extension
|
|
################################
|
|
if (is_object($this->recaptcha)) {
|
|
$globalMarkerArray["###RECAPTCHA###"] = $this->recaptcha->getReCaptcha();
|
|
}
|
|
|
|
$globalMarkerArray["###EMAIL_SUBJ###"] = $this->getFieldContent("email_subject");
|
|
$globalMarkerArray["###EMAIL_SUBJ_USER###"] = $this->getFieldContent("email_subject_user");
|
|
$globalMarkerArray["###EMAIL_SUBJECT###"] = $this->getFieldContent("email_subject");
|
|
$globalMarkerArray["###EMAIL_SUBJECT_USER###"] = $this->getFieldContent("email_subject_user");
|
|
$globalMarkerArray["###EMAIL_REDIRECT###"] = $this->getFieldContent("email_redirect");
|
|
$globalMarkerArray["###EMAIL_SENDER###"] = $this->getFieldContent("email_sender");
|
|
$globalMarkerArray["###EMAIL_TO###"] = $this->getFieldContent("email_to");
|
|
$globalMarkerArray["###EMAIL_REQUIREDFIELDS###"] = $this->getFieldContent("email_requiredfields");
|
|
|
|
//bugfixed - thx to Sebastian F.:: $globalMarkerArray['###PID###'] = $this->get_post['id'];
|
|
$globalMarkerArray['###PID###'] = $GLOBALS["TSFE"]->id;
|
|
|
|
##############################################
|
|
# inserted by Reinhard <rf(at)typoheads.at>
|
|
##############################################
|
|
# patch using flexforms provided by Marcel Alburg <alb(at)weeaar.com>
|
|
##############################################
|
|
$globalMarkerArray['###value_language_id###'] = $GLOBALS['TSFE']->sys_language_uid;
|
|
##############################################
|
|
|
|
$globalMarkerArray['###ERROR###'] = $this->error;
|
|
|
|
if($conf['noDefaultErrorList'] && $this->error) {
|
|
$errorText = $GLOBALS["TSFE"]->cObj->getSubpart($this->templateCode_error, "ERROR_START");
|
|
$markers = $this->substituteLangMarkers($errorText);
|
|
$errorText = $this->cObj->substituteMarkerArray($errorText, $markers);
|
|
$globalMarkerArray['###ERROR###'] = $errorText;
|
|
}
|
|
|
|
#############################
|
|
# Ralf Hettinger: markers for current path and url,
|
|
# respecting other GET params that might be issued by other extensions
|
|
#############################
|
|
# relative path with get parameters: ###REL_URL###
|
|
# absolute path without get paramters: ###ABS_URL###
|
|
#############################
|
|
|
|
# Only set get params, if it is the first call of the form.
|
|
# Otherwise problems with multipage forms.
|
|
if (!$this->get_post['SUBMITTED'] && !$this->get_post['submitted']) {
|
|
if (t3lib_div::_GP("L")) {
|
|
$addparams["L"] = t3lib_div::_GP("L");
|
|
}
|
|
if (is_array($addparams)) {
|
|
$addparams = array_merge ($addparams,t3lib_div::_GET());
|
|
} else {
|
|
$addparams = t3lib_div::_GET();
|
|
}
|
|
if (isset($addparams['id'])) {
|
|
unset($addparams['id']);
|
|
}
|
|
$_SESSION['th_mailformplus'][$GLOBALS["TSFE"]->id]['params'] = $addparams;
|
|
if (isset($_SESSION['th_mailformplus'][$GLOBALS["TSFE"]->id]['md5_submitted'])) {
|
|
unset($_SESSION['th_mailformplus'][$GLOBALS["TSFE"]->id]['md5_submitted']);
|
|
}
|
|
}
|
|
$pid_path = $this->pi_getPageLink($GLOBALS['TSFE']->id,'',$_SESSION['th_mailformplus'][$GLOBALS["TSFE"]->id]['params']);
|
|
$pid_path_without_get = $this->pi_getPageLink($GLOBALS['TSFE']->id,'','');
|
|
$globalMarkerArray['###REL_URL###'] = $pid_path;
|
|
$globalMarkerArray['###ABS_URL###'] = t3lib_div::locationHeaderUrl('').$pid_path_without_get;
|
|
if ($this->debug == 1) {
|
|
print "relative URL: ".$pid_path."<br>\n";
|
|
print "absolute URL: ".t3lib_div::locationHeaderUrl('').$pid_path_without_get."<br>\n";
|
|
}
|
|
|
|
# Ralf Hettinger: hook for individual show_form markers
|
|
if (is_array ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey][$this->prefixId]['show_form'])) {
|
|
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey][$this->prefixId]['show_form'] as $classRef) {
|
|
$hookObj= &t3lib_div::getUserObj($classRef);
|
|
if (method_exists($hookObj, 'show_form_postHandling')) {
|
|
$hookObj->show_form_postHandling($globalMarkerArray, $this);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Adds hook for processing of extra item markers (thx to Sebastian Baumann <sebastian.baumann(at)vipa.de> and Georg Ringer <mail(at)ringerge.org>)
|
|
|
|
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['hooks'])) {
|
|
foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['hooks'] as $classRef) {
|
|
$procObj = &t3lib_div::getUserObj($classRef);
|
|
#print $_classRef;
|
|
if (method_exists ($procObj, 'extraItemMarkerProcessor')) {
|
|
#print "call";
|
|
$tempMarkerArray = $procObj->extraItemMarkerProcessor($globalMarkerArray, $this->get_post, $this->conf, $this);
|
|
}
|
|
}
|
|
}
|
|
|
|
##############################################
|
|
# Marks required fields
|
|
# inserted by Mike Mitterer <office(at)bitcon.at>
|
|
##############################################
|
|
|
|
$array_required = split(',', $this->getFieldContent("email_requiredfields"));
|
|
if (is_array($this->conf['fieldConf'])) {
|
|
$temp = array_keys($this->conf['fieldConf']);
|
|
$checkFields = array();
|
|
foreach ($temp as $t) {
|
|
$checkFields[] = substr($t, 0, -1);
|
|
}
|
|
$array_required = array_merge($array_required,$checkFields);
|
|
}
|
|
#print_r($array_required);
|
|
$marker_required = $this->getFieldContent("required_marker");
|
|
foreach($array_required as $field_required) {
|
|
$globalMarkerArray['###required_' . trim($field_required) . '###'] = ($marker_required ? $marker_required : '*');
|
|
}
|
|
#print "sanitizing";
|
|
#$globalMarkerArray = $this->sanitizeValues($globalMarkerArray);
|
|
$this->templateCode = $this->cObj->substituteMarkerArray($this->templateCode, $globalMarkerArray);
|
|
|
|
$this->templateCode = $this->removeUnsetMarkers($this->templateCode);
|
|
return $this->templateCode;
|
|
}
|
|
|
|
|
|
/**
|
|
* get content of input fields
|
|
* only for plugin settings!
|
|
*
|
|
* @param string $fN name of input field
|
|
* @return string parsed input
|
|
*/
|
|
function getFieldContent($fN) {
|
|
switch($fN) {
|
|
case "uid":
|
|
|
|
// The "1" means that the display of single items is CACHED! Set to zero to disable caching.
|
|
return $this->pi_list_linkSingle($this->internal["currentRow"][$fN],$this->internal["currentRow"]["uid"],1);
|
|
break;
|
|
default:
|
|
|
|
# value is set
|
|
if ($this->internal["currentRow"][$fN]) {
|
|
return $this->internal["currentRow"][$fN];
|
|
} else {
|
|
|
|
# no value set: take typoscript default setting
|
|
if ($this->conf['default.'][$fN.'.'] && $this->conf['default.'][$fN]) {
|
|
return $this->cObj->cObjGetSingle($this->conf['default.'][$fN], $this->conf['default.'][$fN.'.'], '');
|
|
} elseif ($this->conf['default.'][$fN.'.']) {
|
|
return $this->cObj->TEXT($this->conf['default.'][$fN.'.']);
|
|
} else {
|
|
|
|
##############################################
|
|
# inserted by Reinhard <rf(at)typoheads.at>
|
|
##############################################
|
|
# patch using flexforms provided by Marcel Alburg <alb(at)weeaar.com>
|
|
##############################################
|
|
if ($this->pi_getFFvalue($this->cObj->data['pi_flexform'], $fN, 's_form') ) {
|
|
return $this->pi_getFFvalue($this->cObj->data['pi_flexform'], $fN, 's_form');
|
|
}
|
|
##############################################
|
|
|
|
return $this->conf['default.'][$fN];
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
function markersCountAsSet($markers, $conditionValue) {
|
|
// Find first || or && or !
|
|
$pattern = '/(_*([A-Za-z0-9]+)_*(\|\||&&)_*([^_]+)_*)|(_*(!)_*([A-Za-z0-9]+))/';
|
|
// recurse if there are more
|
|
if( preg_match($pattern, $conditionValue, $matches) ){
|
|
#####################
|
|
# Changed by Reinhard
|
|
#####################
|
|
# $isset returned true for empty string too. Thx to Martin Liebenberg <martin.liebenberg(at)rwth-aachen.de>
|
|
#####################
|
|
|
|
//$isset = isset($markers['###' . $matches[2] . '###']);
|
|
$isset = isset($markers['###' . $matches[2] . '###']) && strlen($markers['###' . $matches[2] . '###']) > 0;
|
|
if($matches[3] == '||' && $isset)
|
|
$return = true;
|
|
elseif($matches[3] == '||' && !$isset)
|
|
$return = $this-> markersCountAsSet($markers, $matches[4]);
|
|
elseif($matches[3] == '&&' && $isset)
|
|
$return = $this-> markersCountAsSet($markers, $matches[4]);
|
|
elseif($matches[3] == '&&' && !$isset)
|
|
$return = false;
|
|
elseif($matches[6] == '!' && !$isset) {
|
|
return !(isset($markers['###' . $matches[7] . '###']) && $markers['###' . $matches[7] . '###'] != '');
|
|
} elseif($this->debug == 1) {
|
|
debug("Invalid format of ISSET Marker. Hint: " . $matches[2] );
|
|
}
|
|
|
|
} else {
|
|
// remove underscores
|
|
$pattern = '/_*/';
|
|
$str = preg_replace($pattern, $str, '');
|
|
// end of recursion
|
|
$return = isset($markers['###' . $conditionValue . '###']) && ($markers['###' . $conditionValue . '###'] != '');
|
|
|
|
}
|
|
return $return;
|
|
}
|
|
|
|
/**
|
|
* Use or remove subparts with ISSET_var patterns (thx to Stephan Bauer <stephan_bauer(at)gmx.de>
|
|
*
|
|
* @param string $subpart: html content with markers
|
|
* @param array $markers: array with markername->substitution value
|
|
* @return string substituted html content
|
|
*/
|
|
function substituteIssetSubparts($subpart, $markers){
|
|
$flags = array();
|
|
#print "call";
|
|
$nowrite = false;
|
|
$out = array();
|
|
foreach(split(chr(10), $subpart) as $line){
|
|
// works only on it's own line
|
|
$pattern = '/###ISSET_+([^#]*)_*###/';
|
|
// set for odd ISSET_xyz, else reset
|
|
if(preg_match($pattern, $line, $matches)) {
|
|
if(!$flags[$matches[1]]) { // set
|
|
$flags[$matches[1]] = true;
|
|
|
|
// set nowrite flag if required until the next ISSET_xyz
|
|
// (only if not already set by envelop)
|
|
if( (!$this->markersCountAsSet($markers, $matches[1]) )
|
|
&& (! $nowrite ) ) $nowrite = $matches[1];
|
|
|
|
}else{ // close it
|
|
$flags[$matches[1]] = false;
|
|
if($nowrite == $matches[1]) $nowrite = 0;
|
|
}
|
|
} else { // It is no ISSET_line. Write if permission is given.
|
|
if(!$nowrite) $out[] = $line;
|
|
}
|
|
}
|
|
$out = implode(chr(10),$out);
|
|
$out = $this->cObj->substituteMarkerArrayCached($out, $markers);
|
|
return $out;
|
|
}
|
|
|
|
function sanitizeValues($markerArray) {
|
|
//$allowedTags = $this->getFieldContent('allowedTags');
|
|
|
|
#########################################
|
|
# Changed by Reinhard
|
|
#########################################
|
|
# Replaced function_exists because function_exists() is limited to the scope of the own class. In this case it was returning false even if the function existed.
|
|
# Thx to Tomas J Stehlik <tomas(at)stehlik.co.uk>
|
|
#########################################
|
|
# if (function_exists('t3lib_div::removeXSS')) {
|
|
#########################################
|
|
|
|
/*if (method_exists('t3lib_div', 'removeXSS')) {
|
|
foreach ($markerArray as $key => $value) {
|
|
if(is_array($value)) {
|
|
$sanitizedArray[$key] = $this->sanitizeValues($value);
|
|
} else {
|
|
$value = str_replace("\t","",$value);
|
|
$sanitizedArray[$key] = t3lib_div::removeXSS($value);
|
|
}
|
|
}
|
|
} else {*/
|
|
/*require_once(t3lib_extMgm::extPath('th_mailformplus')."RemoveXSS.php");
|
|
foreach ($markerArray as $key => $value) {
|
|
if(is_array($value)) {
|
|
$sanitizedArray[$key] = $this->sanitizeValues($value);
|
|
} else {
|
|
$value = str_replace("\t","",$value);
|
|
$sanitizedArray[$key] = RemoveXSS::RemoveXSS($value);
|
|
|
|
}
|
|
}*/
|
|
//}
|
|
|
|
|
|
# changes by Reinhard
|
|
###################
|
|
# New class for removal of xss as suggested by Gregor Vonderschmitt <gvo(at)simple.ch>
|
|
###################
|
|
if(!is_array($markerArray)) {
|
|
return array();
|
|
}
|
|
|
|
require_once(t3lib_extMgm::extPath('th_mailformplus')."filtreatment.php");
|
|
$filter = new Filtreatment();
|
|
foreach ($markerArray as $key => $value) {
|
|
if(is_array($value)) {
|
|
$sanitizedArray[$key] = $this->sanitizeValues($value);
|
|
} else {
|
|
$value = str_replace("\t","",$value);
|
|
$sanitizedArray[$key] = $filter->ft_xss($value);
|
|
|
|
}
|
|
}
|
|
return $sanitizedArray;
|
|
}
|
|
|
|
/**
|
|
* get correct form template(s), error or email template for the current step
|
|
* form templates are calculated beginning with the given step, other templates
|
|
* are calculated only for the given step, not further.
|
|
* @param string $conf the conf array
|
|
* @param string $subpartPrefix the prefix of the template to search for (example: "TEMPLATE_FORM")
|
|
* @param string $isFormTempl indicates if search for form template or error/email template
|
|
* @param string $multipage_step return template for this step
|
|
* @return string/array template code(s)
|
|
*/
|
|
function readCorrectTemplateCode($conf,$subpartPrefix,$isFormTempl,$multipage_step) {
|
|
$ok = false;
|
|
|
|
$temp = array();
|
|
$subpartPrefix = $subpartPrefix;
|
|
$subpartPrefix_while = $subpartPrefix;
|
|
if ($isFormTempl) {
|
|
$subpartPrefix .= $multipage_step;
|
|
}
|
|
if ($this->debug == 1) {
|
|
$notchosen = array();
|
|
$chosen = array();
|
|
$concl = '';
|
|
}
|
|
$full_postfix = array();
|
|
$data = array();
|
|
if (is_array($conf['multipage.'])) {
|
|
foreach ($conf['multipage.'] as $step=>$postfix) {
|
|
$step = str_replace(".","",$step);
|
|
$data[$step] = $postfix;
|
|
}
|
|
}
|
|
|
|
ksort($data);
|
|
|
|
if (is_array($data)) {
|
|
foreach ($data as $step=>$postfix) {
|
|
|
|
if ($step<=$this->multipageStep) {
|
|
$curr_postfix = $postfix['postfix'];
|
|
$full_postfix[] = $curr_postfix;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
# fallback: if no template with the current postfix is found, try finding a template using previous postfixes
|
|
$test_index = count($full_postfix)-1;
|
|
while (!$ok) {
|
|
if (is_array($conf['multipage.'])) {
|
|
$test_postfix = '';
|
|
for ($index = 0;$index<=$test_index;$index++) {
|
|
$test_postfix .= $full_postfix[$index];
|
|
}
|
|
if ($test_index == -1 ) {
|
|
|
|
if (!strstr($this->templateCode_orig,'###'.$subpartPrefix.'###')) {
|
|
if ($this->debug == 1) {
|
|
$notchosen[] = '###'.$subpartPrefix.'###<br>';
|
|
$concl = "no alternative template found!<br>\n";
|
|
}
|
|
break;
|
|
}
|
|
else {
|
|
if ($this->debug == 1) {
|
|
$chosen[] = '###'.$subpartPrefix.'###<br>';
|
|
}
|
|
$ok = true;
|
|
}
|
|
} elseif (!strstr($this->templateCode_orig,'###'.$subpartPrefix.$test_postfix.'###')) {
|
|
$test_index--;
|
|
if ($this->debug == 1) {
|
|
$notchosen[] = '###'.$subpartPrefix.$test_postfix.'###'."<br>";
|
|
}
|
|
} else {
|
|
$ok = true;
|
|
if ($this->debug == 1) {
|
|
$chosen[] = '###'.$subpartPrefix.$test_postfix.'###'."<br>";
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
$ok = true;
|
|
}
|
|
}
|
|
if ($this->debug == 1) {
|
|
if (strcmp($concl,'') == 0) {
|
|
$concl = "alternative template found!<br>\n";
|
|
}
|
|
print "not chosen alternative templates: <br>\n";
|
|
print_r($notchosen);
|
|
print "chosen alternative template: <br>\n";
|
|
print_r($chosen);
|
|
print "result: ".$concl."<br>\n";
|
|
}
|
|
if (!$isFormTempl) {
|
|
$temp = $this->cObj->getSubpart($this->templateCode_orig,'###'.$subpartPrefix.$test_postfix.'###');
|
|
return $temp;
|
|
}
|
|
# was search for correct form template
|
|
if ($isFormTempl) {
|
|
$i=1;
|
|
$found = true;
|
|
$test_postfix = '';
|
|
while($found) {
|
|
$test_index = count($full_postfix)-1;
|
|
$foundTempl = false;
|
|
while($test_index >= -1 && $foundTempl == false) {
|
|
$test_postfix = '';
|
|
if ($test_index == -1) {
|
|
$test_postfix = '';
|
|
} else {
|
|
for ($index = 0;$index<=$test_index;$index++) {
|
|
$test_postfix .= $full_postfix[$index];
|
|
}
|
|
}
|
|
if (strstr($this->templateCode_orig,'###'.$subpartPrefix_while.$i.$test_postfix.'###')) {
|
|
$foundTempl = true;
|
|
$temp[$i] = $this->cObj->getSubpart($this->templateCode_orig,'###'.$subpartPrefix_while.$i.$test_postfix.'###');
|
|
} else {
|
|
$test_index--;
|
|
}
|
|
}
|
|
if (!$foundTempl) {
|
|
break;
|
|
}
|
|
$i++;
|
|
}
|
|
}
|
|
#if (is_array($temp) && $temp[0] != '') {
|
|
# $temp = $temp[0];
|
|
#}
|
|
return $temp;
|
|
}
|
|
|
|
|
|
/**
|
|
* finds markers (###LLL:[markername]###) in given template Code
|
|
* @param string $templCode the template code in which the markers should be searched for
|
|
* @return array the found language markers with translation text
|
|
*/
|
|
function substituteLangMarkers($templCode) {
|
|
global $LANG;
|
|
$langMarkers = array();
|
|
if ($this->langFile != '') {
|
|
$aLLMarkerList = array();
|
|
preg_match_all('/###LLL:.+?###/Ssm', $templCode, $aLLMarkerList);
|
|
|
|
if ($this->debug == 1) {
|
|
print "Found language markers: <br>";
|
|
print_r($aLLMarkerList);
|
|
}
|
|
|
|
foreach($aLLMarkerList[0] as $LLMarker){
|
|
$llKey = strtolower(substr($LLMarker,7,strlen($LLMarker)-10));
|
|
$marker = $llKey;
|
|
$langMarkers['###LLL:'.$marker.'###'] = recode_string("utf-8..{$GLOBALS['TSFE']->labelsCharset}", $GLOBALS['TSFE']->sL('LLL:'.$this->langFile.':'.$llKey));
|
|
$langMarkers['###LLL:'.strtoupper($marker).'###'] = $langMarkers['###LLL:'.$marker.'###'];
|
|
}
|
|
}
|
|
return $langMarkers;
|
|
}
|
|
|
|
|
|
/**
|
|
* substitute marker defined with Typoscript, adding the results to given array
|
|
* @param array $globalMarkerArray the replaced marker values are added to this array
|
|
* @param array $conf TS-settings
|
|
* @param int $subsLang indicates if language markers should be replaced
|
|
* @return array the markers array
|
|
*/
|
|
function substituteTSMarkers($globalMarkerArray,$conf,$subsLang = 1) {
|
|
#############################
|
|
# markers defined via TypoScript
|
|
# example: plugin.tx_thmailformplus_pi1.markers.abteilungen < temp.jsmenu
|
|
#############################
|
|
|
|
if (is_array($conf['markers.'])) {
|
|
$lastKey = '';
|
|
|
|
foreach (array_keys($conf['markers.']) as $key) {
|
|
|
|
# key ["marker"] not ["marker."]
|
|
if (FALSE == strstr($lastKey, '.') && !is_array($conf['markers.'][$key])) {
|
|
$lastKey = $key;
|
|
|
|
} else {
|
|
|
|
#################################
|
|
# special TS:
|
|
# [markername] = SUBPART
|
|
# [markername].value = [subpart Key]
|
|
# makes it possible to fill a marker with a subpart defined in the template
|
|
#################################
|
|
if (strcasecmp($conf['markers.'][$lastKey], 'SUBPART') == 0 && $conf['markers.'][$lastKey.'.']['value']) {
|
|
# is subpart name without "###" ?
|
|
|
|
$hash = '';
|
|
if (!strstr($conf['markers.'][$lastKey.'.']['value'], '###')) {
|
|
$hash = '###';
|
|
}
|
|
$ts_marker = $this->cObj->getSubpart($this->templateCode_orig,$hash.$conf['markers.'][$lastKey.'.']['value'].$hash);
|
|
if ($subsLang) {
|
|
$langMarkers = $this->substituteLangMarkers($ts_marker);
|
|
$ts_marker = $this->cObj->substituteMarkerArray($ts_marker, $langMarkers);
|
|
}
|
|
}
|
|
#################################
|
|
# standard TS
|
|
#################################
|
|
else {
|
|
$ts_marker = $this->cObj->cObjGetSingle($conf['markers.'][$lastKey], $conf['markers.'][$lastKey.'.']);
|
|
}
|
|
$globalMarkerArray['###'.$lastKey.'###'] = $this->cObj->substituteMarkerArray($ts_marker, $globalMarkerArray);
|
|
#$globalMarkerArray['###'.$lastKey.'###'] = $this->sanitizeValues($globalMarkerArray['###'.$lastKey.'###']);
|
|
}
|
|
}
|
|
}
|
|
return $globalMarkerArray;
|
|
}
|
|
|
|
/**
|
|
* substitute marker defined with Typoscript, returning full template code
|
|
* @param array $templ the template code in which the markers should be replaced
|
|
* @param array $conf TS-settings
|
|
* @param int $subsLang indicates if language markers should be replaced
|
|
* @return string the result template code
|
|
*/
|
|
function substituteTSMarkersTempl($templ,$conf,$subsLang = 1) {
|
|
#############################
|
|
# markers defined via TypoScript
|
|
# example: plugin.tx_thmailformplus_pi1.markers.abteilungen < temp.jsmenu
|
|
#############################
|
|
|
|
if (is_array($conf['markers.'])) {
|
|
$lastKey = '';
|
|
|
|
foreach (array_keys($conf['markers.']) as $key) {
|
|
|
|
# key ["marker"] not ["marker."]
|
|
if (FALSE == strstr($lastKey, '.') && !is_array($conf['markers.'][$key])) {
|
|
$lastKey = $key;
|
|
|
|
} else {
|
|
$markers = array();
|
|
#################################
|
|
# special TS:
|
|
# [markername] = SUBPART
|
|
# [markername].value = [subpart Key]
|
|
# makes it possible to fill a marker with a subpart defined in the template
|
|
#################################
|
|
if (strcasecmp($conf['markers.'][$lastKey], 'SUBPART') == 0 && $conf['markers.'][$lastKey.'.']['value']) {
|
|
# is subpart name without "###" ?
|
|
|
|
$hash = '';
|
|
if (!strstr($conf['markers.'][$lastKey.'.']['value'], '###')) {
|
|
$hash = '###';
|
|
}
|
|
$ts_marker = $this->cObj->getSubpart($this->templateCode_orig,$hash.$conf['markers.'][$lastKey.'.']['value'].$hash);
|
|
if ($subsLang) {
|
|
$langMarkers = $this->substituteLangMarkers($ts_marker);
|
|
$ts_marker = $this->cObj->substituteMarkerArray($ts_marker, $langMarkers);
|
|
}
|
|
$markers['###'.$lastKey.'###'] = $ts_marker;
|
|
}
|
|
#################################
|
|
# standard TS
|
|
#################################
|
|
else {
|
|
$ts_marker = $this->cObj->cObjGetSingle($conf['markers.'][$lastKey], $conf['markers.'][$lastKey.'.']);
|
|
$markers['###'.$lastKey.'###'] = $ts_marker;
|
|
}
|
|
$templ = $this->cObj->substituteMarkerArray($templ,$markers);
|
|
}
|
|
}
|
|
}
|
|
return $templ;
|
|
}
|
|
}
|
|
|
|
|
|
################################
|
|
# Mailformplus API functions / helper functions
|
|
################################
|
|
class user_mailformplusAPI {
|
|
|
|
|
|
#############################
|
|
# returns TYPO3 standard auth-code used for newsletter-registration
|
|
#############################
|
|
# TypoScript config (example):
|
|
# auth = USER
|
|
# auth.userFunc = user_mailformplusAPI->user_authCode
|
|
# auth.dbTable = tt_address
|
|
# auth.where = TEXT
|
|
# auth.where {
|
|
# value = email="{GPvar:email}" AND deleted=0
|
|
# insertData = 1
|
|
# }
|
|
############################
|
|
function user_authCode($content='',$conf=array()) {
|
|
|
|
if ($conf['where'] && $conf['where.']) $where = $this->cObj->cObjGetSingle($conf['where'], $conf['where.'], '');
|
|
else $where = $conf['where'];
|
|
|
|
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
|
|
'*',
|
|
$conf['dbTable'],
|
|
$where
|
|
);
|
|
if ($res && $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
|
|
$authCode = t3lib_div::stdAuthCode($row);
|
|
return $authCode;
|
|
}
|
|
return;
|
|
}
|
|
|
|
|
|
#############################
|
|
# returns a specific DB field value
|
|
#############################
|
|
# TypoScript config (example):
|
|
# uid = USER
|
|
# uid {
|
|
# userFunc = user_mailformplusAPI->user_getDBValue
|
|
# dbTable = tt_address
|
|
# dbField = uid
|
|
# orderBy = uid desc
|
|
# where = TEXT
|
|
# where {
|
|
# value = email="{GPvar:email}" AND deleted=0
|
|
# insertData = 1
|
|
# }
|
|
# }
|
|
############################
|
|
function user_getDBValue($content='',$conf=array()) {
|
|
|
|
$where = $this->cObj->cObjGetSingle($conf['where'], $conf['where.'], '');
|
|
|
|
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
|
|
$conf['dbField'],
|
|
$conf['dbTable'],
|
|
$where,
|
|
'',
|
|
$conf['orderBy']
|
|
);
|
|
if ($res && $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
|
|
$out = $row[$conf['dbField']];
|
|
return $out;
|
|
}
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/th_mailformplus/pi1/class.tx_thmailformplus_pi1.php"]) {
|
|
include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/th_mailformplus/pi1/class.tx_thmailformplus_pi1.php"]);
|
|
}
|
|
|
|
?>
|