33if (!defined(
'NOTOKENRENEWAL')) {
34 define(
'NOTOKENRENEWAL',
'1');
36if (!defined(
'NOREQUIREMENU')) {
37 define(
'NOREQUIREMENU',
'1');
39if (!defined(
'NOREQUIREHTML')) {
40 define(
'NOREQUIREHTML',
'1');
42if (!defined(
'NOREQUIREAJAX')) {
43 define(
'NOREQUIREAJAX',
'1');
45if (!defined(
'NOLOGIN')) {
48if (!defined(
'NOCSRFCHECK')) {
49 define(
"NOCSRFCHECK", 1);
51if (!defined(
'NOIPCHECK')) {
52 define(
'NOIPCHECK',
'1');
59$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
60if (is_numeric($entity)) {
61 define(
"DOLENTITY", $entity);
65require
'../../main.inc.php';
66require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
72 $conf->global->MAIN_FICHINTER_EXPORT_PAST_DELAY = 100;
78if (
GETPOST(
"format",
'alpha')) {
79 $format =
GETPOST(
"format",
'alpha');
82 $type =
GETPOST(
"type",
'alpha');
98if (
GETPOST(
"project",
'alpha')) {
99 $filters[
'project'] =
GETPOST(
"project",
'alpha');
101if (
GETPOST(
"logina",
'alpha')) {
102 $filters[
'logina'] =
GETPOST(
"logina",
'alpha');
104if (
GETPOST(
"logint",
'alpha')) {
105 $filters[
'logint'] =
GETPOST(
"logint",
'alpha');
109 $filters[
'notolderthan'] =
GETPOSTINT(
"notolderthan");
111 $filters[
'notolderthan'] =
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_PAST_DELAY', 100);
116 $filters[
'limit'] = 1000;
118if (
GETPOST(
"module",
'alpha')) {
119 $filters[
'module'] =
GETPOST(
"module",
'alpha');
121if (
GETPOST(
"status",
"intcomma")) {
122 $filters[
'status'] =
GETPOST(
"status",
"intcomma");
126if (!isModEnabled(
'intervention')) {
139 print
'<html><title>Export fichinter cal</title><body>';
140 print
'<div class="error">Module Agenda was not configured properly.</div>';
141 print
'</body></html>';
146$hookmanager->initHooks(array(
'fichinterexport'));
149$reshook = $hookmanager->executeHooks(
'doActions', $filters);
153 print
'<html><title>Export fichinter cal</title><body>';
154 if (!empty($hookmanager->errors) && is_array($hookmanager->errors)) {
155 print
'<div class="error">'.implode(
'<br>', $hookmanager->errors).
'</div>';
157 print
'<div class="error">'.$hookmanager->error.
'</div>';
159 print
'</body></html>';
160} elseif (empty($reshook)) {
165 print
'<html><title>Export fichinter cal</title><body>';
166 print
'<div class="error">Bad value for key.</div>';
167 print
'</body></html>';
173$shortfilename =
'dolibarrcalendar';
174$filename = $shortfilename;
176foreach ($filters as $key => $value) {
179 if ($key ==
'year') {
180 $filename .=
'-year'.$value;
183 $filename .=
'-id'.$value;
185 if ($key ==
'idfrom') {
186 $filename .=
'-idfrom'.$value;
188 if ($key ==
'idto') {
189 $filename .=
'-idto'.$value;
191 if ($key ==
'project') {
192 $filename .=
'-project'.$value;
193 $shortfilename .=
'-project'.$value;
195 if ($key ==
'logina') {
196 $filename .=
'-logina'.$value;
198 if ($key ==
'logint') {
199 $filename .=
'-logint'.$value;
202 if ($key ==
'module') {
203 $filename .=
'-module'.$value;
204 if ($value ==
'project@eventorganization') {
205 $shortfilename .=
'-project';
206 } elseif ($value ==
'conforbooth@eventorganization') {
207 $shortfilename .=
'-conforbooth';
210 if ($key ==
'status') {
211 $filename .=
'-status'.$value;
215if ($format ==
'vcal') {
216 $shortfilename .=
'.vcs';
219if ($format ==
'ical') {
220 $shortfilename .=
'.ics';
223if ($format ==
'rss') {
224 $shortfilename .=
'.rss';
227if ($shortfilename ==
'dolibarrcalendar') {
228 $langs->load(
"errors");
232 print
'<html><title>Export fichinter cal</title><body>';
233 print
'<div class="error">'.$langs->trans(
"ErrorWrongValueForParameterX",
'format').
'</div>';
234 print
'</body></html>';
245$exportholidays =
GETPOSTINT(
'includeholidays');
248if ($format ==
'ical' || $format ==
'vcal') {
249 $result = build_exportfile($format, $type, $cachedelay, $filename, $filters);
252 if (GETPOSTISSET(
"attachment")) {
253 $attachment =
GETPOST(
"attachment");
256 $contenttype =
'text/calendar';
257 if (GETPOSTISSET(
"contenttype")) {
258 $contenttype =
GETPOST(
"contenttype");
261 $outputencoding =
'UTF-8';
264 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
267 header(
'Content-Disposition: attachment; filename="'.$shortfilename.
'"');
271 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
273 header(
'Cache-Control: private, must-revalidate');
277 header(
"X-Frame-Options: SAMEORIGIN");
280 $outputfile = $conf->agenda->dir_temp.
'/'.$filename;
281 $result = readfile($outputfile);
283 print
'File '.$outputfile.
' was empty.';
291 print
'Error '.$fichinterStatic->error;
297if ($format ==
'rss') {
298 $result = build_exportfile($format, $type, $cachedelay, $filename, $filters);
301 if (GETPOSTISSET(
"attachment")) {
302 $attachment =
GETPOST(
"attachment");
305 $contenttype =
'application/rss+xml';
306 if (GETPOSTISSET(
"contenttype")) {
307 $contenttype =
GETPOST(
"contenttype");
310 $outputencoding =
'UTF-8';
313 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
316 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
318 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
325 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
327 header(
'Cache-Control: private, must-revalidate');
331 header(
"X-Frame-Options: SAMEORIGIN");
334 $outputfile = $conf->agenda->dir_temp.
'/'.$filename;
335 $result = readfile($outputfile);
337 print
'File '.$outputfile.
' was empty.';
345 print
'Error '.$fichinterStatic->error;
354print
'<html><title>Export fichinter cal</title><body>';
355print
'<div class="error">'.$fichinterStatic->error.
'</div>';
356print
'</body></html>';
371function build_exportfile($format, $type, $cachedelay, $filename, $filters)
383 global $conf, $langs, $dolibarr_main_url_root, $mysoc;
385 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
386 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
387 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
389 dol_syslog(
"build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
392 if (empty($format)) {
399 if ($format ==
'ical') {
402 $filename = $format.
'.'.$extension;
406 $result =
dol_mkdir($conf->agenda->dir_temp);
407 $outputfile = $conf->agenda->dir_temp.
'/'.$filename;
417 $eventorganization =
'';
423 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
425 dol_syslog(
"build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
432 $eventarray = array();
434 $sql =
"SELECT f.rowid,";
437 $sql .=
" fd.duree,";
438 $sql .=
" f.datec, f.tms as datem,";
439 $sql .=
" f.ref, f.ref_client, fd.description, f.note_private, f.note_public,";
440 $sql .=
" f.fk_soc,";
441 $sql .=
" f.fk_user_author, f.fk_user_modif,";
442 $sql .=
" f.fk_user_valid,";
443 $sql .=
" u.firstname, u.lastname, u.email,";
444 $sql .=
" p.ref as ref_project, c.ref as ref_contract,";
445 $sql .=
" s.nom as socname, f.fk_statut";
447 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
448 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"fichinterdet as fd ON f.rowid = fd.fk_fichinter";
449 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = f.fk_user_author";
451 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on s.rowid = f.fk_soc";
452 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p on p.rowid = f.fk_projet";
453 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contrat as c on c.rowid = f.fk_contrat";
455 $parameters = array(
'filters' => $filters);
457 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
458 $sql .= $hookmanager->resPrint;
460 $sql .=
" WHERE f.entity IN (".getEntity(
'fichinter').
")";
462 foreach ($filters as $key => $value) {
463 if ($key ==
'notolderthan' && $value !=
'') {
464 $sql .=
" AND fd.date >= '".$db->idate($now - ($value * 24 * 60 * 60)).
"'";
466 if ($key ==
'year') {
471 $sql .=
" AND f.rowid = ".(is_numeric($value) ? $value : 0);
473 if ($key ==
'idfrom') {
474 $sql .=
" AND f.rowid >= ".(is_numeric($value) ? $value : 0);
476 if ($key ==
'idto') {
477 $sql .=
" AND f.rowid <= ".(is_numeric($value) ? $value : 0);
479 if ($key ==
'project') {
480 $sql .=
" AND f.fk_project = ".(is_numeric($value) ? $value : 0);
482 if ($key ==
'contract') {
483 $sql .=
" AND f.fk_contract = ".(is_numeric($value) ? $value : 0);
486 if ($key ==
'logina') {
489 if (preg_match(
'/^!/', $logina)) {
490 $logina = preg_replace(
'/^!/',
'', $logina);
493 $userforfilter =
new User($db);
494 $result = $userforfilter->fetch(0, $logina);
496 $sql .=
" AND a.fk_user_author ".$condition.
" ".$userforfilter->id;
497 } elseif ($result < 0 || $condition ==
'=') {
498 $sql .=
" AND a.fk_user_author = 0";
501 if ($key ==
'logini') {
504 if (preg_match(
'/^!/', $logini)) {
505 $logini = preg_replace(
'/^!/',
'', $logini);
508 $userforfilter =
new User($db);
509 $result = $userforfilter->fetch(0, $logini);
510 $sql .=
" AND EXISTS (SELECT ec.rowid FROM ".MAIN_DB_PREFIX.
"element_contact as ec";
511 $sql .=
" WHERE ec.element_id = f.rowid";
512 $sql .=
" AND ec.fk_c_type_contact = 26";
514 $sql .=
" AND ec.fk_socpeople = ".((int) $userforfilter->id);
515 } elseif ($result < 0 || $condition ==
'=') {
516 $sql .=
" AND ec.fk_socpeople = 0";
520 if ($key ==
'loginr') {
523 if (preg_match(
'/^!/', $loginr)) {
524 $loginr = preg_replace(
'/^!/',
'', $loginr);
527 $userforfilter =
new User($db);
528 $result = $userforfilter->fetch(0, $loginr);
529 $sql .=
" AND EXISTS (SELECT ecr.rowid FROM ".MAIN_DB_PREFIX.
"element_contact as ecr";
530 $sql .=
" WHERE ecr.element_id = f.rowid";
531 $sql .=
" WHERE AND ecr.fk_c_type_contact = 27";
533 $sql .=
" AND ecr.fk_socpeople = ".((int) $userforfilter->id);
534 } elseif ($result < 0 || $condition ==
'=') {
535 $sql .=
" AND ecr.fk_socpeople = 0";
540 if ($key ==
'status') {
541 $sql .=
" AND f.fk_statut = ".((int) $value);
546 $sql .=
" AND f.dateo IS NOT NULL";
548 $parameters = array(
'filters' => $filters);
550 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
551 $sql .= $hookmanager->resPrint;
553 $sql .=
" ORDER by fd.date";
556 if (!empty($filters[
'limit'])) {
557 $sql .= $db->plimit((
int) $filters[
'limit']);
562 dol_syslog(
"build_exportfile select event(s)", LOG_DEBUG);
564 $resql = $db->query($sql);
567 while ($obj = $db->fetch_object($resql)) {
572 $event[
'uid'] =
'dolibarragenda-'.$db->database_name.
'-'.$obj->id.
"@".$_SERVER[
"SERVER_NAME"];
573 $event[
'type'] = $type;
575 $datestart = $db->jdate($obj->date) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
585 $duration = $obj->duree;
586 $event[
'location'] = ($obj->socname ? $obj->socname :
"");
587 $event[
'summary'] = $obj->ref.
" - ". $obj->description;
588 if ($obj->ref_client)
589 $event[
'summary'].=
" (".$obj->ref_client.
")";
591 $event[
'desc'] = $obj->description;
593 if ($obj->ref_project)
594 $event[
'desc'] .=
" - ".$obj->ref_project;
596 if ($obj->ref_contract)
597 $event[
'desc'] .=
" - ".$obj->ref_contract;
599 if ($obj->note_public)
600 $event[
'desc'].=
" - ".$obj->note_public;
602 $event[
'startdate'] = $datestart;
603 $event[
'enddate'] =
'';
604 $event[
'duration'] = $duration;
610 $event[
'email'] = $obj->email;
613 if ($eventorganization !=
'') {
614 $link_subscription = $dolibarr_main_url_root.
'/public/eventorganization/attendee_new.php?id='.((int) $obj->id).
'&type=global&noregistration=1';
616 $link_subscription .=
'&securekey='.urlencode($encodedsecurekey);
621 $event[
'created'] = $db->jdate($obj->datec) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
622 $event[
'modified'] = $db->jdate($obj->datem) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
625 $event[
'status'] = $obj->fk_statut;
642 if ($qualified && $datestart) {
643 $eventarray[] = $event;
648 $parameters = array(
'filters' => $filters,
'eventarray' => &$eventarray);
650 $reshook = $hookmanager->executeHooks(
'addMoreEventsExport', $parameters);
652 $eventarray = $hookmanager->resArray;
655 print $db->lasterror();
659 $langs->load(
"agenda");
665 $more = $langs->transnoentities(
"User").
' '.$login;
668 $more = $langs->transnoentities(
"ActionsAskedBy").
' '.$logina;
671 $more = $langs->transnoentities(
"ActionsToDoBy").
' '.$logini;
673 if ($eventorganization) {
674 $langs->load(
"eventorganization");
675 $title = $langs->transnoentities(
"OrganizedEvent").(empty($eventarray[0][
'label']) ?
'' :
' '.$eventarray[0][
'label']);
676 $more =
'ICS file - '.$langs->transnoentities(
"OrganizedEvent").(empty($eventarray[0][
'label']) ?
'' :
' '.$eventarray[0][
'label']);
680 $title =
'Dolibarr actions '.$mysoc->name.
' - '.$more;
683 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
686 $title =
'Dolibarr actions '.$mysoc->name;
688 $desc = $langs->transnoentities(
'ListOfActions');
689 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
694 $outputfiletmp = tempnam($conf->fichinter->dir_temp,
'tmp');
698 if ($format ==
'vcal') {
699 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
700 } elseif ($format ==
'ical') {
701 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
702 } elseif ($format ==
'rss') {
703 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
707 if (
dol_move($outputfiletmp, $outputfile, 0, 1, 0, 0)) {
710 $error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
711 dol_syslog(
"build_exportfile ".$error, LOG_ERR);
716 dol_syslog(
"build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
718 $langs->load(
"errors");
719 $error = $langs->trans(
"ErrorFailToCreateFile", $outputfile);
Class to manage interventions.
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_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.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array())
Move a file into another name.
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.
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)
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.