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

if(isset($_POST['edit'])) {
   if(!$recorder = intval($_POST['recorder'])) send('index.php');

   $ettvd->fetch_recorders();
   if(!isset($ettvd->recorders[$recorder])) send('index.php');

   if(!empty($_POST['matchserver']) && $_POST['matchserver'] != $ettvd->recorders[$recorder]['master'] && !empty($_POST['serverpass']) && !empty($_POST['ettvpass'])) {
      $ettvd->hopserver($recorder, $_POST['matchserver'], $_POST['serverpass'], $_POST['ettvpass']);
   }

   if(isset($_POST['createnew'])) {
      $ettvd->newdemo($_POST['recorder'], $_POST['gamename'], $_POST['recmode'], $_POST['autodisconnect']);
   } else {
      $ettvd->recmode($_POST['recorder'], $_POST['recmode']);
      $ettvd->autodisconnect($_POST['recorder'], $_POST['autodisconnect']);
      $ettvd->gamename($_POST['recorder'], $_POST['gamename']);
   }
   if($_POST['recmode'] == 'ready' && intval($_POST['readynum']) != $ettvd->recorders[$recorder]['readynum']) $ettvd->readynum($recorder, intval($_POST['readynum']));
   send('index.php');
}



$recorder = intval($_GET['recid']);

$ettvd->fetch_recorders();
if(!isset($ettvd->recorders[$recorder])) {
   Header('Location: index.php');
   exit;
}

$tpl->assign('recorder', $ettvd->recorders[$recorder]);
$tpl->assign('body', $tpl->fetch('recedit.tpl'));
$tpl->assign('area', 'Edit Recorder');
require('finish.php');

?>