public override void OnAfterSubmit(FormData formData, FormSubmittedData submittedFormData, string formXml,
                                       CmsEventArgs eventArgs)
    {
        var formFieldDataItem = submittedFormData.DataItems.ToList().FirstOrDefault(x => x.FieldName == "EktFormId");

        //act upon the form submit results
    }
        public override void OnAfterSubmit(FormData formData, FormSubmittedData submittedFormData, string formXml, Cms.Extensibility.CmsEventArgs eventArgs)
        {
            // first we need to retrieve the EktGUID from the ecm cookie.
            dxhManager = new DxHUserConnectionManager(Cms.Framework.ApiAccessMode.LoggedInUser);
            string siteURL = Ektron.Cms.Common.EkFunctions.GetURLBase(commonApi.RequestInformationRef.HostUrl, Convert.ToInt32(commonApi.RequestInformationRef.HostPort), commonApi.RequestInformationRef.HttpsProtocol == "on", Convert.ToInt32(commonApi.RequestInformationRef.HostSSLPort), false) + commonApi.RequestInformationRef.SitePath;
            string visitorId = commonApi.RequestInformationRef.ClientEktGUID;
            long userId = eventArgs.RequestInformation.UserId;

            submittedFormData.DataItems = injectFormFields(submittedFormData, formData.Id, visitorId);

            string[] strKeyValues = new string[2]
                                    {
                                        "dxhvisitorguid|" + visitorId.ToString(),
                                        "siteURL|" + siteURL
                                    };

            #region EktronFormServiceClient
            if (DxHUtils.IsDxHActive())
            {
                var dxhFormServiceBinding = new NetTcpBinding { Security = { Mode = SecurityMode.None } };
                var existingConnection = DxHUtils.GetDxhUrl();

                var url = string.Format(FormServiceEndpoint, existingConnection.EndPoint.ToLower().Replace("/contextbus", "/"));

                var dxhFormServiceEndPoint = new EndpointAddress(new Uri(url));
                var channelFactory = new ChannelFactory<IEktronFormService>(dxhFormServiceBinding, dxhFormServiceEndPoint);
                var efsClient = channelFactory.CreateChannel();

                try
                {
                    ((IClientChannel)efsClient).Open();
                    efsClient.submitFormData(formData, submittedFormData, strKeyValues);
                    ((IClientChannel)efsClient).Close();
                    channelFactory.Close();
                }
                catch (Exception ex)
                {
                    EkException.LogException(ex, System.Diagnostics.EventLogEntryType.Error);
                    ((IClientChannel)efsClient).Abort();
                }
                finally
                {
                    switch (((IClientChannel)efsClient).State)
                    {
                        case CommunicationState.Opened:
                            ((IClientChannel)efsClient).Close();
                            break;
                        case CommunicationState.Opening:
                        case CommunicationState.Closing:
                            break;
                        case CommunicationState.Faulted:
                            ((IClientChannel)efsClient).Abort();
                            break;
                    }
                }
            }

            #endregion

            base.OnAfterSubmit(formData, submittedFormData, formXml, eventArgs);
        }
        private FormFieldDataItem[] injectFormFields(FormSubmittedData submittedFormData, long formId, string visitorId)
        {
            bool bFoundFormId = false;
            bool bFoundFormDataId = false;
            bool bFoundhubspotusertoken = false;
            bool ishubspot = false;
            string hubspotcookie = string.Empty;

            int iIncrementer = 2; // number of fields to inject includes formid, formdataid, hubspotusertoken
            int j = 0; // another counter

            if (this.GetTargetObjectDefinitionId(formId).ToLower() == "hubspot.contact")
            {
                iIncrementer++;
                ishubspot = true;
                if (HttpContext.Current != null)
                    hubspotcookie = (HttpContext.Current.Request.Cookies["hubspotutk"] != null ? HttpContext.Current.Request.Cookies["hubspotutk"].Value : "");

                if (submittedFormData.DataItems.Any(p => p.FieldName.ToLower().Equals("dxhhubspotusertoken")))
                {
                    string cookievalue = submittedFormData.DataItems.Single(p => p.FieldName.ToLower().Equals("dxhhubspotusertoken")).DataValue.ToString();
                    if (string.IsNullOrEmpty(cookievalue))
                    {
                        submittedFormData.DataItems.Single(p => p.FieldName.ToLower().Equals("dxhhubspotusertoken")).DataValue = hubspotcookie;
                    }
                    iIncrementer--;
                    bFoundhubspotusertoken = true;
                }
            }

            // iterate through all of the fields to find dxhformid and/or dxhformdataid.
            // if they are found we will check if they have values. If they have no values
            // we will fill them in.
            for (int i = 0; i < submittedFormData.DataItems.Count(); i++)
            {
                if (submittedFormData.DataItems[i].FieldName.ToLower().Equals("dxhformid"))
                {
                    if (submittedFormData.DataItems[i].DataValue.ToString().Equals(string.Empty))
                    {
                        submittedFormData.DataItems[i].DataValue = formId.ToString();
                    }
                    iIncrementer--;
                    bFoundFormId = true;
                }
                else if (submittedFormData.DataItems[i].FieldName.ToLower().Equals("dxhformdataid"))
                {
                    if (submittedFormData.DataItems[i].DataValue.ToString().Equals(string.Empty))
                    {
                        submittedFormData.DataItems[i].DataValue = submittedFormData.Id.ToString();
                    }
                    iIncrementer--;
                    bFoundFormDataId = true;
                }
            }

            // we create a new array based on the original field count + any additional fields needed
            // which may include formid, formdataid

            FormFieldDataItem[] dataItems = new FormFieldDataItem[submittedFormData.DataItems.Count() + iIncrementer];

            for (j = 0; j < submittedFormData.DataItems.Count(); j++)
            {
                dataItems[j] = submittedFormData.DataItems[j];
            }

            if (!bFoundFormId)
            {
                // we create a field to contain the formid. This is so the Connector won't have to manipulate data
                // in order to send these data points to the contextbus
                Ektron.Cms.FormFieldDataItem ffdiFormId = new Ektron.Cms.FormFieldDataItem();
                ffdiFormId.FieldName = "DxHFormId";
                ffdiFormId.DataValue = formId.ToString();
                dataItems[j++] = ffdiFormId;
            }

            if (!bFoundFormDataId)
            {
                // we create a field to contain the formdataid. This is so the Connector won't have to manipulate data
                // in order to send these data points to the contextbus
                Ektron.Cms.FormFieldDataItem ffdiFormSubId = new Ektron.Cms.FormFieldDataItem();
                ffdiFormSubId.FieldName = "DxHFormDataId";
                ffdiFormSubId.DataValue = submittedFormData.Id.ToString();
                dataItems[j++] = ffdiFormSubId;
            }

            if (!bFoundhubspotusertoken && ishubspot)
            {
                // we create a field to contain the formdataid. This is so the Connector won't have to manipulate data
                // in order to send these data points to the contextbus
                Ektron.Cms.FormFieldDataItem hubspotusertoken = new Ektron.Cms.FormFieldDataItem();
                hubspotusertoken.FieldName = "DxHHubSpotUserToken";
                hubspotusertoken.DataValue = hubspotcookie;
                dataItems[j++] = hubspotusertoken;
            }

            return dataItems;
        }
Exemple #4
0
    private string GeneratePartReportData(string ReportID, FormData FormInfo, FormSubmittedData[] Data, bool CanDelete, bool NeedHeading)
    {
        string strFormsURL;
        string strFormsPath;
        string strManifestURL;
        string strManifestFilePath;
        string strXsltFilePath;
        System.Xml.XmlDocument objReport;
        System.Xml.XmlNode objNode;

        try
        {
            if (ReportID == "")
            {
                return "ERROR: Please select a report.";
            }
            else if (!Information.IsNumeric(ReportID))
            {
                return "ERROR: Invalid report ID: " + ReportID;
            }

            strFormsURL = m_refContentApi.QualifyURL(m_refContentApi.AppPath, "controls/forms/");
            strFormsPath = Server.MapPath(strFormsURL);
            strManifestURL = m_refContentApi.FullyQualifyURL(strFormsURL + "FormReportsManifest.xml");
            strManifestFilePath = strFormsPath + "FormReportsManifest.xml";

            objReport = new System.Xml.XmlDocument();
            objReport.Load(strManifestFilePath);
            objNode = objReport.SelectSingleNode("/*/Reports/Report[" + ReportID + "]");
            if (objNode == null)
            {
                return "ERROR: Could not find report in FormReportsManifest.xml. Report: " + ReportID;
            }

            objNode = objNode.SelectSingleNode("xslt/@src");
            if (objNode == null)
            {
                return "ERROR: The report does not have a specified XSLT file in FormReportsManifest.xml. Report: " + ReportID;
            }
            strXsltFilePath = m_refContentApi.QualifyURL(strFormsPath, objNode.Value);

            string strXml;
            strXml = m_refContentApi.EkModuleRef.SerializeFormData(FormInfo, Data, null);

            System.Xml.Xsl.XsltArgumentList objXsltArgs = new System.Xml.Xsl.XsltArgumentList();
            //'fill in the dynamic data for the fieldlist for this report (if apply).
            string sUpdatedXSLT = "";
            string sUpdatedFieldList = strFormsPath + "UpdateFieldList.xslt";
            objXsltArgs.AddParam("baseURL", string.Empty, m_refContentApi.FullyQualifyURL(""));
            objXsltArgs.AddParam("LangType", string.Empty, Convert.ToString(m_refContentApi.ContentLanguage));
            sUpdatedXSLT = m_refContentApi.XSLTransform(strXml, sUpdatedFieldList, true, false, objXsltArgs, false);
            strXml = m_refContentApi.XSLTransform("<root/>", sUpdatedXSLT, false, false, objXsltArgs, false, true);

            if (true == CanDelete)
            {
                //a version for export report - first page of a short report
                objXsltArgs = new System.Xml.Xsl.XsltArgumentList();
                objXsltArgs.AddParam("canDelete", string.Empty, "false");
                objXsltArgs.AddParam("checkmarkUrl", string.Empty, m_refContentApi.FullyQualifyURL(m_refContentApi.QualifyURL(m_refContentApi.AppImgPath, "../UI/Icons/check.png")));
                objXsltArgs.AddParam("includeHeading", string.Empty, "true");
                string sExport;
                sExport = m_refContentApi.XSLTransform(strXml, strXsltFilePath, true, false, objXsltArgs, false);
                sExport = Regex.Replace(sExport, "</?(?i:pre)(.|\\n)*?>", string.Empty); //Defect # 45861 - Removing PRE tags
                ExportResult.Text = sExport; // sExcelPrefix + sExport + sExcelSuffix;
            }
            else
            {
                ExportResult.Text = "";
            }
            ExportResult.Visible = false;

            objXsltArgs = new System.Xml.Xsl.XsltArgumentList();
            objXsltArgs.AddParam("canDelete", string.Empty, CanDelete ? "true" : "false");
            objXsltArgs.AddParam("checkmarkUrl", string.Empty, m_refContentApi.FullyQualifyURL(m_refContentApi.QualifyURL(m_refContentApi.AppImgPath, "../UI/Icons/check.png")));
            objXsltArgs.AddParam("includeHeading", string.Empty, NeedHeading ? "true" : "false");

            //if (SaveXmlAsFile)
            //{
            //    // Save XML as file for debugging purposes.
            //    string strXmlFilePath;
            //    strXmlFilePath = "Sample" + FormInfo.Title.Replace(" ", "") + "Data.xml";
            //    strXmlFilePath = m_refContentApi.QualifyURL(strFormsPath, strXmlFilePath);

            //    System.IO.StreamWriter sw = new System.IO.StreamWriter(strXmlFilePath);
            //    sw.Write(strXml);
            //    sw.Close();
            //    sw = null;
            //}
            return m_refContentApi.XSLTransform(strXml, strXsltFilePath, true, false, objXsltArgs, false);

        }
        catch (Exception)
        {
            return "";
            //				EkException.ThrowException(ex);
        }
        finally
        {
            objNode = null;
            objReport = null;
        }
    }
Exemple #5
0
 private string DisplayReport(string ReportID, FormData FormInfo, FormSubmittedData[] Data, bool CanDelete)
 {
     return GeneratePartReportData(ReportID, FormInfo, Data, CanDelete, true);
 }