using System;
using System.Data;
using System.Net.Mail;
using System.Runtime.CompilerServices;
using System.Text;
using System.Web;
using System.Collections.Generic;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.property;
using umbraco.cms.businesslogic.web;
using umbraco.interfaces;
using umbraco.DataLayer;
using umbraco.IO;
using System.Collections;
namespace umbraco.cms.businesslogic.workflow
{
///
/// Notifications are a part of the umbraco workflow.
/// A notification is created every time an action on a node occurs and a umbraco user has subscribed to this specific action on this specific node.
/// Notifications generates an email, which is send to the subscribing users.
///
public class Notification
{
public int NodeId { get; private set; }
public int UserId { get; private set; }
public char ActionId { get; private set; }
///
/// Private constructor as this object should not be allowed to be created currently
///
private Notification() { }
///
/// Gets the SQL helper.
///
/// The SQL helper.
protected static ISqlHelper SqlHelper
{
get { return Application.SqlHelper; }
}
///
/// Sends the notifications for the specified user regarding the specified node and action.
///
/// The node.
/// The user.
/// The action.
public static void GetNotifications(CMSNode Node, User user, IAction Action)
{
User[] allUsers = User.getAll();
foreach (User u in allUsers)
{
try
{
if (!u.Disabled && u.GetNotifications(Node.Path).IndexOf(Action.Letter.ToString()) > -1)
{
Log.Add(LogTypes.Notify, User.GetUser(0), Node.Id,
"Notification about " + ui.Text(Action.Alias, u) + " sent to " + u.Name + " (" + u.Email +
")");
sendNotification(user, u, (Document) Node, Action);
}
}
catch (Exception notifyExp)
{
Log.Add(LogTypes.Error, u, Node.Id, "Error in notification: " + notifyExp);
}
}
}
///TODO: Include update with html mail notification and document contents
private static void sendNotification(User performingUser, User mailingUser, Document documentObject,
IAction Action)
{
// retrieve previous version of the document
DocumentVersionList[] versions = documentObject.GetVersions();
int versionCount = (versions.Length > 1) ? (versions.Length - 2) : (versions.Length - 1);
Document oldDoc = new Document(documentObject.Id, versions[versionCount].Version);
// build summary
StringBuilder summary = new StringBuilder();
var props = documentObject.getProperties;
foreach (Property p in props)
{
// check if something was changed and display the changes otherwise display the fields
Property oldProperty = oldDoc.getProperty(p.PropertyType.Alias);
string oldText = oldProperty.Value.ToString();
string newText = p.Value.ToString();
// replace html with char equivalent
ReplaceHTMLSymbols(ref oldText);
ReplaceHTMLSymbols(ref newText);
// make sure to only highlight changes done using TinyMCE editor... other changes will be displayed using default summary
///TODO PPH: Had to change this, as a reference to the editorcontrols is not allowed, so a string comparison is the only way, this should be a DIFF or something instead..
if (p.PropertyType.DataTypeDefinition.DataType.ToString() == "umbraco.editorControls.tinymce.TinyMCEDataType" &&
string.Compare( oldText, newText ) != 0)
{
summary.Append("
");
summary.Append("| Note: | ");
summary.Append(" Red for deleted characters Yellow for inserted characters | ");
summary.Append("
");
summary.Append("");
summary.Append("| New " + p.PropertyType.Name + " | ");
summary.Append("" + replaceLinks(CompareText(oldText, newText, true, false, "", string.Empty)) + " | ");
summary.Append("
");
summary.Append("");
summary.Append("| Old " + oldProperty.PropertyType.Name + " | ");
summary.Append("" + replaceLinks(CompareText(newText, oldText, true, false, "", string.Empty)) + " | ");
summary.Append("
");
}
else
{
summary.Append("");
summary.Append("| " + p.PropertyType.Name + " | ");
summary.Append("