diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index c3941217780..0d8fcaa7ff1 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1563,18 +1563,19 @@ class ActionComm extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Export events from database into a cal file. + * Export events from database into a cal file. * - * @param string $format 'vcal', 'ical/ics', 'rss' - * @param string $type 'event' or 'journal' - * @param int $cachedelay Do not rebuild file if date older than cachedelay seconds - * @param string $filename Force filename - * @param array $filters Array of filters. Exemple array('notolderthan'=>99, 'year'=>..., 'idfrom'=>..., 'notactiontype'=>'systemauto', 'project'=>123, ...) - * @return int <0 if error, nb of events in new file if ok + * @param string $format The format of the export 'vcal', 'ical/ics' or 'rss' + * @param string $type The type of the export 'event' or 'journal' + * @param integer $cachedelay Do not rebuild file if date older than cachedelay seconds + * @param string $filename The name for the exported file. + * @param array $filters Array of filters. Example array('notolderthan'=>99, 'year'=>..., 'idfrom'=>..., 'notactiontype'=>'systemauto', 'project'=>123, ...) + * @param integer $exportholiday 0 = don't integrate holidays into the export, 1 = integrate holidays into the export + * @return integer -1 = error on build export file, 0 = export okay */ - public function build_exportfile($format, $type, $cachedelay, $filename, $filters) + public function build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholiday = 0) { - global $hookmanager; + global $hookmanager; // phpcs:enable global $conf, $langs, $dolibarr_main_url_root, $mysoc; @@ -1789,6 +1790,91 @@ class ActionComm extends CommonObject return -1; } + if($exportholiday == 1) + { + $langs->load("holidays"); + $title = $langs->trans("Holidays"); + + $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.email, u.statut, x.rowid, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.statut as status"; + $sql.= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u"; + $sql.= " WHERE u.rowid = x.fk_user"; + $sql.= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user) + $sql.= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved) + + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + $event = array(); + + if($obj->halfday == -1) + { + $event['fulldayevent'] = false; + + $timestampStart = dol_stringtotime($obj->date_start." 00:00:00", 0); + $timestampEnd = dol_stringtotime($obj->date_end." 12:00:00", 0); + } + elseif($obj->halfday == 1) + { + $event['fulldayevent'] = false; + + $timestampStart = dol_stringtotime($obj->date_start." 12:00:00", 0); + $timestampEnd = dol_stringtotime($obj->date_end." 23:59:59", 0); + } + else + { + $event['fulldayevent'] = true; + + $timestampStart = dol_stringtotime($obj->date_start." 00:00:00", 0); + $timestampEnd = dol_stringtotime($obj->date_end." 23:59:59", 0); + } + + if(!empty($conf->global->AGENDA_EXPORT_FIX_TZ)) + { + $timestampStart =- ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600); + $timestampEnd =- ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600); + } + + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; + $url = $urlwithroot.'/holiday/card.php?id='.$obj->rowid; + + $event['uid'] = 'dolibarrholiday-'.$this->db->database_name.'-'.$obj->rowid."@".$_SERVER["SERVER_NAME"]; + $event['author'] = dolGetFirstLastname($obj->firstname, $obj->lastname); + $event['type'] = 'event'; + $event['category'] = "Holiday"; + $event['transparency'] = 'OPAQUE'; + $event['email'] = $obj->email; + $event['created'] = $timestampStart; + $event['modified'] = $timestampStart; + $event['startdate'] = $timestampStart; + $event['enddate'] = $timestampEnd; + $event['duration'] = $timestampEnd - $timestampStart; + $event['url'] = $url; + + if($obj->status == 2) + { + // 2 = leave wait for approval + $event['summary'] = $title." - ".$obj->lastname." (wait for approval)"; + } + else + { + // 3 = leave approved + $event['summary'] = $title." - ".$obj->lastname; + } + + $eventarray[] = $event; + + $i++; + } + } + } + $langs->load("agenda"); // Define title and desc diff --git a/htdocs/public/agenda/agendaexport.php b/htdocs/public/agenda/agendaexport.php index 9b76f2b90b3..66057f724b4 100644 --- a/htdocs/public/agenda/agendaexport.php +++ b/htdocs/public/agenda/agendaexport.php @@ -157,10 +157,12 @@ $agenda=new ActionComm($db); $cachedelay=0; if (! empty($conf->global->MAIN_AGENDA_EXPORT_CACHE)) $cachedelay=$conf->global->MAIN_AGENDA_EXPORT_CACHE; +$exportholidays = empty($conf->global->AGENDA_SHOW_HOLIDAYS) ? 0 : 1; + // Build file if ($format == 'ical' || $format == 'vcal') { - $result=$agenda->build_exportfile($format, $type, $cachedelay, $filename, $filters); + $result=$agenda->build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholidays); if ($result >= 0) { $attachment = true; @@ -195,7 +197,7 @@ if ($format == 'ical' || $format == 'vcal') if ($format == 'rss') { - $result=$agenda->build_exportfile($format, $type, $cachedelay, $filename, $filters); + $result=$agenda->build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholidays); if ($result >= 0) { $attachment = false;