-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_survey_report.php
240 lines (191 loc) · 6.58 KB
/
view_survey_report.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
<?php include 'db_connect.php' ?>
<?php
$qry = $conn->query("SELECT * FROM survey_set where id = ".$_GET['id'])->fetch_array();
foreach($qry as $k => $v){
if($k == 'title')
$k = 'stitle';
$$k = $v;
}
$taken = $conn->query("SELECT distinct(user_id) from answers where survey_id ={$id} and user_id = ".$_GET['usid'])->num_rows;
$answers = $conn->query("SELECT a.*,q.type from answers a inner join questions q on q.id = a.question_id where a.survey_id ={$id} and a.user_id =".$_GET['usid']);
$ans = array();
while($row=$answers->fetch_assoc()){
if($row['type'] == 'radio_opt'){
$ans[$row['question_id']][$row['answer']][] = 1;
}
if($row['type'] == 'check_opt'){
foreach(explode(",", str_replace(array("[","]"), '', $row['answer'])) as $v){
$ans[$row['question_id']][$v][] = 1;
}
}
if($row['type'] == 'textfield_s'){
$ans[$row['question_id']][] = $row['answer'];
}
}
?>
<style>
.tfield-area{
max-height: 30vh;
overflow: auto;
}
.progress {
margin-bottom: 20px;
}
.progress-bar {
width: 0;
}
.bg-purple {
background-color: #825CD6 !important;
}
.progress .progress-bar {
transition: unset;
}
ul {
list-style-type: none;
}
</style>
<div class="col-lg-12">
<div class="row">
<div class="col-md-4">
<div class="card card-outline card-primary">
<div class="card-header">
<h3 class="card-title"><b>Survey Details</b></h3>
</div>
<div class="card-body p-0 py-2">
<div class="container-fluid">
<p>Title: <b><?php echo $stitle ?></b></p>
<p class="mb-0">Description:</p>
<small><?php echo $description; ?></small>
<p>Start: <b><?php echo date("M d, Y",strtotime($start_date)) ?></b></p>
<p>End: <b><?php echo date("M d, Y",strtotime($end_date)) ?></b></p>
</div>
<hr class="border-primary">
</div>
</div>
</div>
<div class="col-md-8">
<div class="card card-outline card-success">
<div class="card-header">
<h3 class="card-title"><b>Rapport</b></h3>
<div class="card-tools">
<button class="btn btn-outline-primary" type="button" id="print"><i class="fa fa-print"></i> Print</button>
</div>
</div>
<div class="card-body ui-sortable">
<?php
$question = $conn->query("SELECT * FROM questions where survey_id = $id order by abs(order_by) asc,abs(id) asc");
while($row=$question->fetch_assoc()):
?>
<div class="callout callout-info">
<h5><?php echo $row['question'] ?></h5>
<div class="col-md-12">
<input type="hidden" name="qid[<?php echo $row['id'] ?>]" value="<?php echo $row['id'] ?>">
<input type="hidden" name="type[<?php echo $row['id'] ?>]" value="<?php echo $row['type'] ?>">
<?php if($row['type'] != 'textfield_s'):?>
<ul>
<?php foreach(json_decode($row['frm_option']) as $k => $v):
$prog = ((isset($ans[$row['id']][$k]) ? count($ans[$row['id']][$k]) : 0) / $taken) * 100 ;
$prog = round($prog,2);
?>
<li>
<div class="d-inline w-100">
<b> <?php echo "&".$v ?></b>
</div>
<div class="d-flex w-100">
<span class=""><?php echo isset($ans[$row['id']][$k]) ? count($ans[$row['id']][$k]) : 0 ?>/<?php echo $taken ?></span>
<div class="mx-1 col-sm-8">
<div class="progress border w-100" >
<div class="progress-bar progress-bar progress-bar-animated" role="progressbar" aria-valuenow="<?php echo $prog ?>" aria-valuemin="0" aria-valuemax="100" style="">
<?php echo $prog ;?>
</div>
</div>
</div>
<span class="badge badge-pill badge-light"><?php echo $prog ?>%</span>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<?php
$usid = $_GET['usid'];
$tot = $conn->query("SELECT a.survey_id, q.frm_option, a.user_id, a.answer from answers as a, questions as q where a.question_id = q.id and a.survey_id = 10 and a.user_id = '".$usid."' ORDER BY user_id desc")->num_rows;
$rst = $conn->query("SELECT a.survey_id,a.question_id, q.frm_option, a.user_id,COUNT(a.answer) as t,a.answer from answers as a, questions as q where a.question_id = q.id and a.survey_id = 10 and a.user_id = '".$usid."' GROUP by a.answer");
$ans = array();
$sp = 0;
$sr = 0;
$sd = 0;
while($row=$rst->fetch_assoc()):
$ans[$row['question_id']][$row['answer']][] = 1;
$d = array(1,2,3);
$p = array(4,5);
if(in_array($row['answer'],$d)){
$calc = ($row['t'] / $tot) * 100; $sd+=$calc;
}elseif(in_array($row['answer'],$p)){
$calc = ($row['t'] / $tot) * 100; $sp+=$calc;
}
?>
<?php endwhile;?>
<style>
.datee { float:right }
img {
width:12%;
}
</style>
<h1><img src="img/grp2.png"/> positive <span class="border border-success datee"> <?php echo (($sp / 100) * $tot) ?> </span><h1>
<hr>
<h1><img src="img/grp1.png"/> negative <span class="border border-danger datee"> <?php echo (($sd / 100) * $tot) ?> </span><h1>
</div>
<?php endif; ?>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
</div>
</div>
</div>
<script>
$('#manage-survey').submit(function(e){
e.preventDefault()
start_load()
$.ajax({
url:'ajax.php?action=save_answer',
method:'POST',
data:$(this).serialize(),
success:function(resp){
if(resp == 1){
alert_toast("Thank You.",'success')
setTimeout(function(){
location.href = 'index.php?page=survey_widget'
},2000)
}
}
})
})
$('#print').click(function(){
start_load()
var nw = window.open("print_report.php?id=<?php echo $id ?>","_blank","width=800,height=600")
nw.print()
setTimeout(function(){
nw.close()
end_load()
},2500)
})
</script>
<script>
var delay = 500;
$(".progress-bar").each(function(i) {
$(this).delay(delay * i).animate({
width: $(this).attr('aria-valuenow') + '%'
}, delay);
$(this).prop('Counter', 0).animate({
Counter: $(this).text()
}, {
duration: delay,
// easing: 'swing',
step: function(now) {
$(this).text(Math.ceil(now) + '%');
}
});
});
</script>