public static CMPageRegion GetByID(int CMPageRegionID, IEnumerable <string> includeList = null)
        {
            CMPageRegion obj = null;
            string       key = cacheKeyPrefix + CMPageRegionID + GetCacheIncludeText(includeList);

            CMPageRegion tmpClass = null;

            if (Cache.IsEnabled)
            {
                if (Cache.IsEmptyCacheItem(key))
                {
                    return(null);
                }
                tmpClass = Cache[key] as CMPageRegion;
            }

            if (tmpClass != null)
            {
                obj = tmpClass;
            }
            else
            {
                using (Entities entity = new Entities())
                {
                    IQueryable <CMPageRegion> itemQuery = AddIncludes(entity.CMPageRegion, includeList);
                    obj = itemQuery.FirstOrDefault(n => n.CMPageRegionID == CMPageRegionID);
                }
                Cache.Store(key, obj);
            }

            return(obj);
        }
예제 #2
0
        public static CMPageRegion LoadContentRegion(Filters filterList = new Filters())
        {
            int    defaultLanguageID = Helpers.GetDefaultLanguageID();
            string cachingFilterText = GetCacheFilterText(filterList.GetFilterList(), string.Empty);

            CMPageRegion obj = null;
            string       key = cacheKeyPrefix + "LoadContentRegion_" + cachingFilterText + "_" + defaultLanguageID;

            CMPageRegion tmpObj = null;

            if (Cache.IsEnabled)
            {
                tmpObj = Cache[key] as CMPageRegion;
            }

            if (tmpObj != null)
            {
                obj = tmpObj;
            }
            else
            {
                using (Entities entity = new Entities())
                {
                    obj = entity.CMS_LoadContentRegion(filterList.FilterCMPageRegionCMPageID, filterList.FilterCMPageRegionCMRegionID, filterList.FilterCMPageRegionLanguageID, filterList.FilterCMPageRegionUserID, filterList.FilterCMPageRegionCreated, (!String.IsNullOrEmpty(filterList.FilterCMPageRegionNeedsApproval) ? (bool?)Convert.ToBoolean(filterList.FilterCMPageRegionNeedsApproval) : null), defaultLanguageID).FirstOrDefault();
                    if (obj != null)
                    {
                        obj.ContentClean = null;
                    }
                }

                Cache.Store(key, obj);
            }
            return(obj);
        }
 public CMPageRegion(CMPageRegion objectToCopy)
 {
     CMPageID           = objectToCopy.CMPageID;
     CMPageRegionID     = objectToCopy.CMPageRegionID;
     CMRegionID         = objectToCopy.CMRegionID;
     Content            = objectToCopy.Content;
     ContentClean       = objectToCopy.ContentClean;
     Created            = objectToCopy.Created;
     CurrentVersion     = objectToCopy.CurrentVersion;
     Draft              = objectToCopy.Draft;
     EditorUserIDs      = objectToCopy.EditorUserIDs;
     GlobalAreaCMPageID = objectToCopy.GlobalAreaCMPageID;
     LanguageID         = objectToCopy.LanguageID;
     NeedsApproval      = objectToCopy.NeedsApproval;
     UserID             = objectToCopy.UserID;
 }
예제 #4
0
        /// <summary>
        /// This method checks the Content Manager page for form fields.
        /// If it finds form fields it will submit them to the form recipient.
        /// </summary>
        public static void ParseRequestForFormFields(string regionName)
        {
            if (String.IsNullOrEmpty(HttpContext.Current.Request.Form[DynamicSubmitName]))
            {
                return;
            }
            int?   micrositeID   = null;
            bool   globalContact = false;
            CMPage cmPage        = CMSHelpers.GetCurrentRequestCMSPage();

            // determine legit fields
            List <CMPageRegion> prs = new List <CMPageRegion>();
            int?userID = Helpers.GetCurrentUserID();

            if (userID == 0)
            {
                userID = null;
            }
            if (cmPage != null)
            {
                CMRegion cmRegion = CMRegion.CMRegionPage(0, 1, "", "", true, new CMRegion.Filters {
                    FilterCMRegionName = regionName
                }).FirstOrDefault();
                if (cmRegion != null)
                {
                    CMPageRegion currentRegion = CMPageRegion.LoadContentRegion(new CMPageRegion.Filters {
                        FilterCMPageRegionCMRegionID = cmRegion.CMRegionID.ToString(), FilterCMPageRegionUserID = userID.ToString(), FilterCMPageRegionCMPageID = cmPage.CMPageID.ToString(), FilterCMPageRegionNeedsApproval = false.ToString()
                    });
                    if (currentRegion != null)
                    {
                        prs.Add(currentRegion);
                    }
                }
            }

            //Also get Global areas that might contain forms
            List <CMPage> globalAreas = CMSHelpers.GetCachedCMPages().Where(c => !c.CMTemplateID.HasValue && c.FileName.Equals(regionName)).ToList();
            List <CMPage> temp        = new List <CMPage>();

            temp.AddRange(globalAreas);
            foreach (CMPage globalPage in temp)
            {
                CMRegion cmRegion = CMRegion.CMRegionGetByName(regionName).FirstOrDefault();
                if (cmRegion != null)
                {
                    CMPageRegion region = CMPageRegion.LoadContentRegion(new CMPageRegion.Filters {
                        FilterCMPageRegionCMRegionID = cmRegion.CMRegionID.ToString(), FilterCMPageRegionUserID = userID.ToString(), FilterCMPageRegionCMPageID = globalPage.CMPageID.ToString(), FilterCMPageRegionNeedsApproval = false.ToString()
                    });
                    if (region != null)
                    {
                        prs.Clear();
                        prs.Add(region);
                    }
                    else
                    {
                        globalAreas.Remove(globalPage);
                    }
                }
                else
                {
                    globalAreas.Remove(globalPage);
                }
            }
            if (prs.Count > 0)
            {
                bool hasFields = false;

                List <string> validFields = new List <string>();
                List <string> checkBoxes  = new List <string>();

                foreach (CMPageRegion pr in prs)
                {
                    MatchCollection ms = Regex.Matches(pr.Content, @"<(input|textarea|select) (.|\n)*?name=""?((\w|\d|\s|\-|\(|\))+)""?(.|\n)*?/?>", RegexOptions.IgnoreCase | RegexOptions.Multiline);
                    if (ms.Count > 0 && globalAreas.Exists(c => c.CMPageID == pr.CMPageID))
                    {
                        cmPage        = globalAreas.Find(c => c.CMPageID == pr.CMPageID);
                        globalContact = true;
                    }
                    foreach (Match m in ms)
                    {
                        if (!m.ToString().Contains("type=\"radio\"") || !validFields.Contains(m.Groups[3].Value))
                        {
                            validFields.Add(m.Groups[3].Value);
                        }
                        if (m.ToString().Contains("type=\"checkbox\""))
                        {
                            checkBoxes.Add(m.Groups[3].Value);
                        }
                    }
                }

                validFields.Remove("dynamicsubmit");

                CMSubmittedForm newForm = new CMSubmittedForm();
                newForm.IsProcessed    = false;
                newForm.DateSubmitted  = DateTime.UtcNow;
                newForm.FormRecipient  = cmPage.FormRecipient;
                newForm.ResponsePageID = cmPage.ResponsePageID;
                newForm.CMMicrositeID  = cmPage.CMMicrositeID;

                if (HttpContext.Current.Request.Files.Count > 0)
                {
                    if (Regex.IsMatch(HttpContext.Current.Request.Files[0].FileName, "(\\.(doc)|(docx)|(pdf)|(jpg)|(jpeg)|(bmp)|(png)|(gif)|(ppt)|(pptx)|(xls)|(xlsx))$"))
                    {
                        HttpContext.Current.Request.Files[0].SaveAs(HttpContext.Current.Server.MapPath(UploadedFilesLocation + HttpContext.Current.Request.Files[0].FileName));
                        newForm.UploadedFile = HttpContext.Current.Request.Files[0].FileName;
                    }
                    else
                    {
                        Page page = (Page)HttpContext.Current.Handler;
                        page.ClientScript.RegisterStartupScript(page.GetType(), "InvalidFileExt", "alert('Invalid file extension.  Valid extensions are: doc,docx,pdf,jpg,jpeg,bmp,png,gif,ppt,pptx,xls,xlsx');", true);
                        return;
                    }
                }

                if (validFields.Count > 0)
                {
                    StringBuilder formData = new StringBuilder();
                    validFields.ForEach(s =>
                    {
                        if (HttpContext.Current.Request.Form[s] != null)
                        {
                            formData.Append(string.Format("<tr><td>{0}</td><td>{1}</td></tr>", s, HttpContext.Current.Request.Form[s].ToString()));
                            if (!hasFields)
                            {
                                hasFields = true;
                            }
                        }                                                                         // if the item is not posted, no harm, just dont include it
                        else if (checkBoxes.Contains(s))
                        {
                            formData.Append(string.Format("<tr><td>{0}</td><td>{1}</td></tr>", s, "off"));
                            if (!hasFields)
                            {
                                hasFields = true;
                            }
                        }
                    });
                    if (hasFields)
                    {
                        string body = EmailTemplateService.HtmlMessageBody(EmailTemplates.CMSFormPost, new { PageName = cmPage.FileName, FormFields = formData.ToString() });

                        newForm.FormHTML = body;
                        newForm.Save();
                        if (globalContact && !String.IsNullOrEmpty(Settings.GlobalContactEmailAddress))
                        {
                            MailMessage message = new MailMessage();
                            message.To.Add(Settings.GlobalContactEmailAddress);
                            message.IsBodyHtml = true;
                            message.Body       = body;
                            message.Subject    = Globals.Settings.SiteTitle + "- Form Submission From " + cmPage.FileName;
                            if (!String.IsNullOrEmpty(newForm.UploadedFile))
                            {
                                message.Attachments.Add(new Attachment(HttpContext.Current.Server.MapPath(UploadedFilesLocation + newForm.UploadedFile)));
                            }
                            SmtpClient client = new SmtpClient();
                            client.Send(message);
                        }
                        else if (!String.IsNullOrEmpty(cmPage.FormRecipient))
                        {
                            cmPage.FormRecipient.Split(',').ToList().ForEach(recipient =>
                            {
                                MailMessage message = new MailMessage();
                                message.To.Add(recipient);
                                message.IsBodyHtml = true;
                                message.Body       = body;
                                message.Subject    = Globals.Settings.SiteTitle + "- Form Submission From " + cmPage.FileName;
                                if (!String.IsNullOrEmpty(newForm.UploadedFile))
                                {
                                    message.Attachments.Add(new Attachment(HttpContext.Current.Server.MapPath(UploadedFilesLocation + newForm.UploadedFile)));
                                }
                                SmtpClient client = new SmtpClient();
                                client.Send(message);
                            });
                        }
                    }
                    if (hasFields)
                    {
                        if (globalContact)
                        {
                            Page page = (Page)HttpContext.Current.Handler;
                            page.ClientScript.RegisterStartupScript(page.GetType(), PopupScriptName, @"$(document).ready(function(){
	if ($('a#contactDummyLink').length == 0)
		$('div.contactSuccess').parent().parent().prepend('<a href=""#contactSuccess"" style=""display:none;"" id=""contactDummyLink"">success</a>');
	$('a#contactDummyLink').fancybox();
	$('a#contactDummyLink').trigger('click');
	setTimeout(function(){$.fancybox.close();}, 4000);
});", true);
                        }
                        else if (cmPage.ResponsePageID != null)
                        {
                            HttpContext.Current.Response.Redirect(CMSHelpers.GetCachedCMPages().Where(p => p.CMPageID == cmPage.ResponsePageID.Value).Single().FileName);
                        }
                        else
                        {
                            Page page = (Page)HttpContext.Current.Handler;
                            //If you change the key or type of the script below,
                            //you must also change it on the _RadEditor.cs file or your page will not load correctly
                            //in the if statement with Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), "PopupScript")
                            page.ClientScript.RegisterStartupScript(page.GetType(), PopupScriptName, "alert('Thank you. Your form has been submitted successfully.');", true);
                        }
                    }
                }
            }
        }
예제 #5
0
        public static void SendApprovalEmailAlerts(CMPage editedPage, CMPageRegion region, int userID, bool content, bool isAdmin, bool?approval, int?languageID)
        {
            if (Settings.EnableApprovals && Settings.SendApprovalEmails)
            {
                MailMessage email        = new MailMessage();
                SmtpClient  client       = new SmtpClient();
                CMPage      originalPage = editedPage.OriginalCMPageID.HasValue ? CMPage.GetByID(editedPage.OriginalCMPageID.Value) : null;
                string      pageName     = string.Empty;
                if (languageID.HasValue)
                {
                    CMPageTitle titleEntity = null;
                    //If Denied, take the original page title
                    if (originalPage != null && approval.HasValue && !approval.Value)
                    {
                        titleEntity = CMPageTitle.CMPageTitleGetByCMPageIDAndLanguageID(originalPage.CMPageID, languageID.Value).FirstOrDefault();
                    }
                    //If not approve/deny, take the current displayed unapproved page title
                    if (titleEntity == null)
                    {
                        titleEntity = CMPageTitle.CMPageTitleGetByCMPageIDAndLanguageID(editedPage.CMPageID, languageID.Value).FirstOrDefault();
                    }
                    if (titleEntity != null)
                    {
                        pageName = titleEntity.Title;
                    }
                }
                if (String.IsNullOrEmpty(pageName))
                {
                    if (originalPage != null && approval.HasValue && !approval.Value)
                    {
                        pageName = originalPage.Title;
                    }
                    else
                    {
                        pageName = editedPage.Title;
                    }
                }

                Language languageEntity = null;
                if (languageID.HasValue)
                {
                    languageEntity = Language.GetByID(languageID.Value);
                }

                if (!approval.HasValue)
                {
                    User userEntity = User.GetByID(userID);
                    //Don't send Admin Email if Admin is the one who edited
                    if (!isAdmin)
                    {
                        //Send Admin Email
                        email.From = new MailAddress(Globals.Settings.FromEmail);
                        if (!String.IsNullOrEmpty(Settings.ApprovalAdminEmailAddresses))
                        {
                            foreach (string s in Settings.ApprovalAdminEmailAddresses.Split(';'))
                            {
                                email.To.Add(new MailAddress(s));
                            }
                        }
                        else                         //Send to all Admins
                        {
                            foreach (UserRole admin in UserRole.UserRoleGetWithUserByRoleName("Admin"))
                            {
                                email.To.Add(new MailAddress(admin.User.Email, admin.User.Name));
                            }
                        }

                        email.IsBodyHtml = true;
                        email.Body       = userEntity.Name + " has updated the " + (languageEntity != null ? languageEntity.Culture + " " : "") + (content ? "content" : "properties") + " of <a href=\"" + Helpers.RootPath + (content ? (editedPage.CMMicrositeID.HasValue ? CMMicrosite.GetByID(editedPage.CMMicrositeID.Value).Name + "/" : "") + editedPage.FileName + (languageEntity != null ? "?language=" + languageEntity.CultureName : "") : "admin/content-manager/content-manager-page.aspx?id=" + editedPage.CMPageID + (languageEntity != null ? "&language=" + languageEntity.CultureName : "")) + "\">" + pageName + "</a>";
                        email.Subject    = Globals.Settings.SiteTitle + " - " + (content ? "Content" : "Page Properties") + " Approval Required";

                        client.Send(email);
                    }

                    //Send Editor Email
                    email      = new MailMessage();
                    email.From = new MailAddress(Globals.Settings.FromEmail);
                    if (content && region != null && !String.IsNullOrEmpty(region.EditorUserIDs))
                    {
                        foreach (string id in region.EditorUserIDs.Split(','))
                        {
                            if (!id.Equals(userID.ToString()))
                            {
                                User editor = User.GetByID(Convert.ToInt32(id));
                                email.To.Add(new MailAddress(editor.Email, editor.Name));
                            }
                        }
                    }
                    else if (!String.IsNullOrEmpty(editedPage.EditorUserIDs))
                    {
                        foreach (string id in editedPage.EditorUserIDs.Split(','))
                        {
                            if (!id.Equals(userID.ToString()))
                            {
                                User editor = User.GetByID(Convert.ToInt32(id));
                                email.To.Add(new MailAddress(editor.Email, editor.Name));
                            }
                        }
                    }

                    if (email.To.Count > 0)
                    {
                        email.IsBodyHtml = true;
                        email.Body       = userEntity.Name + " has updated the " + (languageEntity != null ? languageEntity.Culture + " " : "") + (content ? "content" : "properties") + " of <a href=\"" + Helpers.RootPath + (content ? (editedPage.CMMicrositeID.HasValue ? CMMicrosite.GetByID(editedPage.CMMicrositeID.Value).Name + "/" : "") + editedPage.FileName + (languageEntity != null ? "?language=" + languageEntity.CultureName : "") : "admin/content-manager/content-manager-page.aspx?id=" + editedPage.CMPageID + (languageEntity != null ? "&language=" + languageEntity.CultureName : "")) + "\">" + pageName + "</a>, which you have also edited.  The page is still awaiting approval from an Admin.";
                        email.Subject    = Globals.Settings.SiteTitle + " - " + (content ? "Content" : "Page Properties") + " Edited";

                        client = new SmtpClient();
                        client.Send(email);
                    }
                }
                else                 //Approve/Denied
                {
                    //Send Editors Email
                    email      = new MailMessage();
                    email.From = new MailAddress(Globals.Settings.FromEmail);
                    if (content && region != null && !String.IsNullOrEmpty(region.EditorUserIDs))
                    {
                        foreach (string id in region.EditorUserIDs.Split(','))
                        {
                            if (!id.Equals(userID.ToString()))
                            {
                                User editor = User.GetByID(Convert.ToInt32(id));
                                email.To.Add(new MailAddress(editor.Email, editor.Name));
                            }
                        }
                    }
                    else if (!String.IsNullOrEmpty(editedPage.EditorUserIDs))
                    {
                        foreach (string id in editedPage.EditorUserIDs.Split(','))
                        {
                            if (!id.Equals(userID.ToString()))
                            {
                                User editor = User.GetByID(Convert.ToInt32(id));
                                email.To.Add(new MailAddress(editor.Email, editor.Name));
                            }
                        }
                    }

                    if (email.To.Count > 0)
                    {
                        email.IsBodyHtml = true;
                        email.Body       = "An Admin has " + (approval.Value ? "approved" : "denied") + " the " + (languageEntity != null ? languageEntity.Culture + " " : "") + (content ? "content" : "properties") + " changes to <a href=\"" + Helpers.RootPath + (content ? (editedPage.CMMicrositeID.HasValue ? CMMicrosite.GetByID(editedPage.CMMicrositeID.Value).Name + "/" : "") + editedPage.FileName + (languageEntity != null ? "?language=" + languageEntity.CultureName : "") : "admin/content-manager/content-manager-page.aspx?id=" + editedPage.CMPageID + (languageEntity != null ? "&language=" + languageEntity.CultureName : "")) + "\">" + pageName + "</a> that you made.";
                        email.Subject    = Globals.Settings.SiteTitle + " - " + (content ? "Content" : "Page Properties") + " " + (approval.Value ? "Approved" : "Denied");

                        client = new SmtpClient();
                        client.Send(email);
                    }
                }
            }
        }
예제 #6
0
 public static void SendApprovalEmailAlerts(CMPage editedPage, CMPageRegion region, int userID, bool content, bool isAdmin)
 {
     SendApprovalEmailAlerts(editedPage, region, userID, content, isAdmin, null, null);
 }