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