Spaces:
Sleeping
Sleeping
| // 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(); | |
| ?> |