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