forked from mahdahar/crm-summit
fix: align activity uploads and attachments
This commit is contained in:
parent
318a78b1ff
commit
e2d29cd12a
@ -283,3 +283,8 @@ final class HealthTest extends CIUnitTestCase
|
||||
- PHP 8.1 or higher
|
||||
- Extensions required: `intl`, `mbstring`, `json`
|
||||
- MySQLi database driver by default
|
||||
|
||||
## Agent Preferences
|
||||
|
||||
- Prefer Serena tools (`serena_get_symbols_overview`, `serena_find_symbol`, `serena_search_for_pattern`) for codebase exploration before falling back to `Read`, `Glob`, or `Grep`.
|
||||
- Reserve `bash` for execution tasks (git, composer, php spark, etc.) and use Serena output to avoid unnecessary token use.
|
||||
|
||||
@ -1026,7 +1026,12 @@ class Activities extends Controller {
|
||||
echo 'Error: ' . $_FILES['file']['error'] . '<br>';
|
||||
}
|
||||
else {
|
||||
move_uploaded_file($_FILES['file']['tmp_name'], 'upload/' . $_FILES['file']['name'] );
|
||||
$subfolder = date('Y/m');
|
||||
$uploadDir = FCPATH . "upload/$subfolder/";
|
||||
if (!is_dir($uploadDir)) {
|
||||
mkdir($uploadDir, 0755, true);
|
||||
}
|
||||
move_uploaded_file($_FILES['file']['tmp_name'], $uploadDir . $_FILES['file']['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,10 +6,31 @@ $attachment = $attachment['attachment'];
|
||||
$filelist = $attachment;
|
||||
$file_array = explode (',', $filelist);
|
||||
|
||||
function resolve_attachment_relative_path($filename) {
|
||||
$uploadRoot = FCPATH . 'upload' . DIRECTORY_SEPARATOR;
|
||||
$pattern = $uploadRoot . '*' . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . $filename;
|
||||
$matches = @glob($pattern);
|
||||
if ($matches !== false) {
|
||||
foreach ($matches as $match) {
|
||||
if (is_file($match)) {
|
||||
$relative = str_replace('\\', '/', substr($match, strlen($uploadRoot)));
|
||||
return 'upload/' . $relative;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 'upload/' . $filename;
|
||||
}
|
||||
|
||||
$i = 1;
|
||||
foreach ($file_array as $value){
|
||||
if($i == 1) {echo "<b>Attachment : </b><br/>";}
|
||||
echo "<a href='".base_url()."upload/$value' target='_blank'>$value </a><br/>";
|
||||
$trimmedValue = trim($value);
|
||||
if ($trimmedValue === '') {
|
||||
$i++;
|
||||
continue;
|
||||
}
|
||||
$relativePath = resolve_attachment_relative_path($trimmedValue);
|
||||
echo "<a href='".base_url($relativePath)."' target='_blank'>$trimmedValue </a><br/>";
|
||||
$i++;
|
||||
}
|
||||
echo "<br/>";
|
||||
|
||||
@ -1178,6 +1178,9 @@ toggleCalibrateAccordion();
|
||||
// }
|
||||
</script>
|
||||
|
||||
<script src="<?=base_url();?>/assets/uppy/uppy-full.js"></script>
|
||||
<script>
|
||||
window.crmActivitiesUploadEndpoint = <?= json_encode(base_url('activities/upload')) ?>;
|
||||
</script>
|
||||
<script type="module" src="<?=base_url();?>/assets/uppy/uppy-old.js"></script>
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import { Uppy, Dashboard, XHRUpload } from "https://releases.transloadit.com/uppy/v3.15.0/uppy.min.mjs";
|
||||
|
||||
const uploadEndpoint = window.crmActivitiesUploadEndpoint ?? "/activities/upload";
|
||||
|
||||
// var uppy = new Uppy({
|
||||
// onBeforeFileAdded: (currentFile, files) => {
|
||||
|
||||
@ -22,14 +24,17 @@ import { Uppy, Dashboard, XHRUpload } from "https://releases.transloadit.com/upp
|
||||
var uppy = new Uppy({
|
||||
onBeforeFileAdded: (currentFile, files) => {
|
||||
|
||||
const month = (new Date().getMonth() + 1).toString().padStart(2, '0');
|
||||
const day = (new Date().getDate()).toString().padStart(2, '0');
|
||||
const now = new Date();
|
||||
const hours = now.getHours().toString().padStart(2, '0');
|
||||
const minutes = now.getMinutes().toString().padStart(2, '0');
|
||||
const seconds = now.getSeconds().toString().padStart(2, '0');
|
||||
const milliseconds = now.getMilliseconds().toString().padStart(3, '0');
|
||||
|
||||
// Menghilangkan koma (,) dalam nama file
|
||||
const sanitizedFileName = currentFile.name.replace(/,/g, '');
|
||||
|
||||
// TAHUN-BULAN-HARI_TIMESTAMP - NAMA_FILE
|
||||
const name = `${new Date().getFullYear()}-${month}-${day}_${Date.now()} - ${sanitizedFileName}`;
|
||||
// Format: HHMMSSmmm_FILENAME
|
||||
const name = `${hours}${minutes}${seconds}${milliseconds}_${sanitizedFileName}`;
|
||||
|
||||
// Membuat objek file yang dimodifikasi
|
||||
const modifiedFile = {
|
||||
@ -52,7 +57,7 @@ onBeforeFileAdded: (currentFile, files) => {
|
||||
height: 300,
|
||||
})
|
||||
|
||||
.use(XHRUpload, { endpoint: "/activities/upload", method: 'post' });
|
||||
.use(XHRUpload, { endpoint: uploadEndpoint, method: 'post' });
|
||||
|
||||
uppy.on("complete", (result) => {
|
||||
let array = result.successful;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user