Subversion Repositories cheapmusic

Rev

Rev 127 | Rev 134 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
45 - 1
<?php
65 - 2
include_once ('php/clsLibGTIN.php');
3
include_once ('php/constants.php');
45 - 4
 
5
error_reporting(E_ALL);
6
 
65 - 7
// add new entry to wishlist
52 - 8
function addWishlist($uid, $wlArr) {
50 - 9
    $nul = 'NULL';
45 - 10
    $conn = MySessionHandler::getDBSessionId();
11
 
12
    $created = mysqli_real_escape_string($conn, time());
13
    $modified = $created;
14
 
52 - 15
    $uid = mysqli_real_escape_string($conn, $uid);
16
    $mid = isset($wlArr->{'mid'}) ? mysqli_real_escape_string($conn, $wlArr->{'mid'}) : "";
17
    $rid = isset($wlArr->{'rid'}) ? mysqli_real_escape_string($conn, $wlArr->{'rid'}) : "";
81 - 18
    $asin = isset($wlArr->{'asin'}) ? "'" . mysqli_real_escape_string($conn, $wlArr->{'asin'}) . "'" : "NULL";
50 - 19
    $barcode = (empty($wlArr->{'barcode'}) ? "NULL" : "'" . mysqli_real_escape_string($conn, $wlArr->{'barcode'}) . "'");
20
    $title = isset($wlArr->{'title'}) ? "'" . mysqli_real_escape_string($conn, $wlArr->{'title'}) . "'" : "NULL";
21
    $artist = isset($wlArr->{'artist'}) ? "'" . mysqli_real_escape_string($conn, $wlArr->{'artist'}) . "'" : "NULL";
73 - 22
    $cond = 'Any';
45 - 23
    $format = 'Any';
46 - 24
    $currency = 'USD'; //bugbug
45 - 25
    $price = 'NULL';
50 - 26
    $url = isset($wlArr->{'url'}) ? "'" . mysqli_real_escape_string($conn, $wlArr->{'url'}) . "'" : "NULL";
27
    $thumbnail = isset($wlArr->{'thumbnail'}) ? "'" . mysqli_real_escape_string($conn, $wlArr->{'thumbnail'}) . "'" : "NULL";
96 - 28
    $ip = inet_pton($_SERVER['REMOTE_ADDR']);
45 - 29
 
30
    $sql = "INSERT
31
            INTO wishlist
96 - 32
            (id, created, ip, modified, uid, mid, rid, asin, barcode, title, artist, cond, format, currency, price, url, thumbnail)
33
            VALUES (NULL, '$created', '$ip', '$modified', '$uid', '$mid', '$rid', " . $asin . ", " . $barcode . ", " . $title . ", " . $artist . ", '$cond', '$format', '$currency', '$price', " . $url . ", " . $thumbnail . ")";
45 - 34
 
35
    if ($result = mysqli_query($conn, $sql)) {
52 - 36
        return 0;
65 - 37
    }
38
    else {
45 - 39
        $error = mysqli_errno($conn);
40
        if ($error == 1062) {
52 - 41
            return 1;
65 - 42
        }
43
        else {
45 - 44
            error_log("MySQL Read Wishlist SQL: " . $sql);
52 - 45
            error_log("MySQL Read Wishlist Error: " . mysqli_error($conn) . " (" . $error . ")");
46
            return -1;
45 - 47
        }
48
    }
49
 
52 - 50
    return -1;
45 - 51
}
52
 
46 - 53
function checkWishlist($type, $id) {
45 - 54
    $conn = MySessionHandler::getDBSessionId();
81 - 55
    if ($type == "master") {
56
        $colName = "mid";
57
    } else if ($type == "release") {
58
        $colName = "rid";
59
    } else if ($type == "asin") {
60
        $colName = "asin";
61
    }
45 - 62
 
52 - 63
    $uid = mysqli_real_escape_string($conn, $_SESSION['sessData']['userID']);
45 - 64
 
65
    $sql = "SELECT id
66
            FROM wishlist
81 - 67
            WHERE uid = '$uid' and $colName = '$id'";
45 - 68
 
69
    if ($result = mysqli_query($conn, $sql)) {
70
        if (mysqli_num_rows($result) > 0) {
71
            return true;
72
        }
73
    }
65 - 74
    else if (mysqli_errno($conn)) {
75
        error_log("MySQL Check Wishlist SQL: " . $sql);
76
        error_log("MySQL Check Wishlist Error: " . mysqli_error($conn) . " (" . mysqli_errno($conn) . ")");
77
        return true;
78
    }
45 - 79
 
80
    return false;
46 - 81
}
82
 
83
function getWishlist() {
127 - 84
    $xh = new Html;
85
    $xh->init($_SESSION["htmlIndent"]);
86
 
107 - 87
    if (!isLoggedIn()) {
127 - 88
        $xh->add_attribute("class", "container bg-warning text-center py-3");
89
        $xh->tag('div');
90
            $xh->add_attribute("class", "display-6");
91
            $xh->tag('p');
92
                $xh->add_attribute("class", "material-icons");
93
                $xh->tag('i', "error_outline");
94
                $xh->tag('span', " Please login to your Find Cheap Music account in order to maintain the wishlist.");
95
            $xh->close(); // p
96
        $xh->close(); // div
97
 
98
        $html = $xh->flush();
99
       //error_log(print_r($html, 1));
100
 
101
        return $html;
107 - 102
    }
103
 
46 - 104
    $conn = MySessionHandler::getDBSessionId();
105
 
106
    $uid = $_SESSION['sessData']['userID'];
107
 
108
    $sql = "SELECT *
109
            FROM wishlist
110
            WHERE uid = '$uid'";
111
 
112
    if ($result = mysqli_query($conn, $sql)) {
113
        if (mysqli_num_rows($result) > 0) {
127 - 114
            $xh->add_attribute("class", "container");
115
            $xh->tag('div');
116
              $xh->add_attribute("class", "input-group mt-3");
117
              $xh->tag('div');
118
                $xh->add_attribute("class", "input-group-prepend");
119
                $xh->tag('div');
120
                  $xh->add_attribute("class", "input-group-text");
121
                  $xh->tag('span');
122
                    $xh->add_attribute("class", "material-icons");
123
                    $xh->tag('i', "search");
124
                  $xh->close(); // span
125
                $xh->close(); // div
126
                $xh->add_attribute("type", "text");
127
                $xh->add_attribute("class", "form-control");
128
                $xh->add_attribute("id", "tableFilter");
129
                $xh->add_attribute("placeholder", "Search for..");
130
                $xh->add_attribute("aria-label", "Search for entry");
131
                $xh->single_tag('input');
132
                $xh->add_attribute("id", "tableFilterButton");
133
                $xh->add_attribute("class", "input-group-append");
134
                $xh->tag('div');
135
                $xh->add_attribute("id", "tableFilterReset");
136
                $xh->add_attribute("type", "button");
137
                $xh->add_attribute("class", "btn rounded");
138
                  $xh->tag('button');
139
                    $xh->add_attribute("class", "material-icons");
140
                    $xh->tag('i', "cancel_presentation");
141
                  $xh->close(); // button
142
                $xh->close(); // div
143
                $xh->add_attribute("nonce", base64_encode($_SESSION["nonce"]));
144
                $xh->tag('script');
145
                  $str =  trim('document.addEventListener("DOMContentLoaded", function() {');
146
                  $str .= trim('	document.getElementById("tableFilter").addEventListener("keyup", function() {');
147
                  $str .= trim('        filterWishlist();');
148
                  $str .= trim('	});');
149
                  $str .= trim('	document.getElementById("tableFilterReset").addEventListener("click", function() {');
150
                  $str .= trim('        document.getElementById("tableFilter").value = "";');
151
                  $str .= trim('        filterWishlist();');
152
                  $str .= trim('	});');
153
                  $str .= trim('});');
154
                  $xh->insert_code($str);
155
                $xh->close(); // script
156
              $xh->close(); // div
52 - 157
 
127 - 158
              $xh->add_attribute("method", "post");
159
              $xh->add_attribute("action", "/index.php");
160
              $xh->tag('form');
161
                $xh->insert_code(inputSessionTab());
162
                $xh->add_attribute("id", "discogsTitle");
163
                $xh->add_attribute("type", "hidden");
164
                $xh->add_attribute("name", "discogsTitle");
165
                $xh->add_attribute("value", "");
166
                $xh->single_tag('input');
167
                $xh->add_attribute("id", "discogsArtist");
168
                $xh->add_attribute("type", "hidden");
169
                $xh->add_attribute("name", "discogsArtist");
170
                $xh->add_attribute("value", "");
171
                $xh->single_tag('input');
172
                $xh->add_attribute("id", "discogsBarcode");
173
                $xh->add_attribute("type", "hidden");
174
                $xh->add_attribute("name", "discogsBarcode");
175
                $xh->add_attribute("value", "");
176
                $xh->single_tag('input');
177
                $xh->insert_code(inputNonce());
178
                $xh->add_attribute("class", "table");
179
                $xh->tag('div');
180
                  $xh->add_attribute("id", "wishlistTable");
181
                  $xh->add_attribute("class", "table table-striped table-condensed table-hover small");
182
                  $xh->tag('table');
183
                    $xh->add_attribute("class", "head-dark table-header-sticky");
184
                    $xh->tag('thead');
185
                      $xh->tag('tr');
186
                        $xh->add_attribute("class", "hide-medium");
187
                        $xh->tag('th', "");
188
                        $xh->add_attribute("id", "sortColumn1");
189
                        $xh->add_attribute("class", "text-left cursor-pointer");
190
                        $xh->tag('th');
191
                          $xh->add_attribute("class", "nowrap");
192
                          $xh->tag('span');
193
                            $xh->tag('span', "Artist");
194
                            $xh->add_attribute("class", "d-block d-md-none");
195
                            $xh->tag('span', "<br>");
196
                            $xh->add_attribute("class", "material-icons hide-material-icons material-text material-nrm");
197
                            $xh->tag('i', "arrow_drop_up");
198
                            $xh->add_attribute("class", "material-icons hide-material-icons material-text material-nlm");
199
                            $xh->tag('i', "arrow_drop_down");
200
                          $xh->close(); // span
201
                        $xh->close(); // th
46 - 202
 
127 - 203
                        $xh->add_attribute("id", "sortColumn2");
204
                        $xh->add_attribute("class", "text-left cursor-pointer");
205
                        $xh->tag('th');
206
                          $xh->add_attribute("class", "nowrap");
207
                          $xh->tag('span');
208
                            $xh->tag('span', "Title");
209
                            $xh->add_attribute("class", "d-block d-md-none");
210
                            $xh->tag('span', "<br>");
211
                            $xh->add_attribute("class", "material-icons hide-material-icons material-text material-nrm");
212
                            $xh->tag('i', "arrow_drop_up");
213
                            $xh->add_attribute("class", "material-icons hide-material-icons material-text material-nlm");
214
                            $xh->tag('i', "arrow_drop_down");
215
                          $xh->close(); // span
216
                        $xh->close(); // th
217
 
218
                        $xh->add_attribute("id", "sortColumn3");
219
                        $xh->add_attribute("class", "d-none");
220
                        $xh->tag('th', "");
221
 
222
                        $xh->add_attribute("id", "sortColumn4");
223
                        $xh->add_attribute("class", "cursor-pointer hide-medium hide-small");
224
                        $xh->tag('th');
225
                          $xh->add_attribute("class", "nowrap");
226
                          $xh->tag('span');
227
                            $xh->tag('span', "Barcode");
228
                            $xh->add_attribute("class", "d-block d-md-none");
229
                            $xh->tag('span', "<br>");
230
                            $xh->add_attribute("class", "material-icons hide-material-icons material-text material-nrm");
231
                            $xh->tag('i', "arrow_drop_up");
232
                            $xh->add_attribute("class", "material-icons hide-material-icons material-text material-nlm");
233
                            $xh->tag('i', "arrow_drop_down");
234
                          $xh->close(); // span
235
                        $xh->close(); // th
236
 
237
                        $xh->add_attribute("id", "sortColumn5");
238
                        $xh->add_attribute("class", "cursor-pointer hide-small");
239
                        $xh->tag('th');
240
                          $xh->add_attribute("class", "nowrap");
241
                          $xh->tag('span');
242
                            $xh->tag('span', "Condition");
243
                            $xh->add_attribute("class", "d-block d-md-none");
244
                            $xh->tag('span', "<br>");
245
                            $xh->add_attribute("class", "material-icons hide-material-icons material-text material-nrm");
246
                            $xh->tag('i', "arrow_drop_up");
247
                            $xh->add_attribute("class", "material-icons hide-material-icons material-text material-nlm");
248
                            $xh->tag('i', "arrow_drop_down");
249
                          $xh->close(); // span
250
                        $xh->close(); // th
251
 
252
                        $xh->add_attribute("id", "sortColumn6");
253
                        $xh->add_attribute("class", "cursor-pointer hide-small");
254
                        $xh->tag('th');
255
                          $xh->add_attribute("class", "nowrap");
256
                          $xh->tag('span');
257
                            $xh->tag('span', "Format");
258
                            $xh->add_attribute("class", "d-block d-md-none");
259
                            $xh->tag('span', "<br>");
260
                            $xh->add_attribute("class", "material-icons hide-material-icons material-text material-nrm");
261
                            $xh->tag('i', "arrow_drop_up");
262
                            $xh->add_attribute("class", "material-icons hide-material-icons material-text material-nlm");
263
                            $xh->tag('i', "arrow_drop_down");
264
                          $xh->close(); // span
265
                        $xh->close(); // th
266
 
267
                        $xh->add_attribute("class", "d-none");
268
                        $xh->tag('th', "Ceiling Price Plain Number");
269
 
270
                        $xh->add_attribute("id", "sortColumn7");
271
                        $xh->add_attribute("class", "cursor-pointer");
272
                        $xh->tag('th');
273
                          $xh->add_attribute("class", "nowrap");
274
                          $xh->tag('span');
275
                            $xh->tag('span', "Price");
276
                            $xh->add_attribute("class", "d-block d-md-none");
277
                            $xh->tag('span', "<br>");
278
                            $xh->add_attribute("class", "material-icons hide-material-icons material-text material-nrm");
279
                            $xh->tag('i', "arrow_drop_up");
280
                            $xh->add_attribute("class", "material-icons hide-material-icons material-text material-nlm");
281
                            $xh->tag('i', "arrow_drop_down");
282
                          $xh->close(); // span
283
                        $xh->close(); // th
284
 
285
                        $xh->tag('th', "");
286
                        $xh->add_attribute("class", "d-none");
287
                        $xh->tag('th', "");
288
                      $xh->close(); // tr
289
                    $xh->close(); // thead
290
 
291
                    $xh->add_attribute("nonce", base64_encode($_SESSION["nonce"]));
292
                    $xh->tag('script');
293
                      $str =  trim('document.addEventListener("DOMContentLoaded", function() {');
294
                      $str .= trim('	document.getElementById("sortColumn1").addEventListener("click", function() {');
295
                      $str .= trim('        sortTable("wishlistTable", 1, "text");');
296
                      $str .= trim('	});');
297
                      $str .= trim('	document.getElementById("sortColumn2").addEventListener("click", function() {');
298
                      $str .= trim('        sortTable("wishlistTable", 2, "text");');
299
                      $str .= trim('	});');
300
                      $str .= trim('	document.getElementById("sortColumn4").addEventListener("click", function() {');
301
                      $str .= trim('        sortTable("wishlistTable", 4, "text");');
302
                      $str .= trim('	});');
303
                      $str .= trim('	document.getElementById("sortColumn5").addEventListener("click", function() {');
304
                      $str .= trim('        sortTable("wishlistTable", 5, "text");');
305
                      $str .= trim('	});');
306
                      $str .= trim('	document.getElementById("sortColumn6").addEventListener("click", function() {');
307
                      $str .= trim('        sortTable("wishlistTable", 6, "text");');
308
                      $str .= trim('	});');
309
                      $str .= trim('	document.getElementById("sortColumn7").addEventListener("click", function() {');
310
                      $str .= trim('        sortTable("wishlistTable", 7, "numeric");');
311
                      $str .= trim('	});');
312
                      $str .= trim('});');
313
                    $xh->insert_code($str);
314
                  $xh->close(); // script
315
                  $xh->tag('tbody');
316
 
65 - 317
            while ($row = mysqli_fetch_assoc($result)) {
125 - 318
                $artist = (empty($row["artist"]) ? "Various" : htmlentities($row["artist"]));
319
                $altText = "Image for " . htmlentities($row['title']) . " by " . $artist;
46 - 320
                $price = print_monetary($row['price'], $row['currency']);
125 - 321
                $searchTitle = 'Searching for:<br><br><strong>' . htmlentities($row['title']) . " by " . $artist;
50 - 322
                if ($row['barcode'] !== null) {
323
                    $searchTitle .= " (" . displayBarcode($row['barcode']) . ")";
324
                }
52 - 325
                $searchTitle .= "</strong>";
47 - 326
 
127 - 327
                $xh->add_attribute("class", "border");
130 - 328
                $xh->add_attribute("data-id", $row['id']);
329
                $xh->add_attribute("data-title", htmlentities($row['title']));
330
                $xh->add_attribute("data-artist", $artist);
331
                $xh->add_attribute("data-barcode", htmlentities($row['barcode']));
332
                $xh->add_attribute("data-search-title", $searchTitle);
127 - 333
                $xh->tag('tr');
334
                  $xh->add_attribute("class", "hide-medium wl-img");
335
                  $xh->tag('td');
336
                    $xh->add_attribute("class", "img-fluid lazyload");
337
                    $xh->add_attribute("src",PIXEL);
338
                    $xh->add_attribute("data-src", $row["thumbnail"]);
339
                    $xh->add_attribute("alt", $altText);
340
                    $xh->single_tag('img');
341
                  $xh->close(); // td
52 - 342
 
127 - 343
                  $xh->tag('td', $artist);
344
                  $xh->tag('td', htmlentities($row['title']));
345
                  $xh->add_attribute("class", "d-none");
346
                  $xh->tag('td', htmlentities($row['barcode']));
347
                  $xh->add_attribute("class", "hide-medium hide-small");
348
                  $xh->tag('td', displayBarcode($row['barcode']));
349
                  $xh->add_attribute("class", "hide-small");
350
                  $xh->tag('td', $row['cond']);
351
                  $xh->add_attribute("class", "hide-small");
352
                  $xh->tag('td', $row['format']);
353
                  $xh->add_attribute("class", "d-none");
354
                  $xh->tag('td', $row['price']);
355
                  $xh->tag('td', $price);
356
                  $xh->add_attribute("class", "text-nowrap");
357
                  $xh->tag('td');
358
                  $xh->add_attribute("id", "wlEditBtn" . $row['id']);
359
                  $xh->add_attribute("class", "btn btn-sm btn-warning rounded px-1");
360
                  $xh->add_attribute("type", "button");
361
                  $xh->add_attribute("data-toggle", "tooltip");
362
                  $xh->add_attribute("title", "Edit");
363
                  $xh->add_attribute("aria-label", "Edit Entry");
364
                  $xh->tag('button');
365
                      $xh->add_attribute("class", "material-icons");
366
                      $xh->tag('i', "edit");
367
                  $xh->close(); // button
368
                  $xh->tag('span' , " ");
369
                  $xh->add_attribute("id", "wlDeleteBtn" . $row['id']);
370
                  $xh->add_attribute("class", "btn btn-sm btn-danger rounded px-1");
371
                  $xh->add_attribute("type", "button");
372
                  $xh->add_attribute("data-toggle", "tooltip");
373
                  $xh->add_attribute("title", "Delete");
374
                  $xh->add_attribute("aria-label", "Delete Entry");
375
                  $xh->tag('button');
376
                      $xh->add_attribute("class", "material-icons");
377
                      $xh->tag('i', "cancel_presentation");
378
                  $xh->close(); // button
379
                  $xh->tag('span' , " ");
130 - 380
                  $xh->add_attribute("id", "wlInfoBtn" . $row['id']);
127 - 381
                  $xh->add_attribute("class", "btn btn-sm btn-info rounded px-1 hide-small");
382
                  $xh->add_attribute("role", "button");
383
                  $xh->add_attribute("data-toggle", "tooltip");
384
                  $xh->add_attribute("title", "Information");
385
                  $xh->add_attribute("aria-label", "Information for Entry");
386
                  $xh->add_attribute("href", htmlentities($row['url']));
387
                  $xh->add_attribute("target", "_blank", "rel", "noreferrer noopener");
388
                  $xh->tag('a');
389
                      $xh->add_attribute("class", "material-icons");
390
                      $xh->tag('i', "info_outline");
391
                  $xh->close(); // a
392
                  $xh->tag('span' , " ");
393
                  $xh->add_attribute("id", "wlSearchBtn" . $row['id']);
394
                  $xh->add_attribute("type", "submit");
395
                  $xh->add_attribute("name", "submit");
396
                  $xh->add_attribute("value", "discogsSearch");
397
                  $xh->add_attribute("class", "btn btn-sm btn-success rounded px-1");
398
                  $xh->tag('button');
399
                      $xh->add_attribute("class", "material-icons");
400
                      $xh->add_attribute("title", "Search for Store Offers");
401
                      $xh->add_attribute("aria-label", "Search Store Offers for Entry");
402
                      $xh->add_attribute("data-toggle", "tooltip");
403
                      $xh->tag('i', "search");
404
                  $xh->close(); // button
405
                  $xh->close(); // td
406
                  $xh->add_attribute("id", "wlIdRow" . $row['id']);
407
                  $xh->add_attribute("class", "d-none");
408
                  $xh->tag('td', "");
409
                $xh->close(); // tr
46 - 410
            }
52 - 411
 
127 - 412
              $xh->close(); // tbody
413
              $xh->close(); // table
130 - 414
              $xh->add_attribute("nonce", base64_encode($_SESSION["nonce"]));
415
              $xh->tag('script');
416
                $str  = trim('document.addEventListener("DOMContentLoaded", function() {');
417
                $str .= trim('  document.getElementById("wishlistTable").addEventListener("click", function(event) {');
418
                $str .= trim('       e = event.target.closest("button") || event.target.closest("a");');
419
                $str .= trim('       tr = event.target.closest("tr");');
420
                $str .= trim('       if (e && tr && e.id.startsWith("wlEditBtn")) {');
421
                $str .= trim('           var id = tr.getAttribute("data-id");');
422
                $str .= trim('           window.dataLayer.push({ "event" : "trackEvent", "eventCategory" : "Wishlist", "eventAction" : "Edit", "eventLabel" : ""});');
423
                $str .= trim('           editWishlist(id, e);');
424
                $str .= trim('       } else if (e && tr && e.id.startsWith("wlDeleteBtn")) {');
425
                $str .= trim('           var id = tr.getAttribute("data-id");');
426
                $str .= trim('           var title = tr.getAttribute("data-title");');
427
                $str .= trim('           var artist = tr.getAttribute("data-artist");');
428
                $str .= trim('           window.dataLayer.push({ "event" : "trackEvent", "eventCategory" : "Wishlist", "eventAction" : "Delete", "eventLabel" : ""});');
429
                $str .= trim('           deleteWishlist(id, e, title, artist);');
430
                $str .= trim('       } else if (e && tr && e.id.startsWith("wlInfoBtn")) {');
431
                $str .= trim('           window.dataLayer.push({ "event" : "trackEvent", "eventCategory" : "Album Info", "eventAction" : "Click", "eventLabel" : ""});');
432
                $str .= trim('       } else if (e && tr && e.id.startsWith("wlSearchBtn")) {');
433
/* bugbug Merge with htmlTools.php (search_term)*/
434
                $str .= trim('           var title = tr.getAttribute("data-title");');
435
                $str .= trim('           var artist = tr.getAttribute("data-artist");');
436
                $str .= trim('           var barcode = tr.getAttribute("data-barcode");');
437
                $str .= trim('           var searchTitle = tr.getAttribute("data-search-title");');
438
                $str .= trim('           document.getElementById("discogsTitle").value = title;');
439
                $str .= trim('           document.getElementById("discogsArtist").value = artist;');
440
                $str .= trim('           document.getElementById("discogsBarcode").value = barcode;');
441
                $str .= trim('           progressBar(searchTitle);');
442
                $str .= trim('       }');
443
                $str .= trim('  });');
444
                $str .= trim('});');
445
                $xh->insert_code($str);
446
              $xh->close(); // script
447
 
127 - 448
              $xh->close(); // div
449
              $xh->close(); // form
450
 
451
              $xh->add_attribute("class", "modal fade");
452
              $xh->add_attribute("id", "editWishlistModal");
453
              $xh->tag('div');
454
                $xh->add_attribute("class", "modal-dialog");
455
                $xh->tag('div');
456
                  $xh->add_attribute("class", "modal-content");
457
                  $xh->tag('div');
458
                    $xh->add_attribute("class", "modal-header bg-secondary");
459
                    $xh->tag('div');
460
                      $xh->add_attribute("class", "modal-title display-6");
461
                      $xh->tag('p', "Edit Wishlist Entry");
462
                    $xh->close(); // div>
463
                    $xh->add_attribute("class", "mt-0");
464
                    $xh->add_attribute("id", "wlMsg");
465
                    $xh->tag('span', "");
466
                    $xh->insert_code(inputSessionTab());
467
                    $xh->add_attribute("type", "hidden");
468
                    $xh->add_attribute("name", "wlId");
469
                    $xh->add_attribute("id", "wlId");
470
                    $xh->single_tag('input');
471
                    $xh->add_attribute("class", "modal-body");
472
                    $xh->tag('div');
473
                      $xh->add_attribute("class", "form-group");
474
                      $xh->tag('div');
475
                        $xh->add_attribute("for", "wlArtist");
476
                        $xh->tag('label', "Artist:");
477
                        $xh->add_attribute("type", "text");
478
                        $xh->add_attribute("class", "form-control");
479
                        $xh->add_attribute("id", "wlArtist");
480
                        $xh->single_tag('input');
481
                      $xh->close(); // div
482
                      $xh->add_attribute("class", "form-group");
483
                      $xh->tag('div');
484
                        $xh->add_attribute("for", "wlTitle");
485
                        $xh->tag('label', "Title:");
486
                        $xh->add_attribute("type", "text");
487
                        $xh->add_attribute("class", "form-control");
488
                        $xh->add_attribute("id", "wlTitle");
489
                        $xh->single_tag('input');
490
                      $xh->close(); // div
491
                      $xh->add_attribute("class", "form-group");
492
                      $xh->tag('div');
493
                        $xh->add_attribute("for", "wlBarcode");
494
                        $xh->tag('label', "Barcode:");
495
                        $xh->add_attribute("type", "text");
496
                        $xh->add_attribute("class", "form-control");
497
                        $xh->add_attribute("id", "wlBarcode");
498
                        $xh->single_tag('input');
499
                      $xh->close(); // div
500
                      $xh->add_attribute("class", "form-group");
501
                      $xh->tag('div');
502
                        $xh->add_attribute("for", "wlCond");
503
                        $xh->tag('label', "Condition:");
504
                        $xh->add_attribute("class", "form-control");
505
                        $xh->add_attribute("id", "wlCond");
506
                        $xh->tag('select');
507
                          $xh->tag('option', "Any");
508
                          $xh->tag('option', "New");
509
                          $xh->tag('option', "Used");
510
                        $xh->close(); // select
511
                      $xh->close(); // div
512
                      $xh->add_attribute("class", "form-group");
513
                      $xh->tag('div');
514
                        $xh->add_attribute("for", "wlFormat");
515
                        $xh->tag('label', "Format:");
516
                        $xh->add_attribute("class", "form-control");
517
                        $xh->add_attribute("id", "wlFormat");
518
                        $xh->tag('select');
519
                          $xh->tag('option', "Any");
520
                          $xh->tag('option', "CD");
521
                          $xh->tag('option', "Record");
522
                          $xh->tag('option', "Digital");
523
                          $xh->tag('option', "Book");
524
                        $xh->close(); // select
525
                      $xh->close(); // div
526
                      $xh->add_attribute("class", "form-group");
527
                      $xh->tag('div');
528
                        $xh->add_attribute("for", "wlPrice");
529
                        $xh->tag('label', "Ceiling Price:");
530
                        $xh->add_attribute("type", "text");
531
                        $xh->add_attribute("class", "form-control");
532
                        $xh->add_attribute("id", "wlPrice");
533
                        $xh->single_tag('input');
534
                      $xh->close(); // div
535
                    $xh->close(); // div
536
                    $xh->add_attribute("class", "modal-footer bg-secondary");
537
                    $xh->tag('div');
538
                    $xh->add_attribute("id", "saveEditedWl");
539
                    $xh->add_attribute("type", "button");
540
                    $xh->add_attribute("class", "btn btn-success");
541
                    $xh->add_attribute("name", "submit");
542
                    $xh->add_attribute("value", "Save");
543
                    $xh->tag('button', "Save");
544
                    $xh->add_attribute("nonce", base64_encode($_SESSION["nonce"]));
545
                    $xh->tag('script');
546
                      $str =  trim('document.addEventListener("DOMContentLoaded", function() {');
547
                      $str .= trim('	document.getElementById("saveEditedWl").addEventListener("click", function() {');
548
                      $str .= trim('        saveEditedWishlist();');
549
                      $str .= trim('	});');
550
                      $str .= trim('});');
551
                      $xh->insert_code($str);
552
                    $xh->close(); // script
553
                    $xh->add_attribute("type", "button");
554
                    $xh->add_attribute("class", "btn btn-danger");
555
                    $xh->add_attribute("data-dismiss", "modal");
556
                    $xh->tag('button', "Cancel");
557
                    $xh->close(); // div
558
                  $xh->close(); // div
559
                $xh->close(); // div
560
              $xh->close(); // div
561
            $xh->close(); // div
65 - 562
        }
563
        else {
127 - 564
            $xh->add_attribute("class", "container bg-warning text-center py-3");
565
            $xh->tag('div');
566
                $xh->add_attribute("class", "display-6");
567
                $xh->tag('p');
568
                    $xh->add_attribute("class", "material-icons");
569
                    $xh->tag('i', "bookmark");
570
                    $xh->tag('span', " Your wishlist is currently empty. Add matching albums from the search results.");
571
                $xh->close(); // p
572
            $xh->close(); // div
46 - 573
        }
574
    }
65 - 575
    else if (mysqli_errno($conn)) {
576
        error_log("MySQL Read Wishlist SQL: " . $sql);
577
        error_log("MySQL Read Wishlist Error: " . mysqli_error($conn) . " (" . mysqli_errno($conn) . ")");
578
    }
46 - 579
 
127 - 580
    $html = $xh->flush();
581
    //error_log(print_r($html, 1));
582
 
583
    return $html;
52 - 584
}
585
 
586
function deleteWishlist($uid, $id) {
587
    $conn = MySessionHandler::getDBSessionId();
588
 
589
    $id = mysqli_real_escape_string($conn, $id);
590
    $uid = mysqli_real_escape_string($conn, $uid);
591
 
592
    $sql = "DELETE FROM wishlist WHERE id = $id AND uid = $uid;";
593
 
594
    if (!($result = mysqli_query($conn, $sql))) {
65 - 595
        error_log("MySQL Delete Wishlist SQL: " . $sql);
596
        error_log("MySQL Delete Wishlist Error: " . mysqli_error($conn) . " (" . mysqli_errno($conn) . ")");
597
        return -1;
52 - 598
    }
599
 
600
    return 0;
601
}
602
 
603
function updateWishlist($uid, $wlArr) {
604
    $nul = 'NULL';
605
    $conn = MySessionHandler::getDBSessionId();
606
 
607
    $modified = mysqli_real_escape_string($conn, time());
608
 
609
    $id = (empty($wlArr['id']) ? "NULL" : "'" . mysqli_real_escape_string($conn, $wlArr['id']) . "'");
610
    $uid = mysqli_real_escape_string($conn, $uid);
611
    $barcode = (empty($wlArr['barcode']) ? "NULL" : "'" . mysqli_real_escape_string($conn, $wlArr['barcode']) . "'");
612
    $title = isset($wlArr['title']) ? "'" . mysqli_real_escape_string($conn, $wlArr['title']) . "'" : "NULL";
613
    $artist = isset($wlArr['artist']) ? "'" . mysqli_real_escape_string($conn, $wlArr['artist']) . "'" : "NULL";
73 - 614
    $cond = isset($wlArr['cond']) ? mysqli_real_escape_string($conn, $wlArr['cond']) : "Any";
52 - 615
    $format = isset($wlArr['format']) ? mysqli_real_escape_string($conn, $wlArr['format']) : "Any";
616
    $currency = 'USD'; //bugbug
617
    $price = isset($wlArr['price']) ? "'" . mysqli_real_escape_string($conn, $wlArr['price']) . "'" : "NULL";
618
 
619
    $sql = "UPDATE wishlist
73 - 620
            SET modified='$modified', barcode=" . $barcode . ", title=" . $title . ", artist=" . $artist . ", cond='$cond', format='$format', price=" . $price . "
52 - 621
            WHERE id=$id and uid=$uid";
622
 
623
    if ($result = mysqli_query($conn, $sql)) {
624
        return 0;
65 - 625
    }
626
    else {
52 - 627
        error_log("MySQL Update Wishlist SQL: " . $sql);
628
        error_log("MySQL Update Wishlist Error: " . mysqli_error($conn) . " (" . $error . ")");
629
        return -1;
630
    }
631
 
632
    return -1;
633
}
73 - 634
 
635
function unsubscribeWishlist($arr) {
116 - 636
    if (empty($arr['id']) || empty($arr['email'])) {
637
        return "";
638
    }
73 - 639
    $conn = MySessionHandler::getDBSessionId();
640
 
641
    $modified = mysqli_real_escape_string($conn, time());
642
 
643
    $id = mysqli_real_escape_string($conn, $arr['id']);
644
    $email = mysqli_real_escape_string($conn, $arr['email']);
645
 
646
    $sql = "UPDATE users
647
            SET wlEmailFlag = '0'
648
            WHERE id=$id and email='$email'";
649
 
650
    if (!($result = mysqli_query($conn, $sql))) {
651
        error_log("MySQL Update Wishlist SQL: " . $sql);
652
        error_log("MySQL Update Wishlist Error: " . mysqli_error($conn) . " (" . $error . ")");
653
    }
654
 
127 - 655
    $xh = new Html;
656
    $xh->init($_SESSION["htmlIndent"]);
73 - 657
 
127 - 658
    $xh->add_attribute("class", "container text-center bg-warning p-3 rounded");
659
    $xh->tag('div');
660
    $xh->add_attribute("class", "display-6 font-weight-bold");
661
    $xh->tag('p', "The wishlist price check emails for " . $email . " have been turned off.");
662
    $xh->tag('p', "You can reinstate the emails at any time by setting the option 'Email Price Checks' for your account back to 'Yes'.");
663
    $xh->close(); // div>";
664
 
665
    $html = $xh->flush();
666
    //error_log(print_r($html, 1));
667
 
668
    return $html;
73 - 669
}
78 - 670
 
671
function checkPriceMonitor() {
672
    if (empty($_SESSION['sessData']['userID'])) {
673
        unset($_SESSION['priceMonitor']);
674
        return -1;
675
    }
676
 
677
    $conn = MySessionHandler::getDBSessionId();
678
 
679
    $uid = $_SESSION['sessData']['userID'];
680
 
681
    $sql = "SELECT created, access
682
            FROM pricemonitor
683
            WHERE userId = '$uid'";
684
 
685
    if ($result = mysqli_query($conn, $sql)) {
686
        if (mysqli_num_rows($result) > 0) {
687
            if ($row = mysqli_fetch_assoc($result)) {
688
                $_SESSION['priceMonitor']['created'] = $row['created'];
689
                $_SESSION['priceMonitor']['access'] = $row['access'];
110 - 690
                if ($_SESSION['priceMonitor']['created'] > $_SESSION['priceMonitor']['access']) {
79 - 691
                    $_SESSION['priceMonitor']['newFlag'] = true;
692
                } else {
693
                    $_SESSION['priceMonitor']['newFlag'] = false;
694
                }
78 - 695
 
696
                return 0;
697
            }
698
        }
699
    }
700
    else if (mysqli_errno($conn)) {
701
        error_log("MySQL Read Price Monitor SQL: " . $sql);
702
        error_log("MySQL Read Price Monitor Error: " . mysqli_error($conn) . " (" . mysqli_errno($conn) . ")");
703
    }
704
 
705
    return -1;
706
}
707
 
708
 
709
function getPriceMonitor() {
127 - 710
    $xh = new Html;
711
    $xh->init($_SESSION["htmlIndent"]);
712
 
107 - 713
    if (!isLoggedIn()) {
127 - 714
        $xh->add_attribute("class", "container bg-warning text-center py-3");
715
        $xh->tag('div');
716
            $xh->add_attribute("class", "display-6");
717
            $xh->tag('p');
718
                $xh->add_attribute("class", "material-icons");
719
                $xh->tag('i', "error_outline");
720
                $xh->tag('span', " Please login to your Find Cheap Music account in order to see the price monitor results.");
721
            $xh->close(); // p
722
        $xh->close(); // div
723
 
724
        $html = $xh->flush();
725
       //error_log(print_r($html, 1));
726
 
727
        return $html;
107 - 728
    }
729
 
78 - 730
    $conn = MySessionHandler::getDBSessionId();
731
 
732
    $uid = $_SESSION['sessData']['userID'];
733
 
734
    $sql = "SELECT data
735
            FROM pricemonitor
736
            WHERE userId = '$uid'";
737
 
738
    if ($result = mysqli_query($conn, $sql)) {
739
        if (mysqli_num_rows($result) > 0) {
740
            if ($row = mysqli_fetch_assoc($result)) {
741
                $access = mysqli_real_escape_string($conn, time());
742
                $sql = "UPDATE pricemonitor
743
                        SET access = $access
744
                        WHERE userId = '$uid'";
745
                if (!($result = mysqli_query($conn, $sql))) {
746
                    error_log("MySQL Update Price Monitor SQL: " . $sql);
747
                    error_log("MySQL Update Price Monitor Error: " . mysqli_error($conn) . " (" . $error . ")");
748
                }
749
 
121 - 750
                $html = gzdecode(base64_decode($row['data']));
751
                $html = str_replace(base64_encode("xxxNONCExxx"), base64_encode($_SESSION["nonce"]), $html);
752
                return ($html);
78 - 753
            }
754
        }
755
    }
756
    else if (mysqli_errno($conn)) {
757
        error_log("MySQL Read Price Monitor SQL: " . $sql);
758
        error_log("MySQL Read Price Monitor Error: " . mysqli_error($conn) . " (" . mysqli_errno($conn) . ")");
759
    }
760
 
127 - 761
    $xh->add_attribute("class", "container bg-warning text-center py-3");
762
    $xh->tag('div');
763
        $xh->add_attribute("class", "display-6");
764
        $xh->tag('p');
765
            $xh->add_attribute("class", "material-icons");
766
            $xh->tag('i', "bookmark");
767
            $xh->tag('span', " Your price monitor list is currently empty.");
768
        $xh->close(); // p
769
    $xh->close(); // div
770
 
771
    $html = $xh->flush();
772
   //error_log(print_r($html, 1));
773
 
774
    return $html;
78 - 775
}