<?php
require('includes/global.php');
$ettvd->init();

if(isset($_POST['play'])) {
   $error = array();
   
   if(intval($_POST['replayer']) < 1) $error['replayer'] = ERROR;
   if(!isset($_POST['demo']))         $error['demo'] = ERROR;
   
   if(empty($error)) {
      if($ettvd->playgame($_POST['replayer'], $_POST['demo'])) {
         send('index.php');
      }
   } else {
      $tpl->assign('error', $error);
   }
}

$ettvd->fetch_replayers();
$str = '<select name="replayer">';
if(empty($ettvd->replayers)) {
   $str .= '<option value="0">No replayers running</option>';
} else {
   foreach($ettvd->replayers AS $replayer) {
      $str .= '<option value="'.$replayer['num'].'"';
      if($replayer['num'] == intval($_GET['player'])) $str.= ' selected="selected"';
      $str .= '>'.$replayer['num'].' ('.$replayer['ip'].')</option>';
   }
}
$tpl->assign('replayer', $str.'</select>');

$tpl->assign('area', 'Play Demo');
$tpl->assign('body', $tpl->fetch('play.tpl'));
require('finish.php');
?>