Spaces:
Sleeping
Sleeping
Update app.py
Browse files73 unmodified lines747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411573 unmodified linesdef sender_page():st.title("📨 إرسال شكوى جديدة")# تعريف دالة لمسح حقل الشكوىdef clear_complaint():if "complaint_text" in st.session_state:del st.session_state.complaint_textcomplaint_text = st.text_area("📝 وصف الشكوى", key="complaint_text")if st.button("📤 إرسال الشكوى", on_click=clear_complaint):if not complaint_text.strip():st.warning("⚠️ الرجاء إدخال نص الشكوى")else:conn = get_db_connection()try:# إنشاء معرف فريد للشكوىuser_complaints = conn.execute("SELECT COUNT(*) FROM complaints WHERE username = ?",(st.session_state.auth["username"],)).fetchone()[0]complaint_id = f"{st.session_state.auth['username'][:4]}_{user_complaints + 1:07d}"conn.execute("""INSERT INTO complaints(complaint_id, username, complaint_text, status, response, timestamp)VALUES (?, ?, ?, ?, ?, ?)""",(complaint_id, st.session_state.auth["username"], complaint_text.strip(),"Pending", "", datetime.now().strftime("%Y-%m-%d %H:%M:%S")))conn.commit()st.success("✅ تم تقديم الشكوى بنجاح")st.rerun()except sqlite3.Error as e:st.error(f"❌ حدث خطأ أثناء حفظ الشكوى: {str(e)}")finally:conn.close()# عرض الشكاوى السابقةst.subheader("📋 الشكاوى السابقة")conn = get_db_connection()73 unmodified lines747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311473 unmodified linesdef sender_page():st.title("📨 إرسال شكوى جديدة")# تعريف حقل إدخال النصif 'complaint_text' not in st.session_state:st.session_state.complaint_text = ""complaint_text = st.text_area("📝 وصف الشكوى", value=st.session_state.complaint_text, key="complaint_input")if st.button("📤 إرسال الشكوى"):conn = get_db_connection()try:# إنشاء معرف فريد للشكوىuser_complaints = conn.execute("SELECT COUNT(*) FROM complaints WHERE username = ?",(st.session_state.auth["username"],)).fetchone()[0]complaint_id = f"{st.session_state.auth['username'][:4]}_{user_complaints + 1:07d}"# إدراج الشكوى في قاعدة البياناتconn.execute("""INSERT INTO complaints(complaint_id, username, complaint_text, status, response, timestamp)VALUES (?, ?, ?, ?, ?, ?)""",(complaint_id, st.session_state.auth["username"], complaint_text,"Pending", "", datetime.now().strftime("%Y-%m-%d %H:%M:%S")))conn.commit()# تفريغ حقل الإدخال بعد الإرسالst.session_state.complaint_text = ""st.rerun() # إعادة تحميل الصفحة لتطبيق التغييراتexcept sqlite3.Error as e:st.error(f"❌ حدث خطأ أثناء حفظ الشكوى: {str(e)}")finally:conn.close()# عرض الشكاوى السابقةst.subheader("📋 الشكاوى السابقة")conn = get_db_connection()
app.py+33-34