forked from photogabble/blacknova
-
Notifications
You must be signed in to change notification settings - Fork 0
/
teams.php
602 lines (533 loc) · 29.1 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
<?php
// Blacknova Traders - A web-based massively multiplayer space combat and trading game
// Copyright (C) 2001-2014 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 :(
require_once './common.php';
Bnt\Login::checkLogin($pdo_db, $lang, $langvars, $bntreg, $template);
// Database driven language entries
$langvars = Bnt\Translate::load($pdo_db, $lang, array('teams', 'common', 'global_includes', 'global_funcs', 'main', 'footer'));
$title = $langvars['l_team_title'];
Bnt\Header::display($pdo_db, $lang, $template, $title);
echo "<h1>" . $title . "</h1>\n";
$testing = false; // set to false to get rid of password when creating new team
// Typecast into ints (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 = preg_replace('/[^0-9]/', '', $_REQUEST['confirmleave']);
}
$invited = null;
if (array_key_exists('invited', $_REQUEST) == true)
{
$invited = preg_replace('/[^0-9]/', '', $_REQUEST['invited']);
}
$teamname = null;
if (array_key_exists('teamname', $_POST) == true)
{
$teamname = $_POST['teamname'];
}
$teamdesc = null;
if (array_key_exists('teamdesc', $_POST) == true)
{
$teamname = $_POST['teamdesc'];
}
$confirmed = null;
if (array_key_exists('confirmed', $_REQUEST) == true)
{
$confirmed = preg_replace('/[^0-9]/', '', $_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.email = ?;", array($_SESSION['username'])) or die ($db->ErrorMsg());
Bnt\Db::logDbErrors($db, $result, __LINE__, __FILE__);
$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.email = ?;", array($_SESSION['username'])) or die ($db->ErrorMsg());
Bnt\Db::logDbErrors($db, $invite, __LINE__, __FILE__);
$invite_info=$invite->fields;
}
else
{
$invite_info = null;
}
// Get Team Info
if (!is_null($whichteam))
{
$result_team = $db->Execute("SELECT * FROM {$db->prefix}teams WHERE id = ?;", array($whichteam)) or die ($db->ErrorMsg());
Bnt\Db::logDbErrors($db, $result_team, __LINE__, __FILE__);
$team = $result_team->fields;
}
else
{
$result_team = $db->Execute("SELECT * FROM {$db->prefix}teams WHERE id = ?;", array($playerinfo['team'])) or die ($db->ErrorMsg());
Bnt\Db::logDbErrors($db, $result_team, __LINE__, __FILE__);
$team = $result_team->fields;
}
switch ($teamwhat)
{
case 1: // INFO on single team
Bad\Team::showInfo($db, $langvars, $whichteam, 0, $playerinfo);
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
break;
case 2: // LEAVE
if (!Bad\Team::isTeamMember($team, $playerinfo))
{
echo "<strong><font color=red>An error occured</font></strong><br>You are not a member of this Team.";
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
break;
}
if (is_null($confirmleave))
{
echo $langvars['l_team_confirmleave'] . " <strong>" . $team['team_name'] . "</strong> ? <a href=\"teams.php?teamwhat=$teamwhat&confirmleave=1&whichteam=$whichteam\">" . $langvars['l_yes'] . "</a> - <a href=\"teams.php\">" . $langvars['l_no'] . "</a><br><br>";
}
elseif ($confirmleave == 1)
{
if ($team['number_of_members'] == 1)
{
if (!Bad\Team::isTeamOwner($team, $playerinfo))
{
$langvars['l_team_error'] = str_replace("[error]", "<strong><font color=red>An error occured</font></strong><br>", $langvars['l_team_error']);
echo $langvars['l_team_error'];
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
continue;
}
$resx = $db->Execute("DELETE FROM {$db->prefix}teams WHERE id = ?;", array($whichteam));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
$resy = $db->Execute("UPDATE {$db->prefix}ships SET team='0' WHERE ship_id = ?;", array($playerinfo['ship_id']));
Bnt\Db::logDbErrors($db, $resy, __LINE__, __FILE__);
$resz = $db->Execute("UPDATE {$db->prefix}ships SET team_invite = 0 WHERE team_invite = ?;", array($whichteam));
Bnt\Db::logDbErrors($db, $resz, __LINE__, __FILE__);
$res = $db->Execute("SELECT DISTINCT sector_id FROM {$db->prefix}planets WHERE owner = ? AND base = 'Y';", array($playerinfo['ship_id']));
Bnt\Db::logDbErrors($db, $res, __LINE__, __FILE__);
$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']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
if (!empty ($sectors))
{
foreach ($sectors as $sector)
{
Bnt\Ownership::calc($db, $sector, $min_bases_to_own, $langvars);
}
}
Bnt\Defense::defenceVsDefence($db, $playerinfo['ship_id'], $langvars);
Bnt\Ship::leavePlanet($db, $playerinfo['ship_id']);
$langvars['l_team_onlymember'] = str_replace("[team_name]", "<strong>$team[team_name]</strong>", $langvars['l_team_onlymember']);
echo $langvars['l_team_onlymember'] . "<br><br>";
Bnt\PlayerLog::writeLog($db, $playerinfo['ship_id'], LOG_TEAM_LEAVE, $team['team_name']);
}
else
{
if (Bad\Team::isTeamOwner($team, $playerinfo))
{
echo $langvars['l_team_youarecoord'] . " <strong>$team[team_name]</strong>. " . $langvars['l_team_relinq'] . "<br><br>";
echo "<form accept-charset='utf-8' 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>" . $langvars['l_team_newc'] . "</td><td><select name=newcreator>";
$res = $db->Execute("SELECT character_name, ship_id, team FROM {$db->prefix}ships WHERE team = ? ORDER BY character_name ASC;", array($whichteam));
Bnt\Db::logDbErrors($db, $res, __LINE__, __FILE__);
while (!$res->EOF)
{
$row = $res->fields;
if (!Bad\Team::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=" . $langvars['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']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
$resy = $db->Execute("UPDATE {$db->prefix}teams SET number_of_members = number_of_members - 1 WHERE id = ?;", array($whichteam));
Bnt\Db::logDbErrors($db, $resy, __LINE__, __FILE__);
$res = $db->Execute("SELECT DISTINCT sector_id FROM {$db->prefix}planets WHERE owner = ? AND base = 'Y' AND corp != 0;", array($playerinfo['ship_id']));
Bnt\Db::logDbErrors($db, $res, __LINE__, __FILE__);
$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']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
if (!empty ($sectors))
{
foreach ($sectors as $sector)
{
Bnt\Ownership::calc($db, $sector, $min_bases_to_own, $langvars);
}
}
echo $langvars['l_team_youveleft'] . " <strong>" . $team['team_name'] . "</strong>.<br><br>";
Bnt\Defense::defenceVsDefence($db, $playerinfo['ship_id'], $langvars);
Bnt\Ship::leavePlanet($db, $playerinfo['ship_id']);
Bnt\PlayerLog::writeLog($db, $playerinfo['ship_id'], LOG_TEAM_LEAVE, $team['team_name']);
Bnt\PlayerLog::writeLog($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));
Bnt\Db::logDbErrors($db, $res, __LINE__, __FILE__);
$newcreatorname = $res->fields;
echo $langvars['l_team_youveleft'] . " <strong>" . $team['team_name'] . "</strong> " . $langvars['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']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
$resy = $db->Execute("UPDATE {$db->prefix}ships SET team = ? WHERE team = ?;", array($newcreator, $whichteam));
Bnt\Db::logDbErrors($db, $resy, __LINE__, __FILE__);
$resz = $db->Execute("UPDATE {$db->prefix}teams SET number_of_members = number_of_members - 1, creator = ? WHERE id = ?;", array($newcreator, $whichteam));
Bnt\Db::logDbErrors($db, $resz, __LINE__, __FILE__);
$res = $db->Execute("SELECT DISTINCT sector_id FROM {$db->prefix}planets WHERE owner = ? AND base = 'Y' AND corp != 0;", array($playerinfo['ship_id']));
Bnt\Db::logDbErrors($db, $res, __LINE__, __FILE__);
$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']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
if (!empty ($sectors))
{
foreach ($sectors as $sector)
{
Bnt\Ownership::calc($db, $sector, $min_bases_to_own, $langvars);
}
}
Bnt\PlayerLog::writeLog($db, $playerinfo['ship_id'], LOG_TEAM_NEWLEAD, $team['team_name'] ."|". $newcreatorname['character_name']);
Bnt\PlayerLog::writeLog($db, $newcreator, LOG_TEAM_LEAD, $team['team_name']);
}
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
break;
case 3: // JOIN
if ($playerinfo['team'] != 0)
{
echo $langvars['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']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
$resy = $db->Execute("UPDATE {$db->prefix}teams SET number_of_members = number_of_members + 1 WHERE id = ?;", array($whichteam));
Bnt\Db::logDbErrors($db, $resy, __LINE__, __FILE__);
echo $langvars['l_team_welcome'] . " <strong>" . $team['team_name'] . "</strong>.<br><br>";
Bnt\PlayerLog::writeLog($db, $playerinfo['ship_id'], LOG_TEAM_JOIN, $team['team_name']);
Bnt\PlayerLog::writeLog($db, $team['creator'], LOG_TEAM_NEWMEMBER, $team['team_name'] ."|". $playerinfo['character_name']);
}
else
{
echo $langvars['l_team_noinviteto'] . "<br>";
}
}
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
break;
case 4:
echo "Not implemented yet. Sorry! :)<br><br>";
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
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 (Bad\Team::isTeamOwner($team, $playerinfo) == false)
{
$langvars['l_team_error'] = str_replace("[error]", "<strong><font color=red>An error occured</font></strong><br>", $langvars['l_team_error']);
echo $langvars['l_team_error'];
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
continue;
}
else
{
$who = preg_replace('/[^0-9]/', '', $who);
$result = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE ship_id = ?;", array($who));
Bnt\Db::logDbErrors($db, $result, __LINE__, __FILE__);
$whotoexpel = $result->fields;
if (is_null($confirmed))
{
echo $langvars['l_team_ejectsure'] . " " . $whotoexpel['character_name'] . "? <a href=\"teams.php?teamwhat=$teamwhat&confirmed=1&who=$who\">" . $langvars['l_yes'] . "</a> - <a href=\"teams.php\">" . $langvars['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));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
$resy = $db->Execute("UPDATE {$db->prefix}ships SET team = '0' WHERE ship_id = ?;", array($who));
Bnt\Db::logDbErrors($db, $resy, __LINE__, __FILE__);
// 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']));
Bnt\PlayerLog::writeLog($db, $who, LOG_TEAM_KICK, $team['team_name']);
echo $whotoexpel['character_name'] . " " . $langvars['l_team_ejected'] . "<br>";
}
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
}
break;
case 6: // Create Team
if ($playerinfo['team'] != 0)
{
echo $langvars['l_team_leavefirst'] . "<br>";
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
continue;
}
if (is_null ($teamname))
{
echo "<form accept-charset='utf-8' action='teams.php' method='post'>\n";
echo $langvars['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 $langvars['l_team_enterdesc'] . ": ";
echo "<input type='text' name='teamdesc' size='40' maxlength='254'><br>\n";
echo "<input type='submit' value='" . $langvars['l_submit'] . "'><input type='reset' value='" . $langvars['l_reset'] . "'>\n";
echo "</form>\n";
echo "<br><br>\n";
}
else
{
$teamname = trim(htmlentities($teamname, ENT_HTML5, 'UTF-8'));
$teamdesc = trim(htmlentities($teamdesc, ENT_HTML5, 'UTF-8'));
if (!Bad\Team::validateTeam($db, $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";
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
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));
Bnt\Db::logDbErrors($db, $res, __LINE__, __FILE__);
$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']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
$resy = $db->Execute("UPDATE {$db->prefix}ships SET team=? WHERE ship_id = ?;", array($playerinfo['ship_id'], $playerinfo['ship_id']));
Bnt\Db::logDbErrors($db, $resy, __LINE__, __FILE__);
echo $langvars['l_team_team'] . " <strong>" . $teamname . "</strong> " . $langvars['l_team_hcreated'] . ".<br><br>";
Bnt\PlayerLog::writeLog($db, $playerinfo['ship_id'], LOG_TEAM_CREATE, $teamname);
}
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
break;
case 7: // INVITE player
if (Bad\Team::isTeamMember($team, $playerinfo) == false)
{
echo "<br>You are not in this team!<br>";
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
break;
}
if (is_null($invited))
{
echo "<form accept-charset='utf-8' 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>" . $langvars['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));
Bnt\Db::logDbErrors($db, $res, __LINE__, __FILE__);
while (!$res->EOF)
{
$row = $res->fields;
if (Bad\Team::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='" . $langvars['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\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . "<br><br>";
break;
}
$res = $db->Execute("SELECT character_name,team_invite FROM {$db->prefix}ships WHERE ship_id = ?;", array($who));
Bnt\Db::logDbErrors($db, $res, __LINE__, __FILE__);
$newpl = $res->fields;
if ($newpl['team_invite'])
{
$langvars['l_team_isorry'] = str_replace("[name]", $newpl['character_name'], $langvars['l_team_isorry']);
echo $langvars['l_team_isorry'] . "<br><br>";
}
else
{
$resx = $db->Execute("UPDATE {$db->prefix}ships SET team_invite = ? WHERE ship_id = ?;", array($whichteam, $who));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
echo $langvars['l_team_plinvted'] . "<br>" . $langvars['l_team_plinvted2'] . "<br>";
Bnt\PlayerLog::writeLog($db, $who, LOG_TEAM_INVITE, $team['team_name']);
}
}
else
{
echo $langvars['l_team_notyours'] . "<br>";
}
}
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . "<br><br>";
break;
case 8: // REFUSE invitation
echo $langvars['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']));
Bnt\Db::logDbErrors($db, $resx, __LINE__, __FILE__);
Bnt\PlayerLog::writeLog($db, $team['creator'], LOG_TEAM_REJECT, $playerinfo['character_name'] ."|". $invite_info['team_name']);
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
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 (Bad\Team::isTeamOwner($team, $playerinfo) == false)
{
$langvars['l_team_error'] = str_replace("[error]", "<strong><font color=red>An error occured</font></strong><br>", $langvars['l_team_error']);
echo $langvars['l_team_error'];
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
break;
}
if (is_null($update))
{
echo "<form accept-charset='utf-8' action='teams.php' method='post'>";
echo $langvars['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 $langvars['l_team_eddesc'] . " . : <br>";
echo "<input type='text' name='teamdesc' size='40' maxlength='254' value='{$team['description']}'><br>";
echo "<input type='submit' value='" . $langvars['l_submit'] . "'><input type='reset' value='{" . $langvars['l_reset'] . "'>";
echo "</form>";
echo "<br><br>";
}
else
{
$teamname = trim(htmlentities($teamname, ENT_HTML5, 'UTF-8'));
$teamdesc = trim(htmlentities($teamdesc, ENT_HTML5, 'UTF-8'));
if (Bad\Team::validateTeam($db, $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";
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
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>");
Bnt\Db::logDbErrors($db, $res, __LINE__, __FILE__);
echo $langvars['l_team_team'] . " <strong>" . $teamname . "</strong> " . $langvars['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>");
Bnt\Db::logDbErrors($db, $result_team_name, __LINE__, __FILE__);
Bnt\PlayerLog::writeLog($db, $playerinfo['ship_id'], LOG_TEAM_RENAME, $teamname);
while (!$result_team_name->EOF)
{
$teamname_array = $result_team_name->fields;
Bnt\PlayerLog::writeLog($db, $teamname_array['ship_id'], LOG_TEAM_M_RENAME, $teamname);
$result_team_name->MoveNext();
}
}
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
break;
default:
if ($playerinfo['team'] == 0)
{
echo $langvars['l_team_notmember'];
Bad\Team::displayInviteInfo($langvars, $playerinfo, $invite_info);
}
else
{
if ($playerinfo['team'] < 0)
{
$playerinfo['team'] = -$playerinfo['team'];
$result = $db->Execute("SELECT * FROM {$db->prefix}teams WHERE id = ?;", array($playerinfo['team']));
Bnt\Db::logDbErrors($db, $result, __LINE__, __FILE__);
$whichteam = $result->fields;
echo $langvars['l_team_urejected'] . " <strong>" . $whichteam['team_name'] . "</strong><br><br>";
echo "<br><br><a href=\"teams.php\">" . $langvars['l_clickme'] . "</a> " . $langvars['l_team_menu'] . ".<br><br>";
break;
}
$result = $db->Execute("SELECT * FROM {$db->prefix}teams WHERE id = ?;", array($playerinfo['team']));
Bnt\Db::logDbErrors($db, $result, __LINE__, __FILE__);
$whichteam = $result->fields;
if ($playerinfo['team_invite'])
{
$result = $db->Execute("SELECT * FROM {$db->prefix}teams WHERE id = ?;", array($playerinfo['team_invite']));
Bnt\Db::logDbErrors($db, $result, __LINE__, __FILE__);
$whichinvitingteam = $result->fields;
}
$isowner = Bad\Team::isTeamOwner($whichteam, $playerinfo);
Bad\Team::showInfo($db, $langvars, $playerinfo['team'], $isowner, $playerinfo);
}
$res= $db->Execute("SELECT COUNT(*) as total FROM {$db->prefix}teams WHERE admin='N'");
Bnt\Db::logDbErrors($db, $res, __LINE__, __FILE__);
$num_res = $res->fields;
if ($num_res['total'] > 0)
{
Bad\Team::displayAllTeams($db, $langvars);
}
else
{
echo $langvars['l_team_noteams'] . "<br><br>";
}
break;
}
echo "<br><br>";
Bnt\Text::gotoMain($db, $lang, $langvars);
Bnt\Footer::display($pdo_db, $lang, $bntreg, $template);
?>