Subversion Repositories munaweb

Rev

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

Rev Author Line No. Line
2 - 1
<!DOCTYPE html>
2
<html lang="en">
3
 
4
<head>
5
    <title>Export eBay Listings to Shopify</title>
6
    <meta charset="UTF-8">
7
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
9
    <link rel="icon" href="favicon.ico" type="image/x-icon">
10
 
30 - 11
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
12
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
13
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
14
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
15
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
16
    <script src="js/XMLWriter.js"></script>
17
    <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>
18
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.23.0/moment.min.js"></script>
19
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.23/moment-timezone-with-data-2012-2022.min.js"></script>
2 - 20
    <link rel="stylesheet" href="css/tablesorter.theme.blue.css">
21
    <script src="js/jquery.tablesorter.min.js"></script>
22
    <script src="js/jquery.tablesorter.widgets.js"></script>
23
    <script src="js/jquery.parser-input-select.js"></script>
30 - 24
    <link rel="stylesheet" href="css/style.css">
25
    <script src="js/muna-tools.js"></script>
2 - 26
</head>
27
 
28
<body onload="return initConfig();">
30 - 29
    <div>
30
        <div">
31
            <div class="container-fluid bg-secondary">
32
                <div class="clearfix">
33
                    <img class="img-fluid float-right" src="images/MUNA%20-%20Logo%20100x100.png" alt="MUNA Trading Logo" />
34
                    <h1 id="connected">Export eBay Listings to Shopify
35
                    <input id="login" type="button" class="btn bg-success mb-2 w3-hide" onclick="eBayLogin();" value="Login" /></h1>
36
                </div>
2 - 37
            </div>
38
 
30 - 39
            <div class="col border">
2 - 40
                <div>
30 - 41
                    <form id="searchForm" class="container-fluid bg-light" onsubmit="return getListings();">
42
                        <div id="form1div" class="w3-hide">
43
                            <div class="form-check">
44
                                <label for="completedList">
45
                                    <input id="completedList" class="form-check-input" type="radio" name="rptType" value="completedList" checked>Completed Listings
46
                                </label>
47
                            </div>
48
                            <div class="form-check">
49
                                <label for="liveList">
50
                                    <input id="liveList" class="form-check-input" type="radio" name="rptType" value="liveList" checked>Live Listings
51
                                </label>
52
                            </div>
53
                            <input id="startButton" type="button" class="btn btn-danger" onclick="getListings();" value="Start" />
6 - 54
                        </div>
30 - 55
                        <div id="form2div" class="w3-hide">
56
                            <input id="downloadButton" type="button" class="btn btn-dark" onclick="downloadListings()" value="Download CSV" />
6 - 57
                        </div>
2 - 58
                    </form>
59
                </div>
30 - 60
                <div class="modal" id="progressBarDiv">
61
                    <div class="modal-dialog">
62
                        <div class="modal-content">
63
                            <div class="modal-header">
64
                                <h4 id="progressBarHeader"></h4>
65
                            </div>
66
                            <div class="modal-body">
67
                                <div class="progress">
68
                                    <div id="progressBar" class="progress-bar" style="width:0%">0%</div>
69
                                </div>
70
                            </div>
71
                        </div>
2 - 72
                    </div>
73
                </div>
30 - 74
                <div id="results" class="border bg-info w3-hide"></div>
75
                <div id="csv" class="w3-hide"></div>
76
                <div id="logging"></div>
2 - 77
            </div>
78
        </div>
79
 
30 - 80
        <footer class="container-fluid text-center border border-bottom-0 border-left-0 border-right-0">
17 - 81
            <div w3-include-html="php/footer.php"></div>
2 - 82
        </footer>
83
 
84
    </div>
85
 
86
    <script>
87
 
88
// Globals
89
var tableName = 'exportTable';
90
var tableSorterName = 'selectTable';
91
var liveListing;
92
var maxPagesToProcess = 0;
93
var pagesToProcess = 0;
94
var pagesProcessed = 0;
95
var maxNotesToAdd = 0;
96
var notesToAdd = 0;
97
var notesAdded = 0;
98
var html = [];
99
 
100
// Initialize Configuration Variables
101
function initConfig() {
102
    var x = document.getElementById("form1div");
103
    if (x.className.indexOf("w3-show") == -1) {
104
        x.className += " w3-show";
105
    }
106
 
107
    eBayAuthToken = readCookie();
108
    if (eBayAuthToken.length > 0) {
109
        connected();
110
    }
111
 
112
    if (eBayAuthTokenFlag === false) {
113
        x = document.getElementById("login");
114
        if (x.className.indexOf("w3-show") == -1) {
115
            x.className += " w3-show";
116
        }
117
    }
118
}
119
 
120
function connected() {
121
    var x;
122
 
123
    eBayAuthTokenFlag = true;
124
    document.getElementById("connected").innerHTML += " (Connected)";
125
 
126
    x = document.getElementById("startButton");
30 - 127
    x.className = x.className.replace(" btn-danger", " btn-dark");
2 - 128
 
129
    x = document.getElementById("login");
130
    x.className = x.className.replace(" w3-show", "");
131
 
132
    x = document.getElementById("results");
133
    x.innerHTML = "";
134
    x.className = x.className.replace(" w3-show", "");
135
    x.className = x.className.replace(" process-errors", "");
136
}
137
 
138
function requireNewLogin() {
139
    var x = document.getElementById("startButton");
30 - 140
    x.className = x.className.replace(" btn-dark", " btn-danger ");
2 - 141
}
142
 
143
function downloadListings() {
144
    var noteList = [];
145
    var table = document.getElementById(tableSorterName);
146
 
147
    maxPagesToProcess = 0;
148
    pagesToProcess = 0;
149
    pagesProcessed = 0;
150
 
151
    initProgressBar("Downloading Selected Items");
152
 
153
    var x = document.getElementById("results");
154
    x.innerHTML = '';
155
    x.className = x.className.replace("process-errors", "");
156
    if (x.className.indexOf("w3-show") == -1) {
157
        x.className += " w3-show";
158
    }
159
    x.innerHTML = '<p><strong>Downloading Listings...</strong></p>';
160
 
161
    document.getElementById("csv").innerHTML = '';
162
 
163
    tableStart();
164
    for (var i = 2; i < table.rows.length; i++) {
165
        if (table.rows[i].cells[0].children[0].checked) {
166
            ++maxPagesToProcess;
167
            ++pagesToProcess;
168
            noteList.push(table.rows[i].cells[3].innerHTML);
169
            eBaySearch(table.rows[i].cells[3].innerHTML);
170
 
171
            table.deleteRow(i--);
172
        }
173
    }
174
 
175
    function checkpagesToProcess() {
176
        if (pagesToProcess > 0) {
177
            window.setTimeout(checkpagesToProcess, 100); // wait 100 milliseconds
178
        } else {
179
            tableEnd();
7 - 180
            tableSorterUpdateCounters(tableSorterName);
2 - 181
            endProgressBar();
182
            exportTableToCSV(tableName, 'import.csv');
183
            addNotes(noteList);
184
        }
185
    }
186
 
187
    checkpagesToProcess();
188
}
189
 
190
function addNotes(noteList) {
191
    var i, x;
192
 
193
    maxNotesToAdd = 0;
194
    notesToAdd = 0;
195
    notesAdded = 0;
196
 
197
    if (!liveListing) {
198
        initProgressBar('Adding Notes to Ended Listings');
199
 
200
        for (i = 0; i < noteList.length; i++) {
201
            ++maxNotesToAdd;
202
            ++notesToAdd;
203
            addNote(noteList[i]);
204
        }
205
    }
206
 
207
    function checkNotesToAdd() {
208
        if (notesToAdd > 0) {
209
            window.setTimeout(checkNotesToAdd, 100); // wait 100 milliseconds
210
        } else {
211
            endProgressBar();
212
 
213
            x = document.getElementById("results");
214
            x.innerHTML += '<p><strong>Report Finished!</strong></p>';
215
            if (!x.className.includes("process-errors")) {
216
                setTimeout(function() {
217
                    x.className = x.className.replace(" w3-show", "");
218
                }, 3000);
219
            }
220
        }
221
    }
222
 
223
    checkNotesToAdd();
224
}
225
 
226
function tableStart() {
227
    document.getElementById("csv").innerHTML = '';
228
    html = [];
229
 
230
    html.push('<h3>Shopify Import</h3>');
30 - 231
    html.push('<div class="border table-responsive">');
2 - 232
    html.push('<table id="' + tableName + '">');
233
    html.push('<thead>');
234
    html.push('<tr>');
235
 
236
    html.push(tableHeader('Handle'));
237
    html.push(tableHeader('Title'));
238
    html.push(tableHeader('Body (HTML)'));
239
    html.push(tableHeader('Vendor'));
240
    html.push(tableHeader('Type'));
241
    html.push(tableHeader('Tags'));
242
    html.push(tableHeader('Published'));
25 - 243
    html.push(tableHeader('Option1 Name'));
244
    html.push(tableHeader('Option1 Value'));
245
    html.push(tableHeader('Option2 Name'));
246
    html.push(tableHeader('Option2 Value'));
247
    html.push(tableHeader('Option3 Name'));
248
    html.push(tableHeader('Option3 Value'));
2 - 249
    html.push(tableHeader('Variant SKU'));
25 - 250
    html.push(tableHeader('Variant Grams'));
2 - 251
    html.push(tableHeader('Variant Inventory Tracker'));
25 - 252
    html.push(tableHeader('Variant Inventory Qty'));
2 - 253
    html.push(tableHeader('Variant Inventory Policy'));
254
    html.push(tableHeader('Variant Fulfillment Service'));
255
    html.push(tableHeader('Variant Price'));
25 - 256
    html.push(tableHeader('Variant Compare At Price'));
2 - 257
    html.push(tableHeader('Variant Requires Shipping'));
258
    html.push(tableHeader('Variant Taxable'));
259
    html.push(tableHeader('Variant Barcode'));
260
    html.push(tableHeader('Image Src'));
261
    html.push(tableHeader('Image Position'));
262
    html.push(tableHeader('Image Alt Text'));
25 - 263
    html.push(tableHeader('Gift Card'));
264
    html.push(tableHeader('Google Shopping / MPN'));
265
    html.push(tableHeader('Google Shopping / Age Group'));
266
    html.push(tableHeader('Google Shopping / Gender'));
267
    html.push(tableHeader('Google Shopping / Google Product Category'));
268
    html.push(tableHeader('SEO Title'));
269
    html.push(tableHeader('SEO Description'));
270
    html.push(tableHeader('Google Shopping / AdWords Grouping'));
271
    html.push(tableHeader('Google Shopping / AdWords Labels'));
272
    html.push(tableHeader('Google Shopping / Condition'));
273
    html.push(tableHeader('Google Shopping / Custom Product'));
274
    html.push(tableHeader('Google Shopping / Custom Label 0'));
275
    html.push(tableHeader('Google Shopping / Custom Label 1'));
276
    html.push(tableHeader('Google Shopping / Custom Label 2'));
277
    html.push(tableHeader('Google Shopping / Custom Label 3'));
278
    html.push(tableHeader('Google Shopping / Custom Label 4'));
279
    html.push(tableHeader('Variant Image'));
2 - 280
    html.push(tableHeader('Variant Weight Unit'));
25 - 281
    html.push(tableHeader('Variant Tax Code'));
282
    html.push(tableHeader('Cost per item'));
2 - 283
 
284
    html.push('</tr>');
285
    html.push('</thead>');
286
    html.push('<tbody>');
287
}
288
 
289
function tableEntry(JsonObj) {
290
    var i, n, barcode, handle;
291
    var tags = [];
292
    var ConditionDescription = JsonObj.ConditionDescription;
293
    var ConditionID = JsonObj.ConditionID;
294
    var CurrentPrice = JsonObj.SellingStatus.CurrentPrice;
295
    var CurrentPriceValue = CurrentPrice === undefined ? 0.00 : Number(CurrentPrice.text);
296
    var price = CurrentPriceValue;
297
    var Description = JsonObj.Description;
298
    var userDescription;
299
    var ItemID = JsonObj.ItemID;
300
    var ItemSpecifics = JsonObj.ItemSpecifics;
6 - 301
    var PictureURL = getJsonArray(JsonObj.PictureDetails.PictureURL);
2 - 302
    var PrimaryCategoryName = JsonObj.PrimaryCategory.CategoryName;
16 - 303
    var Quantity = Number(JsonObj.Quantity);
304
    var QuantitySold = Number(JsonObj.SellingStatus.QuantitySold);
2 - 305
    var SKU = JsonObj.SKU;
306
    var ProductListingDetails = JsonObj.ProductListingDetails;
307
    var weightInGrams = 0;
308
    var categoryName = PrimaryCategoryName;
309
 
310
    var Title = JsonObj.Title;
311
 
312
    if (Number(ConditionID) === 1000) {
313
        tags.push("Condition: Brand New");
314
    } else {
315
        tags.push("Condition: Preowned");
316
    }
317
 
318
    n = (SKU === undefined ? 0 : SKU.indexOf(" - "));
319
    if (n > 0) {
320
        barcode = SKU.substr(n + 3);
321
        barcode = barcode.substr(barcode.indexOf(" ") + 1);
322
        handle = 'B' + barcode;
323
        barcode = '\'' + barcode;
324
        SKU = SKU.substr(0, n);
325
    } else {
326
        if (categoryName.indexOf("Books") != -1 && ProductListingDetails && ProductListingDetails.ISBN && isNumeric(ProductListingDetails.ISBN)) {
327
            barcode = '\'' + ProductListingDetails.ISBN;
328
            handle = 'B' + ProductListingDetails.ISBN;
329
        } else if (ProductListingDetails && ProductListingDetails.UPC && isNumeric(ProductListingDetails.UPC)) {
330
            barcode = '\'' + ProductListingDetails.UPC;
331
            handle = 'B' + ProductListingDetails.UPC;
332
        } else if (ProductListingDetails && ProductListingDetails.ProductReferenceID && isNumeric(ProductListingDetails.ProductReferenceID)) {
333
            barcode = 'R' + ProductListingDetails.ProductReferenceID;
334
            handle = barcode;
335
        } else {
336
            barcode = 'H' + Title.hashCode();
337
            handle = barcode;
338
        }
339
    }
340
 
341
    userDescription = extractDescription(Description);
16 - 342
    if (ItemSpecifics && ItemSpecifics.NameValueList && PrimaryCategoryName.indexOf('DVD') < 0) {
343
        userDescription += '<table><tbody>';
344
        for (i = 0; i < ItemSpecifics.NameValueList.length; i++) {
345
            var itemSpecific = ItemSpecifics.NameValueList[i];
346
            if (itemSpecific.Name != 'All returns accepted' &&
347
                itemSpecific.Name != 'Item must be returned within' &&
348
                itemSpecific.Name != 'Refund will be given as' &&
349
                itemSpecific.Name != 'Return policy details' &&
350
                itemSpecific.Name != 'Restocking Fee' &&
351
                itemSpecific.Name != 'Return shipping will be paid by') {
352
                userDescription += '<tr><td style="padding: 0;">' + itemSpecific.Name + ':</td><td style="padding: 0;">' + itemSpecific.Value + '</td></tr>';
2 - 353
            }
354
        }
16 - 355
        userDescription += '</tbody></table>';
2 - 356
    }
357
 
358
    if (ConditionDescription &&
359
        (userDescription.indexOf('Please view all actual images.') < 0 && userDescription.indexOf('mint condition') < 0)) {
360
        userDescription += '<p>' + ConditionDescription + '</p>';
361
    }
362
 
363
    if (categoryName.indexOf("CDs") != -1) {
364
        categoryName = 'Music CDs';
365
        price = 4.95;
366
    } else if (categoryName.indexOf("Movies") != -1) {
367
        categoryName = 'Movies';
368
        price = 4.95;
369
    } else if (categoryName.indexOf("Books") != -1) {
370
        categoryName = 'Books';
371
        price = 5.95;
372
    } else if (categoryName.indexOf("Trading Cards") != -1) {
373
        if (categoryName.indexOf("Baseball") != -1) {
374
            tags.push('Trading Cards: Baseball');
375
        } else if (categoryName.indexOf("Football") != -1) {
376
            tags.push('Trading Cards: Football');
377
        } else if (categoryName.indexOf("Basketball") != -1) {
378
            tags.push('Trading Cards: Basketball');
379
        } else if (categoryName.indexOf("Soccer") != -1) {
380
            tags.push('Trading Cards: Soccer');
381
        } else if (categoryName.indexOf("Ice Hockey") != -1) {
382
            tags.push('Trading Cards: Ice Hockey');
383
        } else if (categoryName.indexOf("Auto Racing") != -1) {
384
            tags.push('Trading Cards: Auto Racing');
385
        }
386
        categoryName = 'Trading Cards';
387
        price = 1.99;
388
    }
389
    tags.push(categoryName);
390
 
391
    if (liveListing) {
392
        tags.push('_eBay Live');
393
 
394
        price = round((CurrentPriceValue * 0.80), 1) + 0.05; // always end with 5
395
        if (categoryName.indexOf("CDs") != -1 && price < 4.95) {
396
            price = 4.95;
397
        } else if (categoryName.indexOf("Movies") != -1 && price < 4.95) {
398
            price = 4.95;
399
        } else if (categoryName.indexOf("Books") != -1 && price < 5.95) {
400
            price = 5.95;
401
        } else if (categoryName.indexOf("Trading Cards") != -1 && price < 1.99) {
402
            price = 1.99;
403
        }
404
    }
405
 
406
    if (JsonObj.ShippingPackageDetails !== undefined) {
407
        if (JsonObj.ShippingPackageDetails.WeightMajor !== undefined) {
408
            weightInGrams += (Number(JsonObj.ShippingPackageDetails.WeightMajor.text) * 453.5);
409
        }
410
 
411
        if (JsonObj.ShippingPackageDetails.WeightMinor !== undefined) {
412
            weightInGrams += (Number(JsonObj.ShippingPackageDetails.WeightMinor.text) * 28.3);
413
        }
414
    }
415
 
416
    html.push('<tr>');
417
 
418
    html.push(tableCell(handle));
419
    html.push(tableCell(Title));
420
    html.push(tableCell(escapeHtml(userDescription)));
421
    html.push(tableCell("MUNA Trading"));
422
    html.push(tableCell(categoryName));
423
    html.push(tableCell(tags.join(',')));
424
    html.push(tableCell("TRUE"));
28 - 425
    html.push(tableCell("Title"));
426
    html.push(tableCell("Default Title"));
25 - 427
    html.push(tableCell(""));
428
    html.push(tableCell(""));
429
    html.push(tableCell(""));
430
    html.push(tableCell(""));
2 - 431
    html.push(tableCell((SKU !== undefined ? SKU : "")));
25 - 432
    html.push(tableCell(Math.floor(weightInGrams)));
2 - 433
    html.push(tableCell("shopify"));
16 - 434
    html.push(tableCell((Quantity - QuantitySold)));
2 - 435
    html.push(tableCell("deny"));
436
    html.push(tableCell("manual"));
437
    html.push(tableCell(price));
25 - 438
    html.push(tableCell(""));
2 - 439
    html.push(tableCell("TRUE"));
440
    html.push(tableCell("TRUE"));
441
    html.push(tableCell(barcode));
6 - 442
    html.push(tableCell(PictureURL[0].substr(0, PictureURL[0].lastIndexOf('/') + 1) + '$_57.JPG'));
2 - 443
    html.push(tableCell(1));
444
    html.push(tableCell(Title + " Image 1"));
25 - 445
    html.push(tableCell("FALSE"));
446
    html.push(tableCell(""));
447
    html.push(tableCell(""));
448
    html.push(tableCell(""));
449
    html.push(tableCell(""));
450
    html.push(tableCell(""));
451
    html.push(tableCell(""));
452
    html.push(tableCell(""));
453
    html.push(tableCell(""));
454
    html.push(tableCell(""));
455
    html.push(tableCell(""));
456
    html.push(tableCell(""));
457
    html.push(tableCell(""));
458
    html.push(tableCell(""));
459
    html.push(tableCell(""));
460
    html.push(tableCell(""));
461
    html.push(tableCell(""));
2 - 462
    html.push(tableCell("oz"));
25 - 463
    html.push(tableCell(""));
464
    html.push(tableCell(""));
2 - 465
 
466
    html.push('</tr>');
467
 
6 - 468
    for (i = 1; i < PictureURL.length; i++) {
469
        html.push('<tr>');
2 - 470
 
6 - 471
        html.push(tableCell(handle));
472
        html.push(tableCell(""));
473
        html.push(tableCell(""));
474
        html.push(tableCell(""));
475
        html.push(tableCell(""));
476
        html.push(tableCell(""));
477
        html.push(tableCell(""));
478
        html.push(tableCell(""));
479
        html.push(tableCell(""));
480
        html.push(tableCell(""));
481
        html.push(tableCell(""));
482
        html.push(tableCell(""));
483
        html.push(tableCell(""));
484
        html.push(tableCell(""));
485
        html.push(tableCell(""));
486
        html.push(tableCell(""));
25 - 487
        html.push(tableCell(""));
488
        html.push(tableCell(""));
489
        html.push(tableCell(""));
490
        html.push(tableCell(""));
491
        html.push(tableCell(""));
492
        html.push(tableCell(""));
493
        html.push(tableCell(""));
494
        html.push(tableCell(""));
6 - 495
        html.push(tableCell(PictureURL[i].substr(0, PictureURL[i].lastIndexOf('/') + 1) + '$_57.JPG'));
496
        html.push(tableCell(i + 1));
497
        html.push(tableCell(Title + " Image " + (i + 1)));
498
        html.push(tableCell(""));
499
        html.push(tableCell(""));
25 - 500
        html.push(tableCell(""));
501
        html.push(tableCell(""));
502
        html.push(tableCell(""));
503
        html.push(tableCell(""));
504
        html.push(tableCell(""));
505
        html.push(tableCell(""));
506
        html.push(tableCell(""));
507
        html.push(tableCell(""));
508
        html.push(tableCell(""));
509
        html.push(tableCell(""));
510
        html.push(tableCell(""));
511
        html.push(tableCell(""));
512
        html.push(tableCell(""));
513
        html.push(tableCell(""));
514
        html.push(tableCell(""));
515
        html.push(tableCell(""));
516
        html.push(tableCell(""));
517
        html.push(tableCell(""));
2 - 518
 
6 - 519
        html.push('</tr>');
2 - 520
    }
521
}
522
 
523
function extractDescription(str) {
524
    var startText = "<!-- *************** Place description here ****************** -->";
525
    var startPos = str.indexOf(startText) + startText.length;
526
    var endPos = str.lastIndexOf("<!-- *************** Place description here ****************** -->");
527
    var userDescription = str.substr(startPos, endPos - startPos);
528
    var parser = new DOMParser();
529
    var htmlDoc = parser.parseFromString(userDescription, "text/html");
530
 
531
    return ((htmlDoc.getElementsByTagName('div')[0] !== undefined ? htmlDoc.getElementsByTagName('div')[0].innerHTML : userDescription));
532
}
533
 
534
function tableEnd() {
535
    html.push('</tbody>');
536
    html.push('</table>');
537
    html.push('</div>');
538
 
539
    document.getElementById("csv").innerHTML = html.join('');
540
}
541
 
542
function addNote(itemId) {
543
    var i;
544
    var xml;
545
 
546
    var xw = new XMLWriter('UTF-8', '1.0');
547
    var xhr = new XMLHttpRequest();
548
 
549
    if (!createAddXMLNote(xw, xhr, 'SetUserNotesRequest', 'SetUserNotes', itemId)) {
550
        return;
551
    }
552
 
553
    xml = xw.flush();
554
    xw.close();
555
 
556
    xhr.onload = function() {
16 - 557
        var jsonObj = XMLparse(xhr.responseXML, false);
558
        var obj = jsonObj.SetUserNotesResponse;
2 - 559
        var returnCode = obj.Ack;
19 - 560
        var str;
2 - 561
 
562
        var x = document.getElementById("results");
563
        if (x.className.indexOf("w3-show") == -1) {
564
            x.className += " w3-show";
565
        }
566
 
567
        if (returnCode == 'Success' || (returnCode == 'Warning' && obj.Errors.ErrorCode == '21917108')) {
19 - 568
            str = '<p>' + itemId + ': <strong>' + returnCode + '</strong></p>';
2 - 569
 
570
            if (returnCode == 'Warning') {
19 - 571
                str += "<p>" + obj.Errors.SeverityCode + " (" + obj.Errors.ErrorCode + "): " + escapeHtml(obj.Errors.LongMessage) + "</p>";
2 - 572
            }
19 - 573
 
574
            x.innerHTML += str;
2 - 575
        } else {
576
            x.className += " process-errors";
30 - 577
            str = '<p class="text-danger">' + itemId + ': <strong>' + returnCode + ':</strong></p>';
2 - 578
 
6 - 579
            var errors = getJsonArray(obj.Errors);
19 - 580
            str += "<p>";
6 - 581
            for (i = 0; i < errors.length; i++) {
19 - 582
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
2 - 583
            }
19 - 584
            str += "</p>";
585
 
586
            x.innerHTML += str;
2 - 587
        }
588
 
589
        if (obj.Message) {
590
            x.innerHTML += obj.Message;
591
        }
592
 
593
        --notesToAdd;
594
        ++notesAdded;
595
 
596
        updateProgressBar(maxNotesToAdd, notesAdded);
597
    };
598
 
599
    xhr.send(xml);
600
}
601
 
602
function createAddXMLNote(xw, xhr, xmlrequest, callname, itemId) {
603
    var today = new Date();
604
    var todayYYYYMMDD = today.toISOString().slice(0, 10);
605
 
606
    xw.writeStartDocument();
607
    xw.writeStartElement(xmlrequest);
608
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
609
 
610
    xw.writeStartElement('RequesterCredentials');
611
    xw.writeElementString('eBayAuthToken', eBayAuthToken);
612
    xw.writeEndElement(); /* RequesterCredentials */
613
 
614
    xw.writeElementString('ItemID', itemId);
615
    xw.writeElementString('Action', 'AddOrUpdate');
616
    xw.writeElementString('NoteText', 'Exported to Shopify on ' + todayYYYYMMDD);
617
 
618
    xw.writeElementString('ErrorLanguage', 'en_US');
619
    xw.writeElementString('Version', configeBayTradingVersion);
620
    xw.writeElementString('WarningLevel', configWarningLevel);
621
 
622
    xw.writeEndElement(); /* xmlrequest */
623
    xw.writeEndDocument();
624
 
625
    xhr.open('POST', configProxyUrl, true);
626
    xhr.setRequestHeader('Content-Type', 'text/xml');
627
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
628
    xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
629
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
630
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
631
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
632
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
633
    xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
634
 
635
    return true;
636
}
637
 
638
function eBaySearch(itemId) {
639
    var i;
640
    var xml;
641
 
642
    var xw = new XMLWriter('UTF-8', '1.0');
643
    var xhr = new XMLHttpRequest();
644
 
645
    if (!createAddXMLSearch(xw, xhr, 'GetItemRequest', 'GetItem', itemId)) {
646
        return;
647
    }
648
 
649
    xml = xw.flush();
650
    xw.close();
651
 
652
    xhr.onload = function() {
16 - 653
        var jsonObj = XMLparse(xhr.responseXML, false);
654
        var obj = jsonObj.GetItemResponse;
2 - 655
        var returnCode = obj.Ack;
19 - 656
        var str;
2 - 657
 
658
        var x = document.getElementById("results");
659
        if (x.className.indexOf("w3-show") == -1) {
660
            x.className += " w3-show";
661
        }
662
 
663
        if (returnCode == 'Success') {
664
            tableEntry(obj.Item);
665
        } else {
666
            x.className += " process-errors";
30 - 667
            str = '<p class="text-danger">' + itemId + ': <strong>' + returnCode + ':</strong></p>';
2 - 668
 
6 - 669
            var errors = getJsonArray(obj.Errors);
19 - 670
            str += "<p>";
6 - 671
            for (i = 0; i < errors.length; i++) {
19 - 672
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
2 - 673
            }
19 - 674
            str += "</p>";
6 - 675
 
19 - 676
            x.innerHTML += str;
2 - 677
        }
678
 
679
        --pagesToProcess;
680
        ++pagesProcessed;
681
 
682
        updateProgressBar(maxPagesToProcess, pagesProcessed);
683
    };
684
 
685
    xhr.send(xml);
686
}
687
 
688
function createAddXMLSearch(xw, xhr, xmlrequest, callname, itemId) {
689
 
690
    xw.writeStartDocument();
691
    xw.writeStartElement(xmlrequest);
692
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
693
 
694
    xw.writeStartElement('RequesterCredentials');
695
    xw.writeElementString('eBayAuthToken', eBayAuthToken);
696
    xw.writeEndElement(); /* RequesterCredentials */
697
 
698
    xw.writeElementString('ItemID', itemId);
699
    xw.writeElementString('IncludeItemSpecifics', 'true');
700
    xw.writeElementString('DetailLevel', 'ReturnAll');
701
 
702
    xw.writeElementString('ErrorLanguage', 'en_US');
703
    xw.writeElementString('Version', configeBayTradingVersion);
704
    xw.writeElementString('WarningLevel', configWarningLevel);
705
 
706
    xw.writeEndElement(); /* xmlrequest */
707
    xw.writeEndDocument();
708
 
709
    xhr.open('POST', configProxyUrl, true);
710
    xhr.setRequestHeader('Content-Type', 'text/xml');
711
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
712
    xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
713
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
714
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
715
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
716
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
717
    xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
718
 
719
    return true;
720
}
721
 
722
function getListings() {
723
    var x;
724
 
725
    if (eBayAuthTokenFlag === false) {
726
        return;
727
    }
728
 
729
    document.getElementById("logging").innerHTML = '';
730
 
731
    x = document.getElementById("results");
732
    if (x.className.indexOf("w3-show") == -1) {
733
        x.className += " w3-show";
734
    }
735
    x.className = x.className.replace("process-errors", "");
736
    x.innerHTML = '<p><strong>Retrieving Listings...</strong></p>';
737
 
738
    initProgressBar('Getting Items for Export (1/2)');
739
 
740
    liveListing = (getRadioValue('rptType') == 'liveList');
741
    tableSorterStart();
742
    maxPagesToProcess = 1;
743
    pagesToProcess = 1;
744
    pagesProcessed = 0;
745
    eBaySorterSearch(1);
746
 
747
    function checkpagesToProcess() {
748
        if (pagesToProcess > 0) {
749
            window.setTimeout(checkpagesToProcess, 100); // wait 100 milliseconds
750
        } else {
751
            tableSorterEnd();
752
            endProgressBar();
753
            // fillSorterListings(); is now in tableSorterEnd()
754
        }
755
    }
756
 
757
    checkpagesToProcess();
758
}
759
 
760
function tableSorterStart() {
761
    document.getElementById("logging").innerHTML = '';
762
    html = [];
763
 
764
    html.push('<h3>Items for Export</h3>');
765
    html.push('<p>Showing <span id="filtered-rows">0</span> of <span id="total-rows">0</span> / <span id="selected-rows">0</span> selected.</p>');
30 - 766
    html.push('<div class="border table-responsive">');
2 - 767
    html.push('<table id="' + tableSorterName + '" class="tablesorter">');
768
    html.push('<thead>');
769
    html.push('<tr>');
770
 
6 - 771
    html.push(tableHeaderCheckbox());
2 - 772
    html.push(tableHeader('Image'));
773
    html.push(tableHeader('Title'));
774
    html.push(tableHeader('Item Id'));
775
    html.push(tableHeader('SKU'));
776
    html.push(tableHeader('Category'));
777
    html.push(tableHeader('Format'));
778
    html.push(tableHeader('Price'));
779
    html.push(tableHeader('Quantity'));
780
    html.push(tableHeader('Views'));
781
    html.push(tableHeader('Watchers'));
782
    html.push(tableHeader(liveListing ? 'Start Date' : 'End Date'));
783
    html.push(tableHeader('Note'));
784
 
785
    html.push('</tr>');
786
    html.push('</thead>');
787
    html.push('<tbody>');
788
}
789
 
790
function tableSorterEntry(JsonObj) {
791
    var i;
792
    var image;
793
    var title;
794
    var itemId;
795
    var sku;
796
    var format;
797
    var price;
798
    var quantity;
799
    var views;
800
    var watchers;
801
    var listingDate;
802
    var privateNote;
803
    var ebayNote;
804
    var relisted;
16 - 805
    var bidCount;
2 - 806
 
807
    for (i = 0; i < JsonObj.length; i++) {
16 - 808
        image = getJsonValue(JsonObj[i].PictureDetails.GalleryURL).replace('http:', 'https:');
2 - 809
        title = getJsonValue(JsonObj[i].Title);
810
        itemId = getJsonValue(JsonObj[i].ItemID);
811
        sku = getJsonValue(JsonObj[i].SKU);
812
        format = getJsonValue(JsonObj[i].ListingType);
16 - 813
        bidCount = (typeof(JsonObj[i].SellingStatus) === 'object' ? Number(getJsonValue(JsonObj[i].SellingStatus.BidCount)) : 0);
2 - 814
        if (format == 'Chinese') {
815
            format = 'Auction';
816
            price = getJsonValue(JsonObj[i].StartPrice.text);
817
        } else {
818
            format = 'Fixed Price';
819
            price = getJsonValue(JsonObj[i].BuyItNowPrice.text);
820
        }
821
        quantity = getJsonValue(JsonObj[i].QuantityAvailable);
822
        views = '';
16 - 823
        watchers = Number(getJsonValue(JsonObj[i].WatchCount));
824
        listingDate = getJsonValue((liveListing ? JsonObj[i].ListingDetails.StartTime : JsonObj[i].ListingDetails.EndTime)).substr(0, 10);
2 - 825
        privateNote = getJsonValue(JsonObj[i].PrivateNotes);
826
        ebayNote = getJsonValue(JsonObj[i].eBayNotes);
827
        relisted = getJsonValue(JsonObj[i].Relisted);
828
 
829
        if (!liveListing) {
830
            if (privateNote.startsWith("Exported to ") || relisted == 'true' || privateNote.startsWith("Sold via ") || privateNote.startsWith("Relisted As New Item")) {
831
                continue;
832
            }
16 - 833
        } else {
834
            if (bidCount > 0) {
835
                continue;
836
            }
2 - 837
        }
838
 
16 - 839
 
840
 
2 - 841
        html.push('<tr>');
842
 
843
        html.push(tableCellCheckbox());
30 - 844
        html.push(tableCell('<img class="img-fluid" src="' + image + '" alt="Gallery Image" style="max-height:100px;max-width:100px;">'));
2 - 845
        html.push(tableCell(title));
846
        html.push(tableCell(itemId));
847
        html.push(tableCell(sku));
848
        html.push(tableCellLabel('Category' + itemId));
849
        html.push(tableCell(format));
850
        html.push(tableCell('$' + price));
851
        html.push(tableCell(quantity));
852
        html.push(tableCellLabel('Views' + itemId));
853
        html.push(tableCell(watchers));
854
        html.push(tableCell(listingDate));
855
        html.push(tableCell(privateNote + ' ' + ebayNote));
856
 
857
        html.push('</tr>');
858
    }
859
}
860
 
861
function tableSorterEnd() {
862
    html.push('</tbody>');
863
    html.push('</table>');
864
    html.push('</div>');
865
 
866
    document.getElementById("logging").innerHTML = html.join('');
867
 
868
    $(function() {
869
        $("#" + tableSorterName).on('tablesorter-initialized', function() {
870
 
871
            // class name to add on tr when checkbox is checked
872
            var highlightClass = 'checked',
873
                // resort the table after the checkbox is modified?
874
                resort = true,
875
                $table = $(this),
876
                c = this.config,
877
                wo = c && c.widgetOptions,
878
                // include sticky header checkbox; if installed
879
                $sticky = c && wo.$sticky || '',
880
                doChecky = function(c, col) {
881
                    $table
882
                        .children('tbody')
883
                        .children('tr:visible')
884
                        .children('td:nth-child( ' + (parseInt(col, 10) + 1) + ' )')
885
                        .find('input[type=checkbox]')
886
                        .each(function() {
887
                            this.checked = c;
888
                            $(this).trigger('change');
889
                        });
890
                };
891
 
892
            $table
893
                .children('tbody')
894
                .on('change', 'input[type=checkbox]', function() {
895
                    // ignore change if updating all rows
896
                    if ($table[0].ignoreChange) {
897
                        return;
898
                    }
899
                    var $this = $(this);
900
                    $this.closest('tr').toggleClass(highlightClass, this.checked);
19 - 901
                    // resort will jump bqack to the top
902
                    // $this.trigger('updateCell', [$this.closest('td'), resort]);
2 - 903
 
904
                    // handle header
7 - 905
                    var rowCount = $('#' + tableSorterName + ' tbody tr').length;
2 - 906
                    var checkedCount = $('#' + tableSorterName + ' tbody .checked').length;
907
                    var ua = window.navigator.userAgent;
908
                    if (checkedCount === 0) {
909
                        $table.add($sticky).find('thead input[type=checkbox]').prop('checked', false);
910
                        $table.add($sticky).find('thead input[type=checkbox]').prop('indeterminate', false);
911
                    } else if (checkedCount === rowCount) {
912
                        $table.add($sticky).find('thead input[type=checkbox]').prop('checked', true);
913
                        $table.add($sticky).find('thead input[type=checkbox]').prop('indeterminate', false);
914
                    } else {
915
                        $table.add($sticky).find('thead input[type=checkbox]').prop('checked', !(ua.indexOf('Trident/') > -1 || ua.indexOf('Edge/') > -1));
916
                        $table.add($sticky).find('thead input[type=checkbox]').prop('indeterminate', true);
917
                    }
918
                    $('#selected-rows').html(checkedCount);
919
                })
920
                .end()
921
                .add($sticky)
922
                .find('thead input[type=checkbox]')
923
                // Click on checkbox in table header to toggle all inputs
924
                .on('change', function() {
925
                    // prevent updateCell for every cell
926
                    $table[0].ignoreChange = true;
927
                    var c = this.checked,
928
                        col = $(this).closest('th').attr('data-column');
929
                    doChecky(c, col);
930
                    // update main & sticky header
931
 
932
                    $table.children('tbody').children('tr:visible').toggleClass(highlightClass, c);
933
                    // update all at once
934
                    $table[0].ignoreChange = false;
935
                    $table.trigger('update', [resort]);
936
 
937
                    // handle header
7 - 938
                    var rowCount = $('#' + tableSorterName + ' tbody tr').length;
2 - 939
                    var checkedCount = $('#' + tableSorterName + ' tbody .checked').length;
940
                    var ua = window.navigator.userAgent;
941
                    if (checkedCount === 0) {
942
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('checked', false);
943
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('indeterminate', false);
944
                    } else if (checkedCount === rowCount) {
945
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('checked', true);
946
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('indeterminate', false);
947
                    } else {
948
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('checked', !(ua.indexOf('Trident/') > -1 || ua.indexOf('Edge/') > -1));
949
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('indeterminate', true);
950
                    }
951
                    $('#selected-rows').html(checkedCount);
952
                })
953
                .on('mouseup', function() {
954
                    return false;
955
                });
956
 
957
        });
958
 
959
        $("#" + tableSorterName).tablesorter({
960
            theme: "blue",
961
            widgets: ["zebra", "stickyHeaders", "filter"],
962
            headers: {
963
                0: {
964
                    sorter: "checkbox"
965
                },
966
                1: {
967
                    sorter: false,
968
                    filter: false
969
                }
970
            },
971
            initialized: function() {
972
                fillSorterListings();
973
            }
974
        });
975
 
976
        $("#" + tableSorterName).bind('filterInit filterEnd', function(event, data) {
977
            $('#filtered-rows').html(data.filteredRows);
978
            $('#total-rows').html(data.totalRows);
979
        });
980
    });
981
}
982
 
983
function eBaySorterSearch(pageNo) {
984
    var i;
985
    var xml;
986
 
987
    var xw = new XMLWriter('UTF-8', '1.0');
988
    var xhr = new XMLHttpRequest();
989
 
990
    if (!createSorterAddXMLSearch(xw, xhr, 'GetMyeBaySelling', pageNo)) {
991
        return;
992
    }
993
 
994
    xml = xw.flush();
995
    xw.close();
996
 
997
    xhr.onload = function() {
16 - 998
        var jsonObj = XMLparse(xhr.responseXML, false);
999
        var obj = jsonObj.GetMyeBaySellingResponse;
2 - 1000
        var returnCode = obj.Ack;
19 - 1001
        var str;
2 - 1002
 
1003
        var objArray = (liveListing ? obj.ActiveList : obj.UnsoldList);
1004
 
1005
        var x = document.getElementById("results");
1006
 
1007
        if (returnCode == 'Success') {
16 - 1008
            tableSorterEntry(objArray.ItemArray.Item);
2 - 1009
 
1010
            if (Number(objArray.PaginationResult.TotalNumberOfPages) > pageNo) {
1011
                maxPagesToProcess = Number(objArray.PaginationResult.TotalNumberOfPages);
1012
                ++pagesToProcess;
1013
                eBaySorterSearch(pageNo + 1);
1014
            }
1015
 
1016
            updateProgressBar(maxPagesToProcess, pagesProcessed);
1017
        } else {
1018
            x.className += " process-errors";
30 - 1019
            str = '<p class="text-danger">' + obj.CorrelationID + ': <strong>' + returnCode + ':</strong></p>';
6 - 1020
            var errors = getJsonArray(obj.Errors);
19 - 1021
            str += "<p>";
6 - 1022
            for (i = 0; i < errors.length; i++) {
19 - 1023
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
2 - 1024
            }
19 - 1025
            str += "</p>";
6 - 1026
 
19 - 1027
            x.innerHTML += str;
2 - 1028
        }
1029
 
1030
        --pagesToProcess;
1031
        ++pagesProcessed;
1032
 
1033
        updateProgressBar(maxPagesToProcess, pagesProcessed);
1034
    };
1035
 
1036
    xhr.send(xml);
1037
}
1038
 
1039
function createSorterAddXMLSearch(xw, xhr, callname, pageNo) {
14 - 1040
    var outputSelector;
1041
 
2 - 1042
    xw.writeStartDocument();
1043
    xw.writeStartElement(callname + "Request");
1044
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
1045
 
1046
    xw.writeStartElement('RequesterCredentials');
1047
    xw.writeElementString('eBayAuthToken', eBayAuthToken);
1048
    xw.writeEndElement(); /* RequesterCredentials */
1049
 
1050
    xw.writeElementString('DetailLevel', 'ReturnAll');
1051
    xw.writeStartElement('DeletedFromSoldList');
1052
    xw.writeElementString('Include', 'false');
1053
    xw.writeEndElement(); /* DeletedFromSoldList */
1054
    xw.writeStartElement('DeletedFromUnsoldList');
1055
    xw.writeElementString('Include', 'false');
1056
    xw.writeEndElement(); /* DeletedFromUnsoldList */
1057
    xw.writeStartElement('ScheduledList');
1058
    xw.writeElementString('Include', 'false');
1059
    xw.writeEndElement(); /* ScheduledList */
1060
    xw.writeStartElement('SellingSummary');
1061
    xw.writeElementString('Include', 'false');
1062
    xw.writeEndElement(); /* SellingSummary */
1063
    xw.writeStartElement('SoldList');
1064
    xw.writeElementString('Include', 'false');
1065
    xw.writeEndElement(); /* SoldList */
1066
 
1067
    xw.writeStartElement(liveListing ? 'UnsoldList' : 'ActiveList');
1068
    xw.writeElementString('Include', 'false');
1069
    xw.writeEndElement(); /* ActiveList */
1070
 
1071
    xw.writeStartElement(liveListing ? 'ActiveList' : 'UnsoldList');
1072
    xw.writeElementString('Include', 'true');
1073
    xw.writeElementString('IncludeNotes', 'true');
1074
    xw.writeStartElement('Pagination');
1075
    xw.writeElementString('EntriesPerPage', '200');
1076
    xw.writeElementString('PageNumber', '' + pageNo);
1077
    xw.writeEndElement(); /* Pagination*/
1078
    xw.writeEndElement(); /* UnsoldList> */
1079
 
14 - 1080
    outputSelector = liveListing ? 'ActiveList.' : 'UnsoldList.';
1081
 
16 - 1082
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.SellingStatus.BidCount');
14 - 1083
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.BuyItNowPrice');
1084
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.eBayNotes');
1085
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.ItemID');
16 - 1086
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.ListingDetails.' + (liveListing ? 'StartTime' : 'EndTime'));
14 - 1087
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.ListingType');
1088
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.PrivateNotes');
1089
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.QuantityAvailable');
1090
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.PictureDetails');
1091
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.Relisted');
1092
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.SKU');
1093
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.Title');
1094
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.StartPrice');
1095
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.WatchCount');
1096
    xw.writeElementString('OutputSelector', outputSelector + 'PaginationResult');
1097
 
2 - 1098
    xw.writeElementString('ErrorLanguage', 'en_US');
1099
    xw.writeElementString('Version', configeBayTradingVersion);
1100
    xw.writeElementString('WarningLevel', configWarningLevel);
1101
 
1102
    xw.writeEndElement(); /* xmlrequest */
1103
    xw.writeEndDocument();
1104
 
1105
    xhr.open('POST', configProxyUrl, true);
1106
    xhr.setRequestHeader('Content-Type', 'text/xml');
1107
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
1108
    xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
1109
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
1110
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
1111
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
1112
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
1113
    xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
1114
 
1115
    return true;
1116
}
1117
 
1118
function fillSorterListings() {
1119
    var i;
1120
    var x = document.getElementById(tableSorterName);
1121
    var fillList = [];
1122
    var maxItems = 20;
1123
 
1124
    listingsToFill = 0;
1125
    maxListingsToFill = 0;
1126
    listingsFilled = 0;
1127
 
1128
    initProgressBar('Filling Listing Information (2/2)');
1129
 
1130
    for (i = 2; i < x.rows.length; i++) {
1131
        fillList.push(x.rows[i].cells[3].innerHTML);
1132
    }
6 - 1133
 
16 - 1134
    for (i = 0; (i * maxItems) < fillList.length; i++) {
2 - 1135
        ++listingsToFill;
1136
        ++maxListingsToFill;
1137
        fillSorterListing(fillList.slice(i * maxItems, (i + 1) * maxItems));
1138
    }
1139
 
1140
    function checkListingsToFill() {
1141
        if (listingsToFill > 0) {
1142
            window.setTimeout(checkListingsToFill, 100); // wait 100 milliseconds
1143
        } else {
1144
            $("#" + tableSorterName).trigger("update");
1145
 
1146
            endProgressBar();
1147
 
1148
            x = document.getElementById("form1div");
1149
            x.className = x.className.replace(" w3-show", "");
1150
            x = document.getElementById("form2div");
1151
            x.className += " w3-show";
1152
 
1153
            x = document.getElementById("results");
1154
            x.innerHTML += '<p><strong>Report Finished!</strong></p>';
1155
            if (!x.className.includes("process-errors")) {
1156
                setTimeout(function() {
1157
                    x.className = x.className.replace(" w3-show", "");
1158
                }, 3000);
1159
            }
1160
        }
1161
    }
1162
 
1163
    checkListingsToFill();
1164
}
1165
 
1166
function fillSorterListing(itemIdList) {
1167
    var i;
1168
    var xml;
1169
 
1170
    var xw = new XMLWriter('UTF-8', '1.0');
1171
    var xhr = new XMLHttpRequest();
1172
 
1173
    if (!createSorterFillXMLSearch(xw, xhr, 'GetMultipleItems', itemIdList)) {
1174
        return;
1175
    }
1176
 
1177
    xml = xw.flush();
1178
    xw.close();
1179
 
1180
    xhr.onload = function() {
16 - 1181
        var jsonObj = XMLparse(xhr.responseXML, false);
1182
        var obj = jsonObj.GetMultipleItemsResponse;
2 - 1183
        var returnCode = obj.Ack;
19 - 1184
        var str;
2 - 1185
 
1186
        var x = document.getElementById("results");
1187
 
1188
        if (returnCode == 'Success') {
1189
            for (i = 0; i < obj.Item.length; i++) {
1190
                var itemId = getJsonValue(obj.Item[i].ItemID);
1191
                document.getElementById("Views" + itemId).innerHTML = getJsonValue(obj.Item[i].HitCount);
1192
                document.getElementById("Category" + itemId).innerHTML = getJsonValue(obj.Item[i].PrimaryCategoryName);
6 - 1193
            }
2 - 1194
        } else {
1195
            x.className += " process-errors";
30 - 1196
            str = '<p class="text-danger"><strong>' + returnCode + ':</strong></p>';
2 - 1197
 
6 - 1198
            var errors = getJsonArray(obj.Errors);
19 - 1199
            str += "<p>";
6 - 1200
            for (i = 0; i < errors.length; i++) {
19 - 1201
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
2 - 1202
            }
1203
            x.innerHTML += "</p>";
19 - 1204
 
1205
            x.innerHTML += str;
2 - 1206
        }
1207
 
1208
        --listingsToFill;
1209
        ++listingsFilled;
1210
        updateProgressBar(maxListingsToFill, listingsFilled);
1211
    };
1212
 
1213
    xhr.send(xml);
1214
}
1215
 
1216
function createSorterFillXMLSearch(xw, xhr, callname, itemIdList) {
1217
    var i;
6 - 1218
 
2 - 1219
    xw.writeStartDocument();
1220
    xw.writeStartElement(callname + "Request");
1221
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
1222
 
1223
    for (i = 0; i < itemIdList.length; i++) {
1224
        xw.writeElementString('ItemID', itemIdList[i]);
1225
    }
1226
 
1227
    xw.writeElementString('ErrorLanguage', 'en_US');
1228
    xw.writeElementString('Version', configeBayShoppingVersion);
1229
    xw.writeElementString('WarningLevel', configWarningLevel);
1230
 
1231
    xw.writeEndElement(); /* xmlrequest */
1232
    xw.writeEndDocument();
1233
 
1234
    xhr.open('POST', configProxyUrl, true);
1235
    xhr.setRequestHeader('Content-Type', 'text/xml');
1236
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
1237
    xhr.setRequestHeader('X-EBAY-API-VERSION', configeBayShoppingVersion);
1238
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
1239
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
1240
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
1241
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
1242
    xhr.setRequestHeader('X-EBAY-API-REQUEST-ENCODING', 'XML');
1243
    xhr.setRequestHeader('X-Proxy-URL', configeBayShopping);
1244
 
1245
    return true;
1246
}
1247
 
1248
    </script>
17 - 1249
    <script>includeHTML();</script>
2 - 1250
 
1251
</body>
1252
</html>