private bool sendEmailNotification(string PageID, string PageName, string PageURL) { bool result = false; try { Configuration config = new Configuration(SPContext.Current.Site.ID, SPContext.Current.Web.ID); if(!string.IsNullOrEmpty(config.PAGE_NAME) && !string.IsNullOrEmpty(config.APPROVAL_LIST)) { ApproveData AD = new ApproveData(SPContext.Current.Site.ID, SPContext.Current.Web.ID, config.PAGE_NAME); string UserEmails = AD.GetEmailByPage(PageID); if(!string.IsNullOrEmpty(UserEmails)) { EmailControl emailControl = new EmailControl(); string bodyh = "You have a Policy Pending.</br>Please <a href='http://sharepoint/Pages/Pending.aspx'>Click Here</a> to acknowledge Pending Policies"; // string bodyh = string.Format("You need to approve the policy: <a href='{0}'>{0}</a>", PageURL, PageName); emailControl.SendEmialInternal(SPContext.Current.Site.ID, SPContext.Current.Site.Zone, SPContext.Current.Web.ID, UserEmails, bodyh, "Approve policy"); } } result = true; } catch{ } return result; }
public void AnalyzeSLAInformation() { this.ApproveMessageError ="Start Trace "; List<DataApprove> dataapproveList = new List<DataApprove>(); List<DataPublishPage> dataPublishPageList = new List<DataPublishPage>(); List<DataPublishPage> ResultdataPublishPageList = new List<DataPublishPage>(); SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(this.siteID)) { using (SPWeb web = site.OpenWeb(this.webID)) { if (web.Lists.TryGetList(this.approveList) != null && web.Lists.TryGetList(this.listName) != null) { SPList PublicPageList = web.Lists[this.listName]; SPQuery pageListQuery = new SPQuery(); pageListQuery.Query = "<Where><And><Eq><FieldRef Name='_ModerationStatus' /><Value Type='ModStat'>Approved</Value></Eq><Gt><FieldRef Name='SLA' /><Value IncludeTimeValue='FALSE' Type='DateTime'><Today /></Value></Gt></And></Where>"; pageListQuery.Folder = PublicPageList.RootFolder.SubFolders["Policies"]; SPListItemCollection pagesCollection = PublicPageList.GetItems(pageListQuery); foreach (SPListItem pageItem in pagesCollection) { string tempversion = string.Empty; string tempcategory = string.Empty; SPFieldUserValueCollection localSharePointGroup = null; SPFieldUserValueCollection localPolicySupervisor = null; if (pageItem.Fields.ContainsField(constants.columns.PageList.Version) && pageItem[constants.columns.PageList.Version] != null) tempversion = pageItem[constants.columns.PageList.Version].ToString(); if (pageItem.Fields.ContainsField(constants.columns.PageList.PageCategory) && pageItem[constants.columns.PageList.PageCategory] != null) tempcategory = pageItem[constants.columns.PageList.PageCategory].ToString(); if (pageItem[constants.columns.PageList.ApprovalGroup] != null && pageItem[constants.columns.PageList.PolicySupervisor] != null) { localSharePointGroup = new SPFieldUserValueCollection(pageItem.Web, pageItem[constants.columns.PageList.ApprovalGroup].ToString()); localPolicySupervisor = new SPFieldUserValueCollection(pageItem.Web, pageItem[constants.columns.PageList.PolicySupervisor].ToString()); if (localSharePointGroup[0].User == null) { this.ApproveMessageError += "Send in Group"; if (web.Groups.GetByID(localSharePointGroup[0].LookupId) != null) { SPList apporoveList = web.Lists[this.approveList]; SPQuery listQuery = new SPQuery(); listQuery.Query = string.Format("<Where><And><Eq><FieldRef Name='Policy_x0020_Page_x0020_ID' /><Value Type='Text'>{0}</Value></Eq><Eq><FieldRef Name='_UIVersionString' /><Value Type='Text'>{1}</Value></Eq></And></Where>", pageItem.ID.ToString(), pageItem[constants.columns.PageList.Version].ToString()); SPListItemCollection cgenericCollection = apporoveList.GetItems(listQuery); if (cgenericCollection.Count == 0) { string allnames = GetAllNamesinGroup(this.siteID, this.webID, localSharePointGroup[0].LookupId); if (!string.IsNullOrEmpty(allnames)) { EmailControl emailControl = new EmailControl(); string bodyh = string.Format("User {0} has not acknowledged the policy: {1} by the due date", allnames, pageItem.Title); this.ApproveMessageError += " Before sddn email suvervisor: " + localPolicySupervisor[0].User.Email; emailControl.SendEmialInternal(this.siteID, site.Zone, this.webID, localPolicySupervisor[0].User.Email, bodyh, "Pending policy"); } } else { List<SPUser> usersisgroup = GetUsersInGroup(this.siteID, this.webID, localSharePointGroup[0].LookupId); List<string> readyUserList = new List<string>(); string NamesNotapprov = string.Empty; foreach (SPListItem approveItem in cgenericCollection) { SPFieldUserValue userValue = new SPFieldUserValue(web, approveItem["Created By"].ToString()); readyUserList.Add(userValue.User.LoginName); } foreach (SPUser cuser in usersisgroup) { if (readyUserList.IndexOf(cuser.LoginName) == -1) { if (string.IsNullOrEmpty(NamesNotapprov)) { NamesNotapprov = cuser.Name; } else { NamesNotapprov += string.Format(" ,{0}", cuser.Name); } } } if (!string.IsNullOrEmpty(NamesNotapprov)) { EmailControl emailControl = new EmailControl(); string bodyh = string.Format("User {0} has not acknowledged the policy: {1} by the due date", NamesNotapprov, pageItem.Title); this.ApproveMessageError += " Before sddn email suvervisor: " + localPolicySupervisor[0].User.Email; emailControl.SendEmialInternal(this.siteID, site.Zone, this.webID, localPolicySupervisor[0].User.Email, bodyh, "Pending policy"); } } } } else { //No send individual } } } } else { //This list doesn't exist this.ApproveMessageError = "The list doesn't exist"; } } } }); }