NEW FEATURE: vacation support
[e-DoKo.git] / include / functions.php
index cb09d6c6ad33a55b83283ea11eb96238b15c9a0d..b4c344d244e436946d830bdc95c722491a7d15f4 100644 (file)
@@ -329,17 +329,22 @@ function check_wedding($cards)
   return 0;
 }
 
-function count_trump($cards)
+function count_trump($cards,$status='pregame')
 {
   global $RULES;
 
   $trump = 0;
 
-  /* count each trump, including the foxes */
+  /* count each trump, including the foxes, since this is used to determine poverty status */
   foreach($cards as $c)
     if( (int)($c) <27)
       $trump++;
 
+  /* In case we really want to know the amount of trump, we can use the status variable.
+   * This is needed for example to figure out what icon to display on the table in case of
+   * trump given back in poverty */
+  if($status=='all') return $trump;
+
   /* normally foxes don't count as trump, so we substract them here
    * in case someone has schweinchen, one or two of them should count as trump
    * though, so we need to add one trump for those cases */
@@ -727,7 +732,7 @@ function can_call($what,$hash)
 
 function display_table ()
 {
-  global $gameid, $GT, $debug,$INDEX,$defaulttimezone;
+  global $gameid, $GT, $debug,$INDEX,$defaulttimezone,$session;
   global $RULES,$GAME,$gametype;
 
   $result = DB_query("SELECT  User.fullname as name,".
@@ -762,10 +767,22 @@ function display_table ()
       $timenow   = strtotime(date("Y-m-d H:i:s"));
 
       echo "  <div class=\"table".($pos-1)."\">\n";
-      if(!$debug)
-       echo "   $name \n";
+
+      if($debug)
+       echo "   <a href=\"".$INDEX."?action=game&amp;me=".$hash."\">";
+      if($vacation = check_vacation($user))
+       {
+         $start   = $vacation[0];
+         $stop    = substr($vacation[1],0,10);
+         $comment = $vacation[2];
+
+             $title = "begin: $start  end: $stop $comment";
+             echo "   <span class=\"vacation\" title=\"$title\">$name (on vacation until $stop)</span> \n";
+       }
       else
-       echo "   <a href=\"".$INDEX."?action=game&amp;me=".$hash."\">$name</a>\n";
+       echo "   $name \n";
+      if($debug)
+       echo"</a>\n";
 
       /* add hints for poverty, wedding, solo, etc */
       if( $gametype != "solo")
@@ -777,7 +794,7 @@ function display_table ()
          {
            $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
            $cards    = DB_get_all_hand($userhash);
-           $trumpNR  = count_trump($cards);
+           $trumpNR  = count_trump($cards,'all');
            if($trumpNR)
              echo "   <img src=\"pics/button/poverty_trump_button.png\" class=\"button\" alt=\"poverty < trump back\" title=\"poverty - trump back\" />";
            else
@@ -792,7 +809,7 @@ function display_table ()
            {
              $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
              $cards    = DB_get_all_hand($userhash);
-             $trumpNR  = count_trump($cards);
+             $trumpNR  = count_trump($cards,'all');
              if($trumpNR)
                echo "   <img src=\"pics/button/poverty_trump_button.png\" class=\"button\" alt=\"poverty < trump back\" title=\"poverty - trump back\" />";
              else
@@ -805,7 +822,7 @@ function display_table ()
            {
              $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
              $cards    = DB_get_all_hand($userhash);
-             $trumpNR  = count_trump($cards);
+             $trumpNR  = count_trump($cards,'all');
              if($trumpNR)
                echo "   <img src=\"pics/button/poverty2_trump_button.png\" class=\"button\" alt=\"poverty2 < trump back\" title=\"poverty2 - trump back\"/>";
              else
@@ -863,8 +880,8 @@ function display_table ()
        }
 
       echo "    <br />\n";
-      echo "    <span title=\"".date("Y-m-d H:i:s",$timenow).  "\">local time</span>\n";
-      echo "    <span title=\"".date("Y-m-d H:i:s",$lastlogin)."\">last login</span>\n";
+      echo "    <span title=\"local time: ".date("Y-m-d H:i:s",$timenow).  " ".
+                            "last login: ".date("Y-m-d H:i:s",$lastlogin)."\">time info</span>\n";
       echo "   </div>\n";
 
     }
@@ -1157,5 +1174,38 @@ function getCache($cacheFile, $expireTime)
   return false;
 }
 
+function check_vacation($userid)
+{
+  /* get start date */
+  $result = DB_query_array("SELECT value FROM User_Prefs".
+                    " WHERE user_id='$userid' AND pref_key='vacation start'" );
+  if($result)
+    $start = $result[0];
+  else
+    return NULL;
+
+  /* get end date */
+  $result = DB_query_array("SELECT value FROM User_Prefs".
+                    " WHERE user_id='$userid' AND pref_key='vacation stop'" );
+  if($result)
+    $stop = $result[0];
+  else
+    return NULL;
+
+  /* get comment */
+  $result = DB_query_array("SELECT value FROM User_Prefs".
+                    " WHERE user_id='$userid' AND pref_key='vacation comment'" );
+  if($result)
+    $comment = $result[0];
+  else
+    $comment = '';
+
+  /* check if user is on vacation. TODO: use user's timezone */
+  if( (time() - strtotime($start) >0) &&
+      (strtotime($stop) - time()  >0))
+    return array ($start,$stop,$comment);
+  else
+    return NULL;
+}
 
 ?>