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