-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
189 lines (175 loc) · 5.72 KB
/
index.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
184
185
186
187
188
<!--The html form -->
<html>
<head>
<title>Trani</title>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>
<style>
body
{
margin:0;
padding:0;
background-color:#f1f1f1;
}
h1{
background-color: #0d2a45;
background-position: center;
padding: 30px;
font-family: "Graphik", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-size: 50px;
font-weight: 900;
color: white;
}
.box
{
width:1270px;
padding:20px;
background-color:#fff;
border:1px solid #ccc;
border-radius:5px;
margin-top:25px;
box-sizing:border-box;
}
footer
{
width:1270px;
padding:20px;
background-color:#fff;
border:1px solid #ccc;
border-radius:5px;
margin-top:25px;
margin-left:133px;
box-sizing:border-box;
</style>
</head>
<body>
<div class="container box">
<h1 align="center">trani</h1>
<br />
<div class="table table-responsive">
<br />
<div align="right">
<button type="button" name="add" id="add" class="btn btn-info">Add</button>
</div>
<br />
<div id="alert_message"></div>
<table id="user_data" class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Account Number</th>
<th>Bank</th>
<th>Amount</th>
<th></th>
<th></th>
</tr>
</thead>
</table>
</div>
</div>
</body>
</html>
<!--Javascript and JQuery part -->
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
fetch_data();
//function that uses ajax to get the table data from fetch file
function fetch_data()
{
var dataTable = $('#user_data').DataTable({
"processing" : true,
"serverSide" : true,
"order" : [],
"ajax" : {
url:"fetch.php",
type:"POST"
}
});
}
//For when you want to add a new recipient it creates the form cells and gives them an id and prepends the row to the table body
$('#add').click(function(){
var html = '<tr>';
html += '<td contenteditable id="data1"></td>';
html += '<td contenteditable id="data2"></td>';
html += '<td><input id="data3" type= "number"/></td>';
html += '<td align="center"> <select class="form-control" id="data4"> <option value= "058">Guarantee Trust Bank</option> <option value="044">Access Bank</option></select></td>';
html += '<td><input id="data5" type= "number"></td>';
html += '<td><button type="button" name="insert" id="insert" class="btn btn-success btn-xs">Save</button></td>';
html += '<td><button type="button" name="pay" id="pay" class="btn btn-info btn-xs">Pay Once</button></td>';
html += '</tr>';
$('#user_data').prepend(html);
});
//When you click insert this checks if all fields are valid and posts the data to the insert file
$(document).on('click', '#insert', function(){
var name = $('#data1').text();
var description = $('#data2').text();
var account_number = $('#data3').val();
var bank_code = $('#data4').val();
var amount = $('#data5').val();
if(name != '' && description != '' && account_number != '' && bank_code != '' && amount != '')
{
$.ajax({
url:"insert.php",
method:"POST",
data:{name:name, description:description, account_number:account_number, bank_code:bank_code, amount:amount},
success:function(data)
{
$('#alert_message').html('<div class="alert alert-success">'+data+'</div>');
$('#user_data').DataTable().destroy();
fetch_data();
}
});
setInterval(function(){
$('#alert_message').html('');
}, 5000);
}
else
{
alert("Please enter missing fields ");
}
});
//delete the existing row of data
$(document).on('click', '.delete', function(){
var id = $(this).attr("id");
if(confirm("Are you sure you want to remove this?"))
{
$.ajax({
url:"delete.php",
method:"POST",
data:{id:id},
success:function(data)
{
$('#alert_message').html('<div class="alert alert-success">'+data+'</div>');
$('#user_data').DataTable().destroy();
fetch_data();
}
})
}
});
//when you click pay it asks for confirmation then posts the id to the pay file
$(document).on('click', '.pay', function(){
var id = $(this).attr("id");
if(confirm("Kindly check all values to ensure no error before clicking ok"))
{
$.ajax({
url:"pay.php",
method:"POST",
data:{id:id},
success:function(data)
{
$('#alert_message').html('<div class="alert alert-success">'+data+'</div>');
$('#user_data').DataTable().destroy();
$(this).remove();
$('#alert_message').html('<div class="alert alert-success">'+data+'</div>');
}
})
}
});
});
</script>
<footer align = "center">powered by <a href="https://paystack.com/" target="_blank" >paystack</a>