-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvote_sheet.php
More file actions
205 lines (183 loc) · 5.65 KB
/
vote_sheet.php
File metadata and controls
205 lines (183 loc) · 5.65 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<meta name="viewport" content="width=1124">
<title>Voting System</title>
</head>
<?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: 20%;
padding: 15px;
cursor: pointer;
border-radius: 3px;
margin-bottom: 1em
}
.candidate:hover {
background-color: white;
box-shadow: 2.5px 3px #00000063;
}
.candidate img {
height: 14vh;
width: 23vw;
margin-left:20px;
margin: auto;
}
span.rem_btn {
position: absolute;
right: 0;
top: -1em;
z-index: 10;
display: none
}
span.rem_btn.active{
display: block
}
.text-center{
font-size: 16px;
}
@media screen and (max-width: 800px;) {
.candidate {
margin: 10% auto;
width: 13px;
padding: 15px;
cursor: pointer;
border-radius: 3px;
margin-bottom: 1em;
font-size: 6px;
}
.candidate img {
height: 14vh;
width: 28vw;
margin: 10% auto;
}
.text-center{
font-size: 16px;
}
}
</style>
<div class="container-fluid">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<form action="" id="manage-vote">
<input style= "font-size:50px;" type="hidden" name="voting_id" value="<?php echo $id ?>">
<div class="col-lg-12">
<div class="text-center" style= "font-size:30px;">
<h3 style= "font-size:55px;"><b><?php echo $title ?></b></h3>
<large><b><?php echo $description; ?></b></large>
</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" style= "font-size:20px;">
<h3 style= "font-size:50px;"><b><?php echo $row['category'] ?></b></h3>
<large style= "font-size:30px;">Max Selection : <b><?php echo $set_arr[$row['id']]['max_selection']; ?></b></large>
</div>
</div>
</div>
<div class="row mt-3">
<?php foreach ($opt_arr[$row['id']] as $candidate) {
?>
<div class="candidate" style="position: relative; font-size: 10%;" 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; margin:13% auto">
<img src="assets/img/<?php echo $candidate['image_path'] ?>" alt="">
</div>
<br>
<large> <div class="text-center" style= "display: flex; font-size: 26px"> </large>
<large class="text-center" style= "display: flex; font-size: 26px"><b><?php echo ucwords($candidate['opt_txt']) ?></b></large>
</div>
</div>
</div>
<?php } ?>
</div>
<?php endwhile; ?>
</div>
<hr>
<button class="btn-block btn-primary" style= "font-size:400%; margin: 10% auto; background-size:60%;">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>