/
index.php
3380 lines (2574 loc) · 137 KB
/
index.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
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php //RMRK Pokemon System. Yay.
require_once('settings.php');
if (!file_exists($pcfg['sqlite_db'])) die('Database not found!');
if (isset($_REQUEST['api'])) {
require_once('api.php');
die();
}
//First off, perhaps a lucky user has discovered a wild pokemon? Or maybe we're just loading up lists.
if (isset($_REQUEST['ajax'])) {
require_once('ajax.php');
exit;
}
require_once('../SSI.php');
require_once('smf.php');
require_once('lib.php');
require_once('libextra.php');
require_once('db.php');
require_once('chance.php');
require_once('misc/bases.php');
//Figure out if this user can administrate.
$pcfg['is_admin'] = false;
foreach ($pcfg['admin_groups'] as $allowed) {
if (in_array($allowed, $user_info['groups'])) {
$pcfg['is_admin'] = true;
break;
}
}
if (isset($_GET['regenerate']) && $context['user']['is_admin']) {
if (isset($_GET['trainers'])) { $file_db->exec("CREATE TABLE IF NOT EXISTS trainers (
id INTEGER PRIMARY KEY,
trainerpic INTEGER,
pokemon TEXT,
seen TEXT,
dex TEXT,
starttime INTEGER,
lastcaught INTEGER,
trades TEXT,
fave INTEGER,
badges TEXT,
catches INTEGER,
sightings INTEGER)");
$notice = 'Trainers table (re)built successfully.';
} elseif (isset($_GET['pokemon'])) { $file_db->exec("CREATE TABLE IF NOT EXISTS pokemon (
id INTEGER PRIMARY KEY,
owners TEXT,
shiny_owners TEXT,
encounters INTEGER,
shiny_encounters INTEGER,
captures INTEGER,
shiny_captures INTEGER
)");
$notice = 'Pokemon table (re)built successfully.';
} elseif (isset($_GET['stats'])) { $file_db->exec("CREATE TABLE IF NOT EXISTS stats (
total_trainers INTEGER,
total_encounters INTEGER,
total_captures INTEGER
)");
$notice = 'Stats table (re)built successfully.';
} elseif (isset($_GET['adminlog'])) { $file_db->exec("CREATE TABLE IF NOT EXISTS adminlog (
id INTEGER PRIMARY KEY,
time INTEGER,
user INTEGER,
type INTEGER,
params TEXT,
extra TEXT
)");
$notice = 'Adminlog table (re)built successfully.';
} elseif (isset($_GET['trades'])) { $file_db->exec("CREATE TABLE IF NOT EXISTS trades (
id INTEGER PRIMARY KEY,
trainer1 INT,
pokemon1 TEXT,
trainer2 INT,
pokemon2 TEXT,
stage INT,
date INT,
code INT
)");
$notice = 'Trades table (re)built successfully.';
} elseif (isset($_GET['tradelog'])) { $file_db->exec("CREATE TABLE IF NOT EXISTS tradelog (
id INTEGER PRIMARY KEY,
trainer1 INT,
trainer2 INT,
pokemon1 TEXT,
pokemon2 TEXT,
date INT
)");
$notice = 'Tradelog table (re)built successfully.';
}
}
function layout_above($pagetitle, $pageheader) {
global $context, $baseurl, $smf_baseurl, $smf_scripturl, $notice;
echo '<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="sprite.css" rel="stylesheet" type="text/css" />
<link href=\'http://fonts.googleapis.com/css?family=Press+Start+2P\' rel=\'stylesheet\' type=\'text/css\'>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="script.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>';
if (isset($_GET['trainer']) || isset($_GET['trainer2'])) { echo'
<script>
$(function() {
$( "#maincontent" ).tabs();
});
</script>';
}
echo '
<script>
$(document).ready(function() { $("#pokemonselect").select2(); });
</script>
';
echo '
<script>
$(function() {
$( document ).tooltip({
position: {
my: "center bottom-20",
at: "center top",
using: function( position, feedback ) {
$( this ).css( position );
$( "<div>" )
.addClass( "arrow" )
.addClass( feedback.vertical )
.addClass( feedback.horizontal )
.appendTo( this );
}
}
});
});
</script>';
if (isset($_GET['admin'])) {
echo '<script type="text/javascript"><!-- // --><![CDATA[
var smf_theme_url = "'.$smf_baseurl.'Themes/rmrk7";
var smf_default_theme_url = "'.$smf_baseurl.'Themes/default";
var smf_images_url = "'.$smf_baseurl.'Themes/rmrk7/images";
var smf_scripturl = "'.$smf_scripturl.'";
var smf_iso_case_folding = false;
var smf_charset = "UTF-8";
var ajax_notification_text = "Loading...";
var ajax_notification_cancel_text = "Cancel";
// ]]></script>';
}
echo'
<title>',$pagetitle,'</title>
</head>
<body>
<div id="wrapper">',isset($notice)? $notice : '','
<a id="logo" href="."><img src="images/logo',( date('D') == "Sun" ? '_ss' : '' ),'.png" ',( date('D') == "Sun" ? 'title="Shiny Sunday! Encounters have 7% chance to be shiny!"' : '' ),'/></a><h1 id="pagetitle">',isset($pageheader)? $pageheader : '','</h1>
',$context['user']['is_logged'] ? '<a href="?trainer='.$context['user']['id'].'" style="float:right;clear:right;margin: -20px 10px 5px 5px;" title="Your Trainer Page"><img src="images/captured.png" /></a><a href="?pc" style="float:right;margin: -15px 10px 5px 5px;" title="Your Settings"><img src="images/pc.png" /></a><a href="?trade" style="float:right;margin: -20px 10px 5px 5px;" title="Trade Center"><img src="images/tradebag.png" /></a>' : '','
<div id="main">';
}
function layout_below() {
global $context, $pcfg;
echo '
</div>';
echo '
<div style="text-align: center; margin-top: 30px; border-top: 5px dashed #555; padding-top: 30px; font-size: 8px; line-height: 14px;">
<a href="?help" style="float:right;margin-right:20px;"><img src="images/help.png" title="RMRKMon Help" /></a>
<a href="http://rmrk.net/?board=270">RMRKMon Board</a> | RMRKMon is an <a href="http://rmrk.net/">RMRK</a> feature.<br>
Pokémon ©1995-2014 Nintendo, Creatures and GAME FREAK™</div>';
if ($pcfg['is_admin']) echo '<div style="text-align: center; margin-top: 30px; border-top: 5px dashed #555; padding-top: 30px; padding-bottom: 30px;"><a href="?admin"><img src="images/key.png" title="Administrate"></a></div>';
echo'
</div>
</body>
</html>';
}
function trainer_box($id) {
global $file_db, $userdata, $context, $smf_userdata, $admin_users, $baseurl, $pcfg, $pokemon;
if (isset($userdata)) {
if ($id != $userdata[0]['id']) {
$userdata = userdata($id);
echo '<!-- ID mismatch, reloaded userdata for trainerbox -->';
}
}
$smf_userdata = pokemon_fetchMember($member_ids = $id, $output_method = 'array');
echo '
<div class="trainer_box pokeborder">
'.( empty($userdata[0]['version']) ? '' : '<span style="color:'.$pcfg[ 'color'.$userdata[0]['version'] ].';" title="'.$pcfg[ 'version'.$userdata[0]['version'] ].'">•</span>').'',$smf_userdata[$id]['name'],' <a href="http://rmrk.net/?action=profile;u='.$id.'"><img src="images/rmrk_link.png" alt="RMRK Profile" /></a><hr>
',isset($userdata[0]['fave']) ? '<p class="trainerfave">' : '','
<img src="images/trainers/',$userdata[0]['trainerpic'],'.gif" class="trainerpic"/>';
if (isset($userdata[0]['fave'])) {
echo '<img class="trainer_fave_pokemon" src="'.$baseurl.'img/anim2/'.(is_shiny($userdata[0]['fave']) ? 'shiny/' : '').sprintf("%03d",round($userdata[0]['fave'])).'.gif" />';
}
echo'
',isset($userdata[0]['fave']) ? '</p>' : '','';
if (!empty($userdata[0]['extrafave'])) {
echo '<br>';
$userfaves = explode(',',$userdata[0]['extrafave']);
foreach ($userfaves as $ufave) {
echo '<img src="'.$baseurl.'img/small/'.(is_shiny($ufave) ? 'shiny/' : '').sprintf("%03d",round($ufave)).'.png" style="background:url(images/team_ball.png) center center no-repeat;" title="'.$pokemon[round($ufave)].(is_shiny($ufave) ? ' (Shiny)' : '').'">';
}
}
echo'
<hr>';
badge_strip($id, $userdata);
echo'
',empty($userdata[0]['lastcaught']) ? '' : '<div>Last Caught:<span> '.date('M jS, Y', $userdata[0]['lastcaught']).'</span></div>','
<div>Trainer Since:<span>',date('M jS, Y', $userdata[0]['starttime']),'</span></div><br><br><hr>
',empty($userdata[0]['seen']) ? '' : '<div>Pokemon Seen:<span> '.count(explode(',',$userdata[0]['seen'])).'</span></div>','
',empty($userdata[0]['pokemon']) ? '' : '<div>Pokemon Owned:<span> '.count(explode(',',$userdata[0]['pokemon'])).'</span></div>','
',empty($userdata[0]['dex']) ? '' : '<div>Pokedex Entries:<span> '.count(explode(',',$userdata[0]['dex'])).'</span></div>','';
if( ($context['user']['id'] == $id || $pcfg['is_admin'] == true) || ($userdata[0]['opentrade'] == 1 || in_array($context['user']['id'], $smf_userdata[$id]['buddies'])) && ($context['user']['is_logged']) ) {
echo '<br><br><br><hr>';
if ($context['user']['id'] == $id || $pcfg['is_admin'] == true) echo'<a style="margin: 0px auto;" href="?release='.$id.'"><img src="images/releasep.png" title="Release Pokemon" /></a> ';
if ( ($userdata[0]['opentrade'] == 1 || in_array($context['user']['id'], $smf_userdata[$id]['buddies']) ) && $id != $context['user']['id']) echo' <a style="margin: 0px auto;" href="?trade;open='.$id.'"><img src="images/tradeball.png" title="Trade with ',$smf_userdata[$id]['name'],'" /></a>';
if (!empty($userdata[0]['pokemon']) && $context['user']['id'] != $id) echo ' <a href="?compare='.$id.'"><img src="images/poke_diff.png" title="Compare Pokemon" /></a>';
}
echo'</div>';
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
if (isset($_GET['trainer2'])) {
$id = (int)$_GET['trainer2'];
//Who is this user?
$smf_userdata = ssi_fetchMember($member_ids = $id, $output_method = 'array');
if (empty($smf_userdata)) die('That user doesn\'t exist!');
//Does this user's pokemon trainer alter-ego exist?
$userdata = userdata($id);
if (empty($userdata)) {
layout_above('Trainer Profile: '.$smf_userdata[$id]['name'], $smf_userdata[$id]['name']);
echo 'This user hasn\'t seen or caught any pokemon yet, sorry!';
layout_below();
} else { //We have something to deal with
layout_above('Trainer Profile: '.$smf_userdata[$id]['name'], 'Trainer info: '.$smf_userdata[$id]['name']);
if (!empty($userdata[0]['fave'])) {
echo '<div id="faveback" style="background:url(img/global900/',sprintf("%03d",round($userdata[0]['fave'])),'.png) 100% 0% no-repeat;"></div>';
}
echo '<div style="text-align:center; margin-bottom: 10px; overflow:auto;" id="maincontent">';
trainer_box($id);
echo '<ul id="sectlinks">';
if (!empty($userdata[0]['pokemon'])) echo '<li><a style="background:#3890D8 url(images/bg_blue.png) bottom left repeat-x;color:#fff;" class="sectionlink pokeborder" href="#pokemon">Pokemon<img src="images/captured.png" /></a></li>
';
if (!empty($userdata[0]['seen'])) echo '<li><a style="background:#4BD08B url(images/bg_green.png) bottom left repeat-x;color:#fff;" class="sectionlink pokeborder" href="#seen">Sightings<img src="images/seen.png" /></a></li>
';
if (!empty($userdata[0]['dex'])) echo '<li><a style="background:#D86D37 url(images/bg_red.png) bottom left repeat-x;color:#fff;" class="sectionlink pokeborder" href="#dex">Pokedex<img src="images/pokedex.png" /></a></li>
';
echo '<div style="clear:both;"></div></ul>
<script type=\'text/javascript\'>//<![CDATA[
$(window).load(function(){
$(\'input\').keyup(function() {
filter(this);
});
function filter(element) {
var value = $(element).val();
$(".pbox").each(function () {
if ($(this).text().indexOf(value) > -1) {
$(this).show();
} else {
$(this).hide();
}
});
}
});//]]>
</script>
<div style="text-align:center; font-size: 8px; float:left; clear:both;">Filter: <input type="text"></div>';
if (!empty($userdata[0]['pokemon'])) {
echo '
<div id="pokemon">';
echo '
<div style="height: 20px;clear:both;"></div><div style="clear:both;padding: 20px 0px; text-align: center; border-top: 5px dashed #555;">Owned Pokemon:</div>
';
$owned_pokemon = explode(',',$userdata[0]['pokemon']);
sort($owned_pokemon);
//We only wish to show each pokemon once, but still recognise duplicates.
$dupe_check = array_count_values($owned_pokemon);
foreach ($owned_pokemon as $poke) {
if (isset($dupe_shown)) {
if (in_array($poke, $dupe_shown)) continue;
}
echo '
<div class="pbox pokeborder',(is_shiny($poke) ? ' shiny' : ''),'"><div class="pokenumber">#',round($poke),'</div>',cprite($poke, true),'<br>
<span',(is_shiny($poke) ? ' class="shiny flc"><span style="font-size:0;">!</span>' : ' class="flc">').strtolower($pokemon[round($poke)]),'</span>',$dupe_check[$poke] > 1 ? '<div class="multipoke"><img src="'.$baseurl.'images/pokeballsmall.png" />'.$dupe_check[$poke].'</div>' : '','</div>';
if ($dupe_check[$poke] > 1) {
$dupe_shown[] = $poke;
}
}
echo '
</div>';
}
if (!empty($userdata[0]['seen'])) {
echo '
<div id="seen">';
echo '
<div style="height: 20px;clear:both;"></div><div style="clear:both;padding: 20px 0px; text-align: center; border-top: 5px dashed #555;">Seen Pokemon:</div>';
$seen_pokemon = explode(',',$userdata[0]['seen']);
//To distinguish pokemon that they have only seen but not either owned or currently own, we'll compare to their pokedex.
$dex_pokemon = explode(',',$userdata[0]['dex']);
sort($seen_pokemon);
foreach ($seen_pokemon as $poke) {
echo '
<div class="pbox pokeborder',(is_shiny($poke) ? ' shiny' : ''),'"><div class="pokenumber">#',round($poke),'</div>',cprite($poke, true),'<br>
<span class="flc">',(is_shiny($poke) ? '<span style="font-size:0;">!</span>' : ''),'',strtolower($pokemon[round($poke)]),'</span></div>';
}
echo '
</div>';
}
if (!empty($userdata[0]['dex'])) {
echo '
<div id="dex">';
echo '
<div style="height: 20px;clear:both;"></div><div style="clear:both;padding: 20px 0px; text-align: center; border-top: 5px dashed #555;">Pokedex:</div>';
$dex_pokemon = explode(',',$userdata[0]['dex']);
sort($dex_pokemon);
foreach ($dex_pokemon as $poke) {
echo '
<div class="pbox pokeborder"><div class="pokenumber">#',round($poke),'</div>',cprite($poke, true),'<br>
<span class="flc">',strtolower($pokemon[round($poke)]),'</span></div>';
}
}
echo '</div>';
layout_below();
}
exit;
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
if (isset($_GET['trainer'])) {
$id = (int)$_GET['trainer'];
//Who is this user?
$smf_userdata = ssi_fetchMember($member_ids = $id, $output_method = 'array');
if (empty($smf_userdata)) die('That user doesn\'t exist!');
//Does this user's pokemon trainer alter-ego exist?
$userdata = userdata($id);
if (empty($userdata)) {
layout_above('Trainer Profile: '.$smf_userdata[$id]['name'], $smf_userdata[$id]['name']);
echo 'This user hasn\'t seen or caught any pokemon yet, sorry!';
layout_below();
} else { //We have something to deal with
layout_above('Trainer Profile: '.$smf_userdata[$id]['name'], 'Trainer info: '.$smf_userdata[$id]['name']);
if (!empty($userdata[0]['fave'])) {
echo '<div id="faveback" style="background:url(img/global900/',sprintf("%03d",round($userdata[0]['fave'])),'.png) 100% 0% no-repeat;"></div>';
}
echo '<div style="text-align:center; margin-bottom: 10px; overflow:auto;" id="maincontent">';
//Trainer stuff goes here.
if (!empty($userdata[0]['pokemon'])) {
$owned_pokemon = explode(',',$userdata[0]['pokemon']);
sort($owned_pokemon);
$total_owned = count($owned_pokemon);
} else $total_owned = 0;
if (!empty($userdata[0]['seen'])) {
$seen_pokemon = explode(',',$userdata[0]['seen']);
sort($seen_pokemon);
$total_seen = count($seen_pokemon);
} else $total_seen = 0;
if (!empty($userdata[0]['dex'])) {
$dex_pokemon = explode(',',$userdata[0]['dex']);
sort($dex_pokemon);
$total_dex = count($dex_pokemon);
$percent_dex = round( ((count($dex_pokemon) / count($pokemon)) * 100), 2 );
} else {
$total_dex = 0;
$percent_dex = 0;
}
if (empty($userdata[0]['trades'])) $total_trades = 0;
else {
$trades = explode(',', $userdata[0]['trades']);
$total_trades = count($trades);
}
//echo '<!-- ',print_r($userdata),' -->';
echo '<h1 style="text-align:left;font-family: \'pkmn\';font-size:22px;border-bottom: 2px dotted #555;padding-bottom: 2px;">',( empty($userdata[0]['version']) ? '' : '<span style="color:'.$pcfg[ 'color'.$userdata[0]['version'] ].'; font-size:28px;line-height:1px;text-shadow: 0px 0px 1px #fff;" title="'.$pcfg[ 'version'.$userdata[0]['version'] ].'">•</span>'),' ',$smf_userdata[$id]['name'],' ',badge_strip($id, $userdata, $output_method = "echo_nocruft"),'</h1><h1 style="font-family: \'pkmn\';font-size:22px;border-bottom: 2px dotted #555;padding: 2px 0; overflow:auto;text-align:left;"><div class="trainer2headericon">
<img src="images/captured1x.png" title="Number of pokemon owned" />',$total_owned,'
<img src="images/seen1x.png" title="Number of different pokemon seen" />',$total_seen,'
<img src="images/pokedex1x.png" title="Pokedex completion" />',$percent_dex,'%
<img src="images/sightings1x.png" title="Encounters" />',number_format($userdata[0]['sightings']),'
<img src="images/catches1x.png" title="Catches" />',number_format($userdata[0]['catches']),'
<img src="images/trades1x.png" title="Trades Performed" />',number_format($total_trades),'</div>';
if( ($context['user']['id'] == $id || $pcfg['is_admin'] == true) || ($userdata[0]['opentrade'] == 1 || in_array($context['user']['id'], $smf_userdata[$id]['buddies'])) && ($context['user']['is_logged']) ) {
if ($context['user']['id'] == $id || $pcfg['is_admin'] == true) echo'<a href="?release='.$id.'"><img src="images/releasep.png" title="Release Pokemon" /></a> ';
if ( ($userdata[0]['opentrade'] == 1 || in_array($context['user']['id'], $smf_userdata[$id]['buddies']) ) && $id != $context['user']['id']) echo' <a href="?trade;open='.$id.'"><img src="images/tradeball.png" title="Trade with ',$smf_userdata[$id]['name'],'" /></a>';
if (!empty($userdata[0]['pokemon']) && $context['user']['id'] != $id) echo ' <a href="?compare='.$id.'"><img src="images/poke_diff.png" title="Compare Pokemon" /></a>';
}
echo'
</h1>';
//Perhaps our trainer has chosen a favourite type? Else just default to normal (13)
if (empty($userdata[0]['favetype'])) $userdata[0]['favetype'] = 13;
echo '
<div id="trainerstage',isset($_GET['xy']) ? '-xy' : '','" style="background: url(',$baseurl,'images/stagebg/',$userdata[0]['favetype'],'.png) no-repeat center center;"><span class="valignhelper"></span><img src="images/trainers/',$userdata[0]['trainerpic'],'.gif" class="stagetrainer"/>';
if (isset($_GET['xy'])) $giftype = '';
else $giftype = '2';
//While testing, no checking.
if (!empty($userdata[0]['fave'])) echo '<img src="'.$baseurl.'img/anim',$giftype,'/'.(is_shiny($userdata[0]['fave']) ? 'shiny/' : '').sprintf("%03d",round($userdata[0]['fave'])).'.gif" />';
if (!empty($userdata[0]['extrafave'])) {
$efaves = explode(',',$userdata[0]['extrafave']);
foreach ($efaves as $ef) {
echo '<img src="'.$baseurl.'img/anim',$giftype,'/'.(is_shiny($ef) ? 'shiny/' : '').sprintf("%03d",round($ef)).'.gif" />';
}
}
echo'
</div>';
//print_r($userdata);
echo '<hr style="clear:both;">';
echo'
<ul id="sectlinks2">';
if (!empty($userdata[0]['pokemon'])) echo '<li style="background:#3890D8 url(images/bg_blue.png) bottom left repeat-x;color:#fff;" class="pokeborder"><a class="sectionlink2" href="#pokemon">Pokemon<img src="images/captured.png" /></a></li>
';
if (!empty($userdata[0]['seen'])) echo '<li style="background:#4BD08B url(images/bg_green.png) bottom left repeat-x;color:#fff;" class="pokeborder"><a class="sectionlink2" href="#seen">Sightings<img src="images/seen.png" /></a></li>
';
if (!empty($userdata[0]['dex'])) echo '<li style="background:#D86D37 url(images/bg_red.png) bottom left repeat-x;color:#fff;" class="pokeborder"><a class="sectionlink2" href="#dex">Pokedex<img src="images/pokedex.png" /></a></li>
';
echo '</ul>
<script type=\'text/javascript\'>//<![CDATA[
$(window).load(function(){
$(\'input\').keyup(function() {
filter(this);
});
function filter(element) {
var value = $(element).val();
$(".pbox").each(function () {
if ($(this).text().indexOf(value) > -1) {
$(this).show();
} else {
$(this).hide();
}
});
}
});//]]>
</script>
<div style="text-align:center; font-size: 8px; float:left; clear:both;">Filter: <input type="text"></div>';
if (!empty($userdata[0]['pokemon'])) {
echo '
<div id="pokemon">';
echo '
<div style="clear:both;text-align: center;">Owned Pokemon:</div><br>
';
//We only wish to show each pokemon once, but still recognise duplicates.
$dupe_check = array_count_values($owned_pokemon);
foreach ($owned_pokemon as $poke) {
if (isset($dupe_shown)) {
if (in_array($poke, $dupe_shown)) continue;
}
echo '
<div class="pbox pokeborder',(is_shiny($poke) ? ' shiny' : ''),'"><div class="pokenumber">#',round($poke),'</div>',cprite($poke, true),'<br>
<span',(is_shiny($poke) ? ' class="shiny flc"><span style="font-size:0;">!</span>' : ' class="flc">').strtolower($pokemon[round($poke)]),'</span>',$dupe_check[$poke] > 1 ? '<div class="multipoke"><img src="'.$baseurl.'images/pokeballsmall.png" />'.$dupe_check[$poke].'</div>' : '','</div>';
if ($dupe_check[$poke] > 1) {
$dupe_shown[] = $poke;
}
}
echo '
</div>';
}
if (!empty($userdata[0]['seen'])) {
echo '
<div id="seen">
<div style="clear:both;text-align: center;">Seen Pokemon:</div><br>';
//To distinguish pokemon that they have only seen but not either owned or currently own, we'll compare to their pokedex.
foreach ($seen_pokemon as $poke) {
echo '
<div class="pbox pokeborder',(is_shiny($poke) ? ' shiny' : ''),'"><div class="pokenumber">#',round($poke),'</div>',cprite($poke, true),'<br>
<span class="flc">',(is_shiny($poke) ? '<span style="font-size:0;">!</span>' : ''),'',strtolower($pokemon[round($poke)]),'</span></div>';
}
echo '
</div>';
}
if (!empty($userdata[0]['dex'])) {
echo '
<div id="dex">
<div style="clear:both;text-align: center;">Pokedex:</div><br>';
foreach ($dex_pokemon as $poke) {
echo '
<div class="pbox pokeborder"><div class="pokenumber">#',round($poke),'</div>',cprite($poke, true),'<br>
<span class="flc">',strtolower($pokemon[round($poke)]),'</span></div>';
}
}
echo '
</div>';
layout_below();
}
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
elseif (isset($_GET['pokemon'])) { //Let trainers see who owns what pokemon, how many times this pokemon has been caught / encountered and so on.
$poke = (int)$_GET['pokemon'];
if(!array_key_exists($poke, $pokemon)) {
layout_above('Error','No Pokemon');
echo 'No pokemon with that number! It may be that the system has not added that generation of pokemon yet.';
layout_below();
exit;
}
$pokedata = pokemondata($poke);
$has_trainers = false;
//Before we go further, if there are any owners or shiny owners we want to hit SMF to get their usernames.
$user_ids = array();
if (!empty($pokedata[0]['owners'])) {
//Our pokemon's owner and shiny_owner strings need to be arrays before we can deal with them.
$poke_owners = explode(',',$pokedata[0]['owners']);
if (!empty($poke_owners)) {
foreach ($poke_owners as $poke_owner) {
if (!in_array($poke_owner, $user_ids)) $user_ids[] = $poke_owner;
}
$has_trainers = true;
}
}
if (!empty($pokedata[0]['shiny_owners'])) {
$poke_shiny_owners = explode(',',$pokedata[0]['shiny_owners']);
if (!empty($poke_shiny_owners)) {
foreach ($poke_shiny_owners as $poke_shiny_owner) {
if (!in_array($poke_shiny_owner, $user_ids)) $user_ids[] = $poke_shiny_owner;
}
$has_trainers = true;
}
}
//Good to go. Assuming the pokemon is popular, this can unavoidably become a VERY! large query. Consider a custom SSI-style function that only returns what we need; ['name']!
if ($has_trainers == true) {
$smf_userdata = pokemon_fetchMember($member_ids = $user_ids, $output_method = 'array');
}
layout_above('Pokemon Data for '.$pokemon[$poke], '<img src="img/small/'.sprintf("%03d",$poke).'.png" /> '.$pokemon[$poke]);
echo '<div id="faveback" style="background:url(img/global900/'.sprintf("%03d",round($poke)).'.png) 90% 0% no-repeat;"></div>';
//If this is from a yet-to-be-enabled gen, say so.
if ($poke > $pcfg['pokemon_highest_enabled']) echo '<div class="pokeborder standard" style="line-height: 20px;">'.$info_symbol.' <span style="font-size:8px;">This pokemon is uncatchable until its generation is enabled.</span></div>';
//Show a fancy animated sprite of our pokemon, freshly ripped from X&Y!
echo '<img style="display:block; margin: 0 auto;" src="img/anim/'.sprintf("%03d",$poke).'.gif" />';
echo '<div style="text-align:center;padding: 5px 0px;">';
foreach ($p_type[$poke] as $ptype) {
echo '<a href="?type='.$type[$ptype].'"><img src="'.$baseurl.'images/types/'.$ptype.'.gif" /></a> ';
}
echo '</div>';
//Show a little box to allow quick navigation to the previous / next pokemon.
echo '
<div style="font-size: 8px; padding: 10px; margin: 0 auto;width: 70%; text-align: center; border: 2px dotted #555; margin-bottom: 10px;line-height: 26px;max-width: 600px;overflow:auto;">
', array_key_exists(($poke - 1), $pokemon) ? '<a style="float:left;text-decoration:none;" href="?pokemon='.($poke - 1).'"><-#'.sprintf("%03d",($poke - 1)).' '.$pokemon[($poke - 1)].'</a>' : '' ,'';
echo '
<form method="get" action="'.$baseurl.'" style="display:inline;margin-left: -15px;"><select id="pokemonselect" class="s2select" name="pokemon" data-placeholder="Select Pokemon">';
foreach ($pokemon as $key => $selpoke) {
echo '
<option'. ($key == $poke ? ' selected="selected"' : '') .' value="'.$key.'">#'.sprintf("%03d",$key).' '.$selpoke.'</option>';
}
echo'
</select> <input type="submit" value="Go"></form>';
echo'
', array_key_exists(($poke + 1), $pokemon) ? '<a style="float:right;text-decoration:none;" href="?pokemon='.($poke + 1).'">#'.sprintf("%03d",($poke + 1)).' '.$pokemon[($poke + 1)].'-></a>' : '' ,'';
if (!empty($evolves_from[$poke]) or !empty($evolves_to[$poke])) {
echo '<hr>';
if (!empty($evolves_from[$poke])) echo '<div style="float:left;width:49%;border-right: 2px dotted #555;">
Evolves from: <a href="?pokemon='.$evolves_from[$poke].'">'.$pokemon[$evolves_from[$poke]].'</a>
</div>';
if (!empty($evolves_to[$poke])) {
echo '<div style="float:right;width:49%;border-left:2px dotted #555;">Evolves to:';
foreach ($evolves_to[$poke] as $epoke) {
echo ' <a href="?pokemon='.$epoke.'">'.$pokemon[$epoke].'</a>';
}
echo '</div>';
}
}
echo'
</div>
<span style="display:block; clear:both; font-size: 8px; text-align:center; padding: 10px 0px;line-height: 20px;"><img src="images/bulba.png" style="margin-right: 5px;" alt="Bulbapedia Article" /><a href="http://bulbapedia.bulbagarden.net/wiki/'.$pokemon[$poke].'" target="_blank">'.$pokemon[$poke].'</a><br>';
echo'</span>';
//Show two boxes, one for normal and one for shiny.
echo '
<div class="pokeborder pokeinfo" style="float:left;">
<span class="pokename">',( $affinity[$poke] == 1 ? '<span style="color:'.$pcfg['color1'].';" title="Only '.$pcfg['version1'].' trainers encounter this pokemon">•</span>' : '' ),'',( $affinity[$poke] == 2 ? '<span style="color:'.$pcfg['color2'].';" title="Only '.$pcfg['version2'].' trainers encounter this pokemon">•</span>' : '' ),''.$pokemon[$poke].'</span><hr>
<div style="text-align: center; background:url('.$baseurl.'images/bases/'.$p_base[$poke].'.png) center 95% no-repeat;"><img src="img/anim2/'.sprintf("%03d",$poke).'.gif" /></div><hr style="clear:both;">
<textarea wrap="off" id="poken" style="width: 80%; height: 12px; padding: 2px; font-size: 8px;overflow:hidden;font-family: \'Press Start 2P\', sans-serif;" onclick="SelectAll(\'poken\')">[url='.$baseurl.'?pokemon='.$poke.';'.$pokemon[$poke].'][img]'.$baseurl.'img/named/'.sprintf("%03d",$poke).'.png[/img][/url]</textarea><hr>
<div>Times Encountered:<span>',$pokedata[0]['encounters'],'</span></div>
<div>Times Captured:<span>',$pokedata[0]['captures'],'</span></div>
<div>Encounter Chance:<span>',$e_chance[$poke],'%</span></div>
<br style="clear:both;">';
if (!empty($poke_owners)) {
echo'
<hr>
Trainers who own this pokemon:
<div style="line-height: 16px;">';
foreach ($poke_owners as $owner) {
echo '<a href="?trainer='.$owner.'">'.$smf_userdata[$owner]['name'].'</a> ';
}
echo'
</div>';
}
echo'
</div>';
//And now the shiny one.
echo '
<div class="pokeborder pokeinfo" style="float:right;">
<span class="pokename">',( $affinity[$poke] == 1 ? '<span style="color:'.$pcfg['color1'].';" title="Only '.$pcfg['version1'].' trainers encounter this pokemon">•</span>' : '' ),'',( $affinity[$poke] == 2 ? '<span style="color:'.$pcfg['color2'].';" title="Only '.$pcfg['version2'].' trainers encounter this pokemon">•</span>' : '' ),'Shiny '.$pokemon[$poke].'</span><hr>
<div style="text-align: center; background:url('.$baseurl.'images/bases/'.$p_base[$poke].'.png) center 95% no-repeat;"><img src="img/anim2/shiny/'.sprintf("%03d",$poke).'.gif" /></div><hr>
<textarea wrap="off" id="pokens" style="width: 80%; height: 12px; padding: 2px; font-size: 8px;overflow:hidden;font-family: \'Press Start 2P\', sans-serif;" onclick="SelectAll(\'pokens\')">[url='.$baseurl.'?pokemon='.$poke.';'.$pokemon[$poke].'(Shiny)][img]'.$baseurl.'img/named/shiny/'.sprintf("%03d",$poke).'.png[/img][/url]</textarea><hr>
<div>Times Encountered:<span>',$pokedata[0]['shiny_encounters'],'</span></div>
<div>Times Captured:<span>',$pokedata[0]['shiny_captures'],'</span></div>
<div>Encounter Chance:<span>1% of ',$e_chance[$poke],'%</span></div><br style="clear:both;">';
if (!empty($poke_shiny_owners)) {
echo'
<hr>
Trainers who own this pokemon:
<div style="line-height: 16px;">';
foreach ($poke_shiny_owners as $shiny_owner) {
echo '<a href="?trainer='.$shiny_owner.'">'.$smf_userdata[$shiny_owner]['name'].'</a> ';
}
echo'
</div>';
}
echo'
</div>';
echo '<div style="clear:both;"></div>';
layout_below();
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
elseif (isset($_GET['type'])) { //Just list pokemon according to a certain type.
//To be user friendly, we're linking type via text. Do a reverse lookup to convert it back to the ID.
$vtype = array_search($_GET['type'], $type);
if (empty($vtype)) {
layout_above('Error','Error');
echo 'No such type';
layout_below();
exit;
}
//We'll want to let the user check off their pokemon against this list. If we have a user viewing this page, at least.
if ($context['user']['is_logged']) {
$userdata = userdata($context['user']['id']);
$seen = explode(',',$userdata[0]['seen']);
$seen = array_map('round', $seen); //We don't care about shinies here.
$owned = explode(',',$userdata[0]['pokemon']);
$owned = array_map('round', $owned); //Or here!
$dex = explode(',',$userdata[0]['dex']);
}
layout_above($type[$vtype].' type Pokemon',$type[$vtype].' type Pokemon');
//First, let users quickly choose other types.
echo '
<div class="pokeborder standard" style="text-align:center;margin-bottom: 30px;"><h3>All Types</h3>
';
foreach ($type as $tkey => $ttype) {
echo '<a href="?type='.$ttype.'"><img src="'.$baseurl.'images/types/'.$tkey.'.gif" style="padding:5px;" /></a>';
}
echo'
</div>';
echo '<h2 style="text-align:center;font-size:24px;">'.$type[$vtype].' type Pokemon</h2>';
//We want a 2 column list here. Pokes that have $vtype as a main, then as a secondary type.
echo '
<div id="submain" style="background:url(images/vertical5px.png) top center repeat-y;overflow:auto;padding-bottom: 20px;">';
//First, pokemon who have this type as their main type.
echo '
<div class="trade" style="float:left;">
<h2 style="margin-bottom:8px;border-bottom:none;">Main Type</h2>';
foreach ($pokemon as $key => $poke) {
if ($p_type[$key][0] == $vtype) {
echo '<img src="'.$baseurl.'img/anim2/'.sprintf("%03d",$key).'.gif" style="float:left;border-top:2px dotted #555;"><h3 style="margin-left:96px;border-top:2px dotted #555;padding-top:4px;"><a href="?pokemon='.$key.'">#'.sprintf("%03d",$key).' '.$pokemon[$key].'</a>';
//As we're floating these, we need to reverse the order so they appear in the correct order again. If that makes sense. Uh
$ftype = array_reverse($p_type[$key]);
foreach ($ftype as $ptype) {
echo '<img src="'.$baseurl.'images/types/'.$ptype.'.gif" style="float:right;padding-top:6px;" />';
}
echo '</h3>';
if (isset($userdata)) { //If our viewer is logged in, let them check ownership.
echo '<div style="text-align:center;">';
if (in_array($key, $seen)) echo '<img src="'.$baseurl.'images/l_seen_yes.png" /> ';
else echo '<img src="'.$baseurl.'images/l_seen_no.png" /> ';
if (in_array($key, $owned)) echo '<img src="'.$baseurl.'images/l_owned_yes.png" /> ';
else echo '<img src="'.$baseurl.'images/l_owned_no.png" /> ';
if (in_array($key, $dex)) echo '<img src="'.$baseurl.'images/l_dex_yes.png" />';
else echo '<img src="'.$baseurl.'images/l_dex_no.png" />';
echo '</div>';
}
echo'
<div style="clear:both;padding:5px 0px;"></div>';
}
}
echo'
</div>';
//Now, pokemon who have this type as their secondary type.
echo '
<div class="trade" style="float:right;">
<h2 style="margin-bottom:8px;border-bottom:none;">Secondary Type</h2>';
foreach ($pokemon as $key => $poke) { //Not all pokes have secondary types.
if (array_key_exists(1, $p_type[$key])) {
if ($p_type[$key][1] == $vtype) {
echo '<img src="'.$baseurl.'img/anim2/'.sprintf("%03d",$key).'.gif" style="float:left;border-top:2px dotted #555;"><h3 style="margin-left:96px;border-top:2px dotted #555;padding-top:4px;"><a href="?pokemon='.$key.'">#'.sprintf("%03d",$key).' '.$pokemon[$key].'</a>';
//As we're floating these, we need to reverse the order so they appear in the correct order again. If that makes sense. Uh
$ftype = array_reverse($p_type[$key]);
foreach ($ftype as $ptype) {
echo '<img src="'.$baseurl.'images/types/'.$ptype.'.gif" style="float:right;padding-top:6px;" />';
}
echo '</h3>';
if (isset($userdata)) { //If our viewer is logged in, let them check ownership.
echo '<div style="text-align:center;">';
if (in_array($key, $seen)) echo '<img src="'.$baseurl.'images/l_seen_yes.png" /> ';
else echo '<img src="'.$baseurl.'images/l_seen_no.png" /> ';
if (in_array($key, $owned)) echo '<img src="'.$baseurl.'images/l_owned_yes.png" /> ';
else echo '<img src="'.$baseurl.'images/l_owned_no.png" /> ';
if (in_array($key, $dex)) echo '<img src="'.$baseurl.'images/l_dex_yes.png" />';
else echo '<img src="'.$baseurl.'images/l_dex_no.png" />';
echo '</div>';
}
echo'
<div style="clear:both;padding:5px 0px;"></div>';
}
}
}
echo'
</div>';
echo'
</div>';
layout_below();
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
elseif (isset($_GET['pc'])) { //Geddit? This is basically a control panel, manage our account, release pokemon and the like.
//We're not doing squat if you're not logged in.
if ($context['user']['is_guest']) {
layout_above('Error','Not Logged in');
layout_below();
die();
}
//You also need to have a trainer profile to be able to manage it.
$userdata = userdata($context['user']['id']);
if (empty($userdata)) {
layout_above('Error','No trainer profile');
echo 'You\'re not a pokemon trainer if you\'ve never encountered or caught any pokemon!';
layout_below();
die();
}
if (isset($_GET['team'])) {
if (isset($_POST['poke_pick'])) {
if ($_POST['sesc'] != $context['session_id']) { //We're still checking sessions though.
layout_above('Error','Error');
echo 'Something went wrong. Try logging out and back in.';
layout_below();
exit;
}
if (empty($_POST['poke_pick'])) { //Submitted an empty form? Dolt.
layout_above('Error','Error');
echo 'No Pokemon Selected!';
layout_below();
exit;
}
$userpokemon = explode(',', $userdata[0]['pokemon']);
//We should still validate that they own the pokemon. This also weeds out malicious submissions.
foreach ($_POST['poke_pick'] as $picked_poke) {
if (in_array($picked_poke, $userpokemon)) {
foreach ($userpokemon as $key => $value) {
if ($value == $picked_poke) {
unset($userpokemon[$key]);
break;
}
}
} else {
layout_above('Error','Error');
echo 'Unowned pokemon submitted';
layout_below();
exit;
}
}
//All safe, all confirmed, good to go.
$submitted_pokemon = implode(',', $_POST['poke_pick']);
update_trainer($context['user']['id'], 'extrafave', $submitted_pokemon);
//Now confirm for them their new team.
layout_above('Team Updated','Team Updated');
echo 'Here is your new team:<br><br>
<div style="text-align:center;">';
echo '<img src="'.$baseurl.'images/trainers/'.$userdata[0]['trainerpic'].'.gif"/><img src="'.$baseurl.'img/anim2/'.(is_shiny($userdata[0]['fave']) ? 'shiny/' : '' ).''.sprintf("%03d", $userdata[0]['fave']).'.gif"/>';
foreach ($_POST['poke_pick'] as $poke) {
echo '<img src="'.$baseurl.'img/anim2/'.(is_shiny($poke) ? 'shiny/' : '' ).''.sprintf("%03d", $poke).'.gif" style="margin-left:-10px;" />';
}
echo '</div>';
layout_below();
exit;
}
layout_above('Choose Team','Choose Team');
echo 'Choose 5 Pokemon from your collection to join your '.$pokemon[round($userdata[0]['fave'])].'.<br><br>';
echo '
<script type="text/javascript">
jQuery(function(){
var max = 5;
var checkboxes = $(\'input[type="checkbox"]\');
checkboxes.change(function(){
var current = checkboxes.filter(\':checked\').length;
checkboxes.filter(\':not(:checked)\').prop(\'disabled\', current >= max);
});
});
</script>
<form method="post" action="?pc;team" id="release">';
$pokecounter = 0;
$owned_pokemon = explode(',',$userdata[0]['pokemon']);
sort($owned_pokemon);