| 45 |
- |
1 |
<?php
|
|
|
2 |
include_once('php/clsLibGTIN.php');
|
|
|
3 |
include_once('php/constants.php');
|
|
|
4 |
|
|
|
5 |
error_reporting(E_ALL);
|
|
|
6 |
|
|
|
7 |
// add new entry to wishlist
|
|
|
8 |
function addWishlist($wlArr) {
|
|
|
9 |
$conn = MySessionHandler::getDBSessionId();
|
|
|
10 |
|
|
|
11 |
$created = mysqli_real_escape_string($conn, time());
|
|
|
12 |
$modified = $created;
|
|
|
13 |
|
|
|
14 |
$uid = $_SESSION['sessData']['userID'];
|
| 46 |
- |
15 |
$mid = isset($wlArr->{'mid'}) ? mysqli_real_escape_string($conn, $wlArr->{'mid'}) : 'NULL';
|
|
|
16 |
$rid = isset($wlArr->{'rid'}) ? mysqli_real_escape_string($conn, $wlArr->{'rid'}) : 'NULL';
|
| 45 |
- |
17 |
$title = mysqli_real_escape_string($conn, $wlArr->{'title'});
|
|
|
18 |
$artist = mysqli_real_escape_string($conn, $wlArr->{'artist'});
|
|
|
19 |
$format = 'Any';
|
| 46 |
- |
20 |
$currency = 'USD'; //bugbug
|
| 45 |
- |
21 |
$price = 'NULL';
|
|
|
22 |
$thumbnail = mysqli_real_escape_string($conn, $wlArr->{'thumbnail'});
|
|
|
23 |
|
|
|
24 |
$sql = "INSERT
|
|
|
25 |
INTO wishlist
|
| 46 |
- |
26 |
(id, created, modified, uid, mid, rid, title, artist, format, currency, price, thumbnail)
|
|
|
27 |
VALUES (NULL, '$created', '$modified', '$uid', '$mid', '$rid', '$title', '$artist', '$format', '$currency', '$price', '$thumbnail')";
|
| 45 |
- |
28 |
|
|
|
29 |
if ($result = mysqli_query($conn, $sql)) {
|
| 46 |
- |
30 |
$_SESSION['wishlistAdd'] = "<div class=\"alert alert-success alert-dismissible my-0\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button>" . $wlArr->{'title'} . " by " . $wlArr->{'artist'} . " has been added to the wishlist.</div>";
|
| 45 |
- |
31 |
} else {
|
|
|
32 |
$error = mysqli_errno($conn);
|
|
|
33 |
if ($error == 1062) {
|
| 46 |
- |
34 |
$_SESSION['wishlistAdd'] = "<div class=\"alert alert-warning alert-dismissible my-0\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button>" . $wlArr->{'title'} . " by " . $wlArr->{'artist'} . " is already on the wishlist.</div>";
|
| 45 |
- |
35 |
} else {
|
| 46 |
- |
36 |
$_SESSION['wishlistAdd'] = "<div class=\"alert alert-danger alert-dismissible my-0\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button>Error. Could not add " . $wlArr->{'title'} . " by " . $wlArr->{'artist'} . " to the wishlist.</div>";
|
| 45 |
- |
37 |
error_log("MySQL Read Wishlist SQL: " . $sql);
|
|
|
38 |
error_log("MySQL Write Wishlist Error: " . mysqli_error($conn) . " (" . $error . ")");
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
return;
|
|
|
43 |
}
|
|
|
44 |
|
| 46 |
- |
45 |
function checkWishlist($type, $id) {
|
| 45 |
- |
46 |
$conn = MySessionHandler::getDBSessionId();
|
|
|
47 |
|
|
|
48 |
$uid = $_SESSION['sessData']['userID'];
|
|
|
49 |
|
|
|
50 |
$sql = "SELECT id
|
|
|
51 |
FROM wishlist
|
| 46 |
- |
52 |
WHERE uid = '$uid' and " . ($type == "master" ? "mid" : "rid") . " = '$id'";
|
| 45 |
- |
53 |
|
|
|
54 |
if ($result = mysqli_query($conn, $sql)) {
|
|
|
55 |
if (mysqli_num_rows($result) > 0) {
|
|
|
56 |
return true;
|
|
|
57 |
}
|
|
|
58 |
} else if (mysqli_errno($conn)) {
|
|
|
59 |
error_log("MySQL Read Wishlist SQL: " . $sql);
|
|
|
60 |
error_log("MySQL Read Wishlist Error: " . mysqli_error($conn) . " (" . mysqli_errno($conn) . ")");
|
|
|
61 |
return true;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
return false;
|
| 46 |
- |
65 |
}
|
|
|
66 |
|
|
|
67 |
function getWishlist() {
|
|
|
68 |
$str = '';
|
|
|
69 |
$conn = MySessionHandler::getDBSessionId();
|
|
|
70 |
|
|
|
71 |
$uid = $_SESSION['sessData']['userID'];
|
|
|
72 |
|
|
|
73 |
$sql = "SELECT *
|
|
|
74 |
FROM wishlist
|
|
|
75 |
WHERE uid = '$uid'";
|
|
|
76 |
|
|
|
77 |
if ($result = mysqli_query($conn, $sql)) {
|
|
|
78 |
if (mysqli_num_rows($result) > 0) {
|
|
|
79 |
$str .= "<table id=\"wishlistTable\" class=\"table table-striped table-condensed small\">";
|
|
|
80 |
$str .= "<thead class=\"thead-dark sticky-top\">";
|
|
|
81 |
$str .= "<tr><th>Image</th>";
|
|
|
82 |
$str .= "<th class=\"text-left\" style=\"cursor:pointer;\" onclick=\"sortTable('wishlistTable', 1, 'text')\">Artist<span class=\"float-right\"><i class=\"fas fa-caret-up\"</i><i class=\"fas fa-caret-down\"></span></th>";
|
|
|
83 |
$str .= "<th class=\"text-left\" style=\"cursor:pointer;\" onclick=\"sortTable('wishlistTable', 2, 'text')\">Title<span class=\"float-right\"><i class=\"fas fa-caret-up\"</i><i class=\"fas fa-caret-down\"></span></th>";
|
|
|
84 |
$str .= "<th style=\"cursor:pointer;\" onclick=\"sortTable('wishlistTable', 3, 'text')\">Format<span class=\"float-right\"><i class=\"fas fa-caret-up\"</i><i class=\"fas fa-caret-down\"></span></th>";
|
|
|
85 |
$str .= "<th class=\"d-none\">Ceiling Price Number</th>";
|
|
|
86 |
$str .= "<th style=\"cursor:pointer;\" onclick=\"sortTable('wishlistTable', 4, 'currency')\">Ceiling Price<span class=\"float-right\"><i class=\"fas fa-caret-up\"</i><i class=\"fas fa-caret-down\"></span></th>";
|
|
|
87 |
$str .= "<th></th><th></th><th></th><th></th></tr></thead>";
|
|
|
88 |
$str .= "<tbody>";
|
|
|
89 |
|
|
|
90 |
while($row = mysqli_fetch_assoc($result)) {
|
|
|
91 |
$artist = (empty($row["artist"]) ? "Various" : $row["artist"]);
|
|
|
92 |
$altText = "Image for " . $row['title'] . " by " . $artist;
|
|
|
93 |
$price = print_monetary($row['price'], $row['currency']);
|
|
|
94 |
|
|
|
95 |
$str .= "<tr>";
|
|
|
96 |
$str .= "<td><img class=\"img-fluid\" style=\"max-height:3em;\" src=\"" . $row["thumbnail"] . "\" alt=\"$altText\"></td>";
|
|
|
97 |
$str .= "<td>$artist</td>";
|
|
|
98 |
$str .= "<td>" . $row['title'] . "</td>";
|
|
|
99 |
$str .= "<td>" . $row['format'] . "</td>";
|
|
|
100 |
$str .= "<td class=\"d-none\">" . $row['price'] . "</td>";
|
|
|
101 |
$str .= "<td>" . $price . "</td>";
|
|
|
102 |
$str .= "<td><i class=\"fas fa-edit\" style='font-size:1.5em;'></i></td>";
|
|
|
103 |
$str .= "<td><i class=\"fas fa-window-close\" style=\"color:red;font-size:1.5em;\"></i></td>";
|
|
|
104 |
$str .= "<td><i class=\"fas fa-info-circle\" style='font-size:1.5em;'</td>";
|
|
|
105 |
$str .= "<td><i class=\"fas fa-search\" style='font-size:1.5em;'></i></td>";
|
|
|
106 |
|
|
|
107 |
$str .= "</tr>";
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
$str .= "</tbody>";
|
|
|
111 |
$str .= "</table>";
|
|
|
112 |
}
|
|
|
113 |
} else if (mysqli_errno($conn)) {
|
|
|
114 |
error_log("MySQL Read Wishlist SQL: " . $sql);
|
|
|
115 |
error_log("MySQL Read Wishlist Error: " . mysqli_error($conn) . " (" . mysqli_errno($conn) . ")");
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
return $str;
|
| 45 |
- |
119 |
}
|