NEW : Recurrent events on agenda v1

This commit is contained in:
Faustin 2022-07-02 18:48:35 +02:00
parent ef57cde3da
commit 259224c3be
3 changed files with 177 additions and 153 deletions

View File

@ -409,93 +409,130 @@ if (empty($reshook) && $action == 'add') {
$error++; $error++;
} }
if (!$error) { if (!$error) {
$db->begin(); $db->begin();
// Creation of action/event $dayoffset = 0;
$idaction = $object->create($user); $monthoffset = 0;
if ($idaction > 0) { // If event is recurrent
if (!$object->error) { $userepeatevent = ($conf->global->MAIN_FEATURES_LEVEL == 2 ? 1 : 0);
// Category association if ($userepeatevent && GETPOSTISSET('recurrulefreq') && GETPOST('recurrulefreq') != 'no' && GETPOSTISSET("limityear") && GETPOSTISSET("limitmonth") && GETPOSTISSET("limitday")) {
$categories = GETPOST('categories', 'array'); $repeateventlimitdate = dol_mktime('23', '59', '59', GETPOST("limitmonth", 'int'), GETPOST("limitday", 'int'), GETPOST("limityear", 'int') < 2100 ? GETPOST("limityear", 'int') : 2100, $tzforfullday ? $tzforfullday : 'tzuser');
$object->setCategories($categories); if (GETPOST('recurrulefreq') == 'DAILY') {
$dayoffset = 1;
} elseif (GETPOST('recurrulefreq') == 'WEEKLY') {
$dayoffset = 7;
} elseif (GETPOST('recurrulefreq') == 'MONTHLY') {
$monthoffset = 1;
}
} else { // If event is not recurrent, limit date is the date of the event
$repeateventlimitdate = $datep;
}
unset($_SESSION['assignedtouser']); while ($datep <= $repeateventlimitdate) {
$finalobject = clone $object;
$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 reminders $finalobject->datep = $datep;
if ($addreminder == 'on') { $finalobject->datef = $datef;
$actionCommReminder = new ActionCommReminder($db); // Creation of action/event
$idaction = $finalobject->create($user);
$dateremind = dol_time_plus_duree($datep, -$offsetvalue, $offsetunit); if ($idaction > 0) {
if (!$finalobject->error) {
// Category association
$categories = GETPOST('categories', 'array');
$finalobject->setCategories($categories);
$actionCommReminder->dateremind = $dateremind; unset($_SESSION['assignedtouser']);
$actionCommReminder->typeremind = $remindertype;
$actionCommReminder->offsetunit = $offsetunit; $moreparam = '';
$actionCommReminder->offsetvalue = $offsetvalue; if ($user->id != $finalobject->userownerid) {
$actionCommReminder->status = $actionCommReminder::STATUS_TODO; $moreparam = "filtert=-1"; // We force to remove filter so created record is visible when going back to per user view.
$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 // Create reminders
foreach ($object->userassigned as $userassigned) { if ($addreminder == 'on') {
$actionCommReminder->fk_user = $userassigned['id']; $actionCommReminder = new ActionCommReminder($db);
$res = $actionCommReminder->create($user);
if ($res <= 0) { $dateremind = dol_time_plus_duree($datep, -$offsetvalue, $offsetunit);
// If error
$db->rollback(); $actionCommReminder->dateremind = $dateremind;
$langs->load("errors"); $actionCommReminder->typeremind = $remindertype;
$error = $langs->trans('ErrorReminderActionCommCreation'); $actionCommReminder->offsetunit = $offsetunit;
setEventMessages($error, null, 'errors'); $actionCommReminder->offsetvalue = $offsetvalue;
$action = 'create'; $donotclearsession = 1; $actionCommReminder->status = $actionCommReminder::STATUS_TODO;
break; $actionCommReminder->fk_actioncomm = $finalobject->id;
if ($remindertype == 'email') {
$actionCommReminder->fk_email_template = $modelmail;
}
// the notification must be created for every user assigned to the event
foreach ($finalobject->userassigned as $userassigned) {
$actionCommReminder->fk_user = $userassigned['id'];
$res = $actionCommReminder->create($user);
if ($res <= 0) {
// If error
$db->rollback();
$langs->load("errors");
$error = $langs->trans('ErrorReminderActionCommCreation');
setEventMessages($error, null, 'errors');
$action = 'create'; $donotclearsession = 1;
break;
}
} }
} }
}
// Modify $moreparam so we are sure to see the event we have just created, whatever are the default value of filter on next page. // Modify $moreparam so we are sure to see the event we have just created, whatever are the default value of filter on next page.
/*$moreparam .= ($moreparam ? '&' : '').'search_actioncode=0'; /*$moreparam .= ($moreparam ? '&' : '').'search_actioncode=0';
$moreparam .= ($moreparam ? '&' : '').'search_status=-1'; $moreparam .= ($moreparam ? '&' : '').'search_status=-1';
$moreparam .= ($moreparam ? '&' : '').'search_filtert='.$object->userownerid; $moreparam .= ($moreparam ? '&' : '').'search_filtert='.$object->userownerid;
*/ */
$moreparam .= ($moreparam ? '&' : '').'disabledefaultvalues=1'; $moreparam .= ($moreparam ? '&' : '').'disabledefaultvalues=1';
if ($error) { if ($error) {
$db->rollback();
} else {
$db->commit();
}
} else {
// If error
$db->rollback(); $db->rollback();
} else { $langs->load("errors");
$db->commit(); $error = $langs->trans($finalobject->error);
setEventMessages($error, null, 'errors');
$action = 'create'; $donotclearsession = 1;
} }
if (!empty($backtopage)) {
dol_syslog("Back to ".$backtopage.($moreparam ? (preg_match('/\?/', $backtopage) ? '&'.$moreparam : '?'.$moreparam) : ''));
header("Location: ".$backtopage.($moreparam ? (preg_match('/\?/', $backtopage) ? '&'.$moreparam : '?'.$moreparam) : ''));
} elseif ($idaction) {
header("Location: ".DOL_URL_ROOT.'/comm/action/card.php?id='.$idaction.($moreparam ? '&'.$moreparam : ''));
} else {
header("Location: ".DOL_URL_ROOT.'/comm/action/index.php'.($moreparam ? '?'.$moreparam : ''));
}
exit;
} else { } else {
// If error
$db->rollback(); $db->rollback();
$langs->load("errors"); setEventMessages($finalobject->error, $finalobject->errors, 'errors');
$error = $langs->trans($object->error);
setEventMessages($error, null, 'errors');
$action = 'create'; $donotclearsession = 1; $action = 'create'; $donotclearsession = 1;
} }
} else {
$db->rollback(); // If event is not recurrent, we stop here
setEventMessages($object->error, $object->errors, 'errors'); if (!($userepeatevent && GETPOSTISSET('recurrulefreq') && GETPOST('recurrulefreq') != 'no' && GETPOSTISSET("limityear") && GETPOSTISSET("limitmonth") && GETPOSTISSET("limitday"))) {
$action = 'create'; $donotclearsession = 1; break;
}
// increment date for recurrent events
$datep = dol_time_plus_duree($datep, $dayoffset, 'd');
$datep = dol_time_plus_duree($datep, $monthoffset, 'm');
$datef = dol_time_plus_duree($datef, $dayoffset, 'd');
$datef = dol_time_plus_duree($datef, $monthoffset, 'm');
} }
if (!empty($backtopage)) {
dol_syslog("Back to ".$backtopage.($moreparam ? (preg_match('/\?/', $backtopage) ? '&'.$moreparam : '?'.$moreparam) : ''));
header("Location: ".$backtopage.($moreparam ? (preg_match('/\?/', $backtopage) ? '&'.$moreparam : '?'.$moreparam) : ''));
} elseif ($idaction) {
header("Location: ".DOL_URL_ROOT.'/comm/action/card.php?id='.$idaction.($moreparam ? '&'.$moreparam : ''));
} else {
header("Location: ".DOL_URL_ROOT.'/comm/action/index.php'.($moreparam ? '?'.$moreparam : ''));
}
exit;
} }
} }
@ -917,9 +954,10 @@ $arrayrecurrulefreq = array(
'no'=>$langs->trans("OnceOnly"), 'no'=>$langs->trans("OnceOnly"),
'MONTHLY'=>$langs->trans("EveryMonth"), 'MONTHLY'=>$langs->trans("EveryMonth"),
'WEEKLY'=>$langs->trans("EveryWeek"), 'WEEKLY'=>$langs->trans("EveryWeek"),
//'DAYLY'=>$langs->trans("EveryDay") 'DAILY'=>$langs->trans("EveryDay")
); );
$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda'; $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda';
llxHeader('', $langs->trans("Agenda"), $help_url); llxHeader('', $langs->trans("Agenda"), $help_url);
@ -1038,44 +1076,26 @@ if ($action == 'create') {
print img_picto($langs->trans("Recurrence"), 'recurring', 'class="paddingright2"'); print img_picto($langs->trans("Recurrence"), 'recurring', 'class="paddingright2"');
print '<input type="hidden" name="recurid" value="'.$object->recurid.'">'; print '<input type="hidden" name="recurid" value="'.$object->recurid.'">';
$selectedrecurrulefreq = 'no'; $selectedrecurrulefreq = 'no';
$selectedrecurrulebymonthday = '';
$selectedrecurrulebyday = '';
if ($object->recurrule && preg_match('/FREQ=([A-Z]+)/i', $object->recurrule, $reg)) {
$selectedrecurrulefreq = $reg[1];
}
if ($object->recurrule && preg_match('/FREQ=MONTHLY.*BYMONTHDAY=(\d+)/i', $object->recurrule, $reg)) {
$selectedrecurrulebymonthday = $reg[1];
}
if ($object->recurrule && preg_match('/FREQ=WEEKLY.*BYDAY(\d+)/i', $object->recurrule, $reg)) {
$selectedrecurrulebyday = $reg[1];
}
print $form->selectarray('recurrulefreq', $arrayrecurrulefreq, $selectedrecurrulefreq, 0, 0, 0, '', 0, 0, 0, '', 'marginrightonly'); print $form->selectarray('recurrulefreq', $arrayrecurrulefreq, $selectedrecurrulefreq, 0, 0, 0, '', 0, 0, 0, '', 'marginrightonly');
// If recurrulefreq is MONTHLY // For recursive event
print '<div class="hidden marginrightonly inline-block repeateventBYMONTHDAY">'; $repeateventlimitdate = $repeateventlimitdate ? $repeateventlimitdate : '';
print $langs->trans("DayOfMonth").': <input type="input" size="2" name="BYMONTHDAY" value="'.$selectedrecurrulebymonthday.'">'; print '<div class="hidden marginrightonly inline-block repeateventlimitdate">';
print '</div>'; print $langs->trans("Until")." ";
// If recurrulefreq is WEEKLY print $form->selectDate($repeateventlimitdate, 'limit', 0, 0, 0, "action", 1, 0, 0, '', '', '', '', 1, '', '', 'tzuserrel');
print '<div class="hidden marginrightonly inline-block repeateventBYDAY">';
print $langs->trans("DayOfWeek").': <input type="input" size="4" name="BYDAY" value="'.$selectedrecurrulebyday.'">';
print '</div>'; print '</div>';
print '<script type="text/javascript"> print '<script type="text/javascript">
jQuery(document).ready(function() { jQuery(document).ready(function() {
function init_repeat() function init_repeat()
{ {
if (jQuery("#recurrulefreq").val() == \'MONTHLY\') if (jQuery("#recurrulefreq").val() == \'MONTHLY\' || jQuery("#recurrulefreq").val() == \'WEEKLY\' || jQuery("#recurrulefreq").val() == \'DAILY\')
{ {
jQuery(".repeateventBYMONTHDAY").css("display", "inline-block"); /* use this instead of show because we want inline-block and not block */ jQuery(".repeateventlimitdate").css("display", "inline-block"); /* use this instead of show because we want inline-block and not block */
jQuery(".repeateventBYDAY").hide();
}
else if (jQuery("#recurrulefreq").val() == \'WEEKLY\')
{
jQuery(".repeateventBYMONTHDAY").hide();
jQuery(".repeateventBYDAY").css("display", "inline-block"); /* use this instead of show because we want inline-block and not block */
} }
else else
{ {
jQuery(".repeateventBYMONTHDAY").hide(); jQuery(".repeateventlimitdate").hide();
jQuery(".repeateventBYDAY").hide();
} }
} }
init_repeat(); init_repeat();
@ -1544,64 +1564,64 @@ if ($id > 0) {
print '<tr><td><span class="fieldrequired">'.$langs->trans("Date").'</span></td><td colspan="3" class="valignmiddle height30 small"><input type="checkbox" id="fullday" name="fullday" '.($object->fulldayevent ? ' checked' : '').'>'; print '<tr><td><span class="fieldrequired">'.$langs->trans("Date").'</span></td><td colspan="3" class="valignmiddle height30 small"><input type="checkbox" id="fullday" name="fullday" '.($object->fulldayevent ? ' checked' : '').'>';
print '<label for="fullday">'.$langs->trans("EventOnFullDay").'</label>'; print '<label for="fullday">'.$langs->trans("EventOnFullDay").'</label>';
// Recurring event // // Recurring event
$userepeatevent = ($conf->global->MAIN_FEATURES_LEVEL == 2 ? 1 : 0); // $userepeatevent = ($conf->global->MAIN_FEATURES_LEVEL == 2 ? 1 : 0);
if ($userepeatevent) { // if ($userepeatevent) {
// Repeat // // Repeat
//print '<tr><td></td><td colspan="3">'; // //print '<tr><td></td><td colspan="3">';
print ' &nbsp; &nbsp; &nbsp; &nbsp; <div class="opacitymedium inline-block">'; // print ' &nbsp; &nbsp; &nbsp; &nbsp; <div class="opacitymedium inline-block">';
print img_picto($langs->trans("Recurrence"), 'recurring', 'class="paddingright2"'); // print img_picto($langs->trans("Recurrence"), 'recurring', 'class="paddingright2"');
print '<input type="hidden" name="recurid" value="'.$object->recurid.'">'; // print '<input type="hidden" name="recurid" value="'.$object->recurid.'">';
$selectedrecurrulefreq = 'no'; // $selectedrecurrulefreq = 'no';
$selectedrecurrulebymonthday = ''; // $selectedrecurrulebymonthday = '';
$selectedrecurrulebyday = ''; // $selectedrecurrulebyday = '';
if ($object->recurrule && preg_match('/FREQ=([A-Z]+)/i', $object->recurrule, $reg)) { // if ($object->recurrule && preg_match('/FREQ=([A-Z]+)/i', $object->recurrule, $reg)) {
$selectedrecurrulefreq = $reg[1]; // $selectedrecurrulefreq = $reg[1];
} // }
if ($object->recurrule && preg_match('/FREQ=MONTHLY.*BYMONTHDAY=(\d+)/i', $object->recurrule, $reg)) { // if ($object->recurrule && preg_match('/FREQ=MONTHLY.*BYMONTHDAY=(\d+)/i', $object->recurrule, $reg)) {
$selectedrecurrulebymonthday = $reg[1]; // $selectedrecurrulebymonthday = $reg[1];
} // }
if ($object->recurrule && preg_match('/FREQ=WEEKLY.*BYDAY(\d+)/i', $object->recurrule, $reg)) { // if ($object->recurrule && preg_match('/FREQ=WEEKLY.*BYDAY(\d+)/i', $object->recurrule, $reg)) {
$selectedrecurrulebyday = $reg[1]; // $selectedrecurrulebyday = $reg[1];
} // }
print $form->selectarray('recurrulefreq', $arrayrecurrulefreq, $selectedrecurrulefreq, 0, 0, 0, '', 0, 0, 0, '', 'marginrightonly'); // print $form->selectarray('recurrulefreq', $arrayrecurrulefreq, $selectedrecurrulefreq, 0, 0, 0, '', 0, 0, 0, '', 'marginrightonly');
// If recurrulefreq is MONTHLY // // If recurrulefreq is MONTHLY
print '<div class="hidden marginrightonly inline-block repeateventBYMONTHDAY">'; // print '<div class="hidden marginrightonly inline-block repeateventBYMONTHDAY">';
print $langs->trans("DayOfMonth").': <input type="input" size="2" name="BYMONTHDAY" value="'.$selectedrecurrulebymonthday.'">'; // print $langs->trans("DayOfMonth").': <input type="input" size="2" name="BYMONTHDAY" value="'.$selectedrecurrulebymonthday.'">';
print '</div>'; // print '</div>';
// If recurrulefreq is WEEKLY // // If recurrulefreq is WEEKLY
print '<div class="hidden marginrightonly inline-block repeateventBYDAY">'; // print '<div class="hidden marginrightonly inline-block repeateventBYDAY">';
print $langs->trans("DayOfWeek").': <input type="input" size="4" name="BYDAY" value="'.$selectedrecurrulebyday.'">'; // print $langs->trans("DayOfWeek").': <input type="input" size="4" name="BYDAY" value="'.$selectedrecurrulebyday.'">';
print '</div>'; // print '</div>';
print '<script type="text/javascript"> // print '<script type="text/javascript">
jQuery(document).ready(function() { // jQuery(document).ready(function() {
function init_repeat() // function init_repeat()
{ // {
if (jQuery("#recurrulefreq").val() == \'MONTHLY\') // if (jQuery("#recurrulefreq").val() == \'MONTHLY\')
{ // {
jQuery(".repeateventBYMONTHDAY").css("display", "inline-block"); /* use this instead of show because we want inline-block and not block */ // jQuery(".repeateventBYMONTHDAY").css("display", "inline-block"); /* use this instead of show because we want inline-block and not block */
jQuery(".repeateventBYDAY").hide(); // jQuery(".repeateventBYDAY").hide();
} // }
else if (jQuery("#recurrulefreq").val() == \'WEEKLY\') // else if (jQuery("#recurrulefreq").val() == \'WEEKLY\')
{ // {
jQuery(".repeateventBYMONTHDAY").hide(); // jQuery(".repeateventBYMONTHDAY").hide();
jQuery(".repeateventBYDAY").css("display", "inline-block"); /* use this instead of show because we want inline-block and not block */ // jQuery(".repeateventBYDAY").css("display", "inline-block"); /* use this instead of show because we want inline-block and not block */
} // }
else // else
{ // {
jQuery(".repeateventBYMONTHDAY").hide(); // jQuery(".repeateventBYMONTHDAY").hide();
jQuery(".repeateventBYDAY").hide(); // jQuery(".repeateventBYDAY").hide();
} // }
} // }
init_repeat(); // init_repeat();
jQuery("#recurrulefreq").change(function() { // jQuery("#recurrulefreq").change(function() {
init_repeat(); // init_repeat();
}); // });
}); // });
</script>'; // </script>';
print '</div>'; // print '</div>';
//print '</td></tr>'; // //print '</td></tr>';
} // }
print '</td></tr>'; print '</td></tr>';
// Date start - end // Date start - end

View File

@ -159,6 +159,7 @@ DateActionBegin=Start event date
ConfirmCloneEvent=Are you sure you want to clone the event <b>%s</b>? ConfirmCloneEvent=Are you sure you want to clone the event <b>%s</b>?
RepeatEvent=Repeat event RepeatEvent=Repeat event
OnceOnly=Once only OnceOnly=Once only
EveryDay=Every day
EveryWeek=Every week EveryWeek=Every week
EveryMonth=Every month EveryMonth=Every month
DayOfMonth=Day of month DayOfMonth=Day of month
@ -174,3 +175,4 @@ AddReminder=Create an automatic reminder notification for this event
ErrorReminderActionCommCreation=Error creating the reminder notification for this event ErrorReminderActionCommCreation=Error creating the reminder notification for this event
BrowserPush=Browser Popup Notification BrowserPush=Browser Popup Notification
ActiveByDefault=Enabled by default ActiveByDefault=Enabled by default
Until=until

View File

@ -157,6 +157,7 @@ DateActionBegin=Date début événément
ConfirmCloneEvent=Êtes-vous sûr de vouloir cloner cet événement <b>%s</b> ? ConfirmCloneEvent=Êtes-vous sûr de vouloir cloner cet événement <b>%s</b> ?
RepeatEvent=Evénement répétitif RepeatEvent=Evénement répétitif
OnceOnly=Une seule fois OnceOnly=Une seule fois
EveryDay=Chaque jour
EveryWeek=Chaque semaine EveryWeek=Chaque semaine
EveryMonth=Chaque mois EveryMonth=Chaque mois
DayOfMonth=Jour du mois DayOfMonth=Jour du mois
@ -172,3 +173,4 @@ AddReminder=Créer une notification de rappel automatique pour cet événement
ErrorReminderActionCommCreation=Erreur lors de la création de la notification de rappel pour cet événement ErrorReminderActionCommCreation=Erreur lors de la création de la notification de rappel pour cet événement
BrowserPush=Notification par Popup navigateur BrowserPush=Notification par Popup navigateur
ActiveByDefault=Activé par défaut ActiveByDefault=Activé par défaut
Until=jusqu'à