From 47fe3598f415763327021a2fcf668ecff9cfbe75 Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Tue, 21 Apr 2026 14:47:20 +0700 Subject: [PATCH] fix: attachment link on email sent --- app/Controllers/Activities.php | 26 ++++++++++++++++++++++++-- app/Views/activities_compose.php | 2 +- app/Views/activities_detail.php | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/Controllers/Activities.php b/app/Controllers/Activities.php index 091378d..3737172 100644 --- a/app/Controllers/Activities.php +++ b/app/Controllers/Activities.php @@ -60,6 +60,8 @@ class Activities extends Controller { $attachment = 'upload/' . substr($attachment, 5); } + $attachment = preg_replace('#^(?:upload/)+#', 'upload/', $attachment); + if (strpos($attachment, 'upload/legacy/file/') === 0 || strpos($attachment, 'upload/') === 0) { return $attachment; } @@ -100,6 +102,25 @@ class Activities extends Controller { return implode(',', array_unique(array_filter($normalized))); } + protected function normalizeAttachmentListForExternalMailer(?string $attachments): string + { + $normalizedList = $this->normalizeAttachmentList($attachments); + if ($normalizedList === '') { + return ''; + } + + $items = array_filter(array_map('trim', explode(',', $normalizedList)), static function ($item) { + return $item !== ''; + }); + + $externalList = []; + foreach ($items as $item) { + $externalList[] = preg_replace('#^(?:upload/)+#', '', $item); + } + + return implode(',', array_unique(array_filter($externalList))); + } + protected function findFirstUploadedFile(array $files): ?UploadedFile { foreach ($files as $file) { @@ -1458,7 +1479,7 @@ class Activities extends Controller { $sql = "select subject, attachment,siteid from activities where actid='$actid'"; $query = $db->query($sql); $result = $query->getResultArray(); - $data['attachment'] = $result[0]['attachment']; + $data['attachment'] = $this->normalizeAttachmentList($result[0]['attachment']); $data['subject'] = $result[0]['subject']; $siteid = $result[0]['siteid']; @@ -1504,6 +1525,7 @@ class Activities extends Controller { $subject = $this->request->getVar('subject'); $message = $this->request->getVar('message'); $attachment = $this->normalizeAttachmentList($this->request->getVar('attachment')); + $attachmentForMailer = $this->normalizeAttachmentListForExternalMailer($attachment); // // $attachments = explode(',',$attachment); // /* @@ -1552,7 +1574,7 @@ class Activities extends Controller { 'bcc' => $bccs, 'subject' => $subject, 'message' => $message, - 'attachment' => $attachment, + 'attachment' => $attachmentForMailer, 'certificates' => $certificates ]; $jsonData = json_encode($data); diff --git a/app/Views/activities_compose.php b/app/Views/activities_compose.php index 296d01c..9ac5dce 100644 --- a/app/Views/activities_compose.php +++ b/app/Views/activities_compose.php @@ -106,7 +106,7 @@ foreach ($emails as $data) {