mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 09:38:23 +01:00
Function sendEmailsReminder()
This commit is contained in:
@@ -29,6 +29,10 @@
|
|||||||
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncommreminder.class.php';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1974,30 +1978,100 @@ class ActionComm extends CommonObject
|
|||||||
|
|
||||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
|
||||||
$this->db->begin();
|
//Select all action comm reminder
|
||||||
|
$sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE typeremind = 'email'";
|
||||||
// TODO Scan events of type 'email' into table llx_actioncomm_reminder with status todo, send email, then set status to done
|
|
||||||
|
|
||||||
$sql = "SELECT rowid as id, fk_email_template FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE typeremind = 'email'";
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
|
|
||||||
if($resql){
|
if($resql){
|
||||||
while($obj = $this->db->fetch_object($resql)){
|
while($obj = $this->db->fetch_object($resql)){
|
||||||
$formmail = new FormMail($this->db);
|
|
||||||
|
|
||||||
$arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($obj->fk_email_template)) ? $obj->fk_email_template : 0, 1, '(SendingReminderActionComm)');
|
$actionCommReminder = new ActionCommReminder($this->db);
|
||||||
|
$res = $actionCommReminder->fetch($obj->id);
|
||||||
|
if($res < 0) {
|
||||||
|
$error++;
|
||||||
|
$this->errors[] = "Failed to load invoice ActionComm Reminder";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$error)
|
||||||
|
{
|
||||||
|
//Select email template
|
||||||
|
$formmail = new FormMail($this->db);
|
||||||
|
$arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : 0, 1, '(SendingReminderActionComm)');
|
||||||
|
|
||||||
|
$res = $this->fetch($actionCommReminder->fk_actioncomm);
|
||||||
|
|
||||||
|
if ($res > 0)
|
||||||
|
{
|
||||||
|
// PREPARE EMAIL
|
||||||
|
|
||||||
|
// Make substitution in email content
|
||||||
|
$substitutionarray = getCommonSubstitutionArray($langs, 0, '', $this);
|
||||||
|
|
||||||
|
complete_substitutions_array($substitutionarray, $langs, $this);
|
||||||
|
|
||||||
|
// Content
|
||||||
|
$sendContent = make_substitutions($langs->trans($arraymessage->content), $substitutionarray);
|
||||||
|
|
||||||
|
//Topic
|
||||||
|
$sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : $langs->trans('EventReminder');
|
||||||
|
|
||||||
|
// Recipient
|
||||||
|
$recipient = new User($this->db);
|
||||||
|
$res = $recipient->fetch($actionCommReminder->fk_user);
|
||||||
|
if ($res > 0 && !empty($recipient->email)) $to = $recipient->email;
|
||||||
|
else {
|
||||||
|
$this->errors[] = "Failed to load recipient";
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sender
|
||||||
|
$from = $conf->global->MAIN_MAIL_EMAIL_FROM;
|
||||||
|
|
||||||
|
// Errors Recipient
|
||||||
|
$errors_to = $conf->global->MAIN_MAIL_ERRORS_TO;
|
||||||
|
|
||||||
|
// Mail Creation
|
||||||
|
$cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', '', '', '', '');
|
||||||
|
|
||||||
|
// Sending Mail
|
||||||
|
if ($cMailFile->sendfile())
|
||||||
|
{
|
||||||
|
$actionCommReminder->status=$actionCommReminder::STATUS_DONE;
|
||||||
|
$res = $actionCommReminder->update($user);
|
||||||
|
if($res<0) {
|
||||||
|
$this->errors[] = "Failed to update status of ActionComm Reminder";
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
else $nbMailSend++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$errorsMsg[] = $cMailFile->error.' : '.$to;
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!$error)
|
||||||
|
{
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
// Delete also very old past events (we do not keep more than 1 month record in past)
|
// Delete also very old past events (we do not keep more than 1 month record in past)
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE dateremind < '".$this->db->jdate($now - (3600 * 24 * 32))."'";
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_reminder WHERE dateremind < '".$this->db->jdate($now - (3600 * 24 * 32))."'";
|
||||||
$this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
|
|
||||||
$this->db->commit();
|
if($resql) $this->db->commit();
|
||||||
|
else $this->db->rollback();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return $error;
|
return $error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6244,6 +6244,13 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null,
|
|||||||
if (is_object($object) && $object->element == 'commande') $substitutionarray['__URL_ORDER__'] = DOL_MAIN_URL_ROOT."/commande/card.php?id=".$object->id;
|
if (is_object($object) && $object->element == 'commande') $substitutionarray['__URL_ORDER__'] = DOL_MAIN_URL_ROOT."/commande/card.php?id=".$object->id;
|
||||||
if (is_object($object) && $object->element == 'facture') $substitutionarray['__URL_INVOICE__'] = DOL_MAIN_URL_ROOT."/compta/facture/card.php?id=".$object->id;
|
if (is_object($object) && $object->element == 'facture') $substitutionarray['__URL_INVOICE__'] = DOL_MAIN_URL_ROOT."/compta/facture/card.php?id=".$object->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_object($object) && $object->element == 'action')
|
||||||
|
{
|
||||||
|
$substitutionarray['__EVENT_LABEL__'] = $object->label;
|
||||||
|
$substitutionarray['__EVENT_DATE__'] = dol_print_date($object->datep, '%A %d %b %Y');
|
||||||
|
$substitutionarray['__EVENT_TIME__'] = dol_print_date($object->datep, '%H:%M:%S');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($exclude) || !in_array('objectamount', $exclude))
|
if (empty($exclude) || !in_array('objectamount', $exclude))
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ PredefinedMailContentSendShipping=__(Hello)__\n\nPlease find shipping __REF__ at
|
|||||||
PredefinedMailContentSendFichInter=__(Hello)__\n\nPlease find intervention __REF__ attached\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__
|
PredefinedMailContentSendFichInter=__(Hello)__\n\nPlease find intervention __REF__ attached\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__
|
||||||
PredefinedMailContentLink=You can click on the link below to make your payment if it is not already done.\n\n%s\n\n
|
PredefinedMailContentLink=You can click on the link below to make your payment if it is not already done.\n\n%s\n\n
|
||||||
PredefinedMailContentGeneric=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__
|
PredefinedMailContentGeneric=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__
|
||||||
PredefinedMailContentSendActionComm=__(Hello)__\n\nEvent reminder "__EVENT_LABEL__" on __EVENT_DATE__ at __EVENT_TIME__\n__(Sincerely)__\n\n__USER_SIGNATURE__
|
PredefinedMailContentSendActionComm=Event reminder "__EVENT_LABEL__" on __EVENT_DATE__ at __EVENT_TIME__<br><br>This is an automatic message, please do not reply.
|
||||||
DemoDesc=Dolibarr is a compact ERP/CRM supporting several business modules. A demo showcasing all modules makes no sense as this scenario never occurs (several hundred available). So, several demo profiles are available.
|
DemoDesc=Dolibarr is a compact ERP/CRM supporting several business modules. A demo showcasing all modules makes no sense as this scenario never occurs (several hundred available). So, several demo profiles are available.
|
||||||
ChooseYourDemoProfil=Choose the demo profile that best suits your needs...
|
ChooseYourDemoProfil=Choose the demo profile that best suits your needs...
|
||||||
ChooseYourDemoProfilMore=...or build your own profile<br>(manual module selection)
|
ChooseYourDemoProfilMore=...or build your own profile<br>(manual module selection)
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ PredefinedMailContentThirdparty=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNA
|
|||||||
PredefinedMailContentContact=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__
|
PredefinedMailContentContact=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__
|
||||||
PredefinedMailContentUser=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__
|
PredefinedMailContentUser=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__
|
||||||
PredefinedMailContentLink=Vous pouvez cliquer sur le lien ci-dessous pour effectuer votre paiement si ce n'est déjà fait.\n\n%s\n\n
|
PredefinedMailContentLink=Vous pouvez cliquer sur le lien ci-dessous pour effectuer votre paiement si ce n'est déjà fait.\n\n%s\n\n
|
||||||
PredefinedMailContentSendActionComm=__(Hello)__\n\nRappel événement "__EVENT_LABEL__" le __EVENT_DATE__ à __EVENT_TIME__\n__(Sincerely)__\n\n__USER_SIGNATURE__
|
PredefinedMailContentSendActionComm=Rappel événement "__EVENT_LABEL__" le __EVENT_DATE__ à __EVENT_TIME__<br><br>Ceci est un message automatique, merci de ne pas répondre.
|
||||||
DemoDesc=Dolibarr est un logiciel de gestion proposant plusieurs modules métiers. Une démonstration qui inclut tous ces modules n'a pas de sens car ce cas n'existe jamais (plusieurs centaines de modules disponibles). Aussi, quelques profils type de démo sont disponibles.
|
DemoDesc=Dolibarr est un logiciel de gestion proposant plusieurs modules métiers. Une démonstration qui inclut tous ces modules n'a pas de sens car ce cas n'existe jamais (plusieurs centaines de modules disponibles). Aussi, quelques profils type de démo sont disponibles.
|
||||||
ChooseYourDemoProfil=Veuillez choisir le profil de démonstration qui correspond le mieux à votre activité…
|
ChooseYourDemoProfil=Veuillez choisir le profil de démonstration qui correspond le mieux à votre activité…
|
||||||
ChooseYourDemoProfilMore=...ou construisez votre propre profil<br>(sélection manuelle des modules)
|
ChooseYourDemoProfilMore=...ou construisez votre propre profil<br>(sélection manuelle des modules)
|
||||||
|
|||||||
Reference in New Issue
Block a user