dolibarr 21.0.0-alpha
agendaexport.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2008-2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
32if (!defined('NOTOKENRENEWAL')) {
33 define('NOTOKENRENEWAL', '1');
34}
35if (!defined('NOREQUIREMENU')) {
36 define('NOREQUIREMENU', '1'); // If there is no menu to show
37}
38if (!defined('NOREQUIREHTML')) {
39 define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
40}
41if (!defined('NOREQUIREAJAX')) {
42 define('NOREQUIREAJAX', '1');
43}
44if (!defined('NOLOGIN')) {
45 define("NOLOGIN", 1); // This means this output page does not require to be logged.
46}
47if (!defined('NOCSRFCHECK')) {
48 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
49}
50if (!defined('NOIPCHECK')) {
51 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
52}
53
54
55// It's a wrapper, so empty header
56
63{
64 print '<html><title>Export agenda cal</title><body>';
65}
72{
73 print '</body></html>';
74}
75
76// For MultiCompany module.
77// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
78// Because 2 entities can have the same ref
79$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
80if (is_numeric($entity)) {
81 define("DOLENTITY", $entity);
82}
83
84// Load Dolibarr environment
85require '../../main.inc.php';
86require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
87
88$object = new ActionComm($db);
89
90// Not older than
91if (!getDolGlobalString('MAIN_AGENDA_EXPORT_PAST_DELAY')) {
92 $conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY = 100; // default limit
93}
94
95// Define format, type and filter
96$format = 'ical';
97$type = 'event';
98if (GETPOST("format", 'alpha')) {
99 $format = GETPOST("format", 'alpha');
100}
101if (GETPOST("type", 'alpha')) {
102 $type = GETPOST("type", 'alpha');
103}
104
105$filters = array();
106if (GETPOSTINT("year")) {
107 $filters['year'] = GETPOSTINT("year");
108}
109if (GETPOSTINT("id")) {
110 $filters['id'] = GETPOSTINT("id");
111}
112if (GETPOSTINT("idfrom")) {
113 $filters['idfrom'] = GETPOSTINT("idfrom");
114}
115if (GETPOSTINT("idto")) {
116 $filters['idto'] = GETPOSTINT("idto");
117}
118if (GETPOST("project", 'alpha')) {
119 $filters['project'] = GETPOST("project", 'alpha');
120}
121if (GETPOST("logina", 'alpha')) {
122 $filters['logina'] = GETPOST("logina", 'alpha');
123}
124if (GETPOST("logint", 'alpha')) {
125 $filters['logint'] = GETPOST("logint", 'alpha');
126}
127if (GETPOST("notactiontype", 'alpha')) { // deprecated
128 $filters['notactiontype'] = GETPOST("notactiontype", 'alpha');
129}
130if (GETPOST("actiontype", 'alpha')) {
131 $filters['actiontype'] = GETPOST("actiontype", 'alpha');
132}
133if (GETPOST("actioncode", 'alpha')) {
134 $filters['actioncode'] = GETPOST("actioncode", 'alpha');
135}
136if (GETPOSTINT("notolderthan")) {
137 $filters['notolderthan'] = GETPOSTINT("notolderthan");
138} else {
139 $filters['notolderthan'] = getDolGlobalString('MAIN_AGENDA_EXPORT_PAST_DELAY', 100);
140}
141if (GETPOSTINT("limit")) {
142 $filters['limit'] = GETPOSTINT("limit");
143} else {
144 $filters['limit'] = 1000;
145}
146if (GETPOST("module", 'alpha')) {
147 $filters['module'] = GETPOST("module", 'alpha');
148}
149if (GETPOST("status", "intcomma")) {
150 $filters['status'] = GETPOST("status", "intcomma");
151}
152
153// Security check
154if (!isModEnabled('agenda')) {
155 httponly_accessforbidden('Module Agenda not enabled');
156}
157
158
159/*
160 * View
161 */
162
163// Check config
164if (!getDolGlobalString('MAIN_AGENDA_XCAL_EXPORTKEY')) {
165 $user->getrights();
166
167 top_httphead();
168
170 print '<div class="error">Module Agenda was not configured properly.</div>';
172 exit;
173}
174
175// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
176$hookmanager->initHooks(array('agendaexport'));
177
178$reshook = $hookmanager->executeHooks('doActions', $filters); // Note that $action and $object may have been modified by some
179if ($reshook < 0) {
180 top_httphead();
181
183 if (!empty($hookmanager->errors) && is_array($hookmanager->errors)) {
184 print '<div class="error">'.implode('<br>', $hookmanager->errors).'</div>';
185 } else {
186 print '<div class="error">'.$hookmanager->error.'</div>';
187 }
189} elseif (empty($reshook)) {
190 // Check exportkey
191 if (!GETPOST("exportkey") || getDolGlobalString('MAIN_AGENDA_XCAL_EXPORTKEY') != GETPOST("exportkey")) {
192 $user->getrights();
193
194 top_httphead();
195
197 print '<div class="error">Bad value for key.</div>';
199 exit;
200 }
201}
202
203
204// Define filename with prefix on filters predica (each predica set must have on cache file)
205$shortfilename = 'dolibarrcalendar';
206$filename = $shortfilename;
207// Complete long filename
208foreach ($filters as $key => $value) {
209 //if ($key == 'notolderthan') $filename.='-notolderthan'.$value; This filter key is already added before and does not need to be in filename
210 if ($key == 'year') {
211 $filename .= '-year'.$value;
212 }
213 if ($key == 'id') {
214 $filename .= '-id'.$value;
215 }
216 if ($key == 'idfrom') {
217 $filename .= '-idfrom'.$value;
218 }
219 if ($key == 'idto') {
220 $filename .= '-idto'.$value;
221 }
222 if ($key == 'project') {
223 $filename .= '-project'.$value;
224 $shortfilename .= '-project'.$value;
225 }
226 if ($key == 'logina') {
227 $filename .= '-logina'.$value; // Author
228 }
229 if ($key == 'logint') {
230 $filename .= '-logint'.$value; // Assigned to
231 }
232 if ($key == 'notactiontype') { // deprecated
233 $filename .= '-notactiontype'.$value;
234 }
235 if ($key == 'actiontype') {
236 $filename .= '-actiontype'.$value;
237 }
238 if ($key == 'actioncode') {
239 $filename .= '-actioncode'.$value;
240 }
241 if ($key == 'module') {
242 $filename .= '-module'.$value;
243 if ($value == 'project@eventorganization') {
244 $shortfilename .= '-project';
245 } elseif ($value == 'conforbooth@eventorganization') {
246 $shortfilename .= '-conforbooth';
247 }
248 }
249 if ($key == 'status') {
250 $filename .= '-status'.$value;
251 }
252}
253// Add extension
254if ($format == 'vcal') {
255 $shortfilename .= '.vcs';
256 $filename .= '.vcs';
257}
258if ($format == 'ical') {
259 $shortfilename .= '.ics';
260 $filename .= '.ics';
261}
262if ($format == 'rss') {
263 $shortfilename .= '.rss';
264 $filename .= '.rss';
265}
266if ($shortfilename == 'dolibarrcalendar') {
267 $langs->load("errors");
268
269 top_httphead();
270
272 print '<div class="error">'.$langs->trans("ErrorWrongValueForParameterX", 'format').'</div>';
274 exit;
275}
276
277$agenda = new ActionComm($db);
278
279$cachedelay = 0;
280if (getDolGlobalString('MAIN_AGENDA_EXPORT_CACHE')) {
281 $cachedelay = getDolGlobalString('MAIN_AGENDA_EXPORT_CACHE');
282}
283
284$exportholidays = GETPOSTINT('includeholidays');
285
286// Build file
287if ($format == 'ical' || $format == 'vcal') {
288 // For export of conforbooth, we disable the filter 'notolderthan'
289 if (!empty($filters['project']) && !empty($filters['module']) && ($filters['module'] == 'project@eventorganization' || $filters['module'] == 'conforbooth@eventorganization')) {
290 $filters['notolderthan'] = null;
291 }
292
293 $result = $agenda->build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholidays);
294 if ($result >= 0) {
295 $attachment = true;
296 if (GETPOSTISSET("attachment")) {
297 $attachment = GETPOST("attachment");
298 }
299 //$attachment = false;
300 $contenttype = 'text/calendar';
301 if (GETPOSTISSET("contenttype")) {
302 $contenttype = GETPOST("contenttype");
303 }
304 //$contenttype='text/plain';
305 $outputencoding = 'UTF-8';
306
307 if ($contenttype) {
308 header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
309 }
310 if ($attachment) {
311 header('Content-Disposition: attachment; filename="'.$shortfilename.'"');
312 }
313
314 if ($cachedelay) {
315 header('Cache-Control: max-age='.$cachedelay.', private, must-revalidate');
316 } else {
317 header('Cache-Control: private, must-revalidate');
318 }
319
320 header("X-Frame-Options: SAMEORIGIN"); // By default, frames allowed only if on same domain (stop some XSS attacks)
321
322 // Clean parameters
323 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
324 $result = readfile($outputfile);
325 if (!$result) {
326 print 'File '.$outputfile.' was empty.';
327 }
328
329 //header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
330 exit;
331 } else {
332 top_httphead();
333
334 print 'Error '.$agenda->error;
335
336 exit;
337 }
338}
339
340if ($format == 'rss') {
341 $result = $agenda->build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholidays);
342 if ($result >= 0) {
343 $attachment = false;
344 if (GETPOSTISSET("attachment")) {
345 $attachment = GETPOST("attachment");
346 }
347 //$attachment = false;
348 $contenttype = 'application/rss+xml';
349 if (GETPOSTISSET("contenttype")) {
350 $contenttype = GETPOST("contenttype");
351 }
352 //$contenttype='text/plain';
353 $outputencoding = 'UTF-8';
354
355 if ($contenttype) {
356 header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
357 }
358 if ($attachment) {
359 header('Content-Disposition: attachment; filename="'.$filename.'"');
360 } else {
361 header('Content-Disposition: inline; filename="'.$filename.'"');
362 }
363
364 // Ajout directives pour resoudre bug IE
365 //header('Cache-Control: Public, must-revalidate');
366 //header('Pragma: public');
367 if ($cachedelay) {
368 header('Cache-Control: max-age='.$cachedelay.', private, must-revalidate');
369 } else {
370 header('Cache-Control: private, must-revalidate');
371 }
372
373 header("X-Frame-Options: SAMEORIGIN"); // By default, frames allowed only if on same domain (stop some XSS attacks)
374
375 // Clean parameters
376 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
377 $result = readfile($outputfile);
378 if (!$result) {
379 print 'File '.$outputfile.' was empty.';
380 }
381
382 // header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
383 exit;
384 } else {
385 top_httphead();
386
387 print 'Error '.$agenda->error;
388
389 exit;
390 }
391}
392
393
395
397print '<div class="error">'.$agenda->error.'</div>';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined( 'NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined( 'NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined( 'NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined( 'NOIPCHECK')) llxHeaderVierge()
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 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.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.