LAYOUT: fixed some typos, changed CSS a bit
[e-DoKo.git] / index.php
index bf96982f7a61e653a13b43df8631d604d086fb9c..a0e2fb2445180d6c407fb43417c761c6ee167307 100644 (file)
--- a/index.php
+++ b/index.php
@@ -29,18 +29,22 @@ if(myisset("logout"))
     session_unset();
     session_destroy();
     $_SESSION = array();
-    echo "you are now logged out!";
+    echo "<div class=\"message\"><span class=\"bigger\">You are now logged out!</span><br />\n".
+      "(<a href=\"$host\">This will take you back to the home-page</a>)</div>";
   }
 else if(myisset("new"))
   {
     if( isset($_SESSION["name"]) )
       {
        $names = DB_get_all_names();
+       echo "<div class=\"user\">\n";
        output_form_for_new_game($names);
+       echo "</div>\n";
+       display_user_menu();
       }
     else
       {
-       echo "Please log in.";
+       echo "<div class=\"message\">Please <a href=\"$host\">log in</a>.</div>";
       }
   }
 /*check if everything is ready to set up a new game */
@@ -1401,13 +1405,13 @@ else if(myisset("me"))
                    "      <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
                }
 
-             echo "<div class=\"card".($pos-1)."\">";
+             echo "      <div class=\"card".($pos-1)."\">\n        ";
 
              /* display comments */
              display_card($card,$PREF["cardset"]);
              if($comment!="")
-               echo "  <span class=\"comment\"> ".$comment."</span>\n";
-             echo "</div></div></li>\n";
+               echo "\n        <span class=\"comment\"> ".$comment."</span>\n";
+             echo "      </div>\n";
 
              /*check if we still have cards left, else set status to gameover */
              if(sizeof(DB_get_hand($me))==0)
@@ -1479,8 +1483,13 @@ else if(myisset("me"))
                      else if($r[0] == "contra")
                        $contra = $r[1];
                    }
-                 /* save score in database */
-                 // get calls from re/contra
+
+                 /*
+                  * save score in database
+                  *
+                  */
+
+                 /* get calls from re/contra */
                  $call_re     = NULL;
                  $call_contra = NULL;
                  foreach($userids as $user)
@@ -1509,85 +1518,126 @@ else if(myisset("me"))
                            }
                        }
                    }
-                 // no call, check 120:120
-                 if($call_re == NULL && $call_contra==NULL)
-                   if($re==120)
-                     mysql_query("INSERT INTO Score".
-                                 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'againstqueens')");
 
-                 // no call or one call do scoring
-                 if($call_re != NULL && $call_contra!=NULL)
-                   {
-                     // two calls: not sure what to do yet
-                   }
+                 /* figure out who one */
+                 $winning_party = NULL;
+
+                 if($call_re == NULL && $call_contra==NULL)
+                   if($re>120)
+                     $winning_party="re";
+                   else
+                     $winning_party="contra";
                  else
                    {
-                     $offset = 0;
+                     if($call_re)
+                       {
+                         $offset = 120 - $call_re;
+                         if($call_re == 0)
+                           $offset--; /* since we use a > in the next equation */
+
+                         if($re > 120+$offset)
+                           $winning_party="re";
+                         else if ( $call_contra == NULL )
+                           $winning_party="contra";
+                       }
 
-                     if($call_re!=NULL)
-                       $offset = 120 - $call_re;
-                     else if($call_contra!=NULL)
-                       $offset = -1*(120 - $call_contra)-1;
+                     if($call_contra)
+                       {
+                         $offset = 120 - $call_contra;
+                         if($call_contra == 0)
+                           $offset--; /* since we use a > in the next equation */
+
+                         if($contra > 120+$offset)
+                           $winning_party="contra";
+                         else if ( $call_contra == NULL )
+                           $winning_party="re";
+                       }
+                   }
 
-                     if($call_re==0)
-                       $offset -= 1;
+                 /* one point for each call of the other party in case the other party didn't win
+                  * and one point each in case the party made more than points than one of the calls
+                  */
+                 if($winning_party!="contra" && $call_contra!=NULL)
+                   {
+                     for( $p=$call_contra;$p<=120; $p+=30 )
+                       {
+                         mysql_query("INSERT INTO Score".
+                                     " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'against$p')");
+                       }
 
-                     if($call_contra==0)
-                       $offset += 1;
+                     for( $p=$call_contra; $p<120; $p+=30)
+                       {
+                         if( $re >= $p )
+                           mysql_query("INSERT INTO Score".
+                                       " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'made$p')");
+                       }
+                   }
+                 if($winning_party!="re" and $call_re!=NULL)
+                   {
+                     for( $p=$call_re;$p<=120; $p+=30 )
+                       {
+                         mysql_query("INSERT INTO Score".
+                                     " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'against$p')");
+                       }
 
-                     if($re > 120 + $offset)
+                     for( $p=$call_re; $p<120; $p+=30)
                        {
-                         /* re won */
+                         if( $contra>=$p )
+                           mysql_query("INSERT INTO Score".
+                                       " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'made$p')");
+                       }
+                   }
 
-                         /* normal win */
-                         foreach(array(120,150,180,210,240) as $p)
-                           {
-                             $offset = 0;
-                             if($p==240)
-                               $offset = 1;
+                 /* point in case contra won */
+                 if($winning_party=="contra")
+                   {
+                     mysql_query("INSERT INTO Score".
+                                 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'againstqueens')");
+                   }
 
-                             if($re>$p-$offset)
-                               mysql_query("INSERT INTO Score".
-                                           " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'".(240-$p)."')");
-                           }
+                 /* one point each for winning and each 30 points + calls */
+                 if($winning_party=="re")
+                   {
+                     foreach(array(120,150,180,210,240) as $p)
+                       {
+                         $offset = 0;
+                         if($p==240 || $call_contra!=NULL)
+                           $offset = 1;
 
-                         /* re called something and won */
-                         if($call_re!=NULL)
-                           foreach(array(0,30,60,90,120) as $p)
-                             {
-                               if($call_re<$p+1)
-                                 mysql_query("INSERT INTO Score".
-                                             " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'call$p')");
-                             }
+                         if($re>$p-$offset)
+                           mysql_query("INSERT INTO Score".
+                                       " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'".(240-$p)."')");
                        }
-                     else
+                     /* re called something and won */
+                     foreach(array(0,30,60,90,120) as $p)
                        {
-                         /* contra won */
-                         mysql_query("INSERT INTO Score".
-                                     " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'againstqueens')");
-
-                         /* normal win */
-                         foreach(array(120,150,180,210,240) as $p)
-                           {
-                             $offset = 0;
-                             if($p==240)
-                               $offset = 1;
-
-                             if($re>$p-$offset)
-                               mysql_query("INSERT INTO Score".
-                                           " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'".(240-$p)."')");
-                           }
+                         if($call_re!=NULL && $call_re<$p+1)
+                           mysql_query("INSERT INTO Score".
+                                       " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'call$p')");
+                       }
+                   }
+                 else if( $winning_party=="contra")
+                   {
+                     foreach(array(120,150,180,210,240) as $p)
+                       {
+                         $offset = 0;
+                         if($p==240 || $call_re!=NULL)
+                           $offset = 1;
 
-                         /* contra called something and won */
-                         if($call_contra!=NULL)
-                           foreach(array(0,30,60,90,120) as $p)
-                             {
-                               if($call_contra<$p+1)
-                                 mysql_query("INSERT INTO Score".
-                                             " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'call$p')");
-                             }
+                         if($contra>$p-$offset)
+                           mysql_query("INSERT INTO Score".
+                                       " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'".(240-$p)."')");
+                       }
+                     /* re called something and won */
+                     foreach(array(0,30,60,90,120) as $p)
+                       {
+                         if($call_contra!=NULL && $call_contra<$p+1)
+                           mysql_query("INSERT INTO Score".
+                                       " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'call$p')");
                        }
                    }
+
+
                  /* send out final email */
                  $all = array();
 
@@ -1640,7 +1690,7 @@ else if(myisset("me"))
                                " GROUP BY User.fullname" );
          while( $r = mysql_fetch_array($result,MYSQL_NUM))
            echo "      <div class=\"card".($r[3]-1)."\">\n".
-                "        <span class=\"score\">".$r[2]."<br /> ".$r[1]."</span>\n".
+                "        <div class=\"score\">".$r[2]."<br /> ".$r[1]."</div>\n".
                 "      </div>\n";
 
          echo "    </div>\n  </li>\n";  /* end div trick, end li trick */
@@ -1713,7 +1763,7 @@ else if(myisset("me"))
       /* check if game is over, display results */
       if(DB_get_game_status_by_gameid($gameid)=='play')
        {
-         echo "the game is over for you.. other people still need to play though";
+         echo "The game is over for you.. other people still need to play though";
        }
       else
        {
@@ -1728,8 +1778,26 @@ else if(myisset("me"))
          echo "<div class=\"total\"> Totals:<br />\n";
          while( $r = mysql_fetch_array($result,MYSQL_NUM))
            echo "  ".$r[0]." ".$r[1]."<br />\n";
+
+         echo "<div class=\"re\">\n Points Re: <br />\n";
+         $queryresult = mysql_query("SELECT score FROM Score ".
+                                    "  WHERE game_id=$gameid AND party='re'".
+                                    " ");
+         while($r = mysql_fetch_array($queryresult,MYSQL_NUM) )
+           echo "   ".$r[0]."<br />\n";
+         echo "</div>\n";
+
+         echo "<div class=\"contra\">\n Points Contra: <br />\n";
+         $queryresult = mysql_query("SELECT score FROM Score ".
+                                    "  WHERE game_id=$gameid AND party='contra'".
+                                    " ");
+         while($r = mysql_fetch_array($queryresult,MYSQL_NUM) )
+           echo "   ".$r[0]."<br />\n";
+         echo "</div>\n";
+
          echo "</div>\n";
 
+
        }
       break;
     default:
@@ -2059,7 +2127,7 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
         }
        else
         {
-          echo "Sorry email and password don't match. Please <a href=\"$host\">try again</a>. <br />";
+          echo "<div class=\"message\">Sorry email and password don't match. Please <a href=\"$host\">try again</a>. </div>";
         }
      };
      output_footer();