Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified ams.db
Binary file not shown.
61 changes: 60 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,19 @@ def init_db():
FOREIGN KEY (teacher_id) REFERENCES teacher(teacher_id)
)
""")

# Feedback table
cursor.execute("""
CREATE TABLE IF NOT EXISTS feedback (
id INTEGER PRIMARY KEY AUTOINCREMENT,
role TEXT NOT NULL,
name TEXT,
email TEXT,
feedback_type TEXT NOT NULL,
message TEXT NOT NULL,
rating INTEGER,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
""")
# Insert default super admin if not exists
cursor.execute("SELECT COUNT(*) FROM admin WHERE admin_id = 'superadmin'")
if cursor.fetchone()[0] == 0:
Expand Down Expand Up @@ -1605,7 +1617,54 @@ def export_achievement(achievement_id):
flash("Failed to generate export card. Please try again.", "danger")
return redirect(url_for("student-achievements"))

# ─── Feedback Routes ───────────────────────────────────────────────────────────

@app.route("/feedback", methods=["GET", "POST"])
def feedback():
if request.method == "POST":
role = request.form.get("role", "").strip()
name = request.form.get("name", "").strip()
email = request.form.get("email", "").strip()
feedback_type = request.form.get("feedback_type", "").strip()
message = request.form.get("message", "").strip()
rating = request.form.get("rating", None)

if not role or not feedback_type or not message:
flash("Please fill in all required fields.", "danger")
return redirect(url_for("feedback"))

try:
rating = int(rating) if rating else None
except ValueError:
rating = None

conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
cursor.execute("""
INSERT INTO feedback (role, name, email, feedback_type, message, rating)
VALUES (?, ?, ?, ?, ?, ?)
""", (role, name or None, email or None, feedback_type, message, rating))
conn.commit()
conn.close()

flash("Thank you for your feedback!", "success")
return redirect(url_for("feedback"))

return render_template("feedback.html")


@app.route("/admin/feedback")
def admin_feedback():
if session.get("admin_logged_in") != True:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR AUTH Admin feedback page always redirects due to nonexistent session key

admin_logged_in is never set anywhere in the codebase; every other admin route checks session.get("logged_in") and session.get("admin_id"), so legitimate admins are always bounced to the login page.

Suggested change
if session.get("admin_logged_in") != True:
if not session.get("logged_in") or not session.get("admin_id"):
Prompt to fix with AI

Copy this prompt into your AI coding assistant to fix this issue.

In `app.py` at line 1658, the condition `if session.get("admin_logged_in") != True:` uses a session key that is never set anywhere in the application. Fix it to match the existing admin auth pattern used throughout the codebase: replace line 1658 with `if not session.get("logged_in") or not session.get("admin_id"):`. This makes the admin feedback page consistent with every other admin-only route (e.g. lines 286, 342) and allows authenticated admins to actually access the page.

return redirect(url_for("admin_login"))

conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
cursor.execute("SELECT * FROM feedback ORDER BY created_at DESC")
feedbacks = cursor.fetchall()
conn.close()

return render_template("admin_feedback.html", feedbacks=feedbacks)
if __name__ == "__main__":
init_db()
add_profile_picture_column()
Expand Down
50 changes: 50 additions & 0 deletions templates/admin_feedback.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% extends "base.html" %}
{% block content %}

<div style="max-width: 1100px; margin: 40px auto; padding: 0 20px;">
<h2 style="font-size:1.8rem; margin-bottom:6px; color:#1a1a2e;">Feedback Submissions</h2>
<p style="color:#666; margin-bottom:28px;">All feedback submitted by students and teachers.</p>

{% if feedbacks %}
<div style="overflow-x:auto;">
<table style="width:100%; border-collapse:collapse; background:#fff; border-radius:12px; overflow:hidden; box-shadow:0 2px 12px rgba(0,0,0,0.07);">
<thead>
<tr style="background:linear-gradient(135deg,#4f46e5,#7c3aed); color:#fff;">
<th style="padding:14px 16px; text-align:left;">#</th>
<th style="padding:14px 16px; text-align:left;">Role</th>
<th style="padding:14px 16px; text-align:left;">Name</th>
<th style="padding:14px 16px; text-align:left;">Email</th>
<th style="padding:14px 16px; text-align:left;">Type</th>
<th style="padding:14px 16px; text-align:left;">Message</th>
<th style="padding:14px 16px; text-align:left;">Rating</th>
<th style="padding:14px 16px; text-align:left;">Submitted</th>
</tr>
</thead>
<tbody>
{% for fb in feedbacks %}
<tr style="border-bottom:1px solid #f0f0f0; {% if loop.index is odd %}background:#fafafa;{% endif %}">
<td style="padding:12px 16px; color:#999;">{{ fb[0] }}</td>
<td style="padding:12px 16px;">
<span style="padding:4px 10px; border-radius:20px; font-size:0.8rem; font-weight:600; background:{{ '#dbeafe' if fb[1] == 'Student' else '#fef9c3' }}; color:{{ '#1d4ed8' if fb[1] == 'Student' else '#854d0e' }};">{{ fb[1] }}</span>
</td>
<td style="padding:12px 16px;">{{ fb[2] or '—' }}</td>
<td style="padding:12px 16px;">{{ fb[3] or '—' }}</td>
<td style="padding:12px 16px; font-weight:500;">{{ fb[4] }}</td>
<td style="padding:12px 16px; max-width:280px; color:#444;">{{ fb[5] }}</td>
<td style="padding:12px 16px; font-size:1.1rem;">
{% if fb[6] %}{% for i in range(fb[6]) %}⭐{% endfor %}{% else %}—{% endif %}
</td>
<td style="padding:12px 16px; color:#999; font-size:0.85rem;">{{ fb[7][:16] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div style="text-align:center; padding:60px; background:#fff; border-radius:16px; box-shadow:0 2px 12px rgba(0,0,0,0.07);">
<p style="font-size:1.2rem; color:#999;">No feedback submitted yet.</p>
</div>
{% endif %}
</div>

{% endblock %}
1 change: 1 addition & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ <h2>Achievement Management System</h2>
<li><a href="{{ url_for('teacher') }}">Teacher Login</a></li>
{% endif %}
<li><a href="#FAQ">FAQ</a></li>
<li><a href="{{ url_for('feedback') }}">Feedback</a></li>
</ul>
<div class="nav-toggle">
<span class="bar"></span>
Expand Down
102 changes: 102 additions & 0 deletions templates/feedback.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{% extends "base.html" %}
{% block content %}

<div style="max-width: 680px; margin: 60px auto; padding: 0 20px;">

{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div style="
padding: 14px 18px;
margin-bottom: 20px;
border-radius: 10px;
font-weight: 500;
background: {{ '#d4edda' if category == 'success' else '#f8d7da' }};
color: {{ '#155724' if category == 'success' else '#721c24' }};
border: 1px solid {{ '#c3e6cb' if category == 'success' else '#f5c6cb' }};
">{{ message }}</div>
{% endfor %}
{% endif %}
{% endwith %}

<div style="background:#fff; border-radius:16px; box-shadow:0 4px 24px rgba(0,0,0,0.08); padding:40px;">
<h2 style="margin:0 0 6px; font-size:1.8rem; color:#1a1a2e;">Share Your Feedback</h2>
<p style="margin:0 0 28px; color:#666;">Help us improve the Achievement Management System.</p>

<form method="POST" action="/feedback">

<div style="margin-bottom:20px;">
<label style="display:block; font-weight:600; margin-bottom:8px; color:#333;">I am a <span style="color:red">*</span></label>
<div style="display:flex; gap:12px;">
{% for role in ['Student', 'Teacher'] %}
<label style="flex:1; display:flex; align-items:center; gap:10px; padding:12px 16px; border:2px solid #e0e0e0; border-radius:10px; cursor:pointer; font-weight:500;">
<input type="radio" name="role" value="{{ role }}" required style="accent-color:#4f46e5; width:18px; height:18px;">
{{ role }}
</label>
{% endfor %}
</div>
</div>

<div style="margin-bottom:20px;">
<label style="display:block; font-weight:600; margin-bottom:8px; color:#333;">Name <span style="color:#999; font-weight:400;">(optional)</span></label>
<input type="text" name="name" placeholder="Your name" style="width:100%; padding:12px 14px; border:2px solid #e0e0e0; border-radius:10px; font-size:1rem; box-sizing:border-box; outline:none;" onfocus="this.style.borderColor='#4f46e5'" onblur="this.style.borderColor='#e0e0e0'">
</div>

<div style="margin-bottom:20px;">
<label style="display:block; font-weight:600; margin-bottom:8px; color:#333;">Email <span style="color:#999; font-weight:400;">(optional, for follow-up)</span></label>
<input type="email" name="email" placeholder="your@email.com" style="width:100%; padding:12px 14px; border:2px solid #e0e0e0; border-radius:10px; font-size:1rem; box-sizing:border-box; outline:none;" onfocus="this.style.borderColor='#4f46e5'" onblur="this.style.borderColor='#e0e0e0'">
</div>

<div style="margin-bottom:20px;">
<label style="display:block; font-weight:600; margin-bottom:8px; color:#333;">Feedback Type <span style="color:red">*</span></label>
<select name="feedback_type" required style="width:100%; padding:12px 14px; border:2px solid #e0e0e0; border-radius:10px; font-size:1rem; box-sizing:border-box; background:#fff; outline:none;" onfocus="this.style.borderColor='#4f46e5'" onblur="this.style.borderColor='#e0e0e0'">
<option value="" disabled selected>Select a type</option>
<option value="Bug Report">🐛 Bug Report</option>
<option value="Feature Request">✨ Feature Request</option>
<option value="General Feedback">💬 General Feedback</option>
<option value="Academic Concern">📚 Academic Concern</option>
</select>
</div>

<div style="margin-bottom:20px;">
<label style="display:block; font-weight:600; margin-bottom:8px; color:#333;">Message / Suggestion <span style="color:red">*</span></label>
<textarea name="message" rows="5" placeholder="Describe your feedback in detail..." required style="width:100%; padding:12px 14px; border:2px solid #e0e0e0; border-radius:10px; font-size:1rem; box-sizing:border-box; resize:vertical; outline:none;" onfocus="this.style.borderColor='#4f46e5'" onblur="this.style.borderColor='#e0e0e0'"></textarea>
</div>

<div style="margin-bottom:28px;">
<label style="display:block; font-weight:600; margin-bottom:8px; color:#333;">Overall Experience (1–5)</label>
<div style="display:flex; gap:8px;" id="star-rating">
{% for i in range(1, 6) %}
<label style="cursor:pointer; font-size:2rem; color:#ccc;" class="star-label">
<input type="radio" name="rating" value="{{ i }}" style="display:none;" class="star-input">★
</label>
{% endfor %}
</div>
</div>

<button type="submit" style="width:100%; padding:14px; background:linear-gradient(135deg,#4f46e5,#7c3aed); color:#fff; border:none; border-radius:10px; font-size:1rem; font-weight:600; cursor:pointer;">
Submit Feedback
</button>

</form>
</div>
</div>

<script>
const stars = document.querySelectorAll('.star-label');
stars.forEach((star, index) => {
star.addEventListener('mouseover', () => {
stars.forEach((s, i) => s.style.color = i <= index ? '#f59e0b' : '#ccc');
});
star.addEventListener('mouseout', () => {
const checked = document.querySelector('.star-input:checked');
const checkedIndex = checked ? parseInt(checked.value) - 1 : -1;
stars.forEach((s, i) => s.style.color = i <= checkedIndex ? '#f59e0b' : '#ccc');
});
star.addEventListener('click', () => {
stars.forEach((s, i) => s.style.color = i <= index ? '#f59e0b' : '#ccc');
});
});
</script>

{% endblock %}
Loading