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