+ $return[] = array( $pl['name'], round($pl['points']/$pl['nr'],3) );
+ }
+
+ return $return;
+}
+
+function format_score_table_ascii($score)
+{
+ $output="";
+ if(sizeof($score)==0)
+ return "";
+
+ /* truncate table if we have too many games */
+ $max = sizeof($score);
+ if($max>6) $output.=" (table truncated to last 6 games)\n";
+
+ /* output header */
+ foreach($score[0]['players'] as $id=>$points)
+ {
+ $name = DB_get_name('userid',$id); /*TODO*/
+ $output.= " ".substr($name,0,2)." |";
+ }
+ $output.=" P |\n";
+ $output.= "------+------+------+------+------+\n";
+
+ /* output score for each game */
+ $i=0;
+ foreach($score as $game)
+ {
+ $i++;
+ if($i-1<$max-6) continue;
+
+ foreach($game['players'] as $id=>$points)
+ $output.=str_pad($points,6," ",STR_PAD_LEFT)."|";
+ $output.=str_pad($game['points'],4," ",STR_PAD_LEFT);
+
+ /* check for solo */
+ if($game['solo'])
+ $output.= " S|";
+ else
+ $output.= " |";
+
+ $output.="\n";
+ }
+ return $output;
+}
+
+function format_score_table_html($score,$userid)
+{
+ global $INDEX;
+
+ if(sizeof($score)==0)
+ return "";
+
+ $output = "<div class=\"scoretable\">\n<table class=\"score\">\n <thead>\n <tr>\n";
+
+ /* output header */
+ $output.= " <th> No </th>";
+ foreach($score[0]['players'] as $id=>$points)
+ {
+ $name = DB_get_name('userid',$id); /*TODO*/
+ $output.= "<th> ".substr($name,0,2)." </th>";
+ }
+ $output.="<th>P</th>\n </tr>\n </thead>\n <tbody>\n";
+
+ $i=0;
+ foreach($score as $game)
+ {
+ $i++;
+ $output.=" <tr>";
+ $userhash = DB_get_hash_from_gameid_and_userid($game['gameid'],$userid);
+ /* create link to old games only if you are logged in and its your game*/
+ if(isset($_SESSION['id']) && $_SESSION['id']==$userid)
+ $output.=" <td> <a href=\"".$INDEX."?action=game&me=".$userhash."\">$i</a></td>";
+ else
+ $output.=" <td>$i</td>";
+
+ foreach($game['players'] as $id=>$points)
+ $output.="<td>".$points."</td>";
+ $output.="<td>".$game['points'];
+
+ /* check for solo */
+ if($game['solo'])
+ $output.= " S";
+ $output.="</td></tr>\n";