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';
266 if (GETPOSTISSET(
"contenttype")) {
267 $contenttype =
GETPOST(
"contenttype");
270 $outputencoding =
'UTF-8';
273 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
276 header(
'Content-Disposition: attachment; filename="'.$shortfilename.
'"');
280 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
282 header(
'Cache-Control: private, must-revalidate');
286 header(
"X-Frame-Options: SAMEORIGIN");
289 $outputfile =
$conf->agenda->dir_temp.
'/'.$filename;
290 $result = readfile($outputfile);
292 print
'File '.$outputfile.
' was empty.';
300 print
'Error '.$fichinterStatic->error;
306if ($format ==
'rss') {
307 $result = build_exportfile($format, $type, $cachedelay, $filename, $filters);
310 if (GETPOSTISSET(
"attachment")) {
311 $attachment =
GETPOST(
"attachment");
314 $contenttype =
'application/rss+xml';
315 if (GETPOSTISSET(
"contenttype")) {
316 $contenttype =
GETPOST(
"contenttype");
319 $outputencoding =
'UTF-8';
322 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
325 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
327 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
334 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
336 header(
'Cache-Control: private, must-revalidate');
340 header(
"X-Frame-Options: SAMEORIGIN");
343 $outputfile =
$conf->agenda->dir_temp.
'/'.$filename;
344 $result = readfile($outputfile);
346 print
'File '.$outputfile.
' was empty.';
354 print
'Error '.$fichinterStatic->error;
363print
'<html><title>Export fichinter cal</title><body>';
364print
'<div class="error">'.$fichinterStatic->error.
'</div>';
365print
'</body></html>';
380function build_exportfile($format, $type, $cachedelay, $filename, $filters)
392 global
$conf, $langs, $dolibarr_main_url_root, $mysoc;
394 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
395 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
396 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
398 dol_syslog(
"build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
401 if (empty($format)) {
408 if ($format ==
'ical') {
411 $filename = $format.
'.'.$extension;
416 $outputfile =
$conf->agenda->dir_temp.
'/'.$filename;
426 $eventorganization =
'';
432 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
434 dol_syslog(
"build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
441 $eventarray = array();
443 $sql =
"SELECT f.rowid,";
446 $sql .=
" fd.duree,";
447 $sql .=
" f.datec, f.tms as datem,";
448 $sql .=
" f.ref, f.ref_client, fd.description, f.note_private, f.note_public,";
449 $sql .=
" f.fk_soc,";
450 $sql .=
" f.fk_user_author, f.fk_user_modif,";
451 $sql .=
" f.fk_user_valid,";
452 $sql .=
" u.firstname, u.lastname, u.email,";
453 $sql .=
" p.ref as ref_project, c.ref as ref_contract,";
454 $sql .=
" s.nom as socname, f.fk_statut";
456 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
457 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"fichinterdet as fd ON f.rowid = fd.fk_fichinter";
458 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = f.fk_user_author";
460 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on s.rowid = f.fk_soc";
461 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p on p.rowid = f.fk_projet";
462 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contrat as c on c.rowid = f.fk_contrat";
464 $parameters = array(
'filters' => $filters);
466 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
467 $sql .= $hookmanager->resPrint;
469 $sql .=
" WHERE f.entity IN (".getEntity(
'fichinter').
")";
471 foreach ($filters as $key => $value) {
472 if ($key ==
'notolderthan' && $value !=
'') {
473 $sql .=
" AND fd.date >= '".$db->idate($now - ($value * 24 * 60 * 60)).
"'";
475 if ($key ==
'year') {
480 $sql .=
" AND f.rowid = ".(is_numeric($value) ? $value : 0);
482 if ($key ==
'idfrom') {
483 $sql .=
" AND f.rowid >= ".(is_numeric($value) ? $value : 0);
485 if ($key ==
'idto') {
486 $sql .=
" AND f.rowid <= ".(is_numeric($value) ? $value : 0);
488 if ($key ==
'project') {
489 $sql .=
" AND f.fk_project = ".(is_numeric($value) ? $value : 0);
491 if ($key ==
'contract') {
492 $sql .=
" AND f.fk_contract = ".(is_numeric($value) ? $value : 0);
495 if ($key ==
'logina') {
498 if (preg_match(
'/^!/', $logina)) {
499 $logina = preg_replace(
'/^!/',
'', $logina);
502 $userforfilter =
new User($db);
503 $result = $userforfilter->fetch(0, $logina);
505 $sql .=
" AND a.fk_user_author ".$condition.
" ".$userforfilter->id;
506 } elseif ($result < 0 || $condition ==
'=') {
507 $sql .=
" AND a.fk_user_author = 0";
510 if ($key ==
'logini') {
513 if (preg_match(
'/^!/', $logini)) {
514 $logini = preg_replace(
'/^!/',
'', $logini);
517 $userforfilter =
new User($db);
518 $result = $userforfilter->fetch(0, $logini);
519 $sql .=
" AND EXISTS (SELECT ec.rowid FROM ".MAIN_DB_PREFIX.
"element_contact as ec";
520 $sql .=
" WHERE ec.element_id = f.rowid";
521 $sql .=
" AND ec.fk_c_type_contact = 26";
523 $sql .=
" AND ec.fk_socpeople = ".((int) $userforfilter->id);
524 } elseif ($result < 0 || $condition ==
'=') {
525 $sql .=
" AND ec.fk_socpeople = 0";
529 if ($key ==
'loginr') {
532 if (preg_match(
'/^!/', $loginr)) {
533 $loginr = preg_replace(
'/^!/',
'', $loginr);
536 $userforfilter =
new User($db);
537 $result = $userforfilter->fetch(0, $loginr);
538 $sql .=
" AND EXISTS (SELECT ecr.rowid FROM ".MAIN_DB_PREFIX.
"element_contact as ecr";
539 $sql .=
" WHERE ecr.element_id = f.rowid";
540 $sql .=
" WHERE AND ecr.fk_c_type_contact = 27";
542 $sql .=
" AND ecr.fk_socpeople = ".((int) $userforfilter->id);
543 } elseif ($result < 0 || $condition ==
'=') {
544 $sql .=
" AND ecr.fk_socpeople = 0";
549 if ($key ==
'status') {
550 $sql .=
" AND f.fk_statut = ".((int) $value);
555 $sql .=
" AND f.dateo IS NOT NULL";
557 $parameters = array(
'filters' => $filters);
559 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
560 $sql .= $hookmanager->resPrint;
562 $sql .=
" ORDER by fd.date";
565 if (!empty($filters[
'limit'])) {
566 $sql .= $db->plimit((
int) $filters[
'limit']);
571 dol_syslog(
"build_exportfile select event(s)", LOG_DEBUG);
573 $resql = $db->query($sql);
576 while ($obj = $db->fetch_object($resql)) {
581 $event[
'uid'] =
'dolibarragenda-'.$db->database_name.
'-'.$obj->id.
"@".$_SERVER[
"SERVER_NAME"];
582 $event[
'type'] = $type;
584 $datestart = $db->jdate($obj->date) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
594 $duration = $obj->duree;
595 $event[
'location'] = ($obj->socname ? $obj->socname :
"");
596 $event[
'summary'] = $obj->ref.
" - ". $obj->description;
597 if ($obj->ref_client)
598 $event[
'summary'].=
" (".$obj->ref_client.
")";
600 $event[
'desc'] = $obj->description;
602 if ($obj->ref_project)
603 $event[
'desc'] .=
" - ".$obj->ref_project;
605 if ($obj->ref_contract)
606 $event[
'desc'] .=
" - ".$obj->ref_contract;
608 if ($obj->note_public)
609 $event[
'desc'].=
" - ".$obj->note_public;
611 $event[
'startdate'] = $datestart;
612 $event[
'enddate'] =
'';
613 $event[
'duration'] = $duration;
619 $event[
'email'] = $obj->email;
622 if ($eventorganization !=
'') {
623 $link_subscription = $dolibarr_main_url_root.
'/public/eventorganization/attendee_new.php?id='.((int) $obj->id).
'&type=global&noregistration=1';
625 $link_subscription .=
'&securekey='.urlencode($encodedsecurekey);
630 $event[
'created'] = $db->jdate($obj->datec) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
631 $event[
'modified'] = $db->jdate($obj->datem) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
634 $event[
'status'] = $obj->fk_statut;
651 if ($qualified && $datestart) {
652 $eventarray[] = $event;
657 $parameters = array(
'filters' => $filters,
'eventarray' => &$eventarray);
659 $reshook = $hookmanager->executeHooks(
'addMoreEventsExport', $parameters);
661 $eventarray = $hookmanager->resArray;
664 print $db->lasterror();
668 $langs->load(
"agenda");
674 $more = $langs->transnoentities(
"User").
' '.$login;
677 $more = $langs->transnoentities(
"ActionsAskedBy").
' '.$logina;
680 $more = $langs->transnoentities(
"ActionsToDoBy").
' '.$logini;
682 if ($eventorganization) {
683 $langs->load(
"eventorganization");
684 $title = $langs->transnoentities(
"OrganizedEvent").(empty($eventarray[0][
'label']) ?
'' :
' '.$eventarray[0][
'label']);
685 $more =
'ICS file - '.$langs->transnoentities(
"OrganizedEvent").(empty($eventarray[0][
'label']) ?
'' :
' '.$eventarray[0][
'label']);
689 $title =
'Dolibarr actions '.$mysoc->name.
' - '.$more;
692 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
695 $title =
'Dolibarr actions '.$mysoc->name;
697 $desc = $langs->transnoentities(
'ListOfActions');
698 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
703 $outputfiletmp = tempnam(
$conf->fichinter->dir_temp,
'tmp');
707 if ($format ==
'vcal') {
708 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
709 } elseif ($format ==
'ical') {
710 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
711 } elseif ($format ==
'rss') {
712 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
716 if (
dol_move($outputfiletmp, $outputfile,
'0', 1, 0, 0)) {
719 $error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
720 dol_syslog(
"build_exportfile ".$error, LOG_ERR);
725 dol_syslog(
"build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
727 $langs->load(
"errors");
728 $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.
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)
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.