204 lines
8.6 KiB
PHP
204 lines
8.6 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;
|
|
}
|
|
|
|
require_once 'validators/xml_validator.php';
|
|
|
|
/**
|
|
* Scans the repository directory for eCTD sequences.
|
|
*
|
|
* @param string $repoPath The path to the repository.
|
|
* @return array A list of sequences found.
|
|
*/
|
|
function scanRepository($repoPath) {
|
|
$sequences = [];
|
|
if (!is_dir($repoPath)) {
|
|
return [];
|
|
}
|
|
|
|
$items = scandir($repoPath);
|
|
foreach ($items as $item) {
|
|
if ($item[0] === '.') {
|
|
continue;
|
|
}
|
|
$sequencePath = $repoPath . '/' . $item;
|
|
if (is_dir($sequencePath)) {
|
|
$xmlPath = $sequencePath . '/index.xml';
|
|
$productName = 'Unknown';
|
|
$status = 'Pending Validation';
|
|
|
|
if (file_exists($xmlPath)) {
|
|
$xml_content = file_get_contents($xmlPath);
|
|
$errors = XmlValidator::validate($xml_content);
|
|
|
|
if (empty($errors)) {
|
|
$status = 'Validated';
|
|
$xml = simplexml_load_string($xml_content);
|
|
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)) {
|
|
$productName = (string)$result[0];
|
|
}
|
|
}
|
|
} else {
|
|
$status = 'Validation Failed';
|
|
}
|
|
} else {
|
|
$status = 'Missing index.xml';
|
|
}
|
|
|
|
$sequences[] = [
|
|
'id' => $item,
|
|
'product' => $productName,
|
|
'status' => $status,
|
|
'last_scanned' => date('Y-m-d H:i:s'),
|
|
];
|
|
}
|
|
}
|
|
return $sequences;
|
|
}
|
|
|
|
// Define the repository path and scan it.
|
|
$repositoryPath = __DIR__ . '/repository';
|
|
$sequences = scanRepository($repositoryPath);
|
|
|
|
function getStatusBadgeClass($status) {
|
|
switch ($status) {
|
|
case 'Validated':
|
|
return 'bg-success';
|
|
case 'Validation Failed':
|
|
return 'bg-danger';
|
|
case 'Missing index.xml':
|
|
case 'Invalid XML':
|
|
return 'bg-danger';
|
|
case 'Pending Validation':
|
|
return 'bg-warning text-dark';
|
|
default:
|
|
return 'bg-secondary';
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<!-- SEO and Meta Tags -->
|
|
<title><?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'eCTD Submission Manager'); ?></title>
|
|
<meta name="description" content="<?php echo htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'Manage eCTD submissions and validate file structures efficiently.'); ?>">
|
|
<meta property="og:title" content="<?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'eCTD Submission Manager'); ?>">
|
|
<meta property="og:description" content="<?php echo htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'Manage eCTD submissions and validate file structures efficiently.'); ?>">
|
|
<meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
|
|
<meta name="twitter:card" content="summary_large_image">
|
|
<meta name="twitter:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
|
|
|
|
<!-- Bootstrap CSS -->
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<!-- Bootstrap Icons -->
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
|
|
<!-- Google Fonts (Inter) -->
|
|
<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&display=swap" rel="stylesheet">
|
|
|
|
<!-- Custom CSS -->
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
|
|
<!-- Header -->
|
|
<nav class="navbar navbar-expand-lg navbar-dark header-gradient shadow-sm">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="#">
|
|
<i class="bi bi-folder-check"></i>
|
|
<?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'eCTD Submission Manager'); ?>
|
|
</a>
|
|
<div class="d-flex">
|
|
<span class="navbar-text me-3">Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?>!</span>
|
|
<a href="logout.php" class="btn btn-outline-light">Logout</a>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<!-- Main Content -->
|
|
<main class="container main-container">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h2">Submissions Dashboard</h1>
|
|
<button id="scanRepoBtn" class="btn btn-primary d-flex align-items-center">
|
|
<span class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true" style="display: none;"></span>
|
|
<i class="bi bi-search"></i>
|
|
<span class="button-text ms-2">Scan Repository</span>
|
|
</button>
|
|
</div>
|
|
|
|
<?php if (isset($_GET['scan']) && $_GET['scan'] === 'success'): ?>
|
|
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
|
<strong>Success!</strong> The repository has been scanned and the dashboard is updated.
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Sequence ID</th>
|
|
<th>Product</th>
|
|
<th>Status</th>
|
|
<th>Last Scanned</th>
|
|
<th class="text-end">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($sequences as $sequence): ?>
|
|
<tr>
|
|
<td><strong><?php echo htmlspecialchars($sequence['id']); ?></strong></td>
|
|
<td><?php echo htmlspecialchars($sequence['product']); ?></td>
|
|
<td>
|
|
<span class="badge rounded-pill <?php echo getStatusBadgeClass($sequence['status']); ?>">
|
|
<?php echo htmlspecialchars($sequence['status']); ?>
|
|
</span>
|
|
</td>
|
|
<td><?php echo htmlspecialchars($sequence['last_scanned']); ?></td>
|
|
<td class="text-end">
|
|
<a href="sequence.php?id=<?php echo htmlspecialchars($sequence['id']); ?>" class="btn btn-outline-secondary btn-sm btn-action" title="View Details">
|
|
<i class="bi bi-eye"></i> View
|
|
</a>
|
|
<button class="btn btn-outline-primary btn-sm btn-action" title="Upload Files">
|
|
<i class="bi bi-upload"></i> Upload
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<!-- Bootstrap JS Bundle -->
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<!-- Custom JS -->
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
</body>
|
|
</html>
|