Text
Text
Text
further divided into three parts (Exercises, Corrected Exercises, and Lectures),
we'll add functionality to display this structure on the home page and the
documents page.
```
/root
/assets
/css
styles.css
/js
scripts.js
/includes
header.php
footer.php
db.php
functions.php
/uploads
/admin
index.php
/user
profile.php
/forum
index.php
/docs
index.php
upload.php
view.php
/help
faq.php
contact.php
/search
index.php
/home
index.php
/auth
register.php
login.php
logout.php
reset_password.php
index.php
README.md
```
```php
<?php
include('../includes/header.php');
include('../includes/db.php');
function getSubjectsBySemester($semester) {
return [
'Mathematics', 'Physics', 'Chemistry', 'Biology', 'History', 'Geography',
'Literature', 'Computer Science', 'Art'
]; // Replace with dynamic fetching from DB if needed
}
?>
<div class="container">
<h2>Home</h2>
<p>Welcome to the Document Management System home page.</p>
<h3>Semesters</h3>
<div class="semesters">
<?php for ($semester = 1; $semester <= 8; $semester++): ?>
<div class="semester">
<h4>Semester <?php echo $semester; ?></h4>
<ul>
<?php foreach (getSubjectsBySemester($semester) as $subject): ?
>
<li>
<a href="../docs/index.php?semester=<?php echo
$semester; ?>&subject=<?php echo urlencode($subject); ?>">
<?php echo $subject; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endfor; ?>
</div>
</div>
<?php
include('../includes/footer.php');
?>
```
```php
<?php
include('../includes/header.php');
include('../includes/db.php');
<div class="container">
<h2>Documents</h2>
<?php if ($semester && $subject): ?>
<h3>Semester <?php echo htmlspecialchars($semester); ?> - <?php echo
htmlspecialchars($subject); ?></h3>
<div class="document-sections">
<div class="section">
<h4>Exercises (Uncorrected)</h4>
<ul>
<?php while ($doc = $result->fetch_assoc()): ?>
<?php if ($doc['type'] == 'exercise'): ?>
<li><a href="view.php?id=<?php echo $doc['id']; ?>"><?
php echo $doc['title']; ?></a></li>
<?php endif; ?>
<?php endwhile; ?>
</ul>
</div>
<div class="section">
<h4>Corrected Exercises</h4>
<ul>
<?php while ($doc = $result->fetch_assoc()): ?>
<?php if ($doc['type'] == 'corrected_exercise'): ?>
<li><a href="view.php?id=<?php echo $doc['id']; ?>"><?
php echo $doc['title']; ?></a></li>
<?php endif; ?>
<?php endwhile; ?>
</ul>
</div>
<div class="section">
<h4>Lectures</h4>
<ul>
<?php while ($doc = $result->fetch_assoc()): ?>
<?php if ($doc['type'] == 'lecture'): ?>
<li><a href="view.php?id=<?php echo $doc['id']; ?>"><?
php echo $doc['title']; ?></a></li>
<?php endif; ?>
<?php endwhile; ?>
</ul>
</div>
</div>
<?php else: ?>
<p>Please select a semester and subject from the home page.</p>
<?php endif; ?>
</div>
<?php
include('../includes/footer.php');
?>
```
```php
<?php
include('../includes/header.php');
include('../includes/db.php');
include('../includes/functions.php');
redirectIfNotLoggedIn();
if (move_uploaded_file($_FILES['file']['tmp_name'], $target_file)) {
$stmt = $conn->prepare("INSERT INTO documents (title, description, subject,
semester, type, file, user_id) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssisii", $title, $description, $subject, $semester,
$type, $file, $_SESSION['user_id']);
if ($stmt->execute()) {
echo "Document uploaded successfully!";
} else {
echo "Error: " . $stmt->error;
}
} else {
echo "Error uploading file.";
}
}
?>
<div class="container">
<h2>Upload Document</h2>
<form action="upload.php" method="post" enctype="multipart/form-data">
<div>
<label for="title">Title:</label>
<input type="text" id="title" name="title" required>
</div>
<div>
<label for="description">Description:</label>
<textarea id="description" name="description" required></textarea>
</div>
<div>
<label for="subject">Subject:</label>
<input type="text" id="subject" name="subject" required>
</div>
<div>
<label for="semester">Semester:</label>
<input type="number" id="semester" name="semester" required>
</div>
<div>
<label for="type">Type:</label>
<select id="type" name="type" required>
<option value="exercise">Exercise (Uncorrected)</option>
<option value="corrected_exercise">Corrected Exercise</option>
<option value="lecture">Lecture</option>
</select>
</div>
<div>
<label for="file">File:</label>
<input type="file" id="file" name="file" required>
</div>
<button type="submit">Upload</button>
</form>
</div>
<?php
include('../includes/footer.php');
?>
```
```sql
CREATE DATABASE document_management;
USE document_management;
This code should now reflect the structure you require, with documents categorized
by semester, subject, and type, and displayed accordingly on the home and documents
pages. You can add these files to your respective folders and test the
functionality. Adjustments may be needed depending on your specific environment and
needs.