add modification of the notifications

This commit is contained in:
atm-greg 2020-09-29 14:08:49 +02:00
parent 988a532bed
commit 1ed6312f4b

View File

@ -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 '<hr>';
print '<table class="border tableforfield centpercent">';
print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("Reminders").'</td><td>';
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 ' - <span class="opacitymedium">';
print $langs->trans("NotSent");
print ' </span>';
} elseif ($actioncommreminder->status == $actioncommreminder::STATUS_DONE) {
print ' - <span class="opacitymedium">';
print $langs->trans("Done");
print ' </span>';
}
print '<br>';
}
}
$actionCommReminder = $object->reminders[$firstreminderId];
}
else
{
$checked = '';
$actionCommReminder = new ActionCommReminder($db);
$actionCommReminder->offsetvalue = 10;
$actionCommReminder->offsetunit = 'i';
$actionCommReminder->typeremind = 'email';
}
print '<tr><td>'.$langs->trans("AddReminder").'</td><td colspan="3"><input type="checkbox" id="addreminder" name="addreminder" '.$checked.'></td></tr>';
print '<div class="reminderparameters" '.(empty($checked) ? 'style="display: none;"' : '').'>';
print '<table class="border centpercent">';
//Reminder
print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("ReminderTime").'</td><td colspan="3">';
print '<input type="number" name="offsetvalue" value="'.$actionCommReminder->offsetvalue.'" size="5">';
print '</td></tr>';
//Time Type
print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("TimeType").'</td><td colspan="3">';
print $form->selectTypeDuration('offsetunit', $actionCommReminder->offsetunit);
print '</td></tr>';
//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 '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("ReminderType").'</td><td colspan="3">';
print $form->selectarray('selectremindertype', $TRemindTypes, $actionCommReminder->typeremind);
print '</td></tr>';
$hide = '';
if ($actionCommReminder->typeremind == 'browser') $hide = 'style="display:none;"';
//Mail Model
print '<tr '.$hide.'><td class="titlefieldcreate nowrap">'.$langs->trans("EMailTemplates").'</td><td colspan="3">';
print $form->selectModelMail('actioncommsend', 'actioncomm_send', 1);
print '</td></tr>';
print '</table>';
print "\n".'<script type="text/javascript">';
print '$(document).ready(function () {
$("#addreminder").click(function(){
if (this.checked) {
$(".reminderparameters").show();
} else {
$(".reminderparameters").hide();
}
});
$("#selectremindertype").change(function(){
var selected_option = $("#selectremindertype option:selected").val();
if(selected_option == "email") {
$("#select_actioncommsendmodel_mail").closest("tr").show();
} else {
$("#select_actioncommsendmodel_mail").closest("tr").hide();
};
});
})';
print '</script>'."\n";
}
dol_fiche_end();