Spaces:
Sleeping
Sleeping
File size: 7,196 Bytes
102fe5c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | <?php
// Include database connection
require_once 'includes/db_connect.php';
require_once 'includes/domain_utils.php';
require_once 'includes/auth_check.php';
// Get all domains using the utility function
$domainTables = getDomainTables($conn);
$domainCount = count($domainTables);
// Get project count using the utility function
$projectCount = getTotalProjectCount($conn);
// Get student information if available
$studentCountQuery = "SHOW TABLES LIKE 'students_info'";
$studentTableExists = $conn->query($studentCountQuery)->num_rows > 0;
$studentCount = "N/A";
if ($studentTableExists) {
$countStudentsQuery = "SELECT COUNT(*) as student_count FROM students_info";
$countStudentsResult = $conn->query($countStudentsQuery);
if ($countStudentsResult && $countStudentsResult->num_rows > 0) {
$studentCount = $countStudentsResult->fetch_assoc()['student_count'];
}
}
// Get recent projects from all domains
$recentProjects = [];
foreach ($domainTables as $tableName) {
$domainNumber = str_replace('domain_', '', $tableName);
// Get the correct project name field
$projectNameField = getProjectNameField($conn, $tableName);
$recentProjectsQuery = "SELECT *, '$domainNumber' as domain_number FROM $tableName ORDER BY Project_ID DESC LIMIT 3";
$recentProjectsResult = $conn->query($recentProjectsQuery);
if ($recentProjectsResult && $recentProjectsResult->num_rows > 0) {
while ($project = $recentProjectsResult->fetch_assoc()) {
$project['project_name_field'] = $projectNameField;
$recentProjects[] = $project;
}
}
}
// Sort recent projects by ID in descending order and limit to 5
usort($recentProjects, function($a, $b) {
return intval($b['Project_ID']) - intval($a['Project_ID']);
});
$recentProjects = array_slice($recentProjects, 0, 5);
// Get domain descriptions
$domainDescriptions = getDomainDescriptions($conn);
// Include header
include 'includes/header.php';
?>
<div class="row mb-4">
<div class="col-md-12">
<div class="card bg-primary text-white">
<div class="card-body">
<h2 class="card-title">Welcome to the Domain Management System!</h2>
<p class="card-text">This system provides access to projects, domains, and student information from our database.</p>
<?php if (isset($_SESSION['user_type'])): ?>
<p class="card-text">Logged in as: <?php echo $_SESSION['username']; ?> (<?php echo ucfirst($_SESSION['user_type']); ?>)</p>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="row mb-4">
<div class="col-md-4">
<div class="card text-center mb-3 shadow-sm">
<div class="card-body">
<i class="fas fa-layer-group fa-3x mb-3 text-primary"></i>
<h5 class="card-title">Domains</h5>
<p class="card-text display-4"><?php echo $domainCount; ?></p>
<a href="domains.php" class="btn btn-primary">View All Domains</a>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-center mb-3 shadow-sm">
<div class="card-body">
<i class="fas fa-project-diagram fa-3x mb-3 text-primary"></i>
<h5 class="card-title">Projects</h5>
<p class="card-text display-4"><?php echo $projectCount; ?></p>
<a href="projects.php" class="btn btn-primary">View All Projects</a>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-center mb-3 shadow-sm">
<div class="card-body">
<i class="fas fa-user-graduate fa-3x mb-3 text-primary"></i>
<h5 class="card-title">Students</h5>
<p class="card-text display-4"><?php echo $studentCount; ?></p>
<a href="students.php" class="btn btn-primary">View All Students</a>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="card shadow-sm">
<div class="card-header bg-dark text-white">
<h5 class="mb-0"><i class="fas fa-clock mr-2"></i> Recent Projects</h5>
</div>
<div class="card-body">
<?php if (!empty($recentProjects)): ?>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="thead-light">
<tr>
<th>Project ID</th>
<th>Project Name</th>
<th>Type</th>
<th>Domain</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($recentProjects as $project):
// Get project name using the correct field
$projectNameField = $project['project_name_field'];
$projectName = $project[$projectNameField];
$domainNumber = $project['domain_number'];
$domainDesc = isset($domainDescriptions[$domainNumber]) ? $domainDescriptions[$domainNumber] : 'Domain ' . $domainNumber;
?>
<tr>
<td><?php echo $project['Project_ID']; ?></td>
<td><?php echo $projectName; ?></td>
<td><span class="badge <?php echo $project['H/S'] === 'Hardware' ? 'bg-danger' : 'bg-success'; ?>"><?php echo $project['H/S']; ?></span></td>
<td>Domain <?php echo $domainNumber; ?>: <?php echo $domainDesc; ?></td>
<td>
<a href="project_details.php?domain=<?php echo $domainNumber; ?>&id=<?php echo $project['Project_ID']; ?>" class="btn btn-sm btn-info">
<i class="fas fa-eye"></i> View Details
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<div class="alert alert-info">
<i class="fas fa-info-circle"></i> No projects found.
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php
// Include footer
include 'includes/footer.php';
// Close connection
$conn->close();
?> |