calendar_ical_export.php 5.3 KB

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