calendar_ical_export.php 5.4 KB

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