diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php
index 0fe69fa10ea..3818f459893 100644
--- a/htdocs/comm/action/card.php
+++ b/htdocs/comm/action/card.php
@@ -48,7 +48,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
// Load translation files required by the page
-$langs->loadLangs(array("companies", "other", "commercial", "bills", "orders", "agenda"));
+$langs->loadLangs(array("companies", "other", "commercial", "bills", "orders", "agenda", "mails"));
$action = GETPOST('action', 'aZ09');
$cancel = GETPOST('cancel', 'alpha');
@@ -393,31 +393,36 @@ if (empty($reshook) && $action == 'add')
$moreparam = '';
if ($user->id != $object->userownerid) $moreparam = "filtert=-1"; // We force to remove filter so created record is visible when going back to per user view.
- //Create eminder
+ //Create reminders
if ($addreminder == 'on'){
$actionCommReminder = new ActionCommReminder($db);
- $dateremind = dol_time_plus_duree($datep, -$offsetvalue, 'i');
+ $dateremind = dol_time_plus_duree($datep, -$offsetvalue, $offsetunit);
$actionCommReminder->dateremind = $dateremind;
$actionCommReminder->typeremind = $remindertype;
- $actionCommReminder->fk_user = $user;
$actionCommReminder->offsetunit = $offsetunit;
$actionCommReminder->offsetvalue = $offsetvalue;
$actionCommReminder->status = $actionCommReminder::STATUS_TODO;
$actionCommReminder->fk_actioncomm = $object->id;
if ($remindertype == 'email') $actionCommReminder->fk_email_template = $modelmail;
- $res = $actionCommReminder->create($user);
+ // the notification must be created for every user assigned to the event
+ foreach ($object->userassigned as $userassigned)
+ {
+ $actionCommReminder->fk_user = $userassigned['id'];
+ $res = $actionCommReminder->create($user);
- if ($res <= 0){
- // If error
- $error++;
- $langs->load("errors");
- $error = $langs->trans('ErrorReminderActionCommCreation').' '.$actionCommReminder->error;
- setEventMessages($error, $actionCommReminder->errors, 'errors');
- $action = 'create'; $donotclearsession = 1;
- }
+ if ($res <= 0){
+ // If error
+ $db->rollback();
+ $langs->load("errors");
+ $error = $langs->trans('ErrorReminderActionCommCreation');
+ setEventMessages($error, null, 'errors');
+ $action = 'create'; $donotclearsession = 1;
+ break;
+ }
+ }
}
if ($error) {
@@ -634,9 +639,51 @@ if (empty($reshook) && $action == 'update')
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);
+ $object->loadReminders();
+ if (!empty($object->reminders) && $object->datep > dol_now())
+ {
+ foreach ($object->reminders as $reminder)
+ {
+ $reminder->delete($user);
+ }
+ $object->reminders = array();
+ }
+
+ //Create reminders
+ if ($addreminder == 'on' && $object->datep > dol_now()){
+ $actionCommReminder = new ActionCommReminder($db);
+
+ $dateremind = dol_time_plus_duree($datep, -$offsetvalue, $offsetunit);
+
+ $actionCommReminder->dateremind = $dateremind;
+ $actionCommReminder->typeremind = $remindertype;
+ $actionCommReminder->offsetunit = $offsetunit;
+ $actionCommReminder->offsetvalue = $offsetvalue;
+ $actionCommReminder->status = $actionCommReminder::STATUS_TODO;
+ $actionCommReminder->fk_actioncomm = $object->id;
+ if ($remindertype == 'email') $actionCommReminder->fk_email_template = $modelmail;
+
+ // the notification must be created for every user assigned to the event
+ foreach ($object->userassigned as $userassigned)
+ {
+ $actionCommReminder->fk_user = $userassigned['id'];
+ $res = $actionCommReminder->create($user);
+
+ if ($res <= 0){
+ // If error
+ $langs->load("errors");
+ $error = $langs->trans('ErrorReminderActionCommCreation');
+ setEventMessages($error, null, 'errors');
+ $action = 'create'; $donotclearsession = 1;
+ break;
+ }
+ }
+ }
+
unset($_SESSION['assignedtouser']);
- $db->commit();
+ if (!$error) $db->commit();
+ else $db->rollback();
} else {
setEventMessages($object->error, $object->errors, 'errors');
$db->rollback();
@@ -1236,7 +1283,7 @@ if ($action == 'create')
}
});
- $("#selectremindertype").click(function(){
+ $("#selectremindertype").change(function(){
var selected_option = $("#selectremindertype option:selected").val();
if(selected_option == "email") {
$("#select_actioncommsendmodel_mail").closest("tr").show();
@@ -1664,41 +1711,82 @@ if ($id > 0)
{
$filtreuserid = $user->id;
if ($user->rights->agenda->allactions->read) $filtreuserid = 0;
- $object->loadReminders('', $filteruserid);
+ $object->loadReminders('', $filteruserid, false);
print '
';
- print '';
-
- print '| '.$langs->trans("Reminders").' | ';
-
if (count($object->reminders) > 0) {
- if (count($object->reminders) > 0) {
- $tmpuserstatic = new User($db);
+ $checked = 'checked';
+ $keys = array_keys($object->reminders);
+ $firstreminderId = array_shift($keys);
- foreach ($object->reminders as $actioncommreminderid => $actioncommreminder) {
- print $TRemindTypes[$actioncommreminder->typeremind];
- if ($actioncommreminder->fk_user > 0) {
- $tmpuserstatic->fetch($actioncommreminder->fk_user);
- print ' ('.$tmpuser->getNomUrl(0, '', 0, 0, 16).')';
- }
- print ' - '.$actioncommreminder->offsetvalue.' '.$TDurationTypes[$actioncommreminder->offsetunit];
- if ($actioncommreminder->status == $actioncommreminder::STATUS_TODO) {
- print ' - ';
- print $langs->trans("NotSent");
- print ' ';
- } elseif ($actioncommreminder->status == $actioncommreminder::STATUS_DONE) {
- print ' - ';
- print $langs->trans("Done");
- print ' ';
- }
- }
- }
+ $actionCommReminder = $object->reminders[$firstreminderId];
+
+ }
+ else
+ {
+ $checked = '';
+ $actionCommReminder = new ActionCommReminder($db);
+ $actionCommReminder->offsetvalue = 10;
+ $actionCommReminder->offsetunit = 'i';
+ $actionCommReminder->typeremind = 'email';
}
+ print ' |
| '.$langs->trans("AddReminder").' | |
';
+
+ print '';
+
+ print '
';
+
+ print "\n".''."\n";
}
dol_fiche_end();
@@ -1980,7 +2068,7 @@ if ($id > 0)
{
$filtreuserid = $user->id;
if ($user->rights->agenda->allactions->read) $filtreuserid = 0;
- $object->loadReminders('', $filteruserid);
+ $object->loadReminders('', $filteruserid, false);
print '
| '.$langs->trans("Reminders").' | ';
@@ -1991,7 +2079,7 @@ if ($id > 0)
print $TRemindTypes[$actioncommreminder->typeremind];
if ($actioncommreminder->fk_user > 0) {
$tmpuserstatic->fetch($actioncommreminder->fk_user);
- print ' ('.$tmpuser->getNomUrl(0, '', 0, 0, 16).')';
+ print ' ('.$tmpuserstatic->getNomUrl(0, '', 0, 0, 16).')';
}
print ' - '.$actioncommreminder->offsetvalue.' '.$TDurationTypes[$actioncommreminder->offsetunit];
if ($actioncommreminder->status == $actioncommreminder::STATUS_TODO) {
@@ -2003,6 +2091,7 @@ if ($id > 0)
print $langs->trans("Done");
print ' ';
}
+ print ' ';
}
}
diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php
index a5084bfac74..c6fd2183459 100644
--- a/htdocs/comm/action/class/actioncomm.class.php
+++ b/htdocs/comm/action/class/actioncomm.class.php
@@ -925,6 +925,18 @@ class ActionComm extends CommonObject
}
}
+ if (!$error)
+ {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
+ $sql .= " WHERE fk_actioncomm = ".$this->id;
+
+ $res = $this->db->query($sql);
+ if (!$res) {
+ $this->error = $this->db->lasterror();
+ $error++;
+ }
+ }
+
// Removed extrafields
if (!$error) {
$result = $this->deleteExtraFields();
@@ -1958,9 +1970,10 @@ class ActionComm extends CommonObject
*
* @param string $type Type of reminder 'browser' or 'email'
* @param int $fk_user Id of user
+ * @param bool $onlypast true = get only past reminder, false = get all reminders linked to this
* @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
*/
- public function loadReminders($type = '', $fk_user = 0)
+ public function loadReminders($type = '', $fk_user = 0, $onlypast = true)
{
global $conf, $langs, $user;
@@ -1971,7 +1984,10 @@ class ActionComm extends CommonObject
//Select all action comm reminders for event
$sql = "SELECT rowid as id, typeremind, dateremind, status, offsetvalue, offsetunit, fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
- $sql .= " WHERE fk_actioncomm = ".$this->id." AND dateremind <= '".$this->db->idate(dol_now())."'";
+ $sql .= " WHERE fk_actioncomm = ".$this->id;
+ if ($onlypast) {
+ $sql .= " AND dateremind <= '".$this->db->idate(dol_now())."'";
+ }
if ($type) {
$sql .= " AND typeremind ='".$this->db->escape($type)."'";
}
|