X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=include%2Ffunctions.php;h=b4c344d244e436946d830bdc95c722491a7d15f4;hp=466b4ae34f631d7c6a08414ebbbdd079aa0943b9;hb=c1585e23cb3ea757674c234c9193889b4f2f2090;hpb=b568d14fe83e919b41452d8ae5b57a7dedc671cf diff --git a/include/functions.php b/include/functions.php index 466b4ae..b4c344d 100644 --- a/include/functions.php +++ b/include/functions.php @@ -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 "
\n"; - if(!$debug) - echo " $name \n"; + + if($debug) + echo " "; + if($vacation = check_vacation($user)) + { + $start = $vacation[0]; + $stop = substr($vacation[1],0,10); + $comment = $vacation[2]; + + $title = "begin: $start end: $stop $comment"; + echo " $name (on vacation until $stop) \n"; + } else - echo " $name\n"; + echo " $name \n"; + if($debug) + echo"\n"; /* add hints for poverty, wedding, solo, etc */ if( $gametype != "solo") @@ -777,14 +794,14 @@ 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 " \"poverty"; + echo " \"poverty"; else - echo " \"poverty"; + echo " \"poverty"; } else - echo " \"poverty\" />"; + echo " \"poverty\" title=\"poverty partner\" />"; if($GT=="dpoverty") if($party=="re") @@ -792,79 +809,79 @@ 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 " \"poverty"; + echo " \"poverty"; else - echo " \"poverty"; + echo " \"poverty"; } else - echo " \"poverty\" />"; + echo " \"poverty\" title=\"poverty partner\" />"; else if($sickness=="poverty") { $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 " \"poverty2"; + echo " \"poverty2"; else - echo " \"poverty2"; + echo " \"poverty2"; } else - echo " \"poverty2\" />"; + echo " \"poverty2\" title=\"poverty2 partner\" />"; if($GT=="wedding" && $party=="re") if($sickness=="wedding") - echo " \"wedding\""; + echo " \"wedding\""; else - echo " \"wedding"; + echo " \"wedding"; if(ereg("solo",$GT) && $party=="re") { if(ereg("queen",$GT)) - echo " \"$GT\""; + echo " \"$GT\""; else if(ereg("jack",$GT)) - echo " \"$GT\""; + echo " \"$GT\""; else if(ereg("club",$GT)) - echo " \"$GT\""; + echo " \"$GT\""; else if(ereg("spade",$GT)) - echo " \"$GT\""; + echo " \"$GT\""; else if(ereg("heart",$GT)) - echo " \"$GT\""; + echo " \"$GT\""; else if(ereg("trumpless",$GT)) - echo " \"$GT\""; + echo " \"$GT\""; else if(ereg("trump",$GT)) - echo " \"$GT\""; + echo " \"$GT\""; } /* add point calls */ if($call!=NULL) { if($party=="re") - echo " \"re\""; + echo " \"re\""; else - echo " \"contra\""; + echo " \"contra\""; switch($call) { case "0": - echo " \"0\""; + echo " \"0\""; break; case "30": - echo " \"30\""; + echo " \"30\""; break; case "60": - echo " \"60\""; + echo " \"60\""; break; case "90": - echo " \"90\""; + echo " \"90\""; break; } } echo "
\n"; - echo " local time\n"; - echo " last login\n"; + echo " time info\n"; echo "
\n"; } @@ -939,11 +956,12 @@ function generate_score_table($session) foreach($gameids as $gameid) { $re_score = DB_get_score_by_gameid($gameid); + $gametype = DB_get_gametype_by_gameid($gameid); foreach($player as $id=>$points) { $party = DB_get_party_by_gameid_and_userid($gameid,$id); if($party == "re") - if(DB_get_gametype_by_gameid($gameid)=="solo") + if($gametype=="solo") $player[$id] += 3*$re_score; else $player[$id] += $re_score; @@ -953,7 +971,7 @@ function generate_score_table($session) $score[$i]['gameid'] = $gameid ; $score[$i]['players'] = $player; $score[$i]['points'] = abs($re_score); - $score[$i]['solo'] = (DB_get_gametype_by_gameid($gameid)=="solo"); + $score[$i]['solo'] = ($gametype=="solo"); $i++; } @@ -982,12 +1000,14 @@ function generate_global_score_table() foreach($gameids as $gameid) { $re_score = DB_get_score_by_gameid($gameid); + $gametype = DB_get_gametype_by_gameid($gameid); + /* TODO: this shouldn't loop over all players, just the 4 players that are in the game */ foreach($player as $key=>$pl) { $party = DB_get_party_by_gameid_and_userid($gameid,$pl['id']); if($party == "re") - if(DB_get_gametype_by_gameid($gameid)=="solo") + if($gametype=="solo") $player[$key]['points'] += 3*$re_score; else $player[$key]['points'] += $re_score; @@ -1070,39 +1090,60 @@ function format_score_table_html($score,$userid) if(sizeof($score)==0) return ""; - $output = "
\n\n \n \n"; + $output = "
\n
\n"; /* output header */ - $output.= " "; + $header = ""; + $header.= " \n \n"; + $header.= " "; foreach($score[0]['players'] as $id=>$points) { $name = DB_get_name('userid',$id); /*TODO*/ - $output.= ""; + $header.= ""; } - $output.="\n \n \n \n"; + $header.="\n \n \n"; + /* use the same as footer */ + $footer = ""; + $footer.= " \n \n"; + $footer.= " "; + foreach($score[0]['players'] as $id=>$points) + { + $name = DB_get_name('userid',$id); /*TODO*/ + $footer.= ""; + } + $footer.="\n \n \n"; + + /* body */ + $body = ""; + $body.= " \n"; $i=0; foreach($score as $game) { $i++; - $output.=" "; + $body.=" "; $userhash = DB_get_hash_from_gameid_and_userid($game['gameid'],$userid); /* create link to old games only if you are logged in and its your game*/ if(isset($_SESSION['id']) && $_SESSION['id']==$userid) - $output.=" "; + $body.=" "; else - $output.=" "; + $body.=" "; foreach($game['players'] as $id=>$points) - $output.=""; - $output.=""; + $body.="\n"; + $body.= " S"; + $body.="\n"; } + $output.=$header; + if($i>12) + $output.=$footer; + $output.=$body; + $output.=" \n
No
No ".substr($name,0,2)." ".substr($name,0,2)." P
P
No ".substr($name,0,2)." P
$i $i$i$i".$points."".$game['points']; + $body.="".$points."".$game['points']; /* check for solo */ if($game['solo']) - $output.= " S"; - $output.="
\n
\n"; return $output; @@ -1133,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; +} ?>