Skip to content

File attachments broken in documents.php with Dolibarr 21.0.1 #9

@seeyei

Description

@seeyei

Describe the bug
File attachments don't work when sending emails from patient documents page after upgrading to Dolibarr 21.0.1. Documents that should be attached to emails are not included in the email form.

To Reproduce
Steps to reproduce the behavior:

  1. Go to patient documents: /custom/cabinetmed/documents.php?socid=XXXX
  2. Upload a document (e.g., consultation report, medical report)
  3. Click on "Send by email" on the uploaded document
  4. See that the email form opens without the document attached

Expected behavior
The document should appear in the "Attached files" section of the email form, ready to be sent to the patient.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome
  • Dolibarr Version: 21.0.1
  • DOLIMED Version: 10.0.1

Additional context
This worked correctly in Dolibarr 16.0 + DOLIMED 10.0. After upgrading to Dolibarr 21.0.1, the issue appeared.

Possible root cause:
Dolibarr 21's card_presend.tpl.php may be overwriting the $file variable when object->element = 'societe' and object->last_main_doc is empty (normal for Patient objects).

Proposed fix:

// In documents.php, action presend, add before template include:
if (!empty(GETPOST('urlfile')) && file_exists($fullpathfile)) {
    $file = $fullpathfile;
    $original_last_main_doc = $object->last_main_doc ?? '';
    $object->last_main_doc = str_replace(DOL_DATA_ROOT.'/', '', $fullpathfile);
}

include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';

// Restore original value
if (!empty(GETPOST('urlfile')) && file_exists($fullpathfile)) {
    $object->last_main_doc = $original_last_main_doc;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions