# app.py import streamlit as st import pandas as pd import os # بيانات المستخدمين (مؤقتًا ثابتة) users = { "user1": {"password": "1234", "role": "user"}, "admin1": {"password": "admin", "role": "admin"} } CSV_FILE = "complaints.csv" # إنشاء الملف لو مش موجود if not os.path.exists(CSV_FILE): df = pd.DataFrame(columns=["id", "username", "complaint", "status", "response"]) df.to_csv(CSV_FILE, index=False) # تحميل البيانات def load_data(): return pd.read_csv(CSV_FILE) # حفظ البيانات def save_data(df): df.to_csv(CSV_FILE, index=False) # تسجيل الدخول def login(): st.sidebar.title("🔐 Login") username = st.sidebar.text_input("Username") password = st.sidebar.text_input("Password", type="password") if st.sidebar.button("Login"): if username in users and users[username]["password"] == password: return username, users[username]["role"] else: st.sidebar.error("❌ Invalid credentials") return None, None return None, None # واجهة المستخدم العادي def user_interface(username): st.title("📨 Submit a Complaint") complaint = st.text_area("Your Complaint") if st.button("Submit"): df = load_data() new_id = len(df) + 1 new_row = pd.DataFrame([[new_id, username, complaint, "Open", ""]], columns=df.columns) df = pd.concat([df, new_row], ignore_index=True) save_data(df) st.success("✅ Complaint submitted successfully!") st.subheader("📋 Your Complaints") df = load_data() user_df = df[df["username"] == username] st.table(user_df) # واجهة المسؤول def admin_interface(): st.title("🛠️ Admin Dashboard") df = load_data() for i, row in df.iterrows(): st.markdown(f"**Complaint #{row['id']} by {row['username']}**") st.markdown(f"- Complaint: {row['complaint']}") st.markdown(f"- Status: `{row['status']}`") response = st.text_input(f"Response for Complaint #{row['id']}", value=row['response'], key=f"res_{row['id']}") status = st.selectbox("Update Status", ["Open", "In Progress", "Closed"], index=["Open", "In Progress", "Closed"].index(row['status']), key=f"stat_{row['id']}") if st.button(f"Update #{row['id']}"): df.at[i, "response"] = response df.at[i, "status"] = status save_data(df) st.success(f"✅ Complaint #{row['id']} updated.") # التطبيق الرئيسي def main(): username, role = login() if username: if role == "user": user_interface(username) elif role == "admin": admin_interface() if __name__ == "__main__": main()