Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,44 +71,62 @@ def login_page():
|
|
| 71 |
else:
|
| 72 |
st.warning("❌ اسم المستخدم غير موجود")
|
| 73 |
|
| 74 |
-
def
|
| 75 |
-
st.title("
|
| 76 |
-
|
| 77 |
-
# تعريف حقل إدخال النص
|
| 78 |
-
if 'complaint_text' not in st.session_state:
|
| 79 |
-
st.session_state.complaint_text = ""
|
| 80 |
-
|
| 81 |
-
complaint_text = st.text_area("📝 وصف الشكوى", value=st.session_state.complaint_text, key="complaint_input")
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
)
|
| 102 |
-
conn.commit()
|
| 103 |
-
|
| 104 |
-
# تفريغ حقل الإدخال بعد الإرسال
|
| 105 |
-
st.session_state.complaint_text = ""
|
| 106 |
-
st.rerun() # إعادة تحميل الصفحة لتطبيق التغييرات
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
# عرض الشكاوى السابقة
|
| 113 |
st.subheader("📋 الشكاوى السابقة")
|
| 114 |
conn = get_db_connection()
|
|
|
|
| 71 |
else:
|
| 72 |
st.warning("❌ اسم المستخدم غير موجود")
|
| 73 |
|
| 74 |
+
def receiver_page():
|
| 75 |
+
st.title("📬 إدارة الشكاوى")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
conn = get_db_connection()
|
| 78 |
+
try:
|
| 79 |
+
pending_count = conn.execute(
|
| 80 |
+
"SELECT COUNT(*) FROM complaints WHERE status = 'Pending'"
|
| 81 |
+
).fetchone()[0]
|
| 82 |
+
|
| 83 |
+
if pending_count > 0:
|
| 84 |
+
st.warning(f"🚨 يوجد {pending_count} شكوى جديدة لم يتم التعامل معها!")
|
| 85 |
+
|
| 86 |
+
# الحل: تحويل النتائج إلى قاموس (dict) قبل الاستخدام
|
| 87 |
+
complaints = conn.execute(
|
| 88 |
+
"SELECT * FROM complaints ORDER BY id DESC"
|
| 89 |
+
).fetchall()
|
| 90 |
+
|
| 91 |
+
# تحويل كل صف إلى قاموس
|
| 92 |
+
complaints_list = [dict(row) for row in complaints]
|
| 93 |
+
|
| 94 |
+
if not complaints_list:
|
| 95 |
+
st.info("لا توجد شكاوى حالياً.")
|
| 96 |
+
else:
|
| 97 |
+
st.subheader("📋 جميع الشكاوى")
|
| 98 |
+
selected_complaint = st.selectbox(
|
| 99 |
+
"اختر شكوى للتعامل معها",
|
| 100 |
+
complaints_list,
|
| 101 |
+
format_func=lambda x: f"{x['complaint_id']} - {x['username']}"
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
st.subheader(f"📨 معرف الشكوى: {selected_complaint['complaint_id']}")
|
| 105 |
+
st.write(f"👤 مقدم الشكوى: {selected_complaint['username']}")
|
| 106 |
+
st.write(f"📝 الشكوى: {selected_complaint['complaint_text']}")
|
| 107 |
+
st.write(f"📅 الوقت: {selected_complaint['timestamp']}")
|
| 108 |
+
|
| 109 |
+
new_status = st.selectbox(
|
| 110 |
+
"🔄 تحديث الحالة",
|
| 111 |
+
["Pending", "In Progress", "Resolved"],
|
| 112 |
+
index=["Pending", "In Progress", "Resolved"].index(selected_complaint["status"])
|
| 113 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
+
new_response = st.text_area(
|
| 116 |
+
"💬 الرد على الشكوى",
|
| 117 |
+
value=selected_complaint["response"] or ""
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
if st.button("💾 حفظ التعديلات"):
|
| 121 |
+
conn.execute(
|
| 122 |
+
"UPDATE complaints SET status = ?, response = ? WHERE complaint_id = ?",
|
| 123 |
+
(new_status, new_response.strip(), selected_complaint["complaint_id"])
|
| 124 |
+
)
|
| 125 |
+
conn.commit()
|
| 126 |
+
st.success("✅ تم حفظ التعديلات")
|
| 127 |
+
st.rerun()
|
| 128 |
+
finally:
|
| 129 |
+
conn.close()
|
| 130 |
# عرض الشكاوى السابقة
|
| 131 |
st.subheader("📋 الشكاوى السابقة")
|
| 132 |
conn = get_db_connection()
|