-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvote_sheet.php
More file actions
165 lines (152 loc) · 4.86 KB
/
vote_sheet.php
File metadata and controls
165 lines (152 loc) · 4.86 KB
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
<?php include('db_connect.php');?>
<?php
$voting = $conn->query("SELECT * FROM voting_list where is_default = 1 ");
foreach ($voting->fetch_array() as $key => $value) {
$$key = $value;
}
$vchk = $conn->query("SELECT distinct(voting_id) from votes where user_id = ".$_SESSION['login_id']."")->num_rows;
if($vchk > 0){
header('Location:voting.php?page=view_vote');
}
$vote = $conn->query("SELECT * FROM voting_list where id=".$id);
foreach ($vote->fetch_array() as $key => $value) {
$$key= $value;
}
$opts = $conn->query("SELECT * FROM voting_opt where voting_id=".$id);
$opt_arr = array();
$set_arr = array();
while($row=$opts->fetch_assoc()){
$opt_arr[$row['category_id']][] = $row;
$set_arr[$row['category_id']] = array('id'=>'','max_selection'=>1);
}
$settings = $conn->query("SELECT * FROM voting_cat_settings where voting_id=".$id);
while($row=$settings->fetch_assoc()){
$set_arr[$row['category_id']] = $row;
}
?>
<style>
.candidate {
margin: auto;
width: 16vw;
padding: 10px;
cursor: pointer;
border-radius: 3px;
margin-bottom: 1em
}
.candidate:hover {
background-color: #80808030;
box-shadow: 2.5px 3px #00000063;
}
.candidate img {
height: 14vh;
width: 8vw;
margin: auto;
}
span.rem_btn {
position: absolute;
right: 0;
top: -1em;
z-index: 10;
display: none
}
span.rem_btn.active{
display: block
}
</style>
<div class="container-fluid">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<form action="" id="manage-vote">
<input type="hidden" name="voting_id" value="<?php echo $id ?>">
<div class="col-lg-12">
<div class="text-center">
<h3><b><?php echo $title ?></b></h3>
<small><b><?php echo $description; ?></b></small>
</div>
<?php
$cats = $conn->query("SELECT * FROM category_list where id in (SELECT category_id from voting_opt where voting_id = '".$id."' )");
while($row = $cats->fetch_assoc()):
?>
<hr>
<div class="row mb-4">
<div class="col-md-12">
<div class="text-center">
<h3><b><?php echo $row['category'] ?></b></h3>
<small>Max Selection : <b><?php echo $set_arr[$row['id']]['max_selection']; ?></b></small>
</div>
</div>
</div>
<div class="row mt-3">
<?php foreach ($opt_arr[$row['id']] as $candidate) {
?>
<div class="candidate" style="position: relative;" data-cid = '<?php echo $row['id'] ?>' data-max="<?php echo $set_arr[$row['id']]['max_selection'] ?>" data-name="<?php echo $row['category'] ?>">
<input type="checkbox" name="opt_id[<?php echo $row['id'] ?>][]" value="<?php echo $candidate['id'] ?>" style="display: none">
<span class="rem_btn">
<label for="" class="btn btn-primary"><span class="fa fa-check"></span></label>
</span>
<div class="item" data-id="<?php echo $candidate['id'] ?>">
<div style="display: flex">
<img src="assets/img/<?php echo $candidate['image_path'] ?>" alt="">
</div>
<br>
<div class="text-center">
<large class="text-center"><b><?php echo ucwords($candidate['opt_txt']) ?></b></large>
</div>
</div>
</div>
<?php } ?>
</div>
<?php endwhile; ?>
</div>
<hr>
<button class="btn-block btn-primary">Sumbit</button>
</form>
</div>
</div>
</div>
</div>
<script>
$('.candidate').click(function(){
var chk = $(this).find('input[type="checkbox"]').prop("checked");
if(chk == true){
$(this).find('input[type="checkbox"]').prop("checked",false)
}else{
var arr_chk = $("input[name='opt_id["+$(this).attr('data-cid')+"][]']:checked").length
if($(this).attr('data-max') == 1){
$("input[name='opt_id["+$(this).attr('data-cid')+"][]']").prop("checked",false)
$(this).find('input[type="checkbox"]').prop("checked",true)
}else{
if(arr_chk >= $(this).attr('data-max')){
alert_toast("Choose only "+$(this).attr('data-max')+" for "+$(this).attr('data-name')+" category","warning")
return false;
}
}
$(this).find('input[type="checkbox"]').prop("checked",true)
}
$('.candidate').each(function(){
if($(this).find('input[type="checkbox"]').prop("checked") == true){
$(this).find('.rem_btn').addClass('active')
}else{
$(this).find('.rem_btn').removeClass('active')
}
})
})
$('#manage-vote').submit(function(e){
e.preventDefault()
start_load();
$.ajax({
url:'ajax.php?action=submit_vote',
method:'POST',
data:$(this).serialize(),
success:function(resp){
if(resp == 1){
alert_toast("Vote success fully submitted");
setTimeout(function(){
location.reload()
},1500)
}
}
})
})
</script>