Guest User

For Skarn

a guest
Dec 13th, 2011
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. /*
  2. * This file contains functions for data validation and form-level events.
  3. * Because the functions are referenced in the form definition (.xsf) file,
  4. * it is recommended that you do not modify the name of the function,
  5. * or the name and number of arguments.
  6. *
  7. */
  8.  
  9. // The following line is created by Microsoft Office InfoPath to define the prefixes
  10. // for all the known namespaces in the main XML data file.
  11. // Any modification to the form template files made outside of InfoPath
  12. // will not be automatically updated.
  13. //<namespacesDefinition>
  14. XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-11-19T14:53:38"');
  15. //</namespacesDefinition>
  16.  
  17. function butt_createEmail::OnClick(eventObj)
  18. {
  19. emailView("view1")
  20. }
  21.  
  22. function emailView(strView)
  23. {
  24. //get the users temporary folder
  25. var objFSO = new ActiveXObject("Scripting.FileSystemObject");
  26. var strTempPath = objFSO.GetSpecialFolder(2);
  27.  
  28. //load the form XML
  29. var strXML = XDocument.DOM.xml
  30. var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
  31. xmlDoc.async = false;
  32. xmlDoc.validateOnParse = false;
  33. xmlDoc.loadXML(strXML);
  34.  
  35. //load the view XSL
  36. var xslDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
  37. xslDoc.async = false;
  38. xslDoc.validateOnParse = false;
  39. xslDoc.load(strView + ".xsl");
  40.  
  41. //generate the HTML transform
  42. var strHTMLTransformed = xmlDoc.transformNode(xslDoc);
  43. var htmlDoc = new ActiveXObject("htmlfile");
  44. htmlDoc.write(strHTMLTransformed);
  45.  
  46. //obtain a clean string of the solution path
  47. var uriPath = XDocument.Solution.URI.replace(new RegExp("%20","g"), " ");
  48. uriPath = uriPath.replace("file:///","");
  49. uriPath = uriPath.replace("manifest.xsf","");
  50.  
  51. //create an outlook email
  52. var appOutlook = new ActiveXObject("Outlook.Application");
  53. var objMailItem = appOutlook.CreateItem(0);
  54. objMailItem.BodyFormat = 1;
  55.  
  56. //locate images in the HTML and update image paths / store base64
  57. var myImages = htmlDoc.images;
  58. var re;
  59. for(var i = 0;i < myImages.length ;i++)
  60. {
  61. //determine the type of image (reference or inline)
  62. re = new RegExp("msoinline","ig");
  63. if (re.test(myImages(i).src) != true)
  64. {
  65. //reference images can be dealt with as normal image files and are in the 'cache' folder.
  66. var imgSource = uriPath + myImages(i).nameProp;
  67. }
  68. else
  69. {
  70. //inline images are base64 embedded images and need to be extracted first
  71. //we create an in memory xml document to store the Base64 and then convert it to binary
  72. //using an ADODB.Stream
  73. var strBase64 = myImages(i).attributes("xd:inline").value;
  74. var base64xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
  75. base64xmlDoc.async = false;
  76.  
  77. var nodeNew = base64xmlDoc.createElement("imageFile");
  78. nodeNew.dataType = "bin.base64";
  79. nodeNew.text = strBase64;
  80.  
  81. //convert the Base64 into a binary file
  82. var adodbStream = new ActiveXObject("ADODB.Stream");
  83. adodbStream.type = 1;
  84. adodbStream.open();
  85. adodbStream.write(nodeNew.nodeTypedValue);
  86. adodbStream.savetoFile(strTempPath + myImages(i).nameProp + ".bmp",2);
  87. adodbStream.close();
  88. var imgSource = strTempPath + myImages(i).nameProp + ".bmp";
  89.  
  90. //we now want the HTML to use the saved binary file as the img and not the inline.
  91. strHTMLTransformed = strHTMLTransformed.replace("msoinline/" + myImages(i).nameProp, myImages(i).nameProp + ".bmp");
  92. myImages(i).attributes("xd:inline").value = '';
  93. }
  94.  
  95. //finally we add the actual image file to the email as an attachment so it will reference correctly.
  96. objMailItem.Attachments.Add(imgSource,1,0,"");
  97. }
  98.  
  99. //set the HTML of the email body
  100. var strHTMLTransformed = htmlDoc.documentElement.outerHTML;
  101. objMailItem.HTMLBody = strHTMLTransformed;
  102.  
  103. //and display the final product
  104. objMailItem.Display();
  105. }
  106.  
  107.  
Advertisement
Add Comment
Please, Sign In to add comment