From 732bb708269e68ec08099af015828db008be7858 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Thu, 24 Sep 2020 11:47:41 +0200 Subject: [PATCH 01/10] fix sql --- htdocs/install/mysql/migration/12.0.0-13.0.0.sql | 1 + htdocs/install/mysql/tables/llx_actioncomm_reminder.sql | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index 1f7740de467..8e3d0e1ee69 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -306,6 +306,7 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value ALTER TABLE llx_actioncomm_reminder ADD COLUMN entity integer NOT NULL DEFAULT 1; ALTER TABLE llx_actioncomm_reminder ADD COLUMN fk_actioncomm integer NOT NULL; ALTER TABLE llx_actioncomm_reminder ADD COLUMN fk_email_template integer; +ALTER TABLE llx_actioncomm_reminder CHANGE offsetunit offsetunit VARCHAR(10); ALTER TABLE llx_actioncomm_reminder DROP INDEX uk_actioncomm_reminder_unique; ALTER TABLE llx_actioncomm_reminder ADD UNIQUE uk_actioncomm_reminder_unique (fk_user, typeremind, offsetvalue, offsetunit, fk_actioncomm); diff --git a/htdocs/install/mysql/tables/llx_actioncomm_reminder.sql b/htdocs/install/mysql/tables/llx_actioncomm_reminder.sql index 78dd00d6ea5..ff992227d0d 100644 --- a/htdocs/install/mysql/tables/llx_actioncomm_reminder.sql +++ b/htdocs/install/mysql/tables/llx_actioncomm_reminder.sql @@ -21,7 +21,7 @@ CREATE TABLE llx_actioncomm_reminder( typeremind varchar(32) NOT NULL, fk_user integer NOT NULL, offsetvalue integer NOT NULL, - offsetunit varchar(1) NOT NULL, + offsetunit varchar(10) NOT NULL, status integer NOT NULL DEFAULT 0, entity integer NOT NULL DEFAULT 1, fk_actioncomm integer NOT NULL, From 101405b052a576a3b506934e3cd3eaf3f5862190 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Thu, 24 Sep 2020 12:31:28 +0200 Subject: [PATCH 02/10] fix notification creation => must create for every user linked to the event --- htdocs/comm/action/card.php | 31 +++++++++++-------- htdocs/comm/action/class/actioncomm.class.php | 8 +++-- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 0fe69fa10ea..be100a97656 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,7 +393,7 @@ 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 reminder if ($addreminder == 'on'){ $actionCommReminder = new ActionCommReminder($db); @@ -401,23 +401,28 @@ if (empty($reshook) && $action == 'add') $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) { @@ -1236,7 +1241,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(); diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index a5084bfac74..113f860962f 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1958,9 +1958,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 +1972,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)."'"; } From e6eff6511e03149d7ce2f96deed2686c6837b09d Mon Sep 17 00:00:00 2001 From: atm-greg Date: Thu, 24 Sep 2020 15:20:30 +0200 Subject: [PATCH 03/10] fix reminder offsetunit and display problems --- htdocs/comm/action/card.php | 8 +++++--- htdocs/install/mysql/migration/12.0.0-13.0.0.sql | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index be100a97656..5179b4c0ab1 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -397,7 +397,7 @@ if (empty($reshook) && $action == 'add') 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; @@ -1697,6 +1697,7 @@ if ($id > 0) print $langs->trans("Done"); print ' '; } + print '
'; } } } @@ -1985,7 +1986,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").''; @@ -1996,7 +1997,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) { @@ -2008,6 +2009,7 @@ if ($id > 0) print $langs->trans("Done"); print ' '; } + print '
'; } } diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index 8e3d0e1ee69..1f7740de467 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -306,7 +306,6 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value ALTER TABLE llx_actioncomm_reminder ADD COLUMN entity integer NOT NULL DEFAULT 1; ALTER TABLE llx_actioncomm_reminder ADD COLUMN fk_actioncomm integer NOT NULL; ALTER TABLE llx_actioncomm_reminder ADD COLUMN fk_email_template integer; -ALTER TABLE llx_actioncomm_reminder CHANGE offsetunit offsetunit VARCHAR(10); ALTER TABLE llx_actioncomm_reminder DROP INDEX uk_actioncomm_reminder_unique; ALTER TABLE llx_actioncomm_reminder ADD UNIQUE uk_actioncomm_reminder_unique (fk_user, typeremind, offsetvalue, offsetunit, fk_actioncomm); From b269af5bf602b040a34742852d46ee472d0ec60f Mon Sep 17 00:00:00 2001 From: atm-greg Date: Thu, 24 Sep 2020 15:26:35 +0200 Subject: [PATCH 04/10] delete reminders on ActionComm::delete --- htdocs/comm/action/class/actioncomm.class.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 113f860962f..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(); From 6aad3b47f5cbd798c3139010d1c84e627f686b3a Mon Sep 17 00:00:00 2001 From: atm-greg Date: Thu, 24 Sep 2020 15:28:41 +0200 Subject: [PATCH 05/10] remove fields size modification --- htdocs/install/mysql/tables/llx_actioncomm_reminder.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/tables/llx_actioncomm_reminder.sql b/htdocs/install/mysql/tables/llx_actioncomm_reminder.sql index ff992227d0d..78dd00d6ea5 100644 --- a/htdocs/install/mysql/tables/llx_actioncomm_reminder.sql +++ b/htdocs/install/mysql/tables/llx_actioncomm_reminder.sql @@ -21,7 +21,7 @@ CREATE TABLE llx_actioncomm_reminder( typeremind varchar(32) NOT NULL, fk_user integer NOT NULL, offsetvalue integer NOT NULL, - offsetunit varchar(10) NOT NULL, + offsetunit varchar(1) NOT NULL, status integer NOT NULL DEFAULT 0, entity integer NOT NULL DEFAULT 1, fk_actioncomm integer NOT NULL, From 5244c05abbee09cadf213e74bbfb1151028c389d Mon Sep 17 00:00:00 2001 From: atm-greg Date: Thu, 24 Sep 2020 15:30:29 +0200 Subject: [PATCH 06/10] reminders in the future can be displayed too --- htdocs/comm/action/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 5179b4c0ab1..6c9f7f55f08 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -1669,7 +1669,7 @@ if ($id > 0) { $filtreuserid = $user->id; if ($user->rights->agenda->allactions->read) $filtreuserid = 0; - $object->loadReminders('', $filteruserid); + $object->loadReminders('', $filteruserid, false); print '
'; From 554948d3e21d3a73e312a1df80501b2ac4a05754 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Thu, 24 Sep 2020 15:34:52 +0200 Subject: [PATCH 07/10] bad user for getNomUrl --- htdocs/comm/action/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 6c9f7f55f08..d158528ce0f 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -1685,7 +1685,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) { From 988a532bed7502235120246146deaa26a9807229 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Mon, 28 Sep 2020 16:37:17 +0200 Subject: [PATCH 08/10] fix br --- htdocs/comm/action/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index d158528ce0f..07bc0dd481b 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -1697,7 +1697,7 @@ if ($id > 0) print $langs->trans("Done"); print ' '; } - print '
'; + print '
'; } } } @@ -2009,7 +2009,7 @@ if ($id > 0) print $langs->trans("Done"); print ' '; } - print '
'; + print '
'; } } From 1ed6312f4b0d83131ac8f74f2f3b41b74a796d3b Mon Sep 17 00:00:00 2001 From: atm-greg Date: Tue, 29 Sep 2020 14:08:49 +0200 Subject: [PATCH 09/10] add modification of the notifications --- htdocs/comm/action/card.php | 136 +++++++++++++++++++++++++++++------- 1 file changed, 109 insertions(+), 27 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 07bc0dd481b..94119fbee5c 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -393,7 +393,7 @@ 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 reminder + //Create reminders if ($addreminder == 'on'){ $actionCommReminder = new ActionCommReminder($db); @@ -639,9 +639,51 @@ if (empty($reshook) && $action == 'update') $categories = GETPOST('categories', 'array'); $object->setCategories($categories); + $object->loadReminders(); + if (!empty($object->reminders)) + { + foreach ($object->reminders as $reminder) + { + $reminder->delete($user); + } + $object->reminders = array(); + } + + //Create reminders + if ($addreminder == 'on'){ + $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(); @@ -1673,38 +1715,78 @@ if ($id > 0) print '
'; - print ''; - - 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 ' ('.$tmpuserstatic->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 ' '; - } - print '
'; - } - } + $actionCommReminder = $object->reminders[$firstreminderId]; + + } + else + { + $checked = ''; + $actionCommReminder = new ActionCommReminder($db); + $actionCommReminder->offsetvalue = 10; + $actionCommReminder->offsetunit = 'i'; + $actionCommReminder->typeremind = 'email'; } + print '
'.$langs->trans("AddReminder").'
'; + + //Reminder + print ''; + + //Time Type + print ''; + + //Reminder Type + $TRemindTypes = array(); + if (!empty($conf->global->AGENDA_REMINDER_EMAIL)) $TRemindTypes['email'] = $langs->trans('EMail'); + if (!empty($conf->global->AGENDA_REMINDER_BROWSER)) $TRemindTypes['browser'] = $langs->trans('BrowserPush'); + print ''; + + $hide = ''; + if ($actionCommReminder->typeremind == 'browser') $hide = 'style="display:none;"'; + + //Mail Model + print ''; print '
'.$langs->trans("ReminderTime").''; + print ''; + print '
'.$langs->trans("TimeType").''; + print $form->selectTypeDuration('offsetunit', $actionCommReminder->offsetunit); + print '
'.$langs->trans("ReminderType").''; + print $form->selectarray('selectremindertype', $TRemindTypes, $actionCommReminder->typeremind); + print '
'.$langs->trans("EMailTemplates").''; + print $form->selectModelMail('actioncommsend', 'actioncomm_send', 1); print '
'; + + print "\n".''."\n"; } dol_fiche_end(); From a61f79c039e081eced1ad0420a46f7a4799b95d6 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Tue, 29 Sep 2020 14:10:24 +0200 Subject: [PATCH 10/10] only update reminders if event is not past --- htdocs/comm/action/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 94119fbee5c..3818f459893 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -640,7 +640,7 @@ if (empty($reshook) && $action == 'update') $object->setCategories($categories); $object->loadReminders(); - if (!empty($object->reminders)) + if (!empty($object->reminders) && $object->datep > dol_now()) { foreach ($object->reminders as $reminder) { @@ -650,7 +650,7 @@ if (empty($reshook) && $action == 'update') } //Create reminders - if ($addreminder == 'on'){ + if ($addreminder == 'on' && $object->datep > dol_now()){ $actionCommReminder = new ActionCommReminder($db); $dateremind = dol_time_plus_duree($datep, -$offsetvalue, $offsetunit);