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