205 lines
7.9 KiB
PHP
205 lines
7.9 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
// If the user is not logged in, redirect to the login page.
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
// sequence.php
|
|
|
|
require_once 'validators/xml_validator.php';
|
|
|
|
function getSequenceDetails($sequenceId) {
|
|
$basePath = __DIR__ . '/repository';
|
|
$sequencePath = $basePath . '/' . $sequenceId;
|
|
|
|
if (!is_dir($sequencePath)) {
|
|
return null;
|
|
}
|
|
|
|
$details = [
|
|
'id' => $sequenceId,
|
|
'productName' => 'N/A',
|
|
'status' => 'Unknown',
|
|
'files' => [],
|
|
'xml_content' => '',
|
|
'validation_errors' => []
|
|
];
|
|
|
|
// List files in the directory
|
|
$files = scandir($sequencePath);
|
|
$details['files'] = array_diff($files, ['.', '..']);
|
|
|
|
$xmlPath = $sequencePath . '/index.xml';
|
|
if (file_exists($xmlPath)) {
|
|
$xmlContent = file_get_contents($xmlPath);
|
|
$details['xml_content'] = htmlspecialchars($xmlContent);
|
|
$errors = XmlValidator::validate($xmlContent);
|
|
|
|
if (empty($errors)) {
|
|
$details['status'] = 'Validated';
|
|
$xml = simplexml_load_string($xmlContent);
|
|
if ($xml) {
|
|
// Correctly parsing with namespace
|
|
$namespaces = $xml->getNamespaces(true);
|
|
$ectd_ns = isset($namespaces['ectd']) ? $namespaces['ectd'] : 'urn:ectd-org:ectd';
|
|
$xml->registerXPathNamespace('ectd', $ectd_ns);
|
|
|
|
// Example of fetching a value, adjust xpath as per actual XML structure
|
|
$result = $xml->xpath('//product-name'); // Simplified xpath
|
|
if (empty($result)) {
|
|
// Try another common path
|
|
$result = $xml->xpath('//admin/product-name');
|
|
}
|
|
|
|
if (!empty($result)) {
|
|
$details['productName'] = (string)$result[0];
|
|
} else {
|
|
$details['productName'] = 'N/A';
|
|
}
|
|
}
|
|
} else {
|
|
$details['status'] = 'Validation Failed';
|
|
$details['validation_errors'] = $errors;
|
|
}
|
|
} else {
|
|
$details['status'] = 'Missing index.xml';
|
|
}
|
|
|
|
return $details;
|
|
}
|
|
|
|
$sequenceId = isset($_GET['id']) ? basename($_GET['id']) : '';
|
|
$sequenceDetails = null;
|
|
$uploadMessage = '';
|
|
|
|
// Handle file upload
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['sequenceFile'])) {
|
|
if (!empty($sequenceId) && is_numeric($sequenceId)) {
|
|
$targetDir = __DIR__ . '/repository/' . $sequenceId . '/';
|
|
if (!is_dir($targetDir)) {
|
|
mkdir($targetDir, 0775, true);
|
|
}
|
|
$targetFile = $targetDir . basename($_FILES['sequenceFile']['name']);
|
|
|
|
if (move_uploaded_file($_FILES['sequenceFile']['tmp_name'], $targetFile)) {
|
|
$uploadMessage = '<div class="alert alert-success mt-3">File uploaded successfully.</div>';
|
|
} else {
|
|
$uploadMessage = '<div class="alert alert-danger mt-3">Sorry, there was an error uploading your file.</div>';
|
|
}
|
|
} else {
|
|
$uploadMessage = '<div class="alert alert-danger mt-3">Invalid sequence ID for upload.</div>';
|
|
}
|
|
}
|
|
|
|
|
|
if (!empty($sequenceId) && is_numeric($sequenceId)) {
|
|
$sequenceDetails = getSequenceDetails($sequenceId);
|
|
}
|
|
|
|
// Determine badge class based on status
|
|
$statusClass = 'bg-secondary';
|
|
if (isset($sequenceDetails['status'])) {
|
|
switch ($sequenceDetails['status']) {
|
|
case 'Validated':
|
|
$statusClass = 'bg-success';
|
|
break;
|
|
case 'Validation Failed':
|
|
$statusClass = 'bg-danger';
|
|
break;
|
|
case 'Missing index.xml':
|
|
$statusClass = 'bg-warning text-dark';
|
|
break;
|
|
}
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Sequence Details - eCTD Submission Manager</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
|
|
<header class="header bg-primary text-white">
|
|
<div class="container d-flex justify-content-between align-items-center">
|
|
<h1 class="h4 mb-0">eCTD Submission Manager</h1>
|
|
<a href="index.php" class="btn btn-light">← Back to Dashboard</a>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="container mt-4">
|
|
<?php if ($sequenceDetails): ?>
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h2 class="h5 mb-0">Sequence Details: <?php echo htmlspecialchars($sequenceDetails['id']); ?></h2>
|
|
</div>
|
|
<div class="card-body">
|
|
<p><strong>Product Name:</strong> <?php echo htmlspecialchars($sequenceDetails['productName']); ?></p>
|
|
<p><strong>Status:</strong> <span class="badge <?php echo $statusClass; ?>"><?php echo htmlspecialchars($sequenceDetails['status']); ?></span></p>
|
|
|
|
<?php if (!empty($sequenceDetails['validation_errors'])): ?>
|
|
<h3 class="h6 mt-4">Validation Report</h3>
|
|
<div class="alert alert-danger">
|
|
<ul class="mb-0">
|
|
<?php foreach ($sequenceDetails['validation_errors'] as $error): ?>
|
|
<li><?php echo htmlspecialchars($error); ?></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<h3 class="h6 mt-4">Files in Sequence</h3>
|
|
<?php if (!empty($sequenceDetails['files'])): ?>
|
|
<ul class="list-group">
|
|
<?php foreach ($sequenceDetails['files'] as $file): ?>
|
|
<li class="list-group-item"><?php echo htmlspecialchars($file); ?></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php else: ?>
|
|
<p>No files found in this sequence.</p>
|
|
<?php endif; ?>
|
|
|
|
<h3 class="h6 mt-4">index.xml Content</h3>
|
|
<?php if (!empty($sequenceDetails['xml_content'])): ?>
|
|
<pre class="bg-light p-3 rounded"><code><?php echo $sequenceDetails['xml_content']; ?></code></pre>
|
|
<?php else: ?>
|
|
<p>No index.xml content to display.</p>
|
|
<?php endif; ?>
|
|
|
|
<hr class="my-4">
|
|
|
|
<h3 class="h6 mt-4">Upload File to Sequence</h3>
|
|
<?php echo $uploadMessage; ?>
|
|
<form action="sequence.php?id=<?php echo htmlspecialchars($sequenceId); ?>" method="post" enctype="multipart/form-data">
|
|
<div class="mb-3">
|
|
<label for="sequenceFile" class="form-label">Select file</label>
|
|
<input class="form-control" type="file" id="sequenceFile" name="sequenceFile" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Upload File</button>
|
|
</form>
|
|
|
|
</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="alert alert-danger" role="alert">
|
|
<strong>Error:</strong> Invalid or missing sequence ID.
|
|
</div>
|
|
<?php endif; ?>
|
|
</main>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js"></script>
|
|
</body>
|
|
</html>
|