<?php

require_once "inc/stdLib.php";
include "inc/template.inc";
include "inc/persLib.php";
if ($_POST["ok"]) {
    $fid = updDocFld($_POST);
    $docid = $_POST["docid"];
} else {
    if ($_POST["neu"]) {
        $fid = insDocFld($_POST);
        $docid = $_POST["docid"];
    } else {
        if ($_POST["del"]) {
            $fid = delDocFld($_POST);
            $docid = $_POST["docid"];
        } else {
            $docid = $_GET["docid"] ? $_GET["docid"] : $_POST["docid"];
        }
    }
}
$link2 = "dokument2.php?did={$docid}";
$link3 = "dokument3.php?docid={$docid}";
$doc = getDocVorlage($docid);
$t = new Template($base);
doHeader($t);
$t->set_file(array("doc" => "dokument3.tpl"));
$t->set_var(array(Link2 => $link2, Link3 => $link3, vorlage => $doc["document"]["vorlage"]));
$t->set_block("doc", "Liste", "Block");
if ($doc["felder"]) {
    foreach ($doc["felder"] as $zeile) {
        if ($_POST['did'] != $did) {
            $doc->loadDocument("vorlage/" . $_FILES['file']['name']);
            $vars = $doc->getTags();
            if ($ext == 'rtf') {
                $doc->savefile("vorlage/" . $_FILES['file']['name']);
            }
            $data['beschreibung'] = '';
            $data['zeichen'] = '.';
            $data['laenge'] = 25;
            $data['docid'] = $did;
            $p = 1;
            foreach ($vars as $hit) {
                $data['feldname'] = $hit;
                $data['platzhalter'] = $hit;
                $data['position'] = $p;
                insDocFld($data);
                $p++;
            }
        }
        $msg = '';
    } else {
        $msg = 'Falsches Dateiformat';
    }
} else {
    if ($_POST["del"]) {
        $did = delDocVorlage($_POST);
    }
}
$link2 = "dokument2.php?did=" . $_GET["did"];
if ($did) {
    $link3 = "dokument3.php?docid=" . $did;