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