Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines9101112121314151516171837 unmodified lines56575859596061625 unmodified lines6869707172737475767778798081827172737475767778798081828384858687888984909192938 unmodified lines102103104991051061071031081091101111121081131141151162 unmodified lines1191201211171181191201211221231241251251261271281292 unmodified lines1321331341341351361371388 unmodified lines# تحميل أو إنشاء ملف CSVfile_path = "complaints.csv"if os.path.exists(file_path): df = pd.read_csv(file_path) df = pd.read_csv(file_path, encoding='utf-8-sig')else: df = pd.DataFrame(columns=["complaint_id", "username", "complaint_text", "status", "response", "timestamp"]) df.to_csv(file_path, index=False) df.to_csv(file_path, index=False, encoding='utf-8-sig')
# -----------------------------------------# تهيئة session state37 unmodified lines st.warning("❌ اسم المستخدم غير موجود.")
# -----------------------------------------# واجهة مقدم الشكوى# مقدم الشكوىelif st.session_state.user_type == "sender": st.title("📨 تقديم شكوى") complaint_text = st.text_area("وصف الشكوى")5 unmodified lines complaint_id = f"{prefix}_{next_id:06}"
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") new_complaint = { "complaint_id": complaint_id, "username": st.session_state.username, "complaint_text": complaint_text, "status": "Pending", "response": "", "timestamp": timestamp } df = pd.concat([df, pd.DataFrame([new_complaint])], ignore_index=True) df.to_csv(file_path, index=False) st.success("✅ تم تقديم الشكوى بنجاح") st.rerun()
# التحقق من التكرار if not ((df["username"] == st.session_state.username) & (df["complaint_text"] == complaint_text)).any(): new_complaint = { "complaint_id": complaint_id, "username": st.session_state.username, "complaint_text": complaint_text, "status": "Pending", "response": "", "timestamp": timestamp } df = pd.concat([df, pd.DataFrame([new_complaint])], ignore_index=True) df.to_csv(file_path, index=False, encoding='utf-8-sig') st.success("✅ تم تقديم الشكوى بنجاح") st.experimental_set_query_params(clear=True) st.rerun() else: st.warning("⚠️ تم إرسال هذه الشكوى بالفعل من قبل.")
# إشعار بتحديث حالة الشكوى # إشعار بتحديث حالة الشكوى أو الرد user_complaints = df[df["username"] == st.session_state.username] if not user_complaints.empty: last_complaint = user_complaints.iloc[-1]8 unmodified lines if st.button("🚪 تسجيل الخروج"): st.session_state.is_logged_in = False st.session_state.user_type = None st.session_state.username = "" st.rerun()
# -----------------------------------------# واجهة مستقبل الشكوى# مستقبل الشكوىelif st.session_state.user_type == "receiver": st.title("📬 إدارة الشكاوى")
if df.empty: st.info("🚫 لا توجد شكاوى حالياً للتعامل معها.") st.info("لا توجد شكاوى حالياً للتعامل معها.") else: current_count = len(df) new_complaints = current_count - st.session_state.last_seen_count2 unmodified lines st.session_state.last_seen_count = current_count
st.subheader("📋 جميع الشكاوى") selected_index = st.selectbox( "اختر شكوى للتعامل معها", df.index, format_func=lambda i: f"{df.loc[i, 'complaint_id']} - {df.loc[i, 'username']}" ) selected_index = st.selectbox("اختر شكوى للتعامل معها", df.index, format_func=lambda i: f"{df.loc[i, 'complaint_id']} - {df.loc[i, 'username']}") selected_row = df.loc[selected_index]
st.write(f"### ✉️ شكوى: {selected_row['complaint_id']}") st.write(f"**اسم المستخدم:** {selected_row['username']}") st.write(f"**مقدم الشكوى:** {selected_row['username']}") st.write(f"**الوصف:** {selected_row['complaint_text']}")
new_status = st.selectbox("🔄 تحديث الحالة", ["Pending", "In Progress", "Resolved"], index=["Pending", "In Progress", "Resolved"].index(selected_row["status"]))2 unmodified lines if st.button("💾 حفظ التعديلات"): df.at[selected_index, "status"] = new_status df.at[selected_index, "response"] = new_response df.to_csv(file_path, index=False) df.to_csv(file_path, index=False, encoding='utf-8-sig') st.success("✅ تم حفظ التع��يلات") st.rerun()
app.py+27-26