You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2021-10-14 14:49:19

cillox
Member
Registered: 2017-08-18
Posts: 14

Send last Followup Attachment

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

#2 2022-06-28 10:20:51

chch18
Member
Registered: 2022-06-28
Posts: 2

Re: Send last Followup Attachment

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

#3 2023-05-09 11:49:02

vlcek_vratko
Member
Registered: 2023-05-09
Posts: 4

Re: Send last Followup Attachment

Hi guys,


I know it's been a while, but this problem still exists, have you found any solution?

Thanks a lot.

V.

Offline

#4 2023-11-02 11:40:14

Changemanager
Member
Registered: 2023-02-21
Posts: 39

Re: Send last Followup Attachment

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

Board footer

Powered by FluxBB