-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcoinlist.php
128 lines (96 loc) · 3.51 KB
/
coinlist.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
<!DOCTYPE html>
<?php
require_once "mdie/meekrodb.php";
ini_set('display_errors', '0');
?>
<html>
<head>
<script src="jquery.min.js"></script>
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" media="screen">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
</head>
<body>
<?php
include "header.php";
// update coin shares
$update = $_GET["stotal"];
$slug = $_GET["slug"];
$sell = $_GET["sell"];
$sellslug = $_GET["sellslug"];
if (!$sell) {
// ...
} else {
DB::$throw_exception_on_error = "true";
try {
$dbcoin = str_ireplace("-", "_", $sellslug);
$mysqli_price = DB::queryRaw("SELECT priceusd from exchange_$dbcoin order by id desc limit 1");
$sellprice = $mysqli_price->fetch_assoc();
$sellprice_output = $sellprice["priceusd"];
$sell_now = $sellprice_output * $sell;
$mysqli_owned = DB::queryRaw("SELECT owned,cash from coinlist where slug=%s", $sellslug);
$owned = $mysqli_owned->fetch_assoc();
$cash_output = $owned["cash"];
$owned_now = $owned["owned"];
$owned_final = $owned_now - $sell;
$cash_now = $cash_output + $sell_now;
$mysqli_owned_update = DB::query("UPDATE coinlist SET owned=%i WHERE slug=%s", $owned_final, $sellslug);
$mysqli_cash_update = DB::query("UPDATE coinlist SET cash=%i WHERE slug=%s", $cash_now, $sellslug);
?>
<br /><center>
<div class="card border-success mb-3" style="max-width: 90%;">
<div class="card-header"><p class="text-info">Sold at market value <?php echo $sellprice_output; ?></p></div>
<div class="card-body">
<h4 class="card-title"><?php echo $name_now; ?></h4>
<p class="card-text"><?php echo "$sell_now ($sell shares) of $name_now purchased."; ?><br /><br />Cash now: $<?php echo number_format($cash_now); ?></p>
</div>
</div></center>
<?php
} catch(MeekroDBException $e) {
echo "||Failed||";
}
}
// buy
$buy = $_GET["buy"];
$buyslug = $_GET["buyslug"];
if (!$buy) {
// ...
} else {
try {
$dbcoin = str_ireplace("-", "_", $buyslug);
$mysqli_price = DB::queryRaw("SELECT priceusd from exchange_$dbcoin order by id desc limit 1");
$buyprice = $mysqli_price->fetch_assoc();
$buyprice_output = $buyprice["priceusd"];
$buy_now = $buyprice_output * $buy;
$mysqli_owned = DB::queryRaw("SELECT owned,cash from coinlist where slug=%s", $buyslug);
$owned = $mysqli_owned->fetch_assoc();
$owned_now = $owned["owned"];
$cash_output = $owned["cash"];
$cash_now = $cash_output - $buy_now;
$owned_final = $owned_now + $buy;
$mysqli_owned_update = DB::query("UPDATE coinlist SET owned=%i WHERE slug=%s", $owned_final, $buyslug);
$mysqli_cash_update = DB::query("UPDATE coinlist SET cash=%i WHERE slug=%s", $cash_now, $buyslug);
?>
<br /><center>
<div class="card border-success mb-3" style="max-width: 90%;">
<div class="card-header"><p class="text-info">Purchased at market value <?php echo $buyprice_output; ?></p></div>
<div class="card-body">
<h4 class="card-title"><?php echo $owned_name; ?></h4>
<p class="card-text"><?php echo "$buy_now ($buy shares) of $owned_name purchased."; ?><br /><br />Cash now: $<?php echo number_format($cash_now); ?></p>
</div>
</div></center>
<?php
} catch(MeekroDBException $e) {
echo "||Failed||";
}
}
?>
<!-- <div id="coinlist">Loading ...</div>
<script>
setInterval(function(){
$('#coinlist').load('mdie/coinshow.php');
}, 3600)
</script>-->
<?php include "mdie/coinshow.php"; ?>
</body>
</html>