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