Exemplo n.º 1
0
        private static void read_contactform_elements(XmlReader readerXml, ContactForm_Configuration config)
        {
            // Just step through the subtree of this
            while (readerXml.Read())
            {
                if (readerXml.NodeType == XmlNodeType.Element)
                {
                    switch (readerXml.Name.ToLower())
                    {
                    case "explanationtext":
                        read_contactform_element(readerXml, config, ContactForm_Configuration_Element_Type_Enum.ExplanationText);
                        break;

                    case "hiddenvalue":
                        read_contactform_element(readerXml, config, ContactForm_Configuration_Element_Type_Enum.HiddenValue);
                        break;

                    case "textbox":
                        read_contactform_element(readerXml, config, ContactForm_Configuration_Element_Type_Enum.TextBox);
                        break;

                    case "selectbox":
                        read_contactform_element(readerXml, config, ContactForm_Configuration_Element_Type_Enum.SelectBox);
                        break;

                    case "subject":
                        read_contactform_element(readerXml, config, ContactForm_Configuration_Element_Type_Enum.Subject);
                        break;

                    case "email":
                        read_contactform_element(readerXml, config, ContactForm_Configuration_Element_Type_Enum.Email);
                        break;

                    case "radioset":
                        read_contactform_element(readerXml, config, ContactForm_Configuration_Element_Type_Enum.RadioSet);
                        break;

                    case "checkboxset":
                        read_contactform_element(readerXml, config, ContactForm_Configuration_Element_Type_Enum.CheckBoxSet);
                        break;

                    case "textarea":
                        read_contactform_element(readerXml, config, ContactForm_Configuration_Element_Type_Enum.TextArea);
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary> Read the contact form system configuration file from within the config subfolder on the web app </summary>
        /// <param name="ConfigFile"> Complete path and name of the configuration file to read </param>
        /// <returns> Built configuration object for the contact form </returns>
        public static ContactForm_Configuration Read_Config(string ConfigFile)
        {
            ContactForm_Configuration returnValue = new ContactForm_Configuration();

            // Streams used for reading
            Stream        readerStream = null;
            XmlTextReader readerXml    = null;

            try
            {
                // Open a link to the file
                readerStream = new FileStream(ConfigFile, FileMode.Open, FileAccess.Read);

                // Open a XML reader connected to the file
                readerXml = new XmlTextReader(readerStream);

                while (readerXml.Read())
                {
                    if (readerXml.NodeType == XmlNodeType.Element)
                    {
                        switch (readerXml.Name.ToLower())
                        {
                        case "contactform":
                            Read_ContactForm_Details(readerXml.ReadSubtree(), returnValue);
                            break;
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                returnValue.Error = ee.Message;
            }
            finally
            {
                if (readerXml != null)
                {
                    readerXml.Close();
                }
                if (readerStream != null)
                {
                    readerStream.Close();
                }
            }

            return(returnValue);
        }
Exemplo n.º 3
0
        private static void Read_ContactForm_Details(XmlReader readerXml, ContactForm_Configuration config)
        {
            // Read the attributes
            if (readerXml.MoveToAttribute("Name"))
            {
                config.Name = readerXml.Value.Trim();
            }

            // Just step through the subtree of this
            while (readerXml.Read())
            {
                if (readerXml.NodeType == XmlNodeType.Element)
                {
                    switch (readerXml.Name.ToLower())
                    {
                    case "elements":
                        read_contactform_elements(readerXml.ReadSubtree(), config);
                        break;
                    }
                }
            }
        }
        /// <summary> Constructor for a new instance of the Contact_HtmlSubwriter class </summary>
        /// <param name="Last_Mode"> URL for the last mode this user was in before selecting contact us</param>
        /// <param name="UserHistoryRequestInfo"> Some history and user information to include in the final email </param>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        public Contact_HtmlSubwriter(string Last_Mode, string UserHistoryRequestInfo, RequestCache RequestSpecificValues) : base(RequestSpecificValues)
        {
            // Save the parameters
            lastMode = Last_Mode;

            // Set the error message to an empty string to start with
            errorMsg = String.Empty;

            // We need the aggregation here
            Item_Aggregation aggregation;

            if (!Get_Collection(RequestSpecificValues.Current_Mode, RequestSpecificValues.Tracer, out aggregation))
            {
                aggregation = RequestSpecificValues.Top_Collection;
            }

            // Determine the configuration to use for this contact us form
            configuration = UI_ApplicationCache_Gateway.Configuration.ContactForm;
            if ((aggregation != null) && (aggregation.ContactForm != null))
            {
                configuration = aggregation.ContactForm;
            }

            postBackValues = new Dictionary <string, string>();
            foreach (string thisKey in HttpContext.Current.Request.Form.AllKeys)
            {
                if (thisKey != "item_action")
                {
                    string value = HttpContext.Current.Request.Form[thisKey];
                    if (!String.IsNullOrEmpty(value))
                    {
                        postBackValues[thisKey] = value;
                    }
                }
            }

            // If this is a post back, send email
            if (HttpContext.Current.Request.Form["item_action"] == null)
            {
                return;
            }

            string action = HttpContext.Current.Request.Form["item_action"];

            if (action == "email")
            {
                // Some values to collect information
                string subject      = "Contact [" + RequestSpecificValues.Current_Mode.Instance_Abbreviation + " Submission]";
                string message_from = RequestSpecificValues.Current_Mode.Instance_Abbreviation + "<" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">";
                if (!String.IsNullOrEmpty(UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay))
                {
                    message_from = UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + "<" + UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromAddress + ">";
                }
                int           text_area_count = configuration.TextAreaElementCount;
                StringBuilder emailBuilder    = new StringBuilder();

                // Make sure all the required fields are completed and build the emails
                StringBuilder errorBuilder  = new StringBuilder();
                int           control_count = 1;
                foreach (ContactForm_Configuration_Element thisElement in configuration.FormElements)
                {
                    if ((thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.HiddenValue) && (thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.ExplanationText))
                    {
                        // Determine the name of this control
                        string control_name = String.Empty;
                        if (!String.IsNullOrEmpty(thisElement.Name))
                        {
                            control_name = thisElement.Name.Replace(" ", "_");
                        }
                        if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.Subject)
                        {
                            control_name = "subject";
                        }
                        if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.Email)
                        {
                            control_name = "email";
                        }
                        if (String.IsNullOrEmpty(control_name))
                        {
                            control_name = "Control" + control_count;
                        }

                        if (!postBackValues.ContainsKey(control_name))
                        {
                            if (thisElement.Required)
                            {
                                errorBuilder.Append(thisElement.QueryText.Get_Value(RequestSpecificValues.Current_Mode.Language).Replace(":", "") + "<br />");
                            }
                        }
                        else
                        {
                            if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.Subject)
                            {
                                subject = postBackValues[control_name] + " [" + RequestSpecificValues.Current_Mode.Instance_Abbreviation + " Submission]";
                            }
                            else if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.Email)
                            {
                                string entered_message_from = postBackValues[control_name];

                                if (!IsValidEmail(entered_message_from))
                                {
                                    errorBuilder.Append(thisElement.QueryText.Get_Value(RequestSpecificValues.Current_Mode.Language).Replace(":", "") + " (INVALID) <br />");
                                }

                                message_from = RequestSpecificValues.Current_Mode.Instance_Abbreviation + "<" + entered_message_from + ">";
                                if (!String.IsNullOrEmpty(UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay))
                                {
                                    message_from = UI_ApplicationCache_Gateway.Settings.Email.Setup.DefaultFromDisplay + "<" + entered_message_from + ">";
                                }

                                emailBuilder.Append("Email:\t\t" + entered_message_from + "\n");
                            }
                            else if (thisElement.Element_Type == ContactForm_Configuration_Element_Type_Enum.TextArea)
                            {
                                if (text_area_count == 1)
                                {
                                    emailBuilder.Insert(0, postBackValues[control_name] + "\n\n");
                                }
                                else
                                {
                                    if (emailBuilder.Length > 0)
                                    {
                                        emailBuilder.Append("\n");
                                    }
                                    emailBuilder.Append(thisElement.QueryText.Get_Value(RequestSpecificValues.Current_Mode.Language) + "\n");
                                    emailBuilder.Append(postBackValues[control_name] + "\n\n");
                                }
                            }
                            else
                            {
                                emailBuilder.Append(control_name.Replace("_", " ") + ":\t\t" + postBackValues[control_name] + "\n");
                            }
                        }

                        control_count++;
                    }
                }

                if (errorBuilder.Length > 0)
                {
                    errorMsg = errorBuilder.ToString();
                    return;
                }

                // Create the final body
                string email_body = emailBuilder + "\n\n" + UserHistoryRequestInfo;

                // Determine the sendee
                string sendTo = UI_ApplicationCache_Gateway.Settings.Email.System_Email;
                if ((aggregation != null) && (!String.IsNullOrEmpty(aggregation.Contact_Email)))
                {
                    sendTo = aggregation.Contact_Email.Replace(";", ",");
                }

                int userid = -1;
                if (RequestSpecificValues.Current_User != null)
                {
                    userid = RequestSpecificValues.Current_User.UserID;
                }

                EmailInfo newEmail = new EmailInfo
                {
                    Body           = email_body,
                    isContactUs    = true,
                    isHTML         = false,
                    RecipientsList = sendTo,
                    Subject        = subject,
                    UserID         = userid,
                    FromAddress    = message_from
                };

                string error_msg;
                bool   email_error = !Email_Helper.SendEmail(newEmail, out error_msg);


                // Send back to the home for this collection, sub, or group
                if (email_error)
                {
                    HttpContext.Current.Response.Redirect(UI_ApplicationCache_Gateway.Settings.Servers.System_Error_URL, false);
                    HttpContext.Current.ApplicationInstance.CompleteRequest();
                }
                else
                {
                    // Send back to the home for this collection, sub, or group
                    RequestSpecificValues.Current_Mode.Mode = Display_Mode_Enum.Contact_Sent;
                    UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                }
            }
        }
Exemplo n.º 5
0
        private static void read_contactform_element(XmlReader readerXml, ContactForm_Configuration config, ContactForm_Configuration_Element_Type_Enum type)
        {
            // Create the element object
            ContactForm_Configuration_Element newElement = new ContactForm_Configuration_Element(type);

            // Read the attributes
            if (readerXml.MoveToAttribute("Name"))
            {
                newElement.Name = readerXml.Value.Trim();
                if (String.IsNullOrEmpty(newElement.QueryText.DefaultValue))
                {
                    newElement.QueryText.DefaultValue = newElement.Name.Replace("_", " ") + ":";
                }
            }
            if (readerXml.MoveToAttribute("CssClass"))
            {
                newElement.CssClass = readerXml.Value.Trim();
            }
            if (readerXml.MoveToAttribute("Query"))
            {
                newElement.QueryText.DefaultValue = readerXml.Value.Trim();
            }
            else if (readerXml.MoveToAttribute("Text"))
            {
                newElement.QueryText.DefaultValue = readerXml.Value.Trim();
            }
            if (readerXml.MoveToAttribute("UserAttribute"))
            {
                string attr = readerXml.Value.Trim();
                newElement.UserAttribute = User_Object_Attribute_Mapping_Enum_Converter.ToEnum(attr);
            }
            if (readerXml.MoveToAttribute("AlwaysShow"))
            {
                string alwaysShow = readerXml.Value.Trim();
                switch (alwaysShow.ToLower())
                {
                case "false":
                    newElement.AlwaysShow = false;
                    break;

                case "true":
                    newElement.AlwaysShow = true;
                    break;
                }
            }
            if (readerXml.MoveToAttribute("Required"))
            {
                string required = readerXml.Value.Trim();
                switch (required.ToLower())
                {
                case "false":
                    newElement.Required = false;
                    break;

                case "true":
                    newElement.Required = true;
                    break;
                }
            }

            readerXml.MoveToElement();

            // Just step through the subtree of this
            XmlReader subTreeReader = readerXml.ReadSubtree();

            while (subTreeReader.Read())
            {
                if (subTreeReader.NodeType == XmlNodeType.Element)
                {
                    switch (subTreeReader.Name.ToLower())
                    {
                    case "option":
                        if (!subTreeReader.IsEmptyElement)
                        {
                            subTreeReader.Read();
                            if (newElement.Options == null)
                            {
                                newElement.Options = new List <string>();
                            }
                            newElement.Options.Add(subTreeReader.Value.Trim());
                        }
                        break;

                    case "language":
                        if (!subTreeReader.IsEmptyElement)
                        {
                            if (subTreeReader.MoveToAttribute("Code"))
                            {
                                string            language_code = subTreeReader.Value.Trim();
                                Web_Language_Enum enum_lang     = Web_Language_Enum_Converter.Code_To_Enum(language_code);
                                if (enum_lang != Web_Language_Enum.UNDEFINED)
                                {
                                    subTreeReader.Read();
                                    newElement.QueryText.Add_Translation(enum_lang, subTreeReader.Value.Trim());
                                }
                            }
                        }
                        break;
                    }
                }
            }


            config.Add_Element(newElement);
        }