BUGFIX: gametype was displayed in pre-phase of the game
[e-DoKo.git] / include / output.php
index f4d3fdf0de0f08738fbbe379adab41d842bfd7c1..c2a644b59516a7177744b178418d8dff5e87e24d 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-/* Copyright 2006, 2007, 2008, 2009, 2010 Arun Persaud <arun@nubati.net>
+/* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 Arun Persaud <arun@nubati.net>
  *
  *   This file is part of e-DoKo.
  *
@@ -26,6 +26,21 @@ if(!isset($HOST))
 
 /* functions which only ouput html  */
 
+function autoversion($file)
+{
+  /* changes the file name of e.g. css/style.css to css/style.<md5>.css/js
+   * this way the browser can cache the file and will reload it if the file changed
+   * needs to have .htaccess set up correctly to link back to css/style.css */
+
+  /* only use it for file that have an absolut path */
+  if(!file_exists(dirname($_SERVER['SCRIPT_FILENAME']). '/' . $file))
+    return $file;
+
+  $md5 = md5_file(dirname($_SERVER['SCRIPT_FILENAME']). '/' . $file);
+  return preg_replace('{\\.([^./]+)$}', ".$md5.\$1", $file);
+}
+
+
 function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid)
 {
   global $RULES;
@@ -53,48 +68,80 @@ function output_form_for_new_game($names)
                         * after we selected them to make sure that each name
                         * only shows up once
                         */
+
+  /* delete players name, since he will be on position D anyway */
+  unset($copy_names[array_search($_SESSION["name"],$copy_names)]);
+  srand((float) microtime() * 10000000);
+
+
   echo '  <form action="index.php?action=new" method="post">';
   echo '    <h2> '._('Select players (Remember: you need to be one of the players)').' </h2>';
-  echo '   <div class="table">';
-  echo '     <img class="table" src="pics/table.png" alt="table" />';
 
-  /* ask player for names */
+  echo '   <div class="table">';
 
-  $i=0;
+  echo  "     <div class=\"table1\">\n";
+  $randkey = array_rand($copy_names);
+  $rand = $copy_names[$randkey];
+  /* delete this name from the list of possible names */
+  unset($copy_names[$randkey]);
+  echo "       <select name=\"PlayerB\" size=\"1\">  \n";
+  foreach($names as $name)
+    {
+      if($name==$rand)
+       echo "         <option selected=\"selected\">$name</option>\n";
+      else
+       echo "         <option>$name</option>\n";
+    }
+  echo "       </select>\n     </div>\n";
 
-  /* delete players name, since he will be on position D anyway */
-  unset($copy_names[array_search($_SESSION["name"],$copy_names)]);
+  echo '   <div class="middle">';
 
-  srand((float) microtime() * 10000000);
-  foreach( array("PlayerA","PlayerB","PlayerC","PlayerD") as $player)
+  $randkey = array_rand($copy_names);
+  $rand = $copy_names[$randkey];
+  /* delete this name from the list of possible names */
+  unset($copy_names[$randkey]);
+  echo  "     <div class=\"table0\">\n";
+  echo "       <select name=\"PlayerA\" size=\"1\">  \n";
+  foreach($names as $name)
     {
-      /* pick 3 names at random and put the players name on position D*/
-      if($i<3)
-       {
-         $randkey = array_rand($copy_names);
-         $rand = $copy_names[$randkey];
-         /* delete this name from the list of possible names */
-         unset($copy_names[$randkey]);
-       }
+      if($name==$rand)
+       echo "         <option selected=\"selected\">$name</option>\n";
       else
-       {
-         $rand = $_SESSION["name"];
-       }
+       echo "         <option>$name</option>\n";
+    }
+  echo "       </select>\n     </div>\n";
 
-      echo  "     <div class=\"table".$i."\">\n";
-      $i++;
-      echo "       <select name=\"$player\" size=\"1\">  \n";
-      foreach($names as $name)
-       {
-         if($name==$rand)
-           {
-             echo "         <option selected=\"selected\">$name</option>\n";
-           }
-         else
-           echo "         <option>$name</option>\n";
-       }
-      echo "       </select>\n     </div>\n";
+  echo '     <img class="table" src="pics/table.png" alt="table" />';
+  $randkey = array_rand($copy_names);
+  $rand = $copy_names[$randkey];
+  /* delete this name from the list of possible names */
+  unset($copy_names[$randkey]);
+  echo  "     <div class=\"table2\">\n";
+  echo "       <select name=\"PlayerC\" size=\"1\">  \n";
+  foreach($names as $name)
+    {
+      if($name==$rand)
+       echo "         <option selected=\"selected\">$name</option>\n";
+      else
+       echo "         <option>$name</option>\n";
+    }
+  echo "       </select>\n     </div>\n";
+
+  echo '   </div>';
+  $rand = $_SESSION["name"];
+  echo  "     <div class=\"table3\">\n";
+  $i++;
+  echo "       <select name=\"PlayerD\" size=\"1\">  \n";
+  foreach($names as $name)
+    {
+      if($name==$rand)
+       echo "         <option selected=\"selected\">$name</option>\n";
+      else
+       echo "         <option>$name</option>\n";
     }
+  echo "       </select>\n     </div>\n";
+
+  /* ask player for names */
 
     echo '    </div>';
     echo '';
@@ -208,9 +255,9 @@ function display_link_card($card,$dir="english",$type="card", $selected=0)
     $selected = 'checked="checked"';
 
   if( $card/2 - (int)($card/2) == 0.5)
-    echo "<div class=\"cardinput\"><input type=\"radio\" name=\"".$type."\" value=\"".$card."\" $selected /><img src=\"cards/".$dir."/".$card.".png\" alt=\"".DB_get_card_name($card)."\" /></div>\n";
+    echo "<label class=\"cardinput\"><input type=\"radio\" name=\"".$type."\" value=\"".$card."\" $selected /><img src=\"cards/".$dir."/".$card.".png\" alt=\"".DB_get_card_name($card)."\" /></label>\n";
   else
-    echo "<div class=\"cardinput\" ><input type=\"radio\" name=\"".$type."\" value=\"".$card."\" $selected /><img src=\"cards/".$dir."/".($card-1).".png\" alt=\"".DB_get_card_name($card-1)."\" /></div>\n";
+    echo "<label class=\"cardinput\"><input type=\"radio\" name=\"".$type."\" value=\"".$card."\" $selected /><img src=\"cards/".$dir."/".($card-1).".png\" alt=\"".DB_get_card_name($card-1)."\" /></label>\n";
   return;
 }
 
@@ -371,56 +418,29 @@ function output_header()
 {
    global $REV;
 ?>
-<!DOCTYPE html PUBLIC
-    "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
-    "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<!DOCTYPE html>
+<html lang="en">
   <head>
      <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/standard028.css" />
-     <script type="text/javascript" src="include/jquery.js"> </script>
-     <script type="text/javascript" src="include/jquery.tablesorter.js"></script>
-     <script type="text/javascript" src="include/game.js"> </script>
+     <meta charset="utf-8" />
+     <meta name="viewport" content="width=device-width; initial-scale=1.0;" />
+     <link rel="shortcut icon" href="pics/edoko-favicon.png" />
+     <link rel="stylesheet" href="<?php echo autoversion("css/normalize.css"); ?>" />
+     <link rel="stylesheet" href="<?php echo autoversion("css/standard.css"); ?>" />
+     <link rel="stylesheet" href="<?php echo autoversion("css/dateinput.css"); ?>"/>
+     <script type="text/javascript" src="<?php echo autoversion("js/jquery.js"); ?>"> </script>
+     <script type="text/javascript" src="<?php echo autoversion("js/jquery.tablesorter.js"); ?>"></script>
+     <script type="text/javascript" src="<?php echo autoversion("js/jquery.tools.min.js"); ?>"></script>
+     <script type="text/javascript" src="<?php echo autoversion("js/game.js"); ?>"> </script>
      <script type="text/javascript">
-        $(document).ready(function()
-          {
-              $("#ScoreTable").tablesorter({ widgets: ['zebra']});
-
-             $(".gameshidesession").click( function () {
-                 $(this).parent().children(".gamessession").hide(300);
-                 $(this).parent().children(".gamesshowsession").show();
-                 $(this).hide();
-               });
-
-             $(".gamesshowsession").click( function () {
-                 $(this).parent().children(".gamessession").show(300);
-                 $(this).parent().children(".gameshidesession").show();
-                 $(this).hide();
-               });
-
-             $(".gameshowall").click( function () {
-                 $(".gamessession").show(300);
-                 $(".gamesshowsession").hide();
-                 $(".gameshidesession").show();
-               });
-             $(".gamehideall").click( function () {
-                 $(".gamessession").hide(300);
-                 $(".gamesshowsession").show();
-                 $(".gameshidesession").hide();
-               });
-
-
-           });
      </script>
   </head>
 <body onload="high_last();">
-<div class="header">
+<header>
 <?php
   echo '<h1> '._('Welcome to E-Doko').' </h1>';
 ?>
-</div>
+</header>
 <?php
 
   echo "<div class=\"main\">";
@@ -432,20 +452,18 @@ function output_footer()
   global $REV, $PREF, $INDEX;
 
   echo "</div>\n\n";
-  echo "<div class=\"footer\">\n";
-  echo "  <p class=\"left\"> copyright 2006,2007,2008,2009,2010 <a href=\"$INDEX?action=about\">Arun Persaud, et al.</a> <br />\n".
+  echo "<footer>\n";
+  echo "  <p class=\"left\"> copyright 2006-2012 <a href=\"$INDEX?action=about\">Arun Persaud, et al.</a> <br />\n".
     "  Verwendung der [deutschen] Kartenbilder mit Genehmigung <br />der Spielkartenfabrik Altenburg GmbH,(c) ASS Altenburger <br />\n".
     "  - ASS Altenburger Spielkarten - Spielkartenfabrik Altenburg GmbH <br />\n".
     "  a Carta Mundi Company Email: info@spielkarten.com Internet: www.spielkarten.com</p>\n";
- echo " <p class=\"right\"> See the latest changes <a href=\"http://nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=summary\">\n".
 echo " <p class=\"right\"> See the latest changes <a href=\"http://nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=summary\">\n".
     "  via git </a> <br />or download the source via <br />\n'git clone http://nubati.net/git/e-DoKo.git' <br />\n".
     "  <a href=\"http://www.dreamhost.com/green.cgi\">\n".
-    "  <img  border=\"0\" alt=\"Green Web Hosting! This site hosted by DreamHost.\"".
-    "src=\"https://secure.newdream.net/green1.gif\" height=\"32\" width=\"100\" /></a>\n".
+    "  <img alt=\"Green Web Hosting! This site hosted by DreamHost.\"".
+    " src=\"pics/green1.gif\" height=\"32\" width=\"100\" /></a>\n".
     "  </p> \n";
-  echo "\n";
-  echo "</div>\n";
-
+  echo "</footer>\n\n";
   echo "</body>\n";
   echo "</html>\n";
 
@@ -482,15 +500,9 @@ function output_status()
       echo " | <a href=\"".$WIKI."\">"._('wiki/bugs')."</a>\n";
       echo " | <a href=\"".$RSS."?uid=".$myid."&amp;token=".$token."\">"._('atom')."</a>\n";
       echo " |&nbsp;&nbsp;&nbsp; <a href=\"".$INDEX."?action=logout\">"._('logout')."</a>\n";
-      echo "</div>\n";
+      echo "</div>\n\n";
 
-      echo "<div class=\"lastlogin\"><span>"._('last login').": ".date("r",$unixtime)."</span></div>\n";
-    }
-  else
-    {
-      echo "\n<div class=\"status\">\n";
-      echo "<a href=\"".$INDEX."\">"._('login')."</a>\n";
-      echo "</div>\n";
+      echo "<div class=\"lastlogin\"><span>"._('last login').": ".date("r",$unixtime)."</span></div>\n\n";
     }
   return;
 }
@@ -574,13 +586,13 @@ function output_password_recovery($email,$password)
        <legend>Password recovery</legend>
         <table>
          <tr>
-            <td><label for="email">Old password:</label></td>
+            <td><label for="password0">Old password:</label></td>
             <td><input type="password" id="password0" name="password0" size="20" maxlength="30" /> </td>
          </tr><tr>
-            <td><label for="password">New password:</label></td>
+            <td><label for="password1">New password:</label></td>
             <td><input type="password" id="password1" name="password1" size="20" maxlength="30" /></td>
          </tr><tr>
-            <td><label for="password">Retype:</label></td>
+            <td><label for="password2">Retype:</label></td>
             <td><input type="password" id="password2" name="password2" size="20" maxlength="30" /></td>
          </tr><tr>
            <td></td>
@@ -598,10 +610,10 @@ function output_user_notes($userid,$gameid,$userstatus)
   echo "<div class=\"notes\"> "._('Personal notes').": <br />\n";
   $notes = DB_get_notes_by_userid_and_gameid($userid,$gameid);
   foreach($notes as $note)
-    echo "$note <hr />\n";
+    echo "  $note <hr />\n";
   if($userstatus!='gameover')
-    echo "<input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
-  echo "</div> \n";
+    echo "  <input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
+  echo "</div>\n\n";
 
   return;
 }
@@ -681,6 +693,19 @@ function output_exchanged_cards()
   $show=1;
   for($mypos=1;$mypos<5;$mypos++)
     {
+      /* output comments */
+      if($mypos==2)
+       {
+         /* display all comments on the top right (card1)*/
+         $comments = DB_get_pre_comment($gameid);
+         /* display card */
+         echo "      <div class=\"card1\">\n";
+         /* display comments */
+         foreach( $comments as $comment )
+           echo "        <span class=\"comment\">".$comment[1].": ".$comment[0]."</span>\n";
+         echo "      </div>\n"; /* end div card */
+       }
+
       $usersick = DB_get_sickness_by_pos_and_gameid($mypos,$gameid);
       if($usersick!=NULL ||
         $mypos==$povertypos1 || $mypos==$partnerpos1 ||