-
Notifications
You must be signed in to change notification settings - Fork 1
/
feedback.php
266 lines (244 loc) · 11.3 KB
/
feedback.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
/****************************
* File Name: feedback.php *
* Author: Ammar S.A.A *
* Output: Feedback Page *
****************************/
require('config.php');
require(WEBSITE_PATH.'./includes/db_connection.php');
require(WEBSITE_PATH.'./includes/session.php');
include(WEBSITE_PATH.'./includes/header.php');
include(WEBSITE_PATH.'./includes/logo.php');
include(WEBSITE_PATH.'./includes/menu.php');
$id = '';
$feedback = '';
$feedback_urdu = '';
$rating = '';
$reply = '';
$user_name = '';
$user_email = '';
$creation_date = '';
if(isset($_GET['action']) && isset($_GET['id']))
{
$edit_id = $_GET['id'];
$action = $_GET['action'];
}else{
$edit_id = '';
$action = '';
}
if (IfIsUser($conn)) {
$sql_user = "SELECT * FROM tblusers WHERE user_name = '{$_SESSION['user_name']}' ";
$sql = $conn->query($sql_user);
while($row = mysqli_fetch_array($sql)) {
$id = $row['id'];
$full_name = $row['full_name'];
$email_id = $row['email_id'];
$user_name = $row['user_name'];
$status = $row['status'];
$profile_picture = $row['profile_picture'];
}
} elseif (!IfIsUser($conn)) {
$sql_admin = "SELECT * FROM admin WHERE user_name = '{$_SESSION['user_name']}' ";
$sql = $conn->query($sql_admin);
if ($sql && $sql->num_rows > 0) {
$row = $sql->fetch_assoc();
$id = $row['id'];
$full_name = $row['full_name'];
$email_id = $row['admin_email'];
$user_name = $row['user_name'];
$status = $row['status'];
$profile_picture = $row['profile_picture'];
}
}
if(isset($_POST['feedback_form'])) {
$user_id = $id;
$email = trim($email_id);
$feedback = trim($_POST['feedback']);
$feedback_urdu = trim($_POST['feedback_urdu']);
if (!IfIsUser($conn)) {
$reply = trim($_POST['reply']);
}
//$creation_date = now();
if (empty($reply) && (!empty($feedback) || !empty($feedback_urdu))) {
$sql = "INSERT INTO
tblfeedback
(user_id,
email_id,
feedback,
feedback_urdu,
rating,
creation_date)
VALUES
({$user_id},
'{$email}',
'{$feedback}',
'{$feedback_urdu}',
'{$rating}',
now())";
$result = $conn->query($sql);
if ($result) {
$msg = "<div class='alert alert-success text-capitalize'>thanks for feedback. If needed we'll reach you.</div>";
}else{
$msg = "<div class='alert alert-danger text-capitalize'>Opss! Errors occured, please try again.</div>";
}
}elseif (!empty($reply) || !empty($reply_urdu)) {
$sql = "UPDATE
tblfeedback
SET
reply_id = {$user_id},
feedback_reply = '{$reply}',
reply_date = now()
WHERE
id={$_POST['id']}";
$result = $conn->query($sql);
if ($result) {
$msg = "<div class='alert alert-success text-capitalize'>Hurray! Delivered.</div>";
}else{
$msg = "<div class='alert alert-danger text-capitalize'>Opss! Errors occured, please try again.</div>";
}
}else{
$msg = "<div class='alert alert-danger'>Opss! You have to fill atleast ONE FIELD.</div>";
}
}
if (isset($_GET['action']) && isset($_GET['id']))
{
$select= "SELECT
tblfeedback.id,
tblfeedback.feedback,
tblfeedback.feedback_urdu,
tblfeedback.feedback_reply,
tblfeedback.rating,
admin.user_name,
tblusers.full_name,
tblusers.email_id,
tblfeedback.creation_date,
tblfeedback.reply_date
FROM
tblfeedback
INNER JOIN tblusers ON tblfeedback.user_id = tblusers.id
INNER JOIN admin ON tblfeedback.reply_id = admin.id
#ORDER BY id DESC
WHERE tblfeedback.id={$_GET['id'] }";
$result = $conn->query($select);
if ($result && $result->num_rows > 0) {
$row = $result->fetch_assoc();
$id = $row['id'];
$feedback = $row['feedback'];
$feedback_urdu = $row['feedback_urdu'];
$rating = $row['rating'];
$replied_by = $row['user_name'];
$reply = $row['feedback_reply'];
$admin_name = $row['user_name'];
$user_name = $row['full_name'];
$user_email = $row['email_id'];
$creation_date = $row['creation_date'];
$reply_date = $row['reply_date'];
};
}
if (isset($msg))
{
echo $msg;
}
?>
<section id="content">
<div class="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col">
<!--Feedback Form-->
<form action="#" method="post" role="feedbac_form">
<br/>
<input type="hidden" name="feedback_form" value="feedback_form" />
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<img class="f-img img-circle" src="<?php echo WEBSITE_URL; ?>/images/profile_pictures/<?php if(empty($profile_picture)){ echo '../monitor_mlms.png'; }else{ echo $profile_picture; } ?>" />
<h2>Your Feedback</h2>
<p class="labelenglish"><b>Feedback:</b></p>
<textarea name="feedback" class="blank" rows="3"><?php echo $feedback ?></textarea>
<p class="labelurdu"><b>:رائے</b></p>
<textarea name="feedback_urdu" class="urdu blank" rows="3"><?php echo $feedback_urdu ?></textarea>
<div>
<!--Rating from 1-5 stars-->
<p class="labelenglish" hidden><b>Rating:</b></p><br />
<div class="form-check">
<div class="form-check-inline" name="rating">
<input class="form-check-input" type="radio" name="rating" value="1"
<?php if ($rating == 1) { echo "Checked"; } else { echo " "; } ?>
/>
<label class="form-check-label" for="rating">
⭐
</label>
</div>
<div class="form-check-inline" name="rating">
<input class="form-check-input" type="radio" name="rating" value="2"
<?php if ($rating == 2) { echo "Checked"; } else { echo " "; } ?>
/>
<label class="form-check-label" for="rating">
⭐⭐
</label>
</div>
<div class="form-check-inline" name="rating">
<input class="form-check-input" type="radio" name="rating" value="3"
<?php if ($rating == 3) { echo "Checked"; } else { echo " ";}?>
/>
<label class="form-check-label" for="rating">
⭐⭐⭐
</label>
</div>
<div class="form-check-inline" name="rating">
<input class="form-check-input" type="radio" name="rating" value="4"
<?php if ($rating == 4) { echo "Checked"; } else { echo " ";}?>
/>
<label class="form-check-label" for="rating">
⭐⭐⭐⭐
</label>
</div>
<div class="form-check-inline" name="rating">
<input class="form-check-input" type="radio" name="rating" value="5"
<?php if ($rating == 5) { echo "Checked"; } else { echo " ";}?>
/>
<label class="form-check-label" for="rating">
⭐⭐⭐⭐⭐
</label>
</div>
<!--If Admin edits,Reply-->
<?php if(!IfIsUser($conn) && isset($_GET['id'])){ ?>
<p class="labelenglish"><b>Reply:</b></p>
<textarea name="reply" class="blank" rows="3"><?php echo $reply ?></textarea>
<?php }?>
<!--Buttons-->
<div>
<!--Reset Everything-->
<input type="reset" value="Reset" name="reset" class="btn btn-success" />
<!--If User-->
<?php if(IfIsUser($conn)){?>
<!-- If User edits, Update -->
<?php if(!empty($action) && !empty($edit_id)){ ?>
<input type="submit" value="Update" name="submit" class="btn btn-success" />
<!--If User not edits, Submit-->
<?php }else{ ?>
<input type="submit" value="Submit" name="submit" class="btn btn-success" />
<!--If Admin-->
<?php }}else{ ?>
<!--If Admin edits,Reply-->
<?php if(!empty($action) && !empty($edit_id)){ ?>
<input type="submit" value="Reply" name="submit" class="btn btn-success" />
<!--If Admin not edits, Submit-->
<?php }else{ ?>
<input type="submit" value="Submit" name="submit" class="btn btn-success" />
<?php }} ?>
<!--ENDIF-->
</div>
</div>
</div>
<br />
</form>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<?php
include(WEBSITE_PATH.'./includes/footer.php');
?>