-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit.php
117 lines (97 loc) · 3.16 KB
/
submit.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
<?php
// TODO: separate out common view code into V class
// TODO: update once fixture/match are refactored
require_once 'private_php/p_global.php';
require_once 'private_php/p_match.php';
requireLogin(['can_submit']);
$fixtureId = @$_REQUEST['fid'];
if (!is_numeric($fixtureId)) errorPage(HttpStatus::NotFound);
$fixtureId = (int) $fixtureId;
try {
$fixture = Fixture::loadById($fixtureId);
} catch (Exception $ex) {
errorPage(HttpStatus::NotFound);
}
$fixtures = $CurrentUser->club()->fixturesPendingSubmission();
$loopFixture = null;
foreach ($fixtures as $loopFixture) {
if ($loopFixture->id() == $fixtureId) break;
}
// TODO: distinguish failure scenarios:
// - not the user's club
// - approved
// - already submitted by same club
// - already submitted by other club and not approved - redirect to approval
// - other status - postponed, defaulted, scored bye
// - no date set for match
if (!$loopFixture || $fixture->id() != $loopFixture->id()) errorPage(403);
$match = Match::load($fixtureId);
$submissionBuilt = false;
$error = null;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
try {
if (@$_POST['confirm'] == 'yes') {
$Database->beginTransaction();
try {
$match->buildSubmission();
$match->saveSubmission();
$Database->commit();
} catch (Exception $ex) {
$Database->rollBack();
throw $ex;
}
$match->generateEmailConfirmation();
} else {
$match->buildSubmission();
$submissionBuilt = true;
}
} catch (ReportableException $ex) {
$error = $ex->getMessage();
$submissionBuilt = false;
} catch (Exception $ex) {
//$error = $ex->getMessage(); // debug
errorPage(500);
}
}
pageHeader('Submit Result');
?>
<h2>Submit Result</h2>
<?php if ($error) { ?>
<p class="error"><?php echo htmlspecialchars($error); ?></p>
<?php } ?>
<form method="post" action="submit">
<?php if ($submissionBuilt) { ?>
<p>Please confirm that these details are correct. If you have made a mistake, please use your browser's Back button to return to the submission form. If you are happy that the result is complete and correct, please press Submit to complete the submission.</p>
<?php $match->renderResult(); ?>
<p>
<?php carryForwardPostData(); ?>
<input type="hidden" name="confirm" value="yes" />
<input type="submit" value="Submit" />
</p>
<?php if ($_POST['comments']) { ?>
<p>Comments:<br />
<?php echo encodeMultiLine($_POST['comments']); ?></p>
<?php } ?>
<?php } else { ?>
<p>Please enter the details of the match.</p>
<?php
$division = Division::loadById($fixture->round->division()->id());
/*if ($division->minBoards < $division->maxBoards) {
?> <p>If you used fewer than <?php echo $division->maxBoards; ?> boards, please fill in as many boards as you used, starting at the top, and leave the remainder blank.</p>
<?php
}*/
$match->renderSubmissionForm();
?>
<p>Comments:<br />
<textarea style="width: 40em; max-width: 100%;" maxlength="1024" name="comments"><?php
echo htmlspecialchars(@$_POST['comments']);
?></textarea></p>
<p>
<input type="hidden" name="fid" value="<?php echo $fixtureId; ?>" />
<input type="submit" value="Next" />
</p>
<?php } ?>
</form>
<?php
pageFooter();
?>