<?php
$expand_view=0;
if (isset($_GET['expand_view']))
  $expand_view=$_GET['expand_view'];

$BODY.='<table class="list"><tr>';
    if ($expand_view)
      $BODY.='<th><a href="index.php?page=games" target="_top">'.add_icon("arrow_in").'</a></th>';
    else
      $BODY.='<th><a href="index.php?page=games&expand_view=1" target="_top">'.add_icon("arrow_out").'</a></th>';
$BODY.='   <th>Datum, Zeit</th>
           <th>Spielerzahl</th>
           <th>Rangspiel</th>
           <th>Sieger</th>
           <th>Zweiter</th>
           <th>Dritter</th>
         </tr>';

$query=mysqli_query($db, "SELECT * FROM `games` ORDER BY `datetime` ASC");
while ($data=mysqli_fetch_array($query)) {
  $id=$data['id'];
    $BODY.="<tr><td>";
    if (LOGIN!="")
      $BODY.="<a href=\"index.php?page=edit_game&edit_id=$id\" target=\"_top\">".add_icon("pencil")."</a>";
    $BODY.="</td>";
    $BODY.="<td>".gibmirzeit_von_datetime(DATETIMEFORMAT,$data['datetime'])."</td>\n";
    $BODY.="<td>".count(player_of_game($id))."</td>\n";
    $BODY.="<td>".(($data['scoregame']=="TRUE") ? add_icon("accept"):"")."</td>\n";
    $BODY.="<td style=\"align:right\">".user_id_to_alias($data['first_id']).(($expand_view)? "(".print_bill($data['first_bill']).")":"")."</td>\n";
    $BODY.="<td style=\"align:right\">".user_id_to_alias($data['second_id']).(($expand_view)? "(".print_bill($data['second_bill']).")":"")."</td>\n";
    $BODY.="<td style=\"align:right\">".user_id_to_alias($data['third_id']).(($expand_view)? "(".print_bill($data['third_bill']).")":"")."</td>\n";
    $BODY.="</tr>";
    if ($expand_view) {
    $BODY.="<tr><td></td>";
    $BODY.="<td valign=\"top\">".htmlentities(nl2br($data['location']))."</td>\n";
    $BODY.="<td colspan=\"5\"><i>Spieler: ";
    $player_array=player_of_game($id);
    $i=0;
    for ($i=0;$i<count($player_array);$i++) {
      $BODY.=user_id_to_alias($player_array[$i]);
      if ($i<(count($player_array)-1)) $BODY.=", ";
    }
    $BODY.=" (Pott: ".print_bill($data['base_bill']*$i).")</i></td>";
    $BODY.="</tr><tr><td>&nbsp;</td></tr>";
    }
}
$BODY.='       </table>';
?>
