Wow the spy plugin is fantastic looking, I'm going to grab it and try it out!
Thanks!
*Update*
This is fantastic! The email sent out doesn't quite formate correct for gmail, but its way better then the emails that we were getting before!
Also I was getting the error:
"Assigning the return value of new by reference is deprecated in" then a line number. I though I'd give the info on how to fix this issue.
In PHP5 the & in frount of new is no longer needed so for each line of error go though and find the &new and remove the "&"
Update #2
This add-on is the best!
I changed the code a bit so it works with events & gmail;
#update 3
I added isset($object->diff['dt']) to fix error for changing subscribers & invited ppl!
Code: for spy_hook
<?php
Hook::register("spy");
function spy_before_object_save($object, $ignored){
include_once 'Text/Diff.php';
include_once 'Text/Diff/Renderer.php';
require_once 'Text/Diff/Renderer/inline.php';
$cssDeleted ='<span style="background-color:#ffdddd; text-decoration: line-through;">';
$cssAdded ='<span style="background-color:#ddffdd;">';
$r_inline = new Text_Diff_Renderer_inline(
array(
'leading_context_lines' => 1,
'trailing_context_lines' => 1,
'ins_prefix' => $cssAdded,
'ins_suffix' => '</span>',
'del_prefix' => $cssDeleted,
'del_suffix' => '</span>'
)
);
if($object instanceof ProjectMessage || $object instanceof Comment || $object instanceof ProjectTask || $object instanceof Contact || $object instanceof ProjectEvent){
if(!$object->isNew() && $object->isModified()){
$code = 'return ' . $object->getObjectManagerName() . '::findById(' . $object->getId() . ', true);';
$original = eval($code);
foreach($object->getColumns() as $column){
if($object->isColumnModified($column)){
switch($object->getColumnType($column)){
case 'DATETIME':
if(in_array($column, array('start_date', 'due_date', 'start'))){
if($original->getColumnValue($column) instanceof DateTimeValue && $object->getColumnValue($column) instanceof DateTimeValue){
$time = DateTimeValueLib::get_time_difference($original->getColumnValue($column)->getTimestamp(), $object->getColumnValue($column)->getTimestamp());
$value = $time['days'] ? $object->getColumnValue($column)->format('d.m.y') . user_config_option('date format') . ' / <span class="' . ($time['days'] > 0 ? 'added">+' : 'deleted">') . $time['days'] . ' ' . lang('days') . '</span>' : false;
}elseif($original->getColumnValue($column) instanceof DateTimeValue){
$value = $cssDeleted . $original->getColumnValue($column)->format('d.m.y') . '</span>';
}elseif($object->getColumnValue($column) instanceof DateTimeValue){
$value = $cssAdded . $object->getColumnValue($column)->format('d.m.y') . '</span>';
}
}else{
$value = false;
}
break;
default:
switch($column){
case 'time_estimate':
$old_value = DateTimeValue::FormatTimeDiff(new DateTimeValue(0), new DateTimeValue($original->getTimeEstimate() * 60), 'hm', 60);
$new_value = DateTimeValue::FormatTimeDiff(new DateTimeValue(0), new DateTimeValue($object->getTimeEstimate() * 60), 'hm', 60);
break;
case 'completed_by_id':
case 'assigned_by_user_id':
case 'assigned_to_user_id':
$old_value = ($original->getAssignedTo() instanceof User) ? $original->getAssignedTo()->getObjectName() : '';
$new_value = ($object->getAssignedTo() instanceof User) ? $object->getAssignedTo()->getObjectName() : '';
break;
case 'priority':
$old_value = prepare_priority($original->getPriority());
$new_value = prepare_priority($object->getPriority());
break;
default:
$old_value = $original->getColumnValue($column);
$new_value = $object->getColumnValue($column);
break;
}
$diff = new Text_Diff(
'auto',
array(
explode("\n", $old_value),
explode("\n", $new_value)
)
);
$value = nl2br($r_inline->render($diff));
}
if($value){
$object->diff['dt'][$column] = array(
'label' => 'field ' . $object->getObjectManagerName() . ' ' . $column,
'value' => $value
);
}
}
}
}
}
if($object instanceof Comment && !$object->isNew() && $object->isModified()){
$parent = get_object_by_manager_and_id($object->getRelObjectId(), $object->getRelObjectManager());
Notifier::objectNotification($object, $parent->getSubscribers(), logged_user(), 'modified');
}
}
function prepare_priority($p){
//get this method from /application/views/task/view_list.php =(
$priority = '';
if ($p >= ProjectTasks::PRIORITY_URGENT) {
$priority = lang('urgent priority');
}else if ($p >= ProjectTasks::PRIORITY_HIGH) {
$priority = lang('high priority');
} else if ($p <= ProjectTasks::PRIORITY_LOW) {
$priority = lang('low priority');
}else{
$priority = lang('normal priority');
}
return $priority;
}
?>
Code for general:
<div style="font-family: Verdana, Arial, sans-serif; font-size: 12px;">
<a href="<?php echo $object->getViewUrl() ?>" target="_blank" style="font-size: 18px;"><?php echo $description ?></a><br><br>
<?php foreach ($properties as $k => $p) { ?>
<span style="font-family: Verdana, Arial, sans-serif; font-size: 12px;"><?php echo lang($k) ?>: <?php echo $p ?></span><br><br>
<?php } ?>
<?php if (isset($links) && is_array($links)) {
foreach ($links as $link) {
?><span style="font-family: Verdana, Arial, sans-serif; font-size: 12px;"><?php
if (isset($link['img']))
echo '<img src="'.$link['img'].'"/>';
echo '<a href="'.$link['url'].'" target="_blank">'.$link['text'].'</a>';
?></span><br><?php
}
}
?>
<?php if(isset($object->diff['dt'])){
foreach($object->diff['dt'] as $column => $value){
print '<p><b>' . lang($value['label']) . '</b>: ' . $value['value'] . '</p>';
}
} ?>
<br><br>
<?php if (isset($second_properties) && is_array($second_properties)){
foreach ($second_properties as $k => $p) { ?>
<span style="font-family: Verdana, Arial, sans-serif; font-size: 12px;"><?php echo lang($k) ?>: <?php echo $p ?></span><br><br>
<?php } ?>
<?php } ?>
<div style="color: #818283; font-style: italic; border-top: 2px solid #818283; padding-top: 2px; font-family: Verdana, Arial, sans-serif; font-size: 12px;">
<?php echo lang('system notification email'); ?><br>
<a href="<?php echo ROOT_URL; ?>" target="_blank" style="font-family: Verdana, Arial, sans-serif; font-size: 12px;"><?php echo ROOT_URL; ?></a>
</div>
</div>
Thanks again!