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 $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 print
'File '.$outputfile.
' was empty.';
301 print
'Error '.$fichinterStatic->error;
307if ($format ==
'rss') {
308 $result = build_exportfile($format, $type, $cachedelay, $filename, $filters);
312 $attachment =
GETPOST(
"attachment");
315 $contenttype =
'application/rss+xml';
317 $contenttype =
GETPOST(
"contenttype");
320 $outputencoding =
'UTF-8';
323 header(
'Content-Type: '.$contenttype.($outputencoding ?
'; charset='.$outputencoding :
''));
326 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
328 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
335 header(
'Cache-Control: max-age='.$cachedelay.
', private, must-revalidate');
337 header(
'Cache-Control: private, must-revalidate');
341 header(
"X-Frame-Options: SAMEORIGIN");
344 $outputfile =
$conf->agenda->dir_temp.
'/'.$filename;
345 $result = readfile($outputfile);
347 print
'File '.$outputfile.
' was empty.';
355 print
'Error '.$fichinterStatic->error;
364print
'<html><title>Export fichinter cal</title><body>';
365print
'<div class="error">'.$fichinterStatic->error.
'</div>';
366print
'</body></html>';
381function build_exportfile($format, $type, $cachedelay, $filename, $filters)
395 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
396 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
397 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
399 dol_syslog(
"build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
402 if (empty($format)) {
409 if ($format ==
'ical') {
412 $filename = $format.
'.'.$extension;
417 $outputfile =
$conf->agenda->dir_temp.
'/'.$filename;
427 $eventorganization =
'';
433 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
435 dol_syslog(
"build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
442 $eventarray = array();
444 $sql =
"SELECT f.rowid,";
447 $sql .=
" fd.duree,";
448 $sql .=
" f.datec, f.tms as datem,";
449 $sql .=
" f.ref, f.ref_client, fd.description, f.note_private, f.note_public,";
450 $sql .=
" f.fk_soc,";
451 $sql .=
" f.fk_user_author, f.fk_user_modif,";
452 $sql .=
" f.fk_user_valid,";
453 $sql .=
" u.firstname, u.lastname, u.email,";
454 $sql .=
" p.ref as ref_project, c.ref as ref_contract,";
455 $sql .=
" s.nom as socname, f.fk_statut";
457 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
458 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"fichinterdet as fd ON f.rowid = fd.fk_fichinter";
459 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = f.fk_user_author";
461 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on s.rowid = f.fk_soc";
462 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet as p on p.rowid = f.fk_projet";
463 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contrat as c on c.rowid = f.fk_contrat";
465 $parameters = array(
'filters' => $filters);
467 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
468 $sql .= $hookmanager->resPrint;
470 $sql .=
" WHERE f.entity IN (".getEntity(
'fichinter').
")";
472 foreach ($filters as $key => $value) {
473 if ($key ==
'notolderthan' && $value !=
'') {
474 $sql .=
" AND fd.date >= '".$db->idate($now - ($value * 24 * 60 * 60)).
"'";
476 if ($key ==
'year') {
481 $sql .=
" AND f.rowid = ".((int) $value);
483 if ($key ==
'idfrom') {
484 $sql .=
" AND f.rowid >= ".((int) $value);
486 if ($key ==
'idto') {
487 $sql .=
" AND f.rowid <= ".((int) $value);
489 if ($key ==
'project') {
490 $sql .=
" AND f.fk_project = ".((int) $value);
492 if ($key ==
'contract') {
493 $sql .=
" AND f.fk_contract = ".((int) $value);
496 if ($key ==
'logina') {
498 $sanitizedcondition =
'=';
499 if (preg_match(
'/^!/', $logina)) {
500 $logina = preg_replace(
'/^!/',
'', $logina);
501 $sanitizedcondition =
'<>';
503 $userforfilter =
new User(
$db);
504 $result = $userforfilter->fetch(0, $logina);
506 $sql .=
" AND a.fk_user_author ".$sanitizedcondition.
" ".((int) $userforfilter->id);
507 } elseif ($result < 0 || $sanitizedcondition ==
'=') {
508 $sql .=
" AND a.fk_user_author = 0";
511 if ($key ==
'logini') {
513 $sanitizedcondition =
'=';
514 if (preg_match(
'/^!/', $logini)) {
515 $logini = preg_replace(
'/^!/',
'', $logini);
516 $sanitizedcondition =
'<>';
518 $userforfilter =
new User(
$db);
519 $result = $userforfilter->fetch(0, $logini);
520 $sql .=
" AND EXISTS (SELECT ec.rowid FROM ".MAIN_DB_PREFIX.
"element_contact as ec";
521 $sql .=
" WHERE ec.element_id = f.rowid";
522 $sql .=
" AND ec.fk_c_type_contact = 26";
524 $sql .=
" AND ec.fk_socpeople = ".((int) $userforfilter->id);
525 } elseif ($result < 0 || $sanitizedcondition ==
'=') {
526 $sql .=
" AND ec.fk_socpeople = 0";
530 if ($key ==
'loginr') {
532 $sanitizedcondition =
'=';
533 if (preg_match(
'/^!/', $loginr)) {
534 $loginr = preg_replace(
'/^!/',
'', $loginr);
535 $sanitizedcondition =
'<>';
537 $userforfilter =
new User(
$db);
538 $result = $userforfilter->fetch(0, $loginr);
539 $sql .=
" AND EXISTS (SELECT ecr.rowid FROM ".MAIN_DB_PREFIX.
"element_contact as ecr";
540 $sql .=
" WHERE ecr.element_id = f.rowid";
541 $sql .=
" WHERE AND ecr.fk_c_type_contact = 27";
543 $sql .=
" AND ecr.fk_socpeople = ".((int) $userforfilter->id);
544 } elseif ($result < 0 || $sanitizedcondition ==
'=') {
545 $sql .=
" AND ecr.fk_socpeople = 0";
550 if ($key ==
'status') {
551 $sql .=
" AND f.fk_statut = ".((int) $value);
556 $sql .=
" AND f.dateo IS NOT NULL";
558 $parameters = array(
'filters' => $filters);
560 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
561 $sql .= $hookmanager->resPrint;
563 $sql .=
" ORDER by fd.date";
566 if (!empty($filters[
'limit'])) {
567 $sql .=
$db->plimit((
int) $filters[
'limit']);
572 dol_syslog(
"build_exportfile select event(s)", LOG_DEBUG);
574 $resql =
$db->query($sql);
577 while ($obj =
$db->fetch_object($resql)) {
582 $event[
'uid'] =
'dolibarragenda-'.$db->database_name.
'-'.$obj->id.
"@".$_SERVER[
"SERVER_NAME"];
583 $event[
'type'] = $type;
585 $datestart =
$db->jdate($obj->date) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
595 $duration = $obj->duree;
596 $event[
'location'] = ($obj->socname ? $obj->socname :
"");
597 $event[
'summary'] = $obj->ref.
" - ". $obj->description;
598 if ($obj->ref_client)
599 $event[
'summary'].=
" (".$obj->ref_client.
")";
601 $event[
'desc'] = $obj->description;
603 if ($obj->ref_project)
604 $event[
'desc'] .=
" - ".$obj->ref_project;
606 if ($obj->ref_contract)
607 $event[
'desc'] .=
" - ".$obj->ref_contract;
609 if ($obj->note_public)
610 $event[
'desc'].=
" - ".$obj->note_public;
612 $event[
'startdate'] = $datestart;
613 $event[
'enddate'] =
'';
614 $event[
'duration'] = $duration;
620 $event[
'email'] = $obj->email;
623 if ($eventorganization !=
'') {
624 $link_subscription =
$dolibarr_main_url_root.
'/public/eventorganization/attendee_new.php?id='.((int) $obj->id).
'&type=global&noregistration=1';
626 $link_subscription .=
'&securekey='.urlencode($encodedsecurekey);
631 $event[
'created'] =
$db->jdate($obj->datec) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
632 $event[
'modified'] =
$db->jdate($obj->datem) - ((int)
getDolGlobalString(
'MAIN_FICHINTER_EXPORT_FIX_TZ', 0) * 3600);
635 $event[
'status'] = $obj->fk_statut;
652 if ($qualified && $datestart) {
653 $eventarray[] = $event;
658 $parameters = array(
'filters' => $filters,
'eventarray' => &$eventarray);
660 $reshook = $hookmanager->executeHooks(
'addMoreEventsExport', $parameters);
662 $eventarray = $hookmanager->resArray;
665 print
$db->lasterror();
669 $langs->load(
"agenda");
675 $more = $langs->transnoentities(
"User").
' '.$login;
678 $more = $langs->transnoentities(
"ActionsAskedBy").
' '.$logina;
681 $more = $langs->transnoentities(
"ActionsToDoBy").
' '.$logini;
683 if ($eventorganization) {
684 $langs->load(
"eventorganization");
685 $title = $langs->transnoentities(
"OrganizedEvent").(empty($eventarray[0][
'label']) ?
'' :
' '.$eventarray[0][
'label']);
686 $more =
'ICS file - '.$langs->transnoentities(
"OrganizedEvent").(empty($eventarray[0][
'label']) ?
'' :
' '.$eventarray[0][
'label']);
690 $title =
'Dolibarr actions '.$mysoc->name.
' - '.$more;
693 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
696 $title =
'Dolibarr actions '.$mysoc->name;
698 $desc = $langs->transnoentities(
'ListOfActions');
699 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
704 $outputfiletmp = tempnam(
$conf->fichinter->dir_temp,
'tmp');
708 if ($format ==
'vcal') {
709 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
710 } elseif ($format ==
'ical') {
711 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
712 } elseif ($format ==
'rss') {
713 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
717 if (
dol_move($outputfiletmp, $outputfile,
'0', 1, 0, 0)) {
720 $error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
721 dol_syslog(
"build_exportfile ".$error, LOG_ERR);
726 dol_syslog(
"build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
728 $langs->load(
"errors");
729 $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.