-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcashier_credit_transfer.php.bak
400 lines (366 loc) · 15 KB
/
cashier_credit_transfer.php.bak
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<?php
session_start();
include_once 'include/dbconnect2.php';
if(!isset($_SESSION['user'])){
header ("Location: login.php");
}
$res=$db->query("select * from users where username='".$_SESSION['user']."'");
$userRow=mysqli_fetch_array($res);
$username=$userRow['username'];
$userCategory=$userRow['category'];
$getCredit=$db->query("select username,credit from ((select * from player_credit) union (select * from cashier_credit) union (select * from master_credit)) as a where a.username='$username'");
$creditBalance=mysqli_fetch_array($getCredit);
$sourceCredit=$creditBalance['credit'];
$targetUser=$_POST['target_username'];
$amount=$_POST['amount'];
$checkUser=$db->query("SELECT username FROM cashier_credit WHERE username='$targetUser'");
$userRowCount=mysqli_num_rows($checkUser);
$getTargetCreditSQL = $db->query("SELECT credit FROM cashier_credit WHERE username='$targetUser'");
$getTargetCreditArray=mysqli_fetch_array($getTargetCreditSQL);
$getTargetCreditArray2=$getTargetCreditArray['credit'];
$getTargetCreditFloat=floatval($getTargetCreditArray2);
$getSourceCreditFloat=floatval($sourceCredit);
if(isset($_POST['topup'])){
$totalAmount = $getTargetCreditFloat+$amount;
$transferAmount = $getSourceCreditFloat-$amount;
if($userRowCount > 0){
if($amount > $getSourceCreditFloat && $userCategory != 0){
?>
<script>alert('Insufficient Amount');</script>
<?php
}
else{
$updateTarget = "UPDATE cashier_credit SET credit='$totalAmount' where username='$targetUser';";
if(mysqli_query($db,$updateTarget) === TRUE)
{
if(mysqli_affected_rows($db)>0){
if($userCategory == 1){
$updateSource = "UPDATE master_credit SET credit='$transferAmount' where username='$username'";
}
elseif($userCategory == 2){
$updateSource = "UPDATE cashier_credit SET credit='$transferAmount' where username='$username'";
}
$transfer=$db->query($updateSource);
$message = mysqli_real_escape_string($db,"$username,$targetUser,$amount,-,$getTargetCreditFloat,$totalAmount");
$logsql = "INSERT into transaction_log (date,transaction) values ( now(),'$message')";
$logging=$db->query($logsql) or trigger_error($db->error."[$logsql]");
?>
<script>alert('Topup success');</script>
<?php
}
else
{
?>
<script>alert('Topup Fail');</script>
<?php
}
}
}
}
else{
?>
<script>alert('Invalid User');</script>
<?php
}
}
elseif(isset($_POST['withdraw'])){
$totalAmount = $getTargetCreditFloat-$amount;
$transferAmount = $getSourceCreditFloat+$amount;
if($userRowCount > 0){
if($amount > $getTargetCreditFloat ){
?>
<script>alert('Withdraw Amount Exceed');</script>
<?php
}
else{
$updateTarget = "UPDATE cashier_credit SET credit='$totalAmount' where username='$targetUser';";
if(mysqli_query($db,$updateTarget) === TRUE)
{
if(mysqli_affected_rows($db) > 0){
if($userCategory == 1){
$updateSource = "UPDATE master_credit SET credit='$transferAmount' where username='$username'";
}
elseif($userCategory == 2){
$updateSource = "UPDATE cashier_credit SET credit='$transferAmount' where username='$username'";
}
$transfer=$db->query($updateSource);
?>
<script>alert('Withdraw success');</script>
<?php
}
else
{
?>
<script>alert('Withdraw Fail');</script>
<?php
}
}
}
}
else{
?>
<script>alert('Invalid User');</script>
<?php
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="generator"
content="HTML Tidy for HTML5 (experimental) for Windows https://github.com/w3c/tidy-html5/tree/c63cc39" />
<title>App Testing</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- jQuery UI -->
<link href="https://code.jquery.com/ui/1.10.3/themes/redmond/jquery-ui.css" rel="stylesheet" media="screen" />
<!-- Bootstrap -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<!-- styles -->
<link href="css/styles.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css" />
<script type="text/javascript" language="javascript" src="js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap/latest/css/bootstrap.css" />
<script type="text/javascript" language="javascript" >
$(document).ready(function() {
var dataTable = $('#cashier-credit').DataTable( {
"processing": true,
"serverSide": true,
"ajax":{
url :"cashier-credit-data.php", // json datasource
type: "post", // method , by default get
error: function(){ // error handling
$(".cashier-credit-error").html("");
$("#cashier-credit").append('<tbody class="cashier-credit-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#cashier-credit_processing").css("display","none");
}
}
} );
} );
</script>
</head>
<body>
<div class="header">
<div class="container">
<div class="row">
<div class="col-md-5">
<!-- Logo -->
<div class="logo">
<h1>
<a href="index.php">Admin Test Portal</a>
</h1>
</div>
</div>
<div class="col-md-5">
<div class="row">
<div class="col-lg-12"></div>
</div>
</div>
<div class="col-md-2">
<div class="navbar navbar-inverse" role="banner">
<nav class="collapse navbar-collapse bs-navbar-collapse navbar-right" role="navigation">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">My Account<b class="caret"></b></a>
<ul class="dropdown-menu animated fadeInUp">
<li>
Username: <?php echo $username ?>
</li>
<li>
<a href="logout.php?logout">Logout</a>
</li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
</div>
<div class="page-content">
<div class="row">
<div class="col-md-2">
<div class="sidebar content-box" style="display: block;">
<ul class="nav">
<!-- Main menu -->
<li><a href="index.php"><i class="glyphicon glyphicon-home"></i> Dashboard</a></li>
<?php
if($userCategory == 0){
?>
<li><a href="reports.php"><i class="glyphicon glyphicon-list"></i> Reports</a></li>
<li class="submenu">
<a href="#">
<i class="glyphicon glyphicon-list"></i> Credit Transfer
<span class="caret pull-right"></span>
</a>
<!-- Sub menu -->
<ul>
<li><a href="master_credit_transfer.php">Master</a></li>
<li><a href="cashier_credit_transfer.php">Cashier</a></li>
<li><a href="player_credit_transfer.php">Player</a></li>
</ul>
</li>
<li class="submenu">
<a href="#">
<i class="glyphicon glyphicon-list"></i> Extra
<span class="caret pull-right"></span>
</a>
<!-- Sub menu -->
<ul>
<li><a href="signup_internal.php">Signup New User</a></li>
</ul>
</li>
<?php
}
elseif($userCategory == 1){
?>
<li><a href="reports.php"><i class="glyphicon glyphicon-list"></i> Reports</a></li>
<li class="submenu">
<a href="#">
<i class="glyphicon glyphicon-list"></i> Credit Transfer
<span class="caret pull-right"></span>
</a>
<!-- Sub menu -->
<ul>
<li><a href="cashier_credit_transfer.php">Cashier</a></li>
<li><a href="player_credit_transfer.php">Player</a></li>
</ul>
</li>
<li class="submenu">
<a href="#">
<i class="glyphicon glyphicon-list"></i> Extra
<span class="caret pull-right"></span>
</a>
<!-- Sub menu -->
<ul>
<li><a href="signup_internal.php">Signup New User</a></li>
</ul>
</li>
<?php
}
elseif($userCategory == 2){
?>
<li><a href="reports.php"><i class="glyphicon glyphicon-list"></i> Reports</a></li>
<li class="submenu">
<a href="#">
<i class="glyphicon glyphicon-list"></i> Credit Transfer
<span class="caret pull-right"></span>
</a>
<!-- Sub menu -->
<ul>
<li><a href="player_credit_transfer.php">Player</a></li>
</ul>
</li>
<li class="submenu">
<a href="#">
<i class="glyphicon glyphicon-list"></i> Extra
<span class="caret pull-right"></span>
</a>
<!-- Sub menu -->
<ul>
<li><a href="signup_internal.php">Signup New User</a></li>
</ul>
</li>
<?php
}
?>
</ul>
</div>
<!--Credit Balance Value -->
<div class="sidebar content-box" style="display: block;">
<b>Total Credit Balance:</b>
<?php
if ($userCategory == 0){
echo "<p style='float: right;'>Infinite</p>";
}
else{
echo "<p style='float: right;'>$sourceCredit</p>";
}
?>
</div>
</div>
<div class="col-md-10">
<div class="row">
<div class="col-md-5">
<div class="content-box-large">
<div class="panel-heading">
<div class="panel-title">Top Up/Withdraw</div>
</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="post">
<div class="form-group">
<label for="Username" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<?php
$dropDownSQL=$db->query("SELECT username from cashier_credit");
?>
<select name="target_username" class="form-control" >
<option value="0">Choose</option>
<?php
while($dropdown = mysqli_fetch_array($dropDownSQL)){
echo '<option value="'.$dropdown['username'].'">'. $dropdown['username'].'</option>';
}
?>
</select>
<!-- <input type="text" class="form-control" placeholder="Username" required="" id="target_username" name="target_username" /> -->
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2" for="prepend">Credit</label>
<div class="col-md-10">
<div class="row">
<div class="col-sm-12">
<div class="input-group">
<span class="input-group-addon">RM</span>
<input class="form-control" name="amount" id="amount" required="" placeholder="Amount" type="number" step="any" /></div>
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input class="btn btn-primary" type="submit" value="Top Up" id="topup" name="topup" onClick="return confirm('Confirm Topup?');" >
<input class="btn btn-primary" type="submit" value="Withdraw" name="withdraw" id="withdraw" onClick="return confirm('Confirm Withdraw?');">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="content-box-large">
<div class="panel-heading">
<div class="panel-title">Player List</div>
</div>
<div class="panel-body">
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="cashier-credit">
<thead>
<tr>
<th>Username</th>
<th>Credit</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="container">
<div class="copy text-center">Property of Seremban
<a href='#'>Website</a></div>
</div>
</footer>
<link href="vendors/datatables/dataTables.bootstrap.css" rel="stylesheet" media="screen" />
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<!-- jQuery UI -->
<script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="vendors/datatables/js/jquery.dataTables.min.js"></script>
<script src="vendors/datatables/dataTables.bootstrap.js"></script>
<script src="js/custom.js"></script>
<script src="js/tables.js"></script></body>
</html>