<?php

if (core::ifPost("from") AND core::getPost("from") == "document") {

    if(core::getPost("id") == "add"){
        $add = document::add();
        if($add != FALSE) {
            session::resetTemp();
            $location = "/document-". $add .".html";
        } else {
            $location = "/add-document.html";
        }
    } else {
        document::update();
        $location = "/document-". core::getPost("id") .".html";
    }

    json::create("documents");
    json::create("documents-limited");
    document::cleanOrphanTags();

    header("Location: " . $location);
    exit();
} else {
    header('HTTP/1.0 401 Unauthorized');
    exit();
}

