calendar_ical_export.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php // $id: $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos S.A.
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  14. ==============================================================================
  15. */
  16. /**
  17. ==============================================================================
  18. * @package dokeos.admin
  19. * @author Carlos Vargas
  20. * This file is the calendar/ical_export.php
  21. ==============================================================================
  22. */
  23. /**
  24. * Initialisation
  25. */
  26. // name of the language file that needs to be included
  27. $language_file = 'agenda';
  28. // we are not inside a course, so we reset the course id
  29. $cidReset = true;
  30. // setting the global file that gets the general configuration, the databases, the languages, ...
  31. require_once ('../inc/global.inc.php');
  32. $this_section = SECTION_MYAGENDA;
  33. api_block_anonymous_users();
  34. require_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  35. require_once (api_get_path(LIBRARY_PATH).'icalcreator/iCalcreator.class.php');
  36. // setting the name of the tool
  37. $nameTools = get_lang('MyAgenda');
  38. // setting the database variables
  39. //$TABLECOURS = Database :: get_main_table(TABLE_MAIN_COURSE);
  40. //$TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  41. //$TABLEAGENDA =Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  42. //$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  43. //$tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  44. // the variables for the days and the months
  45. // Defining the shorts for the days
  46. $DaysShort = array (get_lang("SundayShort"), get_lang("MondayShort"), get_lang("TuesdayShort"), get_lang("WednesdayShort"), get_lang("ThursdayShort"), get_lang("FridayShort"), get_lang("SaturdayShort"));
  47. // Defining the days of the week to allow translation of the days
  48. $DaysLong = array (get_lang("SundayLong"), get_lang("MondayLong"), get_lang("TuesdayLong"), get_lang("WednesdayLong"), get_lang("ThursdayLong"), get_lang("FridayLong"), get_lang("SaturdayLong"));
  49. // Defining the months of the year to allow translation of the months
  50. $MonthsLong = array (get_lang("JanuaryLong"), get_lang("FebruaryLong"), get_lang("MarchLong"), get_lang("AprilLong"), get_lang("MayLong"), get_lang("JuneLong"), get_lang("JulyLong"), get_lang("AugustLong"), get_lang("SeptemberLong"), get_lang("OctoberLong"), get_lang("NovemberLong"), get_lang("DecemberLong"));
  51. if(!empty($_GET['id']) && $_GET['id']==strval(intval($_GET['id'])))
  52. {
  53. define('ICAL_LANG',api_get_language_isocode());
  54. if(!empty($_GET['type']))
  55. {
  56. $ical = new vcalendar();
  57. $ical->setConfig('unique_id',api_get_path(WEB_PATH));
  58. $ical->setProperty( 'method', 'PUBLISH' );
  59. $ical->setConfig('url',api_get_path(WEB_PATH));
  60. $vevent = new vevent();
  61. switch($_GET['class'])
  62. {
  63. case 'public':
  64. $vevent->setClass('PUBLIC');
  65. break;
  66. case 'private':
  67. $vevent->setClass('PRIVATE');
  68. break;
  69. case 'confidential':
  70. $vevent->setClass('CONFIDENTIAL');
  71. break;
  72. default:
  73. $vevent->setClass('PRIVATE');
  74. break;
  75. }
  76. switch($_GET['type'])
  77. {
  78. case 'personal':
  79. //require_once (api_get_path(SYS_CODE_PATH).'calendar/myagenda.inc.php');
  80. $ai = get_personal_agenda_item($_GET['id']);
  81. $vevent->setProperty( 'summary', mb_convert_encoding($ai['title'],'UTF-8',$charset));
  82. if(empty($ai['date'])){header('location:'.$_SERVER['REFERER_URI']);}
  83. list($y,$m,$d,$h,$M,$s) = preg_split('/[\s:-]/',$ai['date']);
  84. $vevent->setProperty('dtstart',array('year'=>$y,'month'=>$m,'day'=>$d,'hour'=>$h,'min'=>$M,'sec'=>$s));
  85. if(empty($ai['enddate']))
  86. {
  87. $y2=$y;$m2=$m;$d2=$d;$h2=$h;$M2=$M+15;$s2=$s;
  88. if($M2>60){$M2=$M2-60;$h2+=1;}
  89. }
  90. else
  91. {
  92. list($y2,$m2,$d2,$h2,$M2,$s2) = preg_split('/[\s:-]/',$ai['enddate']);
  93. }
  94. $vevent->setProperty('dtend',array('year'=>$y2,'month'=>$m2,'day'=>$d2,'hour'=>$h2,'min'=>$M2,'sec'=>$s2));
  95. //$vevent->setProperty( 'LOCATION', get_lang('Unknown') ); // property name - case independent
  96. $vevent->setProperty( 'description', mb_convert_encoding($ai['text'],'UTF-8',$charset));
  97. //$vevent->setProperty( 'comment', 'This is a comment' );
  98. $user = api_get_user_info($ai['user']);
  99. $vevent->setProperty('organizer',$user['mail']);
  100. $vevent->setProperty('attendee',$user['mail']);
  101. //$vevent->setProperty( 'rrule', array( 'FREQ' => 'WEEKLY', 'count' => 4));// occurs also four next weeks
  102. $ical->setConfig('filename',$y.$m.$d.$h.$M.$s.'-'.rand(1,1000).'.ics');
  103. $ical->setComponent ($vevent); // add event to calendar
  104. $ical->returnCalendar();
  105. break;
  106. case 'course':
  107. $TABLEAGENDA =Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  108. //$TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  109. require_once (api_get_path(SYS_CODE_PATH).'admin/calendar.lib.php');
  110. $ai = get_agenda_item($_GET['id']);
  111. $vevent->setProperty( 'summary', mb_convert_encoding($ai['title'],'UTF-8',$charset));
  112. if(empty($ai['start_date'])){header('location:'.$_SERVER['REFERER_URI']);}
  113. list($y,$m,$d,$h,$M,$s) = preg_split('/[\s:-]/',$ai['start_date']);
  114. $vevent->setProperty('dtstart',array('year'=>$y,'month'=>$m,'day'=>$d,'hour'=>$h,'min'=>$M,'sec'=>$s));
  115. if(empty($ai['end_date']))
  116. {
  117. $y2=$y;$m2=$m;$d2=$d;$h2=$h;$M2=$M+15;$s2=$s;
  118. if($M2>60){$M2=$M2-60;$h2+=1;}
  119. }
  120. else
  121. {
  122. list($y2,$m2,$d2,$h2,$M2,$s2) = preg_split('/[\s:-]/',$ai['end_date']);
  123. }
  124. $vevent->setProperty('dtend',array('year'=>$y2,'month'=>$m2,'day'=>$d2,'hour'=>$h2,'min'=>$M2,'sec'=>$s2));
  125. $vevent->setProperty( 'description', mb_convert_encoding($ai['content'],'UTF-8',$charset));
  126. //$vevent->setProperty( 'comment', 'This is a comment' );
  127. $user = api_get_user_info($ai['user']);
  128. $vevent->setProperty('organizer',$user['mail']);
  129. //$vevent->setProperty('attendee',$user['mail']);
  130. $course = api_get_course_info();
  131. $vevent->setProperty('location', $course['name']); // property name - case independent
  132. if($ai['repeat'])
  133. {
  134. $trans = array('daily'=>'DAILY','weekly'=>'WEEKLY','monthlyByDate'=>'MONTHLY','yearly'=>'YEARLY');
  135. $freq = $trans[$ai['repeat_type']];
  136. list($e_y,$e_m,$e_d) = split('/',date('Y/m/d',$ai['repeat_end']));
  137. $vevent->setProperty('rrule',array('FREQ'=>$freq,'UNTIL'=>array('year'=>$e_y,'month'=>$e_m,'day'=>$e_d),'INTERVAL'=>'1'));
  138. }
  139. //$vevent->setProperty( 'rrule', array( 'FREQ' => 'WEEKLY', 'count' => 4));// occurs also four next weeks
  140. $ical->setConfig('filename',$y.$m.$d.$h.$M.$s.'-'.rand(1,1000).'.ics');
  141. $ical->setComponent ($vevent); // add event to calendar
  142. $ical->returnCalendar();
  143. break;
  144. default:
  145. header('location:'.$_SERVER['REFERER_URI']);
  146. die();
  147. }
  148. }
  149. }
  150. else
  151. {
  152. header('location:'.$_SERVER['REFERER_URI']);
  153. die();
  154. }
  155. ?>