Yes, we did it as logical hook
you can find resources googling
we are using a simple function for using the email module of sugar (I've attached it)
then a function called by logical hook after save that check the name of the new assigned_user with the old one: if they differ we send the mail
PHP Code:
<?php
require_once('modules/Users/User.php');
require_once 'custom/include/sendSugarPHPMail.php';
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class send_notification{
var $debugTI=FALSE;
function send_notification(&$bean, $event, $arguments){
global $current_user;
if ($this->debugTI) {
foreach ($_REQUEST as $key => $value) {
error_log('request: '.$key .' ' .$value);
}
foreach ($_SERVER as $key => $value) {
error_log('request: '.$key .' ' .$value);
}
}
$GLOBALS['log']->info("start send task notification");
if ($this->debugTI) {
error_log("Dentro");
error_log("assigned:" . $bean->fetched_row['assigned_user_id']);
error_log("assigned nuovo:" . $bean->assigned_user_id);
error_log("if" . ((!empty($bean->fetched_row['assigned_user_id']) &&
!empty($bean->assigned_user_id)) &&
($bean->fetched_row['assigned_user_id'] != $bean->assigned_user_id)));
}
if ((!empty($bean->fetched_row['assigned_user_id']) &&
!empty($bean->assigned_user_id)) &&
($bean->fetched_row['assigned_user_id'] !=$bean->assigned_user_id)){
$new_user= new User();
if ($this->debugTI) {
$user_met=get_class_methods($new_user);
foreach ($user_met as $value) {
error_log($value);
}
}
$new_user->retrieve($bean->assigned_user_id);
$subject = "Progetto: {$bean->project_name} - Task: {$bean->name}";
$body = "{$current_user->name} ha assegnato il task a: {$bean->assigned_user_name}\n";
$body .= 'Description: ' . (empty($bean->description)? ' n/a ' : $bean->description) . "\n";
//$body .= '<a href=\''.$_SERVER['HTTP_REFERER'].'?module='.$_REQUEST['module'].'&action=DetailView&record='.$bean->fetched_row['id'].'\'> '.$_SERVER['HTTP_REFERER'].'?module='.$_REQUEST['module'].'&action=DetailView&record='.$bean->fetched_row['id'].'</a>';
$body .= '<'.$_SERVER['HTTP_REFERER'].'?module='.$_REQUEST['module'].'&action=DetailView&record='.$bean->fetched_row['id'].'>';
$email=$new_user->getUsersNameAndEmail();
if ($this->debugTI) {
foreach ($email as $key => $value) {
error_log('mail'.$key .' ' .$value);
}
}
$to[$email['name']] = $email['email'];
$GLOBALS['log']->info($new_user->first_name. " send task notification");
if (!sendSugarPHPMail($to, $subject, $body)){
$GLOBALS['log']->info("Could not send project task notification: " . $mail->ErrorInfo);
}
}
}
public function getEmail($obj) {
$info = User::getEmailInfo($obj->id);
return $info['email'];
}
}
?>
Bookmarks