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';
73 $conf->global->MAIN_FICHINTER_EXPORT_PAST_DELAY = 100;
79if (
GETPOST(
"format",
'alpha')) {
80 $format =
GETPOST(
"format",
'alpha');
83 $type =
GETPOST(
"type",
'alpha');
99if (
GETPOST(
"project",
'alpha')) {
100 $filters[
'project'] =
GETPOST(
"project",
'alpha');
102if (
GETPOST(
"logina",
'alpha')) {
103 $filters[
'logina'] =
GETPOST(
"logina",
'alpha');
105if (
GETPOST(
"logint",
'alpha')) {
106 $filters[
'logint'] =
GETPOST(
"logint",
'alpha');
110 $filters[
'notolderthan'] =
GETPOSTINT(
"notolderthan");
112 $filters[
'notolderthan'] =
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_PAST_DELAY', 100);
117 $filters[
'limit'] = 1000;
119if (
GETPOST(
"module",
'alpha')) {
120 $filters[
'module'] =
GETPOST(
"module",
'alpha');
122if (
GETPOST(
"status",
"intcomma")) {
123 $filters[
'status'] =
GETPOST(
"status",
"intcomma");
127if (!isModEnabled(
'intervention')) {
140 print
'<html><title>Export fichinter cal</title><body>';
141 print
'<div class="error">Module Agenda was not configured properly.</div>';
142 print
'</body></html>';
147$hookmanager->initHooks(array(
'fichinterexport'));
150$reshook = $hookmanager->executeHooks(
'doActions', $filters);
154 print
'<html><title>Export fichinter cal</title><body>';
155 if (!empty($hookmanager->errors) && is_array($hookmanager->errors)) {
156 print
'<div class="error">'.implode(
'<br>', $hookmanager->errors).
'</div>';
158 print
'<div class="error">'.$hookmanager->error.
'</div>';
160 print
'</body></html>';
161} elseif (empty($reshook)) {
166 print
'<html><title>Export fichinter cal</title><body>';
167 print
'<div class="error">Bad value for key.</div>';
168 print
'</body></html>';
174$shortfilename =
'dolibarrcalendar';
175$filename = $shortfilename;
177foreach ($filters as $key => $value) {
180 if ($key ==
'year') {
181 $filename .=
'-year'.$value;
184 $filename .=
'-id'.$value;
186 if ($key ==
'idfrom') {
187 $filename .=
'-idfrom'.$value;
189 if ($key ==
'idto') {
190 $filename .=
'-idto'.$value;
192 if ($key ==
'project') {
193 $filename .=
'-project'.$value;
194 $shortfilename .=
'-project'.$value;
196 if ($key ==
'logina') {
197 $filename .=
'-logina'.$value;
199 if ($key ==
'logint') {
200 $filename .=
'-logint'.$value;
203 if ($key ==
'module') {
204 $filename .=
'-module'.$value;
205 if ($value ==
'project@eventorganization') {
206 $shortfilename .=
'-project';
207 } elseif ($value ==
'conforbooth@eventorganization') {
208 $shortfilename .=
'-conforbooth';
211 if ($key ==
'status') {
212 $filename .=
'-status'.$value;
216if ($format ==
'vcal') {
217 $shortfilename .=
'.vcs';
220if ($format ==
'ical') {
221 $shortfilename .=
'.ics';
224if ($format ==
'rss') {
225 $shortfilename .=
'.rss';
228if ($shortfilename ==
'dolibarrcalendar') {
229 $langs->load(
"errors");
233 print
'<html><title>Export fichinter cal</title><body>';
234 print
'<div class="error">'.$langs->trans(
"ErrorWrongValueForParameterX",
'format').
'</div>';
235 print
'</body></html>';
246$exportholidays =
GETPOSTINT(
'includeholidays');
249if ($format ==
'ical' || $format ==
'vcal') {
250 $result = build_exportfile($format, $type, $cachedelay, $filename, $filters);
253 if (GETPOSTISSET(
"attachment")) {
254 $attachment =
GETPOST(
"attachment");
257 $contenttype =
'text/calendar';
258 if (GETPOSTISSET(
"contenttype")) {
259 $contenttype =
GETPOST(
"contenttype");
262 $outputencoding =
'UTF-8';
265 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
268 header(
'Content-Disposition: attachment; filename="'.$shortfilename.
'"');
272 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
274 header(
'Cache-Control: private, must-revalidate');
278 header(
"X-Frame-Options: SAMEORIGIN");
281 $outputfile = $conf->agenda->dir_temp.
'/'.$filename;
282 $result = readfile($outputfile);
284 print
'File '.$outputfile.
' was empty.';
292 print
'Error '.$fichinterStatic->error;
298if ($format ==
'rss') {
299 $result = build_exportfile($format, $type, $cachedelay, $filename, $filters);
302 if (GETPOSTISSET(
"attachment")) {
303 $attachment =
GETPOST(
"attachment");
306 $contenttype =
'application/rss+xml';
307 if (GETPOSTISSET(
"contenttype")) {
308 $contenttype =
GETPOST(
"contenttype");
311 $outputencoding =
'UTF-8';
314 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
317 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
319 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
326 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
328 header(
'Cache-Control: private, must-revalidate');
332 header(
"X-Frame-Options: SAMEORIGIN");
335 $outputfile = $conf->agenda->dir_temp.
'/'.$filename;
336 $result = readfile($outputfile);
338 print
'File '.$outputfile.
' was empty.';
346 print
'Error '.$fichinterStatic->error;
355print
'<html><title>Export fichinter cal</title><body>';
356print
'<div class="error">'.$fichinterStatic->error.
'</div>';
357print
'</body></html>';
372function build_exportfile($format, $type, $cachedelay, $filename, $filters)
384 global $conf, $langs, $dolibarr_main_url_root, $mysoc;
386 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
387 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
388 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
390 dol_syslog(
"build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
393 if (empty($format)) {
400 if ($format ==
'ical') {
403 $filename = $format.
'.'.$extension;
407 $result =
dol_mkdir($conf->agenda->dir_temp);
408 $outputfile = $conf->agenda->dir_temp.
'/'.$filename;
418 $eventorganization =
'';
424 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
426 dol_syslog(
"build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
433 $eventarray = array();
435 $sql =
"SELECT f.rowid,";
438 $sql .=
" fd.duree,";
439 $sql .=
" f.datec, f.tms as datem,";
440 $sql .=
" f.ref, f.ref_client, fd.description, f.note_private, f.note_public,";
441 $sql .=
" f.fk_soc,";
442 $sql .=
" f.fk_user_author, f.fk_user_modif,";
443 $sql .=
" f.fk_user_valid,";
444 $sql .=
" u.firstname, u.lastname, u.email,";
445 $sql .=
" p.ref as ref_project, c.ref as ref_contract,";
446 $sql .=
" s.nom as socname, f.fk_statut";
448 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
449 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"fichinterdet as fd ON f.rowid = fd.fk_fichinter";
450 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = f.fk_user_author";
452 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on s.rowid = f.fk_soc";
453 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p on p.rowid = f.fk_projet";
454 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contrat as c on c.rowid = f.fk_contrat";
456 $parameters = array(
'filters' => $filters);
458 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
459 $sql .= $hookmanager->resPrint;
461 $sql .=
" WHERE f.entity IN (".getEntity(
'fichinter').
")";
463 foreach ($filters as $key => $value) {
464 if ($key ==
'notolderthan' && $value !=
'') {
465 $sql .=
" AND fd.date >= '".$db->idate($now - ($value * 24 * 60 * 60)).
"'";
467 if ($key ==
'year') {
472 $sql .=
" AND f.rowid = ".(is_numeric($value) ? $value : 0);
474 if ($key ==
'idfrom') {
475 $sql .=
" AND f.rowid >= ".(is_numeric($value) ? $value : 0);
477 if ($key ==
'idto') {
478 $sql .=
" AND f.rowid <= ".(is_numeric($value) ? $value : 0);
480 if ($key ==
'project') {
481 $sql .=
" AND f.fk_project = ".(is_numeric($value) ? $value : 0);
483 if ($key ==
'contract') {
484 $sql .=
" AND f.fk_contract = ".(is_numeric($value) ? $value : 0);
487 if ($key ==
'logina') {
490 if (preg_match(
'/^!/', $logina)) {
491 $logina = preg_replace(
'/^!/',
'', $logina);
494 $userforfilter =
new User($db);
495 $result = $userforfilter->fetch(0, $logina);
497 $sql .=
" AND a.fk_user_author ".$condition.
" ".$userforfilter->id;
498 } elseif ($result < 0 || $condition ==
'=') {
499 $sql .=
" AND a.fk_user_author = 0";
502 if ($key ==
'logini') {
505 if (preg_match(
'/^!/', $logini)) {
506 $logini = preg_replace(
'/^!/',
'', $logini);
509 $userforfilter =
new User($db);
510 $result = $userforfilter->fetch(0, $logini);
511 $sql .=
" AND EXISTS (SELECT ec.rowid FROM ".MAIN_DB_PREFIX.
"element_contact as ec";
512 $sql .=
" WHERE ec.element_id = f.rowid";
513 $sql .=
" AND ec.fk_c_type_contact = 26";
515 $sql .=
" AND ec.fk_socpeople = ".((int) $userforfilter->id);
516 } elseif ($result < 0 || $condition ==
'=') {
517 $sql .=
" AND ec.fk_socpeople = 0";
521 if ($key ==
'loginr') {
524 if (preg_match(
'/^!/', $loginr)) {
525 $loginr = preg_replace(
'/^!/',
'', $loginr);
528 $userforfilter =
new User($db);
529 $result = $userforfilter->fetch(0, $loginr);
530 $sql .=
" AND EXISTS (SELECT ecr.rowid FROM ".MAIN_DB_PREFIX.
"element_contact as ecr";
531 $sql .=
" WHERE ecr.element_id = f.rowid";
532 $sql .=
" WHERE AND ecr.fk_c_type_contact = 27";
534 $sql .=
" AND ecr.fk_socpeople = ".((int) $userforfilter->id);
535 } elseif ($result < 0 || $condition ==
'=') {
536 $sql .=
" AND ecr.fk_socpeople = 0";
541 if ($key ==
'status') {
542 $sql .=
" AND f.fk_statut = ".((int) $value);
547 $sql .=
" AND f.dateo IS NOT NULL";
549 $parameters = array(
'filters' => $filters);
551 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
552 $sql .= $hookmanager->resPrint;
554 $sql .=
" ORDER by fd.date";
557 if (!empty($filters[
'limit'])) {
558 $sql .= $db->plimit((
int) $filters[
'limit']);
563 dol_syslog(
"build_exportfile select event(s)", LOG_DEBUG);
565 $resql = $db->query($sql);
568 while ($obj = $db->fetch_object($resql)) {
573 $event[
'uid'] =
'dolibarragenda-'.$db->database_name.
'-'.$obj->id.
"@".$_SERVER[
"SERVER_NAME"];
574 $event[
'type'] = $type;
576 $datestart = $db->jdate($obj->date) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
586 $duration = $obj->duree;
587 $event[
'location'] = ($obj->socname ? $obj->socname :
"");
588 $event[
'summary'] = $obj->ref.
" - ". $obj->description;
589 if ($obj->ref_client)
590 $event[
'summary'].=
" (".$obj->ref_client.
")";
592 $event[
'desc'] = $obj->description;
594 if ($obj->ref_project)
595 $event[
'desc'] .=
" - ".$obj->ref_project;
597 if ($obj->ref_contract)
598 $event[
'desc'] .=
" - ".$obj->ref_contract;
600 if ($obj->note_public)
601 $event[
'desc'].=
" - ".$obj->note_public;
603 $event[
'startdate'] = $datestart;
604 $event[
'enddate'] =
'';
605 $event[
'duration'] = $duration;
611 $event[
'email'] = $obj->email;
614 if ($eventorganization !=
'') {
615 $link_subscription = $dolibarr_main_url_root.
'/public/eventorganization/attendee_new.php?id='.((int) $obj->id).
'&type=global&noregistration=1';
617 $link_subscription .=
'&securekey='.urlencode($encodedsecurekey);
622 $event[
'created'] = $db->jdate($obj->datec) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
623 $event[
'modified'] = $db->jdate($obj->datem) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
626 $event[
'status'] = $obj->fk_statut;
643 if ($qualified && $datestart) {
644 $eventarray[] = $event;
649 $parameters = array(
'filters' => $filters,
'eventarray' => &$eventarray);
651 $reshook = $hookmanager->executeHooks(
'addMoreEventsExport', $parameters);
653 $eventarray = $hookmanager->resArray;
656 print $db->lasterror();
660 $langs->load(
"agenda");
666 $more = $langs->transnoentities(
"User").
' '.$login;
669 $more = $langs->transnoentities(
"ActionsAskedBy").
' '.$logina;
672 $more = $langs->transnoentities(
"ActionsToDoBy").
' '.$logini;
674 if ($eventorganization) {
675 $langs->load(
"eventorganization");
676 $title = $langs->transnoentities(
"OrganizedEvent").(empty($eventarray[0][
'label']) ?
'' :
' '.$eventarray[0][
'label']);
677 $more =
'ICS file - '.$langs->transnoentities(
"OrganizedEvent").(empty($eventarray[0][
'label']) ?
'' :
' '.$eventarray[0][
'label']);
681 $title =
'Dolibarr actions '.$mysoc->name.
' - '.$more;
684 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
687 $title =
'Dolibarr actions '.$mysoc->name;
689 $desc = $langs->transnoentities(
'ListOfActions');
690 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
695 $outputfiletmp = tempnam($conf->fichinter->dir_temp,
'tmp');
699 if ($format ==
'vcal') {
700 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
701 } elseif ($format ==
'ical') {
702 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
703 } elseif ($format ==
'rss') {
704 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
708 if (
dol_move($outputfiletmp, $outputfile,
'0', 1, 0, 0)) {
711 $error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
712 dol_syslog(
"build_exportfile ".$error, LOG_ERR);
717 dol_syslog(
"build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
719 $langs->load(
"errors");
720 $error = $langs->trans(
"ErrorFailToCreateFile", $outputfile);
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.