+function format_score_table_ascii($score)
+{
+ $output="";
+ if(sizeof($score)==0)
+ return "";
+
+ // if(sizeof($score)>5) $header.= " ... \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";
+
+ $max = sizeof($score);
+ $i=0;
+
+ if($i<$max-6) $output.=" ...\n";
+
+ 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><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);
+ $output.=" <td> <a href=\"".$INDEX."?action=game&me=".$userhash."\">$i</a></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";
+ }
+
+ $output.="</tbody>\n</table></div>\n";
+
+ return $output;
+}
+
+function createCache($content, $cacheFile)
+{
+ $fp = fopen($cacheFile,"w");
+ if($fp)
+ {
+ fwrite($fp,$content);
+ fclose($fp);
+ }
+ else
+ echo "WARNING: couldn't create cache file";
+
+ return;
+}
+
+function getCache($cacheFile, $expireTime)
+{
+ if( file_exists($cacheFile) &&
+ filemtime($cacheFile )>( time() - $expireTime ) )
+ {
+ return file_get_contents($cacheFile);
+ }
+
+ return false;
+}