Spaces:
Sleeping
Sleeping
Update app.py
Browse files24 unmodified lines252627282930313233343536373819 unmodified lines58596061626364656667686970717211 unmodified lines848586878889902 unmodified lines939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521536 unmodified lines16016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921024 unmodified linesif "last_seen_count" not in st.session_state:st.session_state.last_seen_count = len(df)# -----------------------------------------# تسجيل الدخول# -----------------------------------------# تحميل بيانات المستخدمينusers_file = "users.csv"if os.path.exists(users_file):users_df = pd.read_csv(users_file, encoding='utf-8-sig')else:st.error("⚠️ ملف المستخدمين غير موجود!")st.stop()19 unmodified lineselse:st.warning("❌ اسم المستخدم غير موجود.")# مقدم الشكوىelif st.session_state.user_type == "sender":st.title("📨 تقديم شكوى")complaint_text = st.text_area("Description ")if st.button("Send complaint"):user_id = st.session_state.username.split("_")[-1].upper()existing_ids = df[df["username"] == st.session_state.username]["complaint_id"]next_id = len(existing_ids) + 1#complaint_id = f"SUE {user_id}-{next_id:06}"prefix = st.session_state.username[:4].lower()complaint_id = f"{prefix}_{next_id:06}"11 unmodified linesst.success("✅ تم تقديم الشكوى بنجاح")st.rerun()# إشعار بتحديث حالة الشكوى أو الردuser_complaints = df[df["username"] == st.session_state.username]if not user_complaints.empty:last_complaint = user_complaints.iloc[-1]2 unmodified linesif pd.notna(last_complaint["response"]) and last_complaint["response"].strip() != "":st.success(f"💬 تم الرد على شكواك: {last_complaint['response']}")# عرض الشكاوى الخاصة بهst.subheader("📋 last complaints")st.dataframe(user_complaints[["complaint_id", "complaint_text", "status", "response", "timestamp"]], use_container_width=True)# زر تسجيل الخروجif st.button("🚪 Log out"):st.session_state.is_logged_in = Falsest.session_state.user_type = Nonest.rerun()# -----------------------------------------# مستقبل الشكوى# مستقبل الشكوىelif st.session_state.user_type == "receiver":st.title("📬 إدارة الشكاوى")if df.empty:st.info("لا توجد شكاوى حالياً للتعامل معها.")else:# تنبيه عن شكاوى جديدةcurrent_count = len(df)new_complaints = current_count - st.session_state.last_seen_countif new_complaints > 0:st.success(f"📬 تم تقديم {new_complaints} شكوى جديدة منذ آخر زيارة.")st.session_state.last_seen_count = current_count# عرض الشكاوىst.subheader("📋 جميع الشكاوى")if not df.empty:selected_index = st.selectbox("اختر شكوى للتعامل معها",df.index,format_func=lambda i: f"{df.loc[i, 'complaint_id']} - {df.loc[i, 'username']}",key="select_complaint")selected_row = df.loc[selected_index]st.write(f"### ✉️ شكوى: {selected_row['complaint_id']}")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"]))new_response = st.text_area("📝 الرد على الشكوى", value=selected_row["response"] or "")if st.button("💾 حفظ التعديلات"):df.at[selected_index, "status"] = new_statusdf.at[selected_index, "response"] = new_responsedf.to_csv(file_path, index=False)st.success("✅ تم حفظ التعديلات")st.rerun()else:st.warning("🚫 لا توجد شكاوى حالياً للتعامل معها.")st.write(f"### ✉️ شكوى: {selected_row['complaint_id']}")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"]))6 unmodified linesst.success("✅ تم حفظ التعديلات")st.rerun()# زر لتحميل الشكاوىst.download_button(label="📥 تحميل الشكاوى كـ CSV",data=df.to_csv(index=False).encode('utf-8'),file_name="complaints_export.csv",mime="text/csv")# ✅ زر تسجيل الخروج يظهر دائمًاif st.button("🚪 تسجيل الخروج"):st.session_state.is_logged_in = Falsest.session_state.user_type = Nonest.session_state.username = ""st.rerun()# عرض الشكاوىst.subheader("📋 جميع الشكاوى")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['complaint_text']}")new_status = st.selectbox("🔄 تحديث الحالة", ["Pending", "In Progress", "Resolved"], index=["Pending", "In Progress", "Resolved"].index(selected_row["status"]))new_response = st.text_area("📝 الرد على الشكوى", value=selected_row["response"] or "")if st.button("💾 حفظ التعديلات"):df.at[selected_index, "status"] = new_statusdf.at[selected_index, "response"] = new_responsedf.to_csv(file_path, index=False)st.success("✅ تم حفظ التعديلات")st.rerun()# زر لتحميل الشكاوىst.download_button(label="📥 تحميل الشكاوى كـ CSV",data=df.to_csv(index=False, encoding='utf-8-sig'),file_name="complaints_export.csv",mime="text/csv"))# زر تسجيل الخروجif st.button("🚪Sign Out"):st.session_state.is_logged_in = Falsest.session_state.user_type = Nonest.rerun()24 unmodified lines252627282930313233343519 unmodified lines55565758596061626364656667686911 unmodified lines818283848586872 unmodified lines909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271286 unmodified lines13513613713813914014114214314414514614714814924 unmodified linesif "last_seen_count" not in st.session_state:st.session_state.last_seen_count = len(df)# -----------------------------------------# تحميل بيانات المستخدمينusers_file = "users.csv"if os.path.exists(users_file):users_df = pd.read_csv(users_file, encoding='utf-8-sig')else:st.error("⚠️ ملف المستخدمين غير موجود!")st.stop()19 unmodified lineselse:st.warning("❌ اسم المستخدم غير موجود.")# -----------------------------------------# واجهة مقدم الشكوىelif st.session_state.user_type == "sender":st.title("📨 تقديم شكوى")complaint_text = st.text_area("وصف الشكوى")if st.button("إرسال الشكوى"):user_id = st.session_state.username.split("_")[-1].upper()existing_ids = df[df["username"] == st.session_state.username]["complaint_id"]next_id = len(existing_ids) + 1prefix = st.session_state.username[:4].lower()complaint_id = f"{prefix}_{next_id:06}"11 unmodified linesst.success("✅ تم تقديم الشكوى بنجاح")st.rerun()# إشعار بتحديث حالة الشكوىuser_complaints = df[df["username"] == st.session_state.username]if not user_complaints.empty:last_complaint = user_complaints.iloc[-1]2 unmodified linesif pd.notna(last_complaint["response"]) and last_complaint["response"].strip() != "":st.success(f"💬 تم الرد على شكواك: {last_complaint['response']}")st.subheader("📋 الشكاوى السابقة")st.dataframe(user_complaints[["complaint_id", "complaint_text", "status", "response", "timestamp"]], use_container_width=True)if st.button("🚪 تسجيل الخروج"):st.session_state.is_logged_in = Falsest.session_state.user_type = Nonest.session_state.username = ""st.rerun()# -----------------------------------------# واجهة مستقبل الشكوىelif st.session_state.user_type == "receiver":st.title("📬 إدارة الشكاوى")if df.empty:st.info("🚫 لا توجد شكاوى حالياً للتعامل معها.")else:current_count = len(df)new_complaints = current_count - st.session_state.last_seen_countif new_complaints > 0:st.success(f"📬 تم تقديم {new_complaints} شكوى جديدة منذ آخر زيارة.")st.session_state.last_seen_count = current_countst.subheader("📋 جميع الشكاوى")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['complaint_text']}")new_status = st.selectbox("🔄 تحديث الحالة", ["Pending", "In Progress", "Resolved"], index=["Pending", "In Progress", "Resolved"].index(selected_row["status"]))6 unmodified linesst.success("✅ تم حفظ التعديلات")st.rerun()st.download_button(label="📥 تحميل الشكاوى كـ CSV",data=df.to_csv(index=False, encoding='utf-8-sig'),file_name="complaints_export.csv",mime="text/csv")if st.button("🚪 تسجيل الخروج"):st.session_state.is_logged_in = Falsest.session_state.user_type = Nonest.session_state.username = ""st.rerun()
app.py+23-84