-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadminHome.php
234 lines (222 loc) · 8.21 KB
/
adminHome.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
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
<?php
ob_start();
session_start();
include_once 'doeconnect.php';
require __DIR__ . '/vendor/autoload.php';
use ZuluCrypto\StellarSdk\Keypair;
use ZuluCrypto\StellarSdk\Server;
use ZuluCrypto\StellarSdk\XdrModel\Asset;
use ZuluCrypto\StellarSdk\XdrModel\AccountId;
use ZuluCrypto\StellarSdk\XdrModel\Operation\SetOptionsOp;
if(isset($_POST['btn-balance']))
{
$username = $_SESSION['username'];
$query = "SELECT Publickey,Seed FROM Users WHERE Username = '$username'";
$result = mysqli_query($conn,$query);
if(!$result)
{
print 'Error : Query failed to execute';
}
$row = mysqli_fetch_array($result);
$publickey = $row['Publickey'];
$seed = $row['Seed'];
$server = Server::testNet();
$account = $server->getAccount($publickey);
foreach ($account->getBalances() as $balance)
{
if($balance->getAssetCode() == "DOECredits")
{
$doebalance = $balance->getBalance();
}
}
}
if(isset($_POST['btn-transaction']))
{
//retrieve source,destination,amount
$sourcename = $_SESSION['username'];
$destname = $_POST['destination'];
$amount = $_POST['amount'];
//interaction with db
$query1 = "SELECT Publickey,Seed FROM Users where Username like '$sourcename'";
$query2 = "SELECT Publickey,Seed FROM Users where Username like '$destname'";
$result1 = mysqli_query($conn,$query1);
$result2 = mysqli_query($conn,$query2);
$row1 = mysqli_fetch_array($result1);
$row2 = mysqli_fetch_array($result2);
$sourcePublickey = $row1['Publickey'];
$sourceSeed = $row1['Seed'];
$destPublickey = $row2['Publickey'];
$destSeed = $row2['Seed'];
//speak to stellar and get keypair
$sourceKeypair = Keypair::newFromSeed($sourceSeed);
$receivingKeypair = Keypair::newFromSeed($destSeed);
//Asset initialisation
$asset = new Asset(Asset::TYPE_ALPHANUM_12);
$asset->setAssetCode("DOECredits");
$issuer = new AccountId('GBLJGGNZB7GTTC2D2AZ3HPAAIO4CQMES442C4OEI6PDZFRG4MBQL6ZOS');
$asset->setIssuer($issuer);
//server start
$server = Server::testNet();
//build transaction
$txEnvelope = $server->buildTransaction($sourceKeypair)
->addCustomAssetPaymentOp($asset, $amount, $receivingKeypair->getPublicKey())
->getTransactionEnvelope();
//source signs transaction
$txEnvelope->sign($sourceKeypair);
//encode transaction
$b64Tx = base64_encode($txEnvelope->toXdr());
//submit transaction
$transaction = $server->submitB64Transaction($b64Tx);
$transactionID = $transaction->getTransactionHash();
$query3 = "Select ID from Users where Username like '$sourcename'";
$query4 = "Select ID from Users where Username like '$destname'";
$result3 = mysqli_query($conn,$query3);
$result4 = mysqli_query($conn,$query4);
$row3 = mysqli_fetch_array($result3);
$row4 = mysqli_fetch_array($result4);
$sourceID = $row3['ID'];
$destID = $row4['ID'];
$query5 = "INSERT INTO Transactions(TransactionID,SourceID,DestinationID,Amount)
VALUES('$transactionID','$sourceID','$destID','$amount')";
$result5 = mysqli_query($conn,$query5);
if(!result5)
{
echo "Error : Failed to execute query";
}
}
if (isset($_POST['btn-logout']))
{
unset($_SESSION['username']);
session_unset();
session_destroy();
header("Location: index.php");
exit;
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Home</title>
<link rel="stylesheet" href="CSS/Form.css" type="text/css"/>
</head>
<body background="CSS/thumb-1920-840086.jpg">
<div class="login-page">
<div class="form">
<form method="post" class="login-form" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off">
<a class="message">TRANSACTION</a>
<br>
<br>
<input type="text" class="form-control" name="amount" placeholder="Enter Amount">
<br>
<input type="text" class="form-control" name="destination" placeholder="Enter destination username">
<br><br>
<button type="submit" class="btn btn-block btn-primary" name="btn-transaction">Submit transaction</button>
</div>
</div>
<div class="login-form">
<div class="form">
<button type="submit" class="btn btn-block btn-primary" name="btn-balance">View Balance</button>
<h2><?php
if(isset($doebalance))
{
echo 'Balance : '.$doebalance;
}
?> </h2>
<button type="submit" class="btn btn-block btn-primary" name="btn-merchants">View Merchants</button>
<h2><?php
if(isset($_POST['btn-merchants']))
{
$query = "SELECT Username FROM Users WHERE AccountType = 'Merchant'";
$result = mysqli_query($conn,$query);
echo "Merchants :";
echo "<br>";
while($row = mysqli_fetch_assoc($result))
{
foreach($row as $cname => $cvalue)
{
print "$cvalue\t";
echo "<br>";
}
print "\r\n";
}
}
?> </h2>
<button type="submit" class="btn btn-block btn-primary" name="btn-customers">View Customers</button>
<h2><?php
if(isset($_POST['btn-customers']))
{
$query = "SELECT Username FROM Users WHERE AccountType = 'Customer'";
$result = mysqli_query($conn,$query);
echo "Customers :";
echo "<br>";
while($row = mysqli_fetch_assoc($result))
{
foreach($row as $cname => $cvalue)
{
print "$cvalue\t";
echo "<br>";
}
print "\r\n";
}
}
?></h2>
<button type="submit" class="btn btn-block btn-primary" name="btn-admins">View Admins</button>
<h2><?php
if(isset($_POST['btn-admins']))
{
$query = "SELECT Username FROM Users WHERE AccountType = 'Admin'";
$result = mysqli_query($conn,$query);
echo "Admins :";
echo "<br>";
while($row = mysqli_fetch_assoc($result))
{
foreach($row as $cname => $cvalue)
{
print "$cvalue\t";
echo "<br>";
}
print "\r\n";
}
}
?></h2>
<button type="submit" class="btn btn-block btn-primary" name="btn-viewTransaction">View Transactions</button>
<h5><?php
if(isset($_POST['btn-viewTransaction']))
{
$query = "SELECT * FROM Transactions";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_assoc($result))
{
foreach($row as $cname => $cvalue)
{
echo "<br>";
print "$cname: $cvalue\t";
}
print "\r\n\n";
}
}
?></h5>
<button type="submit" class="btn btn-block btn-primary" name="btn-viewRecharge">View Recharges</button>
<h5><?php
if(isset($_POST['btn-viewRecharge']))
{
$query = "SELECT * FROM Recharges";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_assoc($result))
{
foreach($row as $cname => $cvalue)
{
echo "<br>";
print "$cname: $cvalue\t";
}
print "\r\n\n";
}
}
?></h5>
<button type="submit" class="btn btn-block btn-primary" name="btn-logout">Log Out</button>
</form>
</div>
</div>
</body>
</html>
<?php ob_end_flush(); ?>