31 if (!defined(
'NOTOKENRENEWAL')) {
32 define(
'NOTOKENRENEWAL',
'1');
34 if (!defined(
'NOREQUIREMENU')) {
35 define(
'NOREQUIREMENU',
'1');
37 if (!defined(
'NOREQUIREHTML')) {
38 define(
'NOREQUIREHTML',
'1');
40 if (!defined(
'NOREQUIREAJAX')) {
41 define(
'NOREQUIREAJAX',
'1');
43 if (!defined(
'NOLOGIN')) {
46 if (!defined(
'NOCSRFCHECK')) {
47 define(
"NOCSRFCHECK", 1);
49 if (!defined(
'NOIPCHECK')) {
50 define(
'NOIPCHECK',
'1');
63 print
'<html><title>Export agenda cal</title><body>';
72 print
'</body></html>';
77 $entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
78 if (is_numeric($entity)) {
79 define(
"DOLENTITY", $entity);
82 require
'../../main.inc.php';
83 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
86 if (empty($conf->agenda->enabled)) {
91 if (!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) {
92 $conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY = 100;
98 if (
GETPOST(
"format",
'alpha')) {
99 $format =
GETPOST(
"format",
'alpha');
101 if (
GETPOST(
"type",
'alpha')) {
102 $type =
GETPOST(
"type",
'alpha');
107 $filters[
'year'] =
GETPOST(
"year",
'int');
110 $filters[
'id'] =
GETPOST(
"id",
'int');
112 if (
GETPOST(
"idfrom",
'int')) {
113 $filters[
'idfrom'] =
GETPOST(
"idfrom",
'int');
116 $filters[
'idto'] =
GETPOST(
"idto",
'int');
118 if (
GETPOST(
"project",
'alpha')) {
119 $filters[
'project'] =
GETPOST(
"project",
'alpha');
121 if (
GETPOST(
"logina",
'alpha')) {
122 $filters[
'logina'] =
GETPOST(
"logina",
'alpha');
124 if (
GETPOST(
"logint",
'alpha')) {
125 $filters[
'logint'] =
GETPOST(
"logint",
'alpha');
127 if (
GETPOST(
"notactiontype",
'alpha')) {
128 $filters[
'notactiontype'] =
GETPOST(
"notactiontype",
'alpha');
130 if (
GETPOST(
"actiontype",
'alpha')) {
131 $filters[
'actiontype'] =
GETPOST(
"actiontype",
'alpha');
133 if (
GETPOST(
"notolderthan",
'int')) {
134 $filters[
'notolderthan'] =
GETPOST(
"notolderthan",
"int");
136 $filters[
'notolderthan'] = $conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY;
138 if (
GETPOST(
"module",
'alpha')) {
139 $filters[
'module'] =
GETPOST(
"module",
'alpha');
141 if (
GETPOST(
"status",
'int')) {
142 $filters[
'status'] =
GETPOST(
"status",
'int');
145 if (empty($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY)) {
149 print
'<div class="error">Module Agenda was not configured properly.</div>';
155 $hookmanager->initHooks(array(
'agendaexport'));
157 $reshook = $hookmanager->executeHooks(
'doActions', $filters);
160 if (!empty($hookmanager->errors) && is_array($hookmanager->errors)) {
161 print
'<div class="error">'.implode(
'<br>', $hookmanager->errors).
'</div>';
163 print
'<div class="error">'.$hookmanager->error.
'</div>';
166 } elseif (empty($reshook)) {
168 if (empty($_GET[
"exportkey"]) || $conf->global->MAIN_AGENDA_XCAL_EXPORTKEY != $_GET[
"exportkey"]) {
172 print
'<div class="error">Bad value for key.</div>';
180 $shortfilename =
'dolibarrcalendar';
181 $filename = $shortfilename;
183 foreach ($filters as $key => $value) {
185 if ($key ==
'year') {
186 $filename .=
'-year'.$value;
189 $filename .=
'-id'.$value;
191 if ($key ==
'idfrom') {
192 $filename .=
'-idfrom'.$value;
194 if ($key ==
'idto') {
195 $filename .=
'-idto'.$value;
197 if ($key ==
'project') {
198 $filename .=
'-project'.$value;
200 if ($key ==
'logina') {
201 $filename .=
'-logina'.$value;
203 if ($key ==
'logint') {
204 $filename .=
'-logint'.$value;
206 if ($key ==
'notactiontype') {
207 $filename .=
'-notactiontype'.$value;
209 if ($key ==
'actiontype') {
210 $filename .=
'-actiontype'.$value;
212 if ($key ==
'module') {
213 $filename .=
'-module'.$value;
215 if ($key ==
'status') {
216 $filename .=
'-status'.$value;
220 if ($format ==
'vcal') {
221 $shortfilename .=
'.vcs'; $filename .=
'.vcs';
223 if ($format ==
'ical') {
224 $shortfilename .=
'.ics'; $filename .=
'.ics';
226 if ($format ==
'rss') {
227 $shortfilename .=
'.rss'; $filename .=
'.rss';
229 if ($shortfilename ==
'dolibarrcalendar') {
230 $langs->load(
"errors");
232 print
'<div class="error">'.$langs->trans(
"ErrorWrongValueForParameterX",
'format').
'</div>';
240 if (!empty($conf->global->MAIN_AGENDA_EXPORT_CACHE)) {
241 $cachedelay = $conf->global->MAIN_AGENDA_EXPORT_CACHE;
244 $exportholidays =
GETPOST(
'includeholidays',
'int');
247 if ($format ==
'ical' || $format ==
'vcal') {
248 $result = $agenda->build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholidays);
251 if (isset($_GET[
"attachment"])) {
252 $attachment = $_GET[
"attachment"];
255 $contenttype =
'text/calendar';
256 if (isset($_GET[
"contenttype"])) {
257 $contenttype = $_GET[
"contenttype"];
260 $outputencoding =
'UTF-8';
263 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
266 header(
'Content-Disposition: attachment; filename="'.$shortfilename.
'"');
270 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
272 header(
'Cache-Control: private, must-revalidate');
276 $outputfile = $conf->agenda->dir_temp.
'/'.$filename;
277 $result = readfile($outputfile);
279 print
'File '.$outputfile.
' was empty.';
285 print
'Error '.$agenda->error;
291 if ($format ==
'rss') {
292 $result = $agenda->build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholidays);
295 if (isset($_GET[
"attachment"])) {
296 $attachment = $_GET[
"attachment"];
299 $contenttype =
'application/rss+xml';
300 if (isset($_GET[
"contenttype"])) {
301 $contenttype = $_GET[
"contenttype"];
304 $outputencoding =
'UTF-8';
307 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
310 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
317 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
319 header(
'Cache-Control: private, must-revalidate');
323 $outputfile = $conf->agenda->dir_temp.
'/'.$filename;
324 $result = readfile($outputfile);
326 print
'File '.$outputfile.
' was empty.';
332 print
'Error '.$agenda->error;
340 print
'<div class="error">'.$agenda->error.
'</div>';