| 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
|
|
|
34 |
$str .= "<td><a href=\"php/redirect.php?target=" . $url . "\" target=\"_blank\"><img class=\"img-fluid\" src=\"" . $value["Image"] . "\" alt=\"Item Image\"></a></td>";
|
|
|
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>";
|
|
|
42 |
$categoryImage = "";
|
|
|
43 |
$tooltip = "";
|
|
|
44 |
switch ($value["Category"]) {
|
|
|
45 |
case "CD":
|
|
|
46 |
$categoryImage = "cd";
|
|
|
47 |
$tooltip = "Compact Disc";
|
|
|
48 |
break;
|
|
|
49 |
case "Record":
|
|
|
50 |
$categoryImage = "vinyl";
|
|
|
51 |
$tooltip = "Vinyl Record";
|
|
|
52 |
break;
|
|
|
53 |
case "Digital":
|
|
|
54 |
$categoryImage = "digital";
|
|
|
55 |
$tooltip = "Digital Download";
|
|
|
56 |
break;
|
|
|
57 |
}
|
|
|
58 |
$str .= "<span class=\"font-weight-bold\">" . $value["Condition"] . "</span>";
|
|
|
59 |
$str .= "<br/><br/>";
|
|
|
60 |
$str .= "<img class=\"img-fluid\" title=\"" . $tooltip . "\" data-toggle=\"tooltip\" data-placement=\"right\" data-delay=\"200\" style=\"max-height:32px\" src=\"images/" . "$categoryImage" . ".png\">";
|
|
|
61 |
$str .= "</td>";
|
|
|
62 |
|
|
|
63 |
// Price
|
|
|
64 |
$str .= "<td class=\"hide-small\">" . print_monetary($value["Price"], $value["Currency"]);
|
|
|
65 |
if ($value["Currency"] != $_SESSION["buyerCurrency"]) {
|
|
|
66 |
$str .= "<br/>≈ " . print_monetary($value["ConvertedPrice"], $_SESSION["buyerCurrency"]);
|
|
|
67 |
}
|
|
|
68 |
$str .= "</td>";
|
|
|
69 |
|
|
|
70 |
// Shipping and Handling Cost
|
|
|
71 |
$str .= "<td class=\"hide-small\">";
|
|
|
72 |
if ($value["ShippingCost"] == 0.00) {
|
|
|
73 |
$str .= "Free Shipping";
|
|
|
74 |
} else {
|
|
|
75 |
$str .= print_monetary($value["ShippingCost"], $value["ShippingCurrency"]);
|
|
|
76 |
}
|
|
|
77 |
if ($value["ShippingCurrency"] != $_SESSION["buyerCurrency"]) {
|
|
|
78 |
$str .= "<br/>≈ " . print_monetary($value["ConvertedShippingCost"], $_SESSION["buyerCurrency"]);
|
|
|
79 |
}
|
|
|
80 |
$str .= "<br/>Ships from <img class=\"img-fluid\" title=\"" . getCountry($value["Country"]) . "\" data-toggle=\"tooltip\" data-placement=\"right\" data-delay=\"200\" src=\"images/flags/" . $value["Country"] . ".png\" alt=\"" . getCountry($value["Country"]) . " Flag\"></td>";
|
|
|
81 |
|
|
|
82 |
// Total Price
|
|
|
83 |
$str .= "<td class=\"font-weight-bolder\">" . print_monetary($value["ConvertedTotalPrice"], $_SESSION["buyerCurrency"]) . "</td>";
|
|
|
84 |
|
|
|
85 |
// Link
|
|
|
86 |
//$str .= "<td><a href=\"php/redirect.php?target=" . $url . "\" target=\"_blank\"><img class=\"img-fluid\" src=\"images/button_buy-it-now.png\" alt=\"Buy Iy Now\"></a></td>";
|
|
|
87 |
$str .= "<td><a class=\"btn btn-danger\" role=\"button\" href=\"php/redirect.php?target=" . $url . "\" target=\"_blank\">Buy It Now</a></td>";
|
|
|
88 |
|
|
|
89 |
$str .= "</tr>";
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
$str .= "</tbody>";
|
|
|
93 |
$str .= "<tfoot class=\"text-right\"><tr><td colspan=\"7\">Prices retrieved on " . gmdate("Y-m-d H:i") . " UTC<br>Daily exchange rates updates</td></tr></tfoot>";
|
|
|
94 |
$str .= "</table>";
|
|
|
95 |
$str .= "</div>";
|
|
|
96 |
|
|
|
97 |
return($str);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
// print summary/header on top of listing table
|
|
|
101 |
function printTableHeader() {
|
|
|
102 |
$str = '<div class="container-fluid row text-left mb-3 bg-light">';
|
|
|
103 |
$str .= ' <div class="col-lg-2 col-md-3 col-sm-4';
|
|
|
104 |
if ($_SESSION["lowNew"] <= 0) {
|
|
|
105 |
$str .= " opacity-5";
|
|
|
106 |
}
|
|
|
107 |
$str .= '">';
|
|
|
108 |
$str .= ' <span class="display-4 font-weight-bolder">New</span><br>from ' . print_monetary($_SESSION["lowNew"], $_SESSION["buyerCurrency"]);
|
|
|
109 |
$str .= ' </div>';
|
|
|
110 |
$str .= ' <div class="col-lg-2 col-md-3 col-sm-4';
|
|
|
111 |
if ($_SESSION["lowUsed"] <= 0) {
|
|
|
112 |
$str .= " opacity-5";
|
|
|
113 |
}
|
|
|
114 |
$str .= '">';
|
|
|
115 |
$str .= ' <span class="display-4 font-weight-bolder">Used</span><br>from ' . print_monetary($_SESSION["lowUsed"], $_SESSION["buyerCurrency"]);
|
|
|
116 |
$str .= ' </div>';
|
|
|
117 |
// BUGBUG Digital
|
|
|
118 |
$str .= '</div>';
|
|
|
119 |
|
|
|
120 |
return $str;
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
// compare price for sort low to high
|
|
|
125 |
function compare_price($a, $b)
|
|
|
126 |
{
|
|
|
127 |
return strnatcmp($a['ConvertedTotalPrice'], $b['ConvertedTotalPrice']);
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
// print monetary values with correct symbol and thousands/decimal delimiters
|
|
|
131 |
function print_monetary($num, $curr) {
|
|
|
132 |
if ($curr == "USD") {
|
|
|
133 |
return("$" . number_format($num, 2, '.', ','));
|
|
|
134 |
} else if ($curr == "CAD") {
|
|
|
135 |
return("C $" . number_format($num, 2, '.', ','));
|
|
|
136 |
} else if ($curr == "EUR") {
|
|
|
137 |
return(number_format($num, 2, ',', '.') . "€");
|
|
|
138 |
} else if ($curr == "GBP") {
|
|
|
139 |
return("£" . number_format($num, 2, '.', ','));
|
|
|
140 |
} else if ($curr == "AUD") {
|
|
|
141 |
return("AU $" . number_format($num, 2, '.', ','));
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
return ($curr . " " . number_format($num, 2, '.', ','));
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
// find lowest used / new prices and return their array index
|
|
|
148 |
function findLowest($arr, $type) {
|
|
|
149 |
foreach ($arr as $value) {
|
|
|
150 |
if ($type == $value["Type"]) {
|
|
|
151 |
return($value["ConvertedTotalPrice"]);
|
|
|
152 |
}
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
return(0);
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
// apply exchange rates
|
|
|
159 |
function applyExchangeRates($arr) {
|
|
|
160 |
foreach ($arr as &$value) {
|
|
|
161 |
$value["ConvertedPrice"] = $value["Price"];
|
|
|
162 |
$value["ConvertedShippingCost"] = $value["ShippingCost"];
|
|
|
163 |
|
|
|
164 |
if ($_SESSION["buyerCurrency"] != $value["Currency"]) {
|
|
|
165 |
$value["ConvertedPrice"] = number_format($value["Price"] / getExchangeRate($_SESSION["buyerCurrency"], $value["Currency"]), 2, '.', '');
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
if ($_SESSION["buyerCurrency"] != $value["ShippingCurrency"]) {
|
|
|
169 |
$value["ConvertedShippingCost"] = number_format($value["ShippingCost"] / getExchangeRate($_SESSION["buyerCurrency"], $value["ShippingCurrency"]), 2, '.', '');
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
$value["ConvertedTotalPrice"] = number_format($value["ConvertedPrice"] + $value["ConvertedShippingCost"], 2, '.', '');
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
return($arr);
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
// sanitize user input
|
|
|
179 |
function test_input($data) {
|
|
|
180 |
$data = trim($data);
|
|
|
181 |
$data = stripslashes($data);
|
|
|
182 |
$data = htmlspecialchars($data);
|
|
|
183 |
return $data;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
// get a SESSION value, return empty string if not set
|
|
|
187 |
function getSV($var) {
|
|
|
188 |
if (!isset($_SESSION[$var])) {
|
|
|
189 |
return ('');
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
return($_SESSION[$var]);
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
// initialize a SESSION value if not set
|
|
|
196 |
function initSV($var, $value) {
|
|
|
197 |
if (!isset($_SESSION[$var])) {
|
|
|
198 |
$_SESSION[$var] = $value;
|
|
|
199 |
}
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
// check POST value, return true if set and false if not
|
|
|
203 |
function checkPV($var) {
|
|
|
204 |
if (isset($_POST[$var])) {
|
|
|
205 |
return (true);
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
return(false);
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
// print search filter modal with current selection
|
|
|
212 |
function printSearchFilterModal() {
|
|
|
213 |
$str = '';
|
|
|
214 |
$str .= '<div class="modal fade" id="filterModal">';
|
|
|
215 |
$str .= ' <div class="modal-dialog">';
|
|
|
216 |
$str .= ' <div class="modal-content">';
|
|
|
217 |
$str .= '';
|
|
|
218 |
$str .= ' <div class="modal-header">';
|
|
|
219 |
$str .= ' <h4 class="modal-title">Search Filters</h4>';
|
|
|
220 |
$str .= ' </div>';
|
|
|
221 |
$str .= '';
|
|
|
222 |
$str .= ' <form method="post" action="/index.php">';
|
|
|
223 |
$str .= ' <div class="modal-body">';
|
|
|
224 |
$str .= ' <div class="card-group">';
|
|
|
225 |
$str .= '';
|
|
|
226 |
$str .= ' <div class="card">';
|
|
|
227 |
$str .= ' <div class="card-header font-weight-bold">Condition</div>';
|
|
|
228 |
$str .= ' <div class="card-body">';
|
|
|
229 |
$str .= ' <div class="form-check">';
|
|
|
230 |
$str .= ' <label class="form-check-label">';
|
|
|
231 |
$str .= ' <input name="filterConditionNew" type="checkbox" class="form-check-input" value="New"' . ($_SESSION["filterConditionNew"] ? " checked" : "") . '>New';
|
|
|
232 |
$str .= ' </label>';
|
|
|
233 |
$str .= ' </div>';
|
|
|
234 |
$str .= ' <div class="form-check">';
|
|
|
235 |
$str .= ' <label class="form-check-label">';
|
|
|
236 |
$str .= ' <input name="filterConditionUsed" type="checkbox" class="form-check-input" value="Used"' . ($_SESSION["filterConditionUsed"] ? " checked" : "") . '>Used';
|
|
|
237 |
$str .= ' </label>';
|
|
|
238 |
$str .= ' </div>';
|
|
|
239 |
$str .= ' </div>';
|
|
|
240 |
$str .= ' </div>';
|
|
|
241 |
$str .= '';
|
|
|
242 |
$str .= ' <div class="card">';
|
|
|
243 |
$str .= ' <div class="card-header font-weight-bold">Media Type</div>';
|
|
|
244 |
$str .= ' <div class="card-body">';
|
|
|
245 |
$str .= ' <div class="form-check">';
|
|
|
246 |
$str .= ' <label class="form-check-label">';
|
|
|
247 |
$str .= ' <input name="filterMediaTypeCD" type="checkbox" class="form-check-input" value="CD"' . ($_SESSION["filterMediaTypeCD"] ? " checked" : "") . '>Compact Disc';
|
|
|
248 |
$str .= ' </label>';
|
|
|
249 |
$str .= ' </div>';
|
|
|
250 |
$str .= ' <div class="form-check">';
|
|
|
251 |
$str .= ' <label class="form-check-label">';
|
|
|
252 |
$str .= ' <input name="filterMediaTypeRecord" type="checkbox" class="form-check-input" value="Record"' . ($_SESSION["filterMediaTypeRecord"] ? " checked" : "") . '>Vinyl Record';
|
|
|
253 |
$str .= ' </label>';
|
|
|
254 |
$str .= ' </div>';
|
|
|
255 |
$str .= ' <div class="form-check">';
|
|
|
256 |
$str .= ' <label class="form-check-label">';
|
|
|
257 |
$str .= ' <input name="filterMediaTypeDigital" type="checkbox" class="form-check-input" value="Digital"' . ($_SESSION["filterMediaTypeDigital"] ? " checked" : "") . '>Digital';
|
|
|
258 |
$str .= ' </label>';
|
|
|
259 |
$str .= ' </div>';
|
|
|
260 |
$str .= ' </div>';
|
|
|
261 |
$str .= ' </div>';
|
|
|
262 |
$str .= ' </div>';
|
|
|
263 |
$str .= ' </div>';
|
|
|
264 |
$str .= '';
|
|
|
265 |
$str .= ' <div class="modal-footer ">';
|
|
|
266 |
$str .= ' <button id="save" type="submit" class="btn btn-success" name="submit" value="Save"">Save</button>';
|
|
|
267 |
$str .= ' <button id="discard" type="button" class="btn btn-danger" data-dismiss="modal">Discard</button>';
|
|
|
268 |
$str .= ' </div>';
|
|
|
269 |
$str .= ' </form>';
|
|
|
270 |
$str .= ' </div>';
|
|
|
271 |
$str .= ' </div>';
|
|
|
272 |
$str .= '</div>';
|
|
|
273 |
|
|
|
274 |
return($str);
|
|
|
275 |
}
|
|
|
276 |
?>
|