/
admin_import.php
128 lines (115 loc) · 6.41 KB
/
admin_import.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
<?php
global $T_INJS, $T_PMD_ACH, $T_PMD_IR, $T_PMD_INJ;
$T_INJS_REV = array_flip($T_INJS);
// Input sent?
if (isset($_FILES['xmlfile'])) {
$file = $_FILES['xmlfile']['tmp_name'];
$xml = new DOMDocument();
$xml->load($file);
$xmlteams = $xml->schemaValidate('xml/import.xsd') ? simplexml_load_file($file) : (object) array('team' => array());
$map = array(
# Team::$createEXPECTED => XML import schema field name
# If field is the same do not define entry!
'owned_by_coach_id' => 'coach_id',
'f_race_id' => 'race_id',
'f_lid' => 'league_id',
'f_did' => 'division_id',
'rerolls' => 'rr',
'ff_bought' => 'ff',
'won_0' => 'won',
'lost_0' => 'lost',
'draw_0' => 'draw',
'wt_0' => 'wt',
'gf_0' => 'gf',
'ga_0' => 'ga',
);
foreach ($xmlteams->team as $t) {
# Corrections
$t->played_0 = $t->won+$t->lost+$t->draw;
$t->imported = 1;
# Add team
list($exitStatus, $tid) = Team::create(array_merge(
array_intersect_key((array) $t, array_fill_keys(Team::$createEXPECTED, null)), # Fields which are correctly named in XMl file.
array_combine(array_keys($map), array_values(array_intersect_key((array) $t, array_fill_keys(array_values($map), null)))) # Mapped fields.
));
status(!$exitStatus, $exitStatus ? Team::$T_CREATE_ERROR_MSGS[$exitStatus] : "Created team '$t->name'");
# Add players
$ROLLBACK = false;
if (is_numeric($tid) && !$exitStatus) {
$team = new Team($tid);
foreach ($t->players->player as $p) {
$p = (object) ((array) $p); # Get rid of SimpleXML objects.
if (!$team->isPlayerPosValid($p->pos_id)) {
status(false, "Invalid race position ID '$p->pos_id' for '$p->name'");
$ROLLBACK = true;
break;
}
list($status1, $pid) = Player::create(array(
'nr' => $p->nr, 'f_pos_id' => $p->pos_id, 'name' => $p->name, 'team_id' => $tid
), array('force' => true, 'free' => true)
);
if ($status1) {
status(false, Player::$T_CREATE_ERROR_MSGS[$status1]);
break;
}
$status2 = true;
# The status must be set as the "inj" (not agn) field for EVERY match (import) entry.
# This is because MySQL may pick a random match data entry from which to get the status from.
$pstatus = $T_INJS_REV[strtoupper($p->status)];
# Injuries
foreach (array('ma', 'st', 'ag', 'av', 'ni') as $inj) {
$agn = $T_INJS_REV[strtoupper($inj)];
while ($p->{$inj}-- > 0) {
$status2 &= Match::ImportEntry($pid, array_merge(array_fill_keys(array_merge($T_PMD_ACH, $T_PMD_IR),0), array_combine($T_PMD_INJ, array($pstatus,$agn,($p->{$inj}-- > 0) ? $agn : NONE))));
}
}
# Set player achievements
$status2 &= Match::ImportEntry($pid, array_merge(array_intersect_key((array) $p, array_fill_keys($T_PMD_ACH,null)), array_combine($T_PMD_INJ,array($pstatus,NONE,NONE)), array_fill_keys($T_PMD_IR,0)));
status($status2, "Added to '$t->name' player '$p->name'");
}
# Set correct treasury.
$team->dtreasury($t->treasury*1000 - $team->treasury); // $t->treasury + $delta = XML value
}
if ($ROLLBACK) {
status($team->delete(), 'Successfully deleted new team due to error.');
}
}
}
title($lng->getTrn('menu/admin_menu/import'));
?>
This page allows you to create a customized team for an existing coach.<br>
This is useful if you and your league wish to avoid starting from scratch in order to use OBBLM.<br>
<u>Note</u>: If you discover errors after having imported your team, you can either repair the errors<br>
via the admin tools in the coach corner, or simply delete the team and import a new.<br>
<u>Note</u>: The team import feature is <b>not</b> meant to be a way for you to import the entire state of your league, with stats, into OBBLM.<br>
It's meant to be an easy way of getting your existing teams into OBBLM without having to re-create the teams from scratch ie. buying players, buying team stuff, selecting player skills etc..<br>
The fact that you may specify won, lost and draw games etc. for a imported team is merely to make the team pages of imported teams reflect the actual team progress - it
does not allow you to integreate the imported team's stats with the future collected stats via OBBLM in, for example, the standings tables.
<hr align="left" width="200px">
<br>
Import a team by filling in a <a href="xml/import.xml">XML schema</a> (right click on link --> save as) and uploading it.<br>
<br>
<form enctype="multipart/form-data" action="index.php?section=admin&subsec=import" method="POST">
<b>XML file:</b><br>
<input name="xmlfile" type="file"><br>
<br>
<input type="submit" name="button" value="Import via XML file">
</form>
<br>
<b>Please note</b> that you <i>must</i> run the "syncAll()" synchronization procedure from the <a href='index.php?section=admin&subsec=cpanel'>OBBLM core panel</a> after importing teams.<br>
<br>
When importing teams you will need to know the IDs of the respective coaches, races and player positionals.<br>
Coach IDs can be found in the information section of the Coach's Corner pages.<br>
Race IDs and the IDs of the player positionals allowed by the race can be found on the race's information pages.<br>
You'll also need to know the IDs of the leagues which the teams belong to and likwise division IDs, if the league in question require teams to be tied to a divsions.<br>
League and division IDs <i>you</i> may use are<br><br>
<table>
<tr style='font-style:italic;'><td>League</td><td>Division</td><td>League ID</td><td>Division ID</td><td>League requires team-division ties?</td></tr>
<?php
foreach ($divisions as $did => $desc) {
if ($leagues[$desc['f_lid']]['ring'] == Coach::T_RING_LOCAL_ADMIN) {
echo "<tr><td>".$leagues[$desc['f_lid']]['lname']."</td><td>$desc[dname]</td><td>$desc[f_lid]</td><td>$did</td><td>".(($leagues[$desc['f_lid']]['tie_teams']) ? 'Yes' : 'No')."</td></tr>";
}
}
?>
</table>