You are not logged in.
Pages: 1
Hi,
If active the setup > email notification > Add documents into ticket notifications for each followup send the email with the all documents attached into the ticket, anyone can help me with this? how is the code, tag, rule or option for send only documents attached in the last followup send?.
For example: write the last followup and attached one or two documents and send email notification with this documents.
Last edited by cillox (2021-10-14 14:50:48)
Offline
Hello!
If still relevant))
I tried to do this to change the logic of working with attachments:
In class notificationeventmailing.class.php around line 268
replace
foreach ($inline_docs as $docID => $tag) {
$current->fields['body_html'] = preg_replace([
'/src=["\'][^"\']*document\.send\.php\?docid='.$docID.'(&[^"\']+)?["\']/',
'/href=["\'][^"\']*document\.send\.php\?docid='.$docID.'(&[^"\']+)?["\']/',
], [
'src="cid:' . $tag . '"',
'href="' . $CFG_GLPI['url_base'] . '/front/document.send.php?docid=' . $docID . '$1"',
],
$current->fields['body_html']);
}
$mmail->Body = GLPIMailer::normalizeBreaks($current->fields['body_html']);
$mmail->AltBody = GLPIMailer::normalizeBreaks($current->fields['body_text']);
}
self::attachDocuments($mmail, $documents_to_attach);
to
foreach ($inline_docs as $docID => $tag) {
$current->fields['body_html'] = preg_replace([
'/src=["\'][^"\']*document\.send\.php\?docid='.$docID.'(&[^"\']+)?["\']/',
'/href=["\'][^"\']*document\.send\.php\?docid='.$docID.'(&[^"\']+)?["\']/',
], [
'src="cid:' . $tag . '"',
'href="' . $CFG_GLPI['url_base'] . '/front/document.send.php?docid=' . $docID . '$1"',
],
$current->fields['body_html']);
}
$mmail->Body = GLPIMailer::normalizeBreaks($current->fields['body_html']);
$mmail->AltBody = GLPIMailer::normalizeBreaks($current->fields['body_text']);
}
<------> //patch - attach docs from documents fields of queuednotifications
if($current->fields["documents"]){
$documents_to_attach = [];
$documents_to_attach = importArrayFromDB($current->fields["documents"]);
<------> self::attachDocuments($mmail, $documents_to_attach);
}
In class notificationevent.class.php around line 182
replace
if (class_exists($eventclass)) {
$eventclass::raise(
$event,
$item,
$options,
$label,
$data,
$notificationtarget->setEvent($eventclass),
$template,
$notify_me,
$emitter
);
}
to
if (class_exists($eventclass)) {
<------><------>//attach docs added with followups or tasks
<------><------>if(array_key_exists('followup_id',$options)||array_key_exists('task_id',$options)){
$id_docs_array = [];
if(array_key_exists('followup_id',$options)){
$doc_crit[] = [
'timeline_position' => ['>', CommonITILObject::NO_TIMELINE],
'items_id'=>$options['followup_id']
];
}
if(array_key_exists('task_id',$options)){
$doc_crit[] = [
'timeline_position' => ['>', CommonITILObject::NO_TIMELINE],
'items_id'=>$options['task_id']
];
}
$query = [
'SELECT'=>'documents_id',
'FROM'=>'glpi_documents_items',
'WHERE'=> $doc_crit
];
$docs_ids = $DB->request($query);
foreach($docs_ids as $d_id){
$id_docs_array[] = $d_id['documents_id'];
}
$options['documents'] = $id_docs_array;
}
<------><------>//end of patch attach docs added with followups or tasks
$eventclass::raise(
$event,
$item,
$options,
$label,
$data,
$notificationtarget->setEvent($eventclass),
$template,
$notify_me,
$emitter
);
}
In class notificationeventabstract.class.php around line 140
//Send notification to the user
if ($label == '') {
$send_data = $template->getDataToSend(
$notificationtarget,
$tid,
$key,
$users_infos,
$options
);
$send_data['_notificationtemplates_id'] = $data['notificationtemplates_id'];
$send_data['_itemtype'] = $item->getType();
$send_data['_items_id'] = method_exists($item, "getID")
? $item->getID()
: 0;
$send_data['_entities_id'] = $entity;
$send_data['mode'] = $data['mode'];
//ADD
$send_data['documents'] = $options['documents'];
I only tested this for followup and tasks.
If you have a test environment, you can try testing.
Offline
Hi guys,
I know it's been a while, but this problem still exists, have you found any solution?
Thanks a lot.
V.
Offline
And this doesn't work because it always adds the link to the first attachment and not to the last one, although it displays the latest reply.
##FOREACH last documents##
##document.filename##
##ENDFOREACHdocuments##
##FOREACH last followups##
##followup.description##
##ENDFOREACHfollowups##
Offline
Pages: 1