File size: 5,031 Bytes
a8a001c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!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">
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
    <div class="container">
        <div class="header">
            <h1><a href="{{ url_for('index') }}">Educational Resource Management System</a></h1>
            <a href="{{ url_for('logout') }}" class="logout-btn">Logout</a>
        </div>

        <div class="user-welcome">
            <h2>Welcome, {{ session['username'] }}!</h2>
            <p>You are logged in as a {{ user_type }}</p>
        </div>

        <nav>
            <ul class="nav-list">
                {% if user_type == 'admin' %}
                    <li><a href="{{ url_for('add_resource') }}">Add Resource</a></li>
                {% endif %}
                <li><a href="{{ url_for('view_resources') }}">View Resources</a></li>
            </ul>
        </nav>

        <div class="dashboard-content">
            <h2>View Resources</h2>

            {% with messages = get_flashed_messages(with_categories=true) %}
                {% if messages %}
                    {% for category, message in messages %}
                        <p style="color: {{ 'red' if category == 'error' else 'green' }}">{{ message }}</p>
                    {% endfor %}
                {% endif %}
            {% endwith %}

            <form method="POST" action="{{ url_for('view_resources') }}" class="filter-form">
                <select name="institution" onchange="this.form.submit()">
                    <option value="">Select Institution</option>
                    {% for inst in institutions %}
                        <option value="{{ inst.institution }}" {% if filters.institution == inst.institution %}selected{% endif %}>{{ inst.institution }}</option>
                    {% endfor %}
                </select>

                <select name="department" onchange="this.form.submit()">
                    <option value="">Select Department</option>
                    {% if departments %}
                        {% for dept in departments %}
                            <option value="{{ dept.department }}" {% if filters.department == dept.department %}selected{% endif %}>{{ dept.department }}</option>
                        {% endfor %}
                    {% endif %}
                </select>

                <select name="resource_type" onchange="this.form.submit()">
                    <option value="">Select Resource Type</option>
                    {% for rtype in resource_types %}
                        <option value="{{ rtype.type }}" {% if filters.resource_type == rtype.type %}selected{% endif %}>{{ rtype.type }}</option>
                    {% endfor %}
                </select>
            </form>

            {% if resources %}
                <table>
                    <tr>
                        <th>Resource Name</th>
                        <th>Resource Type</th>
                        <th>Institution</th>
                        <th>Department</th>
                        {% if user_type == 'admin' %}
                            <th>Download</th>
                            <th>Delete</th>
                        {% else %}
                            <th>Download</th>
                        {% endif %}
                    </tr>
                    {% for resource in resources %}
                        <tr>
                            <td>{{ resource.name }}</td>
                            <td>{{ resource.type }}</td>
                            <td>{{ resource.institution }}</td>
                            <td>{{ resource.department }}</td>
                            <td>
                                <a href="{{ url_for('uploaded_file', filename=resource.resource_file) }}" download class="action-btn download-btn">Download</a>
                            </td>
                            {% if user_type == 'admin' %}
                                <td>
                                    <form method="POST" action="{{ url_for('view_resources') }}" style="display: inline;">
                                        <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>
                                    </form>
                                </td>
                            {% endif %}
                        </tr>
                    {% endfor %}
                </table>
            {% else %}
                <p>No resources available.</p>
            {% endif %}
        </div>
    </div>
</body>
</html>