dolibarr 18.0.6
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// Security check
87if (!isModEnabled('agenda')) {
88 httponly_accessforbidden('Module Agenda not enabled');
89}
90
91// Not older than
92if (empty($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) {
93 $conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY = 100; // default limit
94}
95
96// Define format, type and filter
97$format = 'ical';
98$type = 'event';
99if (GETPOST("format", 'alpha')) {
100 $format = GETPOST("format", 'alpha');
101}
102if (GETPOST("type", 'alpha')) {
103 $type = GETPOST("type", 'alpha');
104}
105
106$filters = array();
107if (GETPOST("year", 'int')) {
108 $filters['year'] = GETPOST("year", 'int');
109}
110if (GETPOST("id", 'int')) {
111 $filters['id'] = GETPOST("id", 'int');
112}
113if (GETPOST("idfrom", 'int')) {
114 $filters['idfrom'] = GETPOST("idfrom", 'int');
115}
116if (GETPOST("idto", 'int')) {
117 $filters['idto'] = GETPOST("idto", 'int');
118}
119if (GETPOST("project", 'alpha')) {
120 $filters['project'] = GETPOST("project", 'alpha');
121}
122if (GETPOST("logina", 'alpha')) {
123 $filters['logina'] = GETPOST("logina", 'alpha');
124}
125if (GETPOST("logint", 'alpha')) {
126 $filters['logint'] = GETPOST("logint", 'alpha');
127}
128if (GETPOST("notactiontype", 'alpha')) {
129 $filters['notactiontype'] = GETPOST("notactiontype", 'alpha');
130}
131if (GETPOST("actiontype", 'alpha')) {
132 $filters['actiontype'] = GETPOST("actiontype", 'alpha');
133}
134if (GETPOST("notolderthan", 'int')) {
135 $filters['notolderthan'] = GETPOST("notolderthan", "int");
136} else {
137 $filters['notolderthan'] = $conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY;
138}
139if (GETPOST("module", 'alpha')) {
140 $filters['module'] = GETPOST("module", 'alpha');
141}
142if (GETPOST("status", 'int')) {
143 $filters['status'] = GETPOST("status", 'int');
144}
145// Check config
146if (empty($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY)) {
147 $user->getrights();
148
150 print '<div class="error">Module Agenda was not configured properly.</div>';
152 exit;
153}
154
155// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
156$hookmanager->initHooks(array('agendaexport'));
157
158$reshook = $hookmanager->executeHooks('doActions', $filters); // Note that $action and $object may have been modified by some
159if ($reshook < 0) {
161 if (!empty($hookmanager->errors) && is_array($hookmanager->errors)) {
162 print '<div class="error">'.implode('<br>', $hookmanager->errors).'</div>';
163 } else {
164 print '<div class="error">'.$hookmanager->error.'</div>';
165 }
167} elseif (empty($reshook)) {
168 // Check exportkey
169 if (empty($_GET["exportkey"]) || $conf->global->MAIN_AGENDA_XCAL_EXPORTKEY != $_GET["exportkey"]) {
170 $user->getrights();
171
173 print '<div class="error">Bad value for key.</div>';
175 exit;
176 }
177}
178
179
180// Define filename with prefix on filters predica (each predica set must have on cache file)
181$shortfilename = 'dolibarrcalendar';
182$filename = $shortfilename;
183// Complete long filename
184foreach ($filters as $key => $value) {
185 //if ($key == 'notolderthan') $filename.='-notolderthan'.$value; This filter key is already added before and does not need to be in filename
186 if ($key == 'year') {
187 $filename .= '-year'.$value;
188 }
189 if ($key == 'id') {
190 $filename .= '-id'.$value;
191 }
192 if ($key == 'idfrom') {
193 $filename .= '-idfrom'.$value;
194 }
195 if ($key == 'idto') {
196 $filename .= '-idto'.$value;
197 }
198 if ($key == 'project') {
199 $filename .= '-project'.$value;
200 }
201 if ($key == 'logina') {
202 $filename .= '-logina'.$value; // Author
203 }
204 if ($key == 'logint') {
205 $filename .= '-logint'.$value; // Assigned to
206 }
207 if ($key == 'notactiontype') {
208 $filename .= '-notactiontype'.$value;
209 }
210 if ($key == 'actiontype') {
211 $filename .= '-actiontype'.$value;
212 }
213 if ($key == 'module') {
214 $filename .= '-module'.$value;
215 }
216 if ($key == 'status') {
217 $filename .= '-status'.$value;
218 }
219}
220// Add extension
221if ($format == 'vcal') {
222 $shortfilename .= '.vcs'; $filename .= '.vcs';
223}
224if ($format == 'ical') {
225 $shortfilename .= '.ics'; $filename .= '.ics';
226}
227if ($format == 'rss') {
228 $shortfilename .= '.rss'; $filename .= '.rss';
229}
230if ($shortfilename == 'dolibarrcalendar') {
231 $langs->load("errors");
233 print '<div class="error">'.$langs->trans("ErrorWrongValueForParameterX", 'format').'</div>';
235 exit;
236}
237
238$agenda = new ActionComm($db);
239
240$cachedelay = 0;
241if (!empty($conf->global->MAIN_AGENDA_EXPORT_CACHE)) {
242 $cachedelay = $conf->global->MAIN_AGENDA_EXPORT_CACHE;
243}
244
245$exportholidays = GETPOST('includeholidays', 'int');
246
247// Build file
248if ($format == 'ical' || $format == 'vcal') {
249 $result = $agenda->build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholidays);
250 if ($result >= 0) {
251 $attachment = true;
252 if (isset($_GET["attachment"])) {
253 $attachment = $_GET["attachment"];
254 }
255 //$attachment = false;
256 $contenttype = 'text/calendar';
257 if (isset($_GET["contenttype"])) {
258 $contenttype = $_GET["contenttype"];
259 }
260 //$contenttype='text/plain';
261 $outputencoding = 'UTF-8';
262
263 if ($contenttype) {
264 header('Content-Type: '.$contenttype.($outputencoding ? '; charset='.$outputencoding : ''));
265 }
266 if ($attachment) {
267 header('Content-Disposition: attachment; filename="'.$shortfilename.'"');
268 }
269
270 if ($cachedelay) {
271 header('Cache-Control: max-age='.$cachedelay.', private, must-revalidate');
272 } else {
273 header('Cache-Control: private, must-revalidate');
274 }
275
276 // Clean parameters
277 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
278 $result = readfile($outputfile);
279 if (!$result) {
280 print 'File '.$outputfile.' was empty.';
281 }
282
283 //header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
284 exit;
285 } else {
286 print 'Error '.$agenda->error;
287
288 exit;
289 }
290}
291
292if ($format == 'rss') {
293 $result = $agenda->build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholidays);
294 if ($result >= 0) {
295 $attachment = false;
296 if (isset($_GET["attachment"])) {
297 $attachment = $_GET["attachment"];
298 }
299 //$attachment = false;
300 $contenttype = 'application/rss+xml';
301 if (isset($_GET["contenttype"])) {
302 $contenttype = $_GET["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="'.$filename.'"');
312 }
313
314 // Ajout directives pour resoudre bug IE
315 //header('Cache-Control: Public, must-revalidate');
316 //header('Pragma: public');
317 if ($cachedelay) {
318 header('Cache-Control: max-age='.$cachedelay.', private, must-revalidate');
319 } else {
320 header('Cache-Control: private, must-revalidate');
321 }
322
323 // Clean parameters
324 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
325 $result = readfile($outputfile);
326 if (!$result) {
327 print 'File '.$outputfile.' was empty.';
328 }
329
330 // header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
331 exit;
332 } else {
333 print 'Error '.$agenda->error;
334
335 exit;
336 }
337}
338
339
341print '<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.
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.