File size: 12,550 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?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 the parameters
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    header("Location: index.php");
    exit;
}

$projectId = $_GET['id'];
$domainNumber = isset($_GET['domain']) ? $_GET['domain'] : null;

// Get domain descriptions from utility function
$domainDescriptions = getDomainDescriptions($conn);

// If domain number is not provided, find it by searching all domain tables
if ($domainNumber === null) {
    $domainTables = getDomainTables($conn);
    
    foreach ($domainTables as $domainTable) {
        // Check for project in this domain
        $checkQuery = "SELECT * FROM $domainTable WHERE Project_ID = $projectId LIMIT 1";
        $checkResult = $conn->query($checkQuery);
        
        if ($checkResult && $checkResult->num_rows > 0) {
            $domainNumber = str_replace('domain_', '', $domainTable);
            break;
        }
    }
    
    // If still not found, redirect
    if ($domainNumber === null) {
        header("Location: index.php");
        exit;
    }
}

$domainTable = "domain_" . $domainNumber;

// Get domain description
$domainDescription = isset($domainDescriptions[$domainNumber]) ? $domainDescriptions[$domainNumber] : 'Domain ' . $domainNumber;

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

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

// Fetch project details
$projectQuery = "SELECT * FROM $domainTable WHERE Project_ID = $projectId LIMIT 1";
$projectResult = $conn->query($projectQuery);

if (!$projectResult || $projectResult->num_rows === 0) {
    header("Location: domain_projects.php?domain=$domainNumber");
    exit;
}

$project = $projectResult->fetch_assoc();

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

// Get project name using the correct field
$projectName = $project[$projectNameField];

// Fetch students associated with this project if students_info table exists
$studentsQuery = "SHOW TABLES LIKE 'students_info'";
$studentsTableExists = $conn->query($studentsQuery)->num_rows > 0;

$students = [];
if ($studentsTableExists) {
    $studentsQuery = "SELECT * FROM students_info WHERE Project_ID = $projectId";
    $studentsResult = $conn->query($studentsQuery);
    
    if ($studentsResult && $studentsResult->num_rows > 0) {
        while ($student = $studentsResult->fetch_assoc()) {
            $students[] = $student;
        }
    }
}

// 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>

                <?php if (!$is_student): ?>

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

                <li class="breadcrumb-item"><a href="domain_projects.php?domain=<?php echo $domainNumber; ?>">Domain <?php echo $domainNumber; ?></a></li>

                <?php endif; ?>

                <li class="breadcrumb-item active">Project <?php echo $projectId; ?></li>

            </ol>

        </nav>

    </div>

</div>



<div class="row mb-4">

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

        <div class="card shadow-sm">

            <div class="card-header bg-primary text-white d-flex justify-content-between align-items-center">

                <h4 class="mb-0"><i class="fas fa-project-diagram me-2"></i> Project Details</h4>

                <?php if ($is_faculty): ?>

                <div class="btn-group">

                    <a href="project_edit.php?domain=<?php echo urlencode($domainNumber); ?>&id=<?php echo urlencode($projectId); ?>" class="btn btn-light btn-sm">

                        <i class="fas fa-edit me-1"></i> Edit Project

                    </a>

                    <a href="project_delete.php?domain=<?php echo urlencode($domainNumber); ?>&id=<?php echo urlencode($projectId); ?>" class="btn btn-danger btn-sm">

                        <i class="fas fa-trash-alt me-1"></i> Delete Project

                    </a>

                </div>

                <?php endif; ?>

            </div>

            <div class="card-body">

                <h2 class="card-title"><?php echo htmlspecialchars($projectName); ?></h2>

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

                    <span class="badge bg-secondary me-2">Domain <?php echo htmlspecialchars($domainNumber); ?>: <?php echo htmlspecialchars($domainDescription); ?></span>

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

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

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

                        </span>

                    <?php endif; ?>

                </h6>

                

                <div class="row">

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

                        <div class="card mb-3">

                            <div class="card-header bg-light">

                                <h5 class="mb-0"><i class="fas fa-align-left me-2"></i> Description</h5>

                            </div>

                            <div class="card-body">

                                <p><?php echo nl2br(htmlspecialchars($project['Description'])); ?></p>

                            </div>

                        </div>

                        

                        <?php if (!empty($project['Email'])): ?>

                        <div class="card mb-3">

                            <div class="card-header bg-light">

                                <h5 class="mb-0"><i class="fas fa-envelope me-2"></i> Contact</h5>

                            </div>

                            <div class="card-body">

                                <p><strong>Email:</strong> <?php echo htmlspecialchars($project['Email']); ?></p>

                            </div>

                        </div>

                        <?php endif; ?>

                        

                        <?php if (!empty($project['Links'])): ?>

                        <div class="card mb-3">

                            <div class="card-header bg-light">

                                <h5 class="mb-0"><i class="fas fa-link me-2"></i> Resources</h5>

                            </div>

                            <div class="card-body">

                                <?php

                                    $links = explode(',', $project['Links']);

                                    foreach ($links as $link) {
                                        $link = trim($link);
                                        echo '<a href="' . htmlspecialchars($link) . '" class="btn btn-sm btn-outline-primary me-2 mb-2" target="_blank">';
                                        echo '<i class="fas fa-external-link-alt me-1"></i> View Resource</a>';
                                    }
                                ?>
                            </div>
                        </div>
                        <?php endif; ?>
                    </div>
                    
                    <div class="col-md-4">

                        <div class="card">

                            <div class="card-header bg-light">

                                <h5 class="mb-0"><i class="fas fa-info-circle me-2"></i> Project Info</h5>

                            </div>

                            <ul class="list-group list-group-flush">

                                <li class="list-group-item"><strong>Project ID:</strong> <?php echo htmlspecialchars($project['Project_ID']); ?></li>

                                <li class="list-group-item"><strong>Domain ID:</strong> <?php echo htmlspecialchars($project['Domain_ID']); ?></li>

                                <?php foreach ($project as $key => $value): 

                                    // Skip already displayed fields and empty values

                                    if (in_array($key, [$projectNameField, 'Description', 'Email', 'Links', 'Project_ID', 'Domain_ID', 'H/S']) || empty($value)) {
                                        continue;
                                    }
                                ?>
                                <li class="list-group-item"><strong><?php echo htmlspecialchars($key); ?>:</strong> <?php echo htmlspecialchars($value); ?></li>

                                <?php endforeach; ?>

                            </ul>

                        </div>

                    </div>

                </div>

            </div>

        </div>

    </div>

</div>



<?php if ($is_faculty && !empty($students)): ?>

<div class="row">

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

        <div class="card shadow-sm">

            <div class="card-header bg-info text-white">

                <h5 class="mb-0"><i class="fas fa-users me-2"></i> Team Members</h5>

            </div>

            <div class="card-body">

                <div class="table-responsive">

                    <table class="table table-striped table-hover">

                        <thead class="table-light">

                            <tr>

                                <th>Student ID</th>

                                <th>Name</th>

                                <th>Division</th>

                                <th>Roll No.</th>

                                <th>Email</th>

                                <th>Phone</th>

                            </tr>

                        </thead>

                        <tbody>

                            <?php foreach ($students as $student): ?>

                                <tr>

                                    <td><?php echo htmlspecialchars($student['Student_ID']); ?></td>

                                    <td><?php echo htmlspecialchars($student['Name']); ?></td>

                                    <td><?php echo htmlspecialchars($student['Division']); ?></td>

                                    <td><?php echo htmlspecialchars($student['Roll_No']); ?></td>

                                    <td><?php echo htmlspecialchars($student['Email_ID']); ?></td>

                                    <td><?php echo htmlspecialchars($student['Phone_Number']); ?></td>

                                </tr>

                            <?php endforeach; ?>

                        </tbody>

                    </table>

                </div>

            </div>

        </div>

    </div>

</div>

<?php elseif ($is_student && !empty($students)): ?>

<div class="row">

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

        <div class="card shadow-sm">

            <div class="card-header bg-info text-white">

                <h5 class="mb-0"><i class="fas fa-info-circle me-2"></i> Project Information</h5>

            </div>

            <div class="card-body">

                <div class="alert alert-info">

                    <i class="fas fa-info-circle me-2"></i> This project has team members assigned. Contact your faculty advisor for more information.

                </div>

            </div>

        </div>

    </div>

</div>

<?php endif; ?>



<?php if ($is_faculty): ?>

<div class="row mt-4">

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

        <div class="d-flex justify-content-end">

            <a href="project_manage.php" class="btn btn-secondary me-2">

                <i class="fas fa-list me-1"></i> All Projects

            </a>

            <a href="project_edit.php?domain=<?php echo urlencode($domainNumber); ?>&id=<?php echo urlencode($projectId); ?>" class="btn btn-primary me-2">

                <i class="fas fa-edit me-1"></i> Edit Project

            </a>

            <a href="project_delete.php?domain=<?php echo urlencode($domainNumber); ?>&id=<?php echo urlencode($projectId); ?>" class="btn btn-danger">

                <i class="fas fa-trash-alt me-1"></i> Delete Project

            </a>

        </div>

    </div>

</div>

<?php endif; ?>



<?php

// Include footer

include 'includes/footer.php';



// Close connection

$conn->close();

?>