<% /*
     $Revision$
     $Id$

    File:           scaffolding_print.asp
    Description:    print een model record met stylesheet
                        cust/XXXX/xsl/scf_<model.table>.xsl

    Parameters:     id natuurlijk

    Context:
    Note:

*/ %>
<!-- #include file="../Shared/xml_converter.inc" -->
<!-- #include file="../api2/api2_rest.inc" -->
<%
function scaffolding_print(model, scf_params)
{
    scf_params.print = scf_params.print || {};
    var allincludes = []
    if (!model.print.xmlnode && model.includes) // Bij xmlnode doen we toch niets met de data
    {
        allincludes = [];;
        for (var inc in model.includes)
            allincludes.push(inc);
    }

    var key = getQParamInt("id");
    var xxx_params = { filter: { id: key }, include: allincludes };
    var xxx_array = model.REST_GET(xxx_params);
    if (!xxx_array.length)
        shared.record_not_found();

    // Voor de xmlnode variant gebruiken we bovenstaande REST_GET helemaal niet
    // Toch voeren we die wel uit voor de automatische authorisatiecontrole
    if (model.print.xmlnode) // Die is simpel
    {
        if (model.print.key)
            key = xxx_array[0][model.print.key];
        FCLT2XMLResponse( {xmlnode: model.print.xmlnode, key: key, stylsesheet: model.print.xmlnode});
        Response.End; // Simpel klaar
    }

    var xxx_data = xxx_array[0];
    var xml_antwoord = api2_rest.json2xml(xxx_array, model, true);

    var style = new ActiveXObject("MSXML2.DOMDocument.6.0");
    style.async = false;
    style.resolveExternals = false;
    if (Request.QueryString("debug").Count == 0)
    {
        style.load(Server.MapPath(custpath + "/xsl/scf_" + model.table + ".xsl"));
        if (style.parseError.errorCode)
        {
          abort_with_warning("XSL error: " + style.parseError.reason + " @ " + style.parseError.line + "." + style.parseError.linepos );
        }
        var str_antwoord = xml_antwoord.transformNode(style); // terugstoppen in antwoord
    }
    else
    {
        if (Application("otap_environment") != "O")
            ONLY_ON_OTAP_O;

        style.load(Server.MapPath(rooturl + "/appl/shared/indent.xsl")); // De stylesheet laden. API's redeneren vanuit de root
        var str_antwoord = "<pre>" + Server.HTMLEncode(xml_antwoord.transformNode(style)) + "</pre>";
    }

    Response.write(str_antwoord);
    Response.End;
}
%>