<?php
$PAGE = 'upload';

require_once '../models/tvlist.php';
require_once '../models/tv.php';
require_once '../models/userlist.php';
require_once '../models/datalist.php';
require_once '../models/dataform.php';

$myusername = substr($_SERVER['eppn'], 0, strpos($_SERVER['eppn'], '@'));

$TV = new Tvlist(User::getAccesNum($myusername));
$TVLIST = $TV->getTvlist();
$myusername = substr($_SERVER['eppn'], 0, strpos($_SERVER['eppn'], '@'));
$DATA = new Datalist($myusername);
$TYPE = $_GET["type"];

if(isset($_FILES)){
    $FORM = new Dataform($_POST, $TYPE, $_FILES);
}else{
    $FORM = new Dataform($_POST, $TYPE);
}


if($FORM->isSubmitted()){
    $FORM->validate();

    if($FORM->isValid()){
        $FORM->upload($FORM);
    }
}

include '../views/header.php';      // used: $PAGE, $TVLIST
include '../views/upload_form.php';      // used: $FORM, $TYPE
