dolibarr 24.0.3
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") || !hash_equals(getDolGlobalString('MAIN_FICHINTER_XCAL_EXPORTKEY'), (string) 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->ficheinter->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 // Ajout directives pour resoudre bug IE
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->ficheinter->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->ficheinter->dir_temp);
421 $outputfile = $conf->ficheinter->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_projet = ".((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 f.fk_user_author ".$sanitizedcondition." ".((int) $userforfilter->id);
511 } elseif ($result < 0 || $sanitizedcondition == '=') {
512 $sql .= " AND f.fk_user_author = 0";
513 }
514 }
515 if ($key == 'logint') {
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 if ($result == 0 && $sanitizedcondition == '<>') {
525 continue; // Not assigned to an unknown user: no filter, as for logina
526 }
527 $sql .= " AND ".($sanitizedcondition == '<>' ? "NOT " : "")."EXISTS (SELECT ec.rowid FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc";
528 $sql .= " WHERE ec.element_id = f.rowid";
529 $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element = 'fichinter' AND tc.source = 'internal' AND tc.code = 'INTERVENING'";
530 if ($result > 0) {
531 $sql .= " AND ec.fk_socpeople = ".((int) $userforfilter->id);
532 } elseif ($result < 0 || $sanitizedcondition == '=') {
533 $sql .= " AND ec.fk_socpeople = 0";
534 }
535 $sql .= ")";
536 }
537 if ($key == 'loginr') {
538 $loginr = $value;
539 $sanitizedcondition = '=';
540 if (preg_match('/^!/', $loginr)) {
541 $loginr = preg_replace('/^!/', '', $loginr);
542 $sanitizedcondition = '<>';
543 }
544 $userforfilter = new User($db);
545 $result = $userforfilter->fetch(0, $loginr);
546 $sql .= " AND EXISTS (SELECT ecr.rowid FROM ".MAIN_DB_PREFIX."element_contact as ecr";
547 $sql .= " WHERE ecr.element_id = f.rowid";
548 $sql .= " WHERE AND ecr.fk_c_type_contact = 27"; // FIXME do not use hardcoded ID
549 if ($result > 0) {
550 $sql .= " AND ecr.fk_socpeople = ".((int) $userforfilter->id);
551 } elseif ($result < 0 || $sanitizedcondition == '=') {
552 $sql .= " AND ecr.fk_socpeople = 0";
553 }
554 $sql .= ")";
555 }
556
557 if ($key == 'status') {
558 $sql .= " AND f.fk_statut = ".((int) $value);
559 }
560 }
561
562 // To exclude corrupted events and avoid errors in lightning/sunbird import
563 $sql .= " AND f.dateo IS NOT NULL";
564
565 $parameters = array('filters' => $filters);
566 // Note that $action and $object may have been modified by hook
567 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters);
568 $sql .= $hookmanager->resPrint;
569
570 $sql .= " ORDER by fd.date";
571
572
573 if (!empty($filters['limit'])) {
574 $sql .= $db->plimit((int) $filters['limit']);
575 }
576
577 // print $sql;exit;
578
579 dol_syslog("build_exportfile select event(s)", LOG_DEBUG);
580
581 $resql = $db->query($sql);
582 if ($resql) {
583 $diff = 0;
584 while ($obj = $db->fetch_object($resql)) {
585 $qualified = true;
586
587 // 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author'
588 $event = array();
589 $event['uid'] = 'dolibarragenda-'.$db->database_name.'-'.$obj->id."@".$_SERVER["SERVER_NAME"];
590 $event['type'] = $type;
591
592 $datestart = $db->jdate($obj->date) - ((int) getDolGlobalString('MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
593
594 // fix for -> Warning: A non-numeric value encountered
595 // if (is_numeric($db->jdate($obj->datee))) {
596 // $dateend = $db->jdate($obj->datee) - ((int) getDolGlobalString('MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
597 // } else {
598 // // use start date as fall-back to avoid pb with empty end date on ICS readers
599 // $dateend = $datestart;
600 // }
601
602 $duration = $obj->duree;
603 $event['location'] = ($obj->socname ? $obj->socname : "");
604 $event['summary'] = $obj->ref." - ". $obj->description;
605 if ($obj->ref_client)
606 $event['summary'].= " (".$obj->ref_client.")";
607
608 $event['desc'] = $obj->description;
609
610 if ($obj->ref_project)
611 $event['desc'] .= " - ".$obj->ref_project;
612
613 if ($obj->ref_contract)
614 $event['desc'] .= " - ".$obj->ref_contract;
615
616 if ($obj->note_public)
617 $event['desc'].= " - ".$obj->note_public;
618
619 $event['startdate'] = $datestart;
620 $event['enddate'] = ''; // $dateend; // Not required with type 'journal'
621 $event['duration'] = $duration; // Not required with type 'journal'
622 $event['author'] = dolGetFirstLastname($obj->firstname, $obj->lastname);
623
624 // OPAQUE (busy) or TRANSPARENT (not busy)
625 //$event['transparency'] = (($obj->transparency > 0) ? 'OPAQUE' : 'TRANSPARENT');
626 //$event['category'] = $obj->type_label;
627 $event['email'] = $obj->email;
628
629 // Public URL of event
630 if ($eventorganization != '') {
631 $link_subscription = $dolibarr_main_url_root.'/public/eventorganization/attendee_new.php?id='.((int) $obj->id).'&type=global&noregistration=1';
632 $encodedsecurekey = dol_hash(getDolGlobalString('EVENTORGANIZATION_SECUREKEY').'conferenceorbooth'.((int) $obj->id), 'md5');
633 $link_subscription .= '&securekey='.urlencode($encodedsecurekey);
634
635 //$event['url'] = $link_subscription;
636 }
637
638 $event['created'] = $db->jdate($obj->datec) - ((int) getDolGlobalString('MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
639 $event['modified'] = $db->jdate($obj->datem) - ((int) getDolGlobalString('MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
640 // $event['num_vote'] = $this->num_vote;
641 // $event['event_paid'] = $this->event_paid;
642 $event['status'] = $obj->fk_statut;
643
644 // // TODO: find a way to call "$this->fetch_userassigned();" without overriding "$this" properties
645 // $this->id = $obj->rowid;
646 // $this->fetch_userassigned(false);
647
648 // $assignedUserArray = array();
649
650 // foreach ($this->userassigned as $key => $value) {
651 // $assignedUser = new User($db);
652 // $assignedUser->fetch($value['id']);
653
654 // $assignedUserArray[$key] = $assignedUser;
655 // }
656
657 // $event['assignedUsers'] = $assignedUserArray;
658
659 if ($qualified && $datestart) {
660 $eventarray[] = $event;
661 }
662 $diff++;
663 }
664
665 $parameters = array('filters' => $filters, 'eventarray' => &$eventarray);
666 // Note that $action and $object may have been modified by hook
667 $reshook = $hookmanager->executeHooks('addMoreEventsExport', $parameters);
668 if ($reshook > 0) {
669 $eventarray = $hookmanager->resArray;
670 }
671 } else {
672 print $db->lasterror();
673 return -1;
674 }
675
676 $langs->load("agenda");
677
678 // Define title and desc
679 $title = '';
680 $more = '';
681 if ($login) {
682 $more = $langs->transnoentities("User").' '.$login;
683 }
684 if ($logina) {
685 $more = $langs->transnoentities("ActionsAskedBy").' '.$logina;
686 }
687 if ($logini) {
688 $more = $langs->transnoentities("ActionsToDoBy").' '.$logini;
689 }
690 if ($eventorganization) {
691 $langs->load("eventorganization");
692 $title = $langs->transnoentities("OrganizedEvent").(empty($eventarray[0]['label']) ? '' : ' '.$eventarray[0]['label']);
693 $more = 'ICS file - '.$langs->transnoentities("OrganizedEvent").(empty($eventarray[0]['label']) ? '' : ' '.$eventarray[0]['label']);
694 }
695 if ($more) {
696 if (empty($title)) {
697 $title = 'Dolibarr actions '.$mysoc->name.' - '.$more;
698 }
699 $desc = $more;
700 $desc .= ' ('.$mysoc->name.' - built by Dolibarr)';
701 } else {
702 if (empty($title)) {
703 $title = 'Dolibarr actions '.$mysoc->name;
704 }
705 $desc = $langs->transnoentities('ListOfActions');
706 $desc .= ' ('.$mysoc->name.' - built by Dolibarr)';
707 }
708
709 // Create temp file
710 // Temporary file (allows calling the function by different threads
711 $outputfiletmp = tempnam($conf->ficheinter->dir_temp, 'tmp');
712 dolChmod($outputfiletmp);
713
714 // Write file
715 if ($format == 'vcal') {
716 $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
717 } elseif ($format == 'ical') {
718 $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
719 } elseif ($format == 'rss') {
720 $result = build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
721 }
722
723 if ($result >= 0) {
724 if (dol_move($outputfiletmp, $outputfile, '0', 1, 0, 0)) {
725 $result = 1;
726 } else {
727 $error = 'Failed to rename '.$outputfiletmp.' into '.$outputfile;
728 dol_syslog("build_exportfile ".$error, LOG_ERR);
729 dol_delete_file($outputfiletmp, 0, 1);
730 $result = -1;
731 }
732 } else {
733 dol_syslog("build_exportfile build_xxxfile function fails to for format=".$format." outputfiletmp=".$outputfile, LOG_ERR);
734 dol_delete_file($outputfiletmp, 0, 1);
735 $langs->load("errors");
736 $error = $langs->trans("ErrorFailToCreateFile", $outputfile);
737 }
738 }
739 return $result;
740}
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:620
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:639
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