| using System; |
| using System.Web.UI.WebControls; |
| using Telerik.Workflow; |
| using System.Collections.Generic; |
| using Telerik.Workflow.WebControls; |
| using Telerik.Cms.Engine; |
| using Telerik.News; |
| using Telerik.News.WebControls.Admin; |
| using System.Net.Mail; |
| |
| public partial class Sitefinity_Admin_ControlTemplates_News_ControlPanelEdit : System.Web.UI.UserControl |
| { |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| workflowMenu.Command += new CommandEventHandler(workflowMenu_Command); |
| } |
| |
| void workflowMenu_Command(object sender, CommandEventArgs e) |
| { |
| WorkflowInstance workflow = ((WorkflowMenu)sender).GetWorkflow(); |
| if (workflow != null) |
| { |
| List<EventActivity> commands = new List<EventActivity>(); |
| this.LoadCommands(commands, workflow.Activity.Activities); |
| int idx = int.Parse((string)e.CommandArgument); |
| |
| // The workflow events you could handle are: SendForApproval, Approve, Decline, Publish |
| if ((commands.Count > idx) && (commands[idx].CommandName.Equals("SendForApproval"))) |
| { |
| // Getting currently modified content and format the message |
| string providerName = ((ControlPanel)this.Parent.Parent).ProviderName; |
| NewsManager manager = new NewsManager(providerName); |
| IContent content = manager.Content.GetCurrentState(this.contentView.ContentID); |
| string message = String.Format("'{0}' news item has been sent for approval\n\nhttp://{2}{3}/Sitefinity/Admin/Modules.aspx?module=News&Id={1}&provider={4}", content.GetMetaData("Title"), content.ID, Request.Url.Host, Request.ApplicationPath.Length == 1 ? null : Request.ApplicationPath, providerName); |
| |
| MailMessage mailMsg = new MailMessage(); |
| |
| // From |
| MailAddress mailAddress = new MailAddress("cms-approval@yourcompany.com"); |
| mailMsg.From = mailAddress; |
| |
| // Subject and Body |
| mailMsg.Subject = "News item pending approval"; |
| mailMsg.Body = message; |
| |
| // To |
| string approversRole = "Approver"; |
| string[] usernames = Telerik.Security.UserManager.Default.GetUsersInRole(approversRole); |
| foreach (string username in usernames) |
| { |
| System.Web.Security.MembershipUser user = Telerik.Security.UserManager.Default.GetUser(username); |
| mailMsg.To.Add(user.Email); |
| } |
| |
| // Init SmtpClient and send |
| SmtpClient smtpClient = new SmtpClient(); |
| smtpClient.Send(mailMsg); |
| } |
| } |
| } |
| |
| private void LoadCommands(List<EventActivity> commands, IList<Activity> activities) |
| { |
| foreach (Activity act in activities) |
| { |
| if (act is EventActivity) |
| commands.Add((EventActivity)act); |
| this.LoadCommands(commands, act.Activities); |
| } |
| } |
| } |
| |