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