Skip to content

Commit

Permalink
More log into notify class
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Sep 4, 2014
1 parent 5aaba31 commit 32fd2e0
Showing 1 changed file with 102 additions and 90 deletions.
192 changes: 102 additions & 90 deletions htdocs/core/class/notify.class.php
Expand Up @@ -147,104 +147,116 @@ function send($action, $socid, $texte, $objet_type, $objet_id, $file="")
else $sql.= " AND a.code = '".$action."'"; // New usage
$sql .= " AND s.rowid = ".$socid;

dol_syslog("Notify::send", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
$i = 0;
while ($i < $num) // For each notification couple defined (third party/actioncode)

if ($num > 0)
{
$obj = $this->db->fetch_object($result);

$sendto = $obj->firstname . " " . $obj->lastname . " <".$obj->email.">";
$actiondefid = $obj->adid;

if (dol_strlen($sendto))
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$application=($conf->global->MAIN_APPLICATION_TITLE?$conf->global->MAIN_APPLICATION_TITLE:'Dolibarr ERP/CRM');

$subject = '['.$application.'] '.$langs->transnoentitiesnoconv("DolibarrNotification");

$message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n";
$message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
$message.= "\n";
$message.= $texte;
// Add link
$link='';
switch($objet_type)
{
case 'ficheinter':
$link='/fichinter/fiche.php?id='.$objet_id;
break;
case 'propal':
$link='/comm/propal.php?id='.$objet_id;
break;
case 'facture':
$link='/compta/facture.php?facid='.$objet_id;
break;
case 'order':
$link='/commande/fiche.php?id='.$objet_id;
break;
case 'order_supplier':
$link='/fourn/commande/fiche.php?id='.$objet_id;
break;
}
// Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
if ($link) $message.="\n".$urlwithroot.$link;

$filename = basename($file);

$mimefile=dol_mimetype($file);

$msgishtml=0;

$replyto = $conf->notification->email_from;

$mailfile = new CMailFile(
$subject,
$sendto,
$replyto,
$message,
array($file),
array($mimefile),
array($filename[count($filename)-1]),
'',
'',
0,
$msgishtml
);

if ($mailfile->sendfile())
{
$now=dol_now();
$sendto = htmlentities($sendto);

$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_contact, objet_type, objet_id, email)";
$sql.= " VALUES ('".$this->db->idate($now)."', ".$actiondefid.", ".$obj->cid.", '".$objet_type."', ".$objet_id.", '".$this->db->escape($obj->email)."')";
dol_syslog("Notify::send", LOG_DEBUG);
if (! $this->db->query($sql) )
{
dol_print_error($this->db);
}
}
else
{
$this->error=$mailfile->error;
//dol_syslog("Notify::send ".$this->error, LOG_ERR);
}
}
$i++;
$i = 0;
while ($i < $num) // For each notification couple defined (third party/actioncode)
{
$obj = $this->db->fetch_object($result);

$sendto = $obj->firstname . " " . $obj->lastname . " <".$obj->email.">";
$actiondefid = $obj->adid;

if (dol_strlen($obj->email))
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$application=($conf->global->MAIN_APPLICATION_TITLE?$conf->global->MAIN_APPLICATION_TITLE:'Dolibarr ERP/CRM');

$subject = '['.$application.'] '.$langs->transnoentitiesnoconv("DolibarrNotification");

$message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n";
$message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
$message.= "\n";
$message.= $texte;
// Add link
$link='';
switch($objet_type)
{
case 'ficheinter':
$link='/fichinter/fiche.php?id='.$objet_id;
break;
case 'propal':
$link='/comm/propal.php?id='.$objet_id;
break;
case 'facture':
$link='/compta/facture.php?facid='.$objet_id;
break;
case 'order':
$link='/commande/fiche.php?id='.$objet_id;
break;
case 'order_supplier':
$link='/fourn/commande/fiche.php?id='.$objet_id;
break;
}
// Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
if ($link) $message.="\n".$urlwithroot.$link;

$filename = basename($file);

$mimefile=dol_mimetype($file);

$msgishtml=0;

$replyto = $conf->notification->email_from;

$mailfile = new CMailFile(
$subject,
$sendto,
$replyto,
$message,
array($file),
array($mimefile),
array($filename[count($filename)-1]),
'',
'',
0,
$msgishtml
);

if ($mailfile->sendfile())
{
$now=dol_now();
$sendto = htmlentities($sendto);

$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_contact, objet_type, objet_id, email)";
$sql.= " VALUES ('".$this->db->idate($now)."', ".$actiondefid.", ".$obj->cid.", '".$objet_type."', ".$objet_id.", '".$this->db->escape($obj->email)."')";
dol_syslog("Notify::send", LOG_DEBUG);
if (! $this->db->query($sql) )
{
dol_print_error($this->db);
}
}
else
{
$this->error=$mailfile->error;
//dol_syslog("Notify::send ".$this->error, LOG_ERR);
}
}
else
{
dol_syslog("No notification sent for ".$sendto." because email is empty");
}
$i++;
}
return $i;
}
return $i;
else
{
dol_syslog("No notification sent, nothing into notification setup for the thirdparty socid = ".$socid);
return 0;
}
}
else
{
$this->error=$this->db->error();
{
$this->error=$this->db->lasterror();
return -1;
}

Expand Down

0 comments on commit 32fd2e0

Please sign in to comment.