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

     File:          NaarWorldmeeting.asp
     Description:   Haal een request-url van Worldmeeting op
                    Dat levert een url op waar we daarna naar redirecten

     Parameters:
     Status:
     Context:
     Notes:
*/
%>
<!--#include file="../../appl/Shared/common.inc" -->
<%
var xmlUrl = "https://services.worldmeetings.com/api/v1.0/Order"
var xmlResp;

var xmlhttp = new ActiveXObject("WinHTTP.WinHTTPRequest.5.1");

user.checkAutorisation("WEB_USER24"); // UWVA#31893: Doorlinken naar Worldmeetings alleen met USER24-rechten!

//SXH_PROXY_SET_PROXY = 2
//xmlhttp.setProxy(SXH_PROXY_SET_PROXY, "127.0.0.1:8888"); // Voor debugging met Fiddler
xmlhttp.open("POST", xmlUrl, false);
xmlhttp.SetCredentials("UwvFacilitor","mUSeTu33je8eGEWe", 0);
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8")

// Zonder de ns: twee keer krijg ik
// Validation error in message. Error message: cvc-complex-type.2.4.a:
//        Invalid content was found starting with element 'personalDetails'.
//        One of '{personalDetails}' is expected.

var naam = user.prs_perslid_achternaam();
if (user.prs_perslid_tussenvoegsel())
    naam = user.prs_perslid_tussenvoegsel() + " " + naam;

var req = "<ns:createRequestRequestMessage xmlns:ns=\"http://services.worldmeetings.com/services/v1.0/Order\">"
        + "  <personalDetails>"
        + "      <firstName>" + safe.html(user.prs_perslid_voornaam()) + "</firstName>"
        + "      <lastName>" + safe.html(naam) + "</lastName>"
        + "      <department>" + safe.html(user.afdeling().naam()) + "</department>"
        + "      <gender>" + (user.prs_perslid_geslacht()?"M":"F") + "</gender>"
        + "      <externalIdentifier>"+ String(user_key) +"</externalIdentifier>"
        + "      <communicationDetails>"
        + "         <emailAddress>servicecenterfb@uwv.nl</emailAddress>"
        + "         <telephoneNumber>" + safe.html(user.prs_perslid_telefoonnr()) + "</telephoneNumber>"
        + "      </communicationDetails>"
        + "    </personalDetails>"
        + "  <requestContext>MEETINGS</requestContext>"
        + "</ns:createRequestRequestMessage>";

var msg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
        + "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
        + "               xmlns:xsd='http://www.w3.org/2001/XMLSchema'"
        + "               xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"
        + "  <soap:Body>"
        + req
        + "  </soap:Body>"
        + "</soap:Envelope>";

//__DoLog(Server.HTMLEncode(msg));
//Response.Write(msg)
//Response.End;

xmlhttp.send(msg);

if (xmlhttp.status == 200)
{
    var inputXML = new ActiveXObject("MSXML2.DOMDocument.6.0");
    inputXML.loadXML(xmlhttp.responseText);

    inputXML.setProperty("SelectionLanguage", "XPath");
    inputXML.setProperty("SelectionNamespaces", "xmlns:ns2='http://services.worldmeetings.com/services/v1.0/Order' xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'");
    //node = inputXML.selectSingleNode("S:Envelope/S:Body/ns2:createRequestRequestMessage/url");
    var node = inputXML.selectSingleNode("//url");
    if (node)
    {
      __Log("Naar: " + node.text);
      Response.Redirect(node.text);
    }
    else
        __DoLog("Worldmeeting: geen node?", "#FF0000");
}
else
    __DoLog("Worldmeeting: " + xmlhttp.status + "<br>" + xmlhttp.statusText, "#FF0000");
%>
