harshdhane's picture
Upload 10 files
a8a001c verified
Raw
History Blame Contribute Delete
41.5 kB
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Educational Resource Management System</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Roboto', sans-serif;
line-height: 1.6;
background-color: #f4f7f6;
color: #333;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
background-color: #2c3e50;
color: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.header h1 {
margin: 0;
font-size: 1.8rem;
}
.header a {
color: white;
text-decoration: none;
transition: color 0.3s ease;
}
.header a:hover {
color: #3498db;
}
.user-welcome {
background-color: #ecf0f1;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
text-align: center;
}
.navigation {
display: flex;
justify-content: center;
margin-bottom: 20px;
}
.nav-list {
display: flex;
list-style-type: none;
gap: 20px;
}
.nav-list li a {
text-decoration: none;
color: #2c3e50;
padding: 10px 15px;
border-radius: 6px;
transition: all 0.3s ease;
background-color: #ecf0f1;
display: inline-block;
}
.nav-list li a:hover {
background-color: #3498db;
color: white;
transform: translateY(-3px);
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.logout-btn {
background-color: #e74c3c;
color: white;
text-decoration: none;
padding: 10px 15px;
border-radius: 6px;
transition: background-color 0.3s ease;
}
.logout-btn:hover {
background-color: #c0392b;
}
.dashboard-content {
background-color: white;
border-radius: 8px;
padding: 20px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.dashboard-content h2 {
color: #2c3e50;
margin-bottom: 15px;
text-align: center;
}
.quick-stats {
display: flex;
justify-content: space-around;
margin-top: 20px;
}
.stat-box {
background-color: #ecf0f1;
padding: 15px;
border-radius: 8px;
text-align: center;
width: 200px;
}
@media (max-width: 768px) {
.header {
flex-direction: column;
text-align: center;
}
.nav-list {
flex-direction: column;
align-items: center;
}
.quick-stats {
flex-direction: column;
align-items: center;
gap: 15px;
}
}
</style>
</head>
<body>
<?php
session_start();
if (!isset($_SESSION['username'])) {
header('Location: login.php');
exit();
}
$username = $_SESSION['username'];
$user_type = $_SESSION['user_type'];
?>
<div class="container">
<div class="header">
<h1><a href="index.php">Educational Resource Management System</a></h1>
<a href="logout.php" class="logout-btn">Logout</a>
</div>
<div class="user-welcome">
<h2>Welcome, <?php echo htmlspecialchars($username); ?>!</h2>
<p>You are logged in as a <?php echo htmlspecialchars($user_type); ?></p>
</div>
<nav>
<ul class="nav-list">
<?php if ($user_type === 'admin'): ?>
<li><a href="add_resource.php">Add Resource</a></li>
<?php endif; ?>
<li><a href="view_resources.php">View Resources</a></li>
</ul>
</nav>
<div class="dashboard-content">
<h2>Dashboard Overview</h2>
<div class="quick-stats">
<div class="stat-box">
<h3>Total Resources</h3>
<?php
include 'db.php';
$resource_count_query = "SELECT COUNT(*) as count FROM resources";
$resource_count_result = $conn->query($resource_count_query);
$resource_count = $resource_count_result->fetch_assoc()['count'];
echo "<p>$resource_count</p>";
?>
</div>
<div class="stat-box">
<h3>User Type</h3>
<p><?php echo ucfirst(htmlspecialchars($user_type)); ?></p>
</div>
<div class="stat-box">
<h3>Last Login</h3>
<p><?php echo date('Y-m-d H:i:s'); ?></p>
</div>
</div>
</div>
</div>
</body>
</html>
login.php
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
include 'db.php';
$username = $_POST['username'];
$password = $_POST['password'];
$user_type = $_POST['user_type'];
$sql = "SELECT * FROM users WHERE username = '$username' AND user_type = '$user_type'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
if (password_verify($password, $row['password'])) {
$_SESSION['username'] = $row['username'];
$_SESSION['user_type'] = $row['user_type'];
header('Location: index.php');
exit();
} else {
$error = "Invalid username or password.";
}
} else {
$error = "Invalid username, password, or user type.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background: linear-gradient(to right, #1d3557, #457b9d);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
width: 350px;
text-align: center;
}
.tabs {
display: flex;
justify-content: space-around;
margin-bottom: 20px;
}
.tabs button {
background: none;
border: none;
padding: 10px;
cursor: pointer;
font-size: 16px;
font-weight: bold;
color: #333;
}
.tabs button.active {
color: #1d3557;
border-bottom: 2px solid #1d3557;
}
.form {
display: none;
}
.form.active {
display: block;
}
.form input {
width: 90%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 5px;
}
.form button {
width: 95%;
padding: 10px;
margin: 10px 0;
background: #1d3557;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
.form button:hover {
background: #457b9d;
}
.form a {
display: block;
color: #1d3557;
text-decoration: none;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h2>Login Form</h2>
<div class="tabs">
<button id="adminTab" class="active">Admin Login</button>
<button id="studentTab">Student Login</button>
</div>
<form id="adminForm" class="form active" method="POST" action="">
<input type="text" placeholder="Admin Username" name="username" required><br>
<input type="password" placeholder="Password" name="password" required><br>
<input type="hidden" name="user_type" value="admin">
<button type="submit">Login</button>
<a href="signup.php">Don't have an account? Sign up</a>
</form>
<form id="studentForm" class="form" method="POST" action="">
<input type="text" placeholder="Student Username" name="username" required><br>
<input type="password" placeholder="Password" name="password" required><br>
<input type="hidden" name="user_type" value="student">
<button type="submit">Login</button>
<a href="signup.php">Don't have an account? Sign up</a>
</form>
<?php if (isset($error)) echo "<p style='color: red;'>$error</p>"; ?>
</div>
<script>
const adminTab = document.getElementById('adminTab');
const studentTab = document.getElementById('studentTab');
const adminForm = document.getElementById('adminForm');
const studentForm = document.getElementById('studentForm');
adminTab.addEventListener('click', () => {
adminTab.classList.add('active');
studentTab.classList.remove('active');
adminForm.classList.add('active');
studentForm.classList.remove('active');
});
studentTab.addEventListener('click', () => {
studentTab.classList.add('active');
adminTab.classList.remove('active');
studentForm.classList.add('active');
adminForm.classList.remove('active');
});
</script>
</body>
</html>
logout.php
<?php
session_start();
session_destroy();
header('Location: login.php');
exit();
?>
signup.php
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
include 'db.php';
$username = $_POST['username'];
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
$user_type = $_POST['user_type'];
if ($password !== $confirm_password) {
echo "<script>alert('Passwords do not match!'); window.history.back();</script>";
exit;
}
$hashed_password = password_hash($password, PASSWORD_BCRYPT);
$sql = "INSERT INTO users (username, password, user_type) VALUES ('$username', '$hashed_password', '$user_type')";
if ($conn->query($sql) === TRUE) {
header('Location: login.php');
} else {
echo "Error: " . $conn->error;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Signup</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background: linear-gradient(to right, #1d3557, #457b9d);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
width: 350px;
text-align: center;
}
.tabs {
display: flex;
justify-content: space-around;
margin-bottom: 20px;
}
.tabs button {
background: none;
border: none;
padding: 10px;
cursor: pointer;
font-size: 16px;
font-weight: bold;
color: #333;
}
.tabs button.active {
color: #1d3557;
border-bottom: 2px solid #1d3557;
}
.form {
display: none;
}
.form.active {
display: block;
}
.form input {
width: 90%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 5px;
}
.form button {
width: 95%;
padding: 10px;
margin: 10px 0;
background: #1d3557;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
.form button:hover {
background: #457b9d;
}
.form a {
display: block;
color: #1d3557;
text-decoration: none;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h2>Signup Form</h2>
<div class="tabs">
<button id="adminTab" class="active" onclick="showForm('admin')">Admin Signup</button>
<button id="studentTab" onclick="showForm('student')">Student Signup</button>
</div>
<form id="adminForm" class="form active" method="POST" action="">
<input type="text" name="username" placeholder="Admin Username" required>
<input type="password" name="password" id="adminPassword" placeholder="Password" required>
<input type="password" name="confirm_password" id="adminConfirmPassword" placeholder="Confirm Password" required>
<input type="hidden" name="user_type" value="admin">
<button type="submit" onclick="return validatePasswords('adminPassword', 'adminConfirmPassword')">Signup</button>
<a href="login.php">Already have an account? Login</a>
</form>
<form id="studentForm" class="form" method="POST" action="">
<input type="text" name="username" placeholder="Student Username" required>
<input type="password" name="password" id="studentPassword" placeholder="Password" required>
<input type="password" name="confirm_password" id="studentConfirmPassword" placeholder="Confirm Password" required>
<input type="hidden" name="user_type" value="student">
<button type="submit" onclick="return validatePasswords('studentPassword', 'studentConfirmPassword')">Signup</button>
<a href="login.php">Already have an account? Login</a>
</form>
</div>
<script>
function showForm(type) {
const adminTab = document.getElementById('adminTab');
const studentTab = document.getElementById('studentTab');
const adminForm = document.getElementById('adminForm');
const studentForm = document.getElementById('studentForm');
if (type === 'admin') {
adminTab.classList.add('active');
studentTab.classList.remove('active');
adminForm.classList.add('active');
studentForm.classList.remove('active');
} else {
studentTab.classList.add('active');
adminTab.classList.remove('active');
studentForm.classList.add('active');
adminForm.classList.remove('active');
}
}
function validatePasswords(passwordId, confirmPasswordId) {
const password = document.getElementById(passwordId).value;
const confirmPassword = document.getElementById(confirmPasswordId).value;
if (password !== confirmPassword) {
alert('Passwords do not match!');
return false;
}
return true;
}
</script>
</body>
</html>
view_resources.php
<?php
include 'db.php';
session_start();
if (!isset($_SESSION['username'])) {
header('Location: login.php');
exit();
}
$username = $_SESSION['username'];
$user_type = $_SESSION['user_type'];
// Handle delete resource request
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_resource'])) {
$resource_id = (int)$_POST['delete_resource'];
$delete_sql = "DELETE FROM resources WHERE id = ?";
$stmt = $conn->prepare($delete_sql);
$stmt->bind_param('i', $resource_id);
if ($stmt->execute()) {
$success_message = "Resource deleted successfully.";
} else {
$error_message = "Error deleting resource: " . $conn->error;
}
}
// Fetch institutions, departments, and resource types for dropdown filters
$institutions = $conn->query("SELECT DISTINCT institution FROM resources");
$departments = isset($_POST['institution']) ? $conn->query("SELECT DISTINCT department FROM resources WHERE institution = '" . $conn->real_escape_string($_POST['institution']) . "'") : null;
$resource_types = $conn->query("SELECT DISTINCT type FROM resources");
// Fetch resources based on filters
$filters = [];
$sql = "SELECT * FROM resources WHERE 1=1";
if (isset($_POST['institution']) && $_POST['institution'] !== '') {
$filters['institution'] = $_POST['institution'];
$sql .= " AND institution = ?";
}
if (isset($_POST['department']) && $_POST['department'] !== '') {
$filters['department'] = $_POST['department'];
$sql .= " AND department = ?";
}
if (isset($_POST['resource_type']) && $_POST['resource_type'] !== '') {
$filters['resource_type'] = $_POST['resource_type'];
$sql .= " AND type = ?";
}
$stmt = $conn->prepare($sql);
if ($filters) {
$stmt->bind_param(str_repeat('s', count($filters)), ...array_values($filters));
}
$stmt->execute();
$result = $stmt->get_result();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>View Resources - Educational Resource Management System</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Roboto', sans-serif;
line-height: 1.6;
background-color: #f4f7f6;
color: #333;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
background-color: #2c3e50;
color: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.header h1 {
margin: 0;
font-size: 1.8rem;
}
.header a {
color: white;
text-decoration: none;
transition: color 0.3s ease;
}
.header a:hover {
color: #3498db;
}
.user-welcome {
background-color: #ecf0f1;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
text-align: center;
}
.navigation {
display: flex;
justify-content: center;
margin-bottom: 20px;
}
.nav-list {
display: flex;
list-style-type: none;
gap: 20px;
}
.nav-list li a {
text-decoration: none;
color: #2c3e50;
padding: 10px 15px;
border-radius: 6px;
transition: all 0.3s ease;
background-color: #ecf0f1;
display: inline-block;
}
.nav-list li a:hover {
background-color: #3498db;
color: white;
transform: translateY(-3px);
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.logout-btn {
background-color: #e74c3c;
color: white;
text-decoration: none;
padding: 10px 15px;
border-radius: 6px;
transition: background-color 0.3s ease;
}
.logout-btn:hover {
background-color: #c0392b;
}
.dashboard-content {
background-color: white;
border-radius: 8px;
padding: 20px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.dashboard-content h2 {
color: #2c3e50;
margin-bottom: 15px;
text-align: center;
}
.filter-form {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}
.filter-form select {
padding: 10px;
border-radius: 4px;
border: 1px solid #ddd;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
font-weight: bold;
}
.action-btn {
padding: 8px 12px;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.download-btn {
background-color: #3498db;
color: white;
}
.download-btn:hover {
background-color: #2980b9;
}
.delete-btn {
background-color: #e74c3c;
color: white;
}
.delete-btn:hover {
background-color: #c0392b;
}
@media (max-width: 768px) {
.header {
flex-direction: column;
text-align: center;
}
.nav-list {
flex-direction: column;
align-items: center;
}
.filter-form {
flex-direction: column;
}
.filter-form select {
margin-bottom: 10px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1><a href="index.php">Educational Resource Management System</a></h1>
<a href="logout.php" class="logout-btn">Logout</a>
</div>
<div class="user-welcome">
<h2>Welcome, <?php echo htmlspecialchars($username); ?>!</h2>
<p>You are logged in as a <?php echo htmlspecialchars($user_type); ?></p>
</div>
<nav>
<ul class="nav-list">
<?php if ($user_type === 'admin'): ?>
<li><a href="add_resource.php">Add Resource</a></li>
<?php endif; ?>
<li><a href="view_resources.php">View Resources</a></li>
</ul>
</nav>
<div class="dashboard-content">
<h2>View Resources</h2>
<?php
if (isset($success_message)) {
echo "<p style='color: green;'>$success_message</p>";
}
if (isset($error_message)) {
echo "<p style='color: red;'>$error_message</p>";
}
?>
<form method="POST" action="" class="filter-form">
<select name="institution" onchange="this.form.submit()">
<option value="">Select Institution</option>
<?php while ($row = $institutions->fetch_assoc()): ?>
<option value="<?php echo htmlspecialchars($row['institution']); ?>"
<?php if (isset($_POST['institution']) && $_POST['institution'] === $row['institution']) echo 'selected'; ?>>
<?php echo htmlspecialchars($row['institution']); ?>
</option>
<?php endwhile; ?>
</select>
<select name="department" onchange="this.form.submit()">
<option value="">Select Department</option>
<?php if (isset($departments)): ?>
<?php while ($row = $departments->fetch_assoc()): ?>
<option value="<?php echo htmlspecialchars($row['department']); ?>"
<?php if (isset($_POST['department']) && $_POST['department'] === $row['department']) echo 'selected'; ?>>
<?php echo htmlspecialchars($row['department']); ?>
</option>
<?php endwhile; ?>
<?php endif; ?>
</select>
<select name="resource_type" onchange="this.form.submit()">
<option value="">Select Resource Type</option>
<?php while ($row = $resource_types->fetch_assoc()): ?>
<option value="<?php echo htmlspecialchars($row['type']); ?>"
<?php if (isset($_POST['resource_type']) && $_POST['resource_type'] === $row['type']) echo 'selected'; ?>>
<?php echo htmlspecialchars($row['type']); ?>
</option>
<?php endwhile; ?>
</select>
</form>
<?php if ($result->num_rows > 0): ?>
<table>
<tr>
<th>Resource Name</th>
<th>Resource Type</th>
<th>Institution</th>
<th>Department</th>
<?php if ($user_type === 'admin'): ?>
<th>Download</th>
<th>Delete</th>
<?php else: ?>
<th>Download</th>
<?php endif; ?>
</tr>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo htmlspecialchars($row['name']); ?></td>
<td><?php echo htmlspecialchars($row['type']); ?></td>
<td><?php echo htmlspecialchars($row['institution']); ?></td>
<td><?php echo htmlspecialchars($row['department']); ?></td>
<td>
<a href="uploads/<?php echo htmlspecialchars($row['resource_file']); ?>" download class="action-btn download-btn">Download</a>
</td>
<?php if ($user_type === 'admin'): ?>
<td>
<form method="POST" action="" style="display: inline;">
<button type="submit" name="delete_resource" value="<?php echo $row['id']; ?>" class="action-btn delete-btn" onclick="return confirm('Are you sure you want to delete this resource?')">Delete</button>
</form>
</td>
<?php endif; ?>
</tr>
<?php endwhile; ?>
</table>
<?php else: ?>
<p>No resources available.</p>
<?php endif; ?>
</div>
</div>
</body>
</html>
add_resources.php
<?php
include 'db.php';
session_start();
if (!isset($_SESSION['username'])) {
header('Location: login.php');
exit();
}
$username = $_SESSION['username'];
$user_type = $_SESSION['user_type'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Resource - Educational Resource Management System</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Roboto', sans-serif;
line-height: 1.6;
background-color: #f4f7f6;
color: #333;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
background-color: #2c3e50;
color: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.header h1 {
margin: 0;
font-size: 1.8rem;
}
.header h1 a {
color: white;
text-decoration: none;
transition: color 0.3s ease;
}
.header h1 a:hover {
color: #3498db;
}
.logout-btn {
background-color: #e74c3c;
color: white;
text-decoration: none;
padding: 10px 15px;
border-radius: 6px;
transition: background-color 0.3s ease;
}
.logout-btn:hover {
background-color: #c0392b;
}
.user-welcome {
background-color: #ecf0f1;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
text-align: center;
}
.navigation {
display: flex;
justify-content: center;
margin-bottom: 20px;
}
.nav-list {
display: flex;
list-style-type: none;
gap: 20px;
}
.nav-list li a {
text-decoration: none;
color: #2c3e50;
padding: 10px 15px;
border-radius: 6px;
transition: all 0.3s ease;
background-color: #ecf0f1;
display: inline-block;
}
.nav-list li a:hover {
background-color: #3498db;
color: white;
transform: translateY(-3px);
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.dashboard-content {
background-color: white;
border-radius: 8px;
padding: 20px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.dashboard-content h2 {
color: #2c3e50;
margin-bottom: 20px;
text-align: center;
}
.add-resource-form {
max-width: 600px;
margin: 0 auto;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
color: #2c3e50;
}
.form-group input,
.form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
}
.submit-btn {
width: 100%;
padding: 12px;
background-color: #3498db;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.submit-btn:hover {
background-color: #2980b9;
}
@media (max-width: 768px) {
.header {
flex-direction: column;
text-align: center;
}
.nav-list {
flex-direction: column;
align-items: center;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1><a href="index.php">Educational Resource Management System</a></h1>
<a href="logout.php" class="logout-btn">Logout</a>
</div>
<div class="user-welcome">
<h2>Welcome, <?php echo htmlspecialchars($username); ?>!</h2>
<p>You are logged in as a <?php echo htmlspecialchars($user_type); ?></p>
</div>
<nav>
<ul class="nav-list">
<?php if ($user_type === 'admin'): ?>
<li><a href="add_resource.php">Add Resource</a></li>
<?php endif; ?>
<li><a href="view_resources.php">View Resources</a></li>
</ul>
</nav>
<div class="dashboard-content">
<h2>Add New Resource</h2>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$type = $_POST['type'];
$institution = $_POST['institution'];
$department = $_POST['department'];
$resource_file = $_FILES['resource_file']['name'];
// Save the uploaded file to the uploads directory
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["resource_file"]["name"]);
if (move_uploaded_file($_FILES["resource_file"]["tmp_name"], $target_file)) {
// Insert the resource details into the database
$sql = "INSERT INTO resources (name, type, institution, department, resource_file)
VALUES ('$name', '$type', '$institution', '$department', '$resource_file')";
if ($conn->query($sql) === TRUE) {
echo "<div style='color: green; text-align: center; margin-bottom: 15px;'>Resource added successfully!</div>";
} else {
echo "<div style='color: red; text-align: center; margin-bottom: 15px;'>Error: " . $conn->error . "</div>";
}
} else {
echo "<div style='color: red; text-align: center; margin-bottom: 15px;'>Sorry, there was an error uploading your file.</div>";
}
}
?>
<form action="add_resource.php" method="POST" enctype="multipart/form-data" class="add-resource-form">
<div class="form-group">
<label for="name">Resource Name:</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group">
<label for="type">Resource Type:</label>
<select id="type" name="type" required>
<option value="" disabled selected>Select Resource Type</option>
<option value="Textbooks">Textbooks</option>
<option value="Digital Materials">Digital Materials</option>
<option value="Library Books">Library Books</option>
</select>
</div>
<div class="form-group">
<label for="institution">Institution:</label>
<select id="institution" name="institution" onchange="updateDepartments()" required>
<option value="" disabled selected>Select Institution</option>
<option value="MIT Institute of Design">MIT Institute of Design</option>
<option value="MIT College of Management">MIT College of Management</option>
<option value="MIT School of Food Technology">MIT School of Food Technology</option>
<option value="MIT School of Film and Theatre">MIT School of Film and Theatre</option>
<option value="MIT School of Indian Civil Services">MIT School of Indian Civil Services</option>
<option value="MIT School of Computing">MIT School of Computing</option>
</select>
</div>
<div class="form-group">
<label for="department">Department:</label>
<select id="department" name="department" required>
<option value="" disabled selected>Select Department</option>
</select>
</div>
<div class="form-group">
<label for="resource_file">Upload Resource (PDF/Video):</label>
<input type="file" id="resource_file" name="resource_file" required>
</div>
<button type="submit" class="submit-btn">Add Resource</button>
</form>
</div>
</div>
<script>
// Departments for each institution
const departments = {
"MIT Institute of Design": [
"Bachelor of Design",
"Master of Design (Animation Design)",
"Master of Design (Design Management)",
"Master of Design (Fashion Management and Marketing)"
],
"MIT College of Management": [
"Bachelor of Commerce (HONORS)",
"Bachelor of Computer Applications",
"Master of Business Administration (Executive)"
],
"MIT School of Food Technology": [
"B. Tech. (Food Technology)",
"M. Tech. (Food Safety and Quality Management)",
"M. Tech. (Food Technology)"
],
"MIT School of Film and Theatre": [
"B.A. in Direction & Screenplay Writing",
"B.Sc. in Filmmaking",
"Bachelor of Arts (Dramatics)",
"M.A. in Direction & Screenplay Writing"
],
"MIT School of Indian Civil Services": [
"B.A. (Administration)",
"M.A. (Administration)"
],
"MIT School of Computing": [
"Bachelor of Technology (Computer Science & Engineering)",
"Master of Science (Computer Science/Artificial Intelligence & Machine Learning)",
"Master of Technology (Computer Science & Engineering - Intelligent Systems & Analysis)",
"Master of Technology (Information Technology - Cyber Security)"
]
};
// Function to update department options based on selected institution
function updateDepartments() {
const institutionSelect = document.getElementById("institution");
const departmentSelect = document.getElementById("department");
const selectedInstitution = institutionSelect.value;
// Clear the current options in the department dropdown
departmentSelect.innerHTML = "<option value='' disabled selected>Select Department</option>";
// Get departments for the selected institution
if (departments[selectedInstitution]) {
departments[selectedInstitution].forEach(department => {
const option = document.createElement("option");
option.value = department;
option.text = department;
departmentSelect.appendChild(option);
});
}
}
</script>
</body>
</html>
db.php
<?php
// db.php - Database connection
$servername = "127.0.0.1"; // Use IP instead of "localhost"
$username = "root";
$password = ""; // If you have a password, enter it here
$dbname = "resource_management";
$port = 3307; // Specify the correct port
$conn = new mysqli($servername, $username, $password, $dbname, $port);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>