-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.php
274 lines (240 loc) · 8 KB
/
core.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
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
<?php
class core {
private $db;
function __construct() {
$dbHost = "127.0.0.1";
$dbUser = "root";
$dbPassword = "";
$dbName = "uncrateable";
$this->db = new PDO('mysql:host='.$dbHost.';dbname='.$dbName, $dbUser, $dbPassword);
}
function __destruct() {
$db = null;
}
function loaditemprices()
{
// Function loads the item prices from the json files below and inserts them into the database
$prices = json_decode(file_get_contents("./data/prices.json"),true);
foreach($prices as $item)
{
$ids = array_keys($item['prices']);
foreach ($ids as $id) {
$itemname = $item['prices'][$id]['item_info']['item_name'];
if (isset($item['prices'][$id]['11']))
{
$value = $item['prices'][$id]['11']['0']['current']['value'];
$currency = $item['prices'][$id]['11']['0']['current']['currency'];
}else if(isset($item['prices'][$id]['6']['0'])){
$value = $item['prices'][$id]['6']['0']['current']['value'];
$currency = $item['prices'][$id]['6']['0']['current']['currency'];
} else {
$value = '0';
$currency = 'metal';
}
$query = $this->db->prepare("INSERT INTO prices (`id`,`name`,`price`,`currency`) VALUES (:id, :name, :value, :currency)");
$query->execute(array(':id' => $id, ':name' => $itemname, ':value' => $value, ':currency'=> $currency));
}
}
}
function loaditemimages()
{
// Function that grabs the image details for weapons via Valves API
$itemlist = json_decode(file_get_contents("./data/items.json"),true);
}
function getcrate($number)
{
// Function gets the crate contents
$query = $this->db->query('select * from itemlist where crateno = '.$number);
$result = array();
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
$result[] = array(
"id" => $row['id'],
"item" => $row['item'],
"crateno" => $row['crateno'],
"percentage" => $row['percentage']
);
}
return $result;
}
function getitem($name)
{
// Function gets item information
$query = $this->db->query('select * from prices where name = "'.$name.'"');
$result = array();
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
$result[] = array(
"id" => $row['id'],
"name" => $row['name'],
"price" => $row['price'],
"currency" => $row['currency'],
"image" => $row['image']
);
}
return $result;
}
function getcrateprices($crateno)
{
$query = $this->db->query('select itemlist.item, prices.price, prices.currency, itemlist.percentage from itemlist, prices where itemlist.item = prices.name and crateno = '.$crateno);
$result = array();
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
$result[] = array(
"name" => $row['name'],
"price" => $row['price'],
"currency" => $row['currency'],
"percentage" => $row['percentage']
);
}
return $result;
}
function gethighestcrates()
{
$query = $this->db->query('select * from cratelist order by value desc limit 15');
$result = array();
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
$result[] = array(
"name" => $row['name'],
"userrating" => $row['userrating'],
"value" => $row['value']
);
}
return $result;
}
function createmodal($crateno)
{
$query = $this->db->query('select * from cratelist WHERE id = '.$crateno);
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
echo '
<div class="modal fade" id="crate-'.$row['id'].'">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">'.$row['name'].'</h4>
</div>
<div class="modal-body">
<img src="./assets/img/'.$row['image'].'" height="200" class="img-rounded" align="left">
<div class="glance">
<p><b>This Crate at a glance</b><br/>
Average crate value: '.$row['value'].'<img src="./assets/img/metal.png" height="20"><br/>
Cost on Steam Market Place: no data<br/>
User Ratings: '.$row['userrating'].'<br/>
Highest Value Item: no data<br/>
Lowest Value Item: no data<br/>
</p>
</div>
<div>
<p><b>Description</b><br/>
'.$row['desc'].'<br/></p>
</div>
<div>
<p><b>Contains</b>
<table class="table table-bordered">
<thead>
<tr>
<th>Image</th>
<th>Item Name</th>
<th>Price</th>
</tr>
</thead>
<tbody>';
$items = $this->getcrate($row['id']);
foreach ($items as $item)
{
$iteminfo = $this->getitem($item['item']);
echo '<tr>
<td><img src="'.$iteminfo[0]['image'].'" height="100"></td>
<td>'.$item['item'].'</td>';
echo'<td>'.$iteminfo[0]['price'];
echo' <img src="./assets/img/'.$iteminfo[0]['currency'].'.png" height="40"></td>
</tr>';
}
echo'
</tbody>
</table>
</p>
</div>
</div>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>';
$cratedetail = $this->getcrate($crateno);
foreach ($cratedetail as $iteminfo)
{
echo '';
}
}
}
function createcratedropdown()
{
$query = $this->db->query('select * from cratelist');
echo "<form method='get' action=''>";
echo "<select class='form-control' name='crate' placeholder='Please Select a Crate'>";
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
echo "<option value='".$row['id']."'>".$row['name']."</option>";
}
echo "</select><br/><center><button type='submit' class='btn btn-primary '>Submit</button></center>";
echo "</form>";
}
function createtopcrates()
{
echo '<table class="table table-bordered"><thead><tr><th></th><th>Crate Number</th><th>Value</th><th>Info</th></tr></thead><tbody><tr>';
$query = $this->db->query('select * from cratelist ORDER BY value desc limit 15');
$array = array();
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
echo'<td><img src="./assets/img/'.$row['image'].'" width="100" height="100"></td>';
echo '<td>'.$row['name'].'</td>';
echo '<td>'.$row['value'].' ref (<img src="./assets/img/metal.png" height="30">)</td>';
echo '<td><p><a href="#crate-'.$row['id'].'" role="button" class="btn btn-primary" data-toggle="modal">More Info</a></p></td></tr>';
$array[] = array (
"id" => $row['id'],
);
}
echo "</tbody></table>";
foreach ($array as $detail)
{
$this->createmodal($detail['id']);
}
}
function createyourcrate($id)
{
echo '<table class="table table-bordered"><thead><tr><th></th><th>Crate Number</th><th>Value</th><th>Info</th></tr></thead><tbody><tr>';
$query = $this->db->query('select * from cratelist WHERE id = '.$id);
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
echo'<td><img src="./assets/img/'.$row['image'].'" width="100" height="100"></td>';
echo '<td>'.$row['name'].'</td>';
echo '<td>'.$row['value'].' ref (<img src="./assets/img/metal.png" height="30">)</td>';
echo '<td><p><a href="#crate-'.$id.'" role="button" class="btn btn-primary" data-toggle="modal">More Info</a></p></td></tr>';
}
echo "</tbody></table>";
$this->createmodal($id);
}
function calccrateaverage($crate)
{
$query = $this->db->query('select itemlist.item, prices.price, prices.currency, itemlist.percentage from itemlist, prices where itemlist.item = prices.name and crateno = '.$crate);
$row_count = $query->rowCount();
$total = 0;
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
if($row['currency'] == "keys")
{
$value = $row['price'] * 5.33;
}
else if($row['currency'] == "earbuds")
{
$value = $row['price'] * 117.26;
}
else{
$value = $row['price'];
}
$total = $total + $value;
}
$total = $total / $row_count;
$total = number_format($total, 2);
$query = $this->db->prepare("UPDATE cratelist set `value` = :value where id = :crate;");
$query->execute(array(':value' => $total, ':crate' => $crate));
return $total;
}
}
?>