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 if (GETPOSTISSET("contenttype")) {
268 $contenttype = GETPOST("contenttype");
269 }
270 //$contenttype='text/plain';
271 $outputencoding = 'UTF-8';
272
273 if ($contenttype) {
274 header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
275 }
276 if ($attachment) {
277 header('Content-Disposition: attachment; filename="'.$shortfilename.'"');
278 }
279
280 if ($cachedelay) {
281 header('Cache-Control: max-age='.$cachedelay.', private, must-revalidate');
282 } else {
283 header('Cache-Control: private, must-revalidate');
284 }
285
286 // By default, frames allowed only if on same domain (stop some XSS attacks)
287 header("X-Frame-Options: SAMEORIGIN");
288
289 // Clean parameters
290 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
291 $result = readfile($outputfile);
292 if (!$result) {
293 print 'File '.$outputfile.' was empty.';
294 }
295
296 //header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
297 exit;
298 } else {
299 top_httphead();
300
301 print 'Error '.$fichinterStatic->error;
302
303 exit;
304 }
305}
306
307if ($format == 'rss') {
308 $result = build_exportfile($format, $type, $cachedelay, $filename, $filters);
309 if ($result >= 0) {
310 $attachment = false;
311 if (GETPOSTISSET("attachment")) {
312 $attachment = GETPOST("attachment");
313 }
314 //$attachment = false;
315 $contenttype = 'application/rss+xml';
316 if (GETPOSTISSET("contenttype")) {
317 $contenttype = GETPOST("contenttype");
318 }
319 //$contenttype='text/plain';
320 $outputencoding = 'UTF-8';
321
322 if ($contenttype) {
323 header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
324 }
325 if ($attachment) {
326 header('Content-Disposition: attachment; filename="'.$filename.'"');
327 } else {
328 header('Content-Disposition: inline; filename="'.$filename.'"');
329 }
330
331 // Ajout directives pour resoudre bug IE
332 //header('Cache-Control: Public, must-revalidate');
333 //header('Pragma: public');
334 if ($cachedelay) {
335 header('Cache-Control: max-age='.$cachedelay.', private, must-revalidate');
336 } else {
337 header('Cache-Control: private, must-revalidate');
338 }
339
340 // By default, frames allowed only if on same domain (stop some XSS attacks)
341 header("X-Frame-Options: SAMEORIGIN");
342
343 // Clean parameters
344 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
345 $result = readfile($outputfile);
346 if (!$result) {
347 print 'File '.$outputfile.' was empty.';
348 }
349
350 // header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
351 exit;
352 } else {
353 top_httphead();
354
355 print 'Error '.$fichinterStatic->error;
356
357 exit;
358 }
359}
360
361
363
364print '<html><title>Export fichinter cal</title><body>';
365print '<div class="error">'.$fichinterStatic->error.'</div>';
366print '</body></html>';
367
368
369
370// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
381function build_exportfile($format, $type, $cachedelay, $filename, $filters)
382{
383
384 // some filters possible in the $filters array
385 // logina : user login who creates intervention (author)
386 // logini : user login who performs the intervention
387 // loginr : user login who is responsible for intervention
388
389 global $hookmanager;
390 global $db;
391
392 // phpcs:enable
393 global $conf, $langs, $dolibarr_main_url_root, $mysoc;
394
395 require_once DOL_DOCUMENT_ROOT."/core/lib/xcal.lib.php";
396 require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
397 require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
398
399 dol_syslog("build_exportfile Build export file format=".$format.", type=".$type.", cachedelay=".$cachedelay.", filename=".$filename.", filters size=".count($filters), LOG_DEBUG);
400
401 // Check parameters
402 if (empty($format)) {
403 return -1;
404 }
405
406 // Clean parameters
407 if (!$filename) {
408 $extension = 'vcs';
409 if ($format == 'ical') {
410 $extension = 'ics';
411 }
412 $filename = $format.'.'.$extension;
413 }
414
415 // Create dir and define output file (definitive and temporary)
416 $result = dol_mkdir($conf->agenda->dir_temp);
417 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
418
419 $result = 0;
420
421 $buildfile = true;
422 $login = '';
423 $logina = '';
424 $logini = '';
425 $loginr = '';
426
427 $eventorganization = '';
428
429 $now = dol_now();
430
431 if ($cachedelay) {
432 $nowgmt = dol_now();
433 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
434 if (dol_filemtime($outputfile) > ($nowgmt - $cachedelay)) {
435 dol_syslog("build_exportfile file ".$outputfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay."). Build is canceled");
436 $buildfile = false;
437 }
438 }
439
440 if ($buildfile) {
441 // Build event array
442 $eventarray = array();
443
444 $sql = "SELECT f.rowid,";
445 $sql .= " fd.date,"; // We get the date and the duration from the detail of the interventaion as well as the hour
446 $sql .= " f.datee,"; // End will not be used
447 $sql .= " fd.duree,"; // Duration of the intervention
448 $sql .= " f.datec, f.tms as datem,";
449 $sql .= " f.ref, f.ref_client, fd.description, f.note_private, f.note_public,";
450 $sql .= " f.fk_soc,";
451 $sql .= " f.fk_user_author, f.fk_user_modif,";
452 $sql .= " f.fk_user_valid,";
453 $sql .= " u.firstname, u.lastname, u.email,";
454 $sql .= " p.ref as ref_project, c.ref as ref_contract,";
455 $sql .= " s.nom as socname, f.fk_statut";
456
457 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
458 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."fichinterdet as fd ON f.rowid = fd.fk_fichinter";
459 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = f.fk_user_author";
460
461 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = f.fk_soc";
462 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p on p.rowid = f.fk_projet";
463 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contrat as c on c.rowid = f.fk_contrat";
464
465 $parameters = array('filters' => $filters);
466 // Note that $action and $object may have been modified by hook
467 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters);
468 $sql .= $hookmanager->resPrint;
469
470 $sql .= " WHERE f.entity IN (".getEntity('fichinter').")";
471
472 foreach ($filters as $key => $value) {
473 if ($key == 'notolderthan' && $value != '') {
474 $sql .= " AND fd.date >= '".$db->idate($now - ($value * 24 * 60 * 60))."'";
475 }
476 if ($key == 'year') {
477 $sql .= " AND fd.date BETWEEN '".$db->idate(dol_get_first_day($value, 1))."'";
478 $sql .= " AND '".$db->idate(dol_get_last_day($value, 12))."'";
479 }
480 if ($key == 'id') {
481 $sql .= " AND f.rowid = ".((int) $value);
482 }
483 if ($key == 'idfrom') {
484 $sql .= " AND f.rowid >= ".((int) $value);
485 }
486 if ($key == 'idto') {
487 $sql .= " AND f.rowid <= ".((int) $value);
488 }
489 if ($key == 'project') {
490 $sql .= " AND f.fk_project = ".((int) $value);
491 }
492 if ($key == 'contract') {
493 $sql .= " AND f.fk_contract = ".((int) $value);
494 }
495
496 if ($key == 'logina') {
497 $logina = $value;
498 $sanitizedcondition = '=';
499 if (preg_match('/^!/', $logina)) {
500 $logina = preg_replace('/^!/', '', $logina);
501 $sanitizedcondition = '<>';
502 }
503 $userforfilter = new User($db);
504 $result = $userforfilter->fetch(0, $logina);
505 if ($result > 0) {
506 $sql .= " AND a.fk_user_author ".$sanitizedcondition." ".((int) $userforfilter->id);
507 } elseif ($result < 0 || $sanitizedcondition == '=') {
508 $sql .= " AND a.fk_user_author = 0";
509 }
510 }
511 if ($key == 'logini') {
512 $logini = $value;
513 $sanitizedcondition = '=';
514 if (preg_match('/^!/', $logini)) {
515 $logini = preg_replace('/^!/', '', $logini);
516 $sanitizedcondition = '<>';
517 }
518 $userforfilter = new User($db);
519 $result = $userforfilter->fetch(0, $logini);
520 $sql .= " AND EXISTS (SELECT ec.rowid FROM ".MAIN_DB_PREFIX."element_contact as ec";
521 $sql .= " WHERE ec.element_id = f.rowid";
522 $sql .= " AND ec.fk_c_type_contact = 26"; // FIXME do not use hardcoded ID
523 if ($result > 0) {
524 $sql .= " AND ec.fk_socpeople = ".((int) $userforfilter->id);
525 } elseif ($result < 0 || $sanitizedcondition == '=') {
526 $sql .= " AND ec.fk_socpeople = 0";
527 }
528 $sql .= ")";
529 }
530 if ($key == 'loginr') {
531 $loginr = $value;
532 $sanitizedcondition = '=';
533 if (preg_match('/^!/', $loginr)) {
534 $loginr = preg_replace('/^!/', '', $loginr);
535 $sanitizedcondition = '<>';
536 }
537 $userforfilter = new User($db);
538 $result = $userforfilter->fetch(0, $loginr);
539 $sql .= " AND EXISTS (SELECT ecr.rowid FROM ".MAIN_DB_PREFIX."element_contact as ecr";
540 $sql .= " WHERE ecr.element_id = f.rowid";
541 $sql .= " WHERE AND ecr.fk_c_type_contact = 27"; // FIXME do not use hardcoded ID
542 if ($result > 0) {
543 $sql .= " AND ecr.fk_socpeople = ".((int) $userforfilter->id);
544 } elseif ($result < 0 || $sanitizedcondition == '=') {
545 $sql .= " AND ecr.fk_socpeople = 0";
546 }
547 $sql .= ")";
548 }
549
550 if ($key == 'status') {
551 $sql .= " AND f.fk_statut = ".((int) $value);
552 }
553 }
554
555 // To exclude corrupted events and avoid errors in lightning/sunbird import
556 $sql .= " AND f.dateo IS NOT NULL";
557
558 $parameters = array('filters' => $filters);
559 // Note that $action and $object may have been modified by hook
560 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters);
561 $sql .= $hookmanager->resPrint;
562
563 $sql .= " ORDER by fd.date";
564
565
566 if (!empty($filters['limit'])) {
567 $sql .= $db->plimit((int) $filters['limit']);
568 }
569
570 // print $sql;exit;
571
572 dol_syslog("build_exportfile select event(s)", LOG_DEBUG);
573
574 $resql = $db->query($sql);
575 if ($resql) {
576 $diff = 0;
577 while ($obj = $db->fetch_object($resql)) {
578 $qualified = true;
579
580 // 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author'
581 $event = array();
582 $event['uid'] = 'dolibarragenda-'.$db->database_name.'-'.$obj->id."@".$_SERVER["SERVER_NAME"];
583 $event['type'] = $type;
584
585 $datestart = $db->jdate($obj->date) - ((int) getDolGlobalString('MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
586
587 // fix for -> Warning: A non-numeric value encountered
588 // if (is_numeric($db->jdate($obj->datee))) {
589 // $dateend = $db->jdate($obj->datee) - ((int) getDolGlobalString('MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
590 // } else {
591 // // use start date as fall-back to avoid pb with empty end date on ICS readers
592 // $dateend = $datestart;
593 // }
594
595 $duration = $obj->duree;
596 $event['location'] = ($obj->socname ? $obj->socname : "");
597 $event['summary'] = $obj->ref." - ". $obj->description;
598 if ($obj->ref_client)
599 $event['summary'].= " (".$obj->ref_client.")";
600
601 $event['desc'] = $obj->description;
602
603 if ($obj->ref_project)
604 $event['desc'] .= " - ".$obj->ref_project;
605
606 if ($obj->ref_contract)
607 $event['desc'] .= " - ".$obj->ref_contract;
608
609 if ($obj->note_public)
610 $event['desc'].= " - ".$obj->note_public;
611
612 $event['startdate'] = $datestart;
613 $event['enddate'] = ''; // $dateend; // Not required with type 'journal'
614 $event['duration'] = $duration; // Not required with type 'journal'
615 $event['author'] = dolGetFirstLastname($obj->firstname, $obj->lastname);
616
617 // OPAQUE (busy) or TRANSPARENT (not busy)
618 //$event['transparency'] = (($obj->transparency > 0) ? 'OPAQUE' : 'TRANSPARENT');
619 //$event['category'] = $obj->type_label;
620 $event['email'] = $obj->email;
621
622 // Public URL of event
623 if ($eventorganization != '') {
624 $link_subscription = $dolibarr_main_url_root.'/public/eventorganization/attendee_new.php?id='.((int) $obj->id).'&type=global&noregistration=1';
625 $encodedsecurekey = dol_hash(getDolGlobalString('EVENTORGANIZATION_SECUREKEY').'conferenceorbooth'.((int) $obj->id), 'md5');
626 $link_subscription .= '&securekey='.urlencode($encodedsecurekey);
627
628 //$event['url'] = $link_subscription;
629 }
630
631 $event['created'] = $db->jdate($obj->datec) - ((int) getDolGlobalString('MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
632 $event['modified'] = $db->jdate($obj->datem) - ((int) getDolGlobalString('MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
633 // $event['num_vote'] = $this->num_vote;
634 // $event['event_paid'] = $this->event_paid;
635 $event['status'] = $obj->fk_statut;
636
637 // // TODO: find a way to call "$this->fetch_userassigned();" without overriding "$this" properties
638 // $this->id = $obj->rowid;
639 // $this->fetch_userassigned(false);
640
641 // $assignedUserArray = array();
642
643 // foreach ($this->userassigned as $key => $value) {
644 // $assignedUser = new User($db);
645 // $assignedUser->fetch($value['id']);
646
647 // $assignedUserArray[$key] = $assignedUser;
648 // }
649
650 // $event['assignedUsers'] = $assignedUserArray;
651
652 if ($qualified && $datestart) {
653 $eventarray[] = $event;
654 }
655 $diff++;
656 }
657
658 $parameters = array('filters' => $filters, 'eventarray' => &$eventarray);
659 // Note that $action and $object may have been modified by hook
660 $reshook = $hookmanager->executeHooks('addMoreEventsExport', $parameters);
661 if ($reshook > 0) {
662 $eventarray = $hookmanager->resArray;
663 }
664 } else {
665 print $db->lasterror();
666 return -1;
667 }
668
669 $langs->load("agenda");
670
671 // Define title and desc
672 $title = '';
673 $more = '';
674 if ($login) {
675 $more = $langs->transnoentities("User").' '.$login;
676 }
677 if ($logina) {
678 $more = $langs->transnoentities("ActionsAskedBy").' '.$logina;
679 }
680 if ($logini) {
681 $more = $langs->transnoentities("ActionsToDoBy").' '.$logini;
682 }
683 if ($eventorganization) {
684 $langs->load("eventorganization");
685 $title = $langs->transnoentities("OrganizedEvent").(empty($eventarray[0]['label']) ? '' : ' '.$eventarray[0]['label']);
686 $more = 'ICS file - '.$langs->transnoentities("OrganizedEvent").(empty($eventarray[0]['label']) ? '' : ' '.$eventarray[0]['label']);
687 }
688 if ($more) {
689 if (empty($title)) {
690 $title = 'Dolibarr actions '.$mysoc->name.' - '.$more;
691 }
692 $desc = $more;
693 $desc .= ' ('.$mysoc->name.' - built by Dolibarr)';
694 } else {
695 if (empty($title)) {
696 $title = 'Dolibarr actions '.$mysoc->name;
697 }
698 $desc = $langs->transnoentities('ListOfActions');
699 $desc .= ' ('.$mysoc->name.' - built by Dolibarr)';
700 }
701
702 // Create temp file
703 // Temporary file (allows calling the function by different threads
704 $outputfiletmp = tempnam($conf->fichinter->dir_temp, 'tmp');
705 dolChmod($outputfiletmp);
706
707 // Write file
708 if ($format == 'vcal') {
709 $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
710 } elseif ($format == 'ical') {
711 $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
712 } elseif ($format == 'rss') {
713 $result = build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
714 }
715
716 if ($result >= 0) {
717 if (dol_move($outputfiletmp, $outputfile, '0', 1, 0, 0)) {
718 $result = 1;
719 } else {
720 $error = 'Failed to rename '.$outputfiletmp.' into '.$outputfile;
721 dol_syslog("build_exportfile ".$error, LOG_ERR);
722 dol_delete_file($outputfiletmp, 0, 1);
723 $result = -1;
724 }
725 } else {
726 dol_syslog("build_exportfile build_xxxfile function fails to for format=".$format." outputfiletmp=".$outputfile, LOG_ERR);
727 dol_delete_file($outputfiletmp, 0, 1);
728 $langs->load("errors");
729 $error = $langs->trans("ErrorFailToCreateFile", $outputfile);
730 }
731 }
732 return $result;
733}
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:605
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:624
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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