-
Notifications
You must be signed in to change notification settings - Fork 1
/
teams.php
884 lines (794 loc) · 34.9 KB
/
teams.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
<?php
// Blacknova Traders - A web-based massively multiplayer space combat and trading game
// Copyright (C) 2001-2012 Ron Harwood and the BNT development team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// File: teams.php
// Added a quick fix for creating a new team with the same name
// This file needs to be completely recoded from scratch :(
include "config/config.php";
updatecookie();
// New database driven language entries
load_languages($db, $lang, array('teams', 'common', 'global_includes', 'global_funcs', 'footer'), $langvars, $db_logging);
$title = $l_team_title;
include "header.php";
include_once "includes/defence_vs_defence.php";
include_once "includes/kick_off_planet.php";
if (checklogin())
{
die();
}
?>
<div class="tablecell content both-border">
<div class="pad">
<?
bigtitle();
$testing = false; // set to false to get rid of password when creating new team
// Typecast into integers (this also removes all non numbers)
$whichteam = null;
if (array_key_exists('whichteam', $_REQUEST) == true)
{
$whichteam = (int)$_REQUEST['whichteam'];
}
$teamwhat = null;
if (array_key_exists('teamwhat', $_REQUEST) == true)
{
$teamwhat = (int)$_REQUEST['teamwhat'];
}
$confirmleave = null;
if (array_key_exists('confirmleave', $_REQUEST) == true)
{
$confirmleave = stripnum($_REQUEST['confirmleave']);
}
$invited = null;
if (array_key_exists('invited', $_REQUEST) == true)
{
$invited = stripnum($_REQUEST['invited']);
}
$teamname = null;
if (array_key_exists('teamname', $_POST) == true)
{
$teamname = $_POST['teamname'];
}
$confirmed = null;
if (array_key_exists('confirmed', $_REQUEST) == true)
{
$confirmed = stripnum($_REQUEST['confirmed']);
}
$update = null;
if (array_key_exists('update', $_POST) == true)
{
$update = $_POST['update'];
}
$who = null;
if (array_key_exists('who', $_REQUEST) == true)
{
$who = (int)$_REQUEST['who'];
}
// Setting up some recordsets.
// I noticed before the rewriting of this page that in some case recordset may be fetched more thant once, which is NOT optimized.
// Get user info.
$result = $db->Execute("SELECT {$db->prefix}ships.*, {$db->prefix}teams.team_name, {$db->prefix}teams.description, {$db->prefix}teams.creator, {$db->prefix}teams.id
FROM {$db->prefix}ships
LEFT JOIN {$db->prefix}teams ON {$db->prefix}ships.team = {$db->prefix}teams.id
WHERE {$db->prefix}ships.ship_id='$user_ship_id'") or die($db->ErrorMsg());
db_op_result ($db, $result, __LINE__, __FILE__, $db_logging);
$playerinfo = $result->fields;
// We do not want to query the database, if it is not necessary.
if ($playerinfo['team_invite'] != 0)
{
// Get invite info
$invite = $db->Execute(" SELECT {$db->prefix}ships.ship_id, {$db->prefix}ships.team_invite, {$db->prefix}teams.team_name,{$db->prefix}teams.id
FROM {$db->prefix}ships
LEFT JOIN {$db->prefix}teams ON {$db->prefix}ships.team_invite = {$db->prefix}teams.id
WHERE {$db->prefix}ships.ship_id='$user_ship_id'") or die($db->ErrorMsg());
db_op_result ($db, $invite, __LINE__, __FILE__, $db_logging);
$invite_info = $invite->fields;
}
// Get Team Info
if (!is_null($whichteam))
{
$result_team = $db->Execute("SELECT * FROM {$db->prefix}teams WHERE id=?;", array($whichteam)) or die($db->ErrorMsg());
db_op_result ($db, $result_team, __LINE__, __FILE__, $db_logging);
$team = $result_team->fields;
}
else
{
$result_team = $db->Execute("SELECT * FROM {$db->prefix}teams WHERE id=?;", array($playerinfo['team'])) or die($db->ErrorMsg());
db_op_result ($db, $result_team, __LINE__, __FILE__, $db_logging);
$team = $result_team->fields;
}
switch ($teamwhat)
{
case 1: // INFO on single team
{
showinfo($whichteam, 0);
LINK_BACK();
break;
}
case 2: // LEAVE
{
if (!isTeamMember($team, $playerinfo))
{
echo "<strong><font color=red>An error occured</font></strong><br>You are not a member of this Team.";
LINK_BACK();
break;
}
if (is_null($confirmleave))
{
echo "$l_team_confirmleave <strong>$team[team_name]</strong> ? <a href=\"teams.php?teamwhat=$teamwhat&confirmleave=1&whichteam=$whichteam\">$l_yes</a> - <a href=\"teams.php\">$l_no</a><br><br>";
}
elseif ($confirmleave == 1)
{
if ($team['number_of_members'] == 1)
{
if (!isTeamOwner($team, $playerinfo))
{
$l_team_error = str_replace("[error]", "<strong><font color=red>An error occured</font></strong><br>", $l_team_error);
echo $l_team_error;
LINK_BACK();
continue;
}
$resx = $db->Execute("DELETE FROM {$db->prefix}teams WHERE id=?;", array($whichteam));
db_op_result ($db, $resx, __LINE__, __FILE__, $db_logging);
$resy = $db->Execute("UPDATE {$db->prefix}ships SET team='0' WHERE ship_id=?;", array($playerinfo['ship_id']));
db_op_result ($db, $resy, __LINE__, __FILE__, $db_logging);
$resz = $db->Execute("UPDATE {$db->prefix}ships SET team_invite = 0 WHERE team_invite=?;", array($whichteam));
db_op_result ($db, $resz, __LINE__, __FILE__, $db_logging);
$res = $db->Execute("SELECT DISTINCT sector_id FROM {$db->prefix}planets WHERE owner=? AND base='Y';", array($playerinfo['ship_id']));
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
$i=0;
while (!$res->EOF)
{
$row = $res->fields;
$sectors[$i] = $row['sector_id'];
$i++;
$res->MoveNext();
}
$resx = $db->Execute("UPDATE {$db->prefix}planets SET corp=0 WHERE owner=?;", array($playerinfo['ship_id']));
db_op_result ($db, $resx, __LINE__, __FILE__, $db_logging);
if (!empty($sectors))
{
foreach ($sectors as $sector)
{
calc_ownership($sector);
}
}
defence_vs_defence ($db, $playerinfo['ship_id']);
kick_off_planet($db, $playerinfo['ship_id'], $whichteam);
$l_team_onlymember = str_replace("[team_name]", "<strong>$team[team_name]</strong>", $l_team_onlymember);
echo $l_team_onlymember . "<br><br>";
playerlog ($db, $playerinfo['ship_id'], LOG_TEAM_LEAVE, $team['team_name']);
}
else
{
if (isTeamOwner($team, $playerinfo))
{
echo "$l_team_youarecoord <strong>$team[team_name]</strong>. $l_team_relinq<br><br>";
echo "<form action='teams.php' method=post>";
echo "<table><input type=hidden name=teamwhat value=$teamwhat><input type=hidden name=confirmleave value=2><input type=hidden name=whichteam value=$whichteam>";
echo "<tr><td>$l_team_newc</td><td><select name=newcreator>";
$res = $db->Execute("SELECT character_name,ship_id FROM {$db->prefix}ships WHERE team=? ORDER BY character_name ASC;", array($whichteam));
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
while (!$res->EOF)
{
$row = $res->fields;
if (!isTeamOwner($team, $row))
{
echo "<option value='{$row['ship_id']}'>{$row['character_name']}";
}
$res->MoveNext();
}
echo "</select></td></tr>";
echo "<tr><td><input type=submit value=$l_submit></td></tr>";
echo "</table>";
echo "</form>";
}
else
{
$resx = $db->Execute("UPDATE {$db->prefix}ships SET team='0' WHERE ship_id=?;", array($playerinfo['ship_id']));
db_op_result ($db, $resx, __LINE__, __FILE__, $db_logging);
$resy = $db->Execute("UPDATE {$db->prefix}teams SET number_of_members=number_of_members-1 WHERE id=?;", array($whichteam));
db_op_result ($db, $resy, __LINE__, __FILE__, $db_logging);
$res = $db->Execute("SELECT DISTINCT sector_id FROM {$db->prefix}planets WHERE owner=? AND base='Y' AND corp!=0;", array($playerinfo['ship_id']));
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
$i=0;
while (!$res->EOF)
{
$sectors[$i] = $res->fields['sector_id'];
$i++;
$res->MoveNext();
}
$resx = $db->Execute("UPDATE {$db->prefix}planets SET corp=0 WHERE owner=?;", array($playerinfo['ship_id']));
db_op_result ($db, $resx, __LINE__, __FILE__, $db_logging);
if (!empty($sectors))
{
foreach ($sectors as $sector)
{
calc_ownership($sector);
}
}
echo "$l_team_youveleft <strong>$team[team_name]</strong>.<br><br>";
defence_vs_defence($db, $playerinfo['ship_id']);
kick_off_planet ($db, $playerinfo['ship_id'], $whichteam);
playerlog ($db, $playerinfo['ship_id'], LOG_TEAM_LEAVE, $team['team_name']);
playerlog ($db, $team['creator'], LOG_TEAM_NOT_LEAVE, $playerinfo['character_name']);
}
}
}
elseif ($confirmleave == 2)
{
// owner of a team is leaving and set a new owner
$res = $db->Execute("SELECT character_name FROM {$db->prefix}ships WHERE ship_id=?;", array($newcreator));
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
$newcreatorname = $res->fields;
echo "$l_team_youveleft <strong>$team[team_name]</strong> $l_team_relto $newcreatorname[character_name].<br><br>";
$resx = $db->Execute("UPDATE {$db->prefix}ships SET team='0' WHERE ship_id=?;", array($playerinfo['ship_id']));
db_op_result ($db, $resx, __LINE__, __FILE__, $db_logging);
$resy = $db->Execute("UPDATE {$db->prefix}ships SET team=? WHERE team=?;", array($newcreator, $creator));
db_op_result ($db, $resy, __LINE__, __FILE__, $db_logging);
$resz = $db->Execute("UPDATE {$db->prefix}teams SET number_of_members = number_of_members - 1, creator=? WHERE id=?;", array($newcreator, $whichteam));
db_op_result ($db, $resz, __LINE__, __FILE__, $db_logging);
$res = $db->Execute("SELECT DISTINCT sector_id FROM {$db->prefix}planets WHERE owner=? AND base='Y' AND corp!=0;", array($playerinfo['ship_id']));
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
$i=0;
while (!$res->EOF)
{
$sectors[$i] = $res->fields['sector_id'];
$i++;
$res->MoveNext();
}
$resx = $db->Execute("UPDATE {$db->prefix}planets SET corp=0 WHERE owner=?;", array($playerinfo['ship_id']));
db_op_result ($db, $resx, __LINE__, __FILE__, $db_logging);
if (!empty($sectors))
{
foreach ($sectors as $sector)
{
calc_ownership($sector);
}
}
playerlog ($db, $playerinfo['ship_id'], LOG_TEAM_NEWLEAD, $team['team_name'] ."|". $newcreatorname['character_name']);
playerlog ($db, $newcreator, LOG_TEAM_LEAD, $team['team_name']);
}
LINK_BACK();
break;
}
case 3: // JOIN
{
if ($playerinfo['team'] != 0)
{
echo $l_team_leavefirst . "<br>";
}
else
{
if ($playerinfo['team_invite'] == $whichteam)
{
$resx = $db->Execute("UPDATE {$db->prefix}ships SET team=?, team_invite=0 WHERE ship_id=?;", array($whichteam, $playerinfo['ship_id']));
db_op_result ($db, $resx, __LINE__, __FILE__, $db_logging);
$resy = $db->Execute("UPDATE {$db->prefix}teams SET number_of_members=number_of_members+1 WHERE id=?;", array($whichteam));
db_op_result ($db, $resy, __LINE__, __FILE__, $db_logging);
echo "$l_team_welcome <strong>$team[team_name]</strong>.<br><br>";
playerlog ($db, $playerinfo['ship_id'], LOG_TEAM_JOIN, $team['team_name']);
playerlog ($db, $team['creator'], LOG_TEAM_NEWMEMBER, $team['team_name'] ."|". $playerinfo['character_name']);
}
else
{
echo "$l_team_noinviteto<br>";
}
}
LINK_BACK();
break;
}
case 4:
{
echo "Not implemented yet. Sorry! :)<br><br>";
LINK_BACK();
break;
}
case 5: // Eject member
{
// Check if Co-ordinator of team.
// If not display "An error occured, You are not the leader of this Team." message.
// Then show link back and break;
if (isTeamOwner($team, $playerinfo) == false)
{
$l_team_error = str_replace("[error]", "<strong><font color=red>An error occured</font></strong><br>", $l_team_error);
echo $l_team_error;
LINK_BACK();
continue;
}
else
{
$who = stripnum($who);
$result = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE ship_id=?;", array($who));
db_op_result ($db, $result, __LINE__, __FILE__, $db_logging);
$whotoexpel = $result->fields;
if (is_null($confirmed))
{
echo "$l_team_ejectsure $whotoexpel[character_name]? <a href=\"teams.php?teamwhat=$teamwhat&confirmed=1&who=$who\">$l_yes</a> - <a href=\"teams.php\">$l_no</a><br>";
}
else
{
// check whether the player we are ejecting might have already left in the meantime
// should go here if ($whotoexpel[team] ==
$resx = $db->Execute("UPDATE {$db->prefix}planets SET corp='0' WHERE owner=?;", array($who));
db_op_result ($db, $resx, __LINE__, __FILE__, $db_logging);
$resy = $db->Execute("UPDATE {$db->prefix}ships SET team = '0' WHERE ship_id=?;", array($who));
db_op_result ($db, $resy, __LINE__, __FILE__, $db_logging);
// No more necessary due to COUNT(*) in previous SQL statement
$db->Execute("UPDATE {$db->prefix}teams SET number_of_members=number_of_members-1 WHERE id=?;", array($whotoexpel['team']));
playerlog ($db, $who, LOG_TEAM_KICK, $team['team_name']);
echo "$whotoexpel[character_name] $l_team_ejected<br>";
}
LINK_BACK();
}
break;
}
case 6: // Create Team
{
if ($playerinfo['team'] != 0)
{
echo $l_team_leavefirst . "<br>";
LINK_BACK();
continue;
}
if (is_null($teamname))
{
echo "<form action='teams.php' method='post'>\n";
echo $l_team_entername . ": ";
echo "<input type='hidden' name='teamwhat' value='{$teamwhat}'>\n";
echo "<input type='text' name='teamname' size='40' maxlength='40'><br>\n";
echo $l_team_enterdesc . ": ";
echo "<input type='text' name='teamdesc' size='40' maxlength='254'><br>\n";
echo "<input type='submit' value='{$l_submit}'><input type='reset' value='{$l_reset}'>\n";
echo "</form>\n";
echo "<br><br>\n";
}
else
{
$teamname = trim(htmlspecialchars($teamname));
$teamdesc = trim(htmlspecialchars($teamdesc));
if (!validate_team($teamname, $teamdesc, $playerinfo['ship_id']))
{
echo "<span style='color:#f00;'>Team Creation Failed</span><br>Sorry you have either entered an invalid Team name or Team Description.<br>\n";
LINK_BACK();
break;
}
$res = $db->Execute("INSERT INTO {$db->prefix}teams (id, creator, team_name, number_of_members, description) VALUES (?, ?, ?, '1', ?);", array($playerinfo['ship_id'], $playerinfo['ship_id'], $teamname, $teamdesc));
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
$resx = $db->Execute("INSERT INTO {$db->prefix}zones VALUES(NULL, ?, ?, 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 0);", array("{$teamname}\'s Empire", $playerinfo['ship_id']));
db_op_result ($db, $resx, __LINE__, __FILE__, $db_logging);
$resy = $db->Execute("UPDATE {$db->prefix}ships SET team=? WHERE ship_id=?;", array($playerinfo['ship_id'], $playerinfo['ship_id']));
db_op_result ($db, $resy, __LINE__, __FILE__, $db_logging);
echo "$l_team_team <strong>$teamname</strong> $l_team_hcreated.<br><br>";
playerlog ($db, $playerinfo['ship_id'], LOG_TEAM_CREATE, $teamname);
}
LINK_BACK();
break;
}
case 7: // INVITE player
{
if (isTeamMember($team, $playerinfo) == false)
{
echo "<br>You are not in this team!<br>";
LINK_BACK();
break;
}
if (is_null($invited))
{
echo "<form action='teams.php' method=post>";
echo "<table><input type=hidden name=teamwhat value=$teamwhat><input type=hidden name=invited value=1><input type=hidden name=whichteam value=$whichteam>";
echo "<tr><td>$l_team_selectp:</td><td><select name=who style='width:200px;'>";
$res = $db->Execute("SELECT character_name,ship_id, team FROM {$db->prefix}ships WHERE team<>? AND ship_destroyed ='N' AND turns_used >0 ORDER BY character_name ASC;", array($whichteam));
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
while (!$res->EOF)
{
$row = $res->fields;
if (isTeamOwner($team, $row) == false)
{
echo "<option value='{$row['ship_id']}'>{$row['character_name']}";
}
$res->MoveNext();
}
echo "</select></td></tr>";
echo "<tr><td><input type='submit' value='{$l_submit}'></td></tr>";
echo "</table>";
echo "</form>";
}
else
{
if ($playerinfo['team'] == $whichteam)
{
if (is_null($who))
{
echo "No player was selected.<br>\n";
echo "<br><br><a href=\"teams.php\">$l_clickme</a> $l_team_menu<br><br>";
break;
}
$res = $db->Execute("SELECT character_name,team_invite FROM {$db->prefix}ships WHERE ship_id=?;", array($who));
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
$newpl = $res->fields;
if ($newpl['team_invite'])
{
$l_team_isorry = str_replace("[name]", $newpl['character_name'], $l_team_isorry);
echo $l_team_isorry . "<br><br>";
}
else
{
$resx = $db->Execute("UPDATE {$db->prefix}ships SET team_invite=? WHERE ship_id=?;", array($whichteam, $who));
db_op_result ($db, $resx, __LINE__, __FILE__, $db_logging);
echo $l_team_plinvted . "<br>" . $l_team_plinvted2 . "<br>";
playerlog ($db, $who, LOG_TEAM_INVITE, $team['team_name']);
}
}
else
{
echo $l_team_notyours . "<br>";
}
}
echo "<br><br><a href=\"teams.php\">$l_clickme</a> $l_team_menu<br><br>";
break;
}
case 8: // REFUSE invitation
{
echo "$l_team_refuse <strong>$invite_info[team_name]</strong>.<br><br>";
$resx = $db->Execute("UPDATE {$db->prefix}ships SET team_invite=0 WHERE ship_id=?;", array($playerinfo['ship_id']));
db_op_result ($db, $resx, __LINE__, __FILE__, $db_logging);
playerlog ($db, $team['creator'], LOG_TEAM_REJECT, $playerinfo['character_name'] ."|". $invite_info['team_name']);
LINK_BACK();
break;
}
case 9: // Edit Team
{
// Check if Co-ordinator of team.
// If not display "An error occured, You are not the leader of this Team." message.
// Then show link back and break;
if (isTeamOwner($team, $playerinfo) == false)
{
$l_team_error = str_replace("[error]", "<strong><font color=red>An error occured</font></strong><br>", $l_team_error);
echo $l_team_error;
LINK_BACK();
break;
}
if (is_null($update))
{
echo "<form action='teams.php' method='post'>";
echo $l_team_edname . ": <br>";
echo "<input type='hidden' name='teamwhat' value='{$teamwhat}'>";
echo "<input type='hidden' name='whichteam' value='{$whichteam}'>";
echo "<input type='hidden' name='update' value='true'>";
echo "<input type='text' name='teamname' size='40' maxlength='40' value='{$team['team_name']}'><br>";
echo $l_team_eddesc . ": <br>";
echo "<input type='text' name='teamdesc' size='40' maxlength='254' value='{$team['description']}'><br>";
echo "<input type='submit' value='{$l_submit}'><input type='reset' value='{$l_reset}'>";
echo "</form>";
echo "<br><br>";
}
else
{
$teamname = trim(htmlspecialchars($teamname));
$teamdesc = trim(htmlspecialchars($teamdesc));
if (validate_team($teamname, $teamdesc, $playerinfo['ship_id']) == false)
{
echo "<span style='color:#f00;'>Team Edit Failed</span><br>Sorry you have either entered an invalid Team name or Team Description.<br>\n";
LINK_BACK();
break;
}
$res = $db->Execute("UPDATE {$db->prefix}teams SET team_name=?, description=? WHERE id=?;", array($teamname, $teamdesc, $whichteam)) or die("<font color=red>error: " . $db->ErrorMSG() . "</font>");
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
echo "$l_team_team <strong>$teamname</strong> $l_team_hasbeenr<br><br>";
// Adding a log entry to all members of the renamed team
$result_team_name = $db->Execute("SELECT ship_id FROM {$db->prefix}ships WHERE team=? AND ship_id<>?;", array($whichteam, $playerinfo['ship_id'])) or die("<font color=red>error: " . $db->ErrorMsg() . "</font>");
db_op_result ($db, $result_team_name, __LINE__, __FILE__, $db_logging);
playerlog ($db, $playerinfo['ship_id'], LOG_TEAM_RENAME, $teamname);
while (!$result_team_name->EOF)
{
$teamname_array = $result_team_name->fields;
playerlog ($db, $teamname_array['ship_id'], LOG_TEAM_M_RENAME, $teamname);
$result_team_name->MoveNext();
}
}
LINK_BACK();
break;
}
default:
{
if ($playerinfo['team'] == 0)
{
echo $l_team_notmember;
DISPLAY_INVITE_INFO();
}
else
{
if ($playerinfo['team'] < 0)
{
$playerinfo['team'] = -$playerinfo['team'];
$result = $db->Execute("SELECT * FROM {$db->prefix}teams WHERE id=?;", array($playerinfo['team']));
db_op_result ($db, $result, __LINE__, __FILE__, $db_logging);
$whichteam = $result->fields;
echo "$l_team_urejected <strong>$whichteam[team_name]</strong><br><br>";
LINK_BACK();
break;
}
$result = $db->Execute("SELECT * FROM {$db->prefix}teams WHERE id=?;", array($playerinfo['team']));
db_op_result ($db, $result, __LINE__, __FILE__, $db_logging);
$whichteam = $result->fields;;
if ($playerinfo['team_invite'])
{
$result = $db->Execute("SELECT * FROM {$db->prefix}teams WHERE id=?;", array($playerinfo['team_invite']));
db_op_result ($db, $result, __LINE__, __FILE__, $db_logging);
$whichinvitingteam = $result->fields;
}
$isowner = isTeamOwner($whichteam, $playerinfo);
showinfo($playerinfo['team'], $isowner);
}
$res= $db->Execute("SELECT COUNT(*) as TOTAL FROM {$db->prefix}teams WHERE admin='N';");
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
$num_res = $res->fields;
if ($num_res['TOTAL'] > 0)
{
DISPLAY_ALL_TEAMS();
}
else
{
echo $l_team_noteams . "<br><br>";
}
break;
}
} // End of switch.
echo "<br><br>";
TEXT_GOTOMAIN();
function isTeamMember($team, $playerinfo)
{
// Check to see if the player is in a team? if not return false right there, else carry on.
if ($playerinfo['team'] == 0)
{
return false;
}
// Check to see if the player is a member of $team['id'] if so return true, else return false.
if ($playerinfo['team'] == $team['id'])
{
return true;
}
else
{
return false;
}
}
function isTeamOwner($team, $playerinfo)
{
// Check to see if the player is in a team? if not return false right there, else carry on.
if ($playerinfo['team'] == 0)
{
return false;
}
// Check to see if the player is the Owner of $team['creator'] if so return true, else return false.
if ($playerinfo['ship_id'] == $team['creator'])
{
return true;
}
else
{
return false;
}
}
function LINK_BACK()
{
global $l_clickme, $l_team_menu;
echo "<br><br><a href=\"teams.php\">$l_clickme</a> $l_team_menu.<br><br>";
}
// Rewritten display of teams list
function DISPLAY_ALL_TEAMS()
{
global $color, $color_line1, $color_line2, $color_header, $order, $type, $l_team_galax, $l_team_members, $l_team_member, $l_team_coord, $l_score, $l_name;
global $db;
global $db_logging;
echo "<br><br>$l_team_galax<br>";
echo "<table style='width:100%; border:#fff 1px solid;' border='0' cellspacing='0' cellpadding='2'>";
echo "<tr bgcolor=\"$color_header\">";
if ($type == "d")
{
$type = "a";
$by = "ASC";
}
else
{
$type = "d";
$by = "DESC";
}
echo "<td><strong><a class='new_link' style='font-size:14px;' href=teams.php?order=team_name&type=$type>$l_name</a></strong></td>";
echo "<td><strong><a class='new_link' style='font-size:14px;' href=teams.php?order=number_of_members&type=$type>$l_team_members</a></strong></td>";
echo "<td><strong><a class='new_link' style='font-size:14px;' href=teams.php?order=character_name&type=$type>$l_team_coord</a></strong></td>";
echo "<td><strong><a class='new_link' style='font-size:14px;' href=teams.php?order=total_score&type=$type>$l_score</a></strong></td>";
echo "</tr>";
$sql_query = "SELECT {$db->prefix}ships.character_name,
COUNT(*) as number_of_members,
ROUND(SQRT(SUM(POW({$db->prefix}ships.score,2)))) as total_score,
{$db->prefix}teams.id,
{$db->prefix}teams.team_name,
{$db->prefix}teams.creator
FROM {$db->prefix}ships
LEFT JOIN {$db->prefix}teams ON {$db->prefix}ships.team = {$db->prefix}teams.id
WHERE {$db->prefix}ships.team = {$db->prefix}teams.id AND admin='N'
GROUP BY {$db->prefix}teams.team_name";
// Setting if the order is Ascending or descending, if any.
// Default is ordered by teams.team_name
if ($order)
{
$sql_query .= " ORDER BY " . $order . " $by";
}
$sql_query .= ";";
$res = $db->Execute($sql_query) or die($db->ErrorMsg());
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
$color = $color_line1;
while (!$res->EOF)
{
$row = $res->fields;
echo "<tr bgcolor=\"$color\">";
echo "<td><a href='teams.php?teamwhat=1&whichteam={$row['id']}'>{$row['team_name']}</a></td>";
echo "<td>{$row['number_of_members']}</td>";
// This fixes it so that it actually displays the coordinator, and not the first member of the team.
$res2 = $db->Execute("SELECT character_name FROM {$db->prefix}ships WHERE ship_id = ?;", array($row['creator'])) or die($db->ErrorMsg());
db_op_result ($db, $res2, __LINE__, __FILE__, $db_logging);
while (!$res2->EOF)
{
$row2 = $res2->fields;
$res2->MoveNext();
}
// If there is a way to redo the original sql query instead, please, do so, but I didnt see a way to.
echo "<td><a href='mailto2.php?name={$row2['character_name']}'>{$row2['character_name']}</a></td>";
echo "<td>{$row['total_score']}</td>";
echo "</tr>";
if ($color == $color_line1)
{
$color = $color_line2;
}
else
{
$color = $color_line1;
}
$res->MoveNext();
}
echo "</table><br>";
}
function DISPLAY_INVITE_INFO()
{
global $playerinfo, $invite_info, $l_team_noinvite, $l_team_ifyouwant, $l_team_tocreate, $l_clickme, $l_team_injoin, $l_team_tojoin, $l_team_reject, $l_team_or;
if (!$playerinfo['team_invite'])
{
echo "<br><br><font color=blue size=2><strong>$l_team_noinvite</strong></font><br>";
echo $l_team_ifyouwant . "<br>";
echo "<a href=\"teams.php?teamwhat=6\">$l_clickme</a> $l_team_tocreate<br><br>";
}
else
{
echo "<br><br><font color=blue size=2><strong>$l_team_injoin ";
echo "<a href=teams.php?teamwhat=1&whichteam=$playerinfo[team_invite]>$invite_info[team_name]</a>.</strong></font><br>";
echo "<a href=teams.php?teamwhat=3&whichteam=$playerinfo[team_invite]>$l_clickme</a> $l_team_tojoin <strong>$invite_info[team_name]</strong> $l_team_or <a href=teams.php?teamwhat=8&whichteam=$playerinfo[team_invite]>$l_clickme</a> $l_team_reject<br><br>";
}
}
function showinfo($whichteam,$isowner)
{
global $playerinfo, $invite_info, $team, $l_team_coord, $l_team_member, $l_options, $l_team_ed, $l_team_inv, $l_team_leave, $l_team_members, $l_score, $l_team_noinvites, $l_team_pending;
global $db, $l_team_eject;
global $db_logging;
global $color_line2;
// Heading
echo"<div align=center>";
echo "<h3><font color=white><strong>$team[team_name]</strong>";
echo "<br><font size=2>\"<i>$team[description]</i>\"</font></h3>";
if ($playerinfo['team'] == $team['id'])
{
echo "<font color=white>";
if ($playerinfo['ship_id'] == $team['creator'])
{
echo "$l_team_coord ";
}
else
{
echo "$l_team_member ";
}
echo "$l_options<br><font size=2>";
if ( isTeamOwner($team, $playerinfo) == true)
{
echo "[<a href=teams.php?teamwhat=9&whichteam=$playerinfo[team]>$l_team_ed</a>] - ";
}
echo "[<a href=teams.php?teamwhat=7&whichteam=$playerinfo[team]>$l_team_inv</a>] - [<a href=teams.php?teamwhat=2&whichteam=$playerinfo[team]>$l_team_leave</a>]</font></font>";
}
DISPLAY_INVITE_INFO();
echo "</div>";
// Main table
echo "<table border=2 cellspacing=2 cellpadding=2 bgcolor=\"#400040\" width=\"75%\" align=center>";
echo "<tr>";
echo "<td><font color=white>$l_team_members</font></td>";
echo "</tr><tr bgcolor=$color_line2>";
$result = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE team=?;", array($whichteam));
db_op_result ($db, $result, __LINE__, __FILE__, $db_logging);
while (!$result->EOF)
{
$member = $result->fields;
echo "<td> - $member[character_name] ($l_score $member[score])";
if ($isowner && ($member['ship_id'] != $playerinfo['ship_id']))
{
echo " - <font size=2>[<a href=\"teams.php?teamwhat=5&who=$member[ship_id]\">$l_team_eject</a>]</font></td>";
}
else
{
if ($member['ship_id'] == $team['creator'])
{
echo " - $l_team_coord </td>";
}
}
echo "</tr><tr bgcolor=$color_line2>";
$result->MoveNext();
}
// Displays for members name
$res = $db->Execute("SELECT ship_id,character_name FROM {$db->prefix}ships WHERE team_invite=?;", array($whichteam));
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
echo "<td bgcolor=$color_line2><font color=white>$l_team_pending <strong>$team[team_name]</strong></font></td>";
echo "</tr><tr>";
if ($res->RecordCount() > 0)
{
echo "</tr><tr bgcolor=$color_line2>";
while (!$res->EOF)
{
$who = $res->fields;
echo "<td> - $who[character_name]</td>";
echo "</tr><tr bgcolor=$color_line2>";
$res->MoveNext();
}
}
else
{
echo "<td>$l_team_noinvites <strong>$team[team_name]</strong>.</td>";
echo "</tr><tr>";
}
echo "</tr></table>";
}
function validate_team($name = null, $desc = null, $creator = null)
{
global $db;
global $db_logging;
$name = trim($name);
$desc = trim($desc);
$creator = (int)$creator;
if ( (is_null($name) || empty($name)) || (is_null($desc) || empty($desc)) || (is_null($creator) || empty($creator)) )
{
return false;
}
if (($res = preg_match('/[^A-Za-z0-9\_\s\-\.\']+/', $name, $matches)) !=0)
{
return false;
}
if (($res = preg_match('/[^A-Za-z0-9\_\s\-\.\']+/', $desc, $matches)) !=0)
{
return false;
}
// Just a test to see if an team with a name of $name exists.
// This is just a temp fix until we find a better one.
$res = $db->Execute("SELECT COUNT(*) as found FROM {$db->prefix}teams WHERE team_name = ? AND creator != ?;", array($name, $creator));
db_op_result ($db, $res, __LINE__, __FILE__, $db_logging);
$num_res = $res->fields;
if ($num_res['found'] > 0)
{
return false;
}
return true;
}
?>
</div></div>
<?
include "footer.php";
?>