diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php
index 6a909eddd32..fd41a9eadf4 100644
--- a/htdocs/comm/action/class/actioncomm.class.php
+++ b/htdocs/comm/action/class/actioncomm.class.php
@@ -28,6 +28,12 @@
*/
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/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';
+
+
+
/**
@@ -1954,7 +1960,7 @@ class ActionComm extends CommonObject
*/
public function sendEmailsReminder()
{
- global $conf, $langs;
+ global $conf, $langs, $user;
$error = 0;
$this->output = '';
@@ -1977,17 +1983,118 @@ class ActionComm extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG);
- $this->db->begin();
+ $this->db->begin();
- // TODO Scan events of type 'email' into table llx_actioncomm_reminder with status todo, send email, then set status to done
+ //Select all action comm reminder
+ $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
+ $sql .= " WHERE typeremind = 'email' AND status = 0";
+ $sql .= " AND dateremind <= '".$this->db->idate(dol_now())."'";
+ $sql .= $this->db->order("dateremind", "ASC");
+ $resql = $this->db->query($sql);
- // 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))."'";
- $this->db->query($sql);
+ if ($resql) {
+ $formmail = new FormMail($this->db);
+ $actionCommReminder = new ActionCommReminder($this->db);
- $this->db->commit();
+ while ($obj = $this->db->fetch_object($resql)){
+ $res = $actionCommReminder->fetch($obj->id);
+ if ($res < 0) {
+ $error++;
+ $errorsMsg[] = "Failed to load invoice ActionComm Reminder";
+ }
+
+ if (!$error)
+ {
+ //Select email template
+ $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1);
+
+ // Load event
+ $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 : html_entity_decode($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 {
+ $errorsMsg[] = "Failed to load recipient";
+ $error++;
+ }
+
+ // Sender
+ $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
+ if (empty($from)) {
+ $errorsMsg[] = "Failed to load recipient";
+ $error++;
+ }
+
+ // 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)
+ {
+ $errorsMsg[] = "Failed to update status of ActionComm Reminder";
+ $error++;
+ }
+ else $nbMailSend++;
+ }
+ else {
+ $errorsMsg[] = $cMailFile->error.' : '.$to;
+ $error++;
+ }
+ }
+ else {
+ $error++;
+ }
+ }
+ }
+ } else {
+ $error++;
+ }
+
+ if (!$error)
+ {
+ // 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";
+ $sql .= " WHERE dateremind < '".$this->db->idate($now - (3600 * 24 * 32))."'";
+ $resql = $this->db->query($sql);
+
+ if (!$resql) {
+ $errorsMsg[] = 'Failed to delete old reminders';
+ $error ++;
+ }
+ }
+
+ if (!$error) {
+ $this->db->commit();
+ return 0;
+ }
+ else {
+ $this->db->rollback();
+ return (!empty($errorsMsg)) ? end($errorsMsg) : $error;
+ }
- return $error;
}
/**
diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php
index aeec45555b2..1fef9012858 100644
--- a/htdocs/core/class/html.formmail.class.php
+++ b/htdocs/core/class/html.formmail.class.php
@@ -1253,6 +1253,8 @@ class FormMail extends Form
$defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping");
} elseif ($type_template == 'fichinter_send') {
$defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter");
+ } elseif ($type_template == 'actioncomm_send') {
+ $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm");
} elseif (!empty($type_template)) {
$defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric");
}
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 8631e0e5663..74916ec62e1 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -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 == '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))
diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang
index bbfb143cee8..7b716d8050d 100644
--- a/htdocs/langs/en_US/agenda.lang
+++ b/htdocs/langs/en_US/agenda.lang
@@ -165,4 +165,5 @@ TimeType=Duration type
ReminderType=Callback type
AddReminder=Create an automatic reminder notification for this event
ErrorReminderActionCommCreation=Error creating the reminder notification for this event
-BrowserPush=Browser Notification
\ No newline at end of file
+BrowserPush=Browser Notification
+EventReminder=Event Reminder
\ No newline at end of file
diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang
index 5ef946ddf67..2f126b11fdf 100644
--- a/htdocs/langs/en_US/members.lang
+++ b/htdocs/langs/en_US/members.lang
@@ -117,6 +117,7 @@ SendingEmailOnMemberValidation=Sending email on new member validation
SendingEmailOnNewSubscription=Sending email on new subscription
SendingReminderForExpiredSubscription=Sending reminder for expired subscriptions
SendingEmailOnCancelation=Sending email on cancelation
+SendingReminderActionComm=Sending reminder for agenda event
# Topic of email templates
YourMembershipRequestWasReceived=Your membership was received.
YourMembershipWasValidated=Your membership was validated
diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang
index 54c0572d453..4903bea90da 100644
--- a/htdocs/langs/en_US/other.lang
+++ b/htdocs/langs/en_US/other.lang
@@ -99,6 +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__
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__
+PredefinedMailContentSendActionComm=Event reminder "__EVENT_LABEL__" on __EVENT_DATE__ at __EVENT_TIME__
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.
ChooseYourDemoProfil=Choose the demo profile that best suits your needs...
ChooseYourDemoProfilMore=...or build your own profile
(manual module selection)
diff --git a/htdocs/langs/fr_FR/agenda.lang b/htdocs/langs/fr_FR/agenda.lang
index 76dbaf03bd4..3b7a9f0e8c0 100644
--- a/htdocs/langs/fr_FR/agenda.lang
+++ b/htdocs/langs/fr_FR/agenda.lang
@@ -160,9 +160,10 @@ DateStartPlusOne=Date de début + 1 heure
SetAllEventsToTodo=Réglez tous les événements à "A faire"
SetAllEventsToInProgress=Définir tous les événements à "En cours"
SetAllEventsToFinished=Définir tous les événements sur "Terminés"
-ReminderTime=Reminder period before the event
-TimeType=Duration type
-ReminderType=Callback type
-AddReminder=Create an automatic reminder notification for this event
-ErrorReminderActionCommCreation=Error creating the reminder notification for this event
-BrowserPush=Browser Notification
+ReminderTime=Délai de rappel avant l'événement
+TimeType=Type de durée
+ReminderType=Type de rappel
+AddReminder=Créer une notification de rappel automatique pour cet évènement
+ErrorReminderActionCommCreation=Erreur lors de la création de la notification de rappel de cet événement
+BrowserPush=Notification navigateur
+EventReminder=Rappel événement
diff --git a/htdocs/langs/fr_FR/other.lang b/htdocs/langs/fr_FR/other.lang
index 546cf07600d..0a5abbfbf3a 100644
--- a/htdocs/langs/fr_FR/other.lang
+++ b/htdocs/langs/fr_FR/other.lang
@@ -97,8 +97,12 @@ PredefinedMailContentSendSupplierOrder=__(Hello)__\n\nVeuillez trouver, ci-joint
PredefinedMailContentSendSupplierInvoice=__(Hello)__\n\nVeuillez trouver, ci-joint, la facture __REF__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__
PredefinedMailContentSendShipping=__(Hello)__\n\nVeuillez trouver, ci-joint, le bon d'expédition __REF__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__
PredefinedMailContentSendFichInter=__(Hello)__\n\nVeuillez trouver, ci-joint, la fiche intervention __REF__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__
+PredefinedMailContentThirdparty=__(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__
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
PredefinedMailContentGeneric=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__
+PredefinedMailContentSendActionComm=Rappel événement "__EVENT_LABEL__" le __EVENT_DATE__ à __EVENT_TIME__
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.
ChooseYourDemoProfil=Veuillez choisir le profil de démonstration qui correspond le mieux à votre activité…
ChooseYourDemoProfilMore=...ou construisez votre propre profil
(sélection manuelle des modules)