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