FSN#35623 Putorders webservice laten aanroepen

svn path=/Website/trunk/; revision=28382
This commit is contained in:
Jos Groot Lipman
2016-03-07 13:14:41 +00:00
parent 42ee1aa201
commit 1427de0095
6 changed files with 212 additions and 16 deletions

34
APPL/API/api_flex.asp Normal file
View File

@@ -0,0 +1,34 @@
<%@ language = "JavaScript" %>
<% /*
$Revision$
$Id$
File: api_flex.asp
Description: API voor opvangen van flexfiles
Parameters: Een xml
Status:
Context: (alleen) door Putorders
Notes:
*/
JSON_Result = true;
THIS_FILE = "appl/api/api_flex.asp";
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/json2.js" -->
<!-- #include file="../Shared/flexfiles.inc" -->
<!-- #include file="../Shared/upload.inc" -->
<!-- #include file="../api/api.inc" -->
<%
var API = new API_func();
var flexcode = getQParam("flexcode");
var props = flexProps2(flexcode);
__DoLog(props);
Response.Write(JSON.stringify(props));
Response.End;
%>

View File

@@ -67,6 +67,36 @@ function subfolderKey(pNiveau, pKey)
return subfolder;
}
// MLD:12345:587:M of SML:12345:587:P" waarbij de 581 en P don't care zijn
// RESPH::::AMSG0-01-A047.JPG
// RESPH::::AMSG0-01-A047.JPG,R400x400
function flexProps2(flexcode, params)
{
var getparams = { getFiles: true };
var arr = flexcode.split(",");
if (arr.length > 1)
getparams.resizeCode = arr[1];
flexcode = arr[0];
var arr = flexcode.split(":");
var pModule = arr[0];
if (arr.length > 1)
var pKey = parseInt(arr[1], 10);
if (arr.length > 2)
var pKenmerkKey = parseInt(arr[2], 10);
if (arr.length > 3)
var pNiveau = arr[3];
if (arr.length > 4)
{
getparams.getFiles = false;
getparams.getFile = arr[4];
}
var params = flexProps(pModule, pKey, pKenmerkKey, pNiveau, getparams);
return params;
}
function flexProps(pModule, pKey, pSubpath, pNiveau, params)
{
params = params || {};
@@ -280,6 +310,72 @@ function oneFileInfo(fsoFile, result, pModule, pKey, pSubpath, pNiveau, params)
fso.MoveFile(result.AttachPath + fName, result.AttachPath + filedata.name);
}
// Resize een plaatje eventueel
if (params.resizeCode && filedata.name.match(/\.(png|jpg|jpeg)$/i))
{
var file = result.AttachPath + filedata.name;
var Format = params.resizeCode.match(/^([RrCc])(\d*)x(\d*)$/i); // R800x600
if (Format && Format.length == 4)
{
var oIMG = new ActiveXObject("SLNKDWF.ImageConvert");
try
{
oIMG.Open(result.AttachPath + filedata.name);
}
catch(e)
{
__Log("Kan plaatje {0} niet laden {1}".format(result.AttachPath + filedata.name, e.description));
// Gewoon negeren
return;
}
var RrCc = Format[1];
var h0 = h = parseInt(Format[2], 10);
var w0 = w = parseInt(Format[3], 10);
if (RrCc == "R" || RrCc == "r") // Dan niet croppen maar aspect ratio behouden
{
if (oIMG.Width * h > w * oIMG.Height)
h = oIMG.Height / oIMG.Width * w;
else
w = oIMG.Width / oIMG.Height * h;
}
if (oIMG.Height < h || oIMG.Width < w) // Zou er iets vergroot gaan worden.
{
if (RrCc == "R" || RrCc == "C") // Dan zijn we streng en eisen we minimale afmeting
{
result.message = L("lcl_shared_photo_small").format(h0, w0, oIMG.Height, oIMG.Width);
// DeleteFile(params.AttachPath + result.safefilename);
}
else // Dan maar niet, we vergroten niet.
{
h = oIMG.Height;
w = oIMG.Width;
}
}
if (!result.message && (oIMG.Height != h || oIMG.Width != w))
{
try {
__Log("Resize/Cropping from w=" + oIMG.Width + " h=" + oIMG.Height + " to w=" + w + " h=" + h);
oIMG.Width = w;
oIMG.Height = h;
// TODO: Originele type behouden of altijd naar het compactere jpg?
var tempfile = Server.MapPath(rooturl + '/temp/img_' + customerId + '_' + filedata.digest + "_" + params.resizeCode + ".jpg");
oIMG.SaveAs(tempfile);
filedata.resized = tempfile;
}
catch (e)
{
result.message = L("lcl_shared_thumbnail_error") + e.description;
// Gewoon opruimen
// DeleteFile(params.AttachPath + result.safefilename);
}
}
}
}
if (params.api2name)
{
var deepurl = HTTP.urlzelf() + "/api2/{0}/{1}/attachments/{2}/{3}".format(

View File

@@ -76,23 +76,11 @@ function STR2Stream(xmlstr, xslfile, Stream, params)
if (startPos > 4 && eindPos > startPos)
{
var flexcode = p_bodyhtml.substring(startPos + 1, eindPos);
var props = flexProps2(flexcode);
var arr = flexcode.split(":"); // MLD:12345:587:M of SML:12345:587:P" waarbij de 581 en P don't care zijn
var pModule = arr[0]; // RESPH::::AMSG0-01-A047.JPG
if (arr.length > 1)
var pKey = parseInt(arr[1], 10);
if (arr.length > 2)
var pKenmerkKey = parseInt(arr[2], 10);
if (arr.length > 3)
var pNiveau = parseInt(arr[3], 10);
var getparams = { getFiles: true };
if (arr.length > 4)
var getparams = { getFile: arr[4] };
var params = flexProps(pModule, pKey, pKenmerkKey, pNiveau, getparams);
if (params.files.length)
if (props.files.length)
{
var file = params.AttachPath + params.files[0].name;
var file = props.AttachPath + props.files[0].name;
// TODO: If goede type png/jpg
// TODO: Via SLNKDWF/ resizer? Maar hoe netjes sizing te definieren? Zie het format in UploadForm_save.asp
// of moeten we gewoon de width/height gaan parsen die je bij img src= kunt meegeven?

View File

@@ -145,6 +145,42 @@ function sendMail( p_mailfrom
objFso.DeleteFile(tempfile);
}
// Nu frc-codering opzoeken <img frc="SML:34417:587:P"/>
var startPos = p_bodyhtml.indexOf("frc=") + 4;
var quote = p_bodyhtml.substr(startPos, 1);
var eindPos = p_bodyhtml.indexOf(quote, startPos + 2);
if (startPos > 4 && eindPos > startPos)
{
var flexcode = p_bodyhtml.substring(startPos + 1, eindPos);
if (!S("puo_fclt_web_url") || !S("puo_fclt_web_apikey"))
{
throw { description: "<img frc=...> found in XML but puo_fclt_web_url or puo_fclt_web_apikey not set" };
}
// om te voorkomen dat je elke klant in de hosts file moet opnemen wordt
// aaxx.facilitor.nl ondersteund, daarom fac_id erbij
var fac_web_url = S("puo_fclt_web_url") + "?fac_id=" + customerId;
var url = "{0}&API=GETFLEX&APIKEY={1}&flexcode={2}".format(fac_web_url, S("puo_fclt_web_apikey"), flexcode);
Log2File(2, url);
var http_request = doHTTP(url, { method: "POST", headers: { "accept": "application/json" }});
var props = eval('(' + http_request.responseText + ')');
if (props.flexlog)
Log2File(1, props.flexlog);
if (props.files && props.files.length)
{
var filedata = props.files[0];
if (filedata.resized)
var file = filedata.resized;
else
var file = props.AttachPath + props.files[0].name;
newbody = p_bodyhtml.substr(0, startPos - 4) + "src=\"cid:qrc.png\"" + p_bodyhtml.substr(eindPos + 1);
p_bodyhtml = newbody;
objMail.addRelatedBodyPart(file, "qrc.png", 0);
}
}
Log2File(2, "Before bodyHTML");
objMail.HtmlBody = p_bodyhtml.replace(/\<br\>/g, "\x0D\x0A<br>");
objMail.HTMLBodyPart.Charset = S("puo_mailbodycharset");

View File

@@ -237,7 +237,13 @@ function tryOverrule(path)
return; // doen we niets mee hier
}
}
hook.custenv();
var WshNetwork = new ActiveXObject("WScript.Network");
var puo_data = { customerId: customerId,
custabspath: custabspath,
Computername: WshNetwork.Computername
};
hook.custenv(null, puo_data);
hook = null; // zorg dat de GC het object kan opruimen.
}
}

View File

@@ -136,4 +136,40 @@ function trimall(s)
return s;
}
function doHTTP(url, params)
{
params = params || {};
if (!params.method)
params.method = params.data?"POST":"GET"; // Met data default POST, zonder data default GET
var http_request = new ActiveXObject("Msxml2.ServerXMLHTTP.6.0");
var SXH_PROXY_SET_PROXY = 2;
if (S("puo_useproxy"))
{
var proxy_ip = S("puo_proxyserveripaddress");
Log2File(2, "Opening proxy " + proxy_ip);
XMLhttp.setProxy(SXH_PROXY_SET_PROXY, proxy_ip);
}
http_request.open(params.method, url, false, params.username, params.password); // Synchroon
if (params.headers)
{
for (var head in params.headers)
http_request.setRequestHeader(head, params.headers[head]);
}
//http_request.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
http_request.send(params.data);
if (http_request.status < 200 || http_request.status > 299)
{
Log2File(2, "response = " + http_request.responseText); // Level 2 omdat het soms dagen doorloopt en te groot is
Log2File(2, "response Status = " + http_request.status + ": " + http_request.statusText);
Log2File(3, "response Headers = " + http_request.getAllResponseHeaders);
RaiseAnError(http_request.status, "http_request error " + http_request.status + ": (" + http_request.statusText + ")");
}
else
{
// http_request.getResponseHeader("Content-Type") bijvoorbeeld "application/json; Charset=windows-1252"
Log2File(3, "response = " + http_request.responseText);
}
return http_request;
}