From fdf5fe0f267fb40a8cda945d801bf48dea674cf6 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 29 Jun 2024 19:28:30 +0200 Subject: [PATCH] FIX broken pdf preview when multicompany sharing (#30188) * FIX broken pdf preview when multicompany sharing * Update html.formmail.class.php --------- Co-authored-by: Laurent Destailleur --- htdocs/core/class/html.formmail.class.php | 7 ++++--- htdocs/core/tpl/card_presend.tpl.php | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index aa35fa988d1..c3139bb3c78 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -844,8 +844,9 @@ class FormMail extends Form foreach ($listofpaths as $key => $val) { $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val))); - if ($conf->entity > 1) { - $relativepathtofile = str_replace('/'.$conf->entity.'/', '/', $relativepathtofile); + $entity = (isset($this->param['object_entity']) ? $this->param['object_entity'] : $conf->entity); + if ($entity > 1) { + $relativepathtofile = str_replace('/'.$entity.'/', '/', $relativepathtofile); } // Try to extract data from full path $formfile_params = array(); @@ -855,7 +856,7 @@ class FormMail extends Form // Preview of attachment $out .= img_mime($listofnames[$key]).' '.$listofnames[$key]; - $out .= $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4]); + $out .= $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ? '' : 'entity='.((int) $entity)); if (!$this->withfilereadonly) { $out .= ' '; //$out.= ' '.img_delete($langs->trans("Delete").''; diff --git a/htdocs/core/tpl/card_presend.tpl.php b/htdocs/core/tpl/card_presend.tpl.php index 039f4e2a96a..9f8b7ab95b7 100644 --- a/htdocs/core/tpl/card_presend.tpl.php +++ b/htdocs/core/tpl/card_presend.tpl.php @@ -387,6 +387,7 @@ if ($action == 'presend') { $formmail->param['id'] = $object->id; $formmail->param['returnurl'] = $_SERVER["PHP_SELF"].'?id='.$object->id; $formmail->param['fileinit'] = array($file); + $formmail->param['object_entity'] = $object->entity; // Show form print $formmail->get_form();