ical_export.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file exclusively export calendar items to iCal or similar formats
  5. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  6. */
  7. // name of the language file that needs to be included
  8. $language_file = 'agenda';
  9. // we are not inside a course, so we reset the course id
  10. $cidReset = true;
  11. // setting the global file that gets the general configuration, the databases, the languages, ...
  12. require_once '../inc/global.inc.php';
  13. $this_section = SECTION_MYAGENDA;
  14. api_block_anonymous_users();
  15. // setting the name of the tool
  16. $nameTools = get_lang('MyAgenda');
  17. // the variables for the days and the months
  18. // Defining the shorts for the days
  19. $DaysShort = api_get_week_days_short();
  20. // Defining the days of the week to allow translation of the days
  21. $DaysLong = api_get_week_days_long();
  22. // Defining the months of the year to allow translation of the months
  23. $MonthsLong = api_get_months_long();
  24. if (empty($_GET['id'])) {
  25. api_not_allowed();
  26. }
  27. $id = explode('_', $_GET['id']);
  28. $type = $id[0];
  29. $id = $id[1];
  30. $agenda = new Agenda();
  31. $agenda->type = $type; //course,admin or personal
  32. if (isset($_GET['course_id'])) {
  33. $course_info = api_get_course_info_by_id($_GET['course_id']);
  34. if (!empty($course_info)) {
  35. $agenda->set_course($course_info);
  36. }
  37. }
  38. $event = $agenda->get_event($id);
  39. if (!empty($event)) {
  40. define('ICAL_LANG',api_get_language_isocode());
  41. $ical = new vcalendar();
  42. $ical->setConfig('unique_id',api_get_path(WEB_PATH));
  43. $ical->setProperty( 'method', 'PUBLISH' );
  44. $ical->setConfig('url',api_get_path(WEB_PATH));
  45. $vevent = new vevent();
  46. switch($_GET['class']) {
  47. case 'public':
  48. $vevent->setClass('PUBLIC');
  49. break;
  50. case 'private':
  51. $vevent->setClass('PRIVATE');
  52. break;
  53. case 'confidential':
  54. $vevent->setClass('CONFIDENTIAL');
  55. break;
  56. default:
  57. $vevent->setClass('PRIVATE');
  58. break;
  59. }
  60. $event['start_date'] = api_get_local_time($event['start_date']);
  61. $event['end_date'] = api_get_local_time($event['end_date']);
  62. switch($type) {
  63. case 'personal':
  64. case 'platform':
  65. $vevent->setProperty( 'summary', api_convert_encoding($event['title'],'UTF-8', $charset));
  66. if(empty($event['start_date'])){header('location:'.Security::remove_XSS($_SERVER['HTTP_REFERER']));}
  67. list($y,$m,$d,$h,$M,$s) = preg_split('/[\s:-]/',$event['start_date']);
  68. $vevent->setProperty('dtstart',array('year'=>$y,'month'=>$m,'day'=>$d,'hour'=>$h,'min'=>$M,'sec'=>$s));
  69. if(empty($event['end_date'])) {
  70. $y2=$y;$m2=$m;$d2=$d;$h2=$h;$M2=$M+15;$s2=$s;
  71. if($M2>60){$M2=$M2-60;$h2+=1;}
  72. } else {
  73. list($y2,$m2,$d2,$h2,$M2,$s2) = preg_split('/[\s:-]/',$event['end_date']);
  74. }
  75. $vevent->setProperty('dtend',array('year'=>$y2,'month'=>$m2,'day'=>$d2,'hour'=>$h2,'min'=>$M2,'sec'=>$s2));
  76. //$vevent->setProperty( 'LOCATION', get_lang('Unknown') ); // property name - case independent
  77. $vevent->setProperty( 'description', api_convert_encoding($event['description'],'UTF-8',$charset));
  78. //$vevent->setProperty( 'comment', 'This is a comment' );
  79. //$user = api_get_user_info($event['user']);
  80. //$vevent->setProperty('organizer',$user['mail']);
  81. //$vevent->setProperty('attendee',$user['mail']);
  82. //$vevent->setProperty( 'rrule', array( 'FREQ' => 'WEEKLY', 'count' => 4));// occurs also four next weeks
  83. $ical->setConfig('filename',$y.$m.$d.$h.$M.$s.'-'.rand(1,1000).'.ics');
  84. $ical->setComponent ($vevent); // add event to calendar
  85. $ical->returnCalendar();
  86. break;
  87. case 'course':
  88. $vevent->setProperty( 'summary', api_convert_encoding($event['title'],'UTF-8',$charset));
  89. if(empty($event['start_date'])){header('location:'.Security::remove_XSS($_SERVER['HTTP_REFERER']));}
  90. list($y,$m,$d,$h,$M,$s) = preg_split('/[\s:-]/',$event['start_date']);
  91. $vevent->setProperty('dtstart',array('year'=>$y,'month'=>$m,'day'=>$d,'hour'=>$h,'min'=>$M,'sec'=>$s));
  92. if (empty($event['end_date'])) {
  93. $y2=$y;$m2=$m;$d2=$d;$h2=$h;$M2=$M+15;$s2=$s;
  94. if($M2>60){$M2=$M2-60;$h2+=1;}
  95. } else {
  96. list($y2,$m2,$d2,$h2,$M2,$s2) = preg_split('/[\s:-]/',$event['end_date']);
  97. }
  98. $vevent->setProperty('dtend',array('year'=>$y2,'month'=>$m2,'day'=>$d2,'hour'=>$h2,'min'=>$M2,'sec'=>$s2));
  99. $vevent->setProperty( 'description', api_convert_encoding($event['description'],'UTF-8',$charset));
  100. //$vevent->setProperty( 'comment', 'This is a comment' );
  101. //$user = api_get_user_info($event['user']);
  102. //$vevent->setProperty('organizer',$user['mail']);
  103. //$vevent->setProperty('attendee',$user['mail']);
  104. //$course = api_get_course_info();
  105. $vevent->setProperty('location', $course_info['name']); // property name - case independent
  106. /*if($ai['repeat']) {
  107. $trans = array('daily'=>'DAILY','weekly'=>'WEEKLY','monthlyByDate'=>'MONTHLY','yearly'=>'YEARLY');
  108. $freq = $trans[$ai['repeat_type']];
  109. list($e_y,$e_m,$e_d) = split('/',date('Y/m/d',$ai['repeat_end']));
  110. $vevent->setProperty('rrule',array('FREQ'=>$freq,'UNTIL'=>array('year'=>$e_y,'month'=>$e_m,'day'=>$e_d),'INTERVAL'=>'1'));
  111. }*/
  112. //$vevent->setProperty( 'rrule', array( 'FREQ' => 'WEEKLY', 'count' => 4));// occurs also four next weeks
  113. $ical->setConfig('filename',$y.$m.$d.$h.$M.$s.'-'.rand(1,1000).'.ics');
  114. $ical->setComponent ($vevent); // add event to calendar
  115. $ical->returnCalendar();
  116. break;
  117. default:
  118. header('location:'.Security::remove_XSS($_SERVER['HTTP_REFERER']));
  119. die();
  120. }
  121. } else {
  122. header('location:'.Security::remove_XSS($_SERVER['HTTP_REFERER']));
  123. die();
  124. }