dolibarr 24.0.0-beta
agendaexport.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2008-2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
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// It's a wrapper, so empty header
58
73function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [], $ws = '') // @phan-suppress-current-line PhanRedefineFunction
74{
75 print '<html><title>Export agenda cal</title><body>';
76}
84function llxFooterVierge() // @phan-suppress-current-line PhanRedefineFunction
85{
86 print '</body></html>';
87}
88
89// For MultiCompany module.
90// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
91// Because 2 entities can have the same ref
92$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
93if (is_numeric($entity)) {
94 define("DOLENTITY", $entity);
95}
96
97// Load Dolibarr environment
98require '../../main.inc.php';
106require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
107
108$agenda = new ActionComm($db);
109
110
111// Define format, type and filter
112$format = 'ical';
113$type = 'event';
114if (GETPOST("format", 'alpha')) {
115 $format = GETPOST("format", 'alpha');
116}
117if (GETPOST("type", 'alpha')) {
118 $type = GETPOST("type", 'alpha');
119}
120
121$filters = array();
122if (GETPOSTINT("year")) {
123 $filters['year'] = GETPOSTINT("year");
124}
125if (GETPOSTINT("id")) {
126 $filters['id'] = GETPOSTINT("id");
127}
128if (GETPOSTINT("idfrom")) {
129 $filters['idfrom'] = GETPOSTINT("idfrom");
130}
131if (GETPOSTINT("idto")) {
132 $filters['idto'] = GETPOSTINT("idto");
133}
134if (GETPOST("project", 'alpha')) {
135 $filters['project'] = GETPOST("project", 'alpha');
136}
137if (GETPOST("logina", 'alpha')) {
138 $filters['logina'] = GETPOST("logina", 'alpha');
139}
140if (GETPOST("logint", 'alpha')) {
141 $filters['logint'] = GETPOST("logint", 'alpha');
142}
143if (GETPOST("notactiontype", 'alpha')) { // deprecated
144 $filters['notactiontype'] = GETPOST("notactiontype", 'alpha');
145}
146if (GETPOST("actiontype", 'alpha')) {
147 $filters['actiontype'] = GETPOST("actiontype", 'alpha');
148}
149if (GETPOST("actioncode", 'alpha')) {
150 $filters['actioncode'] = GETPOST("actioncode", 'alpha');
151}
152if (GETPOSTINT("notolderthan")) {
153 $filters['notolderthan'] = GETPOSTINT("notolderthan");
154} else {
155 $filters['notolderthan'] = getDolGlobalInt('MAIN_AGENDA_EXPORT_PAST_DELAY', 100);
156}
157// Max security limit by default to 1000
158if (GETPOSTINT("limit")) {
159 $filters['limit'] = GETPOSTINT("limit");
160} else {
161 $filters['limit'] = 1000;
162}
163if (GETPOST("module", 'alpha')) {
164 $filters['module'] = GETPOST("module", 'alpha');
165}
166if (GETPOST("status", "intcomma")) {
167 $filters['status'] = GETPOST("status", "intcomma");
168}
169
170// Security check
171if (!isModEnabled('agenda')) {
172 httponly_accessforbidden('Module Agenda not enabled');
173}
174
175
176/*
177 * View
178 */
179
180// Check config
181if (!getDolGlobalString('MAIN_AGENDA_XCAL_EXPORTKEY')) {
182 $user->loadRights();
183
184 top_httphead();
185
186 llxHeaderVierge("");
187 print '<div class="error">Module Agenda was not configured properly.</div>';
189 exit;
190}
191
192// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
193$hookmanager->initHooks(array('agendaexport'));
194
195$reshook = $hookmanager->executeHooks('doActions', $filters); // Note that $action and $object may have been modified by some
196if ($reshook < 0) {
197 top_httphead();
198
199 llxHeaderVierge("");
200 if (!empty($hookmanager->errors) && is_array($hookmanager->errors)) {
201 print '<div class="error">'.implode('<br>', $hookmanager->errors).'</div>';
202 } else {
203 print '<div class="error">'.$hookmanager->error.'</div>';
204 }
206} elseif (empty($reshook)) {
207 // Check exportkey
208 if (!GETPOST("exportkey") || getDolGlobalString('MAIN_AGENDA_XCAL_EXPORTKEY') != GETPOST("exportkey")) {
209 $user->loadRights();
210
211 top_httphead();
212
213 llxHeaderVierge("");
214 print '<div class="error">Bad value for key.</div>';
216 exit;
217 }
218}
219
220
221// Define filename with prefix on filters predica (each predica set must have on cache file)
222$shortfilename = 'calendar';
223$filename = $shortfilename;
224// Complete long filename
225foreach ($filters as $key => $value) {
226 //if ($key == 'notolderthan') $filename.='-notolderthan'.$value; This filter key is already added before and does not need to be in filename
227 if ($key == 'year') {
228 $filename .= '-year'.$value;
229 }
230 if ($key == 'id') {
231 $filename .= '-id'.$value;
232 }
233 if ($key == 'idfrom') {
234 $filename .= '-idfrom'.$value;
235 }
236 if ($key == 'idto') {
237 $filename .= '-idto'.$value;
238 }
239 if ($key == 'project') {
240 $filename .= '-project'.$value;
241 $shortfilename .= '-project'.$value;
242 }
243 if ($key == 'logina') {
244 $filename .= '-logina'.$value; // Author
245 }
246 if ($key == 'logint') {
247 $filename .= '-logint'.$value; // Assigned to
248 }
249 if ($key == 'notactiontype') { // deprecated
250 $filename .= '-notactiontype'.$value;
251 }
252 if ($key == 'actiontype') {
253 $filename .= '-actiontype'.$value;
254 }
255 if ($key == 'actioncode') {
256 $filename .= '-actioncode'.$value;
257 }
258 if ($key == 'module') {
259 $filename .= '-module'.$value;
260 if ($value == 'project@eventorganization') {
261 $shortfilename .= '-project';
262 } elseif ($value == 'conforbooth@eventorganization') {
263 $shortfilename .= '-conforbooth';
264 }
265 }
266 if ($key == 'status') {
267 $filename .= '-status'.$value;
268 }
269}
270// Add extension
271if ($format == 'vcal') {
272 $shortfilename .= '.vcs';
273 $filename .= '.vcs';
274}
275if ($format == 'ical') {
276 $shortfilename .= '.ics';
277 $filename .= '.ics';
278}
279if ($format == 'rss') {
280 $shortfilename .= '.rss';
281 $filename .= '.rss';
282}
283if ($shortfilename == 'dolibarrcalendar') {
284 $langs->load("errors");
285
286 top_httphead();
287
288 llxHeaderVierge("");
289 print '<div class="error">'.$langs->trans("ErrorWrongValueForParameterX", 'format').'</div>';
291 exit;
292}
293
294
295$cachedelay = 0;
296if (getDolGlobalString('MAIN_AGENDA_EXPORT_CACHE')) {
297 $cachedelay = getDolGlobalString('MAIN_AGENDA_EXPORT_CACHE');
298}
299
300$exportholidays = GETPOSTINT('includeholidays');
301
302// Build file
303if ($format == 'ical' || $format == 'vcal') {
304 // For export of conforbooth, we disable the filter 'notolderthan'
305 if (!empty($filters['project']) && !empty($filters['module']) && ($filters['module'] == 'project@eventorganization' || $filters['module'] == 'conforbooth@eventorganization')) {
306 $filters['notolderthan'] = null;
307 }
308
309 $result = $agenda->build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholidays);
310 if ($result >= 0) {
311 $attachment = true;
312 if (GETPOSTISSET("attachment")) {
313 $attachment = GETPOST("attachment");
314 }
315 //$attachment = false;
316 $contenttype = 'text/calendar';
317 if (GETPOSTISSET("contenttype")) {
318 $contenttype = GETPOST("contenttype");
319 }
320 //$contenttype='text/plain';
321 $outputencoding = 'UTF-8';
322
323 if ($contenttype) {
324 header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
325 }
326 if ($attachment) {
327 header('Content-Disposition: attachment; filename="'.$shortfilename.'"');
328 }
329
330 if ($cachedelay) {
331 header('Cache-Control: max-age='.$cachedelay.', private, must-revalidate');
332 } else {
333 header('Cache-Control: private, must-revalidate');
334 }
335
336 header("X-Frame-Options: SAMEORIGIN"); // By default, frames allowed only if on same domain (stop some XSS attacks)
337
338 // Clean parameters
339 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
340 $result = readfile($outputfile);
341 if (!$result) {
342 print 'File '.$outputfile.' was empty.';
343 }
344
345 //header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
346 exit;
347 } else {
348 top_httphead();
349
350 print 'Error '.$agenda->error;
351
352 exit;
353 }
354}
355
356if ($format == 'rss') {
357 $result = $agenda->build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholidays);
358 if ($result >= 0) {
359 $attachment = false;
360 if (GETPOSTISSET("attachment")) {
361 $attachment = GETPOST("attachment");
362 }
363 //$attachment = false;
364 $contenttype = 'application/rss+xml';
365 if (GETPOSTISSET("contenttype")) {
366 $contenttype = GETPOST("contenttype");
367 }
368 //$contenttype='text/plain';
369 $outputencoding = 'UTF-8';
370
371 if ($contenttype) {
372 header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
373 }
374 if ($attachment) {
375 header('Content-Disposition: attachment; filename="'.$filename.'"');
376 } else {
377 header('Content-Disposition: inline; filename="'.$filename.'"');
378 }
379
380 // Ajout directives pour resoudre bug IE
381 //header('Cache-Control: Public, must-revalidate');
382 //header('Pragma: public');
383 if ($cachedelay) {
384 header('Cache-Control: max-age='.$cachedelay.', private, must-revalidate');
385 } else {
386 header('Cache-Control: private, must-revalidate');
387 }
388
389 header("X-Frame-Options: SAMEORIGIN"); // By default, frames allowed only if on same domain (stop some XSS attacks)
390
391 // Clean parameters
392 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
393 $result = readfile($outputfile);
394 if (!$result) {
395 print 'File '.$outputfile.' was empty.';
396 }
397
398 // header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
399 exit;
400 } else {
401 top_httphead();
402
403 print 'Error '.$agenda->error;
404
405 exit;
406 }
407}
408
409
411
413print '<div class="error">'.$agenda->error.'</div>';
if(!defined( 'NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined( 'NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined( 'NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined( 'NOIPCHECK')) llxHeaderVierge($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[], $ws='')
Header function.
llxFooterVierge()
Footer function.
Class to manage agenda events (actions)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
isModEnabled($module)
Is Dolibarr module enabled.
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.