Skip to content
Snippets Groups Projects
Commit 7fa3dfb9 authored by Florian Azizian's avatar Florian Azizian
Browse files

FIX #9663 merge data does not work in email templates

parent d263ca58
No related branches found
No related tags found
No related merge requests found
......@@ -898,7 +898,7 @@ abstract class templates_controler_Abstract extends ObjectControler implements O
* @param string $outputType : save to 'file', retrieve 'content'
* @return merged content or path to file
*/
public function merge($templateId, $params = array(), $outputType)
public function merge($templateId, $params = array(), $outputType, $context = '')
{
include_once 'core/class/class_functions.php';
include_once 'modules/templates/templates_tables_definition.php';
......
......@@ -84,7 +84,7 @@ if (!empty($res_id)) {
$myContact['title'] = $contacts->get_civility_contact($myContact['title']);
$datasources['contact'][] = $myContact;
// single Contact
// single Contact
} elseif (isset($res_contact_id) && isset($res_address_id) && is_numeric($res_contact_id)) {
$stmt = $dbDatasource->query('SELECT * FROM view_contacts WHERE contact_id = ? and ca_id = ? ', array($res_contact_id, $res_address_id));
$myContact = $stmt->fetch(PDO::FETCH_ASSOC);
......@@ -96,6 +96,13 @@ if (!empty($res_id)) {
$stmt = $dbDatasource->query('SELECT firstname, lastname, user_id, mail, phone, initials FROM users WHERE user_id = ?', [$res_contact_id]);
$myContact = $stmt->fetch(PDO::FETCH_ASSOC);
$datasources['contact'][] = $myContact;
} elseif (!empty($context)) {
$stmt = $dbDatasource->query('SELECT * FROM view_contacts WHERE contact_id = ? and ca_id = ?', array($datasources['res_letterbox'][0]['contact_id'], $datasources['res_letterbox'][0]['address_id']));
$myContact = $stmt->fetch(PDO::FETCH_ASSOC);
$myContact['postal_address'] = \Contact\controllers\ContactController::formatContactAddressAfnor($myContact);
$myContact['contact_title'] = $contacts->get_civility_contact($myContact['contact_title']);
$myContact['title'] = $contacts->get_civility_contact($myContact['title']);
$datasources['contact'][] = $myContact;
}
if (isset($datasources['contact'][0]['title']) && $datasources['contact'][0]['title'] == '') {
......@@ -236,7 +243,6 @@ if (!empty($res_id)) {
$copiesContact = false;
$copiesEntity = false;
if ($copies->item_type == 'user_id') {
$stmt2 = $dbDatasource->query('SELECT * FROM users WHERE user_id = ?', [$copies->item_id]);
$copiesContact = $stmt2->fetchObject();
$stmt3 = $dbDatasource->query('SELECT en.entity_id, en.entity_label FROM entities en, users_entities ue '
......
......@@ -33,23 +33,23 @@ $sec = new security();
$res_view = $sec->retrieve_view_from_coll_id('letterbox_coll');
$params = array(
'res_id' => $_GET['id'],
'coll_id'=> "letterbox_coll",
'res_view'=> $res_view
);
'res_id' => $_GET['id'],
'coll_id'=> "letterbox_coll",
'res_view'=> $res_view
);
$template = $templateController->get($_REQUEST['templateId']);
$template->template_content = $templateController->merge($_REQUEST['templateId'], $params, 'content');
$template->template_content = $templateController->merge($_REQUEST['templateId'], $params, 'content', 'email');
$template->template_content = str_replace("\r\n", "\n", $template->template_content);
$template->template_content = str_replace("\r", "\n", $template->template_content);
$template->template_content = str_replace("\n", "\\n ", $template->template_content);
$template->template_content = str_replace("''", "'", $template->template_content);
if($_REQUEST['mode'] == 'raw'){
if ($_REQUEST['mode'] == 'raw') {
$template->template_content = str_replace("<br>", "\\n", $template->template_content);
$template->template_content = str_replace("<br />", "\\n", $template->template_content);
$template->template_content = strip_tags($template->template_content);
}
echo "{status : 0, content : '" . addslashes($template->template_content) . "'}";
exit();
\ No newline at end of file
exit();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment