Hadeeratef91 commited on
Commit
59e5abd
·
verified ·
1 Parent(s): 990cdeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -45
app.py CHANGED
@@ -17,22 +17,25 @@ def get_db_connection():
17
  # إنشاء الجداول إذا لم تكن موجودة
18
  def init_db():
19
  conn = get_db_connection()
20
- conn.execute('''CREATE TABLE IF NOT EXISTS users (
21
- id INTEGER PRIMARY KEY AUTOINCREMENT,
22
- username TEXT UNIQUE,
23
- password TEXT,
24
- role TEXT
25
- )''')
26
-
27
- conn.execute('''CREATE TABLE IF NOT EXISTS complaints (
28
- id INTEGER PRIMARY KEY AUTOINCREMENT,
29
- complaint_id TEXT UNIQUE,
30
- username TEXT,
31
- complaint_text TEXT,
32
- status TEXT,
33
- response TEXT,
34
- timestamp TEXT
35
- )''')
 
 
 
36
  conn.commit()
37
  conn.close()
38
 
@@ -59,8 +62,6 @@ def init_session():
59
  "username": "",
60
  "role": ""
61
  }
62
- if "complaint_submitted" not in st.session_state:
63
- st.session_state.complaint_submitted = False
64
 
65
  init_session()
66
 
@@ -101,33 +102,20 @@ def sender_page():
101
 
102
  complaint_id = f"{username}_{user_complaint_count + 1:06d}"
103
 
104
- if st.session_state.complaint_submitted:
105
- st.success("✅ تم إرسال الشكوى مسبقًا")
106
- else:
107
- complaint_text = st.text_area("📝 اكتب شكواك هنا", key="complaint_input")
108
-
109
- if st.button("📨 إرسال الشكوى"):
110
- if complaint_text.strip():
111
- existing = conn.execute(
112
- "SELECT * FROM complaints WHERE complaint_id = ?",
113
- (complaint_id,)
114
- ).fetchone()
115
 
116
- if not existing:
117
- timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
118
- conn.execute(
119
- "INSERT INTO complaints (complaint_id, username, complaint_text, status, response, timestamp, sender_comment) VALUES (?, ?, ?, ?, ?, ?, ?)",
120
- (complaint_id, username, complaint_text.strip(), "Pending", "", timestamp, "")
121
- )
122
- conn.commit()
123
- st.session_state.complaint_submitted = True
124
- st.success("✅ تم إرسال الشكوى بنجاح")
125
- st.rerun()
126
- else:
127
- st.session_state.complaint_submitted = True
128
- st.warning("⚠️ تم إرسال هذه الشكوى مسبقًا")
129
- else:
130
- st.warning("⚠️ لا يمكن إرسال شكوى فارغة")
131
 
132
  st.subheader("📋 الشكاوى السابقة")
133
  complaints = conn.execute(
@@ -157,6 +145,7 @@ def sender_page():
157
  conn2.close()
158
  st.success("✅ تم حفظ تعليقك على الرد")
159
  st.rerun()
 
160
  conn.close()
161
 
162
  # صفحة مستقبل الشكاوى
@@ -247,7 +236,6 @@ def main():
247
  "username": "",
248
  "role": ""
249
  }
250
- st.session_state.complaint_submitted = False
251
  st.rerun()
252
 
253
  if os.path.exists("complaintsBD.db"):
 
17
  # إنشاء الجداول إذا لم تكن موجودة
18
  def init_db():
19
  conn = get_db_connection()
20
+ conn.execute("""
21
+ CREATE TABLE IF NOT EXISTS users (
22
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
23
+ username TEXT UNIQUE,
24
+ password TEXT,
25
+ role TEXT
26
+ )
27
+ """)
28
+ conn.execute("""
29
+ CREATE TABLE IF NOT EXISTS complaints (
30
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
31
+ complaint_id TEXT UNIQUE,
32
+ username TEXT,
33
+ complaint_text TEXT,
34
+ status TEXT,
35
+ response TEXT,
36
+ timestamp TEXT
37
+ )
38
+ """)
39
  conn.commit()
40
  conn.close()
41
 
 
62
  "username": "",
63
  "role": ""
64
  }
 
 
65
 
66
  init_session()
67
 
 
102
 
103
  complaint_id = f"{username}_{user_complaint_count + 1:06d}"
104
 
105
+ complaint_text = st.text_area("📝 اكتب شكواك هنا", key="complaint_input")
 
 
 
 
 
 
 
 
 
 
106
 
107
+ if st.button("📨 إرسال الشكوى"):
108
+ if complaint_text.strip():
109
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
110
+ conn.execute(
111
+ "INSERT INTO complaints (complaint_id, username, complaint_text, status, response, timestamp, sender_comment) VALUES (?, ?, ?, ?, ?, ?, ?)",
112
+ (complaint_id, username, complaint_text.strip(), "Pending", "", timestamp, "")
113
+ )
114
+ conn.commit()
115
+ st.success(f"✅ تم إرسال الشكوى بنجاح. معرف الشكوى هو: {complaint_id}")
116
+ st.rerun()
117
+ else:
118
+ st.warning("⚠️ لا يمكن إرسال شكوى فارغة")
 
 
 
119
 
120
  st.subheader("📋 الشكاوى السابقة")
121
  complaints = conn.execute(
 
145
  conn2.close()
146
  st.success("✅ تم حفظ تعليقك على الرد")
147
  st.rerun()
148
+
149
  conn.close()
150
 
151
  # صفحة مستقبل الشكاوى
 
236
  "username": "",
237
  "role": ""
238
  }
 
239
  st.rerun()
240
 
241
  if os.path.exists("complaintsBD.db"):