+ {
+ DB_set_game_status_by_gameid($gameid,"gameover");
+ /* get score for last trick
+ * all other tricks are handled a few lines further down*/
+ $play = DB_get_cards_by_trick($trickid);
+ $winner = get_winner($play,$gametype); /* returns the position */
+ /* get points of last trick and save it */
+ $points = 0;
+ foreach($play as $card)
+ $points = $points + card_value($card);
+ $winnerid = DB_get_handid_by_gameid_and_position($gameid,$winner);
+ if($winnerid>0)
+ mysql_query("INSERT INTO Score VALUES (NULL, '$gameid', '$winnerid', '$points')");
+ else
+ echo "ERROR during scoring";
+
+ /* email all players */
+ $result = mysql_query("SELECT fullname, SUM(score) FROM Score".
+ " LEFT JOIN Hand ON Hand.id=hand_id".
+ " LEFT JOIN User ON Hand.user_id=User.id".
+ " WHERE Hand.game_id=$gameid".
+ " GROUP BY fullname" );
+ $message = "The game is over. Thanks for playing :)\n";
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ $message .= " FINAL SCORE: ".$r[0]." ".$r[1]."\n";
+ $message .= "\nIf your not in the list above your score is zero...\n";
+ foreach($userids as $user)
+ {
+ $To = DB_get_email_by_userid($user);
+ mymail($To,"[DoKo] game over",$message);
+ }
+ }