-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage_course.php
183 lines (180 loc) · 7.41 KB
/
manage_course.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
<?php
include 'db_connect.php';
if(isset($_GET['id'])){
$qry = $conn->query("SELECT * FROM courses where id= ".$_GET['id']);
foreach($qry->fetch_array() as $k => $val){
$$k=$val;
}
}
?>
<div class="container-fluid">
<form action="" id="manage-course">
<input type="hidden" name="id" value="<?php echo isset($id) ? $id : '' ?>">
<div class="row">
<div class="col-lg-6 border-right">
<h5><b>Course Details</b></h5>
<hr>
<div id="msg" class="form-group"></div>
<div class="form-group">
<label for="" class="control-label">Course</label>
<input type="text" class="form-control" name="course" value="<?php echo isset($course) ? $course :'' ?>" required>
</div>
<div class="form-group">
<label for="" class="control-label">Level</label>
<input type="text" class="form-control" name="level" value="<?php echo isset($level) ? $level :'' ?>" required>
</div>
<div class="form-group">
<label for="" class="control-label">Description</label>
<textarea name="description" id="" cols="30" rows="4" class="form-control" required=""><?php echo isset($description) ? $description :'' ?></textarea>
</div>
</div>
<div class="col-lg-6">
<h5><b>Fee Details</b></h5>
<hr>
<div class="row">
<div class="form-group">
<label for="ft" class="control-label">Fee Type</label>
<input type="text" id="ft" class="form-control-sm">
</div>
<div class="form-group">
<label for="" class="control-label">Amount</label>
<input type="number" step="any" min="0" id="amount" class="form-control-sm text-right">
</div>
<div class="form-group pt-1">
<label for="" class="control-label"> </label>
<button class="btn btn-primary btn-sm" type="button" id="add_fee">Add to List</button>
</div>
</div>
<hr>
<table class="table table-condensed" id="fee-list">
<thead>
<tr>
<th width="5%"></th>
<th width="50%">Type</th>
<th width="45%">Amount</th>
</tr>
</thead>
<tbody>
<?php
if(isset($id)):
$fees = $conn->query("SELECT * FROM fees where course_id = $id");
$total = 0;
while($row=$fees->fetch_assoc()):
$total += $row['amount'];
?>
<tr>
<td class="text-center"><button class="btn-sm btn-outline-danger" type="button" onclick="rem_list($(this))" ><i class="fa fa-times"></i></button></td>
<td>
<input type="hidden" name="fid[]" value="<?php echo $row['id'] ?>">
<input type="hidden" name="type[]" value="<?php echo $row['description'] ?>">
<p><small><b class="ftype"><?php echo $row['description'] ?></b></small></p>
</td>
<td>
<input type="hidden" name="amount[]" value="<?php echo $row['amount'] ?>">
<p class="text-right"><small><b class="famount"><?php echo number_format($row['amount']) ?></b></small></p>
</td>
</tr>
<?php
endwhile;
endif;
?>
</tbody>
<tfoot>
<tr>
<th colspan="2" class="text-center">Total</th>
<th class="text-right">
<input type="hidden" name="total_amount" value="<?php echo isset($total) ? $total : 0 ?>">
<span class="tamount"><?php echo isset($total) ? number_format($total,2) : '0.00' ?></span>
</th>
</tr>
</tfoot>
</table>
</div>
</div>
</form>
</div>
<div id="fee_clone" style="display: none">
<table >
<tr>
<td class="text-center"><button class="btn-sm btn-outline-danger" type="button" onclick="rem_list($(this))" ><i class="fa fa-times"></i></button></td>
<td>
<input type="hidden" name="fid[]">
<input type="hidden" name="type[]">
<p><small><b class="ftype"></b></small></p>
</td>
<td>
<input type="hidden" name="amount[]">
<p class="text-right"><small><b class="famount"></b></small></p>
</td>
</tr>
</table>
</div>
<script>
$('#manage-course').on('reset',function(){
$('#msg').html('')
$('input:hidden').val('')
})
$('#add_fee').click(function(){
var ft = $('#ft').val()
var amount = $('#amount').val()
if(amount == '' || ft == ''){
alert_toast("Please fill the Fee Type and Amount field first.",'warning')
return false;
}
var tr = $('#fee_clone tr').clone()
tr.find('[name="type[]"]').val(ft)
tr.find('.ftype').text(ft)
tr.find('[name="amount[]"]').val(amount)
tr.find('.famount').text(parseFloat(amount).toLocaleString('en-US'))
$('#fee-list tbody').append(tr)
$('#ft').val('').focus()
$('#amount').val('')
calculate_total()
})
function calculate_total(){
var total = 0;
$('#fee-list tbody').find('[name="amount[]"]').each(function(){
total += parseFloat($(this).val())
})
$('#fee-list tfoot').find('.tamount').text(parseFloat(total).toLocaleString('en-US'))
$('#fee-list tfoot').find('[name="total_amount"]').val(total)
}
function rem_list(_this){
_this.closest('tr').remove()
calculate_total()
}
$('#manage-course').submit(function(e){
e.preventDefault()
start_load()
$('#msg').html('')
if($('#fee-list tbody').find('[name="fid[]"]').length <= 0){
alert_toast("Please insert atleast 1 row in the fees table",'danger')
end_load()
return false;
}
$.ajax({
url:'ajax.php?action=save_course',
data: new FormData($(this)[0]),
cache: false,
contentType: false,
processData: false,
method: 'POST',
type: 'POST',
success:function(resp){
if(resp==1){
alert_toast("Data successfully saved.",'success')
setTimeout(function(){
location.reload()
},1000)
}else if(resp == 2){
$('#msg').html('<div class="alert alert-danger mx-2">Course Name & Level already exist.</div>')
end_load()
}
}
})
})
$('.select2').select2({
placeholder:"Please Select here",
width:'100%'
})
</script>