harshdhane commited on
Commit
a8a001c
·
verified ·
1 Parent(s): 2ad0b73

Upload 10 files

Browse files
app.py ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, redirect, url_for, session, flash, send_from_directory
2
+ from werkzeug.utils import secure_filename
3
+ from werkzeug.security import generate_password_hash, check_password_hash
4
+ import os
5
+ from datetime import datetime
6
+ from models import db, User, Resource
7
+
8
+ app = Flask(__name__)
9
+ app.config['SECRET_KEY'] = 'your_secret_key_here'
10
+ app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///resource_management.db'
11
+ app.config['UPLOAD_FOLDER'] = 'uploads'
12
+ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
13
+
14
+ db.init_app(app)
15
+
16
+ # Ensure uploads folder exists
17
+ if not os.path.exists(app.config['UPLOAD_FOLDER']):
18
+ os.makedirs(app.config['UPLOAD_FOLDER'])
19
+
20
+ # Create database tables automatically
21
+ with app.app_context():
22
+ db.create_all()
23
+
24
+ @app.route('/')
25
+ def index():
26
+ if 'username' not in session:
27
+ return redirect(url_for('login'))
28
+ username = session['username']
29
+ user_type = session['user_type']
30
+ resource_count = Resource.query.count()
31
+ last_login = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
32
+ return render_template('index.html', username=username, user_type=user_type, resource_count=resource_count, last_login=last_login)
33
+
34
+ @app.route('/login', methods=['GET', 'POST'])
35
+ def login():
36
+ if request.method == 'POST':
37
+ username = request.form['username']
38
+ password = request.form['password']
39
+ user_type = request.form['user_type']
40
+
41
+ user = User.query.filter_by(username=username, user_type=user_type).first()
42
+ if user and check_password_hash(user.password, password):
43
+ session['username'] = user.username
44
+ session['user_type'] = user.user_type
45
+ return redirect(url_for('index'))
46
+ else:
47
+ flash('Invalid username, password, or user type.', 'error')
48
+ return render_template('login.html')
49
+
50
+ @app.route('/signup', methods=['GET', 'POST'])
51
+ def signup():
52
+ if request.method == 'POST':
53
+ username = request.form['username']
54
+ password = request.form['password']
55
+ confirm_password = request.form['confirm_password']
56
+ user_type = request.form['user_type']
57
+
58
+ if password != confirm_password:
59
+ flash('Passwords do not match!', 'error')
60
+ return redirect(url_for('signup'))
61
+
62
+ existing_user = User.query.filter_by(username=username).first()
63
+ if existing_user:
64
+ flash('Username already exists.', 'error')
65
+ return redirect(url_for('signup'))
66
+
67
+ hashed_password = generate_password_hash(password)
68
+ new_user = User(username=username, password=hashed_password, user_type=user_type)
69
+ db.session.add(new_user)
70
+ db.session.commit()
71
+ flash('Account created successfully. Please log in.', 'success')
72
+ return redirect(url_for('login'))
73
+ return render_template('signup.html')
74
+
75
+ @app.route('/logout')
76
+ def logout():
77
+ session.clear()
78
+ return redirect(url_for('login'))
79
+
80
+ @app.route('/view_resources', methods=['GET', 'POST'])
81
+ def view_resources():
82
+ if 'username' not in session:
83
+ return redirect(url_for('login'))
84
+ user_type = session['user_type']
85
+
86
+ institutions = db.session.query(Resource.institution).distinct()
87
+ resource_types = db.session.query(Resource.type).distinct()
88
+
89
+ filters = {}
90
+ if request.method == 'POST':
91
+ if 'delete_resource' in request.form and user_type == 'admin':
92
+ resource_id = request.form['delete_resource']
93
+ resource = Resource.query.get(resource_id)
94
+ if resource:
95
+ try:
96
+ os.remove(os.path.join(app.config['UPLOAD_FOLDER'], resource.resource_file))
97
+ except FileNotFoundError:
98
+ pass
99
+ db.session.delete(resource)
100
+ db.session.commit()
101
+ flash('Resource deleted successfully.', 'success')
102
+ else:
103
+ flash('Resource not found.', 'error')
104
+ return redirect(url_for('view_resources'))
105
+
106
+ filters['institution'] = request.form.get('institution')
107
+ filters['department'] = request.form.get('department')
108
+ filters['resource_type'] = request.form.get('resource_type')
109
+
110
+ query = Resource.query
111
+ if filters.get('institution'):
112
+ query = query.filter_by(institution=filters['institution'])
113
+ if filters.get('department'):
114
+ query = query.filter_by(department=filters['department'])
115
+ if filters.get('resource_type'):
116
+ query = query.filter_by(type=filters['resource_type'])
117
+
118
+ resources = query.all()
119
+
120
+ departments = []
121
+ if filters.get('institution'):
122
+ departments = db.session.query(Resource.department).filter_by(institution=filters['institution']).distinct()
123
+
124
+ return render_template('view_resources.html', resources=resources, institutions=institutions, departments=departments, resource_types=resource_types, user_type=user_type, filters=filters)
125
+
126
+ @app.route('/add_resource', methods=['GET', 'POST'])
127
+ def add_resource():
128
+ if 'username' not in session or session['user_type'] != 'admin':
129
+ return redirect(url_for('login'))
130
+ if request.method == 'POST':
131
+ name = request.form['name']
132
+ type = request.form['type']
133
+ institution = request.form['institution']
134
+ department = request.form['department']
135
+ resource_file = request.files['resource_file']
136
+
137
+ if resource_file:
138
+ filename = secure_filename(resource_file.filename)
139
+ resource_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
140
+
141
+ new_resource = Resource(name=name, type=type, institution=institution, department=department, resource_file=filename)
142
+ db.session.add(new_resource)
143
+ db.session.commit()
144
+ flash('Resource added successfully!', 'success')
145
+ return redirect(url_for('view_resources'))
146
+ return render_template('add_resource.html')
147
+
148
+ @app.route('/uploads/<filename>')
149
+ def uploaded_file(filename):
150
+ return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
151
+
152
+ if __name__ == '__main__':
153
+ app.run(debug=True)
models.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask_sqlalchemy import SQLAlchemy
2
+
3
+ db = SQLAlchemy()
4
+
5
+ class User(db.Model):
6
+ id = db.Column(db.Integer, primary_key=True)
7
+ username = db.Column(db.String(50), unique=True, nullable=False)
8
+ password = db.Column(db.String(255), nullable=False)
9
+ user_type = db.Column(db.String(20), nullable=False)
10
+
11
+ class Resource(db.Model):
12
+ id = db.Column(db.Integer, primary_key=True)
13
+ name = db.Column(db.String(100), nullable=False)
14
+ type = db.Column(db.String(50), nullable=False)
15
+ institution = db.Column(db.String(100), nullable=False)
16
+ department = db.Column(db.String(100), nullable=False)
17
+ resource_file = db.Column(db.String(255), nullable=False)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ flask
2
+ flask-sqlalchemy
3
+ mysql-connector-python
4
+ flask
5
+ flask-sqlalchemy
6
+ mysql-connector-python
7
+ werkzeug
static/style.css ADDED
@@ -0,0 +1,321 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ * {
2
+ margin: 0;
3
+ padding: 0;
4
+ box-sizing: border-box;
5
+ }
6
+
7
+ body {
8
+ font-family: 'Roboto', sans-serif;
9
+ line-height: 1.6;
10
+ background-color: #f4f7f6;
11
+ color: #333;
12
+ }
13
+
14
+ body.login, body.signup {
15
+ font-family: Arial, sans-serif;
16
+ margin: 0;
17
+ padding: 0;
18
+ background: linear-gradient(to right, #1d3557, #457b9d);
19
+ display: flex;
20
+ justify-content: center;
21
+ align-items: center;
22
+ height: 100vh;
23
+ }
24
+
25
+ .container {
26
+ max-width: 1200px;
27
+ margin: 0 auto;
28
+ padding: 20px;
29
+ }
30
+
31
+ .container.login, .container.signup {
32
+ background: #fff;
33
+ padding: 20px;
34
+ border-radius: 8px;
35
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
36
+ width: 350px;
37
+ text-align: center;
38
+ }
39
+
40
+ .header {
41
+ background-color: #2c3e50;
42
+ color: white;
43
+ padding: 20px;
44
+ border-radius: 8px;
45
+ margin-bottom: 20px;
46
+ display: flex;
47
+ justify-content: space-between;
48
+ align-items: center;
49
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
50
+ }
51
+
52
+ .header h1 {
53
+ margin: 0;
54
+ font-size: 1.8rem;
55
+ }
56
+
57
+ .header a {
58
+ color: white;
59
+ text-decoration: none;
60
+ transition: color 0.3s ease;
61
+ }
62
+
63
+ .header a:hover {
64
+ color: #3498db;
65
+ }
66
+
67
+ .user-welcome {
68
+ background-color: #ecf0f1;
69
+ padding: 15px;
70
+ border-radius: 8px;
71
+ margin-bottom: 20px;
72
+ text-align: center;
73
+ }
74
+
75
+ .navigation {
76
+ display: flex;
77
+ justify-content: center;
78
+ margin-bottom: 20px;
79
+ }
80
+
81
+ .nav-list {
82
+ display: flex;
83
+ list-style-type: none;
84
+ gap: 20px;
85
+ }
86
+
87
+ .nav-list li a {
88
+ text-decoration: none;
89
+ color: #2c3e50;
90
+ padding: 10px 15px;
91
+ border-radius: 6px;
92
+ transition: all 0.3s ease;
93
+ background-color: #ecf0f1;
94
+ display: inline-block;
95
+ }
96
+
97
+ .nav-list li a:hover {
98
+ background-color: #3498db;
99
+ color: white;
100
+ transform: translateY(-3px);
101
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
102
+ }
103
+
104
+ .logout-btn {
105
+ background-color: #e74c3c;
106
+ color: white;
107
+ text-decoration: none;
108
+ padding: 10px 15px;
109
+ border-radius: 6px;
110
+ transition: background-color 0.3s ease;
111
+ }
112
+
113
+ .logout-btn:hover {
114
+ background-color: #c0392b;
115
+ }
116
+
117
+ .dashboard-content {
118
+ background-color: white;
119
+ border-radius: 8px;
120
+ padding: 20px;
121
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
122
+ }
123
+
124
+ .dashboard-content h2 {
125
+ color: #2c3e50;
126
+ margin-bottom: 15px;
127
+ text-align: center;
128
+ }
129
+
130
+ .quick-stats {
131
+ display: flex;
132
+ justify-content: space-around;
133
+ margin-top: 20px;
134
+ }
135
+
136
+ .stat-box {
137
+ background-color: #ecf0f1;
138
+ padding: 15px;
139
+ border-radius: 8px;
140
+ text-align: center;
141
+ width: 200px;
142
+ }
143
+
144
+ .tabs {
145
+ display: flex;
146
+ justify-content: space-around;
147
+ margin-bottom: 20px;
148
+ }
149
+
150
+ .tabs button {
151
+ background: none;
152
+ border: none;
153
+ padding: 10px;
154
+ cursor: pointer;
155
+ font-size: 16px;
156
+ font-weight: bold;
157
+ color: #333;
158
+ }
159
+
160
+ .tabs button.active {
161
+ color: #1d3557;
162
+ border-bottom: 2px solid #1d3557;
163
+ }
164
+
165
+ .form {
166
+ display: none;
167
+ }
168
+
169
+ .form.active {
170
+ display: block;
171
+ }
172
+
173
+ .form input {
174
+ width: 90%;
175
+ padding: 10px;
176
+ margin: 10px 0;
177
+ border: 1px solid #ccc;
178
+ border-radius: 5px;
179
+ }
180
+
181
+ .form button {
182
+ width: 95%;
183
+ padding: 10px;
184
+ margin: 10px 0;
185
+ background: #1d3557;
186
+ color: #fff;
187
+ border: none;
188
+ border-radius: 5px;
189
+ cursor: pointer;
190
+ }
191
+
192
+ .form button:hover {
193
+ background: #457b9d;
194
+ }
195
+
196
+ .form a {
197
+ display: block;
198
+ color: #1d3557;
199
+ text-decoration: none;
200
+ margin-top: 10px;
201
+ }
202
+
203
+ .filter-form {
204
+ display: flex;
205
+ justify-content: space-between;
206
+ margin-bottom: 20px;
207
+ }
208
+
209
+ .filter-form select {
210
+ padding: 10px;
211
+ border-radius: 4px;
212
+ border: 1px solid #ddd;
213
+ }
214
+
215
+ table {
216
+ width: 100%;
217
+ border-collapse: collapse;
218
+ }
219
+
220
+ th, td {
221
+ padding: 12px;
222
+ text-align: left;
223
+ border-bottom: 1px solid #ddd;
224
+ }
225
+
226
+ th {
227
+ background-color: #f2f2f2;
228
+ font-weight: bold;
229
+ }
230
+
231
+ .action-btn {
232
+ padding: 8px 12px;
233
+ border: none;
234
+ border-radius: 4px;
235
+ cursor: pointer;
236
+ transition: background-color 0.3s ease;
237
+ }
238
+
239
+ .download-btn {
240
+ background-color: #3498db;
241
+ color: white;
242
+ }
243
+
244
+ .download-btn:hover {
245
+ background-color: #2980b9;
246
+ }
247
+
248
+ .delete-btn {
249
+ background-color: #e74c3c;
250
+ color: white;
251
+ }
252
+
253
+ .delete-btn:hover {
254
+ background-color: #c0392b;
255
+ }
256
+
257
+ .add-resource-form {
258
+ max-width: 600px;
259
+ margin: 0 auto;
260
+ }
261
+
262
+ .form-group {
263
+ margin-bottom: 15px;
264
+ }
265
+
266
+ .form-group label {
267
+ display: block;
268
+ margin-bottom: 5px;
269
+ color: #2c3e50;
270
+ }
271
+
272
+ .form-group input,
273
+ .form-group select {
274
+ width: 100%;
275
+ padding: 10px;
276
+ border: 1px solid #ddd;
277
+ border-radius: 4px;
278
+ font-size: 16px;
279
+ }
280
+
281
+ .submit-btn {
282
+ width: 100%;
283
+ padding: 12px;
284
+ background-color: #3498db;
285
+ color: white;
286
+ border: none;
287
+ border-radius: 6px;
288
+ cursor: pointer;
289
+ font-size: 16px;
290
+ transition: background-color 0.3s ease;
291
+ }
292
+
293
+ .submit-btn:hover {
294
+ background-color: #2980b9;
295
+ }
296
+
297
+ @media (max-width: 768px) {
298
+ .header {
299
+ flex-direction: column;
300
+ text-align: center;
301
+ }
302
+
303
+ .nav-list {
304
+ flex-direction: column;
305
+ align-items: center;
306
+ }
307
+
308
+ .quick-stats {
309
+ flex-direction: column;
310
+ align-items: center;
311
+ gap: 15px;
312
+ }
313
+
314
+ .filter-form {
315
+ flex-direction: column;
316
+ }
317
+
318
+ .filter-form select {
319
+ margin-bottom: 10px;
320
+ }
321
+ }
templates/add_resource.html ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Add Resource - Educational Resource Management System</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
8
+ <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
9
+ </head>
10
+ <body>
11
+ <div class="container">
12
+ <div class="header">
13
+ <h1><a href="{{ url_for('index') }}">Educational Resource Management System</a></h1>
14
+ <a href="{{ url_for('logout') }}" class="logout-btn">Logout</a>
15
+ </div>
16
+
17
+ <div class="user-welcome">
18
+ <h2>Welcome, {{ session['username'] }}!</h2>
19
+ <p>You are logged in as a {{ session['user_type'] }}</p>
20
+ </div>
21
+
22
+ <nav>
23
+ <ul class="nav-list">
24
+ {% if session['user_type'] == 'admin' %}
25
+ <li><a href="{{ url_for('add_resource') }}">Add Resource</a></li>
26
+ {% endif %}
27
+ <li><a href="{{ url_for('view_resources') }}">View Resources</a></li>
28
+ </ul>
29
+ </nav>
30
+
31
+ <div class="dashboard-content">
32
+ <h2>Add New Resource</h2>
33
+
34
+ {% with messages = get_flashed_messages(with_categories=true) %}
35
+ {% if messages %}
36
+ {% for category, message in messages %}
37
+ <p style="color: {{ 'red' if category == 'error' else 'green' }}">{{ message }}</p>
38
+ {% endfor %}
39
+ {% endif %}
40
+ {% endwith %}
41
+
42
+ <form action="{{ url_for('add_resource') }}" method="POST" enctype="multipart/form-data" class="add-resource-form">
43
+ <div class="form-group">
44
+ <label for="name">Resource Name:</label>
45
+ <input type="text" id="name" name="name" required>
46
+ </div>
47
+
48
+ <div class="form-group">
49
+ <label for="type">Resource Type:</label>
50
+ <select id="type" name="type" required>
51
+ <option value="" disabled selected>Select Resource Type</option>
52
+ <option value="Textbooks">Textbooks</option>
53
+ <option value="Digital Materials">Digital Materials</option>
54
+ <option value="Library Books">Library Books</option>
55
+ </select>
56
+ </div>
57
+
58
+ <div class="form-group">
59
+ <label for="institution">Institution:</label>
60
+ <select id="institution" name="institution" onchange="updateDepartments()" required>
61
+ <option value="" disabled selected>Select Institution</option>
62
+ <option value="MIT Institute of Design">MIT Institute of Design</option>
63
+ <option value="MIT College of Management">MIT College of Management</option>
64
+ <option value="MIT School of Food Technology">MIT School of Food Technology</option>
65
+ <option value="MIT School of Film and Theatre">MIT School of Film and Theatre</option>
66
+ <option value="MIT School of Indian Civil Services">MIT School of Indian Civil Services</option>
67
+ <option value="MIT School of Computing">MIT School of Computing</option>
68
+ </select>
69
+ </div>
70
+
71
+ <div class="form-group">
72
+ <label for="department">Department:</label>
73
+ <select id="department" name="department" required>
74
+ <option value="" disabled selected>Select Department</option>
75
+ </select>
76
+ </div>
77
+
78
+ <div class="form-group">
79
+ <label for="resource_file">Upload Resource (PDF/Video):</label>
80
+ <input type="file" id="resource_file" name="resource_file" required>
81
+ </div>
82
+
83
+ <button type="submit" class="submit-btn">Add Resource</button>
84
+ </form>
85
+ </div>
86
+ </div>
87
+
88
+ <script>
89
+ const departments = {
90
+ "MIT Institute of Design": [
91
+ "Bachelor of Design",
92
+ "Master of Design (Animation Design)",
93
+ "Master of Design (Design Management)",
94
+ "Master of Design (Fashion Management and Marketing)"
95
+ ],
96
+ "MIT College of Management": [
97
+ "Bachelor of Commerce (HONORS)",
98
+ "Bachelor of Computer Applications",
99
+ "Master of Business Administration (Executive)"
100
+ ],
101
+ "MIT School of Food Technology": [
102
+ "B. Tech. (Food Technology)",
103
+ "M. Tech. (Food Safety and Quality Management)",
104
+ "M. Tech. (Food Technology)"
105
+ ],
106
+ "MIT School of Film and Theatre": [
107
+ "B.A. in Direction & Screenplay Writing",
108
+ "B.Sc. in Filmmaking",
109
+ "Bachelor of Arts (Dramatics)",
110
+ "M.A. in Direction & Screenplay Writing"
111
+ ],
112
+ "MIT School of Indian Civil Services": [
113
+ "B.A. (Administration)",
114
+ "M.A. (Administration)"
115
+ ],
116
+ "MIT School of Computing": [
117
+ "Bachelor of Technology (Computer Science & Engineering)",
118
+ "Master of Science (Computer Science/Artificial Intelligence & Machine Learning)",
119
+ "Master of Technology (Computer Science & Engineering - Intelligent Systems & Analysis)",
120
+ "Master of Technology (Information Technology - Cyber Security)"
121
+ ]
122
+ };
123
+
124
+ function updateDepartments() {
125
+ const institutionSelect = document.getElementById("institution");
126
+ const departmentSelect = document.getElementById("department");
127
+ const selectedInstitution = institutionSelect.value;
128
+
129
+ departmentSelect.innerHTML = "<option value='' disabled selected>Select Department</option>";
130
+
131
+ if (departments[selectedInstitution]) {
132
+ departments[selectedInstitution].forEach(department => {
133
+ const option = document.createElement("option");
134
+ option.value = department;
135
+ option.text = department;
136
+ departmentSelect.appendChild(option);
137
+ });
138
+ }
139
+ }
140
+ </script>
141
+ </body>
142
+ </html>
templates/index.html ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Educational Resource Management System</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
8
+ <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
9
+ </head>
10
+ <body>
11
+ <div class="container">
12
+ <div class="header">
13
+ <h1><a href="{{ url_for('index') }}">Educational Resource Management System</a></h1>
14
+ <a href="{{ url_for('logout') }}" class="logout-btn">Logout</a>
15
+ </div>
16
+
17
+ <div class="user-welcome">
18
+ <h2>Welcome, {{ username }}!</h2>
19
+ <p>You are logged in as a {{ user_type }}</p>
20
+ </div>
21
+
22
+ <nav>
23
+ <ul class="nav-list">
24
+ {% if user_type == 'admin' %}
25
+ <li><a href="{{ url_for('add_resource') }}">Add Resource</a></li>
26
+ {% endif %}
27
+ <li><a href="{{ url_for('view_resources') }}">View Resources</a></li>
28
+ </ul>
29
+ </nav>
30
+
31
+ <div class="dashboard-content">
32
+ <h2>Dashboard Overview</h2>
33
+ <div class="quick-stats">
34
+ <div class="stat-box">
35
+ <h3>Total Resources</h3>
36
+ <p>{{ resource_count }}</p>
37
+ </div>
38
+ <div class="stat-box">
39
+ <h3>User Type</h3>
40
+ <p>{{ user_type|capitalize }}</p>
41
+ </div>
42
+ <div class="stat-box">
43
+ <h3>Last Login</h3>
44
+ <p>{{ last_login }}</p>
45
+ </div>
46
+ </div>
47
+ </div>
48
+ </div>
49
+ </body>
50
+ </html>
templates/login.html ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Login</title>
7
+ <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ margin: 0;
12
+ padding: 0;
13
+ background: linear-gradient(to right, #1d3557, #457b9d);
14
+ display: flex;
15
+ justify-content: center;
16
+ align-items: center;
17
+ height: 100vh;
18
+ }
19
+
20
+ .container {
21
+ background: #fff;
22
+ padding: 20px;
23
+ border-radius: 8px;
24
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
25
+ width: 350px;
26
+ text-align: center;
27
+ }
28
+
29
+ .tabs {
30
+ display: flex;
31
+ justify-content: space-around;
32
+ margin-bottom: 20px;
33
+ }
34
+
35
+ .tabs button {
36
+ background: none;
37
+ border: none;
38
+ padding: 10px;
39
+ cursor: pointer;
40
+ font-size: 16px;
41
+ font-weight: bold;
42
+ color: #333;
43
+ }
44
+
45
+ .tabs button.active {
46
+ color: #1d3557;
47
+ border-bottom: 2px solid #1d3557;
48
+ }
49
+
50
+ .form {
51
+ display: none;
52
+ }
53
+
54
+ .form.active {
55
+ display: block;
56
+ }
57
+
58
+ .form input {
59
+ width: 90%;
60
+ padding: 10px;
61
+ margin: 10px 0;
62
+ border: 1px solid #ccc;
63
+ border-radius: 5px;
64
+ }
65
+
66
+ .form button {
67
+ width: 95%;
68
+ padding: 10px;
69
+ margin: 10px 0;
70
+ background: #1d3557;
71
+ color: #fff;
72
+ border: none;
73
+ border-radius: 5px;
74
+ cursor: pointer;
75
+ }
76
+
77
+ .form button:hover {
78
+ background: #457b9d;
79
+ }
80
+
81
+ .form a {
82
+ display: block;
83
+ color: #1d3557;
84
+ text-decoration: none;
85
+ margin-top: 10px;
86
+ }
87
+ </style>
88
+ </head>
89
+ <body class="login">
90
+ <div class="container">
91
+ <h2>Login Form</h2>
92
+ <div class="tabs">
93
+ <button id="adminTab" class="active">Admin Login</button>
94
+ <button id="studentTab">Student Login</button>
95
+ </div>
96
+
97
+ <form id="adminForm" class="form active" method="POST" action="{{ url_for('login') }}">
98
+ <input type="text" placeholder="Admin Username" name="username" required><br>
99
+ <input type="password" placeholder="Password" name="password" required><br>
100
+ <input type="hidden" name="user_type" value="admin">
101
+ <button type="submit">Login</button>
102
+ <a href="{{ url_for('signup') }}">Don't have an account? Sign up</a>
103
+ </form>
104
+
105
+ <form id="studentForm" class="form" method="POST" action="{{ url_for('login') }}">
106
+ <input type="text" placeholder="Student Username" name="username" required><br>
107
+ <input type="password" placeholder="Password" name="password" required><br>
108
+ <input type="hidden" name="user_type" value="student">
109
+ <button type="submit">Login</button>
110
+ <a href="{{ url_for('signup') }}">Don't have an account? Sign up</a>
111
+ </form>
112
+
113
+ {% with messages = get_flashed_messages(with_categories=true) %}
114
+ {% if messages %}
115
+ {% for category, message in messages %}
116
+ <p style="color: {{ 'red' if category == 'error' else 'green' }}">{{ message }}</p>
117
+ {% endfor %}
118
+ {% endif %}
119
+ {% endwith %}
120
+ </div>
121
+
122
+ <script>
123
+ const adminTab = document.getElementById('adminTab');
124
+ const studentTab = document.getElementById('studentTab');
125
+ const adminForm = document.getElementById('adminForm');
126
+ const studentForm = document.getElementById('studentForm');
127
+
128
+ adminTab.addEventListener('click', () => {
129
+ adminTab.classList.add('active');
130
+ studentTab.classList.remove('active');
131
+ adminForm.classList.add('active');
132
+ studentForm.classList.remove('active');
133
+ });
134
+
135
+ studentTab.addEventListener('click', () => {
136
+ studentTab.classList.add('active');
137
+ adminTab.classList.remove('active');
138
+ studentForm.classList.add('active');
139
+ adminForm.classList.remove('active');
140
+ });
141
+ </script>
142
+ </body>
143
+ </html>
templates/signup.html ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Signup</title>
7
+ <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ margin: 0;
12
+ padding: 0;
13
+ background: linear-gradient(to right, #1d3557, #457b9d);
14
+ display: flex;
15
+ justify-content: center;
16
+ align-items: center;
17
+ height: 100vh;
18
+ }
19
+
20
+ .container {
21
+ background: #fff;
22
+ padding: 20px;
23
+ border-radius: 8px;
24
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
25
+ width: 350px;
26
+ text-align: center;
27
+ }
28
+
29
+ .tabs {
30
+ display: flex;
31
+ justify-content: space-around;
32
+ margin-bottom: 20px;
33
+ }
34
+
35
+ .tabs button {
36
+ background: none;
37
+ border: none;
38
+ padding: 10px;
39
+ cursor: pointer;
40
+ font-size: 16px;
41
+ font-weight: bold;
42
+ color: #333;
43
+ }
44
+
45
+ .tabs button.active {
46
+ color: #1d3557;
47
+ border-bottom: 2px solid #1d3557;
48
+ }
49
+
50
+ .form {
51
+ display: none;
52
+ }
53
+
54
+ .form.active {
55
+ display: block;
56
+ }
57
+
58
+ .form input {
59
+ width: 90%;
60
+ padding: 10px;
61
+ margin: 10px 0;
62
+ border: 1px solid #ccc;
63
+ border-radius: 5px;
64
+ }
65
+
66
+ .form button {
67
+ width: 95%;
68
+ padding: 10px;
69
+ margin: 10px 0;
70
+ background: #1d3557;
71
+ color: #fff;
72
+ border: none;
73
+ border-radius: 5px;
74
+ cursor: pointer;
75
+ }
76
+
77
+ .form button:hover {
78
+ background: #457b9d;
79
+ }
80
+
81
+ .form a {
82
+ display: block;
83
+ color: #1d3557;
84
+ text-decoration: none;
85
+ margin-top: 10px;
86
+ }
87
+ </style>
88
+ </head>
89
+ <body class="signup">
90
+ <div class="container">
91
+ <h2>Signup Form</h2>
92
+
93
+ <div class="tabs">
94
+ <button id="adminTab" class="active" onclick="showForm('admin')">Admin Signup</button>
95
+ <button id="studentTab" onclick="showForm('student')">Student Signup</button>
96
+ </div>
97
+
98
+ <form id="adminForm" class="form active" method="POST" action="{{ url_for('signup') }}">
99
+ <input type="text" name="username" placeholder="Admin Username" required>
100
+ <input type="password" name="password" id="adminPassword" placeholder="Password" required>
101
+ <input type="password" name="confirm_password" id="adminConfirmPassword" placeholder="Confirm Password" required>
102
+ <input type="hidden" name="user_type" value="admin">
103
+ <button type="submit" onclick="return validatePasswords('adminPassword', 'adminConfirmPassword')">Signup</button>
104
+ <a href="{{ url_for('login') }}">Already have an account? Login</a>
105
+ </form>
106
+
107
+ <form id="studentForm" class="form" method="POST" action="{{ url_for('signup') }}">
108
+ <input type="text" name="username" placeholder="Student Username" required>
109
+ <input type="password" name="password" id="studentPassword" placeholder="Password" required>
110
+ <input type="password" name="confirm_password" id="studentConfirmPassword" placeholder="Confirm Password" required>
111
+ <input type="hidden" name="user_type" value="student">
112
+ <button type="submit" onclick="return validatePasswords('studentPassword', 'studentConfirmPassword')">Signup</button>
113
+ <a href="{{ url_for('login') }}">Already have an account? Login</a>
114
+ </form>
115
+
116
+ {% with messages = get_flashed_messages(with_categories=true) %}
117
+ {% if messages %}
118
+ {% for category, message in messages %}
119
+ <p style="color: {{ 'red' if category == 'error' else 'green' }}">{{ message }}</p>
120
+ {% endfor %}
121
+ {% endif %}
122
+ {% endwith %}
123
+ </div>
124
+
125
+ <script>
126
+ function showForm(type) {
127
+ const adminTab = document.getElementById('adminTab');
128
+ const studentTab = document.getElementById('studentTab');
129
+ const adminForm = document.getElementById('adminForm');
130
+ const studentForm = document.getElementById('studentForm');
131
+
132
+ if (type === 'admin') {
133
+ adminTab.classList.add('active');
134
+ studentTab.classList.remove('active');
135
+ adminForm.classList.add('active');
136
+ studentForm.classList.remove('active');
137
+ } else {
138
+ studentTab.classList.add('active');
139
+ adminTab.classList.remove('active');
140
+ studentForm.classList.add('active');
141
+ adminForm.classList.remove('active');
142
+ }
143
+ }
144
+
145
+ function validatePasswords(passwordId, confirmPasswordId) {
146
+ const password = document.getElementById(passwordId).value;
147
+ const confirmPassword = document.getElementById(confirmPasswordId).value;
148
+ if (password !== confirmPassword) {
149
+ alert('Passwords do not match!');
150
+ return false;
151
+ }
152
+ return true;
153
+ }
154
+ </script>
155
+ </body>
156
+ </html>
templates/view_resources.html ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>View Resources - Educational Resource Management System</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
8
+ <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
9
+ </head>
10
+ <body>
11
+ <div class="container">
12
+ <div class="header">
13
+ <h1><a href="{{ url_for('index') }}">Educational Resource Management System</a></h1>
14
+ <a href="{{ url_for('logout') }}" class="logout-btn">Logout</a>
15
+ </div>
16
+
17
+ <div class="user-welcome">
18
+ <h2>Welcome, {{ session['username'] }}!</h2>
19
+ <p>You are logged in as a {{ user_type }}</p>
20
+ </div>
21
+
22
+ <nav>
23
+ <ul class="nav-list">
24
+ {% if user_type == 'admin' %}
25
+ <li><a href="{{ url_for('add_resource') }}">Add Resource</a></li>
26
+ {% endif %}
27
+ <li><a href="{{ url_for('view_resources') }}">View Resources</a></li>
28
+ </ul>
29
+ </nav>
30
+
31
+ <div class="dashboard-content">
32
+ <h2>View Resources</h2>
33
+
34
+ {% with messages = get_flashed_messages(with_categories=true) %}
35
+ {% if messages %}
36
+ {% for category, message in messages %}
37
+ <p style="color: {{ 'red' if category == 'error' else 'green' }}">{{ message }}</p>
38
+ {% endfor %}
39
+ {% endif %}
40
+ {% endwith %}
41
+
42
+ <form method="POST" action="{{ url_for('view_resources') }}" class="filter-form">
43
+ <select name="institution" onchange="this.form.submit()">
44
+ <option value="">Select Institution</option>
45
+ {% for inst in institutions %}
46
+ <option value="{{ inst.institution }}" {% if filters.institution == inst.institution %}selected{% endif %}>{{ inst.institution }}</option>
47
+ {% endfor %}
48
+ </select>
49
+
50
+ <select name="department" onchange="this.form.submit()">
51
+ <option value="">Select Department</option>
52
+ {% if departments %}
53
+ {% for dept in departments %}
54
+ <option value="{{ dept.department }}" {% if filters.department == dept.department %}selected{% endif %}>{{ dept.department }}</option>
55
+ {% endfor %}
56
+ {% endif %}
57
+ </select>
58
+
59
+ <select name="resource_type" onchange="this.form.submit()">
60
+ <option value="">Select Resource Type</option>
61
+ {% for rtype in resource_types %}
62
+ <option value="{{ rtype.type }}" {% if filters.resource_type == rtype.type %}selected{% endif %}>{{ rtype.type }}</option>
63
+ {% endfor %}
64
+ </select>
65
+ </form>
66
+
67
+ {% if resources %}
68
+ <table>
69
+ <tr>
70
+ <th>Resource Name</th>
71
+ <th>Resource Type</th>
72
+ <th>Institution</th>
73
+ <th>Department</th>
74
+ {% if user_type == 'admin' %}
75
+ <th>Download</th>
76
+ <th>Delete</th>
77
+ {% else %}
78
+ <th>Download</th>
79
+ {% endif %}
80
+ </tr>
81
+ {% for resource in resources %}
82
+ <tr>
83
+ <td>{{ resource.name }}</td>
84
+ <td>{{ resource.type }}</td>
85
+ <td>{{ resource.institution }}</td>
86
+ <td>{{ resource.department }}</td>
87
+ <td>
88
+ <a href="{{ url_for('uploaded_file', filename=resource.resource_file) }}" download class="action-btn download-btn">Download</a>
89
+ </td>
90
+ {% if user_type == 'admin' %}
91
+ <td>
92
+ <form method="POST" action="{{ url_for('view_resources') }}" style="display: inline;">
93
+ <button type="submit" name="delete_resource" value="{{ resource.id }}" class="action-btn delete-btn" onclick="return confirm('Are you sure you want to delete this resource?')">Delete</button>
94
+ </form>
95
+ </td>
96
+ {% endif %}
97
+ </tr>
98
+ {% endfor %}
99
+ </table>
100
+ {% else %}
101
+ <p>No resources available.</p>
102
+ {% endif %}
103
+ </div>
104
+ </div>
105
+ </body>
106
+ </html>
uploads/full_code_file.txt ADDED
@@ -0,0 +1,1287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ index.php
2
+
3
+ <!DOCTYPE html>
4
+ <html lang="en">
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
+ <title>Educational Resource Management System</title>
9
+ <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
10
+ <style>
11
+ * {
12
+ margin: 0;
13
+ padding: 0;
14
+ box-sizing: border-box;
15
+ }
16
+
17
+ body {
18
+ font-family: 'Roboto', sans-serif;
19
+ line-height: 1.6;
20
+ background-color: #f4f7f6;
21
+ color: #333;
22
+ }
23
+
24
+ .container {
25
+ max-width: 1200px;
26
+ margin: 0 auto;
27
+ padding: 20px;
28
+ }
29
+
30
+ .header {
31
+ background-color: #2c3e50;
32
+ color: white;
33
+ padding: 20px;
34
+ border-radius: 8px;
35
+ margin-bottom: 20px;
36
+ display: flex;
37
+ justify-content: space-between;
38
+ align-items: center;
39
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
40
+ }
41
+
42
+ .header h1 {
43
+ margin: 0;
44
+ font-size: 1.8rem;
45
+ }
46
+
47
+ .header a {
48
+ color: white;
49
+ text-decoration: none;
50
+ transition: color 0.3s ease;
51
+ }
52
+
53
+ .header a:hover {
54
+ color: #3498db;
55
+ }
56
+
57
+ .user-welcome {
58
+ background-color: #ecf0f1;
59
+ padding: 15px;
60
+ border-radius: 8px;
61
+ margin-bottom: 20px;
62
+ text-align: center;
63
+ }
64
+
65
+ .navigation {
66
+ display: flex;
67
+ justify-content: center;
68
+ margin-bottom: 20px;
69
+ }
70
+
71
+ .nav-list {
72
+ display: flex;
73
+ list-style-type: none;
74
+ gap: 20px;
75
+ }
76
+
77
+ .nav-list li a {
78
+ text-decoration: none;
79
+ color: #2c3e50;
80
+ padding: 10px 15px;
81
+ border-radius: 6px;
82
+ transition: all 0.3s ease;
83
+ background-color: #ecf0f1;
84
+ display: inline-block;
85
+ }
86
+
87
+ .nav-list li a:hover {
88
+ background-color: #3498db;
89
+ color: white;
90
+ transform: translateY(-3px);
91
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
92
+ }
93
+
94
+ .logout-btn {
95
+ background-color: #e74c3c;
96
+ color: white;
97
+ text-decoration: none;
98
+ padding: 10px 15px;
99
+ border-radius: 6px;
100
+ transition: background-color 0.3s ease;
101
+ }
102
+
103
+ .logout-btn:hover {
104
+ background-color: #c0392b;
105
+ }
106
+
107
+ .dashboard-content {
108
+ background-color: white;
109
+ border-radius: 8px;
110
+ padding: 20px;
111
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
112
+ }
113
+
114
+ .dashboard-content h2 {
115
+ color: #2c3e50;
116
+ margin-bottom: 15px;
117
+ text-align: center;
118
+ }
119
+
120
+ .quick-stats {
121
+ display: flex;
122
+ justify-content: space-around;
123
+ margin-top: 20px;
124
+ }
125
+
126
+ .stat-box {
127
+ background-color: #ecf0f1;
128
+ padding: 15px;
129
+ border-radius: 8px;
130
+ text-align: center;
131
+ width: 200px;
132
+ }
133
+
134
+ @media (max-width: 768px) {
135
+ .header {
136
+ flex-direction: column;
137
+ text-align: center;
138
+ }
139
+
140
+ .nav-list {
141
+ flex-direction: column;
142
+ align-items: center;
143
+ }
144
+
145
+ .quick-stats {
146
+ flex-direction: column;
147
+ align-items: center;
148
+ gap: 15px;
149
+ }
150
+ }
151
+ </style>
152
+ </head>
153
+ <body>
154
+ <?php
155
+ session_start();
156
+ if (!isset($_SESSION['username'])) {
157
+ header('Location: login.php');
158
+ exit();
159
+ }
160
+ $username = $_SESSION['username'];
161
+ $user_type = $_SESSION['user_type'];
162
+ ?>
163
+
164
+ <div class="container">
165
+ <div class="header">
166
+ <h1><a href="index.php">Educational Resource Management System</a></h1>
167
+ <a href="logout.php" class="logout-btn">Logout</a>
168
+ </div>
169
+
170
+ <div class="user-welcome">
171
+ <h2>Welcome, <?php echo htmlspecialchars($username); ?>!</h2>
172
+ <p>You are logged in as a <?php echo htmlspecialchars($user_type); ?></p>
173
+ </div>
174
+
175
+ <nav>
176
+ <ul class="nav-list">
177
+ <?php if ($user_type === 'admin'): ?>
178
+ <li><a href="add_resource.php">Add Resource</a></li>
179
+ <?php endif; ?>
180
+ <li><a href="view_resources.php">View Resources</a></li>
181
+ </ul>
182
+ </nav>
183
+
184
+ <div class="dashboard-content">
185
+ <h2>Dashboard Overview</h2>
186
+ <div class="quick-stats">
187
+ <div class="stat-box">
188
+ <h3>Total Resources</h3>
189
+ <?php
190
+ include 'db.php';
191
+ $resource_count_query = "SELECT COUNT(*) as count FROM resources";
192
+ $resource_count_result = $conn->query($resource_count_query);
193
+ $resource_count = $resource_count_result->fetch_assoc()['count'];
194
+ echo "<p>$resource_count</p>";
195
+ ?>
196
+ </div>
197
+ <div class="stat-box">
198
+ <h3>User Type</h3>
199
+ <p><?php echo ucfirst(htmlspecialchars($user_type)); ?></p>
200
+ </div>
201
+ <div class="stat-box">
202
+ <h3>Last Login</h3>
203
+ <p><?php echo date('Y-m-d H:i:s'); ?></p>
204
+ </div>
205
+ </div>
206
+ </div>
207
+ </div>
208
+ </body>
209
+ </html>
210
+
211
+
212
+
213
+ login.php
214
+
215
+ <?php
216
+ session_start();
217
+ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
218
+ include 'db.php';
219
+
220
+ $username = $_POST['username'];
221
+ $password = $_POST['password'];
222
+ $user_type = $_POST['user_type'];
223
+
224
+ $sql = "SELECT * FROM users WHERE username = '$username' AND user_type = '$user_type'";
225
+ $result = $conn->query($sql);
226
+
227
+ if ($result->num_rows > 0) {
228
+ $row = $result->fetch_assoc();
229
+ if (password_verify($password, $row['password'])) {
230
+ $_SESSION['username'] = $row['username'];
231
+ $_SESSION['user_type'] = $row['user_type'];
232
+ header('Location: index.php');
233
+ exit();
234
+ } else {
235
+ $error = "Invalid username or password.";
236
+ }
237
+ } else {
238
+ $error = "Invalid username, password, or user type.";
239
+ }
240
+ }
241
+ ?>
242
+
243
+ <!DOCTYPE html>
244
+ <html lang="en">
245
+ <head>
246
+ <meta charset="UTF-8">
247
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
248
+ <title>Login</title>
249
+ <style>
250
+ body {
251
+ font-family: Arial, sans-serif;
252
+ margin: 0;
253
+ padding: 0;
254
+ background: linear-gradient(to right, #1d3557, #457b9d);
255
+ display: flex;
256
+ justify-content: center;
257
+ align-items: center;
258
+ height: 100vh;
259
+ }
260
+
261
+ .container {
262
+ background: #fff;
263
+ padding: 20px;
264
+ border-radius: 8px;
265
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
266
+ width: 350px;
267
+ text-align: center;
268
+ }
269
+
270
+ .tabs {
271
+ display: flex;
272
+ justify-content: space-around;
273
+ margin-bottom: 20px;
274
+ }
275
+
276
+ .tabs button {
277
+ background: none;
278
+ border: none;
279
+ padding: 10px;
280
+ cursor: pointer;
281
+ font-size: 16px;
282
+ font-weight: bold;
283
+ color: #333;
284
+ }
285
+
286
+ .tabs button.active {
287
+ color: #1d3557;
288
+ border-bottom: 2px solid #1d3557;
289
+ }
290
+
291
+ .form {
292
+ display: none;
293
+ }
294
+
295
+ .form.active {
296
+ display: block;
297
+ }
298
+
299
+ .form input {
300
+ width: 90%;
301
+ padding: 10px;
302
+ margin: 10px 0;
303
+ border: 1px solid #ccc;
304
+ border-radius: 5px;
305
+ }
306
+
307
+ .form button {
308
+ width: 95%;
309
+ padding: 10px;
310
+ margin: 10px 0;
311
+ background: #1d3557;
312
+ color: #fff;
313
+ border: none;
314
+ border-radius: 5px;
315
+ cursor: pointer;
316
+ }
317
+
318
+ .form button:hover {
319
+ background: #457b9d;
320
+ }
321
+
322
+ .form a {
323
+ display: block;
324
+ color: #1d3557;
325
+ text-decoration: none;
326
+ margin-top: 10px;
327
+ }
328
+ </style>
329
+ </head>
330
+ <body>
331
+ <div class="container">
332
+ <h2>Login Form</h2>
333
+ <div class="tabs">
334
+ <button id="adminTab" class="active">Admin Login</button>
335
+ <button id="studentTab">Student Login</button>
336
+ </div>
337
+
338
+ <form id="adminForm" class="form active" method="POST" action="">
339
+ <input type="text" placeholder="Admin Username" name="username" required><br>
340
+ <input type="password" placeholder="Password" name="password" required><br>
341
+ <input type="hidden" name="user_type" value="admin">
342
+ <button type="submit">Login</button>
343
+ <a href="signup.php">Don't have an account? Sign up</a>
344
+ </form>
345
+
346
+ <form id="studentForm" class="form" method="POST" action="">
347
+ <input type="text" placeholder="Student Username" name="username" required><br>
348
+ <input type="password" placeholder="Password" name="password" required><br>
349
+ <input type="hidden" name="user_type" value="student">
350
+ <button type="submit">Login</button>
351
+ <a href="signup.php">Don't have an account? Sign up</a>
352
+ </form>
353
+
354
+ <?php if (isset($error)) echo "<p style='color: red;'>$error</p>"; ?>
355
+ </div>
356
+
357
+ <script>
358
+ const adminTab = document.getElementById('adminTab');
359
+ const studentTab = document.getElementById('studentTab');
360
+ const adminForm = document.getElementById('adminForm');
361
+ const studentForm = document.getElementById('studentForm');
362
+
363
+ adminTab.addEventListener('click', () => {
364
+ adminTab.classList.add('active');
365
+ studentTab.classList.remove('active');
366
+ adminForm.classList.add('active');
367
+ studentForm.classList.remove('active');
368
+ });
369
+
370
+ studentTab.addEventListener('click', () => {
371
+ studentTab.classList.add('active');
372
+ adminTab.classList.remove('active');
373
+ studentForm.classList.add('active');
374
+ adminForm.classList.remove('active');
375
+ });
376
+ </script>
377
+ </body>
378
+ </html>
379
+
380
+
381
+
382
+ logout.php
383
+
384
+ <?php
385
+ session_start();
386
+ session_destroy();
387
+ header('Location: login.php');
388
+ exit();
389
+ ?>
390
+
391
+
392
+ signup.php
393
+
394
+ <?php
395
+ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
396
+ include 'db.php';
397
+
398
+ $username = $_POST['username'];
399
+ $password = $_POST['password'];
400
+ $confirm_password = $_POST['confirm_password'];
401
+ $user_type = $_POST['user_type'];
402
+
403
+ if ($password !== $confirm_password) {
404
+ echo "<script>alert('Passwords do not match!'); window.history.back();</script>";
405
+ exit;
406
+ }
407
+
408
+ $hashed_password = password_hash($password, PASSWORD_BCRYPT);
409
+
410
+ $sql = "INSERT INTO users (username, password, user_type) VALUES ('$username', '$hashed_password', '$user_type')";
411
+ if ($conn->query($sql) === TRUE) {
412
+ header('Location: login.php');
413
+ } else {
414
+ echo "Error: " . $conn->error;
415
+ }
416
+ }
417
+ ?>
418
+
419
+ <!DOCTYPE html>
420
+ <html lang="en">
421
+ <head>
422
+ <meta charset="UTF-8">
423
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
424
+ <title>Signup</title>
425
+ <style>
426
+ body {
427
+ font-family: Arial, sans-serif;
428
+ margin: 0;
429
+ padding: 0;
430
+ background: linear-gradient(to right, #1d3557, #457b9d);
431
+ display: flex;
432
+ justify-content: center;
433
+ align-items: center;
434
+ height: 100vh;
435
+ }
436
+
437
+ .container {
438
+ background: #fff;
439
+ padding: 20px;
440
+ border-radius: 8px;
441
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
442
+ width: 350px;
443
+ text-align: center;
444
+ }
445
+
446
+ .tabs {
447
+ display: flex;
448
+ justify-content: space-around;
449
+ margin-bottom: 20px;
450
+ }
451
+
452
+ .tabs button {
453
+ background: none;
454
+ border: none;
455
+ padding: 10px;
456
+ cursor: pointer;
457
+ font-size: 16px;
458
+ font-weight: bold;
459
+ color: #333;
460
+ }
461
+
462
+ .tabs button.active {
463
+ color: #1d3557;
464
+ border-bottom: 2px solid #1d3557;
465
+ }
466
+
467
+ .form {
468
+ display: none;
469
+ }
470
+
471
+ .form.active {
472
+ display: block;
473
+ }
474
+
475
+ .form input {
476
+ width: 90%;
477
+ padding: 10px;
478
+ margin: 10px 0;
479
+ border: 1px solid #ccc;
480
+ border-radius: 5px;
481
+ }
482
+
483
+ .form button {
484
+ width: 95%;
485
+ padding: 10px;
486
+ margin: 10px 0;
487
+ background: #1d3557;
488
+ color: #fff;
489
+ border: none;
490
+ border-radius: 5px;
491
+ cursor: pointer;
492
+ }
493
+
494
+ .form button:hover {
495
+ background: #457b9d;
496
+ }
497
+
498
+ .form a {
499
+ display: block;
500
+ color: #1d3557;
501
+ text-decoration: none;
502
+ margin-top: 10px;
503
+ }
504
+ </style>
505
+ </head>
506
+ <body>
507
+ <div class="container">
508
+ <h2>Signup Form</h2>
509
+
510
+ <div class="tabs">
511
+ <button id="adminTab" class="active" onclick="showForm('admin')">Admin Signup</button>
512
+ <button id="studentTab" onclick="showForm('student')">Student Signup</button>
513
+ </div>
514
+
515
+ <form id="adminForm" class="form active" method="POST" action="">
516
+ <input type="text" name="username" placeholder="Admin Username" required>
517
+ <input type="password" name="password" id="adminPassword" placeholder="Password" required>
518
+ <input type="password" name="confirm_password" id="adminConfirmPassword" placeholder="Confirm Password" required>
519
+ <input type="hidden" name="user_type" value="admin">
520
+ <button type="submit" onclick="return validatePasswords('adminPassword', 'adminConfirmPassword')">Signup</button>
521
+ <a href="login.php">Already have an account? Login</a>
522
+ </form>
523
+
524
+ <form id="studentForm" class="form" method="POST" action="">
525
+ <input type="text" name="username" placeholder="Student Username" required>
526
+ <input type="password" name="password" id="studentPassword" placeholder="Password" required>
527
+ <input type="password" name="confirm_password" id="studentConfirmPassword" placeholder="Confirm Password" required>
528
+ <input type="hidden" name="user_type" value="student">
529
+ <button type="submit" onclick="return validatePasswords('studentPassword', 'studentConfirmPassword')">Signup</button>
530
+ <a href="login.php">Already have an account? Login</a>
531
+ </form>
532
+
533
+ </div>
534
+
535
+ <script>
536
+ function showForm(type) {
537
+ const adminTab = document.getElementById('adminTab');
538
+ const studentTab = document.getElementById('studentTab');
539
+ const adminForm = document.getElementById('adminForm');
540
+ const studentForm = document.getElementById('studentForm');
541
+
542
+ if (type === 'admin') {
543
+ adminTab.classList.add('active');
544
+ studentTab.classList.remove('active');
545
+ adminForm.classList.add('active');
546
+ studentForm.classList.remove('active');
547
+ } else {
548
+ studentTab.classList.add('active');
549
+ adminTab.classList.remove('active');
550
+ studentForm.classList.add('active');
551
+ adminForm.classList.remove('active');
552
+ }
553
+ }
554
+
555
+ function validatePasswords(passwordId, confirmPasswordId) {
556
+ const password = document.getElementById(passwordId).value;
557
+ const confirmPassword = document.getElementById(confirmPasswordId).value;
558
+ if (password !== confirmPassword) {
559
+ alert('Passwords do not match!');
560
+ return false;
561
+ }
562
+ return true;
563
+ }
564
+ </script>
565
+ </body>
566
+ </html>
567
+
568
+
569
+ view_resources.php
570
+
571
+ <?php
572
+ include 'db.php';
573
+ session_start();
574
+
575
+ if (!isset($_SESSION['username'])) {
576
+ header('Location: login.php');
577
+ exit();
578
+ }
579
+
580
+ $username = $_SESSION['username'];
581
+ $user_type = $_SESSION['user_type'];
582
+
583
+ // Handle delete resource request
584
+ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_resource'])) {
585
+ $resource_id = (int)$_POST['delete_resource'];
586
+ $delete_sql = "DELETE FROM resources WHERE id = ?";
587
+ $stmt = $conn->prepare($delete_sql);
588
+ $stmt->bind_param('i', $resource_id);
589
+
590
+ if ($stmt->execute()) {
591
+ $success_message = "Resource deleted successfully.";
592
+ } else {
593
+ $error_message = "Error deleting resource: " . $conn->error;
594
+ }
595
+ }
596
+
597
+ // Fetch institutions, departments, and resource types for dropdown filters
598
+ $institutions = $conn->query("SELECT DISTINCT institution FROM resources");
599
+ $departments = isset($_POST['institution']) ? $conn->query("SELECT DISTINCT department FROM resources WHERE institution = '" . $conn->real_escape_string($_POST['institution']) . "'") : null;
600
+ $resource_types = $conn->query("SELECT DISTINCT type FROM resources");
601
+
602
+ // Fetch resources based on filters
603
+ $filters = [];
604
+ $sql = "SELECT * FROM resources WHERE 1=1";
605
+
606
+ if (isset($_POST['institution']) && $_POST['institution'] !== '') {
607
+ $filters['institution'] = $_POST['institution'];
608
+ $sql .= " AND institution = ?";
609
+ }
610
+ if (isset($_POST['department']) && $_POST['department'] !== '') {
611
+ $filters['department'] = $_POST['department'];
612
+ $sql .= " AND department = ?";
613
+ }
614
+ if (isset($_POST['resource_type']) && $_POST['resource_type'] !== '') {
615
+ $filters['resource_type'] = $_POST['resource_type'];
616
+ $sql .= " AND type = ?";
617
+ }
618
+
619
+ $stmt = $conn->prepare($sql);
620
+ if ($filters) {
621
+ $stmt->bind_param(str_repeat('s', count($filters)), ...array_values($filters));
622
+ }
623
+ $stmt->execute();
624
+ $result = $stmt->get_result();
625
+ ?>
626
+
627
+ <!DOCTYPE html>
628
+ <html lang="en">
629
+ <head>
630
+ <meta charset="UTF-8">
631
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
632
+ <title>View Resources - Educational Resource Management System</title>
633
+ <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
634
+ <style>
635
+ * {
636
+ margin: 0;
637
+ padding: 0;
638
+ box-sizing: border-box;
639
+ }
640
+
641
+ body {
642
+ font-family: 'Roboto', sans-serif;
643
+ line-height: 1.6;
644
+ background-color: #f4f7f6;
645
+ color: #333;
646
+ }
647
+
648
+ .container {
649
+ max-width: 1200px;
650
+ margin: 0 auto;
651
+ padding: 20px;
652
+ }
653
+
654
+ .header {
655
+ background-color: #2c3e50;
656
+ color: white;
657
+ padding: 20px;
658
+ border-radius: 8px;
659
+ margin-bottom: 20px;
660
+ display: flex;
661
+ justify-content: space-between;
662
+ align-items: center;
663
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
664
+ }
665
+
666
+ .header h1 {
667
+ margin: 0;
668
+ font-size: 1.8rem;
669
+ }
670
+
671
+ .header a {
672
+ color: white;
673
+ text-decoration: none;
674
+ transition: color 0.3s ease;
675
+ }
676
+
677
+ .header a:hover {
678
+ color: #3498db;
679
+ }
680
+
681
+ .user-welcome {
682
+ background-color: #ecf0f1;
683
+ padding: 15px;
684
+ border-radius: 8px;
685
+ margin-bottom: 20px;
686
+ text-align: center;
687
+ }
688
+
689
+ .navigation {
690
+ display: flex;
691
+ justify-content: center;
692
+ margin-bottom: 20px;
693
+ }
694
+
695
+ .nav-list {
696
+ display: flex;
697
+ list-style-type: none;
698
+ gap: 20px;
699
+ }
700
+
701
+ .nav-list li a {
702
+ text-decoration: none;
703
+ color: #2c3e50;
704
+ padding: 10px 15px;
705
+ border-radius: 6px;
706
+ transition: all 0.3s ease;
707
+ background-color: #ecf0f1;
708
+ display: inline-block;
709
+ }
710
+
711
+ .nav-list li a:hover {
712
+ background-color: #3498db;
713
+ color: white;
714
+ transform: translateY(-3px);
715
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
716
+ }
717
+
718
+ .logout-btn {
719
+ background-color: #e74c3c;
720
+ color: white;
721
+ text-decoration: none;
722
+ padding: 10px 15px;
723
+ border-radius: 6px;
724
+ transition: background-color 0.3s ease;
725
+ }
726
+
727
+ .logout-btn:hover {
728
+ background-color: #c0392b;
729
+ }
730
+
731
+ .dashboard-content {
732
+ background-color: white;
733
+ border-radius: 8px;
734
+ padding: 20px;
735
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
736
+ }
737
+
738
+ .dashboard-content h2 {
739
+ color: #2c3e50;
740
+ margin-bottom: 15px;
741
+ text-align: center;
742
+ }
743
+
744
+ .filter-form {
745
+ display: flex;
746
+ justify-content: space-between;
747
+ margin-bottom: 20px;
748
+ }
749
+
750
+ .filter-form select {
751
+ padding: 10px;
752
+ border-radius: 4px;
753
+ border: 1px solid #ddd;
754
+ }
755
+
756
+ table {
757
+ width: 100%;
758
+ border-collapse: collapse;
759
+ }
760
+
761
+ th, td {
762
+ padding: 12px;
763
+ text-align: left;
764
+ border-bottom: 1px solid #ddd;
765
+ }
766
+
767
+ th {
768
+ background-color: #f2f2f2;
769
+ font-weight: bold;
770
+ }
771
+
772
+ .action-btn {
773
+ padding: 8px 12px;
774
+ border: none;
775
+ border-radius: 4px;
776
+ cursor: pointer;
777
+ transition: background-color 0.3s ease;
778
+ }
779
+
780
+ .download-btn {
781
+ background-color: #3498db;
782
+ color: white;
783
+ }
784
+
785
+ .download-btn:hover {
786
+ background-color: #2980b9;
787
+ }
788
+
789
+ .delete-btn {
790
+ background-color: #e74c3c;
791
+ color: white;
792
+ }
793
+
794
+ .delete-btn:hover {
795
+ background-color: #c0392b;
796
+ }
797
+
798
+ @media (max-width: 768px) {
799
+ .header {
800
+ flex-direction: column;
801
+ text-align: center;
802
+ }
803
+
804
+ .nav-list {
805
+ flex-direction: column;
806
+ align-items: center;
807
+ }
808
+
809
+ .filter-form {
810
+ flex-direction: column;
811
+ }
812
+
813
+ .filter-form select {
814
+ margin-bottom: 10px;
815
+ }
816
+ }
817
+ </style>
818
+ </head>
819
+ <body>
820
+ <div class="container">
821
+ <div class="header">
822
+ <h1><a href="index.php">Educational Resource Management System</a></h1>
823
+ <a href="logout.php" class="logout-btn">Logout</a>
824
+ </div>
825
+
826
+ <div class="user-welcome">
827
+ <h2>Welcome, <?php echo htmlspecialchars($username); ?>!</h2>
828
+ <p>You are logged in as a <?php echo htmlspecialchars($user_type); ?></p>
829
+ </div>
830
+
831
+ <nav>
832
+ <ul class="nav-list">
833
+ <?php if ($user_type === 'admin'): ?>
834
+ <li><a href="add_resource.php">Add Resource</a></li>
835
+ <?php endif; ?>
836
+ <li><a href="view_resources.php">View Resources</a></li>
837
+ </ul>
838
+ </nav>
839
+
840
+ <div class="dashboard-content">
841
+ <h2>View Resources</h2>
842
+
843
+ <?php
844
+ if (isset($success_message)) {
845
+ echo "<p style='color: green;'>$success_message</p>";
846
+ }
847
+ if (isset($error_message)) {
848
+ echo "<p style='color: red;'>$error_message</p>";
849
+ }
850
+ ?>
851
+
852
+ <form method="POST" action="" class="filter-form">
853
+ <select name="institution" onchange="this.form.submit()">
854
+ <option value="">Select Institution</option>
855
+ <?php while ($row = $institutions->fetch_assoc()): ?>
856
+ <option value="<?php echo htmlspecialchars($row['institution']); ?>"
857
+ <?php if (isset($_POST['institution']) && $_POST['institution'] === $row['institution']) echo 'selected'; ?>>
858
+ <?php echo htmlspecialchars($row['institution']); ?>
859
+ </option>
860
+ <?php endwhile; ?>
861
+ </select>
862
+
863
+ <select name="department" onchange="this.form.submit()">
864
+ <option value="">Select Department</option>
865
+ <?php if (isset($departments)): ?>
866
+ <?php while ($row = $departments->fetch_assoc()): ?>
867
+ <option value="<?php echo htmlspecialchars($row['department']); ?>"
868
+ <?php if (isset($_POST['department']) && $_POST['department'] === $row['department']) echo 'selected'; ?>>
869
+ <?php echo htmlspecialchars($row['department']); ?>
870
+ </option>
871
+ <?php endwhile; ?>
872
+ <?php endif; ?>
873
+ </select>
874
+
875
+ <select name="resource_type" onchange="this.form.submit()">
876
+ <option value="">Select Resource Type</option>
877
+ <?php while ($row = $resource_types->fetch_assoc()): ?>
878
+ <option value="<?php echo htmlspecialchars($row['type']); ?>"
879
+ <?php if (isset($_POST['resource_type']) && $_POST['resource_type'] === $row['type']) echo 'selected'; ?>>
880
+ <?php echo htmlspecialchars($row['type']); ?>
881
+ </option>
882
+ <?php endwhile; ?>
883
+ </select>
884
+ </form>
885
+
886
+ <?php if ($result->num_rows > 0): ?>
887
+ <table>
888
+ <tr>
889
+ <th>Resource Name</th>
890
+ <th>Resource Type</th>
891
+ <th>Institution</th>
892
+ <th>Department</th>
893
+ <?php if ($user_type === 'admin'): ?>
894
+ <th>Download</th>
895
+ <th>Delete</th>
896
+ <?php else: ?>
897
+ <th>Download</th>
898
+ <?php endif; ?>
899
+ </tr>
900
+ <?php while ($row = $result->fetch_assoc()): ?>
901
+ <tr>
902
+ <td><?php echo htmlspecialchars($row['name']); ?></td>
903
+ <td><?php echo htmlspecialchars($row['type']); ?></td>
904
+ <td><?php echo htmlspecialchars($row['institution']); ?></td>
905
+ <td><?php echo htmlspecialchars($row['department']); ?></td>
906
+ <td>
907
+ <a href="uploads/<?php echo htmlspecialchars($row['resource_file']); ?>" download class="action-btn download-btn">Download</a>
908
+ </td>
909
+ <?php if ($user_type === 'admin'): ?>
910
+ <td>
911
+ <form method="POST" action="" style="display: inline;">
912
+ <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>
913
+ </form>
914
+ </td>
915
+ <?php endif; ?>
916
+ </tr>
917
+ <?php endwhile; ?>
918
+ </table>
919
+ <?php else: ?>
920
+ <p>No resources available.</p>
921
+ <?php endif; ?>
922
+ </div>
923
+ </div>
924
+ </body>
925
+ </html>
926
+
927
+
928
+
929
+ add_resources.php
930
+
931
+ <?php
932
+ include 'db.php';
933
+ session_start();
934
+ if (!isset($_SESSION['username'])) {
935
+ header('Location: login.php');
936
+ exit();
937
+ }
938
+ $username = $_SESSION['username'];
939
+ $user_type = $_SESSION['user_type'];
940
+ ?>
941
+
942
+ <!DOCTYPE html>
943
+ <html lang="en">
944
+ <head>
945
+ <meta charset="UTF-8">
946
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
947
+ <title>Add Resource - Educational Resource Management System</title>
948
+ <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
949
+ <style>
950
+ * {
951
+ margin: 0;
952
+ padding: 0;
953
+ box-sizing: border-box;
954
+ }
955
+
956
+ body {
957
+ font-family: 'Roboto', sans-serif;
958
+ line-height: 1.6;
959
+ background-color: #f4f7f6;
960
+ color: #333;
961
+ }
962
+
963
+ .container {
964
+ max-width: 1200px;
965
+ margin: 0 auto;
966
+ padding: 20px;
967
+ }
968
+
969
+ .header {
970
+ background-color: #2c3e50;
971
+ color: white;
972
+ padding: 20px;
973
+ border-radius: 8px;
974
+ margin-bottom: 20px;
975
+ display: flex;
976
+ justify-content: space-between;
977
+ align-items: center;
978
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
979
+ }
980
+
981
+ .header h1 {
982
+ margin: 0;
983
+ font-size: 1.8rem;
984
+ }
985
+
986
+ .header h1 a {
987
+ color: white;
988
+ text-decoration: none;
989
+ transition: color 0.3s ease;
990
+ }
991
+
992
+ .header h1 a:hover {
993
+ color: #3498db;
994
+ }
995
+
996
+ .logout-btn {
997
+ background-color: #e74c3c;
998
+ color: white;
999
+ text-decoration: none;
1000
+ padding: 10px 15px;
1001
+ border-radius: 6px;
1002
+ transition: background-color 0.3s ease;
1003
+ }
1004
+
1005
+ .logout-btn:hover {
1006
+ background-color: #c0392b;
1007
+ }
1008
+
1009
+ .user-welcome {
1010
+ background-color: #ecf0f1;
1011
+ padding: 15px;
1012
+ border-radius: 8px;
1013
+ margin-bottom: 20px;
1014
+ text-align: center;
1015
+ }
1016
+
1017
+ .navigation {
1018
+ display: flex;
1019
+ justify-content: center;
1020
+ margin-bottom: 20px;
1021
+ }
1022
+
1023
+ .nav-list {
1024
+ display: flex;
1025
+ list-style-type: none;
1026
+ gap: 20px;
1027
+ }
1028
+
1029
+ .nav-list li a {
1030
+ text-decoration: none;
1031
+ color: #2c3e50;
1032
+ padding: 10px 15px;
1033
+ border-radius: 6px;
1034
+ transition: all 0.3s ease;
1035
+ background-color: #ecf0f1;
1036
+ display: inline-block;
1037
+ }
1038
+
1039
+ .nav-list li a:hover {
1040
+ background-color: #3498db;
1041
+ color: white;
1042
+ transform: translateY(-3px);
1043
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
1044
+ }
1045
+
1046
+ .dashboard-content {
1047
+ background-color: white;
1048
+ border-radius: 8px;
1049
+ padding: 20px;
1050
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
1051
+ }
1052
+
1053
+ .dashboard-content h2 {
1054
+ color: #2c3e50;
1055
+ margin-bottom: 20px;
1056
+ text-align: center;
1057
+ }
1058
+
1059
+ .add-resource-form {
1060
+ max-width: 600px;
1061
+ margin: 0 auto;
1062
+ }
1063
+
1064
+ .form-group {
1065
+ margin-bottom: 15px;
1066
+ }
1067
+
1068
+ .form-group label {
1069
+ display: block;
1070
+ margin-bottom: 5px;
1071
+ color: #2c3e50;
1072
+ }
1073
+
1074
+ .form-group input,
1075
+ .form-group select {
1076
+ width: 100%;
1077
+ padding: 10px;
1078
+ border: 1px solid #ddd;
1079
+ border-radius: 4px;
1080
+ font-size: 16px;
1081
+ }
1082
+
1083
+ .submit-btn {
1084
+ width: 100%;
1085
+ padding: 12px;
1086
+ background-color: #3498db;
1087
+ color: white;
1088
+ border: none;
1089
+ border-radius: 6px;
1090
+ cursor: pointer;
1091
+ font-size: 16px;
1092
+ transition: background-color 0.3s ease;
1093
+ }
1094
+
1095
+ .submit-btn:hover {
1096
+ background-color: #2980b9;
1097
+ }
1098
+
1099
+ @media (max-width: 768px) {
1100
+ .header {
1101
+ flex-direction: column;
1102
+ text-align: center;
1103
+ }
1104
+
1105
+ .nav-list {
1106
+ flex-direction: column;
1107
+ align-items: center;
1108
+ }
1109
+ }
1110
+ </style>
1111
+ </head>
1112
+ <body>
1113
+ <div class="container">
1114
+ <div class="header">
1115
+ <h1><a href="index.php">Educational Resource Management System</a></h1>
1116
+ <a href="logout.php" class="logout-btn">Logout</a>
1117
+ </div>
1118
+
1119
+ <div class="user-welcome">
1120
+ <h2>Welcome, <?php echo htmlspecialchars($username); ?>!</h2>
1121
+ <p>You are logged in as a <?php echo htmlspecialchars($user_type); ?></p>
1122
+ </div>
1123
+
1124
+ <nav>
1125
+ <ul class="nav-list">
1126
+ <?php if ($user_type === 'admin'): ?>
1127
+ <li><a href="add_resource.php">Add Resource</a></li>
1128
+ <?php endif; ?>
1129
+ <li><a href="view_resources.php">View Resources</a></li>
1130
+ </ul>
1131
+ </nav>
1132
+
1133
+ <div class="dashboard-content">
1134
+ <h2>Add New Resource</h2>
1135
+
1136
+ <?php
1137
+ if ($_SERVER["REQUEST_METHOD"] == "POST") {
1138
+ $name = $_POST['name'];
1139
+ $type = $_POST['type'];
1140
+ $institution = $_POST['institution'];
1141
+ $department = $_POST['department'];
1142
+ $resource_file = $_FILES['resource_file']['name'];
1143
+
1144
+ // Save the uploaded file to the uploads directory
1145
+ $target_dir = "uploads/";
1146
+ $target_file = $target_dir . basename($_FILES["resource_file"]["name"]);
1147
+
1148
+ if (move_uploaded_file($_FILES["resource_file"]["tmp_name"], $target_file)) {
1149
+ // Insert the resource details into the database
1150
+ $sql = "INSERT INTO resources (name, type, institution, department, resource_file)
1151
+ VALUES ('$name', '$type', '$institution', '$department', '$resource_file')";
1152
+
1153
+ if ($conn->query($sql) === TRUE) {
1154
+ echo "<div style='color: green; text-align: center; margin-bottom: 15px;'>Resource added successfully!</div>";
1155
+ } else {
1156
+ echo "<div style='color: red; text-align: center; margin-bottom: 15px;'>Error: " . $conn->error . "</div>";
1157
+ }
1158
+ } else {
1159
+ echo "<div style='color: red; text-align: center; margin-bottom: 15px;'>Sorry, there was an error uploading your file.</div>";
1160
+ }
1161
+ }
1162
+ ?>
1163
+
1164
+ <form action="add_resource.php" method="POST" enctype="multipart/form-data" class="add-resource-form">
1165
+ <div class="form-group">
1166
+ <label for="name">Resource Name:</label>
1167
+ <input type="text" id="name" name="name" required>
1168
+ </div>
1169
+
1170
+ <div class="form-group">
1171
+ <label for="type">Resource Type:</label>
1172
+ <select id="type" name="type" required>
1173
+ <option value="" disabled selected>Select Resource Type</option>
1174
+ <option value="Textbooks">Textbooks</option>
1175
+ <option value="Digital Materials">Digital Materials</option>
1176
+ <option value="Library Books">Library Books</option>
1177
+ </select>
1178
+ </div>
1179
+
1180
+ <div class="form-group">
1181
+ <label for="institution">Institution:</label>
1182
+ <select id="institution" name="institution" onchange="updateDepartments()" required>
1183
+ <option value="" disabled selected>Select Institution</option>
1184
+ <option value="MIT Institute of Design">MIT Institute of Design</option>
1185
+ <option value="MIT College of Management">MIT College of Management</option>
1186
+ <option value="MIT School of Food Technology">MIT School of Food Technology</option>
1187
+ <option value="MIT School of Film and Theatre">MIT School of Film and Theatre</option>
1188
+ <option value="MIT School of Indian Civil Services">MIT School of Indian Civil Services</option>
1189
+ <option value="MIT School of Computing">MIT School of Computing</option>
1190
+ </select>
1191
+ </div>
1192
+
1193
+ <div class="form-group">
1194
+ <label for="department">Department:</label>
1195
+ <select id="department" name="department" required>
1196
+ <option value="" disabled selected>Select Department</option>
1197
+ </select>
1198
+ </div>
1199
+
1200
+ <div class="form-group">
1201
+ <label for="resource_file">Upload Resource (PDF/Video):</label>
1202
+ <input type="file" id="resource_file" name="resource_file" required>
1203
+ </div>
1204
+
1205
+ <button type="submit" class="submit-btn">Add Resource</button>
1206
+ </form>
1207
+ </div>
1208
+ </div>
1209
+
1210
+ <script>
1211
+ // Departments for each institution
1212
+ const departments = {
1213
+ "MIT Institute of Design": [
1214
+ "Bachelor of Design",
1215
+ "Master of Design (Animation Design)",
1216
+ "Master of Design (Design Management)",
1217
+ "Master of Design (Fashion Management and Marketing)"
1218
+ ],
1219
+ "MIT College of Management": [
1220
+ "Bachelor of Commerce (HONORS)",
1221
+ "Bachelor of Computer Applications",
1222
+ "Master of Business Administration (Executive)"
1223
+ ],
1224
+ "MIT School of Food Technology": [
1225
+ "B. Tech. (Food Technology)",
1226
+ "M. Tech. (Food Safety and Quality Management)",
1227
+ "M. Tech. (Food Technology)"
1228
+ ],
1229
+ "MIT School of Film and Theatre": [
1230
+ "B.A. in Direction & Screenplay Writing",
1231
+ "B.Sc. in Filmmaking",
1232
+ "Bachelor of Arts (Dramatics)",
1233
+ "M.A. in Direction & Screenplay Writing"
1234
+ ],
1235
+ "MIT School of Indian Civil Services": [
1236
+ "B.A. (Administration)",
1237
+ "M.A. (Administration)"
1238
+ ],
1239
+ "MIT School of Computing": [
1240
+ "Bachelor of Technology (Computer Science & Engineering)",
1241
+ "Master of Science (Computer Science/Artificial Intelligence & Machine Learning)",
1242
+ "Master of Technology (Computer Science & Engineering - Intelligent Systems & Analysis)",
1243
+ "Master of Technology (Information Technology - Cyber Security)"
1244
+ ]
1245
+ };
1246
+
1247
+ // Function to update department options based on selected institution
1248
+ function updateDepartments() {
1249
+ const institutionSelect = document.getElementById("institution");
1250
+ const departmentSelect = document.getElementById("department");
1251
+ const selectedInstitution = institutionSelect.value;
1252
+
1253
+ // Clear the current options in the department dropdown
1254
+ departmentSelect.innerHTML = "<option value='' disabled selected>Select Department</option>";
1255
+
1256
+ // Get departments for the selected institution
1257
+ if (departments[selectedInstitution]) {
1258
+ departments[selectedInstitution].forEach(department => {
1259
+ const option = document.createElement("option");
1260
+ option.value = department;
1261
+ option.text = department;
1262
+ departmentSelect.appendChild(option);
1263
+ });
1264
+ }
1265
+ }
1266
+ </script>
1267
+ </body>
1268
+ </html>
1269
+
1270
+
1271
+ db.php
1272
+
1273
+ <?php
1274
+ // db.php - Database connection
1275
+ $servername = "127.0.0.1"; // Use IP instead of "localhost"
1276
+ $username = "root";
1277
+ $password = ""; // If you have a password, enter it here
1278
+ $dbname = "resource_management";
1279
+ $port = 3307; // Specify the correct port
1280
+
1281
+ $conn = new mysqli($servername, $username, $password, $dbname, $port);
1282
+
1283
+ if ($conn->connect_error) {
1284
+ die("Connection failed: " . $conn->connect_error);
1285
+ }
1286
+
1287
+ ?>