-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_csv.php
executable file
·72 lines (58 loc) · 1.65 KB
/
create_csv.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
<?php
require_once("common.php");
protect(true);
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=score.csv");
header("Pragma: no-cache");
header("Expires: 0");
require("class-event.php");
require("class-school.php");
function println($s = '') {
echo $s . "\n";
}
foreach($events as $event) {
println($event);
println();
$abbrev = $event->getAbbrev();
$leagues = array();
$rs = mysql_query("SELECT * FROM school ORDER BY league");
while($row = mysql_fetch_object($rs)) {
$leagues[$row->league][] = new School($row->id, $row->name);
}
foreach($leagues as $leagueNum=>$schools) {
println("Pool #" . ($leagueNum + 1));
println("," . implode(",,", $schools));
$rowData = array();
$rowData[] = " ";
foreach($schools as $school) {
$rowData[] = "A,B";
}
println(implode(",", $rowData));
foreach($schools as $school) {
$q = "SELECT * FROM score WHERE school_id=$school->id AND event='$abbrev' ORDER BY level ASC";
$rs = mysql_query($q);
$scores = array();
$rowData = array();
$rowData[] = $school->name;
while($row = mysql_fetch_object($rs)) {
$scores[$row->opponent_id][] = $row->points;
$scoreID = $row->id;
}
foreach($schools as $opponent) {
if($school == $opponent) {
$rowData[] = "x";
$rowData[] = "x";
} else if(isset($scores[$opponent->id])) {
$rowData[] = $scores[$opponent->id][0];
$rowData[] = $scores[$opponent->id][1];
} else {
$rowData[] = " ";
$rowData[] = " ";
}
}
println(implode(",", $rowData));
}
println();
}
}
?>