Exemple #1
0
 public static CMMicrosite GetCurrentRequestCMSMicrosite(HttpContext requestContext = null)
 {
     if (requestContext == null)
     {
         requestContext = HttpContext.Current;
     }
     if (requestContext == null || requestContext.Items["CMSMicrosite"] == "null")
     {
         return(null);
     }
     if (requestContext.Items["CMSMicrosite"] == null)
     {
         string      fileName    = Helpers.GetFileName(requestContext);
         int?        micrositeID = GetCMMicrositeID(fileName, out fileName);
         CMMicrosite microsite   = micrositeID.HasValue ? CMMicrosite.GetByID(micrositeID.Value) : null;
         if (microsite != null)
         {
             CMSHelpers.SetCurrentRequestCMSMicrosite(microsite);
         }
         else
         {
             requestContext.Items["CMSMicrosite"] = "null";
         }
         return(microsite);
     }
     return((CMMicrosite)requestContext.Items["CMSMicrosite"]);
 }
Exemple #2
0
        public static void SendSiteMapApprovalEmailAlerts(int userID, int?micrositeID, int?languageID, bool isAdmin, bool?approval)
        {
            if (Settings.EnableApprovals && Settings.SendApprovalEmails)
            {
                MailMessage email  = new MailMessage();
                SmtpClient  client = new SmtpClient();
                if (!approval.HasValue)
                {
                    string key = "ContentManager_SiteMapApprovalEmails_" + userID + "_" + micrositeID + "_" + languageID;
                    if (!Settings.EnableCaching || HttpContext.Current == null || HttpContext.Current.Cache == null || HttpContext.Current.Cache[key] == null)
                    {
                        User     userEntity     = User.GetByID(userID);
                        Language languageEntity = null;
                        if (languageID.HasValue)
                        {
                            languageEntity = Language.GetByID(languageID.Value);
                        }
                        //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 : "") + (micrositeID.HasValue ? micrositeID == -1 ? " Microsite Default" : " " + CMMicrosite.GetByID(micrositeID.Value).Name : "") + " <a href=\"" + Helpers.RootPath + "admin/content-manager/sitemap.aspx" + (micrositeID.HasValue ? "?micrositeid=" + micrositeID.Value : "") + (languageEntity != null ? (micrositeID.HasValue ? "&" : "?") + "language=" + languageEntity.CultureName : "") + "\">Sitemap</a>";
                            email.Subject    = Globals.Settings.SiteTitle + " - Sitemap Approval Required";

                            client.Send(email);
                        }

                        //Send Editor Email
                        email      = new MailMessage();
                        email.From = new MailAddress(Globals.Settings.FromEmail);

                        List <SMItemUser> allEditors;
                        if (micrositeID.HasValue && micrositeID > 0)
                        {
                            allEditors = SMItemUser.SMItemUserGetByCMMicrositeID(micrositeID);
                        }
                        else if (micrositeID.HasValue && micrositeID == -1)
                        {
                            allEditors = SMItemUser.SMItemUserGetByMicrositeDefault(true);
                        }
                        else
                        {
                            allEditors = SMItemUser.GetAll().Where(s => s.CMMicrositeID == null && !s.MicrositeDefault).ToList();
                        }

                        if (languageID.HasValue)
                        {
                            allEditors = allEditors.Where(s => s.LanguageID == languageID.Value).ToList();
                        }

                        foreach (SMItemUser id in allEditors)
                        {
                            if (id.UserID != userID)
                            {
                                User editor = User.GetByID(id.UserID);
                                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 : "") + (micrositeID.HasValue ? micrositeID == -1 ? " Microsite Default" : " " + CMMicrosite.GetByID(micrositeID.Value).Name : "") + " <a href=\"" + Helpers.RootPath + "admin/content-manager/sitemap.aspx" + (micrositeID.HasValue ? "?micrositeid=" + micrositeID.Value : "") + (languageEntity != null ? (micrositeID.HasValue ? "&" : "?") + "language=" + languageEntity.CultureName : "") + "\">Sitemap</a>, which you have also edited.  The Sitemap is still awaiting approval from an Admin.";
                            email.Subject    = Globals.Settings.SiteTitle + " - Sitemap Edited";

                            client = new SmtpClient();
                            client.Send(email);
                        }
                        //Only send email alerts every 10 minutes per user that changes sitemap
                        if (Settings.EnableCaching && HttpContext.Current != null && HttpContext.Current.Cache != null)
                        {
                            HttpContext.Current.Cache.Insert(key, true, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
                        }
                    }
                }
                else                 //Approve/Denied
                {
                    //Send Editors Email
                    email      = new MailMessage();
                    email.From = new MailAddress(Globals.Settings.FromEmail);

                    List <SMItemUser> allEditors;
                    if (micrositeID.HasValue && micrositeID > 0)
                    {
                        allEditors = SMItemUser.SMItemUserGetByCMMicrositeID(micrositeID);
                    }
                    else if (micrositeID.HasValue && micrositeID == -1)
                    {
                        allEditors = SMItemUser.SMItemUserGetByMicrositeDefault(true);
                    }
                    else
                    {
                        allEditors = SMItemUser.GetAll().Where(s => s.CMMicrositeID == null && !s.MicrositeDefault).ToList();
                    }

                    if (languageID.HasValue)
                    {
                        allEditors = allEditors.Where(s => s.LanguageID == languageID.Value).ToList();
                    }

                    foreach (SMItemUser id in allEditors)
                    {
                        if (id.UserID != userID)
                        {
                            User editor = User.GetByID(id.UserID);
                            email.To.Add(new MailAddress(editor.Email, editor.Name));
                        }
                    }

                    SMItemUser.DeleteAll(micrositeID, languageID);

                    if (email.To.Count > 0)
                    {
                        Language languageEntity = null;
                        if (languageID.HasValue)
                        {
                            languageEntity = Language.GetByID(languageID.Value);
                        }

                        email.IsBodyHtml = true;
                        email.Body       = "An Admin has " + (approval.Value ? "approved" : "denied") + " the changes to the" + (languageEntity != null ? " " + languageEntity.Culture : "") + (micrositeID.HasValue ? micrositeID == -1 ? " Microsite Default" : " " + CMMicrosite.GetByID(micrositeID.Value).Name : "") + " <a href=\"" + Helpers.RootPath + "admin/content-manager/sitemap.aspx" + (micrositeID.HasValue ? "?micrositeid=" + micrositeID.Value : "") + (languageEntity != null ? (micrositeID.HasValue ? "&" : "?") + "language=" + languageEntity.CultureName : "") + "\">Sitemap</a> that you made.";
                        email.Subject    = Globals.Settings.SiteTitle + " - Sitemap " + (approval.Value ? "Approved" : "Denied");

                        client = new SmtpClient();
                        client.Send(email);
                    }
                }
            }
        }
Exemple #3
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);
                    }
                }
            }
        }