-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_survey_report.php
143 lines (138 loc) · 4.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
<?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}")->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}");
$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;
}
</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>
<p>Have Taken: <b><?php echo number_format($taken) ?></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>Survey Report</b></h3>
<div class="card-tools">
<button class="btn btn-flat btn-sm bg-gradient-success" 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-block 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 w-100" >
<div class="progress-bar bg-primary progress-bar-striped" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $prog ?>%">
<span class="sr-only"><?php echo $prog ?>%</span>
</div>
</div>
</div>
<span class="badge badge-info"><?php echo $prog ?>%</span>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<div class="d-block tfield-area w-100 bg-dark">
<?php if(isset($ans[$row['id']])): ?>
<?php foreach($ans[$row['id']] as $val): ?>
<blockquote class="text-dark"><?php echo $val ?></blockquote>
<?php endforeach; ?>
<?php endif; ?>
</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>