diff --git a/assets/uploads/xrays/1773570971_ss.pdf b/assets/uploads/xrays/1773570971_ss.pdf new file mode 100644 index 0000000..9746ddc Binary files /dev/null and b/assets/uploads/xrays/1773570971_ss.pdf differ diff --git a/assets/uploads/xrays/1773582607_69b6b90f692da_scale.jfif b/assets/uploads/xrays/1773582607_69b6b90f692da_scale.jfif new file mode 100644 index 0000000..6c84eda Binary files /dev/null and b/assets/uploads/xrays/1773582607_69b6b90f692da_scale.jfif differ diff --git a/assets/uploads/xrays/1773582628_69b6b9245162b_ورد1.jfif b/assets/uploads/xrays/1773582628_69b6b9245162b_ورد1.jfif new file mode 100644 index 0000000..179e010 Binary files /dev/null and b/assets/uploads/xrays/1773582628_69b6b9245162b_ورد1.jfif differ diff --git a/db/migrations/20260315_change_xray_attachment_to_text.sql b/db/migrations/20260315_change_xray_attachment_to_text.sql new file mode 100644 index 0000000..05d6df1 --- /dev/null +++ b/db/migrations/20260315_change_xray_attachment_to_text.sql @@ -0,0 +1 @@ +ALTER TABLE xray_inquiry_items MODIFY COLUMN attachment LONGTEXT; diff --git a/drugs_groups.php b/drugs_groups.php index e290748..d73cf32 100644 --- a/drugs_groups.php +++ b/drugs_groups.php @@ -7,6 +7,15 @@ $lang = $_SESSION['lang'] ?? 'en'; require_once __DIR__ . '/includes/actions.php'; require_once __DIR__ . '/includes/common_data.php'; -require_once __DIR__ . '/includes/layout/header.php'; + +$is_ajax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'); + +if (!$is_ajax) { + require_once __DIR__ . '/includes/layout/header.php'; +} + require_once __DIR__ . '/includes/pages/drugs_groups.php'; -require_once __DIR__ . '/includes/layout/footer.php'; + +if (!$is_ajax) { + require_once __DIR__ . '/includes/layout/footer.php'; +} \ No newline at end of file diff --git a/includes/actions.php b/includes/actions.php index 73b5278..73687b1 100644 --- a/includes/actions.php +++ b/includes/actions.php @@ -70,6 +70,31 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } return null; } + + function upload_multiple_files_key($key_name, $target_dir = "assets/uploads/") { + $uploaded = []; + if (!isset($_FILES[$key_name])) return []; + + $files = $_FILES[$key_name]; + // Normalize array structure + if (is_array($files['name'])) { + $count = count($files['name']); + if (!is_dir(__DIR__ . "/../" . $target_dir)) { + mkdir(__DIR__ . "/../" . $target_dir, 0775, true); + } + for ($i = 0; $i < $count; $i++) { + if ($files['error'][$i] === UPLOAD_ERR_OK) { + $filename = time() . "_" . uniqid() . "_" . basename($files['name'][$i]); + $target_file = $target_dir . $filename; + if (move_uploaded_file($files['tmp_name'][$i], __DIR__ . "/../" . $target_file)) { + $uploaded[] = ['name' => $files['name'][$i], 'path' => $target_file]; + } + } + } + } + return $uploaded; + } + $lang = $_SESSION['lang'] ?? 'en'; $redirect = false; @@ -650,6 +675,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } elseif ($_POST['action'] === 'add_xray_inquiry') { $patient_name = $_POST['patient_name'] ?? ''; $xray_ids = $_POST['xray_ids'] ?? []; + $row_indices = $_POST['row_indices'] ?? []; // Maps array index to UI row index $results = $_POST['results'] ?? []; $source = $_POST['source'] ?? 'Internal'; $date = $_POST['inquiry_date'] ?: date('Y-m-d H:i'); @@ -664,8 +690,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $testStmt = $db->prepare("INSERT INTO xray_inquiry_items (inquiry_id, xray_id, result, attachment) VALUES (?, ?, ?, ?)"); foreach ($xray_ids as $index => $tid) { if ($tid) { - $attachment = upload_file($_FILES['attachments'] ?? null, $index, "assets/uploads/xrays/"); - $testStmt->execute([$inquiry_id, $tid, $results[$index] ?? '', $attachment]); + $rowIndex = $row_indices[$index] ?? $index; + $files = upload_multiple_files_key("new_attachments_" . $rowIndex, "assets/uploads/xrays/"); + $attachmentJson = !empty($files) ? json_encode($files) : ''; + $testStmt->execute([$inquiry_id, $tid, $results[$index] ?? '', $attachmentJson]); } } } @@ -677,7 +705,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $id = $_POST['id'] ?? ''; $patient_name = $_POST['patient_name'] ?? ''; $xray_ids = $_POST['xray_ids'] ?? []; - $existing_attachments = $_POST['existing_attachments'] ?? []; + $row_indices = $_POST['row_indices'] ?? []; $results = $_POST['results'] ?? []; $source = $_POST['source'] ?? 'Internal'; $date = $_POST['inquiry_date'] ?: date('Y-m-d H:i'); @@ -693,8 +721,26 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $testStmt = $db->prepare("INSERT INTO xray_inquiry_items (inquiry_id, xray_id, result, attachment) VALUES (?, ?, ?, ?)"); foreach ($xray_ids as $index => $tid) { if ($tid) { - $attachment = upload_file($_FILES['attachments'] ?? null, $index, "assets/uploads/xrays/") ?: ($existing_attachments[$index] ?? null); - $testStmt->execute([$id, $tid, $results[$index] ?? '', $attachment]); + $rowIndex = $row_indices[$index] ?? $index; + + // Get new files + $newFiles = upload_multiple_files_key("new_attachments_" . $rowIndex, "assets/uploads/xrays/"); + + // Get existing files + $existingFiles = []; + if (isset($_POST['existing_attachments_' . $rowIndex])) { + foreach ($_POST['existing_attachments_' . $rowIndex] as $fileJson) { + $file = json_decode($fileJson, true); + if ($file) { + $existingFiles[] = $file; + } + } + } + + $allFiles = array_merge($existingFiles, $newFiles); + $attachmentJson = !empty($allFiles) ? json_encode($allFiles) : ''; + + $testStmt->execute([$id, $tid, $results[$index] ?? '', $attachmentJson]); } } } @@ -1022,4 +1068,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { header("Location: " . $_SERVER['REQUEST_URI']); exit; } -} \ No newline at end of file +} diff --git a/includes/layout/footer.php b/includes/layout/footer.php index 9542a6e..46d94eb 100644 --- a/includes/layout/footer.php +++ b/includes/layout/footer.php @@ -4,6 +4,53 @@ + +
+