dolibarr 25.0.0-alpha
agendaexport.php
1<?php
2/* Copyright (C) 2008-2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Charlene Benke <charlene@patas-monkey.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
35if (!defined('NOTOKENRENEWAL')) {
36 define('NOTOKENRENEWAL', '1');
37}
38if (!defined('NOREQUIREMENU')) {
39 define('NOREQUIREMENU', '1'); // If there is no menu to show
40}
41if (!defined('NOREQUIREHTML')) {
42 define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
43}
44if (!defined('NOREQUIREAJAX')) {
45 define('NOREQUIREAJAX', '1');
46}
47if (!defined('NOLOGIN')) {
48 define("NOLOGIN", 1); // This means this output page does not require to be logged.
49}
50if (!defined('NOCSRFCHECK')) {
51 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
52}
53if (!defined('NOIPCHECK')) {
54 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
55}
56
57
58// For MultiCompany module.
59// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
60// Because 2 entities can have the same ref
61$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
62if (is_numeric($entity)) {
63 define("DOLENTITY", $entity);
64}
65
66// Load Dolibarr environment
67require '../../main.inc.php';
68require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
78$fichinterStatic = new Fichinter($db);
79
80// Not older than
81if (!getDolGlobalString('MAIN_FICHINTER_EXPORT_PAST_DELAY')) {
82 $conf->global->MAIN_FICHINTER_EXPORT_PAST_DELAY = 100; // default limit
83}
84
85// Define format, type and filter
86$format = 'ical';
87$type = 'event';
88if (GETPOST("format", 'alpha')) {
89 $format = GETPOST("format", 'alpha');
90}
91if (GETPOST("type", 'alpha')) {
92 $type = GETPOST("type", 'alpha');
93}
94
95$filters = array();
96if (GETPOSTINT("year")) {
97 $filters['year'] = GETPOSTINT("year");
98}
99if (GETPOSTINT("id")) {
100 $filters['id'] = GETPOSTINT("id");
101}
102if (GETPOSTINT("idfrom")) {
103 $filters['idfrom'] = GETPOSTINT("idfrom");
104}
105if (GETPOSTINT("idto")) {
106 $filters['idto'] = GETPOSTINT("idto");
107}
108if (GETPOST("project", 'alpha')) {
109 $filters['project'] = GETPOST("project", 'alpha');
110}
111if (GETPOST("logina", 'alpha')) {
112 $filters['logina'] = GETPOST("logina", 'alpha');
113}
114if (GETPOST("logint", 'alpha')) {
115 $filters['logint'] = GETPOST("logint", 'alpha');
116}
117
118if (GETPOSTINT("notolderthan")) {
119 $filters['notolderthan'] = GETPOSTINT("notolderthan");
120} else {
121 $filters['notolderthan'] = getDolGlobalString('MAIN_FICHINTER_EXPORT_PAST_DELAY', 100);
122}
123if (GETPOSTINT("limit")) {
124 $filters['limit'] = GETPOSTINT("limit");
125} else {
126 $filters['limit'] = 1000;
127}
128if (GETPOST("module", 'alpha')) {
129 $filters['module'] = GETPOST("module", 'alpha');
130}
131if (GETPOST("status", "intcomma")) {
132 $filters['status'] = GETPOST("status", "intcomma");
133}
134
135// Security check
136if (!isModEnabled('intervention')) {
137 httponly_accessforbidden('Module fichinter not enabled');
138}
139
140
141/*
142 * View
143 */
144
145// Check config
146if (!getDolGlobalString('MAIN_FICHINTER_XCAL_EXPORTKEY')) {
147 top_httphead();
148
149 print '<html><title>Export fichinter cal</title><body>';
150 print '<div class="error">Module Agenda was not configured properly.</div>';
151 print '</body></html>';
152 exit;
153}
154
155// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
156$hookmanager->initHooks(array('fichinterexport'));
157
158// Note that $action and $object may have been modified by some
159$reshook = $hookmanager->executeHooks('doActions', $filters);
160if ($reshook < 0) {
161 top_httphead();
162
163 print '<html><title>Export fichinter cal</title><body>';
164 if (!empty($hookmanager->errors) && is_array($hookmanager->errors)) {
165 print '<div class="error">'.implode('<br>', $hookmanager->errors).'</div>';
166 } else {
167 print '<div class="error">'.$hookmanager->error.'</div>';
168 }
169 print '</body></html>';
170} elseif (empty($reshook)) {
171 // Check exportkey
172 if (!GETPOST("exportkey") || getDolGlobalString('MAIN_FICHINTER_XCAL_EXPORTKEY') != GETPOST("exportkey")) {
173 top_httphead();
174
175 print '<html><title>Export fichinter cal</title><body>';
176 print '<div class="error">Bad value for key.</div>';
177 print '</body></html>';
178 exit;
179 }
180}
181
182// Define filename with prefix based on filter criteria (each criterion set must have a corresponding cache file)
183$shortfilename = 'dolibarrcalendar';
184$filename = $shortfilename;
185// Complete long filename
186foreach ($filters as $key => $value) {
187 //if ($key == 'notolderthan')
188 // $filename.='-notolderthan'.$value; This filter key is already added before and does not need to be in filename
189 if ($key == 'year') {
190 $filename .= '-year'.$value;
191 }
192 if ($key == 'id') {
193 $filename .= '-id'.$value;
194 }
195 if ($key == 'idfrom') {
196 $filename .= '-idfrom'.$value;
197 }
198 if ($key == 'idto') {
199 $filename .= '-idto'.$value;
200 }
201 if ($key == 'project') {
202 $filename .= '-project'.$value;
203 $shortfilename .= '-project'.$value;
204 }
205 if ($key == 'logina') {
206 $filename .= '-logina'.$value; // Author
207 }
208 if ($key == 'logint') {
209 $filename .= '-logint'.$value; // Assigned to
210 }
211
212 if ($key == 'module') {
213 $filename .= '-module'.$value;
214 if ($value == 'project@eventorganization') {
215 $shortfilename .= '-project';
216 } elseif ($value == 'conforbooth@eventorganization') {
217 $shortfilename .= '-conforbooth';
218 }
219 }
220 if ($key == 'status') {
221 $filename .= '-status'.$value;
222 }
223}
224// Add extension
225if ($format == 'vcal') {
226 $shortfilename .= '.vcs';
227 $filename .= '.vcs';
228}
229if ($format == 'ical') {
230 $shortfilename .= '.ics';
231 $filename .= '.ics';
232}
233if ($format == 'rss') {
234 $shortfilename .= '.rss';
235 $filename .= '.rss';
236}
237if ($shortfilename == 'dolibarrcalendar') {
238 $langs->load("errors");
239
240 top_httphead();
241
242 print '<html><title>Export fichinter cal</title><body>';
243 print '<div class="error">'.$langs->trans("ErrorWrongValueForParameterX", 'format').'</div>';
244 print '</body></html>';
245 exit;
246}
247
248$fichinter = new Fichinter($db);
249
250$cachedelay = 0;
251if (getDolGlobalString('MAIN_FICHINTER_EXPORT_CACHE')) {
252 $cachedelay = getDolGlobalString('MAIN_FICHINTER_EXPORT_CACHE');
253}
254
255$exportholidays = GETPOSTINT('includeholidays');
256
257// Build file
258if ($format == 'ical' || $format == 'vcal') {
259 $result = build_exportfile($format, $type, $cachedelay, $filename, $filters);
260 if ($result >= 0) {
261 $attachment = true;
262 if (GETPOSTISSET("attachment")) {
263 $attachment = GETPOST("attachment");
264 }
265 //$attachment = false;
266 $contenttype = 'text/calendar';
267 // Only types that can not be rendered as HTML, else the labels of interventions would be interpreted by the browser
268 if (GETPOSTISSET("contenttype") && in_array(GETPOST("contenttype"), array('text/calendar', 'text/plain'))) {
269 $contenttype = GETPOST("contenttype");
270 }
271 //$contenttype='text/plain';
272 $outputencoding = 'UTF-8';
273
274 if ($contenttype) {
275 header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
276 }
277 if ($attachment) {
278 header('Content-Disposition: attachment; filename="'.$shortfilename.'"');
279 }
280
281 if ($cachedelay) {
282 header('Cache-Control: max-age='.$cachedelay.', private, must-revalidate');
283 } else {
284 header('Cache-Control: private, must-revalidate');
285 }
286
287 // By default, frames allowed only if on same domain (stop some XSS attacks)
288 header("X-Frame-Options: SAMEORIGIN");
289
290 // Clean parameters
291 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
292 $result = readfile($outputfile);
293 if (!$result) {
294 dol_syslog("File ".$outputfile." was empty", LOG_WARNING); // The path of the file is not shown on this public page
295 print 'File was empty.';
296 }
297
298 //header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
299 exit;
300 } else {
301 top_httphead();
302
303 print 'Error '.$fichinterStatic->error;
304
305 exit;
306 }
307}
308
309if ($format == 'rss') {
310 $result = build_exportfile($format, $type, $cachedelay, $filename, $filters);
311 if ($result >= 0) {
312 $attachment = false;
313 if (GETPOSTISSET("attachment")) {
314 $attachment = GETPOST("attachment");
315 }
316 //$attachment = false;
317 $contenttype = 'application/rss+xml';
318 // Only types that can not be rendered as HTML, else the labels of interventions would be interpreted by the browser
319 if (GETPOSTISSET("contenttype") && in_array(GETPOST("contenttype"), array('application/rss+xml', 'text/plain'))) {
320 $contenttype = GETPOST("contenttype");
321 }
322 //$contenttype='text/plain';
323 $outputencoding = 'UTF-8';
324
325 if ($contenttype) {
326 header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
327 }
328 if ($attachment) {
329 header('Content-Disposition: attachment; filename="'.$filename.'"');
330 } else {
331 header('Content-Disposition: inline; filename="'.$filename.'"');
332 }
333
334 // Add directives to fix IE bug
335 //header('Cache-Control: Public, must-revalidate');
336 //header('Pragma: public');
337 if ($cachedelay) {
338 header('Cache-Control: max-age='.$cachedelay.', private, must-revalidate');
339 } else {
340 header('Cache-Control: private, must-revalidate');
341 }
342
343 // By default, frames allowed only if on same domain (stop some XSS attacks)
344 header("X-Frame-Options: SAMEORIGIN");
345
346 // Clean parameters
347 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
348 $result = readfile($outputfile);
349 if (!$result) {
350 dol_syslog("File ".$outputfile." was empty", LOG_WARNING); // The path of the file is not shown on this public page
351 print 'File was empty.';
352 }
353
354 // header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
355 exit;
356 } else {
357 top_httphead();
358
359 print 'Error '.$fichinterStatic->error;
360
361 exit;
362 }
363}
364
365
367
368print '<html><title>Export fichinter cal</title><body>';
369print '<div class="error">'.$fichinterStatic->error.'</div>';
370print '</body></html>';
371
372
373
374// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
385function build_exportfile($format, $type, $cachedelay, $filename, $filters)
386{
387
388 // some filters possible in the $filters array
389 // logina : user login who creates intervention (author)
390 // logini : user login who performs the intervention
391 // loginr : user login who is responsible for intervention
392
393 global $hookmanager;
394 global $db;
395
396 // phpcs:enable
397 global $conf, $langs, $dolibarr_main_url_root, $mysoc;
398
399 require_once DOL_DOCUMENT_ROOT."/core/lib/xcal.lib.php";
400 require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
401 require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
402
403 dol_syslog("build_exportfile Build export file format=".$format.", type=".$type.", cachedelay=".$cachedelay.", filename=".$filename.", filters size=".count($filters), LOG_DEBUG);
404
405 // Check parameters
406 if (empty($format)) {
407 return -1;
408 }
409
410 // Clean parameters
411 if (!$filename) {
412 $extension = 'vcs';
413 if ($format == 'ical') {
414 $extension = 'ics';
415 }
416 $filename = $format.'.'.$extension;
417 }
418
419 // Create dir and define output file (definitive and temporary)
420 $result = dol_mkdir($conf->agenda->dir_temp);
421 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
422
423 $result = 0;
424
425 $buildfile = true;
426 $login = '';
427 $logina = '';
428 $logini = '';
429 $loginr = '';
430
431 $eventorganization = '';
432
433 $now = dol_now();
434
435 if ($cachedelay) {
436 $nowgmt = dol_now();
437 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
438 if (dol_filemtime($outputfile) > ($nowgmt - $cachedelay)) {
439 dol_syslog("build_exportfile file ".$outputfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay."). Build is canceled");
440 $buildfile = false;
441 }
442 }
443
444 if ($buildfile) {
445 // Build event array
446 $eventarray = array();
447
448 $sql = "SELECT f.rowid,";
449 $sql .= " fd.date,"; // We get the date and the duration from the detail of the interventaion as well as the hour
450 $sql .= " f.datee,"; // End will not be used
451 $sql .= " fd.duree,"; // Duration of the intervention
452 $sql .= " f.datec, f.tms as datem,";
453 $sql .= " f.ref, f.ref_client, fd.description, f.note_private, f.note_public,";
454 $sql .= " f.fk_soc,";
455 $sql .= " f.fk_user_author, f.fk_user_modif,";
456 $sql .= " f.fk_user_valid,";
457 $sql .= " u.firstname, u.lastname, u.email,";
458 $sql .= " p.ref as ref_project, c.ref as ref_contract,";
459 $sql .= " s.nom as socname, f.fk_statut";
460
461 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
462 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."fichinterdet as fd ON f.rowid = fd.fk_fichinter";
463 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = f.fk_user_author";
464
465 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = f.fk_soc";
466 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p on p.rowid = f.fk_projet";
467 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contrat as c on c.rowid = f.fk_contrat";
468
469 $parameters = array('filters' => $filters);
470 // Note that $action and $object may have been modified by hook
471 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters);
472 $sql .= $hookmanager->resPrint;
473
474 $sql .= " WHERE f.entity IN (".getEntity('fichinter').")";
475
476 foreach ($filters as $key => $value) {
477 if ($key == 'notolderthan' && $value != '') {
478 $sql .= " AND fd.date >= '".$db->idate($now - ($value * 24 * 60 * 60))."'";
479 }
480 if ($key == 'year') {
481 $sql .= " AND fd.date BETWEEN '".$db->idate(dol_get_first_day($value, 1))."'";
482 $sql .= " AND '".$db->idate(dol_get_last_day($value, 12))."'";
483 }
484 if ($key == 'id') {
485 $sql .= " AND f.rowid = ".((int) $value);
486 }
487 if ($key == 'idfrom') {
488 $sql .= " AND f.rowid >= ".((int) $value);
489 }
490 if ($key == 'idto') {
491 $sql .= " AND f.rowid <= ".((int) $value);
492 }
493 if ($key == 'project') {
494 $sql .= " AND f.fk_project = ".((int) $value);
495 }
496 if ($key == 'contract') {
497 $sql .= " AND f.fk_contract = ".((int) $value);
498 }
499
500 if ($key == 'logina') {
501 $logina = $value;
502 $sanitizedcondition = '=';
503 if (preg_match('/^!/', $logina)) {
504 $logina = preg_replace('/^!/', '', $logina);
505 $sanitizedcondition = '<>';
506 }
507 $userforfilter = new User($db);
508 $result = $userforfilter->fetch(0, $logina);
509 if ($result > 0) {
510 $sql .= " AND a.fk_user_author ".$sanitizedcondition." ".((int) $userforfilter->id);
511 } elseif ($result < 0 || $sanitizedcondition == '=') {
512 $sql .= " AND a.fk_user_author = 0";
513 }
514 }
515 if ($key == 'logini') {
516 $logini = $value;
517 $sanitizedcondition = '=';
518 if (preg_match('/^!/', $logini)) {
519 $logini = preg_replace('/^!/', '', $logini);
520 $sanitizedcondition = '<>';
521 }
522 $userforfilter = new User($db);
523 $result = $userforfilter->fetch(0, $logini);
524 $sql .= " AND EXISTS (SELECT ec.rowid FROM ".MAIN_DB_PREFIX."element_contact as ec";
525 $sql .= " WHERE ec.element_id = f.rowid";
526 $sql .= " AND ec.fk_c_type_contact = 26"; // FIXME do not use hardcoded ID
527 if ($result > 0) {
528 $sql .= " AND ec.fk_socpeople = ".((int) $userforfilter->id);
529 } elseif ($result < 0 || $sanitizedcondition == '=') {
530 $sql .= " AND ec.fk_socpeople = 0";
531 }
532 $sql .= ")";
533 }
534 if ($key == 'loginr') {
535 $loginr = $value;
536 $sanitizedcondition = '=';
537 if (preg_match('/^!/', $loginr)) {
538 $loginr = preg_replace('/^!/', '', $loginr);
539 $sanitizedcondition = '<>';
540 }
541 $userforfilter = new User($db);
542 $result = $userforfilter->fetch(0, $loginr);
543 $sql .= " AND EXISTS (SELECT ecr.rowid FROM ".MAIN_DB_PREFIX."element_contact as ecr";
544 $sql .= " WHERE ecr.element_id = f.rowid";
545 $sql .= " WHERE AND ecr.fk_c_type_contact = 27"; // FIXME do not use hardcoded ID
546 if ($result > 0) {
547 $sql .= " AND ecr.fk_socpeople = ".((int) $userforfilter->id);
548 } elseif ($result < 0 || $sanitizedcondition == '=') {
549 $sql .= " AND ecr.fk_socpeople = 0";
550 }
551 $sql .= ")";
552 }
553
554 if ($key == 'status') {
555 $sql .= " AND f.fk_statut = ".((int) $value);
556 }
557 }
558
559 // To exclude corrupted events and avoid errors in lightning/sunbird import
560 $sql .= " AND f.dateo IS NOT NULL";
561
562 $parameters = array('filters' => $filters);
563 // Note that $action and $object may have been modified by hook
564 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters);
565 $sql .= $hookmanager->resPrint;
566
567 $sql .= " ORDER by fd.date";
568
569
570 if (!empty($filters['limit'])) {
571 $sql .= $db->plimit((int) $filters['limit']);
572 }
573
574 // print $sql;exit;
575
576 dol_syslog("build_exportfile select event(s)", LOG_DEBUG);
577
578 $resql = $db->query($sql);
579 if ($resql) {
580 $diff = 0;
581 while ($obj = $db->fetch_object($resql)) {
582 $qualified = true;
583
584 // 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author'
585 $event = array();
586 $event['uid'] = 'dolibarragenda-'.$db->database_name.'-'.$obj->id."@".$_SERVER["SERVER_NAME"];
587 $event['type'] = $type;
588
589 $datestart = $db->jdate($obj->date) - ((int) getDolGlobalString('MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
590
591 // fix for -> Warning: A non-numeric value encountered
592 // if (is_numeric($db->jdate($obj->datee))) {
593 // $dateend = $db->jdate($obj->datee) - ((int) getDolGlobalString('MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
594 // } else {
595 // // use start date as fall-back to avoid pb with empty end date on ICS readers
596 // $dateend = $datestart;
597 // }
598
599 $duration = $obj->duree;
600 $event['location'] = ($obj->socname ? $obj->socname : "");
601 $event['summary'] = $obj->ref." - ". $obj->description;
602 if ($obj->ref_client)
603 $event['summary'].= " (".$obj->ref_client.")";
604
605 $event['desc'] = $obj->description;
606
607 if ($obj->ref_project)
608 $event['desc'] .= " - ".$obj->ref_project;
609
610 if ($obj->ref_contract)
611 $event['desc'] .= " - ".$obj->ref_contract;
612
613 if ($obj->note_public)
614 $event['desc'].= " - ".$obj->note_public;
615
616 $event['startdate'] = $datestart;
617 $event['enddate'] = ''; // $dateend; // Not required with type 'journal'
618 $event['duration'] = $duration; // Not required with type 'journal'
619 $event['author'] = dolGetFirstLastname($obj->firstname, $obj->lastname);
620
621 // OPAQUE (busy) or TRANSPARENT (not busy)
622 //$event['transparency'] = (($obj->transparency > 0) ? 'OPAQUE' : 'TRANSPARENT');
623 //$event['category'] = $obj->type_label;
624 $event['email'] = $obj->email;
625
626 // Public URL of event
627 if ($eventorganization != '') {
628 $link_subscription = $dolibarr_main_url_root.'/public/eventorganization/attendee_new.php?id='.((int) $obj->id).'&type=global&noregistration=1';
629 $encodedsecurekey = dol_hash(getDolGlobalString('EVENTORGANIZATION_SECUREKEY').'conferenceorbooth'.((int) $obj->id), 'md5');
630 $link_subscription .= '&securekey='.urlencode($encodedsecurekey);
631
632 //$event['url'] = $link_subscription;
633 }
634
635 $event['created'] = $db->jdate($obj->datec) - ((int) getDolGlobalString('MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
636 $event['modified'] = $db->jdate($obj->datem) - ((int) getDolGlobalString('MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
637 // $event['num_vote'] = $this->num_vote;
638 // $event['event_paid'] = $this->event_paid;
639 $event['status'] = $obj->fk_statut;
640
641 // // TODO: find a way to call "$this->fetch_userassigned();" without overriding "$this" properties
642 // $this->id = $obj->rowid;
643 // $this->fetch_userassigned(false);
644
645 // $assignedUserArray = array();
646
647 // foreach ($this->userassigned as $key => $value) {
648 // $assignedUser = new User($db);
649 // $assignedUser->fetch($value['id']);
650
651 // $assignedUserArray[$key] = $assignedUser;
652 // }
653
654 // $event['assignedUsers'] = $assignedUserArray;
655
656 if ($qualified && $datestart) {
657 $eventarray[] = $event;
658 }
659 $diff++;
660 }
661
662 $parameters = array('filters' => $filters, 'eventarray' => &$eventarray);
663 // Note that $action and $object may have been modified by hook
664 $reshook = $hookmanager->executeHooks('addMoreEventsExport', $parameters);
665 if ($reshook > 0) {
666 $eventarray = $hookmanager->resArray;
667 }
668 } else {
669 print $db->lasterror();
670 return -1;
671 }
672
673 $langs->load("agenda");
674
675 // Define title and desc
676 $title = '';
677 $more = '';
678 if ($login) {
679 $more = $langs->transnoentities("User").' '.$login;
680 }
681 if ($logina) {
682 $more = $langs->transnoentities("ActionsAskedBy").' '.$logina;
683 }
684 if ($logini) {
685 $more = $langs->transnoentities("ActionsToDoBy").' '.$logini;
686 }
687 if ($eventorganization) {
688 $langs->load("eventorganization");
689 $title = $langs->transnoentities("OrganizedEvent").(empty($eventarray[0]['label']) ? '' : ' '.$eventarray[0]['label']);
690 $more = 'ICS file - '.$langs->transnoentities("OrganizedEvent").(empty($eventarray[0]['label']) ? '' : ' '.$eventarray[0]['label']);
691 }
692 if ($more) {
693 if (empty($title)) {
694 $title = 'Dolibarr actions '.$mysoc->name.' - '.$more;
695 }
696 $desc = $more;
697 $desc .= ' ('.$mysoc->name.' - built by Dolibarr)';
698 } else {
699 if (empty($title)) {
700 $title = 'Dolibarr actions '.$mysoc->name;
701 }
702 $desc = $langs->transnoentities('ListOfActions');
703 $desc .= ' ('.$mysoc->name.' - built by Dolibarr)';
704 }
705
706 // Create temp file
707 // Temporary file (allows calling the function by different threads
708 $outputfiletmp = tempnam($conf->fichinter->dir_temp, 'tmp');
709 dolChmod($outputfiletmp);
710
711 // Write file
712 if ($format == 'vcal') {
713 $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
714 } elseif ($format == 'ical') {
715 $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
716 } elseif ($format == 'rss') {
717 $result = build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
718 }
719
720 if ($result >= 0) {
721 if (dol_move($outputfiletmp, $outputfile, '0', 1, 0, 0)) {
722 $result = 1;
723 } else {
724 $error = 'Failed to rename '.$outputfiletmp.' into '.$outputfile;
725 dol_syslog("build_exportfile ".$error, LOG_ERR);
726 dol_delete_file($outputfiletmp, 0, 1);
727 $result = -1;
728 }
729 } else {
730 dol_syslog("build_exportfile build_xxxfile function fails to for format=".$format." outputfiletmp=".$outputfile, LOG_ERR);
731 dol_delete_file($outputfiletmp, 0, 1);
732 $langs->load("errors");
733 $error = $langs->trans("ErrorFailToCreateFile", $outputfile);
734 }
735 }
736 return $result;
737}
global $dolibarr_main_url_root
Class to manage Dolibarr users.
global $mysoc
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:616
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:635
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=null)
Move a file into another name.
dol_filemtime($pathoffile)
Return time of a file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_now($mode='gmt')
Return date for now.
dolChmod($filepath, $newmask='')
Change mod of a file.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
build_calfile($format, $title, $desc, $events_array, $outputfile)
Build a file from an array of events All input params and data must be encoded in $conf->charset_outp...
Definition xcal.lib.php:36
build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter='', $url='', $langcode='', $useurlforguid=false)
Build a file from an array of events.
Definition xcal.lib.php:325