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

if(isset($_POST['autoreplays'])) {
   if(!empty($_POST['repid'])) {
      $ettvd->autoreplaynum($_POST['repid'], $_POST['autoreplays']);
   }
   send('index.php');
}
if(isset($_POST['kill'])) {
   if($proc = intval($_POST['proc'])) {
      $ettvd->killproc($proc);
   }
   send('index.php');
}
if(isset($_POST['matchname'])) {
   if($recorder = intval($_POST['recorder'])) {
      $ettvd->gamename($recorder, trim($_POST['matchname']));
   }
   send('index.php');
}
if(isset($_POST['recmode'])) {
   if($recorder = intval($_POST['recorder'])) {
      $ettvd->recmode($recorder, $_POST['recmode']);
   }
   send('index.php');
}
if(isset($_POST['dellive'])) {
   foreach($_POST['rep'] AS $key => $value) {
      $replayer = intval($key);
   }
   $ettvd->dellive(intval($_POST['dellive']), $replayer);
   send('index.php');
}
if(isset($_POST['readynum'])) {
   if($recorder = intval($_POST['recorder'])) {
      $ettvd->readynum($recorder, intval($_POST['readynum']));
   }
   send('index.php');
}

if(isset($_GET['viewers']) && isset($_GET['repid'])) {
   if(false !== $viewers = $ettvd->fetch_viewerlist($_GET['repid'])) {
      $tpl->assign('viewers', $viewers);
      $tpl->assign('area', 'Viewers');
      $tpl->assign('body', $tpl->fetch('viewerlist.tpl'));
      require('finish.php');
   } else {
      send('index.php');
   }
}

$ettvd->fetch_servers();
$tpl->assign('javascripts', array('recedit'));
$tpl->assign('replayers', $ettvd->replayers);
$tpl->assign('recorders', $ettvd->recorders);


$tpl->assign('area', 'Servers');
$tpl->assign('body', $tpl->fetch('serverlist.tpl'));
require('finish.php');
?>