This repository has been archived by the owner on Jun 24, 2020. It is now read-only.
forked from TheNAF/naflm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
match_webservice.php
128 lines (112 loc) · 4.69 KB
/
match_webservice.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
<?php
require("header.php");
$_VISSTATE['COOCKIE'] = Coach::cookieLogin(); # If not already logged in then check for login-cookie and try to log in using the stored credentials.
if (!Coach::isLoggedIn())
die("You must be logged into OBBLM to use this webservice.");
$action = $_REQUEST["action"];
if($action == "update") {
$match = new Match($_POST["match_id"]);
function pushIfSet(&$inputArray, $key, $value, $convert) {
if($value != null)
$inputArray[$key] = $convert($value);
}
$toInt = function($value) {
return (int) $value;
};
$timesOneThousand = function($value) {
return (int) $value * 1000;
};
$input = array();
pushIfSet($input, 'submitter_id', $_SESSION['coach_id'], $toInt);
pushIfSet($input, 'stadium', $_POST['stadium'], $toInt);
pushIfSet($input, 'gate', $_POST['gate'], $timesOneThousand);
pushIfSet($input, 'fans', $_POST['fans'], $toInt);
pushIfSet($input, 'ffactor1', $_POST['ff1'], $toInt);
pushIfSet($input, 'ffactor2', $_POST['ff2'], $toInt);
pushIfSet($input, 'income1', $_POST['inc1'], $timesOneThousand);
pushIfSet($input, 'income2', $_POST['inc2'], $timesOneThousand);
pushIfSet($input, 'team1_score', $_POST['result1'], $toInt);
pushIfSet($input, 'team2_score', $_POST['result2'], $toInt);
pushIfSet($input, 'smp1', $_POST['smp1'], $toInt);
pushIfSet($input, 'smp2', $_POST['smp2'], $toInt);
pushIfSet($input, 'tcas1', $_POST['tcas1'], $toInt);
pushIfSet($input, 'tcas2', $_POST['tcas2'], $toInt);
pushIfSet($input, 'fame1', $_POST['fame1'], $toInt);
pushIfSet($input, 'fame2', $_POST['fame2'], $toInt);
pushIfSet($input, 'tv1', $_POST['tv1'], $timesOneThousand);
pushIfSet($input, 'tv2', $_POST['tv2'], $timesOneThousand);
$match->updatePartial($input);
$team = new Team($_POST["team_id"]);
foreach ($team->getPlayers() as $player) {
if (!Match::player_validation($player, $match))
continue;
// We create zero entries for MNG player(s). This is required!
$pid = $player->player_id;
if ($player->getStatus($match->match_id) == MNG) {
$_POST["mvp_$pid"] = 0;
$_POST["cp_$pid"] = 0;
$_POST["td_$pid"] = 0;
$_POST["intcpt_$pid"] = 0;
$_POST["bh_$pid"] = 0;
$_POST["si_$pid"] = 0;
$_POST["ki_$pid"] = 0;
$_POST["ir1_d1_$pid"] = 0;
$_POST["ir1_d2_$pid"] = 0;
$_POST["ir2_d1_$pid"] = 0;
$_POST["ir2_d2_$pid"] = 0;
$_POST["ir3_d1_$pid"] = 0;
$_POST["ir3_d2_$pid"] = 0;
$_POST["inj_$pid"] = NONE;
$_POST["agn1_$pid"] = NONE;
$_POST["agn2_$pid"] = NONE;
}
$match->entry($player->player_id, array(
'mvp' => $_POST["mvp_$pid"],
'cp' => $_POST["cp_$pid"],
'td' => $_POST["td_$pid"],
'intcpt' => $_POST["intcpt_$pid"],
'bh' => $_POST["bh_$pid"],
'si' => $_POST["si_$pid"],
'ki' => $_POST["ki_$pid"],
'ir1_d1' => $_POST["ir1_d1_$pid"],
'ir1_d2' => $_POST["ir1_d2_$pid"],
'ir2_d1' => $_POST["ir2_d1_$pid"],
'ir2_d2' => $_POST["ir2_d2_$pid"],
'ir3_d1' => $_POST["ir3_d1_$pid"],
'ir3_d2' => $_POST["ir3_d2_$pid"],
'inj' => $_POST["inj_$pid"],
'agn1' => $_POST["agn1_$pid"],
'agn2' => $_POST["agn2_$pid"]
));
}
$match->finalizeMatchSubmit();
} else if($action == "getplayerentries") {
$match = new Match($_REQUEST["match_id"]);
$team = new Team($_REQUEST["team_id"]);
$playerEntries = array();
foreach($team->getPlayers() as $player) {
$playerId = $player->player_id;
$playerEntry = $match->getPlayerEntry($playerId);
if(!$playerEntry) {
$playerEntry['mvp'] = 0;
$playerEntry['cp'] = 0;
$playerEntry['td'] = 0;
$playerEntry['intcpt'] = 0;
$playerEntry['bh'] = 0;
$playerEntry['si'] = 0;
$playerEntry['ki'] = 0;
$playerEntry['ir1_d1'] = 0;
$playerEntry['ir1_d2'] = 0;
$playerEntry['ir2_d1'] = 0;
$playerEntry['ir2_d2'] = 0;
$playerEntry['ir3_d1'] = 0;
$playerEntry['ir3_d2'] = 0;
$playerEntry['inj'] = NONE;
$playerEntry['agn1'] = NONE;
$playerEntry['agn2'] = NONE;
}
$playerEntries[$playerId] = $playerEntry;
}
echo json_encode($playerEntries);
}
?>