<?php

require_once '../models/tvlist.php';
require_once '../models/tvform.php';
require_once '../models/userlist.php';
require_once '../models/userform.php';
require_once '../models/user.php';
require_once '../models/datalist.php';

$PAGE = 'additem';
$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'], '@'));


if(isset($_GET['itemtype'])){
    if($_GET['itemtype'] == "tv"){
        $old = "Adja meg a nevet/azonosítót!";
        $TVFORM = new TvForm($_POST, $old);
        if(isset($TVFORM)){
            $TVFORM->validate();
            if($TVFORM->isSubmitted() && $TVFORM->isValid()){
                $TVFORM->add($_POST);
            }
        }
    }
    elseif($_GET['itemtype'] == "user"){
        $old = "Adja meg a nevet!";
        $UFORM = new UserForm($_POST, $old);
        if(isset($UFORM)){
            $UFORM->validate();

            if($UFORM->isSubmitted() && $UFORM->isValid()){
                $UFORM->add($_POST);
            }
        }
    }
}


include '../views/header.php'; // used: $PAGE $TVLIST

if (isset($_GET['itemtype'])) {
    if($_GET['itemtype'] == "tv"){
        $ADDTV = new Tv("");
        $ACTIONS = $ADDTV->getAllActId(substr($_SERVER['eppn'], 0, strpos($_SERVER['eppn'], '@')));
        include '../views/add_tv.php';
    }
    elseif($_GET['itemtype'] == "user"){
        $ADDUSER = new User("", "", "");
        $GROUPS = $ADDUSER->getAllGroups(substr($_SERVER['eppn'], 0, strpos($_SERVER['eppn'], '@')));
        include '../views/add_user.php';
    }
}
