File size: 5,894 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
<?php
// Include database connection and authentication
require_once 'includes/db_connect.php';
require_once 'includes/domain_utils.php';
require_once 'includes/auth_check.php';

// Validate domain parameter
if (!isset($_GET['domain']) || !is_numeric($_GET['domain'])) {
    header("Location: domains.php");
    exit;
}

$domainNumber = $_GET['domain'];
$domainTable = "domain_" . $domainNumber;

// Check if the domain table exists
$tableCheckQuery = "SHOW TABLES LIKE '$domainTable'";
$tableExists = $conn->query($tableCheckQuery)->num_rows > 0;

if (!$tableExists) {
    header("Location: domains.php");
    exit;
}

// Get domain descriptions
$domainDescriptions = getDomainDescriptions($conn);
$domainDescription = isset($domainDescriptions[$domainNumber]) ? $domainDescriptions[$domainNumber] : "Domain $domainNumber";

// Get the correct project name field for this domain
$projectNameField = getProjectNameField($conn, $domainTable);

// Get projects for this domain
$projectsQuery = "SELECT * FROM $domainTable ORDER BY Project_ID";
$projectsResult = $conn->query($projectsQuery);

// Include header
include 'includes/header.php';
?>

<div class="row mb-4">

    <div class="col-md-12">

        <nav aria-label="breadcrumb">

            <ol class="breadcrumb">

                <li class="breadcrumb-item"><a href="index.php">Home</a></li>

                <li class="breadcrumb-item"><a href="domains.php">Domains</a></li>

                <li class="breadcrumb-item active">Domain <?php echo $domainNumber; ?> Projects</li>

            </ol>

        </nav>

        <div class="d-flex justify-content-between align-items-center">

            <h2><i class="fas fa-layer-group me-2"></i> Projects in Domain <?php echo $domainNumber; ?></h2>

            <?php if ($is_faculty): ?>

            <div>

                <a href="project_add.php?domain=<?php echo urlencode($domainNumber); ?>" class="btn btn-primary">

                    <i class="fas fa-plus-circle me-1"></i> Add Project

                </a>

                <a href="project_manage.php?domain=<?php echo urlencode($domainNumber); ?>" class="btn btn-secondary">

                    <i class="fas fa-cog me-1"></i> Manage Projects

                </a>

            </div>

            <?php endif; ?>

        </div>

        <p class="lead"><?php echo htmlspecialchars($domainDescription); ?></p>

    </div>

</div>



<div class="row">

    <?php if ($projectsResult && $projectsResult->num_rows > 0): ?>

        <?php while ($project = $projectsResult->fetch_assoc()): ?>

            <div class="col-md-6 col-lg-4 mb-4">

                <div class="card h-100 shadow-sm <?php echo (isset($project['H/S']) && strtolower($project['H/S']) === 'h') ? 'hardware' : 'software'; ?> project-card">

                    <div class="card-body">

                        <h5 class="card-title"><?php echo htmlspecialchars($project[$projectNameField]); ?></h5>

                        <?php if (isset($project['H/S'])): ?>

                            <h6 class="card-subtitle mb-2 text-muted">

                                <span class="badge bg-<?php echo strtolower($project['H/S']) === 'h' ? 'warning' : 'info'; ?>">

                                    <?php echo strtolower($project['H/S']) === 'h' ? 'Hardware' : 'Software'; ?>

                                </span>

                            </h6>

                        <?php endif; ?>

                        <p class="card-text">

                            <?php if (isset($project['Description'])): ?>

                                <?php echo (strlen($project['Description']) > 100) ? htmlspecialchars(substr($project['Description'], 0, 100)) . '...' : htmlspecialchars($project['Description']); ?>

                            <?php else: ?>

                                <em>No description available</em>

                            <?php endif; ?>

                        </p>

                    </div>

                    <div class="card-footer bg-transparent d-flex justify-content-between align-items-center">

                        <a href="project_details.php?domain=<?php echo urlencode($domainNumber); ?>&id=<?php echo urlencode($project['Project_ID']); ?>" class="btn btn-sm btn-primary">

                            <i class="fas fa-info-circle me-1"></i> Details

                        </a>

                        <?php if ($is_faculty): ?>

                        <div class="btn-group btn-group-sm">

                            <a href="project_edit.php?domain=<?php echo urlencode($domainNumber); ?>&id=<?php echo urlencode($project['Project_ID']); ?>" class="btn btn-outline-success" title="Edit Project">

                                <i class="fas fa-edit"></i>

                            </a>

                            <a href="project_delete.php?domain=<?php echo urlencode($domainNumber); ?>&id=<?php echo urlencode($project['Project_ID']); ?>" class="btn btn-outline-danger" title="Delete Project">

                                <i class="fas fa-trash-alt"></i>

                            </a>

                        </div>

                        <?php endif; ?>

                    </div>

                </div>

            </div>

        <?php endwhile; ?>

    <?php else: ?>

        <div class="col-md-12">

            <div class="alert alert-info">

                <i class="fas fa-info-circle me-2"></i> No projects found in this domain.

                <?php if ($is_faculty): ?>

                <a href="project_add.php?domain=<?php echo urlencode($domainNumber); ?>" class="alert-link">Add a project</a> to get started.

                <?php endif; ?>

            </div>

        </div>

    <?php endif; ?>

</div>



<?php

// Include footer

include 'includes/footer.php';



// Close connection

$conn->close();

?>