PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/public/agenda/agendaexport.php

https://bitbucket.org/speedealing/speedealing
PHP | 213 lines | 125 code | 29 blank | 59 comment | 66 complexity | 2f8d14686acc4455d6f8f00ad9850a92 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2008-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/public/agenda/agendaexport.php
  19. * \ingroup agenda
  20. * \brief Page to export agenda
  21. * http://127.0.0.1/dolibarr/public/agenda/agendaexport.php?format=vcal&exportkey=cle
  22. * http://127.0.0.1/dolibarr/public/agenda/agendaexport.php?format=ical&type=event&exportkey=cle
  23. * http://127.0.0.1/dolibarr/public/agenda/agendaexport.php?format=rss&exportkey=cle
  24. */
  25. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
  26. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
  27. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  28. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  29. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
  30. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show
  31. if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
  32. if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  33. define("NOLOGIN",1); // This means this output page does not require to be logged.
  34. define("NOCSRFCHECK",1); // We accept to go on this page from external web site.
  35. // C'est un wrapper, donc header vierge
  36. /**
  37. * Header function
  38. *
  39. * @return void
  40. */
  41. function llxHeaderVierge() { print '<html><title>Export agenda cal</title><body>'; }
  42. /**
  43. * Footer function
  44. *
  45. * @return void
  46. */
  47. function llxFooterVierge() { print '</body></html>'; }
  48. require '../../main.inc.php';
  49. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  50. // Security check
  51. if (empty($conf->agenda->enabled)) accessforbidden('',1,1,1);
  52. // Define format, type and filter
  53. $format='ical';
  54. $type='event';
  55. if (! empty($_GET["format"])) $format=$_GET["format"];
  56. if (! empty($_GET["type"])) $type=$_GET["type"];
  57. $filters=array();
  58. if (! empty($_GET["year"])) $filters['year']=$_GET["year"];
  59. if (! empty($_GET["id"])) $filters['id']=$_GET["id"];
  60. if (! empty($_GET["idfrom"])) $filters['idfrom']=$_GET["idfrom"];
  61. if (! empty($_GET["idto"])) $filters['idto']=$_GET["idto"];
  62. if (! empty($_GET["login"])) $filters['login']=$_GET["login"];
  63. if (! empty($_GET["logina"])) $filters['logina']=$_GET["logina"];
  64. if (! empty($_GET["logint"])) $filters['logint']=$_GET["logint"];
  65. if (! empty($_GET["logind"])) $filters['logind']=$_GET["logind"];
  66. // Not older than
  67. if (! isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY=100;
  68. $filters['notolderthan']=$conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY;
  69. // Check config
  70. if (empty($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY))
  71. {
  72. $user->getrights();
  73. llxHeaderVierge();
  74. print '<div class="error">Module Agenda was not configured properly.</div>';
  75. llxFooterVierge();
  76. exit;
  77. }
  78. // Check exportkey
  79. if (empty($_GET["exportkey"]) || $conf->global->MAIN_AGENDA_XCAL_EXPORTKEY != $_GET["exportkey"])
  80. {
  81. $user->getrights();
  82. llxHeaderVierge();
  83. print '<div class="error">Bad value for key.</div>';
  84. llxFooterVierge();
  85. exit;
  86. }
  87. // Define filename with prefix on filters predica (each predica set must have on cache file)
  88. $shortfilename='dolibarrcalendar';
  89. $filename=$shortfilename;
  90. // Complete long filename
  91. foreach ($filters as $key => $value)
  92. {
  93. //if ($key == 'notolderthan') $filename.='-notolderthan'.$value; This filter key is already added before and does not need to be in filename
  94. if ($key == 'year') $filename.='-year'.$value;
  95. if ($key == 'id') $filename.='-id'.$value;
  96. if ($key == 'idfrom') $filename.='-idfrom'.$value;
  97. if ($key == 'idto') $filename.='-idto'.$value;
  98. if ($key == 'login') $filename.='-login'.$value;
  99. if ($key == 'logina') $filename.='-logina'.$value; // Author
  100. if ($key == 'logind') $filename.='-logind'.$value; // Affected to
  101. if ($key == 'logint') $filename.='-logint'.$value; // Done by
  102. }
  103. // Add extension
  104. if ($format == 'vcal') { $shortfilename.='.vcs'; $filename.='.vcs'; }
  105. if ($format == 'ical') { $shortfilename.='.ics'; $filename.='.ics'; }
  106. if ($format == 'rss') { $shortfilename.='.rss'; $filename.='.rss'; }
  107. if ($shortfilename=='dolibarrcalendar')
  108. {
  109. $langs->load("main");
  110. $langs->load("errors");
  111. llxHeaderVierge();
  112. print '<div class="error">'.$langs->trans("ErrorWrongValueForParameterX",'format').'</div>';
  113. llxFooterVierge();
  114. exit;
  115. }
  116. $agenda=new ActionComm($db);
  117. $cachedelay=0;
  118. if (! empty($conf->global->MAIN_AGENDA_EXPORT_CACHE)) $cachedelay=$conf->global->MAIN_AGENDA_EXPORT_CACHE;
  119. // Build file
  120. if ($format == 'ical' || $format == 'vcal')
  121. {
  122. $result=$agenda->build_exportfile($format,$type,$cachedelay,$filename,$filters);
  123. if ($result >= 0)
  124. {
  125. $attachment = true;
  126. if (isset($_GET["attachment"])) $attachment=$_GET["attachment"];
  127. //$attachment = false;
  128. $contenttype='text/calendar';
  129. if (isset($_GET["contenttype"])) $contenttype=$_GET["contenttype"];
  130. //$contenttype='text/plain';
  131. $outputencoding='UTF-8';
  132. if ($contenttype) header('Content-Type: '.$contenttype.($outputencoding?'; charset='.$outputencoding:''));
  133. if ($attachment) header('Content-Disposition: attachment; filename="'.$shortfilename.'"');
  134. if ($cachedelay) header('Cache-Control: max-age='.$cachedelay.', private, must-revalidate');
  135. else header('Cache-Control: private, must-revalidate');
  136. // Clean parameters
  137. $outputfile=$conf->agenda->dir_temp.'/'.$filename;
  138. $result=readfile($outputfile);
  139. if (! $result) print 'File '.$outputfile.' was empty.';
  140. //header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
  141. exit;
  142. }
  143. else
  144. {
  145. print 'Error '.$agenda->error;
  146. exit;
  147. }
  148. }
  149. if ($format == 'rss')
  150. {
  151. $result=$agenda->build_exportfile($format,$type,$cachedelay,$filename,$filters);
  152. if ($result >= 0)
  153. {
  154. $attachment = false;
  155. if (isset($_GET["attachment"])) $attachment=$_GET["attachment"];
  156. //$attachment = false;
  157. $contenttype='application/rss+xml';
  158. if (isset($_GET["contenttype"])) $contenttype=$_GET["contenttype"];
  159. //$contenttype='text/plain';
  160. $outputencoding='UTF-8';
  161. if ($contenttype) header('Content-Type: '.$contenttype.($outputencoding?'; charset='.$outputencoding:''));
  162. if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
  163. // Ajout directives pour resoudre bug IE
  164. //header('Cache-Control: Public, must-revalidate');
  165. //header('Pragma: public');
  166. if ($cachedelay) header('Cache-Control: max-age='.$cachedelay.', private, must-revalidate');
  167. else header('Cache-Control: private, must-revalidate');
  168. // Clean parameters
  169. $outputfile=$conf->agenda->dir_temp.'/'.$filename;
  170. $result=readfile($outputfile);
  171. if (! $result) print 'File '.$outputfile.' was empty.';
  172. // header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
  173. exit;
  174. }
  175. else
  176. {
  177. print 'Error '.$agenda->error;
  178. exit;
  179. }
  180. }
  181. llxHeaderVierge();
  182. print '<div class="error">'.$agenda->error.'</div>';
  183. llxFooterVierge();
  184. ?>