34if (!defined(
'NOTOKENRENEWAL')) {
35 define(
'NOTOKENRENEWAL',
'1');
37if (!defined(
'NOREQUIREMENU')) {
38 define(
'NOREQUIREMENU',
'1');
40if (!defined(
'NOREQUIREHTML')) {
41 define(
'NOREQUIREHTML',
'1');
43if (!defined(
'NOREQUIREAJAX')) {
44 define(
'NOREQUIREAJAX',
'1');
46if (!defined(
'NOLOGIN')) {
49if (!defined(
'NOCSRFCHECK')) {
50 define(
"NOCSRFCHECK", 1);
52if (!defined(
'NOIPCHECK')) {
53 define(
'NOIPCHECK',
'1');
60$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
61if (is_numeric($entity)) {
62 define(
"DOLENTITY", $entity);
66require
'../../main.inc.php';
67require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
81 $conf->global->MAIN_FICHINTER_EXPORT_PAST_DELAY = 100;
87if (
GETPOST(
"format",
'alpha')) {
88 $format =
GETPOST(
"format",
'alpha');
91 $type =
GETPOST(
"type",
'alpha');
107if (
GETPOST(
"project",
'alpha')) {
108 $filters[
'project'] =
GETPOST(
"project",
'alpha');
110if (
GETPOST(
"logina",
'alpha')) {
111 $filters[
'logina'] =
GETPOST(
"logina",
'alpha');
113if (
GETPOST(
"logint",
'alpha')) {
114 $filters[
'logint'] =
GETPOST(
"logint",
'alpha');
118 $filters[
'notolderthan'] =
GETPOSTINT(
"notolderthan");
120 $filters[
'notolderthan'] =
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_PAST_DELAY', 100);
125 $filters[
'limit'] = 1000;
127if (
GETPOST(
"module",
'alpha')) {
128 $filters[
'module'] =
GETPOST(
"module",
'alpha');
130if (
GETPOST(
"status",
"intcomma")) {
131 $filters[
'status'] =
GETPOST(
"status",
"intcomma");
135if (!isModEnabled(
'intervention')) {
148 print
'<html><title>Export fichinter cal</title><body>';
149 print
'<div class="error">Module Agenda was not configured properly.</div>';
150 print
'</body></html>';
155$hookmanager->initHooks(array(
'fichinterexport'));
158$reshook = $hookmanager->executeHooks(
'doActions', $filters);
162 print
'<html><title>Export fichinter cal</title><body>';
163 if (!empty($hookmanager->errors) && is_array($hookmanager->errors)) {
164 print
'<div class="error">'.implode(
'<br>', $hookmanager->errors).
'</div>';
166 print
'<div class="error">'.$hookmanager->error.
'</div>';
168 print
'</body></html>';
169} elseif (empty($reshook)) {
174 print
'<html><title>Export fichinter cal</title><body>';
175 print
'<div class="error">Bad value for key.</div>';
176 print
'</body></html>';
182$shortfilename =
'dolibarrcalendar';
183$filename = $shortfilename;
185foreach ($filters as $key => $value) {
188 if ($key ==
'year') {
189 $filename .=
'-year'.$value;
192 $filename .=
'-id'.$value;
194 if ($key ==
'idfrom') {
195 $filename .=
'-idfrom'.$value;
197 if ($key ==
'idto') {
198 $filename .=
'-idto'.$value;
200 if ($key ==
'project') {
201 $filename .=
'-project'.$value;
202 $shortfilename .=
'-project'.$value;
204 if ($key ==
'logina') {
205 $filename .=
'-logina'.$value;
207 if ($key ==
'logint') {
208 $filename .=
'-logint'.$value;
211 if ($key ==
'module') {
212 $filename .=
'-module'.$value;
213 if ($value ==
'project@eventorganization') {
214 $shortfilename .=
'-project';
215 } elseif ($value ==
'conforbooth@eventorganization') {
216 $shortfilename .=
'-conforbooth';
219 if ($key ==
'status') {
220 $filename .=
'-status'.$value;
224if ($format ==
'vcal') {
225 $shortfilename .=
'.vcs';
228if ($format ==
'ical') {
229 $shortfilename .=
'.ics';
232if ($format ==
'rss') {
233 $shortfilename .=
'.rss';
236if ($shortfilename ==
'dolibarrcalendar') {
237 $langs->load(
"errors");
241 print
'<html><title>Export fichinter cal</title><body>';
242 print
'<div class="error">'.$langs->trans(
"ErrorWrongValueForParameterX",
'format').
'</div>';
243 print
'</body></html>';
254$exportholidays =
GETPOSTINT(
'includeholidays');
257if ($format ==
'ical' || $format ==
'vcal') {
258 $result = build_exportfile($format, $type, $cachedelay, $filename, $filters);
261 if (GETPOSTISSET(
"attachment")) {
262 $attachment =
GETPOST(
"attachment");
265 $contenttype =
'text/calendar';
267 if (GETPOSTISSET(
"contenttype") && in_array(
GETPOST(
"contenttype"), array(
'text/calendar',
'text/plain'))) {
268 $contenttype =
GETPOST(
"contenttype");
271 $outputencoding =
'UTF-8';
274 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
277 header(
'Content-Disposition: attachment; filename="'.$shortfilename.
'"');
281 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
283 header(
'Cache-Control: private, must-revalidate');
287 header(
"X-Frame-Options: SAMEORIGIN");
290 $outputfile =
$conf->agenda->dir_temp.
'/'.$filename;
291 $result = readfile($outputfile);
293 dol_syslog(
"File ".$outputfile.
" was empty", LOG_WARNING);
294 print
'File was empty.';
302 print
'Error '.$fichinterStatic->error;
308if ($format ==
'rss') {
309 $result = build_exportfile($format, $type, $cachedelay, $filename, $filters);
312 if (GETPOSTISSET(
"attachment")) {
313 $attachment =
GETPOST(
"attachment");
316 $contenttype =
'application/rss+xml';
318 if (GETPOSTISSET(
"contenttype") && in_array(
GETPOST(
"contenttype"), array(
'application/rss+xml',
'text/plain'))) {
319 $contenttype =
GETPOST(
"contenttype");
322 $outputencoding =
'UTF-8';
325 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
328 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
330 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
337 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
339 header(
'Cache-Control: private, must-revalidate');
343 header(
"X-Frame-Options: SAMEORIGIN");
346 $outputfile =
$conf->agenda->dir_temp.
'/'.$filename;
347 $result = readfile($outputfile);
349 dol_syslog(
"File ".$outputfile.
" was empty", LOG_WARNING);
350 print
'File was empty.';
358 print
'Error '.$fichinterStatic->error;
367print
'<html><title>Export fichinter cal</title><body>';
368print
'<div class="error">'.$fichinterStatic->error.
'</div>';
369print
'</body></html>';
384function build_exportfile($format, $type, $cachedelay, $filename, $filters)
398 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
399 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
400 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
402 dol_syslog(
"build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
405 if (empty($format)) {
412 if ($format ==
'ical') {
415 $filename = $format.
'.'.$extension;
420 $outputfile =
$conf->agenda->dir_temp.
'/'.$filename;
430 $eventorganization =
'';
436 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
438 dol_syslog(
"build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
445 $eventarray = array();
447 $sql =
"SELECT f.rowid,";
450 $sql .=
" fd.duree,";
451 $sql .=
" f.datec, f.tms as datem,";
452 $sql .=
" f.ref, f.ref_client, fd.description, f.note_private, f.note_public,";
453 $sql .=
" f.fk_soc,";
454 $sql .=
" f.fk_user_author, f.fk_user_modif,";
455 $sql .=
" f.fk_user_valid,";
456 $sql .=
" u.firstname, u.lastname, u.email,";
457 $sql .=
" p.ref as ref_project, c.ref as ref_contract,";
458 $sql .=
" s.nom as socname, f.fk_statut";
460 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
461 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"fichinterdet as fd ON f.rowid = fd.fk_fichinter";
462 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = f.fk_user_author";
464 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on s.rowid = f.fk_soc";
465 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p on p.rowid = f.fk_projet";
466 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contrat as c on c.rowid = f.fk_contrat";
468 $parameters = array(
'filters' => $filters);
470 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
471 $sql .= $hookmanager->resPrint;
473 $sql .=
" WHERE f.entity IN (".getEntity(
'fichinter').
")";
475 foreach ($filters as $key => $value) {
476 if ($key ==
'notolderthan' && $value !=
'') {
477 $sql .=
" AND fd.date >= '".$db->idate($now - ($value * 24 * 60 * 60)).
"'";
479 if ($key ==
'year') {
484 $sql .=
" AND f.rowid = ".((int) $value);
486 if ($key ==
'idfrom') {
487 $sql .=
" AND f.rowid >= ".((int) $value);
489 if ($key ==
'idto') {
490 $sql .=
" AND f.rowid <= ".((int) $value);
492 if ($key ==
'project') {
493 $sql .=
" AND f.fk_project = ".((int) $value);
495 if ($key ==
'contract') {
496 $sql .=
" AND f.fk_contract = ".((int) $value);
499 if ($key ==
'logina') {
502 if (preg_match(
'/^!/', $logina)) {
503 $logina = preg_replace(
'/^!/',
'', $logina);
506 $userforfilter =
new User($db);
507 $result = $userforfilter->fetch(0, $logina);
509 $sql .=
" AND a.fk_user_author ".$condition.
" ".((int) $userforfilter->id);
510 } elseif ($result < 0 || $condition ==
'=') {
511 $sql .=
" AND a.fk_user_author = 0";
514 if ($key ==
'logini') {
517 if (preg_match(
'/^!/', $logini)) {
518 $logini = preg_replace(
'/^!/',
'', $logini);
521 $userforfilter =
new User($db);
522 $result = $userforfilter->fetch(0, $logini);
523 $sql .=
" AND EXISTS (SELECT ec.rowid FROM ".MAIN_DB_PREFIX.
"element_contact as ec";
524 $sql .=
" WHERE ec.element_id = f.rowid";
525 $sql .=
" AND ec.fk_c_type_contact = 26";
527 $sql .=
" AND ec.fk_socpeople = ".((int) $userforfilter->id);
528 } elseif ($result < 0 || $condition ==
'=') {
529 $sql .=
" AND ec.fk_socpeople = 0";
533 if ($key ==
'loginr') {
536 if (preg_match(
'/^!/', $loginr)) {
537 $loginr = preg_replace(
'/^!/',
'', $loginr);
540 $userforfilter =
new User($db);
541 $result = $userforfilter->fetch(0, $loginr);
542 $sql .=
" AND EXISTS (SELECT ecr.rowid FROM ".MAIN_DB_PREFIX.
"element_contact as ecr";
543 $sql .=
" WHERE ecr.element_id = f.rowid";
544 $sql .=
" WHERE AND ecr.fk_c_type_contact = 27";
546 $sql .=
" AND ecr.fk_socpeople = ".((int) $userforfilter->id);
547 } elseif ($result < 0 || $condition ==
'=') {
548 $sql .=
" AND ecr.fk_socpeople = 0";
553 if ($key ==
'status') {
554 $sql .=
" AND f.fk_statut = ".((int) $value);
559 $sql .=
" AND f.dateo IS NOT NULL";
561 $parameters = array(
'filters' => $filters);
563 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
564 $sql .= $hookmanager->resPrint;
566 $sql .=
" ORDER by fd.date";
569 if (!empty($filters[
'limit'])) {
570 $sql .= $db->plimit((
int) $filters[
'limit']);
575 dol_syslog(
"build_exportfile select event(s)", LOG_DEBUG);
577 $resql = $db->query($sql);
580 while ($obj = $db->fetch_object($resql)) {
585 $event[
'uid'] =
'dolibarragenda-'.$db->database_name.
'-'.$obj->id.
"@".$_SERVER[
"SERVER_NAME"];
586 $event[
'type'] = $type;
588 $datestart = $db->jdate($obj->date) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
598 $duration = $obj->duree;
599 $event[
'location'] = ($obj->socname ? $obj->socname :
"");
600 $event[
'summary'] = $obj->ref.
" - ". $obj->description;
601 if ($obj->ref_client)
602 $event[
'summary'].=
" (".$obj->ref_client.
")";
604 $event[
'desc'] = $obj->description;
606 if ($obj->ref_project)
607 $event[
'desc'] .=
" - ".$obj->ref_project;
609 if ($obj->ref_contract)
610 $event[
'desc'] .=
" - ".$obj->ref_contract;
612 if ($obj->note_public)
613 $event[
'desc'].=
" - ".$obj->note_public;
615 $event[
'startdate'] = $datestart;
616 $event[
'enddate'] =
'';
617 $event[
'duration'] = $duration;
623 $event[
'email'] = $obj->email;
626 if ($eventorganization !=
'') {
627 $link_subscription =
$dolibarr_main_url_root.
'/public/eventorganization/attendee_new.php?id='.((int) $obj->id).
'&type=global&noregistration=1';
629 $link_subscription .=
'&securekey='.urlencode($encodedsecurekey);
634 $event[
'created'] = $db->jdate($obj->datec) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
635 $event[
'modified'] = $db->jdate($obj->datem) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
638 $event[
'status'] = $obj->fk_statut;
655 if ($qualified && $datestart) {
656 $eventarray[] = $event;
661 $parameters = array(
'filters' => $filters,
'eventarray' => &$eventarray);
663 $reshook = $hookmanager->executeHooks(
'addMoreEventsExport', $parameters);
665 $eventarray = $hookmanager->resArray;
668 print $db->lasterror();
672 $langs->load(
"agenda");
678 $more = $langs->transnoentities(
"User").
' '.$login;
681 $more = $langs->transnoentities(
"ActionsAskedBy").
' '.$logina;
684 $more = $langs->transnoentities(
"ActionsToDoBy").
' '.$logini;
686 if ($eventorganization) {
687 $langs->load(
"eventorganization");
688 $title = $langs->transnoentities(
"OrganizedEvent").(empty($eventarray[0][
'label']) ?
'' :
' '.$eventarray[0][
'label']);
689 $more =
'ICS file - '.$langs->transnoentities(
"OrganizedEvent").(empty($eventarray[0][
'label']) ?
'' :
' '.$eventarray[0][
'label']);
693 $title =
'Dolibarr actions '.$mysoc->name.
' - '.$more;
696 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
699 $title =
'Dolibarr actions '.$mysoc->name;
701 $desc = $langs->transnoentities(
'ListOfActions');
702 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
707 $outputfiletmp = tempnam(
$conf->fichinter->dir_temp,
'tmp');
711 if ($format ==
'vcal') {
712 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
713 } elseif ($format ==
'ical') {
714 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
715 } elseif ($format ==
'rss') {
716 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
720 if (
dol_move($outputfiletmp, $outputfile,
'0', 1, 0, 0)) {
723 $error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
724 dol_syslog(
"build_exportfile ".$error, LOG_ERR);
729 dol_syslog(
"build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
731 $langs->load(
"errors");
732 $error = $langs->trans(
"ErrorFailToCreateFile", $outputfile);
global $dolibarr_main_url_root
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_filemtime($pathoffile)
Return time of a file.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=0)
Move a file into another name.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
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...
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
build_calfile($format, $title, $desc, $events_array, $outputfile)
Build a file from an array of events All input params and data must be encoded in $conf->charset_outp...
build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter='', $url='', $langcode='')
Build a file from an array of events.