Added mail template + parsing.

This commit is contained in:
Markus Birth 2016-05-27 15:29:18 +02:00
parent c807857e27
commit 30cc304a36
3 changed files with 56 additions and 0 deletions

View File

@ -97,6 +97,13 @@ if (!$tpl_done && isset($_SESSION['access_token']) && $_SESSION['access_token'])
switch ($_GET['action']) {
case 'send':
echo "This would send the mail...";
$mtpl = $m->loadTemplate('mail_' . $form_type);
$action = $form_type;
require 'prep_mail.php';
$data['action'] = $action;
$mail_html = $mtpl->render($data);
echo '<hr/>'.$mail_html;
break;
case 'event':
$tpl = $m->loadTemplate('event_html');

46
prep_mail.php Normal file
View File

@ -0,0 +1,46 @@
<?php
// FOR TESTING:
if (!isset($action)) {
$action = 'hotel';
$debug = true;
}
$skey = 'form_' . $action;
$field_data_json = file_get_contents('definitions/' . $action . '.json');
$field_data = json_decode($field_data_json, true);
$fields = array();
// Assign fields to groups, fill in (default) values
foreach ($field_data['fields'] as $key=>$meta) {
$meta['field_id'] = $key;
// Assign session value if set, or use default if set
if (isset($_SESSION[$skey][$key])) {
$meta['value'] = $_SESSION[$skey][$key];
switch ($meta['type']) {
case 'datetime':
$meta['value_unixtime'] = strtotime($meta['value']);
break;
}
}
// Field type marker for Mustache
$meta['fieldtype_' . $meta['type']] = true;
// Add useful default values for some types
if ($meta['type'] == 'datetime') {
$meta['today'] = date('Y-m-d');
}
// Add to fieldlist
$fields[$key] = $meta;
}
if ($debug) {
print_r($fields);
}
$data = array_merge($data, $fields);

View File

@ -0,0 +1,3 @@
This is the Template for the {{action}} Mail!
{{reservationFor_name.value}}