From 259224c3bef96b19f4d63a88d3502800b4bf6b8f Mon Sep 17 00:00:00 2001 From: Faustin Date: Sat, 2 Jul 2022 18:48:35 +0200 Subject: [PATCH] NEW : Recurrent events on agenda v1 --- htdocs/comm/action/card.php | 322 +++++++++++++++++---------------- htdocs/langs/en_US/agenda.lang | 4 +- htdocs/langs/fr_FR/agenda.lang | 4 +- 3 files changed, 177 insertions(+), 153 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 351ab9212bc..ac943350819 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -409,93 +409,130 @@ if (empty($reshook) && $action == 'add') { $error++; } + + if (!$error) { $db->begin(); - // Creation of action/event - $idaction = $object->create($user); + $dayoffset = 0; + $monthoffset = 0; - if ($idaction > 0) { - if (!$object->error) { - // Category association - $categories = GETPOST('categories', 'array'); - $object->setCategories($categories); + // If event is recurrent + $userepeatevent = ($conf->global->MAIN_FEATURES_LEVEL == 2 ? 1 : 0); + if ($userepeatevent && GETPOSTISSET('recurrulefreq') && GETPOST('recurrulefreq') != 'no' && GETPOSTISSET("limityear") && GETPOSTISSET("limitmonth") && GETPOSTISSET("limitday")) { + $repeateventlimitdate = dol_mktime('23', '59', '59', GETPOST("limitmonth", 'int'), GETPOST("limitday", 'int'), GETPOST("limityear", 'int') < 2100 ? GETPOST("limityear", 'int') : 2100, $tzforfullday ? $tzforfullday : 'tzuser'); + 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 - if ($addreminder == 'on') { - $actionCommReminder = new ActionCommReminder($db); + $finalobject->datep = $datep; + $finalobject->datef = $datef; + // 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; - $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; + unset($_SESSION['assignedtouser']); + + $moreparam = ''; + if ($user->id != $finalobject->userownerid) { + $moreparam = "filtert=-1"; // We force to remove filter so created record is visible when going back to per user view. } - // 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); + // Create reminders + if ($addreminder == 'on') { + $actionCommReminder = new ActionCommReminder($db); - if ($res <= 0) { - // If error - $db->rollback(); - $langs->load("errors"); - $error = $langs->trans('ErrorReminderActionCommCreation'); - setEventMessages($error, null, 'errors'); - $action = 'create'; $donotclearsession = 1; - break; + $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 = $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. - /*$moreparam .= ($moreparam ? '&' : '').'search_actioncode=0'; - $moreparam .= ($moreparam ? '&' : '').'search_status=-1'; - $moreparam .= ($moreparam ? '&' : '').'search_filtert='.$object->userownerid; - */ - $moreparam .= ($moreparam ? '&' : '').'disabledefaultvalues=1'; + // 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_status=-1'; + $moreparam .= ($moreparam ? '&' : '').'search_filtert='.$object->userownerid; + */ + $moreparam .= ($moreparam ? '&' : '').'disabledefaultvalues=1'; - if ($error) { + if ($error) { + $db->rollback(); + } else { + $db->commit(); + } + } else { + // If error $db->rollback(); - } else { - $db->commit(); + $langs->load("errors"); + $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 { - // If error $db->rollback(); - $langs->load("errors"); - $error = $langs->trans($object->error); - setEventMessages($error, null, 'errors'); + setEventMessages($finalobject->error, $finalobject->errors, 'errors'); $action = 'create'; $donotclearsession = 1; } - } else { - $db->rollback(); - setEventMessages($object->error, $object->errors, 'errors'); - $action = 'create'; $donotclearsession = 1; + + // If event is not recurrent, we stop here + if (!($userepeatevent && GETPOSTISSET('recurrulefreq') && GETPOST('recurrulefreq') != 'no' && GETPOSTISSET("limityear") && GETPOSTISSET("limitmonth") && GETPOSTISSET("limitday"))) { + 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"), 'MONTHLY'=>$langs->trans("EveryMonth"), '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'; llxHeader('', $langs->trans("Agenda"), $help_url); @@ -1038,44 +1076,26 @@ if ($action == 'create') { print img_picto($langs->trans("Recurrence"), 'recurring', 'class="paddingright2"'); print ''; $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'); - // If recurrulefreq is MONTHLY - print ''; - // If recurrulefreq is WEEKLY - print ''; - //print ''; - } + // // Recurring event + // $userepeatevent = ($conf->global->MAIN_FEATURES_LEVEL == 2 ? 1 : 0); + // if ($userepeatevent) { + // // Repeat + // //print ''; + // print '        
'; + // print img_picto($langs->trans("Recurrence"), 'recurring', 'class="paddingright2"'); + // print ''; + // $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'); + // // If recurrulefreq is MONTHLY + // print ''; + // // If recurrulefreq is WEEKLY + // print ''; + // print ''; + // print '
'; + // //print ''; + // } print ''; // Date start - end diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang index 272ec22df5c..410537acbc1 100644 --- a/htdocs/langs/en_US/agenda.lang +++ b/htdocs/langs/en_US/agenda.lang @@ -135,7 +135,7 @@ AgendaUrlOptionsNotAdmin=logina=!%s to restrict output to actions not own AgendaUrlOptions4=logint=%s to restrict output to actions assigned to user %s (owner and others). AgendaUrlOptionsProject=project=__PROJECT_ID__ to restrict output to actions linked to project __PROJECT_ID__. AgendaUrlOptionsNotAutoEvent=notactiontype=systemauto to exclude automatic events. -AgendaUrlOptionsIncludeHolidays=includeholidays=1 to include events of holidays. +AgendaUrlOptionsIncludeHolidays=includeholidays=1 to include events of holidays. AgendaShowBirthdayEvents=Birthdays of contacts AgendaHideBirthdayEvents=Hide birthdays of contacts Busy=Busy @@ -159,6 +159,7 @@ DateActionBegin=Start event date ConfirmCloneEvent=Are you sure you want to clone the event %s? RepeatEvent=Repeat event OnceOnly=Once only +EveryDay=Every day EveryWeek=Every week EveryMonth=Every 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 BrowserPush=Browser Popup Notification ActiveByDefault=Enabled by default +Until=until \ No newline at end of file diff --git a/htdocs/langs/fr_FR/agenda.lang b/htdocs/langs/fr_FR/agenda.lang index 65e06587e88..a589163dfad 100644 --- a/htdocs/langs/fr_FR/agenda.lang +++ b/htdocs/langs/fr_FR/agenda.lang @@ -96,7 +96,7 @@ PRODUCT_MODIFYInDolibarr=Produit %s modifié PRODUCT_DELETEInDolibarr=Produit%ssupprimé HOLIDAY_CREATEInDolibarr=Demande de congé %s créée HOLIDAY_MODIFYInDolibarr=Demande de congé %s modifiée -HOLIDAY_APPROVEInDolibarr=Demande de congé %s approuvée +HOLIDAY_APPROVEInDolibarr=Demande de congé %s approuvée HOLIDAY_VALIDATEInDolibarr=Demande de congé %s validée HOLIDAY_DELETEInDolibarr=Demande de congé %s supprimée EXPENSE_REPORT_CREATEInDolibarr=Note de frais %s créée @@ -157,6 +157,7 @@ DateActionBegin=Date début événément ConfirmCloneEvent=Êtes-vous sûr de vouloir cloner cet événement %s ? RepeatEvent=Evénement répétitif OnceOnly=Une seule fois +EveryDay=Chaque jour EveryWeek=Chaque semaine EveryMonth=Chaque 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 BrowserPush=Notification par Popup navigateur ActiveByDefault=Activé par défaut +Until=jusqu'à