forked from jennyrudemo/lego-database
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset.php
More file actions
484 lines (377 loc) · 14.6 KB
/
Copy pathset.php
File metadata and controls
484 lines (377 loc) · 14.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
<?php include "txt/header.txt";?>
</div>
<div class="main">
<div id="setLeftColumn">
<div id="setInfo">
<?php
//Koppla upp mot databasen
$connection = mysqli_connect("mysql.itn.liu.se","lego","","lego");
if (!$connection) {
die ('MySQL connection error.');
}
//$searchID = $_GET['searchID'];//
$searchID = "'".$_GET["searchID"]."'";
print "$searchID";
//$searchID = "'3342-1'";
$urlBase="http://www.itn.liu.se/~stegu76/img.bricklink.com/";
$contents = mysqli_query($connection,
"SELECT sets.Setname, sets.SetID, sets.Year, categories.Categoryname, images.has_gif,
images.has_jpg, images.has_largegif, images.has_largejpg
FROM sets, categories, images
WHERE sets.SetID = $searchID AND sets.CatID = categories.CatID AND images.ItemID = sets.SetID
LIMIT 30");
//Skriver ut satsnamn, sats ID, år och katergori
while($row = mysqli_fetch_array($contents)){
//För bild
$SetID = $row['SetID'];
$itemtype = 'S';
$filetype;
if($row['has_gif'] OR $row['has_largegif']){
$filetype = ".gif";
if($row['has_largegif']){
$itemtype = 'SL';
};
}
else{
$filetype = ".jpg";
if($row['has_largejpg']){
$itemtype = 'SL';
};
};
$fileName = $itemtype."/".$SetID.$filetype;
$imgsrc = $urlBase.$fileName;
print("<img src= $imgsrc alt=$fileName>");
$Setname = $row['Setname'];
$SetYear = $row['Year'];
$SetCat = $row['Categoryname'];
print("<h3>$Setname</h3>\n");
print("<p> SetID: $SetID </p> \n");
print("<p> År: $SetYear </p> \n");
print("<p> Kategori: $SetCat </p> \n");
}
// Räknare för antal totala bitar i ett set
$setQuantity = mysqli_query($connection,
"SELECT inventory.Quantity
FROM inventory
WHERE inventory.SetID=$searchID AND (inventory.ItemtypeID = 'P' OR inventory.ItemtypeID = 'M')
LIMIT 30");
$totSetQuantity = 0;
while($quantRow = mysqli_fetch_array($setQuantity)) {
$totSetQuantity += $quantRow['Quantity'];
}
print("<p>Antal bitar: $totSetQuantity</p>\n");
$collectionQuant = mysqli_query($connection,
"SELECT collection.Quantity
FROM collection
WHERE collection.SetID=$searchID
LIMIT 30");
//Kollar om satsen finns i samling
if($colQuantRow = mysqli_fetch_array($collectionQuant)){
$colQuant= $colQuantRow['Quantity'];
print("<p>Satsen finns!</p>");
print("<p>Antal av denna sats: $colQuant </p>");
}
else {
//Om ej i samling: kolla hur många av satsens bitar som finns i samling
//Hur många av bitarna i söksatsen finns i andra satser i samlingen?
//För varje bit i sökta satsen vill vi kolla om den biten finns i
//någon annan sats i samlingen
$partsInSet = mysqli_query($connection,
"SELECT inventory.ItemID, inventory.Quantity, inventory.ColorID
FROM inventory
WHERE inventory.SetID=$searchID AND (inventory.ItemtypeID = 'P' OR inventory.ItemtypeID = 'M')
LIMIT 30"
);
//Display alla bitar och figurer i satsen som vi söker på - IN PROGRESS
//print("<table>");
//lägg till counter för samlarens bitar (som räknas i while loopen) (totPartsCounter)
$totPartsCounter = 0;
while($setRow = mysqli_fetch_array($partsInSet)){
//while loop för varje bit i det sökta setet
$itemID = $setRow['ItemID'];
$colorID = $setRow['ColorID'];
$quantGoal = $setRow['Quantity'];
//sökning på collections mm, se bild på Trello
//kommer ge antal av biten för varje setID, en rad för varje SetID
$bitQuantity = mysqli_query($connection,
"SELECT inventory.Quantity AS invQuantity, collection.Quantity AS colQuantity
FROM inventory, collection
WHERE inventory.ItemID = '$itemID' AND inventory.ColorID = $colorID
AND collection.SetID = inventory.SetID
LIMIT 30
"
);
//varaibel counter
$bitCounter = 0;
//while loop för varje rad i sökningen
while ($bitRow = mysqli_fetch_array($bitQuantity)){
$quantity = $bitRow['invQuantity'] * $bitRow['colQuantity'];
//lägga på quantity till en counter
$bitCounter += $quantity;
}
//när raderna är slut och om counter < quant_goal: return counter
//counter eller countGoal ska läggas till i den totala countern (fullCounter)
//testa om counter >= quant_goal(el counterGoal)
//om den når det: lägg countGoal i totPartsCounter
if ($bitCounter < $quantGoal) {
$totPartsCounter += $bitCounter;
}
else if ($bitCounter >= $quantGoal) {
$totPartsCounter += $quantGoal;
}
}
//Skriv ut fullCounter i "Varav i samling:"
print("<p>Varav i samling (från andra satser): $totPartsCounter</p>");
//print("</table>");
}
//Note: i tabellen: skriv ut totalt antal bitar i samlingen (även om inte alla behövs till att bygga ett set)
print("</div>");
print("<div id='availabilityInfo'>");
print("
<table>
<tr>
<td><img src='./green.svg' class='availInfo' alt='gröm cirkel'></td>
<td><p>Komplett</p></td>
</tr>
<tr>
<td><img class='availInfo' src='./yellow.svg' alt='gul cirkel'></td>
<td><p>Ersättningsbitar finns</p></td>
</tr>
<tr>
<td><img class='availInfo' src='./red.svg' alt='röd cirkel'></td>
<td><p>Ej komplett</p></td>
</tr>
</table> ");
print("</div>");
print("</div>");
print("<div id='setTable'>");
/***********************
* MINIFIGURES *
***********************/
print("<div id='minifigs'>");
print ("<h3>Minifigurer</h3>");
$minifigsSearch= mysqli_query($connection,
"SELECT minifigs.Minifigname, inventory.ItemID, inventory.Quantity,
images.has_gif, images.has_jpg, images.has_largegif, images.has_largejpg
FROM inventory, minifigs, images
WHERE inventory.SetID = $searchID AND inventory.ItemID = minifigs.MinifigID AND
inventory.ItemtypeID = 'M' AND inventory.ItemID=images.ItemID
LIMIT 30");
print("<table>\n<tr>");
print ("<th> </th>");
print ("<th> Bild </th>");
print ("<th> Namn </th>");
print ("<th> Figur ID </th>");
print ("<th> Antal i sats </th>");
print ("<th> Antal i samling </th>");
print ("</tr>\n");
$availableFigGreen = array();
$availableFigRed = array();
//Varje figur
while($minifigRow = mysqli_fetch_array($minifigsSearch)) {
$itemID = $minifigRow['ItemID'];
$itemtype = 'M';
$figName = $minifigRow['Minifigname'];
$inventQuant = $minifigRow['Quantity'];
$bitQuantity = mysqli_query($connection,
"SELECT inventory.Quantity AS invQuantity, collection.Quantity AS colQuantity
FROM inventory, collection
WHERE inventory.ItemID = '$itemID'
AND collection.SetID = inventory.SetID
LIMIT 30
"
);
//Hämta hela bild-url
if($minifigRow['has_gif'] OR $minifigRow['has_largegif']){
$filetype = ".gif";
if(!$minifigRow['has_gif']){
$itemtype = 'ML';
};
}
else{
$filetype = ".jpg";
if(!$minifigRow['has_jpg']){
$itemtype = 'ML';
};
};
$imgsrc = $urlBase.'/'.$itemtype.'/'.$itemID.$filetype;
//Räkna ut colQuant (bitCounter)
$bitCounter = 0;
//while loop för varje rad i sökningen
while ($bitRow = mysqli_fetch_array($bitQuantity)){
$quantity = $bitRow['invQuantity'] * $bitRow['colQuantity'];
//lägga på quantity till en counter
$bitCounter += $quantity;
}
if ($bitCounter >= $inventQuant){
$imgsrcAvail = '"green.svg"';
$availabilityText = 'Tillgänglig';
$availableFigGreen[] =
"<td><img class='availInfo' src=$imgsrcAvail alt=$availabilityText></td>
<td><img src=$imgsrc alt=$figName></td>
<td>$figName</td>
<td>$itemID</td>
<td>$inventQuant</td>
<td>$bitCounter</td>
</tr>\n";
}
else{
$imgsrcAvail = '"red.svg"';
$availabilityText = 'Ej tillgänglig';
$availableFigRed[] =
"<td><img class='availInfo' src=$imgsrcAvail alt=$availabilityText></td>
<td><img src=$imgsrc alt=$figName></td>
<td>$figName</td>
<td>$itemID</td>
<td>$inventQuant</td>
<td>$bitCounter</td>
</tr>\n";
};
}
for ( $i = 0; $i < count($availableFigRed); $i++) {
print $availableFigRed[$i];
}
for ( $i = 0; $i < count($availableFigGreen); $i++) {
print $availableFigGreen[$i];
}
print("</table>");
print("</div>");
/***********************
* PARTS *
***********************/
print("<div id='parts'>");
print ("<h3>Bitar</h3>");
$partsSearch= mysqli_query($connection,
"SELECT parts.Partname, inventory.ItemID, inventory.Quantity, inventory.ColorID,
images.has_gif, images.has_jpg, images.has_largegif, images.has_largejpg, colors.Colorname
FROM inventory, parts, images, colors
WHERE inventory.SetID = $searchID AND inventory.ItemID = parts.PartID AND
inventory.ItemtypeID = 'P' AND inventory.ItemID=images.ItemID AND
inventory.ColorID = images.ColorID AND inventory.ColorID = colors.ColorID
LIMIT 30");
print("<table>\n<tr>");
print ("<th> </th>");
print ("<th> Bild </th>");
print ("<th> Namn </th>");
print ("<th> FigurID </th>");
print ("<th> Färg </th>");
print ("<th> Antal i sats </th>");
print ("<th> Antal i samling </th>");
print ("</tr>\n");
$availableGreen= array();
$availableYellow = array();
$availableRed = array();
//$finnsinte[] = $row;
//Varje bit
while($partsRow = mysqli_fetch_array($partsSearch)) {
$itemID = $partsRow['ItemID'];
$itemtype = 'P';
$partName = $partsRow['Partname'];
$colorID = $partsRow['ColorID'];
$inventQuant = $partsRow['Quantity'];
$colorName = $partsRow['Colorname'];
$bitQuantity = mysqli_query($connection,
"SELECT inventory.Quantity AS invQuantity, collection.Quantity AS colQuantity, inventory.ColorID
FROM inventory, collection
WHERE inventory.ItemID = '$itemID'
AND collection.SetID = inventory.SetID
LIMIT 1000"
);
//Hämta hela bild-url
if($partsRow['has_gif'] OR $partsRow['has_largegif']){
$filetype = ".gif";
if($partsRow['has_gif']){
$itemtype = $itemtype."/".$colorID;
}
else {
$itemtype = 'PL';
};
}
else{
$filetype = ".jpg";
if($partsRow['has_jpg']){
$itemtype = $itemtype."/".$colorID;
}
else {
$itemtype = 'PL';
};
};
$imgsrc = $urlBase.'/'.$itemtype.'/'.$itemID.$filetype;
//Räkna ut colQuant (bitCounter)
$bitCounter = 0;
$mixedColorCounter = 0;
//while loop för varje rad i sökningen
while ($bitRow = mysqli_fetch_array($bitQuantity)){
$tempColorID = $bitRow['ColorID'];
//$quantity = $bitRow['invQuantity'] ;
$quantity = $bitRow['invQuantity'] * $bitRow['colQuantity'];
//lägga på quantity till en counter
if ($tempColorID == $colorID) {
$bitCounter += $quantity;
};
//mixedColorCounter är antalet av en bit, oavsett färg
$mixedColorCounter += $quantity;
}
//AVAILABILITY-FÄRG
//OBS: Lägg till counter för fel färg i while-loopen
//Testa om antal bitar i samlingen uppnår antal i satsen
/*if($bitCounter < $inventQuant){
$imgsrcAvail = 'red';
}*/
if ($bitCounter >= $inventQuant){
$imgsrcAvail = '"green.svg"';
$availabilityText = 'Tillgänglig';
$availableGreen[] =
"<td><img class='availInfo' src=$imgsrcAvail alt=$availabilityText></td>
<td><img src=$imgsrc alt=$partName></td>
<td>$partName</td>
<td>$itemID</td>
<td>$colorName</td>
<td>$inventQuant</td>
<td>$bitCounter ($mixedColorCounter)</td>
</tr>\n";
}
else if($mixedColorCounter >= $inventQuant){
$imgsrcAvail = '"yellow.svg"';
$availabilityText = 'Tillgänglig i annan färg';
$availableYellow[] =
"<td><img class='availInfo' src=$imgsrcAvail alt=$availabilityText></td>
<td><img src=$imgsrc alt=$partName></td>
<td>$partName</td>
<td>$itemID</td>
<td>$colorName</td>
<td>$inventQuant</td>
<td>$bitCounter ($mixedColorCounter)</td>
</tr>\n";
}
else{
$imgsrcAvail = '"red.svg"';
$availabilityText = 'Ej tillgänglig';
$availableRed[] =
"<td><img class='availInfo' src=$imgsrcAvail alt=$availabilityText></td>
<td><img src=$imgsrc alt=$partName></td>
<td>$partName</td>
<td>$itemID</td>
<td>$colorName</td>
<td>$inventQuant</td>
<td>$bitCounter ($mixedColorCounter)</td>
</tr>\n";
};
}
//ev array merge
for ( $i = 0; $i < count($availableRed); $i++) {
print $availableRed[$i];
}
for ( $i = 0; $i < count($availableYellow); $i++) {
print $availableYellow[$i];
}
for ( $i = 0; $i < count($availableGreen); $i++) {
print $availableGreen[$i];
}
print("</table>");
print("</div>");
print("</div>");
?>
</div>
</body>
</html>