Full

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

Yes, you can use the previous files for the remaining parts of the website.

Here's
the complete set of files, including the updates for document management, to make
sure you have everything needed:

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

### Root index.php

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

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document Management System</title>
<link rel="stylesheet" href="assets/css/styles.css">
</head>
<body>
<div class="container">
<h1>Welcome to Document Management System</h1>
<p>Tsy misy manana ny ampy fa sambatra izay mifanampy</p>
<nav>
<ul>
<li><a href="home/index.php">Home</a></li>
<li><a href="docs/index.php">Documents</a></li>
<li><a href="forum/index.php">Forums</a></li>
<li><a href="help/faq.php">Help</a></li>
<li><a href="auth/login.php">Login</a></li>
</ul>
</nav>
<div class="content">
<h2>Tongasoa</h2>
<p>Explore the latest documents and participate in discussions.</p>
</div>
</div>
</body>
</html>

<?php
include('includes/footer.php');
?>
```

### header.php (in /includes)

```php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document Management System</title>
<link rel="stylesheet" href="../assets/css/styles.css">
<script src="../assets/js/scripts.js" defer></script>
</head>
<body>
<header>
<img src="https://via.placeholder.com/150" alt="Logo" class="logo">
<h1>Document Management System</h1>
</header>
```

### footer.php (in /includes)

```php
<footer>
<p>&copy; 2024 Document Management System. All rights reserved.</p>
</footer>
</body>
</html>
```

### db.php (in /includes)


```php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "document_management";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
```

### functions.php (in /includes)

```php
<?php
function isLoggedIn() {
return isset($_SESSION['user_id']);
}

function redirectIfNotLoggedIn() {
if (!isLoggedIn()) {
header('Location: ../auth/login.php');
exit();
}
}

function getUserById($id) {
global $conn;
$stmt = $conn->prepare("SELECT * FROM users WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
return $stmt->get_result()->fetch_assoc();
}
?>
```

### styles.css (in /assets/css)

```css
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}

header {
background-color: green;
color: white;
padding: 1em;
text-align: center;
}
footer {
background-color: black;
color: white;
text-align: center;
padding: 1em;
position: fixed;
bottom: 0;
width: 100%;
}

.container {
margin: 20px;
}

nav ul {
list-style: none;
padding: 0;
}

nav ul li {
display: inline;
margin-right: 10px;
}

nav ul li a {
text-decoration: none;
color: green;
}

nav ul li a:hover {
text-decoration: underline;
}

.content {
margin-top: 20px;
}

.semesters {
display: flex;
flex-wrap: wrap;
}

.semester {
margin: 10px;
padding: 10px;
border: 1px solid #ccc;
width: 200px;
}

.document-sections {
display: flex;
flex-wrap: wrap;
}

.section {
margin: 10px;
padding: 10px;
border: 1px solid #ccc;
width: 300px;
}
```

### scripts.js (in /assets/js)

```javascript
document.addEventListener("DOMContentLoaded", function() {
const forms = document.querySelectorAll('form');
forms.forEach(form => {
form.addEventListener('submit', function(event) {
// Basic client-side validation
const inputs = form.querySelectorAll('input[required],
textarea[required]');
inputs.forEach(input => {
if (!input.value) {
event.preventDefault();
alert('Please fill out all required fields.');
}
});
});
});

// Additional interactive elements can be added here


});
```

### register.php (in /auth)

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

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


$name = $_POST['name'];
$email = $_POST['email'];
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);

$stmt = $conn->prepare("INSERT INTO users (name, email, password) VALUES (?, ?,


?)");
$stmt->bind_param("sss", $name, $email, $password);

if ($stmt->execute()) {
echo "Registration successful!";
} else {
echo "Error: " . $stmt->error;
}
}
?>

<div class="container">
<h2>Register</h2>
<form action="register.php" method="post">
<div>
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
</div>
<div>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit">Register</button>
</form>
</div>

<?php
include('../includes/footer.php');
?>
```

### login.php (in /auth)

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

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


$email = $_POST['email'];
$password = $_POST['password'];

$stmt = $conn->prepare("SELECT id, password FROM users WHERE email = ?");


$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id, $hashed_password);

if ($stmt->num_rows > 0) {
$stmt->fetch();
if (password_verify($password, $hashed_password)) {
$_SESSION['user_id'] = $id;
header('Location: ../user/profile.php');
exit();
} else {
echo "Invalid email or password.";
}
} else {
echo "Invalid email or password.";
}
}
?>

<div class="container">
<h2>Login</h2>
<form action="login.php" method="post">
<div>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit">Login</button>
</form>
</div>

<?php
include('../includes/footer.php');
?>
```

### profile.php (in /user)

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

$user = getUserById($_SESSION['user_id']);
?>

<div class="container">
<h2>Profile</h2>
<p>Name: <?php echo $user['name']; ?></p>
<p>Email: <?php echo $user['email

']; ?></p>
<!-- Add more profile fields as necessary -->
</div>

<?php
include('../includes/footer.php');
?>
```

### 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("ssssssi", $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');
?>
```

### view.php (in /docs)

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

$doc_id = $_GET['id'];
$stmt = $conn->prepare("SELECT * FROM documents WHERE id = ?");
$stmt->bind_param("i", $doc_id);
$stmt->execute();
$document = $stmt->get_result()->fetch_assoc();
?>

<div class="container">
<h2><?php echo $document['title']; ?></h2>
<p><?php echo $document['description']; ?></p>
<embed src="../uploads/<?php echo $document['file']; ?>" type="application/pdf"
width="100%" height="600px" />
</div>

<?php
include('../includes/footer.php');
?>
```

### faq.php (in /help)

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

<div class="container">
<h2>FAQ</h2>
<p>Here you can find answers to the most frequently asked questions.</p>
</div>

<?php
include('../includes/footer.php');
?>
```

### contact.php (in /help)

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

<div class="container">
<h2>Contact Us</h2>
<form action="contact.php" method="post">
<div>
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
</div>
<div>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div>
<label for="message">Message:</label>
<textarea id="message" name="message" required></textarea>
</div>
<button type="submit">Send</button>
</form>
</div>

<?php
include('../includes/footer.php');
?>
```

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

### index.php (in /forum)

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

<div class="container">
<h2>Forum</h2>
<p>Join the discussion in our community forums.</p>
</div>

<?php
include('../includes/footer.php');
?>
```

### index.php (in /search)

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

<div class="container">
<h2>Search</h2>
<form action="index.php" method="get">
<input type="text" name="query" placeholder="Search for documents"
required>
<button type="submit">Search</button>
</form>
</div>

<?php
include('../includes/footer.php');
?>
```

### README.md

```markdown
# Document Management System

## Description
A comprehensive educational website focused on document management, user
engagement, and community discussions.

## Features
- User Registration and Authentication
- User Profiles
- Document Upload and Management
- Content Organization
- Discussion Forums
- Help and Support
- Administrative Tools
- Document Viewing and Interaction
- User Engagement
- Responsive Design
- Home Page Design
- Search and Filtering

## Installation
1. Clone the repository to your server.
2. Import the `document_management.sql` file into your MySQL database.
3. Update the `includes/db.php` file with your database credentials.
4. Replace the placeholder URLs for the logo and background image in
`includes/header.php`.
5. Access the website in your browser.

## Usage
- Register a new user account.
- Login and upload documents.
- View and interact with documents and discussions.

## Technologies Used
- HTML
- CSS
- JavaScript
- PHP
- MySQL
```

### 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)
);
```

### logout.php (in /auth)

```php
<?php
session_start();
session_unset();
session_destroy();
header('Location: login.php');
?>
```
### reset_password.php (in /auth)

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

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


$email = $_POST['email'];
$stmt = $conn->prepare("SELECT id FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();

if ($stmt->num_rows > 0) {
// Send reset password email (this is a placeholder, implement email
sending logic)
echo "A password reset link has been sent to your email.";
} else {
echo "No account found with that

email address.";
}
}
?>

<div class="container">
<h2>Reset Password</h2>
<form action="reset_password.php" method="post">
<div>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<button type="submit">Send Reset Link</button>
</form>
</div>

<?php
include('../includes/footer.php');
?>
```

This setup should now provide you with a fully functional educational document
management system. Add these files to their respective folders and test the
functionality on your local server or web server. Adjustments may be needed
depending on your specific environment and requirements.

You might also like