-
Notifications
You must be signed in to change notification settings - Fork 11
/
deck.php
645 lines (586 loc) · 21.3 KB
/
deck.php
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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
<?php session_start();
require_once 'lib.php';
$js = <<<EOD
function deckAjaxResult(data) {
if (data.id != 0) {
$("#deck-name").val(data.name);
$("#deck-archetype").val(data.archetype);
var decktext = "";
for (var card in data.maindeck) {
decktext = decktext + data.maindeck[card] + " " + card + "\n";
}
$("#deck-contents").val(decktext);
decktext = "";
for (var card in data.sideboard) {
decktext = decktext + data.sideboard[card] + " " + card + "\n";
}
$("#deck-sideboard").val(decktext);
}
}
$(document).ready(function() {
$("#autoenter-deck").change(function() {
var selid = $("#autoenter-deck").val();
$.ajax({
url: 'ajax.php?deck=' + selid,
success: deckAjaxResult
});
$("#autoenter-deck").val(0);
});
});
EOD;
$deckboxScript = "<script src=\"http://deckbox.org/javascripts/bin/tooltip.js\"></script>";
print_header("Deck Database", $js, $deckboxScript);
?>
<div class="grid_10 suffix_1 prefix_1">
<div id="gatherling_main" class="box">
<div class="uppertitle">Deck Database</div>
<?php
if (!isset($_GET['mode'])) { $_GET['mode'] = ''; }
if (strcmp($_GET['mode'], "view") == 0) {
$deck = NULL;
if(isset($_GET['event'])) {
$event = new Event($_GET['event']);
$deck = $event->getPlaceDeck("1st");
} else {
if (isset($_GET['id'])) {
$deck = new Deck($_GET['id']);
}
}
deckProfile($deck);
} else {
// Need to auth for everything else.
if (!isset($_POST['player']) and isset($_GET['player'])) {
$_POST['player'] = $_GET['player'];
}
$deck_player = isset($_POST['player']) ? $_POST['player'] : Player::loginName();
$deck = isset($_POST['id']) ? new Deck($_POST['id']) : NULL;
if (!isset($_POST['event'])) {
$_POST['event'] = $_GET['event'];
}
// part of the reg-decklist feature. both "register" and "addregdeck" switches
if (strcmp($_GET['mode'], "register") == 0) {
deckRegisterForm();
} else if (strcmp($_GET['mode'], "addregdeck") == 0) {
$deck = insertDeck();
if (count($deck->errors) == 0) {
deckProfile($deck);
}
} else if (checkDeckAuth($_POST['event'], $deck_player, $deck)) {
if (strcmp($_POST['mode'], "Create Deck") == 0) {
$deck = insertDeck();
if (count($deck->errors) == 0) {
deckProfile($deck);
}
} elseif (strcmp($_POST['mode'], "Update Deck") == 0) {
$deck = updateDeck($deck);
if (count($deck->errors) == 0) {
deckProfile($deck);
}
} elseif (strcmp($_POST['mode'], "Edit Deck") == 0) {
deckForm($deck);
} elseif (strcmp($_GET['mode'], "create") == 0) {
deckForm();
}
}
}
?>
</div> <!-- gatherling_main box -->
</div> <!-- grid 10 suf 1 pre 1 -->
<?php print_footer(); ?>
<?php
function deckForm($deck = NULL) {
$mode = is_null($deck) ? "Create Deck" : "Update Deck";
if (!is_null($deck)) {
$player = $deck->playername;
$event = $deck->eventname;
} else {
$player = (isset($_POST['player'])) ? $_POST['player'] : $_GET['player'];
$event = (isset($_POST['player'])) ? $_POST['event'] : $_GET['event'];
}
if (!checkDeckAuth($event, $player, $deck)) {
return;
}
$vals = array('contents' => '', 'sideboard' => '');
if(!is_null($deck)) {
foreach ($deck->maindeck_cards as $card => $amt) {
$line = $amt . " " . $card . "\n";
$vals['contents'] = $vals['contents'] . $line;
}
foreach ($deck->sideboard_cards as $card => $amt) {
$line = $amt . " " . $card . "\n";
$vals['sideboard'] = $vals['sideboard'] . $line;
}
$vals['desc'] = $deck->notes;
$vals['archetype'] = $deck->archetype;
$vals['name'] = $deck->name;
}
echo "<form action=\"deck.php\" method=\"post\">\n";
echo "<table align=\"center\" style=\"border-width: 0px;\">\n";
echo "<tr><td valign=\"top\"><b>Directions:</td>\n";
echo "<td>To enter your deck, please give it ";
echo "a name and select an archetype from the drop-down menu below. If ";
echo "you do not specify and archetype, your deck will be labeled as ";
echo "\"Unclassified\". To enter cards, save your deck as a .txt file using the ";
echo "official MTGO client, and then copy and paste the maindeck and ";
echo "sideboard into the appropriate text boxes. ";
echo "The correcr pattern is \"1 Card Name\".</td></tr>\n";
echo "<tr><td><b>Recent Decks</b></td>\n<td>\n";
echo "<select id=\"autoenter-deck\">\n";
echo "<option value=\"0\">Select a recent deck to start from there</option>\n";
$deckplayer = new Player($player);
if (!is_null($deck)) {
if (count($deck->errors) == 0 && count($deck->maindeck_cards) == 0) {
$recentdecks = $deckplayer->getRecentDecks();
foreach ($recentdecks as $adeck) {
echo "<option value=\"{$adeck->id}\">{$adeck->name}</option>\n";
}
}
}
echo "</select></td></tr>";
if (count($deck->errors) > 0) {
echo "<tr><td>Errors</td><td> There are some problems adding your deck: <ul>";
foreach ($deck->errors as $error) {
echo "<li>$error</li>";
}
echo "</ul></td></tr>";
}
echo "<tr><td><b>Name</td>\n<td>";
echo "<input id=\"deck-name\" type=\"text\" name=\"name\" value=\"". htmlentities($vals['name']) . "\" ";
echo "size=\"40\"></td></tr>\n";
if(!is_null($deck)) {echo "<input type=\"hidden\" name=\"id\" value=\"{$deck->id}\">\n";}
echo "<tr><td><b>Archetype</td>\n<td>";
archetypeDropMenu($vals['archetype']);
echo "</td></tr>\n";
echo "<tr><td valign=\"top\"><b>Main Deck</td>\n<td>";
echo "<textarea id=\"deck-contents\" rows=\"20\" cols=\"60\" name=\"contents\">";
echo "{$vals['contents']}</textarea></td></tr>\n";
echo "<tr><td valign=\"top\"><b>Sideboard</td>\n<td>";
echo "<textarea id=\"deck-sideboard\" rows=\"10\" cols=\"60\" name=\"sideboard\">";
echo "{$vals['sideboard']}</textarea></td></tr>\n";
echo "<tr><td valign=\"top\"><b>Comments</td>\n<td>";
echo "<textarea rows=\"10\" cols=\"60\" name=\"notes\">";
echo "{$vals['desc']}</textarea></td></tr>\n";
echo "<tr><td> </td></tr>\n";
echo "<tr><td colspan=\"2\" align=\"center\">\n";
echo "<input type=\"submit\" name=\"mode\" value=\"" . htmlentities($mode) . "\">\n";
echo "<input type=\"hidden\" name=\"player\" value=\"" . htmlentities($player) . "\">";
echo "<input type=\"hidden\" name=\"event\" value=\"" . htmlentities($event) . "\">";
echo "</td></tr></table></form>\n";
}
// deckRegisterForm is part of the reg-decklist feature
function deckRegisterForm($deck = NULL) {
$player = (isset($_POST['player'])) ? $_POST['player'] : $_GET['player'];
$event = (isset($_POST['event'])) ? $_POST['event'] : $_GET['event'];
$vals = array('contents' => '', 'sideboard' => '');
echo "<form action=\"deck.php?mode=addregdeck\" method=\"post\">\n";
echo "<table align=\"center\" style=\"border-width: 0px;\">\n";
echo "<tr><td valign=\"top\"><b>Directions:</td>\n";
echo "<td>To enter your deck, please give it ";
echo "a name and select an archetype from the drop-down menu below. If ";
echo "you do not specify and archetype, your deck will be labeled as ";
echo "\"Unclassified\". To enter cards, save your deck as a .txt file using the ";
echo "official MTGO client, and then copy and paste the maindeck and ";
echo "sideboard into the appropriate text boxes. ";
echo "Do not use a format such as \"1x Card\". ";
echo "The parser will not accept this structure. The correct pattern is ";
echo "\"1 Card\".</td></tr>\n";
echo "<tr><td><b>Recent Decks</b></td>\n<td>\n";
echo "<select id=\"autoenter-deck\">\n";
echo "<option value=\"0\">Select a recent deck to start from there</option>\n";
$deckplayer = new Player($player);
$recentdecks = $deckplayer->getRecentDecks();
foreach ($recentdecks as $adeck) {
echo "<option value=\"{$adeck->id}\">{$adeck->name}</option>\n";
}
echo "</select></td></tr>";
echo "<tr><td><b>Name</td>\n<td>";
echo "<input id=\"deck-name\" type=\"text\" name=\"name\" value=\"" . htmlentities($vals['name']) . "\" ";
echo "size=\"40\"></td></tr>\n";
echo "<tr><td><b>Archetype</td>\n<td>";
archetypeDropMenu($vals['archetype']);
echo "</td></tr>\n";
echo "<tr><td valign=\"top\"><b>Main Deck</td>\n<td>";
echo "<textarea id=\"deck-contents\" rows=\"20\" cols=\"60\" name=\"contents\">";
echo "{$vals['contents']}</textarea></td></tr>\n";
echo "<tr><td valign=\"top\"><b>Sideboard</td>\n<td>";
echo "<textarea id=\"deck-sideboard\" rows=\"10\" cols=\"60\" name=\"sideboard\">";
echo "{$vals['sideboard']}</textarea></td></tr>\n";
echo "<tr><td valign=\"top\"><b>Comments</td>\n<td>";
echo "<textarea rows=\"10\" cols=\"60\" name=\"notes\">";
echo "{$vals['desc']}</textarea></td></tr>\n";
echo "<tr><td> </td></tr>\n";
echo "<tr><td colspan=\"2\" align=\"center\">\n";
echo "<input type=\"submit\" name=\"mode\" value=\"Create Deck\">\n";
echo "<input type=\"hidden\" name=\"player\" value=\"" . htmlentities($player) . "\">";
echo "<input type=\"hidden\" name=\"event\" value=\"" . htmlentities($event) . "\">";
echo "</td></tr></table></form>\n";
}
function archetypeDropMenu($def) {
$archetypes = Deck::getArchetypes();
echo "<select id=\"deck-archetype\" name=\"archetype\">\n";
echo "<option value=\"Unclassified\">- Archetype -</option>\n";
foreach ($archetypes as $name) {
$sel = (strcmp($name, $def) == 0) ? "selected" : "";
echo "<option value=\"$name\" $sel>$name</option>\n";
}
}
function insertDeck() {
$deck = new Deck(0);
$deck->name = $_POST['name'];
$deck->archetype = $_POST['archetype'];
$deck->notes = $_POST['notes'];
$deck->playername = $_POST['player'];
$deck->eventname = $_POST['event'];
$deck->maindeck_cards = parseCards($_POST['contents']);
$deck->sideboard_cards = parseCards($_POST['sideboard']);
if (!$deck->save()) {
deckForm($deck);
}
return $deck;
}
function updateDeck($deck) {
$deck->archetype = $_POST['archetype'];
$deck->name = $_POST['name'];
$deck->notes = $_POST['notes'];
$deck->maindeck_cards = parseCards($_POST['contents']);
$deck->sideboard_cards = parseCards($_POST['sideboard']);
if (!$deck->save()) {
deckForm($deck);
}
return $deck;
}
function parseCards($text) {
$lines = explode("\n", $text);
$badcards = array();
$cardarr = array();
foreach ($lines as $line) {
$chopped = chop($line);
if (preg_match("/[ \t]*([0-9]+)x?[ \t]+(.*)/i", $chopped, $m)) {
$qty = $m[1];
$card = chop($m[2]);
// Wonky character fixes. TODO: separate this out into Card::normalize_name or something
$card = preg_replace("/Æ/", "AE", $card);
$card = preg_replace("/\306/", "AE", $card);
$card = preg_replace("/ö/", "o", $card);
$card = strtolower($card);
if(isset($cardarr[$card])) {
$cardarr[$card] += $qty;
} else {
$cardarr[$card] = $qty;
}
}
}
return $cardarr;
}
function printPlaceString($medal) {
$str = "";
if(strcmp($medal, "t8") == 0) {$str = " - Top 8";}
if(strcmp($medal, "t4") == 0) {$str = " - Top 4";}
if(strcmp($medal, "2nd") == 0) {$str = " - 2nd Place";}
if(strcmp($medal, "1st") == 0) {$str = " - 1st Place";}
echo "$str";
}
function deckProfile($deck) {
if ($deck == NULL || $deck->id == 0) {
echo "<span class=\"error\"><center>Deck is not found. It is possible that it is not entered yet.</center></span>";
return;
}
echo "<center><form action=\"deckdl.php\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"id\" value=\"{$deck->id}\" />\n";
echo "<input type=\"submit\" name=\"mode\" ";
echo "value=\"Download deck as .txt file\" /></form></center><br>\n";
echo "<div class=\"grid_5 alpha\"><div id=\"gatherling_lefthalf\">\n";
deckInfoCell($deck);
maindeckTable($deck);
sideboardTable($deck);
echo "</div> </div>\n";
echo "<div class=\"grid_5 omega\"><div id=\"gatherling_righthalf\">\n";
trophyCell($deck);
matchupTable($deck);
echo "<div class=\"grid_2 alpha\">\n";
symbolTable($deck);
echo "</div> <div class=\"grid_2 omega\">\n";
ccTable($deck);
echo "</div>\n";
echo "<div class=\"clear\"></div>";
exactMatchTable($deck);
echo " </div> </div>\n";
echo "<div class=\"clear\"></div>";
echo "<div>";
commentsTable($deck);
echo "</div>";
echo "<div class=\"clear\"></div>";
echo "<center>\n";
echo "<form action=\"deck.php\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"id\" value=\"$deck->id\" />\n";
echo "<input type=\"submit\" name=\"mode\" value=\"Edit Deck\" />\n";
echo "</form></center>\n";
}
function commentsTable($deck) {
$notes = $deck->notes;
if($notes == "" || is_null($notes)) {
$notes = "<i>No comments have been recorded for this deck.</i>";
} else {
$notes = strip_tags($notes);
$notes = preg_replace("/\n/", "<br />", $notes);
$notes = preg_replace("/\[b\]/", "<b>", $notes);
$notes = preg_replace("/\[\/b\]/", "</b>", $notes);
$notes = preg_replace("/\[i\]/", "<i>", $notes);
$notes = preg_replace("/\[\/i\]/", "</i>", $notes);
}
echo "<table style=\"border-width: 0px; width: 100%; \" cellpadding=1>";
echo "<tr><td><b>COMMENTS</td></tr>";
echo "<tr><td>{$notes}</td></tr>";
echo "</table>";
}
function deckInfoCell($deck) {
include 'config.php';
$ncards = $deck->getCardCount();
$event = $deck->getEvent();
$day = date("F j, Y", strtotime($event->start));
$mstr = image_tag($deck->medal . ".png") . " ";
if($deck->medal == '1st') {
$placing = $mstr . "1st by";
} else if($deck->medal == '2nd') {
$placing = $mstr . "2nd by";
} else if($deck->medal == 't4') {
$placing = $mstr . "Top 4 by";
} else if($deck->medal == 't8') {
$placing = $mstr . "Top 8 by";
} else {
$placing = "Played by";
}
$line3 = "{$placing} ";
if ($deck->playername != NULL) {
$deckplayer = new Player($deck->playername);
$line3 .= $deckplayer->linkTo();
$line3 .= " in <span class=\"eventname\" title=\"{$day}\">{$event->name}</span>\n";
} else {
$line3 .= "Never played (?) according to records.";
}
$rstar = "<font color=\"#FF0000\">*</font>";
$name = $deck->name;
if (empty($name)) {
$name = "** NO NAME **";
}
$line1 = "<b>" . strtoupper($name) . "</b>";
$deck_format = $event->format;
if ($ncards < 6) {$line1 .= $rstar;}
if ($ncards < 60) {
$line1 .= $rstar;
$line1 .= " ({$ncards} cards)";
}
$line2 = $event->format . " · " . $deck->getColorImages() . " " . $deck->archetype;
$line3 .= "<i>(" . $deck->recordString() . ")</i>";
echo "<table style=\"border-width: 0px\">\n";
echo "<tr><td style=\"font-size: 10pt;\">$line1</td></tr>\n";
echo "<tr><td>$line2</td></tr>\n";
echo "<tr><td>$line3</td></tr>\n";
echo "</table>\n";
}
function trophyCell($deck) {
if ($deck->medal == '1st') {
echo "<center>";
if ($deck->getEvent()->hastrophy) {
echo $deck->getEvent()->getTrophyImageLink();
} else {
echo "No trophy uploaded yet!";
}
echo "</center><br /> <br />";
}
}
function sideboardTable($deck) {
$sideboardcards = $deck->sideboard_cards;
ksort($sideboardcards);
arsort($sideboardcards, SORT_NUMERIC);
echo "<table style=\"border-width: 0px\" cellpadding=1>\n";
echo "<tr><td colspan=1><b>SIDEBOARD</td></tr>\n";
foreach ($sideboardcards as $card => $amt) {
echo "<tr><td>{$amt} ";
printCardLink($card);
echo "</td></tr>";
}
echo "</table>\n";
}
function exactMatchTable($deck) {
if ($deck->cardcount < 5) {
return;
}
$decks = $deck->findIdenticalDecks();
if (count($decks) == 0) {
return false;
}
echo "<table style=\"border-width: 0px\" cellpadding=1 align=\"right\">\n";
echo "<tr><th colspan=5 align=\"left\"><b>THIS DECK ALSO PLAYED AS</td></tr>\n";
foreach ($decks as $deck) {
if (!isset($deck->playername)) {
continue;
}
$cell1 = medalImgStr($deck->medal);
$cell4 = $deck->recordString();
echo "<tr><td>$cell1</td>\n";
echo "<td style=\"width: 140px\">" . $deck->linkTo() . "</td>\n";
echo "<td>{$deck->playername}</td>\n";
echo "<td><a href=\"{$deck->getEvent()->threadurl}\">{$deck->eventname}</a></td>\n";
echo "<td style=\"text-align: right; width: 30px;\">$cell4</td></tr>\n";
}
echo "</table>\n";
}
function matchupTable($deck) {
$matches = $deck->getMatches();
echo "<table style=\"border-width: 0px\" cellpadding=1 align=\"right\">\n";
echo "<tr><td colspan=4 align=\"left\"><b>MATCHUPS</td></tr>\n";
if (count($matches) == 0) {
echo "<tr><td colspan=4><i>No matches were found for this deck</td></tr>";
}
$event = new Event($deck->eventname);
if ($event->finalized == '0') {
echo "<tr><td>Matchups are anonymous for deck privacy until event is finalized.</td><tr>";
} else {
foreach ($matches as $match) {
$rnd = 'R' . $match->round;
if($match->timing > 1 && $match->type == 'Single Elimination') {
$rnd = 'T' . pow(2, $match->rounds - $match->round + 1);}
$color = "#FF9900";
$res = "Draw";
if($match->playerMatchInProgress($deck->playername)) {
$res = "In Progress";
}
if($match->playerWon($deck->playername)) {
$color = "#009900";
$res = "Win";
}
if($match->playerLost($deck->playername)) {
$color = "#FF0000";
$res = "Loss";
}
if($match->playerBye ($deck->playername)) {
$res = "Bye";
}
$resStr = "<b><font color=\"color\">$res</font></b>";
if ($res != 'Bye'){
$opp = new Player($match->otherPlayer($deck->playername));
$deckcell = "No Deck Found";
$oppdeck = $opp->getDeckEvent($deck->eventname);
if ($oppdeck != NULL) {
$deckcell = $oppdeck->linkTo();
}
echo "<tr><td align=\"right\">$rnd: </td>\n";
echo "<td align=\"left\"><b><font color=\"$color\">$res</font>: </td>\n";
echo "<td width=30>{$match->getPlayerWins($deck->playername)} - {$match->getPlayerLosses($deck->playername)}</td>";
echo "<td>vs. </td>\n";
echo "<td align=\"left\">" . $opp->linkTo() . " </td>\n";
echo "<td align=\"right\">$deckcell </td></tr>\n";
} else {
echo "<tr><td align=\"right\">$rnd: </td>\n";
echo "<td align=\"left\"><b>$res: </td>\n";
echo "<td width=30> Bye </td>";
echo "<td>vs. </td>\n";
echo "<td align=\"left\"> No Opponent </td>\n";
echo "<td align=\"right\">No Deck Found </td></tr>\n";
}
}
}
echo "<tr><td> </td></tr>";
echo "</table>\n";
}
function maindeckTable($deck) {
$creatures = $deck->getCreatureCards();
$lands = $deck->getLandCards();
$other = $deck->getOtherCardS();
echo "<table style=\"border-width: 0px\" cellpadding=1>\n";
echo "<tr><td colspan=1><b>MAINDECK</td></tr>\n";
echo "<tr><td colspan=2><i>Creatures</td></tr>\n";
foreach ($creatures as $card => $amt) {
echo "<tr><td>{$amt} ";
printCardLink($card);
echo "</td></tr>\n";
}
echo "<tr><td colspan=2><i>Spells</td></tr>\n";
foreach ($other as $card => $amt) {
echo "<tr><td>{$amt} ";
printCardLink($card);
echo "</td></tr>\n";
}
echo "<tr><td colspan=2><i>Lands</td></tr>\n";
foreach ($lands as $card => $amt) {
echo "<tr><td>{$amt} ";
printCardLink($card);
echo "</td></tr>\n";
}
echo "</table>\n";
}
function ccTable($deck) {
$convertedcosts = $deck->getCastingCosts();
echo "<table style=\"border-width: 0px;\">\n";
echo "<tr><td colspan=2 align=\"center\" width=150><b>CASTING COSTS</td></tr>";
$total = 0; $cards = 0;
foreach ($convertedcosts as $cost => $amt) {
echo "<tr><td align=\"right\" width=75>";
echo image_tag("mana{$cost}.png");
echo " </td>\n";
echo "<td width=75 align=\"left\">{$amt}</td></tr>\n";
$total += $cost * $amt;
$cards += $amt;
}
if($cards == 0) {$cards = 1;}
$avg = $total/$cards;
echo "<tr><td align=\"right\"><i>Avg CMC: </td><td align=\"left\"><i>";
printf("%1.2f", $avg);
echo "</td></tr>\n";
echo "</table>";
}
function symbolTable($deck) {
include 'config.php';
echo "<table style=\"border-width: 0px\">\n";
echo "<tr><td align=\"center\" colspan=2 width=150><b>MANA SYMBOLS";
echo "</td></tr>\n";
$cnts = $deck->getColorCounts();
asort($cnts);
$cnts = array_reverse($cnts, true);
$sum = 0;
foreach($cnts as $color => $num) {
if($num > 0) {
echo "<tr><td align=\"right\" width=75>";
echo image_tag("mana{$color}.png");
echo " </td>\n";
echo "<td align=\"left\">$num</td></tr>\n";
$sum += $num;
}
}
echo "<tr><td align=\"right\"><i>Total: </td>\n";
echo "<td align=\"left\"><i>$sum</td></tr>\n";
echo "</table>\n";
}
function authFailed() {
echo "You are not permitted to make that change. It could be because you are not the ";
echo "player who played the deck, or the event has been finalized. Please contact the ";
echo "event host or deck owner to modify this deck. If you <b>are</b> the event host ";
echo "or feel that you should have privilege to modify this deck, you ";
echo "should contact jamuraa via the forums.<br><br>";
}
function loginRequired() {
echo "<center>You can't do that unless you <a href=\"login.php\">log in first</a></center>";
}
function checkDeckAuth($event, $player, $deck = NULL) {
if (!Player::isLoggedIn()) {
loginRequired();
return false;
}
$loginname = Player::loginName();
if (is_null($deck)) {
// Creating a deck.
$entry = new Entry($event, $player);
$auth = $entry->canCreateDeck($loginname);
} else {
// Updating a deck.
$auth = $deck->canEdit($loginname);
}
if ($auth) {
return true;
} else {
authFailed();
}
return false;
}
?>