5 * Copyright (C) 2009 Matteo Nastasi
6 * mailto: nastasi@alternativeoutput.it
7 * matteo.nastasi@milug.org
8 * web: http://www.alternativeoutput.it
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details. You should have received a
19 * copy of the GNU General Public License along with this program; if
20 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21 * Suite 330, Boston, MA 02111-1307, USA.
29 define(TRI_LIMIT, (90 * 24 * 60 * 60));
30 define(TRI_FEW_GAMES, 60);
32 define(MON_LIMIT, (30 * 24 * 60 * 60));
33 define(MON_FEW_GAMES, 20);
35 define(WEE_LIMIT, (7 * 24 * 60 * 60));
36 define(WEE_FEW_GAMES, 10);
44 function Ptsgam($username = "", $pts = 0, $gam = 0)
46 $this->username = $username;
53 $ret = new Ptsgam($this->username, $this->pts, $this->gam);
66 $ret = sprintf ("%.3f", $this->normpts() * 100.0);
67 if (strchr($ret, ".")) {
68 $ret = rtrim(rtrim($ret, "0"), ".");
78 return ($this->pts / $this->gam);
82 function ptsgam_cmp($a, $b)
84 $norma = $a->normpts();
85 $normb = $b->normpts();
87 if ($norma == $normb) {
88 if ($a->gam == $b->gam)
91 return ($a->gam < $b->gam ? 1 : -1);
94 return (($norma < $normb) ? 1 : -1);
97 function placings_show(&$user)
99 $ret = sprintf("<div style='padding: auto;'><table class='placings'>");
100 $ret .= sprintf("<tr><td style='background-color: #f0f0ff;'><br><b>Settimanale</b><br>(non meno di %d partite)<br><br>%s</td>", WEE_FEW_GAMES, placing_show($user, "wee_hi") );
101 $ret .= sprintf("<td style='background-color: #f0f0ff;'><br><b>Settimanale</b><br>(meno di %d partite)<br><br>%s</td></tr>\n", WEE_FEW_GAMES, placing_show($user, "wee_lo") );
103 $ret .= sprintf("<tr><td style='background-color: #fffff0;'><br><b>Mensile</b><br>(non meno di %d partite)<br><br>%s</td>", MON_FEW_GAMES, placing_show($user, "mon_hi") );
104 $ret .= sprintf("<td style='background-color: #fffff0;'><br><b>Mensile</b><br>(meno di %d partite)<br><br>%s</td></tr>\n", MON_FEW_GAMES, placing_show($user, "mon_lo") );
106 $ret .= sprintf("<tr><td style='background-color: #fff0f0;'><br><b>Trimestrale</b><br>(non meno di %d partite)<br><br>%s</td>", TRI_FEW_GAMES, placing_show($user, "tri_hi"));
107 $ret .= sprintf("<td style='background-color: #fff0f0;'><br><b>Trimestrale</b><br>(meno di %d partite)<br><br>%s</td></tr>", TRI_FEW_GAMES, placing_show($user, "tri_lo"));
110 $ret .= sprintf("</table></div>");
114 function placing_show(&$user, $suff)
118 if (($fp = @fopen(LEGAL_PATH."/class_".$suff.".log", 'r')) == FALSE) {
123 $ret = sprintf("<table class='placing'><tr><th>Pos.</th><th>Utente</th><th>Score</th><th>(Punti/Partite)</th>");
124 for ($i = 0 ; !feof($fp) ; $i++) {
125 $bf = fgets($fp, 4096);
126 $ar = csplitter($bf, '|');
128 $pg = new Ptsgam($ar[0], $ar[1], $ar[2]);
130 if ($pg->username == "")
134 $ret .= sprintf("<tr><td>%d</td><td>%s%s%s</td><td>%s</td><td>(%d/%d)</td></tr>", $i+1,
135 ($pg->username == $user->name ? "<b>" : ""), $pg->username, ($pg->username == $user->name ? "</b>" : ""), $pg->snormpts(), $pg->pts, $pg->gam);
137 if ($user != FALSE) {
138 if ($pg->username == $user->name && $i >= 5) {
139 $tail = sprintf("<tr><td colspan=4 style='text-align: center'> . . . . . . . . . . </td></tr>");
140 $tail .= sprintf("<tr><td>%d</td><td>%s%s%s</td><td>%s</td><td>(%d/%d)</td></tr>", $i+1,
141 ($pg->username == $user->name ? "<b>" : ""), $pg->username, ($pg->username == $user->name ? "</b>" : ""), $pg->snormpts(), $pg->pts, $pg->gam);
146 if ($tail != FALSE) {