35if (!defined(
'NOTOKENRENEWAL')) {
36 define(
'NOTOKENRENEWAL',
'1');
38if (!defined(
'NOREQUIREMENU')) {
39 define(
'NOREQUIREMENU',
'1');
41if (!defined(
'NOREQUIREHTML')) {
42 define(
'NOREQUIREHTML',
'1');
44if (!defined(
'NOREQUIREAJAX')) {
45 define(
'NOREQUIREAJAX',
'1');
47if (!defined(
'NOLOGIN')) {
50if (!defined(
'NOCSRFCHECK')) {
51 define(
"NOCSRFCHECK", 1);
53if (!defined(
'NOIPCHECK')) {
54 define(
'NOIPCHECK',
'1');
61$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
62if (is_numeric($entity)) {
63 define(
"DOLENTITY", $entity);
67require
'../../main.inc.php';
68require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
82 $conf->global->MAIN_FICHINTER_EXPORT_PAST_DELAY = 100;
88if (
GETPOST(
"format",
'alpha')) {
89 $format =
GETPOST(
"format",
'alpha');
92 $type =
GETPOST(
"type",
'alpha');
108if (
GETPOST(
"project",
'alpha')) {
109 $filters[
'project'] =
GETPOST(
"project",
'alpha');
111if (
GETPOST(
"logina",
'alpha')) {
112 $filters[
'logina'] =
GETPOST(
"logina",
'alpha');
114if (
GETPOST(
"logint",
'alpha')) {
115 $filters[
'logint'] =
GETPOST(
"logint",
'alpha');
119 $filters[
'notolderthan'] =
GETPOSTINT(
"notolderthan");
121 $filters[
'notolderthan'] =
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_PAST_DELAY', 100);
126 $filters[
'limit'] = 1000;
128if (
GETPOST(
"module",
'alpha')) {
129 $filters[
'module'] =
GETPOST(
"module",
'alpha');
131if (
GETPOST(
"status",
"intcomma")) {
132 $filters[
'status'] =
GETPOST(
"status",
"intcomma");
149 print
'<html><title>Export fichinter cal</title><body>';
150 print
'<div class="error">Module Agenda was not configured properly.</div>';
151 print
'</body></html>';
156$hookmanager->initHooks(array(
'fichinterexport'));
159$reshook = $hookmanager->executeHooks(
'doActions', $filters);
163 print
'<html><title>Export fichinter cal</title><body>';
164 if (!empty($hookmanager->errors) && is_array($hookmanager->errors)) {
165 print
'<div class="error">'.implode(
'<br>', $hookmanager->errors).
'</div>';
167 print
'<div class="error">'.$hookmanager->error.
'</div>';
169 print
'</body></html>';
170} elseif (empty($reshook)) {
175 print
'<html><title>Export fichinter cal</title><body>';
176 print
'<div class="error">Bad value for key.</div>';
177 print
'</body></html>';
183$shortfilename =
'dolibarrcalendar';
184$filename = $shortfilename;
186foreach ($filters as $key => $value) {
189 if ($key ==
'year') {
190 $filename .=
'-year'.$value;
193 $filename .=
'-id'.$value;
195 if ($key ==
'idfrom') {
196 $filename .=
'-idfrom'.$value;
198 if ($key ==
'idto') {
199 $filename .=
'-idto'.$value;
201 if ($key ==
'project') {
202 $filename .=
'-project'.$value;
203 $shortfilename .=
'-project'.$value;
205 if ($key ==
'logina') {
206 $filename .=
'-logina'.$value;
208 if ($key ==
'logint') {
209 $filename .=
'-logint'.$value;
212 if ($key ==
'module') {
213 $filename .=
'-module'.$value;
214 if ($value ==
'project@eventorganization') {
215 $shortfilename .=
'-project';
216 } elseif ($value ==
'conforbooth@eventorganization') {
217 $shortfilename .=
'-conforbooth';
220 if ($key ==
'status') {
221 $filename .=
'-status'.$value;
225if ($format ==
'vcal') {
226 $shortfilename .=
'.vcs';
229if ($format ==
'ical') {
230 $shortfilename .=
'.ics';
233if ($format ==
'rss') {
234 $shortfilename .=
'.rss';
237if ($shortfilename ==
'dolibarrcalendar') {
238 $langs->load(
"errors");
242 print
'<html><title>Export fichinter cal</title><body>';
243 print
'<div class="error">'.$langs->trans(
"ErrorWrongValueForParameterX",
'format').
'</div>';
244 print
'</body></html>';
255$exportholidays =
GETPOSTINT(
'includeholidays');
258if ($format ==
'ical' || $format ==
'vcal') {
259 $result = build_exportfile($format, $type, $cachedelay, $filename, $filters);
263 $attachment =
GETPOST(
"attachment");
266 $contenttype =
'text/calendar';
268 if (
GETPOSTISSET(
"contenttype") && in_array(
GETPOST(
"contenttype"), array(
'text/calendar',
'text/plain'))) {
269 $contenttype =
GETPOST(
"contenttype");
272 $outputencoding =
'UTF-8';
275 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
278 header(
'Content-Disposition: attachment; filename="'.$shortfilename.
'"');
282 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
284 header(
'Cache-Control: private, must-revalidate');
288 header(
"X-Frame-Options: SAMEORIGIN");
291 $outputfile =
$conf->agenda->dir_temp.
'/'.$filename;
292 $result = readfile($outputfile);
294 dol_syslog(
"File ".$outputfile.
" was empty", LOG_WARNING);
295 print
'File was empty.';
303 print
'Error '.$fichinterStatic->error;
309if ($format ==
'rss') {
310 $result = build_exportfile($format, $type, $cachedelay, $filename, $filters);
314 $attachment =
GETPOST(
"attachment");
317 $contenttype =
'application/rss+xml';
319 if (
GETPOSTISSET(
"contenttype") && in_array(
GETPOST(
"contenttype"), array(
'application/rss+xml',
'text/plain'))) {
320 $contenttype =
GETPOST(
"contenttype");
323 $outputencoding =
'UTF-8';
326 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
329 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
331 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
338 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
340 header(
'Cache-Control: private, must-revalidate');
344 header(
"X-Frame-Options: SAMEORIGIN");
347 $outputfile =
$conf->agenda->dir_temp.
'/'.$filename;
348 $result = readfile($outputfile);
350 dol_syslog(
"File ".$outputfile.
" was empty", LOG_WARNING);
351 print
'File was empty.';
359 print
'Error '.$fichinterStatic->error;
368print
'<html><title>Export fichinter cal</title><body>';
369print
'<div class="error">'.$fichinterStatic->error.
'</div>';
370print
'</body></html>';
385function build_exportfile($format, $type, $cachedelay, $filename, $filters)
399 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
400 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
401 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
403 dol_syslog(
"build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
406 if (empty($format)) {
413 if ($format ==
'ical') {
416 $filename = $format.
'.'.$extension;
421 $outputfile =
$conf->agenda->dir_temp.
'/'.$filename;
431 $eventorganization =
'';
437 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
439 dol_syslog(
"build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
446 $eventarray = array();
448 $sql =
"SELECT f.rowid,";
451 $sql .=
" fd.duree,";
452 $sql .=
" f.datec, f.tms as datem,";
453 $sql .=
" f.ref, f.ref_client, fd.description, f.note_private, f.note_public,";
454 $sql .=
" f.fk_soc,";
455 $sql .=
" f.fk_user_author, f.fk_user_modif,";
456 $sql .=
" f.fk_user_valid,";
457 $sql .=
" u.firstname, u.lastname, u.email,";
458 $sql .=
" p.ref as ref_project, c.ref as ref_contract,";
459 $sql .=
" s.nom as socname, f.fk_statut";
461 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
462 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"fichinterdet as fd ON f.rowid = fd.fk_fichinter";
463 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = f.fk_user_author";
465 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on s.rowid = f.fk_soc";
466 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p on p.rowid = f.fk_projet";
467 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contrat as c on c.rowid = f.fk_contrat";
469 $parameters = array(
'filters' => $filters);
471 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
472 $sql .= $hookmanager->resPrint;
474 $sql .=
" WHERE f.entity IN (".getEntity(
'fichinter').
")";
476 foreach ($filters as $key => $value) {
477 if ($key ==
'notolderthan' && $value !=
'') {
478 $sql .=
" AND fd.date >= '".$db->idate($now - ($value * 24 * 60 * 60)).
"'";
480 if ($key ==
'year') {
485 $sql .=
" AND f.rowid = ".((int) $value);
487 if ($key ==
'idfrom') {
488 $sql .=
" AND f.rowid >= ".((int) $value);
490 if ($key ==
'idto') {
491 $sql .=
" AND f.rowid <= ".((int) $value);
493 if ($key ==
'project') {
494 $sql .=
" AND f.fk_project = ".((int) $value);
496 if ($key ==
'contract') {
497 $sql .=
" AND f.fk_contract = ".((int) $value);
500 if ($key ==
'logina') {
502 $sanitizedcondition =
'=';
503 if (preg_match(
'/^!/', $logina)) {
504 $logina = preg_replace(
'/^!/',
'', $logina);
505 $sanitizedcondition =
'<>';
507 $userforfilter =
new User($db);
508 $result = $userforfilter->fetch(0, $logina);
510 $sql .=
" AND a.fk_user_author ".$sanitizedcondition.
" ".((int) $userforfilter->id);
511 } elseif ($result < 0 || $sanitizedcondition ==
'=') {
512 $sql .=
" AND a.fk_user_author = 0";
515 if ($key ==
'logini') {
517 $sanitizedcondition =
'=';
518 if (preg_match(
'/^!/', $logini)) {
519 $logini = preg_replace(
'/^!/',
'', $logini);
520 $sanitizedcondition =
'<>';
522 $userforfilter =
new User($db);
523 $result = $userforfilter->fetch(0, $logini);
524 $sql .=
" AND EXISTS (SELECT ec.rowid FROM ".MAIN_DB_PREFIX.
"element_contact as ec";
525 $sql .=
" WHERE ec.element_id = f.rowid";
526 $sql .=
" AND ec.fk_c_type_contact = 26";
528 $sql .=
" AND ec.fk_socpeople = ".((int) $userforfilter->id);
529 } elseif ($result < 0 || $sanitizedcondition ==
'=') {
530 $sql .=
" AND ec.fk_socpeople = 0";
534 if ($key ==
'loginr') {
536 $sanitizedcondition =
'=';
537 if (preg_match(
'/^!/', $loginr)) {
538 $loginr = preg_replace(
'/^!/',
'', $loginr);
539 $sanitizedcondition =
'<>';
541 $userforfilter =
new User($db);
542 $result = $userforfilter->fetch(0, $loginr);
543 $sql .=
" AND EXISTS (SELECT ecr.rowid FROM ".MAIN_DB_PREFIX.
"element_contact as ecr";
544 $sql .=
" WHERE ecr.element_id = f.rowid";
545 $sql .=
" WHERE AND ecr.fk_c_type_contact = 27";
547 $sql .=
" AND ecr.fk_socpeople = ".((int) $userforfilter->id);
548 } elseif ($result < 0 || $sanitizedcondition ==
'=') {
549 $sql .=
" AND ecr.fk_socpeople = 0";
554 if ($key ==
'status') {
555 $sql .=
" AND f.fk_statut = ".((int) $value);
560 $sql .=
" AND f.dateo IS NOT NULL";
562 $parameters = array(
'filters' => $filters);
564 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
565 $sql .= $hookmanager->resPrint;
567 $sql .=
" ORDER by fd.date";
570 if (!empty($filters[
'limit'])) {
571 $sql .= $db->plimit((
int) $filters[
'limit']);
576 dol_syslog(
"build_exportfile select event(s)", LOG_DEBUG);
578 $resql = $db->query($sql);
581 while ($obj = $db->fetch_object($resql)) {
586 $event[
'uid'] =
'dolibarragenda-'.$db->database_name.
'-'.$obj->id.
"@".$_SERVER[
"SERVER_NAME"];
587 $event[
'type'] = $type;
589 $datestart = $db->jdate($obj->date) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
599 $duration = $obj->duree;
600 $event[
'location'] = ($obj->socname ? $obj->socname :
"");
601 $event[
'summary'] = $obj->ref.
" - ". $obj->description;
602 if ($obj->ref_client)
603 $event[
'summary'].=
" (".$obj->ref_client.
")";
605 $event[
'desc'] = $obj->description;
607 if ($obj->ref_project)
608 $event[
'desc'] .=
" - ".$obj->ref_project;
610 if ($obj->ref_contract)
611 $event[
'desc'] .=
" - ".$obj->ref_contract;
613 if ($obj->note_public)
614 $event[
'desc'].=
" - ".$obj->note_public;
616 $event[
'startdate'] = $datestart;
617 $event[
'enddate'] =
'';
618 $event[
'duration'] = $duration;
624 $event[
'email'] = $obj->email;
627 if ($eventorganization !=
'') {
628 $link_subscription =
$dolibarr_main_url_root.
'/public/eventorganization/attendee_new.php?id='.((int) $obj->id).
'&type=global&noregistration=1';
630 $link_subscription .=
'&securekey='.urlencode($encodedsecurekey);
635 $event[
'created'] = $db->jdate($obj->datec) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
636 $event[
'modified'] = $db->jdate($obj->datem) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
639 $event[
'status'] = $obj->fk_statut;
656 if ($qualified && $datestart) {
657 $eventarray[] = $event;
662 $parameters = array(
'filters' => $filters,
'eventarray' => &$eventarray);
664 $reshook = $hookmanager->executeHooks(
'addMoreEventsExport', $parameters);
666 $eventarray = $hookmanager->resArray;
669 print $db->lasterror();
673 $langs->load(
"agenda");
679 $more = $langs->transnoentities(
"User").
' '.$login;
682 $more = $langs->transnoentities(
"ActionsAskedBy").
' '.$logina;
685 $more = $langs->transnoentities(
"ActionsToDoBy").
' '.$logini;
687 if ($eventorganization) {
688 $langs->load(
"eventorganization");
689 $title = $langs->transnoentities(
"OrganizedEvent").(empty($eventarray[0][
'label']) ?
'' :
' '.$eventarray[0][
'label']);
690 $more =
'ICS file - '.$langs->transnoentities(
"OrganizedEvent").(empty($eventarray[0][
'label']) ?
'' :
' '.$eventarray[0][
'label']);
694 $title =
'Dolibarr actions '.$mysoc->name.
' - '.$more;
697 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
700 $title =
'Dolibarr actions '.$mysoc->name;
702 $desc = $langs->transnoentities(
'ListOfActions');
703 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
708 $outputfiletmp = tempnam(
$conf->fichinter->dir_temp,
'tmp');
712 if ($format ==
'vcal') {
713 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
714 } elseif ($format ==
'ical') {
715 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
716 } elseif ($format ==
'rss') {
717 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
721 if (
dol_move($outputfiletmp, $outputfile,
'0', 1, 0, 0)) {
724 $error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
725 dol_syslog(
"build_exportfile ".$error, LOG_ERR);
730 dol_syslog(
"build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
732 $langs->load(
"errors");
733 $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_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=null)
Move a file into another name.
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_now($mode='gmt')
Return date for now.
dolChmod($filepath, $newmask='')
Change mod of a file.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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, $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='', $useurlforguid=false)
Build a file from an array of events.