function _showAllMat()
{
    $materie = new Materii(getdbh());
    $result['materii'] = $materie->fetchMaterii();
    $data['msg'][] = View::do_fetch(VIEW_PATH . 'showAllMat.tpl.php', $result);
    View::do_dump(VIEW_PATH . 'layout.php', $data);
}
function _show_materii()
{
    $materii = new Materii(getdbh());
    $allMaterii = $materii->fetchGroupaAndMateria();
    $result['materii'] = $allMaterii;
    $data['msg'][] = View::do_fetch(VIEW_PATH . 'afisare_materii.tpl.php', $result);
    View::do_dump(VIEW_PATH . 'layout.php', $data);
}
function _updateMaterii()
{
    isUserLoggedIn();
    $materii = new Materii(getdbh());
    $result = $materii->updateMaterii($_POST['idMaterie'], $_POST['credite'], $_POST['denumire'], $_POST['idProf']);
    if ($result) {
        $data['msg'][] = 'Materia a fost modificata cu success';
        $data['redirect'][] = 'administrare/show_materii';
        View::do_dump(VIEW_PATH . 'layout.php', $data);
    } else {
        $data['msg'][] = "Eroare la modificarea materiei";
        $data['redirect'][] = 'administrare/show_materii';
        View::do_dump(VIEW_PATH . 'layout.php', $data);
    }
}
function _suportCurs()
{
    isUserLoggedIn();
    if (getUserType() == 'student') {
        $data['msg'][] = View::do_fetch(VIEW_PATH . 'suport_curs_stud.php');
        View::do_dump(VIEW_PATH . 'layout.php', $data);
    } else {
        $grupa = new Grupa(getdbh());
        $getGroups = $grupa->fetchAll();
        $result['grupa'] = $getGroups;
        $materie = new Materii(getdbh());
        $getMaterii = $materie->fetchGroupaAndMateria();
        $result['materie'] = $getMaterii;
        $data['msg'][] = View::do_fetch(VIEW_PATH . 'suport_curs_prof.php', $result);
        View::do_dump(VIEW_PATH . 'layout.php', $data);
    }
}
function _adminTeme()
{
    isUserLoggedIn();
    switch ($_POST['actiune']) {
        case 'add':
            $tema = new Teme(getDbh());
            $materii = new Materii(getdbh());
            // $fetch = $materii->getMateriiDetails($_POST['grupaID']);
            $fetch = $materii->getMateriiDetails(1);
            if ($_FILES['fileToUpload']['name'] != '') {
                if ($_FILES['fileToUpload']['size'] > 5242880) {
                    redirect('teme1');
                }
                $file = $_FILES['fileToUpload']['tmp_name'];
                $new_file_name = strtolower($_FILES['fileToUpload']['name']);
                $FileType = pathinfo($new_file_name, PATHINFO_EXTENSION);
                if ($FileType != "xml" && $FileType != "png" && $FileType != "bmp" && $FileType != "jpg" && $FileType != "gif" && $FileType != "doc" && $FileType != "docx" && $FileType != "pdf") {
                    echo "Sorry, only JPG, PNG, GIF, DOC, DOCX, BMP, PDF, XML files are allowed.";
                    redirect('teme2');
                }
            }
            if ($_FILES['fileToUpload']['name'] != '') {
                $result = $tema->addTema($fetch['ID_USER'], $_POST['grupaID'], $_POST['materie'], $_POST['denumire'], $_POST['detalii'], $file);
            } else {
                $result = $tema->addTema($fetch['ID_USER'], $_POST['grupaID'], $_POST['materie'], $_POST['denumire'], $_POST['detalii']);
            }
            if ($result) {
                $data['msg'][] = "Tema de licenta a fost adaugata  cu success";
                $data['redirect'][] = 'teme';
                View::do_dump(VIEW_PATH . 'layout.php', $data);
            } else {
                $data['msg'][] = "Eroare la adaugare";
                $data['redirect'][] = 'teme';
                View::do_dump(VIEW_PATH . 'layout.php', $data);
            }
            break;
        case 'edit':
        case 'delete':
            break;
        default:
            //echo "wrong action"
            break;
    }
}
function _getMateria()
{
    $materii = new Materii(getdbh());
    $result = $materii->fetchGrupaMaterii($_POST['id']);
    echo json_encode($result);
}