Text

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

To implement the division of documents into 8 semesters, each with 9 subjects, and

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.

### Updated Directory Structure

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

### Updated Home Page

**index.php (in /home)**

```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');
?>
```

### Documents Page

**index.php (in /docs)**

```php
<?php
include('../includes/header.php');
include('../includes/db.php');

$semester = $_GET['semester'] ?? null;


$subject = $_GET['subject'] ?? null;

if ($semester && $subject) {


$stmt = $conn->prepare("SELECT * FROM documents WHERE semester = ? AND subject
= ?");
$stmt->bind_param("is", $semester, $subject);
$stmt->execute();
$result = $stmt->get_result();
}
?>

<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');
?>
```

### Upload Document Page (with type selection)

**upload.php (in /docs)**

```php
<?php
include('../includes/header.php');
include('../includes/db.php');
include('../includes/functions.php');
redirectIfNotLoggedIn();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {


$title = $_POST['title'];
$description = $_POST['description'];
$subject = $_POST['subject'];
$semester = $_POST['semester'];
$type = $_POST['type'];
$file = $_FILES['file']['name'];
$target_dir = "../uploads/";
$target_file = $target_dir . basename($file);

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');
?>
```

### Database Schema (MySQL) with document types

```sql
CREATE DATABASE document_management;

USE document_management;

CREATE TABLE users (


id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE documents (


id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
subject VARCHAR(100) NOT NULL,
semester INT NOT NULL,
type ENUM('exercise', 'corrected_exercise', 'lecture') NOT NULL,
file VARCHAR(255) NOT NULL,
user_id INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
```

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.

You might also like