Skip to content

Commit

Permalink
[FEATURE] : Add form variables parsing in email subject, header and f…
Browse files Browse the repository at this point in the history
…ooter
  • Loading branch information
gfilliere committed Sep 11, 2012
1 parent 98356e8 commit d288cb0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion automne/classes/modules/cms_forms/CHANGELOG
@@ -1,5 +1,6 @@
v1.35
[FEATURE] : Add template usage for email actions
[FEATURE] : Add form variables parsing in email subject, header and footer

v1.34
[BUG] : Correct a bug in select tag : values containing commas are not allowed
Expand Down Expand Up @@ -45,4 +46,4 @@ v1.0
First module release

v0.1
Initial import
Initial import
28 changes: 28 additions & 0 deletions automne/templates/mod_cms_forms_header.php
Expand Up @@ -49,6 +49,28 @@ function evalPolymodVars($text, $language){
return $definition->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
}

// Detect and parse mail string vars, if present
function detectAndParseString($string){

$pattern = '/##([a-zA-Z0-9]+)##/';
preg_match_all($pattern, $string, $aMatches);

if(!empty($aMatches)){
foreach($aMatches as $aValues){
foreach($aValues as $key => $val){
if(isset($_POST[$aMatches[1][$key]])) {
$string = str_replace($aMatches[0][$key], $_POST[$aMatches[1][$key]], $string);
}
else {
$string = str_replace($aMatches[0][$key], '', $string);
}
}
}
}

return $string;
}

$separator = (strtolower(APPLICATION_DEFAULT_ENCODING) != 'utf-8') ? "\xa7\xa7" : "\xc2\xa7\xc2\xa7";

//if page has forms
Expand Down Expand Up @@ -390,12 +412,16 @@ function evalPolymodVars($text, $language){
if (isset($texts[1])) { // header
//needed in case of vars in text. Simple and double quotes are not welcome in this case !
$header = evalPolymodVars($texts[1], $form_language->getCode());
$header = detectAndParseString($header);

$body = $header."\n\n".$body;
$bodyHtml = '<div class="important">'.nl2br($header)."</div>".$bodyHtml;
}
if (isset($texts[2])) { //footer
//needed in case of vars in text. Simple and double quotes are not welcome in this case !
$footer = evalPolymodVars($texts[2], $form_language->getCode());
$footer = detectAndParseString($footer);

$body = $body."\n\n". $footer;
$bodyHtml = $bodyHtml.'<div class="important">'.nl2br($footer)."</div>";
}
Expand All @@ -405,6 +431,8 @@ function evalPolymodVars($text, $language){
if ($texts[0]) { //from DB if any
//needed in case of vars in text. Simple and double quotes are not welcome in this case !
$subject = evalPolymodVars($texts[0], $form_language->getCode());
$subject = detectAndParseString($subject);

} else { // or default subject
$subject = $form_language->getMessage(CMS_forms_formular::MESSAGE_CMS_FORMS_EMAIL_SUBJECT, array($form->getAttribute('name'), APPLICATION_LABEL), MOD_CMS_FORMS_CODENAME);
}
Expand Down

0 comments on commit d288cb0

Please sign in to comment.