| 1 |
- |
1 |
<?php
|
|
|
2 |
include_once('php/exchangeRates.php');
|
|
|
3 |
include_once('php/countryCodes.php');
|
|
|
4 |
include_once('php/constants.php');
|
|
|
5 |
include_once('php/ebay.php');
|
|
|
6 |
|
|
|
7 |
// search for items
|
|
|
8 |
function searchAll($searchKey) {
|
|
|
9 |
$arr = [];
|
|
|
10 |
$newArr = [];
|
|
|
11 |
if ($_SESSION["filterConditionNew"]) { $arr = get_ebay($searchKey, constant("NEW")); }
|
|
|
12 |
if ($_SESSION["filterConditionUsed"]) { $newArr = get_ebay($searchKey, constant("USED")); }
|
|
|
13 |
$arr = array_merge($arr, $newArr);
|
|
|
14 |
|
|
|
15 |
$arr = applyExchangeRates($arr);
|
|
|
16 |
usort($arr, 'compare_price');
|
|
|
17 |
|
|
|
18 |
return $arr;
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
// build HTML table from array
|
|
|
22 |
function buildTable($arr) {
|
|
|
23 |
$str = "<div class=\"table\">";
|
|
|
24 |
$str .= "<table class=\"table table-striped table-condensed small\">";
|
|
|
25 |
$str .= "<thead class=\"thead-dark sticky-top\"><tr><th>Image</th><th class=\"text-left\">Title / Merchant</th><th>Condition</th><th class=\"hide-small\">Price</th><th class=\"hide-small\">S/H</th><th>Total</th><th></th></tr></thead>";
|
|
|
26 |
$str .= "<tbody>";
|
|
|
27 |
|
|
|
28 |
foreach ($arr as $value) {
|
|
|
29 |
$url = base64_encode($value["URL"]);
|
|
|
30 |
|
|
|
31 |
$str .= "<tr>";
|
|
|
32 |
|
|
|
33 |
// Image
|
| 2 |
- |
34 |
$str .= "<td><a href=\"/redirect.php?target=" . $url . "\" target=\"_blank\"><img class=\"img-fluid\" src=\"" . $value["Image"] . "\" alt=\"Item Image\"></a></td>";
|
| 1 |
- |
35 |
|
|
|
36 |
// Title / Merchant
|
|
|
37 |
$str .= "<td class=\"text-left\"><span class=\"font-weight-bold\">" . $value["Title"] . "</span><br/>";
|
|
|
38 |
$str .= "<span class=\"font-weight-bold\">" . $value["Merchant"] . "</span><br/>" . $value["SellerName"] . " (" . number_format($value["FeedbackScore"], 0, "", ",") . " / " . $value["FeedbackPercent"] . "%)</td>";
|
|
|
39 |
|
|
|
40 |
// Condition
|
|
|
41 |
$str .= "<td>";
|
| 3 |
- |
42 |
$categoryIcon = "";
|
|
|
43 |
$categoryStyle = "";
|
| 1 |
- |
44 |
$tooltip = "";
|
|
|
45 |
switch ($value["Category"]) {
|
|
|
46 |
case "CD":
|
| 3 |
- |
47 |
$categoryIcon = "fas fa-compact-disc";
|
|
|
48 |
$categoryStyle = "color:silver;";
|
| 1 |
- |
49 |
$tooltip = "Compact Disc";
|
|
|
50 |
break;
|
|
|
51 |
case "Record":
|
| 3 |
- |
52 |
$categoryIcon = "fas fa-dot-circle";
|
| 1 |
- |
53 |
$tooltip = "Vinyl Record";
|
|
|
54 |
break;
|
|
|
55 |
case "Digital":
|
| 3 |
- |
56 |
$categoryIcon = "digital";
|
| 1 |
- |
57 |
$tooltip = "Digital Download";
|
|
|
58 |
break;
|
|
|
59 |
}
|
|
|
60 |
$str .= "<span class=\"font-weight-bold\">" . $value["Condition"] . "</span>";
|
|
|
61 |
$str .= "<br/><br/>";
|
| 3 |
- |
62 |
$str .= "<i class=\"" . $categoryIcon . "\" style=\"font-size:32px;text-shadow:2px 2px 4px #000000;" . $categoryStyle . "\" title=\"" . $tooltip . "\" data-toggle=\"tooltip\" data-placement=\"right\" data-delay=\"200\"></i>";
|
| 1 |
- |
63 |
$str .= "</td>";
|
|
|
64 |
|
|
|
65 |
// Price
|
|
|
66 |
$str .= "<td class=\"hide-small\">" . print_monetary($value["Price"], $value["Currency"]);
|
|
|
67 |
if ($value["Currency"] != $_SESSION["buyerCurrency"]) {
|
|
|
68 |
$str .= "<br/>≈ " . print_monetary($value["ConvertedPrice"], $_SESSION["buyerCurrency"]);
|
|
|
69 |
}
|
|
|
70 |
$str .= "</td>";
|
|
|
71 |
|
|
|
72 |
// Shipping and Handling Cost
|
|
|
73 |
$str .= "<td class=\"hide-small\">";
|
|
|
74 |
if ($value["ShippingCost"] == 0.00) {
|
|
|
75 |
$str .= "Free Shipping";
|
|
|
76 |
} else {
|
|
|
77 |
$str .= print_monetary($value["ShippingCost"], $value["ShippingCurrency"]);
|
|
|
78 |
}
|
|
|
79 |
if ($value["ShippingCurrency"] != $_SESSION["buyerCurrency"]) {
|
|
|
80 |
$str .= "<br/>≈ " . print_monetary($value["ConvertedShippingCost"], $_SESSION["buyerCurrency"]);
|
|
|
81 |
}
|
| 3 |
- |
82 |
$str .= "<br/><img class=\"img-fluid\" title=\"Ships from " . getCountry($value["Country"]) . "\" data-toggle=\"tooltip\" data-placement=\"right\" data-delay=\"200\" src=\"/images/flags/" . $value["Country"] . ".png\" alt=\"" . getCountry($value["Country"]) . " Flag\"></td>";
|
| 1 |
- |
83 |
|
|
|
84 |
// Total Price
|
|
|
85 |
$str .= "<td class=\"font-weight-bolder\">" . print_monetary($value["ConvertedTotalPrice"], $_SESSION["buyerCurrency"]) . "</td>";
|
|
|
86 |
|
|
|
87 |
// Link
|
| 3 |
- |
88 |
$str .= "<td><a class=\"btn btn-danger\" role=\"button\" href=\"/redirect.php?target=" . $url . "\" target=\"_blank\"><i class=\"fas fa-shopping-cart\" style=\"font-size:32px\"></i><br>Buy It Now</a></td>";
|
| 1 |
- |
89 |
|
|
|
90 |
$str .= "</tr>";
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
$str .= "</tbody>";
|
| 3 |
- |
94 |
$str .= "<tfoot class=\"text-right\"><tr><td colspan=\"7\">Prices retrieved on " . gmdate("Y-m-d H:i") . " UTC<br>Daily exchange rates update</td></tr></tfoot>";
|
| 1 |
- |
95 |
$str .= "</table>";
|
|
|
96 |
$str .= "</div>";
|
|
|
97 |
|
|
|
98 |
return($str);
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
// print summary/header on top of listing table
|
|
|
102 |
function printTableHeader() {
|
| 3 |
- |
103 |
$str = '<div class="row text-left bg-light">';
|
|
|
104 |
$str .= ' <div class="col-lg-2 col-md-4 col-sm-6 col-12 ml-3 mb-2';
|
| 1 |
- |
105 |
if ($_SESSION["lowNew"] <= 0) {
|
|
|
106 |
$str .= " opacity-5";
|
|
|
107 |
}
|
|
|
108 |
$str .= '">';
|
| 3 |
- |
109 |
$str .= ' <span class="display-4 font-weight-bolder">New</span> from<br><span class="display-5 font-weight-bolder">' . print_monetary($_SESSION["lowNew"], $_SESSION["buyerCurrency"]) . '</span>';
|
| 1 |
- |
110 |
$str .= ' </div>';
|
| 3 |
- |
111 |
$str .= ' <div class="col-lg-2 col-md-4 col-sm-6 col-12 ml-3 mb-2';
|
| 1 |
- |
112 |
if ($_SESSION["lowUsed"] <= 0) {
|
|
|
113 |
$str .= " opacity-5";
|
|
|
114 |
}
|
|
|
115 |
$str .= '">';
|
| 3 |
- |
116 |
$str .= ' <span class="display-4 font-weight-bolder">Used</span> from<br><span class="display-5 font-weight-bolder">' . print_monetary($_SESSION["lowUsed"], $_SESSION["buyerCurrency"]) . '</span>';
|
| 1 |
- |
117 |
$str .= ' </div>';
|
|
|
118 |
// BUGBUG Digital
|
|
|
119 |
$str .= '</div>';
|
|
|
120 |
|
|
|
121 |
return $str;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
// compare price for sort low to high
|
|
|
126 |
function compare_price($a, $b)
|
|
|
127 |
{
|
|
|
128 |
return strnatcmp($a['ConvertedTotalPrice'], $b['ConvertedTotalPrice']);
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
// print monetary values with correct symbol and thousands/decimal delimiters
|
|
|
132 |
function print_monetary($num, $curr) {
|
|
|
133 |
if ($curr == "USD") {
|
|
|
134 |
return("$" . number_format($num, 2, '.', ','));
|
|
|
135 |
} else if ($curr == "CAD") {
|
|
|
136 |
return("C $" . number_format($num, 2, '.', ','));
|
|
|
137 |
} else if ($curr == "EUR") {
|
|
|
138 |
return(number_format($num, 2, ',', '.') . "€");
|
|
|
139 |
} else if ($curr == "GBP") {
|
|
|
140 |
return("£" . number_format($num, 2, '.', ','));
|
|
|
141 |
} else if ($curr == "AUD") {
|
|
|
142 |
return("AU $" . number_format($num, 2, '.', ','));
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
return ($curr . " " . number_format($num, 2, '.', ','));
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
// find lowest used / new prices and return their array index
|
|
|
149 |
function findLowest($arr, $type) {
|
|
|
150 |
foreach ($arr as $value) {
|
|
|
151 |
if ($type == $value["Type"]) {
|
|
|
152 |
return($value["ConvertedTotalPrice"]);
|
|
|
153 |
}
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
return(0);
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
// apply exchange rates
|
|
|
160 |
function applyExchangeRates($arr) {
|
|
|
161 |
foreach ($arr as &$value) {
|
|
|
162 |
$value["ConvertedPrice"] = $value["Price"];
|
|
|
163 |
$value["ConvertedShippingCost"] = $value["ShippingCost"];
|
|
|
164 |
|
|
|
165 |
if ($_SESSION["buyerCurrency"] != $value["Currency"]) {
|
|
|
166 |
$value["ConvertedPrice"] = number_format($value["Price"] / getExchangeRate($_SESSION["buyerCurrency"], $value["Currency"]), 2, '.', '');
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
if ($_SESSION["buyerCurrency"] != $value["ShippingCurrency"]) {
|
|
|
170 |
$value["ConvertedShippingCost"] = number_format($value["ShippingCost"] / getExchangeRate($_SESSION["buyerCurrency"], $value["ShippingCurrency"]), 2, '.', '');
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
$value["ConvertedTotalPrice"] = number_format($value["ConvertedPrice"] + $value["ConvertedShippingCost"], 2, '.', '');
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
return($arr);
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
// sanitize user input
|
|
|
180 |
function test_input($data) {
|
|
|
181 |
$data = trim($data);
|
|
|
182 |
$data = stripslashes($data);
|
|
|
183 |
$data = htmlspecialchars($data);
|
|
|
184 |
return $data;
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
// get a SESSION value, return empty string if not set
|
|
|
188 |
function getSV($var) {
|
|
|
189 |
if (!isset($_SESSION[$var])) {
|
|
|
190 |
return ('');
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
return($_SESSION[$var]);
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
// initialize a SESSION value if not set
|
|
|
197 |
function initSV($var, $value) {
|
|
|
198 |
if (!isset($_SESSION[$var])) {
|
|
|
199 |
$_SESSION[$var] = $value;
|
|
|
200 |
}
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
// check POST value, return true if set and false if not
|
|
|
204 |
function checkPV($var) {
|
|
|
205 |
if (isset($_POST[$var])) {
|
|
|
206 |
return (true);
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
return(false);
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
// print search filter modal with current selection
|
|
|
213 |
function printSearchFilterModal() {
|
|
|
214 |
$str = '';
|
|
|
215 |
$str .= '<div class="modal fade" id="filterModal">';
|
|
|
216 |
$str .= ' <div class="modal-dialog">';
|
|
|
217 |
$str .= ' <div class="modal-content">';
|
|
|
218 |
$str .= '';
|
| 3 |
- |
219 |
$str .= ' <div class="modal-header bg-primary">';
|
| 1 |
- |
220 |
$str .= ' <h4 class="modal-title">Search Filters</h4>';
|
|
|
221 |
$str .= ' </div>';
|
|
|
222 |
$str .= '';
|
|
|
223 |
$str .= ' <form method="post" action="/index.php">';
|
|
|
224 |
$str .= ' <div class="modal-body">';
|
|
|
225 |
$str .= ' <div class="card-group">';
|
|
|
226 |
$str .= '';
|
|
|
227 |
$str .= ' <div class="card">';
|
|
|
228 |
$str .= ' <div class="card-header font-weight-bold">Condition</div>';
|
|
|
229 |
$str .= ' <div class="card-body">';
|
|
|
230 |
$str .= ' <div class="form-check">';
|
|
|
231 |
$str .= ' <label class="form-check-label">';
|
|
|
232 |
$str .= ' <input name="filterConditionNew" type="checkbox" class="form-check-input" value="New"' . ($_SESSION["filterConditionNew"] ? " checked" : "") . '>New';
|
|
|
233 |
$str .= ' </label>';
|
|
|
234 |
$str .= ' </div>';
|
|
|
235 |
$str .= ' <div class="form-check">';
|
|
|
236 |
$str .= ' <label class="form-check-label">';
|
|
|
237 |
$str .= ' <input name="filterConditionUsed" type="checkbox" class="form-check-input" value="Used"' . ($_SESSION["filterConditionUsed"] ? " checked" : "") . '>Used';
|
|
|
238 |
$str .= ' </label>';
|
|
|
239 |
$str .= ' </div>';
|
|
|
240 |
$str .= ' </div>';
|
|
|
241 |
$str .= ' </div>';
|
|
|
242 |
$str .= '';
|
|
|
243 |
$str .= ' <div class="card">';
|
|
|
244 |
$str .= ' <div class="card-header font-weight-bold">Media Type</div>';
|
|
|
245 |
$str .= ' <div class="card-body">';
|
|
|
246 |
$str .= ' <div class="form-check">';
|
|
|
247 |
$str .= ' <label class="form-check-label">';
|
| 3 |
- |
248 |
$str .= ' <input name="filterMediaTypeCD" type="checkbox" class="form-check-input" value="CD"' . ($_SESSION["filterMediaTypeCD"] ? " checked" : "") . '><i class="fas fa-compact-disc" style="color:silver;"></i> Compact Disc';
|
| 1 |
- |
249 |
$str .= ' </label>';
|
|
|
250 |
$str .= ' </div>';
|
|
|
251 |
$str .= ' <div class="form-check">';
|
|
|
252 |
$str .= ' <label class="form-check-label">';
|
| 3 |
- |
253 |
$str .= ' <input name="filterMediaTypeRecord" type="checkbox" class="form-check-input" value="Record"' . ($_SESSION["filterMediaTypeRecord"] ? " checked" : "") . '><i class="fas fa-dot-circle"></i> Vinyl Record';
|
| 1 |
- |
254 |
$str .= ' </label>';
|
|
|
255 |
$str .= ' </div>';
|
|
|
256 |
$str .= ' <div class="form-check">';
|
|
|
257 |
$str .= ' <label class="form-check-label">';
|
| 3 |
- |
258 |
$str .= ' <input name="filterMediaTypeDigital" type="checkbox" class="form-check-input" value="Digital"' . ($_SESSION["filterMediaTypeDigital"] ? " checked" : "") . '><i class="fas fa-download"></i> Digital';
|
| 1 |
- |
259 |
$str .= ' </label>';
|
|
|
260 |
$str .= ' </div>';
|
|
|
261 |
$str .= ' </div>';
|
|
|
262 |
$str .= ' </div>';
|
|
|
263 |
$str .= ' </div>';
|
|
|
264 |
$str .= ' </div>';
|
|
|
265 |
$str .= '';
|
| 3 |
- |
266 |
$str .= ' <div class="modal-footer bg-primary">';
|
| 2 |
- |
267 |
$str .= ' <button id="save" type="submit" class="btn btn-success" name="submit" value="Save">Save</button>';
|
| 1 |
- |
268 |
$str .= ' <button id="discard" type="button" class="btn btn-danger" data-dismiss="modal">Discard</button>';
|
|
|
269 |
$str .= ' </div>';
|
|
|
270 |
$str .= ' </form>';
|
|
|
271 |
$str .= ' </div>';
|
|
|
272 |
$str .= ' </div>';
|
|
|
273 |
$str .= '</div>';
|
|
|
274 |
|
|
|
275 |
return($str);
|
|
|
276 |
}
|
| 3 |
- |
277 |
|
|
|
278 |
// print search info modal
|
|
|
279 |
function printSearchInfoModal() {
|
|
|
280 |
$str = '';
|
|
|
281 |
$str .= '<div class="modal fade" id="searchInfoModal">';
|
|
|
282 |
$str .= ' <div class="modal-dialog">';
|
|
|
283 |
$str .= ' <div class="modal-content">';
|
|
|
284 |
$str .= '';
|
|
|
285 |
$str .= ' <div class="modal-header bg-primary">';
|
|
|
286 |
$str .= ' <h4 class="modal-title">Search Tips</h4>';
|
|
|
287 |
$str .= ' <button type="button" class="close" data-dismiss="modal"><i class="fas fa-window-close" style="font-size:24px"></i></button>';
|
|
|
288 |
$str .= ' </div>';
|
|
|
289 |
$str .= '';
|
|
|
290 |
$str .= ' <div class="modal-body">';
|
|
|
291 |
$str .= ' <h4>Search Keywords</h4>';
|
|
|
292 |
$str .= '';
|
|
|
293 |
$str .= ' <p><span class=font-weight-bold>Barcode:</span>';
|
|
|
294 |
$str .= ' <br>The 12 or 13 digit barcode, normally located on the back, offers the best chance to find a specific album.</p>';
|
|
|
295 |
$str .= '';
|
|
|
296 |
$str .= ' <p><span class=font-weight-bold>Artist and Title:</span>';
|
|
|
297 |
$str .= ' <br>The full name of the album, including artist and title, will usually lead to a specific album.</p>';
|
|
|
298 |
$str .= '';
|
|
|
299 |
$str .= ' <p><span class=font-weight-bold>Just Artist or Title:</span>';
|
|
|
300 |
$str .= ' <br>Searches for artist or title alone will bring up random albums.</p>';
|
|
|
301 |
$str .= ' </div>';
|
|
|
302 |
$str .= ' </div>';
|
|
|
303 |
$str .= ' </div>';
|
|
|
304 |
$str .= '</div>';
|
|
|
305 |
|
|
|
306 |
return($str);
|
|
|
307 |
}
|
| 1 |
- |
308 |
?>
|