Hadeeratef91 commited on
Commit
d97697c
·
verified ·
1 Parent(s): 75b177a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -23
app.py CHANGED
@@ -30,7 +30,8 @@ def init_db():
30
  complaint_text TEXT,
31
  status TEXT,
32
  response TEXT,
33
- timestamp TEXT
 
34
  )''')
35
  conn.commit()
36
  conn.close()
@@ -45,6 +46,8 @@ def init_session():
45
  "username": "",
46
  "role": ""
47
  }
 
 
48
 
49
  init_session()
50
 
@@ -86,29 +89,35 @@ def sender_page():
86
 
87
  # توليد معرف شكوى فريد
88
  complaint_id = f"{username}_{user_complaint_count + 1:06d}"
89
- complaint_text = st.text_area("📝 اكتب شكواك هنا")
90
-
91
- if st.button("📨 إرسال الشكوى"):
92
- if complaint_text.strip():
93
- # تحقق من عدم وجود شكوى بنفس المعرف
94
- existing = conn.execute(
95
- "SELECT * FROM complaints WHERE complaint_id = ?",
96
- (complaint_id,)
97
- ).fetchone()
98
-
99
- if not existing:
100
- timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
101
- conn.execute(
102
- "INSERT INTO complaints (complaint_id, username, complaint_text, status, response, timestamp) VALUES (?, ?, ?, ?, ?, ?)",
103
- (complaint_id, username, complaint_text.strip(), "Pending", "", timestamp)
104
- )
105
- conn.commit()
106
- st.success(" تم إرسال الشكوى بنجاح")
107
- st.rerun()
 
 
 
 
 
 
 
 
108
  else:
109
- st.warning("⚠️ تم إرسال هذه الشكوى مسبقًا")
110
- else:
111
- st.warning("⚠️ لا يمكن إرسال شكوى فارغة")
112
 
113
  # عرض الشكاوى السابقة
114
  st.subheader("📋 الشكاوى السابقة")
@@ -125,6 +134,20 @@ def sender_page():
125
  if complaint['response']:
126
  st.success(f"💬 الرد من المسؤول: {complaint['response']}")
127
  st.toast(f"📬 تم الرد على الشكوى رقم {complaint['complaint_id']}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  conn.close()
129
 
130
  # صفحة مستقبل الشكاوى
@@ -216,6 +239,7 @@ def main():
216
  "username": "",
217
  "role": ""
218
  }
 
219
  st.rerun()
220
 
221
  if os.path.exists("complaints_system.db"):
 
30
  complaint_text TEXT,
31
  status TEXT,
32
  response TEXT,
33
+ timestamp TEXT,
34
+ sender_comment TEXT
35
  )''')
36
  conn.commit()
37
  conn.close()
 
46
  "username": "",
47
  "role": ""
48
  }
49
+ if "complaint_submitted" not in st.session_state:
50
+ st.session_state.complaint_submitted = False
51
 
52
  init_session()
53
 
 
89
 
90
  # توليد معرف شكوى فريد
91
  complaint_id = f"{username}_{user_complaint_count + 1:06d}"
92
+
93
+ if st.session_state.complaint_submitted:
94
+ st.success(" تم إرسال الشكوى مسبقًا")
95
+ else:
96
+ complaint_text = st.text_area("📝 اكتب شكواك هنا", key="complaint_input")
97
+
98
+ if st.button("📨 إرسال الشكوى"):
99
+ if complaint_text.strip():
100
+ existing = conn.execute(
101
+ "SELECT * FROM complaints WHERE complaint_id = ?",
102
+ (complaint_id,)
103
+ ).fetchone()
104
+
105
+ if not existing:
106
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
107
+ conn.execute(
108
+ "INSERT INTO complaints (complaint_id, username, complaint_text, status, response, timestamp, sender_comment) VALUES (?, ?, ?, ?, ?, ?, ?)",
109
+ (complaint_id, username, complaint_text.strip(), "Pending", "", timestamp, "")
110
+ )
111
+ conn.commit()
112
+ st.session_state.complaint_submitted = True
113
+ st.success("✅ تم إرسال الشكوى بنجاح")
114
+ st.session_state.complaint_input = ""
115
+ st.rerun()
116
+ else:
117
+ st.session_state.complaint_submitted = True
118
+ st.warning("⚠️ تم إرسال هذه الشكوى مسبقًا")
119
  else:
120
+ st.warning("⚠️ لا يمكن إرسال شكوى فارغة")
 
 
121
 
122
  # عرض الشكاوى السابقة
123
  st.subheader("📋 الشكاوى السابقة")
 
134
  if complaint['response']:
135
  st.success(f"💬 الرد من المسؤول: {complaint['response']}")
136
  st.toast(f"📬 تم الرد على الشكوى رقم {complaint['complaint_id']}")
137
+
138
+ comment_key = f"comment_{complaint['complaint_id']}"
139
+ sender_comment = st.text_area("🗨️ تعليقك على الرد", value=complaint['sender_comment'] or "", key=comment_key)
140
+ if st.button("💬 حفظ التعليق", key=f"save_comment_{complaint['complaint_id']}"):
141
+ if sender_comment.strip():
142
+ conn2 = get_db_connection()
143
+ conn2.execute(
144
+ "UPDATE complaints SET sender_comment = ? WHERE complaint_id = ?",
145
+ (sender_comment.strip(), complaint['complaint_id'])
146
+ )
147
+ conn2.commit()
148
+ conn2.close()
149
+ st.success("✅ تم حفظ تعليقك على الرد")
150
+ st.rerun()
151
  conn.close()
152
 
153
  # صفحة مستقبل الشكاوى
 
239
  "username": "",
240
  "role": ""
241
  }
242
+ st.session_state.complaint_submitted = False
243
  st.rerun()
244
 
245
  if os.path.exists("complaints_system.db"):