<%@language = "javascript" %>
<% /*  $Revision$
    $Id$

    File:        workflow_graph.asp
    Description: Maak een mooie grafiek
    Parameters:  start_key (REQUIRED)
    Context:
    Note:        as-is

*/ %>

<%
DOCTYPE_Disable = 1;
%>

<!-- #include file="../Shared/common.inc" -->

<%
    var chl = [];

    var start_key = getQParamInt("start_key", -1);

    var sql = "SELECT mld_workflowstep_omschrijving,"
            + "       mld_workflowstep_start_key,"
            + "       mld_workflowstep_key,"
            + "       mld_stdmelding_omschrijving"
            + "  FROM mld_workflowstep ws,"
            + "       mld_stdmelding ms"
            + " WHERE ws.mld_stdmelding_key = ms.mld_stdmelding_key";

    if (start_key > 0) sql +="   AND (ws.mld_workflowstep_key = "+start_key+" OR ws.mld_workflowstep_start_key = "+start_key+")";

    var oRs = Oracle.Execute(sql);
    while (!oRs.Eof)
    {
        var to = oRs("mld_workflowstep_key").Value;
        chl.push("WS_"+to+ " [ label=\""+oRs("mld_workflowstep_omschrijving").Value+"\\n["+oRs("mld_stdmelding_omschrijving").Value+"]\"]");
        oRs.MoveNext();
    }

/*    var sql = "SELECT mld_workflowstep_omschrijving,"
            + "       mld_workflowstep_start_key,"
            + "       mld_workflowstep_key"
            + "  FROM mld_workflowstep"
            + " WHERE mld_workflowstep_start_key IS NOT NULL";

    var oRs = Oracle.Execute(sql);
    while (!oRs.Eof)
    {
        var from = oRs("mld_workflowstep_start_key").Value;
        var to = oRs("mld_workflowstep_key").Value;
        chl.push("WS_"+from + "--" + "WS_"+to); //  + " [ label=\"Test\"]"
        oRs.MoveNext();
    }
*/

    var sql = "SELECT mld_workflowrule_omschrijving,"
            + "       mld_workflowrule_condition,"
            + "       mld_workflowstep_key,"
            + "       mld_workflowstep_next_key"
            + "  FROM mld_workflowrule";
    if (start_key > 0) sql += " WHERE mld_workflowstep_key IN (SELECT mld_workflowstep_key FROM mld_workflowstep ws WHERE ws.mld_workflowstep_key = "+start_key+" OR ws.mld_workflowstep_start_key = "+start_key+")";

    var oRs = Oracle.Execute(sql);
    while (!oRs.Eof)
    {
        var from = oRs("mld_workflowstep_key").Value;
        var to = oRs("mld_workflowstep_next_key").Value;
        var cond = oRs("mld_workflowrule_condition").Value;
        chl.push("WS_"+from + "->" + "WS_"+to + " [ label=\""+oRs("mld_workflowrule_omschrijving").Value+ (cond?"\\nCOND: "+cond:"") +"\"]");
        oRs.MoveNext();
    }
    ttl = "";
//    url = "http://chart.apis.google.com/chart?"
    post = ""//"http://chart.apis.google.com/chart?"
        + "&cht=gv:dot"
        + "&chl=digraph{"+chl.join(";")+"}"

    var objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")

    objXMLHTTP.open("POST",
                    "http://chart.apis.google.com/chart",
                    false);
    //objXMLHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

   objXMLHTTP.send(post);

    if (objXMLHTTP.status==200)
    {   Response.contenttype = "image/png";
        Response.BinaryWrite(objXMLHTTP.responseBody);
    }
    else
    {
        Response.Write("Mislukt, status = " + objXMLHTTP.status);
        Response.Write(objXMLHTTP.statusText);
        Response.Write(objXMLHTTP.responseText);
    }


%>