-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextrarep.php
180 lines (166 loc) · 6.15 KB
/
extrarep.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
<?
/* This file is used as it is to produce the classifications report.
* But it is also included in produce_certificates.php. This is why it distinguishes whether
* CERTIFICATES is set or not.
*/
require_once "lib.php";
require_once "lib_ref_admin.php";
require_once "db.php";
function formatTime($t,$type)
{
if ($t=="") return "";
if ($t=="DNF" || $t=="DNS") return $t;
switch($type)
{
case 1:
while(strlen($t)>4 && ((($ch=substr($t,0,1))=="0") || $ch==":")) $t = substr($t,1);
return $t;
break;
case 2:
if(strlen($t)>1 && substr($t,0,1)=="0") $t = substr($t,1);
return $t;
break;
default:
return formatTime(substr($t,0,2),2)."/".formatTime(substr($t,2,2),2)." ".formatTime(substr($t,4,9),1);
}
}
function romance($st)
{
return preg_replace("/\(.*\)/","",$st);
}
IF(!isset($CERTIFICATES))
{
if (substr($_SERVER["REQUEST_URI"],0,6)=="/beta/")
require_once "../".DIR_FPDF;
else
require_once DIR_FPDF;
$pdf = new tFPDF();
$pdf->SetAutoPageBreak(true,10);
$pdf->AddFont('DejaVu','','DejaVuSans.ttf',true);
$pdf->AddFont('DejaVu','B','DejaVuSans-Bold.ttf',true);
$pdf->AddPage();
$pdf->SetFont('DejaVu','B',16);
$pdf->Write(5,$_SESSION["c_name"]);
$pdf->Ln();
$pdf->SetFont('','',14);
$pdf->Write(5,"Podiums");
$pdf->Line(11,21,286.5,21);
$pdf->Ln(10);
}
$events = strict_query("SELECT $eventstable.*, name, timetype FROM $eventstable JOIN categories ON categories.id=$eventstable.id ORDER BY $eventstable.id");
while ($rowEvt=cased_mysql_fetch_array($events))
{
$round = 4;
while ($round > 1 && !$rowEvt["r".$round."_open"]) $round--;
$format = strict_query("SELECT name, avgtype FROM formats WHERE id=".$rowEvt["r".$round."_format"]);
$avgname = cased_mysql_result($format,0,"name");
$avgtype = cased_mysql_result($format,0,"avgtype");
$cat_id = $rowEvt["id"];
$timetype = $rowEvt["timetype"];
//
IF(!isset($CERTIFICATES))
{
$pdf->SetFont("","B",12);
$pdf->Write(5,$rowEvt["name"]." Podium ($avgname)");
$pdf->Ln();
$pdf->SetFontSize(10);
}
//
$query =
"SELECT $compstable.name, $timestable.average, $timestable.best ".
"FROM $timestable ".
"JOIN $compstable ON ($timestable.comp_id=$compstable.id) ".
"WHERE $timestable.cat_id=$cat_id AND $timestable.round=$round ".
"ORDER BY $timestable.average=\"\", $timestable.average, $timestable.best";
$result = strict_query($query);
$classification = 0;
$count = 0;
$qualified = 3;
$lasta = "";
$lastb = "";
while ($classification<=$qualified && $row=cased_mysql_fetch_array($result))
{
$count++;
if ($row["average"]!=$lasta || ($timetype!=3 && $row["best"]!=$lastb))
{
$classification = $count;
$lasta = $row["average"];
$lastb = $row["best"];
}
if ($row["best"] > "A") break;
if ($classification && $classification<=$qualified)
{
IF(!isset($CERTIFICATES))
{
$pdf->Write(5,$classification . ". " . romance($row["name"]) . " (" . formatTime($row[($avgtype==2?"best":"average")],$timetype) . ")");
$pdf->Ln();
}
ELSE
printCertificate($text, romance($row["name"]), $classification, $rowEvt["name"], formatTime($row[($avgtype==2?"best":"average")],$timetype));
}
}
$pdf->Ln();
}
//----------------------------------------------------------------------------------------------------------------------------
IF(!isset($CERTIFICATES))
{
$pdf->AddPage();
$pdf->SetFont('DejaVu','B',16);
$pdf->Write(5,$_SESSION["c_name"]);
$pdf->Ln();
$pdf->SetFont('','',14);
$pdf->Write(5,"Special classifications (for Rubik's Cube only)");
$pdf->Line(11,21,286.5,21);
$pdf->Ln(10);
$result = strict_query("SELECT $compstable.name, $compstable.birthday, countries.name AS country FROM $timestable JOIN $compstable ON $compstable.id=$timestable.comp_id JOIN countries ON $compstable.country_id=countries.id WHERE $timestable.cat_id=1 AND $timestable.best<'A' ORDER BY $compstable.birthday DESC LIMIT 1");
if (sql_num_rows($result))
{
$pdf->SetFont("","B",12);
$pdf->Write(5,"Youngest solver");
$pdf->Ln();
$pdf->SetFontSize(10);
$pdf->Write(5,romance(cased_mysql_result($result,0,"name")) . " - " . cased_mysql_result($result,0,"country") . " - " . cased_mysql_result($result,0,"birthday"));
$pdf->Ln(10);
}
$result = strict_query("SELECT $compstable.name, $compstable.birthday, countries.name AS country FROM $timestable JOIN $compstable ON $compstable.id=$timestable.comp_id JOIN countries ON $compstable.country_id=countries.id WHERE $timestable.cat_id=1 AND $timestable.best<'A' ORDER BY $compstable.birthday LIMIT 1");
if (sql_num_rows($result))
{
$pdf->SetFont("","B",12);
$pdf->Write(5,"Oldest solver");
$pdf->Ln();
$pdf->SetFontSize(10);
$pdf->Write(5,romance(cased_mysql_result($result,0,"name"))." - ".cased_mysql_result($result,0,"country")." - ".cased_mysql_result($result,0,"birthday"));
$pdf->Ln(10);
}
$result = strict_query("SELECT $compstable.name, countries.name AS country, $timestable.best FROM $timestable JOIN $compstable ON $compstable.id=$timestable.comp_id JOIN countries ON $compstable.country_id=countries.id WHERE $timestable.cat_id=1 ORDER BY $timestable.best LIMIT 1");
if (sql_num_rows($result))
{
$pdf->SetFont("","B",12);
$pdf->Write(5,"Fastest solve");
$pdf->Ln();
$pdf->SetFontSize(10);
$pdf->Write(5,romance(cased_mysql_result($result,0,"name"))." - ".cased_mysql_result($result,0,"country")." - ".formatTime(cased_mysql_result($result,0,"best"),1));
$pdf->Ln(10);
}
$result = strict_query("SELECT $compstable.name, average, countries.name AS country FROM $compstable ".
"JOIN (SELECT comp_id, MIN(average) AS average FROM $timestable WHERE cat_id=1 GROUP BY comp_id) avg ON avg.comp_id=$compstable.id ".
"JOIN countries ON $compstable.country_id=countries.id ".
"WHERE gender=\"f\" AND average!=\"\" ORDER BY average LIMIT 3");
if (sql_num_rows($result))
{
$pdf->SetFont("","B",12);
$pdf->Write(5,"Fastest females");
$pdf->Ln();
$pdf->SetFontSize(10);
$count = 0;
while ($row=cased_mysql_fetch_array($result))
{
$pdf->Write(5,++$count.". ".romance($row["name"])." - ".$row["country"]." - ".formatTime($row["average"],1));
$pdf->Ln();
}
}
$pdf->SetDisplayMode("fullpage","single");
$pdf->Output(preg_replace("/\W/","",$_SESSION["c_name"])." - Classifications.pdf", "I");
sql_close();
}
?>