calendar_ical_export.php 6.0 KB

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