-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoting_list.php
More file actions
185 lines (176 loc) · 4.84 KB
/
voting_list.php
File metadata and controls
185 lines (176 loc) · 4.84 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
<?php include('db_connect.php');
?>
<style>
.update_default{
cursor: pointer;
}
</style>
<div class="container-fluid">
<div class="col-lg-12">
<div class="row">
<!-- FORM Panel -->
<div class="col-md-4">
<form action="" id="manage-voting">
<div class="card">
<div class="card-header">
Voting Form
</div>
<div class="card-body">
<input type="hidden" name="id">
<div class="form-group">
<label class="control-label">Title</label>
<input type="text" class="form-control" name="title">
</div>
</div>
<div class="card-body">
<div class="form-group">
<label class="control-label">Description</label>
<textarea class="form-control" name="description"></textarea>
</div>
</div>
<div class="card-footer">
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-primary"> Save</button>
<button class="btn btn-sm btn-default" type="button" onclick="$('#manage-voting').get(0).reset()"> Cancel</button>
</div>
</div>
</div>
</div>
</form>
</div>
<!-- FORM Panel -->
<!-- Table Panel -->
<div class="col-md-8">
<div class="card">
<div class="card-body">
<table class="table table-bordered table-hover">
<colgroup>
<col width="5%">
<col width="30%">
<col width="35%">
<col width="10%">
<col width="20%">
</colgroup>
<thead>
<tr>
<th class="text-center">#</th>
<th class="text-center">Title</th>
<th class="text-center">Descrition</th>
<th class="text-center">Default</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$vote = $conn->query("SELECT * FROM voting_list order by id asc");
while($row=$vote->fetch_assoc()):
?>
<tr>
<td class="text-center"><?php echo $i++ ?></td>
<td class=""><a href="index.php?page=manage_voting&id=<?php echo $row['id'] ?>"><?php echo $row['title'] ?></a></td>
<td class=""><?php echo $row['description'] ?></td>
<?php if($row['is_default'] == 1): ?>
<td class="text-center"><div class="badge badge-success">Yes</div></td>
<?php elseif($row['is_default'] == 0): ?>
<td class="text-center"><div class="badge badge-info update_default" data-id="<?php echo $row['id'] ?>">No</div></td>
<?php endif; ?>
<td class="text-center">
<button class="btn btn-sm btn-primary edit_voting" type="button" data-id="<?php echo $row['id'] ?>">Edit</button>
<button class="btn btn-sm btn-danger delete_voting" type="button" data-id="<?php echo $row['id'] ?>">Delete</button>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Table Panel -->
</div>
</div>
</div>
<script>
$('#manage-voting').submit(function(e){
e.preventDefault()
start_load()
$.ajax({
url:'ajax.php?action=save_voting',
method:'POST',
data:$(this).serialize(),
success:function(resp){
if(resp==1){
alert_toast("Data successfully added",'success')
setTimeout(function(){
location.reload()
},1500)
}
else if(resp==2){
alert_toast("Data successfully updated",'success')
setTimeout(function(){
location.reload()
},1500)
}
}
})
})
$('.edit_voting').click(function(){
start_load()
var cat = $('#manage-voting')
var _this = $(this)
cat.get(0).reset()
$.ajax({
url:'ajax.php?action=get_voting',
method:'POST',
data:{id:_this.attr('data-id')},
success:function(resp){
if(typeof resp != undefined){
resp = JSON.parse(resp)
cat.find('[name="id"]').val(_this.attr('data-id'))
cat.find('[name="title"]').val(resp.title)
cat.find('[name="description"]').val(resp.description)
end_load()
}
}
})
})
$('.update_default').click(function(){
_conf("Are you sure to set this data as default?","update_default",[$(this).attr('data-id')])
})
$('.delete_voting').click(function(){
_conf("Are you sure to delete this data?","delete_voting",[$(this).attr('data-id')])
})
function update_default($id){
start_load()
$.ajax({
url:'ajax.php?action=update_voting',
method:'POST',
data:{id:$id},
success:function(resp){
if(resp == 1){
alert_toast("Data successfully updated",'success')
setTimeout(function(){
location.reload()
},1500)
}
}
})
}
function delete_voting($id){
start_load()
$.ajax({
url:'ajax.php?action=delete_voting',
method:'POST',
data:{id:$id},
success:function(resp){
if(resp == 1){
alert_toast("Data successfully deleted",'success')
setTimeout(function(){
location.reload()
},1500)
}
}
})
}
</script>