dolibarr 19.0.4
agendaexport.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2008-2010 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
31if (!defined('NOTOKENRENEWAL')) {
32 define('NOTOKENRENEWAL', '1');
33}
34if (!defined('NOREQUIREMENU')) {
35 define('NOREQUIREMENU', '1'); // If there is no menu to show
36}
37if (!defined('NOREQUIREHTML')) {
38 define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
39}
40if (!defined('NOREQUIREAJAX')) {
41 define('NOREQUIREAJAX', '1');
42}
43if (!defined('NOLOGIN')) {
44 define("NOLOGIN", 1); // This means this output page does not require to be logged.
45}
46if (!defined('NOCSRFCHECK')) {
47 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
48}
49if (!defined('NOIPCHECK')) {
50 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
51}
52
53
54// It's a wrapper, so empty header
55
62{
63 print '<html><title>Export agenda cal</title><body>';
64}
71{
72 print '</body></html>';
73}
74
75// For MultiCompany module.
76// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
77$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
78if (is_numeric($entity)) {
79 define("DOLENTITY", $entity);
80}
81
82// Load Dolibarr environment
83require '../../main.inc.php';
84require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
85
86$object = new ActionComm($db);
87
88// Not older than
89if (!getDolGlobalString('MAIN_AGENDA_EXPORT_PAST_DELAY')) {
90 $conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY = 100; // default limit
91}
92
93// Define format, type and filter
94$format = 'ical';
95$type = 'event';
96if (GETPOST("format", 'alpha')) {
97 $format = GETPOST("format", 'alpha');
98}
99if (GETPOST("type", 'alpha')) {
100 $type = GETPOST("type", 'alpha');
101}
102
103$filters = array();
104if (GETPOST("year", 'int')) {
105 $filters['year'] = GETPOST("year", 'int');
106}
107if (GETPOST("id", 'int')) {
108 $filters['id'] = GETPOST("id", 'int');
109}
110if (GETPOST("idfrom", 'int')) {
111 $filters['idfrom'] = GETPOST("idfrom", 'int');
112}
113if (GETPOST("idto", 'int')) {
114 $filters['idto'] = GETPOST("idto", 'int');
115}
116if (GETPOST("project", 'alpha')) {
117 $filters['project'] = GETPOST("project", 'alpha');
118}
119if (GETPOST("logina", 'alpha')) {
120 $filters['logina'] = GETPOST("logina", 'alpha');
121}
122if (GETPOST("logint", 'alpha')) {
123 $filters['logint'] = GETPOST("logint", 'alpha');
124}
125if (GETPOST("notactiontype", 'alpha')) {
126 $filters['notactiontype'] = GETPOST("notactiontype", 'alpha');
127}
128if (GETPOST("actiontype", 'alpha')) {
129 $filters['actiontype'] = GETPOST("actiontype", 'alpha');
130}
131if (GETPOST("notolderthan", 'int')) {
132 $filters['notolderthan'] = GETPOST("notolderthan", "int");
133} else {
134 $filters['notolderthan'] = $conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY;
135}
136if (GETPOST("module", 'alpha')) {
137 $filters['module'] = GETPOST("module", 'alpha');
138}
139if (GETPOST("status", 'int')) {
140 $filters['status'] = GETPOST("status", 'int');
141}
142
143// Security check
144if (!isModEnabled('agenda')) {
145 httponly_accessforbidden('Module Agenda not enabled');
146}
147
148
149/*
150 * View
151 */
152
153// Check config
154if (!getDolGlobalString('MAIN_AGENDA_XCAL_EXPORTKEY')) {
155 $user->getrights();
156
158 print '<div class="error">Module Agenda was not configured properly.</div>';
160 exit;
161}
162
163// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
164$hookmanager->initHooks(array('agendaexport'));
165
166$reshook = $hookmanager->executeHooks('doActions', $filters); // Note that $action and $object may have been modified by some
167if ($reshook < 0) {
169 if (!empty($hookmanager->errors) && is_array($hookmanager->errors)) {
170 print '<div class="error">'.implode('<br>', $hookmanager->errors).'</div>';
171 } else {
172 print '<div class="error">'.$hookmanager->error.'</div>';
173 }
175} elseif (empty($reshook)) {
176 // Check exportkey
177 if (empty($_GET["exportkey"]) || $conf->global->MAIN_AGENDA_XCAL_EXPORTKEY != $_GET["exportkey"]) {
178 $user->getrights();
179
181 print '<div class="error">Bad value for key.</div>';
183 exit;
184 }
185}
186
187
188// Define filename with prefix on filters predica (each predica set must have on cache file)
189$shortfilename = 'dolibarrcalendar';
190$filename = $shortfilename;
191// Complete long filename
192foreach ($filters as $key => $value) {
193 //if ($key == 'notolderthan') $filename.='-notolderthan'.$value; This filter key is already added before and does not need to be in filename
194 if ($key == 'year') {
195 $filename .= '-year'.$value;
196 }
197 if ($key == 'id') {
198 $filename .= '-id'.$value;
199 }
200 if ($key == 'idfrom') {
201 $filename .= '-idfrom'.$value;
202 }
203 if ($key == 'idto') {
204 $filename .= '-idto'.$value;
205 }
206 if ($key == 'project') {
207 $filename .= '-project'.$value;
208 }
209 if ($key == 'logina') {
210 $filename .= '-logina'.$value; // Author
211 }
212 if ($key == 'logint') {
213 $filename .= '-logint'.$value; // Assigned to
214 }
215 if ($key == 'notactiontype') {
216 $filename .= '-notactiontype'.$value;
217 }
218 if ($key == 'actiontype') {
219 $filename .= '-actiontype'.$value;
220 }
221 if ($key == 'module') {
222 $filename .= '-module'.$value;
223 }
224 if ($key == 'status') {
225 $filename .= '-status'.$value;
226 }
227}
228// Add extension
229if ($format == 'vcal') {
230 $shortfilename .= '.vcs';
231 $filename .= '.vcs';
232}
233if ($format == 'ical') {
234 $shortfilename .= '.ics';
235 $filename .= '.ics';
236}
237if ($format == 'rss') {
238 $shortfilename .= '.rss';
239 $filename .= '.rss';
240}
241if ($shortfilename == 'dolibarrcalendar') {
242 $langs->load("errors");
244 print '<div class="error">'.$langs->trans("ErrorWrongValueForParameterX", 'format').'</div>';
246 exit;
247}
248
249$agenda = new ActionComm($db);
250
251$cachedelay = 0;
252if (getDolGlobalString('MAIN_AGENDA_EXPORT_CACHE')) {
253 $cachedelay = $conf->global->MAIN_AGENDA_EXPORT_CACHE;
254}
255
256$exportholidays = GETPOST('includeholidays', 'int');
257
258// Build file
259if ($format == 'ical' || $format == 'vcal') {
260 $result = $agenda->build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholidays);
261 if ($result >= 0) {
262 $attachment = true;
263 if (isset($_GET["attachment"])) {
264 $attachment = $_GET["attachment"];
265 }
266 //$attachment = false;
267 $contenttype = 'text/calendar';
268 if (isset($_GET["contenttype"])) {
269 $contenttype = $_GET["contenttype"];
270 }
271 //$contenttype='text/plain';
272 $outputencoding = 'UTF-8';
273
274 if ($contenttype) {
275 header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
276 }
277 if ($attachment) {
278 header('Content-Disposition: attachment; filename="'.$shortfilename.'"');
279 }
280
281 if ($cachedelay) {
282 header('Cache-Control: max-age='.$cachedelay.', private, must-revalidate');
283 } else {
284 header('Cache-Control: private, must-revalidate');
285 }
286
287 // Clean parameters
288 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
289 $result = readfile($outputfile);
290 if (!$result) {
291 print 'File '.$outputfile.' was empty.';
292 }
293
294 //header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
295 exit;
296 } else {
297 print 'Error '.$agenda->error;
298
299 exit;
300 }
301}
302
303if ($format == 'rss') {
304 $result = $agenda->build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholidays);
305 if ($result >= 0) {
306 $attachment = false;
307 if (isset($_GET["attachment"])) {
308 $attachment = $_GET["attachment"];
309 }
310 //$attachment = false;
311 $contenttype = 'application/rss+xml';
312 if (isset($_GET["contenttype"])) {
313 $contenttype = $_GET["contenttype"];
314 }
315 //$contenttype='text/plain';
316 $outputencoding = 'UTF-8';
317
318 if ($contenttype) {
319 header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
320 }
321 if ($attachment) {
322 header('Content-Disposition: attachment; filename="'.$filename.'"');
323 }
324
325 // Ajout directives pour resoudre bug IE
326 //header('Cache-Control: Public, must-revalidate');
327 //header('Pragma: public');
328 if ($cachedelay) {
329 header('Cache-Control: max-age='.$cachedelay.', private, must-revalidate');
330 } else {
331 header('Cache-Control: private, must-revalidate');
332 }
333
334 // Clean parameters
335 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
336 $result = readfile($outputfile);
337 if (!$result) {
338 print 'File '.$outputfile.' was empty.';
339 }
340
341 // header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
342 exit;
343 } else {
344 print 'Error '.$agenda->error;
345
346 exit;
347 }
348}
349
350
352print '<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()
Header function.
llxFooterVierge()
Footer function.
Class to manage agenda events (actions)
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.
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.