LAYOUT: moved score table and rules to the top
authorArun Persaud <arun@nubati.net>
Sun, 1 Jun 2008 08:17:36 +0000 (01:17 -0700)
committerArun Persaud <arun@nubati.net>
Sun, 1 Jun 2008 08:17:36 +0000 (01:17 -0700)
removed more of the side layout into the top session bar. removed the list of games in a session and have it now accessable via the score table

Signed-off-by: Arun Persaud <arun@nubati.net>
css/standard006.css [moved from css/standard005.css with 91% similarity]
include/functions.php
include/game.php
include/output.php

similarity index 91%
rename from css/standard005.css
rename to css/standard006.css
index 24ffb30055fbeb0edf0a6ce43572d51ba509dff7..5e9b3351eb71c99855f6d219829eee860e753959 100644 (file)
@@ -337,10 +337,53 @@ ul.tricks li div div span.comment span{
   border-bottom:1px solid black;
   text-align:center;
 }
+div.session div.sessionrules { 
+  width:19em;
+  float:left ;
+  text-align: left;
+}
+div.session div.sessionscore { 
+  width:19em;
+  float:right ;
+  text-align: right;
+}
+div.session div.sessionrules div{
+  display:none;
+  background-color: white;
+  border: 1px solid black;
+  position:absolute;
+  z-index: 30;
+  padding:0.5em;
+}
+div.session div.sessionrules:hover div{
+  display:block;
+}
+div.session div.sessionscore div{
+  position:absolute;
+  width:12em;
+  right:0em;
+  display:none;
+  background-color: white;
+  border: 1px solid black;
+  z-index: 30;
+}
+div.session div.sessionscore:hover div{
+  display:block;
+}
+
+.scoretable{
+  height:20em;
+  overflow: auto;
+}
+table.score {
+  margin:0.5em;
+  width:10em;
+  border-collapse:collapse;
+}
 
-.gameinfo, .useroptions {
+.gameinfo {
   position:absolute;
-  top:10em;
+  top:27em;
   right:0em;
   margin:1em;
   margin-top:0em;
@@ -354,7 +397,7 @@ ul.tricks li div div span.comment span{
 
   padding:0.3em;
 
-  background-color: #eee;
+  background-color: #efefef;
 }
 
 .usermenu {
@@ -448,15 +491,6 @@ div span img.button {
   background-color: #15de26;
 }
 
-.scoretable{
-  height:10em;
-  overflow: auto;
-}
-table.score {
-  width:10em;
-  border-collapse:collapse;
-}
-
 .bigger {
   font-size:larger;
 }
@@ -484,4 +518,5 @@ table.stats td, table.stats th {
 }
 table.stats  tr td:last-child, table.stats  tr th:last-child { border-right: solid 0 black; }
 
-table.stats th { border-bottom: solid 0.2em black }
\ No newline at end of file
+table.stats th { border-bottom: solid 0.2em black }
+
index 7b29a28fe311dbd12e27fd1e2af53d1a6250cc5d..fafcf36ead8a07455f435be8d7f4bb4554b1bf1d 100644 (file)
@@ -863,7 +863,7 @@ function display_user_menu()
          echo "<div class=\"usermenu\">\n";
          echo "It's your turn in these games:<br />\n";
        }
-      
+
       $i++;
       echo "<a href=\"".$INDEX."?action=game&amp;me=".$r[0]."\">game ".DB_format_gameid($r[1])." </a><br />\n";
       if($i>4)
@@ -880,14 +880,20 @@ function display_user_menu()
 
 function generate_score_table($session)
 {
+  /* returns an array with N entries
+   * $score[$i]["gameid"]   = gameid
+   * $score[$i]["players"] = array (id=>total points)
+   * $score[$i]["points"]   = points for this game
+   * $score[$i]["solo"]     = 1 or 0
+   */
+  $score = array();
+  $i=0;
+
   /* get all ids */
   $gameids = DB_get_gameids_of_finished_games_by_session($session);
 
   if($gameids == NULL)
-    return "";
-
-  $output = "<div class=\"scoretable\">\n<table class=\"score\">\n <tr>\n";
-
+    return $score;
 
   /* get player id, names... from the first game */
   $player = array();
@@ -895,42 +901,32 @@ function generate_score_table($session)
                     " LEFT JOIN User On Hand.user_id=User.id".
                     " WHERE Hand.game_id=".$gameids[0]);
   while( $r = DB_fetch_array($result))
-    {
-      $player[] = array( 'id' => $r[0], 'points' => 0 );
-      $output.= "  <td> ".substr($r[1],0,2)." </td>\n";
-    }
-  $output.="  <td>P</td>\n </tr>\n";
+    $player[$r[0]] = 0;
 
   /* get points and generate table */
   foreach($gameids as $gameid)
     {
-      $output.=" <tr>\n";
-
       $re_score = DB_get_score_by_gameid($gameid);
-      foreach($player as $key=>$pl)
+      foreach($player as $id=>$points)
        {
-         $party = DB_get_party_by_gameid_and_userid($gameid,$pl['id']);
+         $party = DB_get_party_by_gameid_and_userid($gameid,$id);
          if($party == "re")
            if(DB_get_gametype_by_gameid($gameid)=="solo")
-             $player[$key]['points'] += 3*$re_score;
+             $player[$id] += 3*$re_score;
            else
-             $player[$key]['points'] += $re_score;
+             $player[$id] += $re_score;
          else if ($party == "contra")
-           $player[$key]['points'] -= $re_score;
-
-         $output.="  <td>".$player[$key]['points']."</td>\n";
+           $player[$id] -= $re_score;
        }
-      $output.="  <td>".abs($re_score);
+      $score[$i]['gameid']  = $gameid ;
+      $score[$i]['players'] = $player;
+      $score[$i]['points']  = abs($re_score);
+      $score[$i]['solo']    = (DB_get_gametype_by_gameid($gameid)=="solo");
 
-      /* check for solo */
-      if(DB_get_gametype_by_gameid($gameid)=="solo")
-       $output.= " S";
-      $output.="</td>\n </tr>\n";
+      $i++;
     }
 
-  $output.="</table></div>\n";
-
-  return $output;
+  return $score;
 }
 
 function generate_global_score_table()
@@ -994,6 +990,87 @@ function generate_global_score_table()
   return $return;
 }
 
+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> Nr </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&amp;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;
+}
+
 
 
 ?>
index 3fbc451e1d83bd149af696c05eddbb028e95f8a9..4f506f5b5b26eb5a19c557c12fe3935912769fa7 100644 (file)
@@ -112,18 +112,28 @@ echo "<form action=\"index.php?action=game&amp;me=$me\" method=\"post\">\n";
 /* output extra division in case this game is part of a session */
 if($session)
   {
-    echo "<div class=\"session\">\n".
-      "This game is part of session $session: \n";
+    echo "<div class=\"session\">\n";
+    echo "  <div class=\"sessionrules\">Rules (+icons fur rules) \n";
+    echo "    <div>\n";
+    echo "       10ofhearts : ".$RULES["dullen"]      ."<br />\n";
+    echo "       schweinchen: ".$RULES["schweinchen"] ."<br />\n";
+    echo "       call:        ".$RULES["call"]        ."<br />\n";
+    echo "    </div>\n  </div>\n";
+    echo "  <div class=\"sessionscore\">Score \n";
+    $score   = generate_score_table($session);
+    echo format_score_table_html($score,$myid);
+    echo "  </div>\n";
     $hashes = DB_get_hashes_by_session($session,$myid);
     $i = 1;
     foreach($hashes as $hash)
       {
-       if($hash == $me)
-         echo "$i \n";
-       else
-         echo "<a href=\"".$INDEX."?action=game&amp;me=".$hash."\">$i</a> \n";
-       $i++;
+        if($hash == $me)
+         $j=$i;
+        $i++;
+       $lasthash=$hash;
       }
+    $i--;
+    echo "This is game number $j of <a href=\"".$INDEX."?action=game&amp;me=$lasthash\">$i</a> in session $session.";
     echo "</div>\n";
   }
 
@@ -1649,35 +1659,9 @@ switch($mystatus)
 
                  $session = DB_get_session_by_gameid($gameid);
                  $score = generate_score_table($session);
-                 /* convert html to ascii */
-                 $score = str_replace("<div class=\"scoretable\">\n<table class=\"score\">\n <tr>\n","",$score);
-                 $score = str_replace("</table></div>\n","",$score);
-                 $score = str_replace("\n","",$score);
-                 $score = str_replace(array("<tr>","</tr>","<td>","</td>"),array("","\n","","|"),$score);
-                 $score = explode("\n",$score);
-
-                 $header = array_slice($score,0,1);
-                 $header = explode("|",$header[0]);
-                 for($i=0;$i<sizeof($header);$i++)
-                   $header[$i]=str_pad($header[$i],6," ",STR_PAD_BOTH);
-                 $header = implode("|",$header);
-                 $header.= "\n------+------+------+------+------+\n";
-                 if(sizeof($score)>5) $header.=   "                ...   \n";
-
-                 if(sizeof($score)>5) $score = array_slice($score,-5,5);
-                 for($i=0;$i<sizeof($score);$i++)
-                   {
-                     $line = explode("|",$score[$i]);
-                     for($j=0;$j<sizeof($line);$j++)
-                       $line[$j]=str_pad($line[$j],6," ",STR_PAD_LEFT);
-                     $score[$i] = implode("|",$line);
-                   }
-
-                 $score = implode("\n",$score);
-                 $score = $header.$score;
 
                  $message .= "Score Table:\n";
-                 $message .= $score;
+                 $message .= format_score_table_ascii($score);
 
                  /* send out final email */
                  $all = array();
@@ -1746,7 +1730,7 @@ switch($mystatus)
       $notes = DB_get_notes_by_userid_and_gameid($myid,$gameid);
       foreach($notes as $note)
        echo "$note <hr />\n";
-      echo "Insert note:<input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
+      echo "<input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
       echo "</div> \n";
 
       $mycards = DB_get_hand($me);
@@ -1869,15 +1853,6 @@ switch($mystatus)
       /* display rule set for this game */
     echo "<div class=\"gameinfo\">\n";
 
-    if($gamestatus != 'pre')
-      echo " Gametype: $GT <br />\n";
-
-    echo "Rules: <br />\n";
-    echo "10ofhearts : ".$RULES["dullen"]      ."<br />\n";
-    echo "schweinchen: ".$RULES["schweinchen"] ."<br />\n";
-    echo "call:        ".$RULES["call"]        ."<br />\n";
-
-    echo "<hr />\n";
     if($gamestatus == 'play' )
       output_form_calls($me);
 
@@ -1888,15 +1863,9 @@ switch($mystatus)
     if($gamestatus == 'play' || $gameend < 60*60*24*7)
       {
        echo "<br />\nA short comment:<input name=\"comment\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
-       echo "<hr />";
       }
 
-    echo "<input type=\"submit\" value=\"submit\" />\n<hr />\n";
-
-    $session = DB_get_session_by_gameid($gameid);
-    $score   = generate_score_table($session);
-
-    echo $score;
+    echo "<input type=\"submit\" value=\"submit\" />\n";
 
     echo "</div>\n";
 
index 2fcfacacc7ed440f64c1e39232f60757dfe3a33c..86db0a0a9e5599e5030e38b3c37822177af43a24 100644 (file)
@@ -99,9 +99,9 @@ function output_table($data,$caption="",$class="")
     $HTML  = "\n<table class=\"$class\">\n";
   else
     $HTML  = "\n<table>\n";
+
   $i=0;
-  
+
   if($caption!="")
     $HTML .= "  <caption> $caption </caption>\n";
 
@@ -270,7 +270,7 @@ function output_header()
      <title>e-Doko</title>
      <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
      <link rel="shortcut icon" type="image/x-icon" href="pics/edoko-favicon.png" />
-     <link rel="stylesheet" type="text/css" href="css/standard005.css" />
+     <link rel="stylesheet" type="text/css" href="css/standard006.css" />
      <script type="text/javascript">
        var current=0;
        function hl(num) {
@@ -397,8 +397,6 @@ function output_select_timezone($name,$timezone="")
   return;
 }
 
-
-
 function output_password_recovery($email,$password)
 {
 ?>