531 lines
24 KiB
JavaScript
531 lines
24 KiB
JavaScript
// ******************************************
|
|
// * $Id$
|
|
// *
|
|
// * sendNotification()
|
|
// * Onderstaande functies worden alleen vanuit sendNotificatie aangeroepen:
|
|
// * notificationMail()
|
|
// * notificationSMS()
|
|
// * notificationSYS()
|
|
// *
|
|
// * Verstuur de notificaties voor putorders.
|
|
// *
|
|
// * Uses: scr="../wsf_shared.js"
|
|
// * scr="./puo_settings.js"
|
|
// * scr="./puo_shared.js
|
|
// * scr="./puo_xmltools.js"
|
|
// * scr="./puo_sendmail.js"
|
|
// * src="./puo_sendsms.js"
|
|
// * src="./puo_sendfile.js"
|
|
// *
|
|
// ******************************************
|
|
// Als ref_key meegeven dan alleen notificaties met die referentie (en module zoals afgeleid uit pcode) zonder delay
|
|
function sendNotification(ref_key, pcode)
|
|
{
|
|
var puo_const = { STATUS_PORTAL: 1 // Niet via Putorders.exe
|
|
, STATUS_EMAIL: 2
|
|
, STATUS_SMS: 4
|
|
, STATUS_POPUP: 8 // Niet via Putorders.exe
|
|
, STATUS_SUMMARY_XSL: 16 // SMS/Email subject via XSL?
|
|
};
|
|
|
|
var strFilter = "";
|
|
if (ref_key > 0 && pcode)
|
|
{ // Filtering op uitsluitend pcode zou te streng zijn. Als je een bezoeker binnen meldt
|
|
// gaat BEZDON af maar die genereert intern een BEZDO2 die een e-mail naar de contact-
|
|
// persoon stuurt. Juist die laatste willen we onmiddelijk sturen
|
|
var xmlnode = "";
|
|
var sql = "SELECT fac_srtnotificatie_xmlnode"
|
|
+ " FROM fac_srtnotificatie"
|
|
+ " WHERE fac_srtnotificatie_code = " + safe.quoted_sql(pcode);
|
|
var oRs = Oracle.Execute(sql);
|
|
if (!oRs.eof)
|
|
xmlnode = oRs("fac_srtnotificatie_xmlnode").Value;
|
|
oRs.Close;
|
|
// Bij reservering notificaties bevat fac_notificatie_refkey de res_key en fac_notificatie_extrakey
|
|
// de deelres_key. We hebben in parameter ref_key de deelres_key meegekregen
|
|
if (xmlnode == 'reservering')
|
|
strFilter = " AND fac_notificatie_extrakey = " + ref_key;
|
|
else
|
|
strFilter = " AND fac_notificatie_refkey = " + ref_key;
|
|
|
|
strFilter += " AND fac_srtnotificatie_xmlnode = " + safe.quoted_sql(xmlnode)
|
|
+ " AND fac_srtnotificatie_delay = 0"; // Alleen als voor immediate geconfigureerd
|
|
}
|
|
else // De scheduled putorders
|
|
{ // Als fac_srtnotificatie_delay = 0 gaat de notificatie normaal al onmiddelijk vanuit de asp
|
|
// en hoeven wij hem niet meer te doen in de scheduled putorders
|
|
// Soms wordt fac.trackaction echter aangeroepen vanuit een database package en zou een notificatie
|
|
// die op delay=0 staat dan nooit meer de deur uit gaan. We kunnen het een configuratiefout noemen
|
|
// maar dat is niet uit te leggen
|
|
// Daarom: in plaats van fac_srtnotificatie_delay = 0 hier uit te sluiten doen we die pas na
|
|
// (hardcoded) 2 minuten delay. Dan is de ASP-code zeker wel klaar.
|
|
strFilter = " AND fac_notificatie_datum + "
|
|
+ " (CASE WHEN fac_srtnotificatie_delay = 0 "
|
|
+ " THEN 120 ELSE COALESCE(fac_srtnotificatie_delay,0) "
|
|
+ " END/60/60/24) < SYSDATE";
|
|
|
|
Log2File(1, "** START sendNotification (" + toDateTimeString(new Date()) + ")");
|
|
}
|
|
|
|
var sql = "SELECT fac_notificatie_receiver_email"
|
|
+ " , fac_notificatie_receiver_phone"
|
|
+ " , fac_notificatie_oms"
|
|
+ " , fac_notificatie_status"
|
|
+ " , fac_notificatie_refkey"
|
|
+ " , fac_notificatie_key"
|
|
+ " , fac_srtnotificatie_xmlnode"
|
|
+ " , fac_srtnotificatie_code"
|
|
+ " , fac_srtnotificatie_srtkm_key"
|
|
+ " , NVL(fac_notificatie_extrakey, -1) fac_notificatie_extrakey"
|
|
+ " , fac_notificatie_sender_email"
|
|
+ " , COALESCE(fac_notificatie_lang, 'NL') fac_notificatie_lang"
|
|
+ " , fac_notificatie_systeemadres"
|
|
+ " , fac_notificatie_attachments"
|
|
+ " FROM fac_v_notifyqueue f"
|
|
+ " WHERE ( BITAND (fac_notificatie_status, " + (puo_const.STATUS_EMAIL | puo_const.STATUS_SMS) + ") > 0"
|
|
+ " OR fac_notificatie_systeemadres IS NOT NULL)"
|
|
+ strFilter
|
|
+ " ORDER BY fac_notificatie_datum"
|
|
+ " , fac_notificatie_key";
|
|
Log2File(3, sql);
|
|
var oRs = Oracle.Execute(sql);
|
|
|
|
var notiMAILed = 0;
|
|
var notiSMSed = 0;
|
|
var notiSYSed = 0;
|
|
while (!oRs.Eof)
|
|
{
|
|
Log2File(1, "\n");
|
|
Log2File(2, "\n\n" + Fill(100, "="));
|
|
Log2File(1, "== Notificatie: "
|
|
+ oRs("fac_notificatie_key").value + " "
|
|
+ oRs("fac_srtnotificatie_code").value + ": "
|
|
+ oRs("fac_notificatie_refkey").value + "; "
|
|
+ (oRs("fac_srtnotificatie_srtkm_key").value || "")
|
|
+ " (" + toDateTimeString(new Date()) + ")"
|
|
);
|
|
if ((S("puo_flags") & 1) != 1) // Voor in testomgevingen
|
|
{
|
|
Log2File(1, "====== Skipping actual sending because of puo_flags");
|
|
return false;
|
|
}
|
|
|
|
var XMLnode = oRs("fac_srtnotificatie_xmlnode").value || "";
|
|
var NotificationXSL = getXslName(XMLnode);
|
|
|
|
notiMAILed += notificationMail(oRs, NotificationXSL, puo_const);
|
|
notiSMSed += notificationSMS (oRs, NotificationXSL, puo_const);
|
|
notiSYSed += notificationSYS (oRs, puo_const);
|
|
Log2File(2, Fill(100, "=") + "\n\n");
|
|
|
|
oRs.MoveNext();
|
|
}
|
|
oRs.Close();
|
|
if (ref_key > 0 && pcode)
|
|
{
|
|
// Zal altijd '1' zijn als we hier komen
|
|
}
|
|
else
|
|
{
|
|
if (notiMAILed > 0) Log2File(1, " " + notiMAILed + " email messages sent");
|
|
if (notiSMSed > 0) Log2File(1, " " + notiSMSed + " SMS messages sent");
|
|
if (notiSYSed > 0) Log2File(1, " " + notiSYSed + " systemadres messages sent");
|
|
}
|
|
}
|
|
|
|
|
|
function notificationMail(rec, p_notificationXSL, params)
|
|
{
|
|
// ======================== 2=mail ========================
|
|
Log2File(2, "*> notificationMail");
|
|
var noti_mailed = 0;
|
|
try
|
|
{
|
|
var receiver_email = rec("fac_notificatie_receiver_email").value || "";
|
|
var sender_email = rec("fac_notificatie_sender_email").value || "";
|
|
var attach_refkey = rec("fac_notificatie_refkey").value;
|
|
var attach_srtkenmerkkey = rec("fac_srtnotificatie_srtkm_key").value;
|
|
var srtcode = rec("fac_srtnotificatie_code").value || "";
|
|
var xmlnode = rec("fac_srtnotificatie_xmlnode").value || "";
|
|
|
|
if (rec("fac_notificatie_status").value & params.STATUS_EMAIL) // bitwise AND
|
|
{
|
|
if (!rec("fac_srtnotificatie_xmlnode").value)
|
|
{
|
|
Log2File(2, "Mailnotificatie basis");
|
|
sendMail( sender_email
|
|
, receiver_email
|
|
, rec("fac_notificatie_oms").Value
|
|
, rec("fac_notificatie_oms").Value
|
|
, ""
|
|
, { attachFileName: ""
|
|
, attachFolder: ""
|
|
, attachSubFolder: ""
|
|
, attachments: []
|
|
}
|
|
);
|
|
}
|
|
else
|
|
{
|
|
// Errors in de generatie van de XML worden afgevangen in fetchXMLContent
|
|
// De functie levert dan een lege string, de notificatie wordt dan als verzonden
|
|
// afgehandeld
|
|
var xml_content = fetchXMLContent( rec("fac_srtnotificatie_xmlnode").value
|
|
, rec("fac_notificatie_refkey").value
|
|
, rec("fac_notificatie_extrakey").value
|
|
, ""
|
|
, rec("fac_notificatie_lang").value
|
|
);
|
|
|
|
if (xml_content)
|
|
{
|
|
var AttachRootPath = S("flexfilespath");
|
|
var attach_folder = "";
|
|
var attach_kenmerk_folder = "";
|
|
if (attach_srtkenmerkkey > 0 && xmlnode == "melding") // alleen voor MLDAFM en MLDAFR
|
|
{
|
|
var sqlkenmerk = "SELECT vk.mld_kenmerk_key"
|
|
+ " FROM mld_kenmerk vk"
|
|
+ " , mld_melding m"
|
|
+ " , mld_stdmelding s"
|
|
+ " , mld_discipline d"
|
|
+ " WHERE m.mld_melding_key = " + attach_refkey
|
|
+ " AND vk.mld_srtkenmerk_key = " + attach_srtkenmerkkey
|
|
+ " AND s.mld_stdmelding_key = m.mld_stdmelding_key"
|
|
+ " AND s.mld_ins_discipline_key = d.ins_discipline_key"
|
|
+ " AND ((vk.mld_stdmelding_key = s.mld_stdmelding_key AND vk.mld_kenmerk_niveau = 'S')"
|
|
+ " OR (vk.mld_stdmelding_key = s.mld_ins_discipline_key AND vk.mld_kenmerk_niveau = 'D')"
|
|
+ " OR (vk.mld_stdmelding_key = d.ins_srtdiscipline_key AND vk.mld_kenmerk_niveau = 'T'))";
|
|
Log2File(3, sqlkenmerk);
|
|
var oRs = Oracle.Execute(sqlkenmerk);
|
|
if (!oRs.Eof)
|
|
{
|
|
attach_kenmerk_folder = String(oRs("mld_kenmerk_key").Value);
|
|
attach_folder = AttachRootPath
|
|
+ "\\MLD\\"
|
|
+ subfolderKey(srtcode.slice(0,1), attach_refkey);
|
|
}
|
|
oRs.Close();
|
|
|
|
}
|
|
Log2File(2, "*>attach_folder: "+attach_folder);
|
|
Log2File(2, "*>attach_kenmerk_folder: "+attach_kenmerk_folder);
|
|
|
|
var SubjectText = "";
|
|
var SubjectTextXSL = "";
|
|
//
|
|
Log2File(2, "XSL file used=" + p_notificationXSL);
|
|
strResult = XML2HTML( xml_content
|
|
, p_notificationXSL
|
|
, rec("fac_srtnotificatie_code").value
|
|
, "email"
|
|
);
|
|
SubjectText = rec("fac_notificatie_oms").value;
|
|
if (rec("fac_notificatie_status").value & params.STATUS_SUMMARY_XSL)
|
|
{
|
|
// Via XSL
|
|
SubjectTextXSL = XML2HTML( xml_content
|
|
, p_notificationXSL
|
|
, rec("fac_srtnotificatie_code").value
|
|
, "summary"
|
|
);
|
|
Log2File(2, "SubjectText na vertaling" + SubjectTextXSL);
|
|
if (SubjectTextXSL)
|
|
{
|
|
SubjectText = SubjectTextXSL;
|
|
}
|
|
}
|
|
//
|
|
if (S("puo_notificationinmailbody"))
|
|
{
|
|
Log2File(2, "Mailnotificatie in de body");
|
|
// In de body
|
|
var attachment_str = rec("fac_notificatie_attachments").value || "";
|
|
var attach_obj = [];
|
|
if (attachment_str)
|
|
attach_obj = attachment_str.split("|");
|
|
sendMail( sender_email
|
|
, receiver_email
|
|
, SubjectText
|
|
, ""
|
|
, strResult
|
|
, { attachFileName: ""
|
|
, attachFolder: attach_folder
|
|
, attachSubFolder: attach_kenmerk_folder
|
|
, attachments: attach_obj
|
|
}
|
|
);
|
|
}
|
|
else
|
|
{
|
|
var startPos = strResult.indexOf("qrc=") + 4;
|
|
var quote = strResult.substr(startPos, 1);
|
|
var eindPos = strResult.indexOf(quote, startPos + 2);
|
|
if (startPos > 4 && eindPos > startPos)
|
|
{
|
|
var qrc = strResult.substring(startPos + 1, eindPos);
|
|
qrc = qrc.replace(/\&/g, "&"); // Het was nog HTML/XML-encoded
|
|
var xc = new ActiveXObject("SLNKDWF.QRCode");
|
|
xc.Text = qrc;
|
|
__Log("Creating QRC: " + qrc);
|
|
var oXML = new ActiveXObject("Msxml2.DOMDocument.6.0");
|
|
var oNode = oXML.createElement("encodeddata");
|
|
oNode.dataType = "bin.base64"; // Zeer snelle oplossing
|
|
oNode.nodeTypedValue = xc.GetAsPNG();
|
|
var b64 = oNode.text;
|
|
|
|
var newbody = strResult.substr(0, startPos - 4) + "src=\"data:image/png;base64," + b64 + "\"" + strResult.substr(eindPos + 1);
|
|
strResult = newbody;
|
|
}
|
|
|
|
Log2File(2, "Mailnotificatie als attachment");
|
|
sendMail( sender_email
|
|
, receiver_email
|
|
, SubjectText
|
|
, "Zie HTML attachment"
|
|
, strResult
|
|
, { attachFileName: "Facilitor.html"
|
|
, attachFolder: attach_folder
|
|
, attachSubFolder: attach_kenmerk
|
|
, attachments: []
|
|
}
|
|
);
|
|
}
|
|
Log2File(2, "Mail sent");
|
|
}
|
|
}
|
|
noti_mailed++;
|
|
}
|
|
}
|
|
catch(e)
|
|
{
|
|
Log2File(0, "Error in SendNotification/MAIL: " + e.description, 1);
|
|
// Wel doorvallen naar wissen bitjes: we blijven notificaties niet tot in den treure proberen
|
|
}
|
|
finally
|
|
{
|
|
// == DONE MAIL ==
|
|
// Let op: bitwise AND en NOT controle.
|
|
var controle = (255 & ~params.STATUS_EMAIL & ~params.STATUS_SUMMARY_XSL);
|
|
var sql = "UPDATE fac_notificatie"
|
|
+ " SET fac_notificatie_status = BITAND (fac_notificatie_status, " + controle + ")"
|
|
+ " WHERE fac_notificatie_key = " + rec("fac_notificatie_key").value;
|
|
Log2File(3, sql);
|
|
Oracle.Execute(sql);
|
|
}
|
|
return noti_mailed;
|
|
}
|
|
|
|
|
|
function notificationSMS(rec, p_notificationXSL, params)
|
|
{
|
|
// ======================== 4=SMS ========================
|
|
Log2File(2, "*> notificationSMS");
|
|
var noti_smsed = 0;
|
|
try
|
|
{
|
|
if (rec("fac_notificatie_status").value & params.STATUS_SMS) // bitwise AND
|
|
{
|
|
var fac_notificatie_receiver_phone = rec("fac_notificatie_receiver_phone").value;
|
|
|
|
var SMSText = rec("fac_notificatie_oms").value;
|
|
var SMSTextXSL = "";
|
|
|
|
if ((rec("fac_notificatie_status").value & params.STATUS_SUMMARY_XSL) && (rec("fac_srtnotificatie_xmlnode").value))
|
|
{
|
|
// Errors in de generatie van de XML worden afgevangen in fetchXMLContent
|
|
// De functie levert dan een lege string, de notificatie wordt dan als verzonden
|
|
// afgehandeld
|
|
var xml_content = fetchXMLContent( rec("fac_srtnotificatie_xmlnode").value
|
|
, rec("fac_notificatie_refkey").value
|
|
, rec("fac_notificatie_extrakey").value
|
|
, ""
|
|
, rec("fac_notificatie_lang").value
|
|
);
|
|
|
|
if (xml_content)
|
|
{
|
|
Log2File(2, "XSL file used=" + p_notificationXSL)
|
|
SMSTextXSL = XML2HTML( xml_content
|
|
, p_notificationXSL
|
|
, rec("fac_srtnotificatie_code").value
|
|
, "summary"
|
|
);
|
|
Log2File(2, "SMSText na vertaling" + SMSTextXSL);
|
|
if (SMSTextXSL)
|
|
{
|
|
SMSText = SMSTextXSL;
|
|
}
|
|
}
|
|
}
|
|
|
|
var smsResult = sendSMS( fac_notificatie_receiver_phone
|
|
, SMSText
|
|
);
|
|
if (smsResult)
|
|
{
|
|
Log2File(2, "SMS sent");
|
|
noti_smsed++;
|
|
}
|
|
}
|
|
}
|
|
catch(e)
|
|
{
|
|
Log2File(0, "Error in SendNotification/SMS: " + e.description, 1);
|
|
// Wel doorvallen naar wissen bitjes: we blijven notificaties niet tot in den treure proberen
|
|
}
|
|
finally
|
|
{
|
|
// == DONE SMS ==
|
|
// Let op: bitwise AND en NOT controle.
|
|
var controle = (255 & ~params.STATUS_SMS & ~params.STATUS_SUMMARY_XSL);
|
|
sql = "UPDATE fac_notificatie"
|
|
+ " SET fac_notificatie_status = BITAND (fac_notificatie_status, " + controle + ")"
|
|
+ " WHERE fac_notificatie_key = " + rec("fac_notificatie_key").value;
|
|
Log2File(3, sql);
|
|
Oracle.Execute(sql);
|
|
}
|
|
|
|
return noti_smsed;
|
|
}
|
|
|
|
/*
|
|
Dit zijn *notificaties* die als *opdracht* verstuurd worden
|
|
Voornamelijk voor system2system koppelingen
|
|
Bijvoorbeeld AANS -> CSUN koppeling
|
|
*/
|
|
function notificationSYS(rec, params)
|
|
{
|
|
// ======================== Systeemadres ========================
|
|
// Het systeemadres wordt niet aangemerkt als bitje in de status kolom
|
|
Log2File(2, "*> notificationSYS");
|
|
var SendOrderResult = { resultcode: 1 };
|
|
var noti_sysed = 0;
|
|
try
|
|
{
|
|
var systeemadres = rec("fac_notificatie_systeemadres").value;
|
|
var xmlnode = rec("fac_srtnotificatie_xmlnode").value || "";
|
|
var refkey = rec("fac_notificatie_refkey").value;
|
|
var extrakey = rec("fac_notificatie_extrakey").value;
|
|
var taal = rec("fac_notificatie_lang").value;
|
|
var code = rec("fac_srtnotificatie_code").value || "";
|
|
var sender_email = rec("fac_notificatie_sender_email").value || "";
|
|
|
|
if (systeemadres)
|
|
{
|
|
var connect = new ConnectorCls();
|
|
// Met FSN#34131 hoop ik echte prs_bedrijfadres informatie te krijgen
|
|
// Tot die tijd ook even zo: je mag achteraan het systeemadres
|
|
// een ##1 zetten voor andere encoding
|
|
var encoding = 0; // text/xml
|
|
if (systeemadres.indexOf('##') > -1)
|
|
{
|
|
encoding = systeemadres.split('##')[1];
|
|
systeemadres = systeemadres.split('##')[0];
|
|
}
|
|
var bedrijfadres = { url: systeemadres,
|
|
extension: "xml",
|
|
ordermode: 0,
|
|
certificateName: "",
|
|
AttachFile: "",
|
|
username: "",
|
|
password: "",
|
|
encoding: encoding };
|
|
connect.connect(bedrijfadres); // vult eventueel bedrijfadres.username/password
|
|
|
|
if (xmlnode)
|
|
{
|
|
// Errors in de generatie van de XML worden afgevangen in fetchXMLContent
|
|
// De functie levert dan een lege string, de notificatie wordt dan als verzonden
|
|
// afgehandeld
|
|
var SendOrderResult = -1;
|
|
var xml_content = fetchXMLContent( xmlnode
|
|
, refkey
|
|
, extrakey
|
|
, ""
|
|
, taal
|
|
);
|
|
if (xml_content)
|
|
{
|
|
var AttachPath = "";
|
|
var ordernr = "Onbekend";
|
|
var System2SystemXSL = S("puo_system2systemxsl");
|
|
|
|
Log2File(3, "In Notifications sender=" + sender_email);
|
|
Log2File(4, "xml_content=" + xml_content);
|
|
Log2File(4, "xsl=" + S("puo_system2systemxsl"));
|
|
Log2File(4, "xsl2=" + System2SystemXSL);
|
|
Log2File(4, "ordernr=" + ordernr);
|
|
Log2File(4, "key=" + refkey);
|
|
Log2File(4, "order_mode=" + bedrijfadres.ordermode);
|
|
Log2File(4, "AttachPath=" + AttachPath);
|
|
Log2File(4, "Code=" + code);
|
|
Log2File(4, "XMLnode=" + xmlnode);
|
|
|
|
var SendOrderResult = SendOrder ( connect
|
|
, xml_content
|
|
, bedrijfadres
|
|
, System2SystemXSL
|
|
, ordernr
|
|
, refkey
|
|
, AttachPath
|
|
, sender_email
|
|
, xmlnode
|
|
, code
|
|
);
|
|
}
|
|
|
|
if (SendOrderResult.resultcode != 0)
|
|
{
|
|
Log2File(0, "Notification to systeemadres failed. Errorcode:" + SendOrderResult.resultcode);
|
|
}
|
|
else
|
|
{
|
|
Log2File(2, "Notification to systeemadres sent");
|
|
noti_sysed++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch(e)
|
|
{
|
|
Log2File(0, "Error in SendNotification/Systemaddress: " + e.description, 1);
|
|
// Wel doorvallen naar wissen bitjes: we blijven notificaties niet tot in den treure proberen
|
|
}
|
|
finally
|
|
{
|
|
// == DONE Systeemadres ==
|
|
if (SendOrderResult.resultcode == 0)
|
|
{
|
|
sql = "UPDATE fac_notificatie"
|
|
+ " SET fac_notificatie_systeemadres = NULL "
|
|
+ " WHERE fac_notificatie_key = " + rec("fac_notificatie_key").value
|
|
Log2File(3, sql);
|
|
Oracle.Execute(sql);
|
|
}
|
|
}
|
|
|
|
return noti_sysed;
|
|
}
|
|
|
|
|
|
|
|
function getXslName(pNode)
|
|
{
|
|
var fso = new ActiveXObject("Scripting.FileSystemObject");
|
|
var resxslsheet = S("puo_notificationxsl");
|
|
|
|
if (pNode)
|
|
{
|
|
resxslsheet = "xsl/" + pNode + ".xsl";
|
|
if (!fso.FileExists(custabspath + "/" + resxslsheet))
|
|
resxslsheet = S("puo_notificationxsl");
|
|
}
|
|
|
|
if (!fso.FileExists(custabspath + "/" + resxslsheet))
|
|
resxslsheet = "../../appl/shared/default.xsl";
|
|
|
|
return resxslsheet;
|
|
}
|
|
|