edit.form.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. /**
  3. * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. if(!OCP\User::isLoggedIn()) {
  9. die('<script type="text/javascript">document.location = oc_webroot;</script>');
  10. }
  11. OCP\JSON::checkAppEnabled('calendar');
  12. $id = $_GET['id'];
  13. $data = OC_Calendar_App::getEventObject($id, true, true);
  14. if(!$data){
  15. OCP\JSON::error(array('data' => array('message' => self::$l10n->t('Wrong calendar'))));
  16. exit;
  17. }
  18. $access = OC_Calendar_App::getaccess($id, OC_Calendar_Share::EVENT);
  19. $object = OC_VObject::parse($data['calendardata']);
  20. $vevent = $object->VEVENT;
  21. $dtstart = $vevent->DTSTART;
  22. $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
  23. switch($dtstart->getDateType()) {
  24. case Sabre_VObject_Property_DateTime::LOCALTZ:
  25. case Sabre_VObject_Property_DateTime::LOCAL:
  26. $startdate = $dtstart->getDateTime()->format('d-m-Y');
  27. $starttime = $dtstart->getDateTime()->format('H:i');
  28. $enddate = $dtend->getDateTime()->format('d-m-Y');
  29. $endtime = $dtend->getDateTime()->format('H:i');
  30. $allday = false;
  31. break;
  32. case Sabre_VObject_Property_DateTime::DATE:
  33. $startdate = $dtstart->getDateTime()->format('d-m-Y');
  34. $starttime = '';
  35. $dtend->getDateTime()->modify('-1 day');
  36. $enddate = $dtend->getDateTime()->format('d-m-Y');
  37. $endtime = '';
  38. $allday = true;
  39. break;
  40. }
  41. $summary = $vevent->getAsString('SUMMARY');
  42. $location = $vevent->getAsString('LOCATION');
  43. $categories = $vevent->getAsString('CATEGORIES');
  44. $description = $vevent->getAsString('DESCRIPTION');
  45. $last_modified = $vevent->__get('LAST-MODIFIED');
  46. if ($last_modified){
  47. $lastmodified = $last_modified->getDateTime()->format('U');
  48. }else{
  49. $lastmodified = 0;
  50. }
  51. if($data['repeating'] == 1){
  52. $rrule = explode(';', $vevent->getAsString('RRULE'));
  53. $rrulearr = array();
  54. foreach($rrule as $rule){
  55. list($attr, $val) = explode('=', $rule);
  56. $rrulearr[$attr] = $val;
  57. }
  58. if(!isset($rrulearr['INTERVAL']) || $rrulearr['INTERVAL'] == ''){
  59. $rrulearr['INTERVAL'] = 1;
  60. }
  61. if(array_key_exists('BYDAY', $rrulearr)){
  62. if(substr_count($rrulearr['BYDAY'], ',') == 0){
  63. if(strlen($rrulearr['BYDAY']) == 2){
  64. $repeat['weekdays'] = array($rrulearr['BYDAY']);
  65. }elseif(strlen($rrulearr['BYDAY']) == 3){
  66. $repeat['weekofmonth'] = substr($rrulearr['BYDAY'], 0, 1);
  67. $repeat['weekdays'] = array(substr($rrulearr['BYDAY'], 1, 2));
  68. }elseif(strlen($rrulearr['BYDAY']) == 4){
  69. $repeat['weekofmonth'] = substr($rrulearr['BYDAY'], 0, 2);
  70. $repeat['weekdays'] = array(substr($rrulearr['BYDAY'], 2, 2));
  71. }
  72. }else{
  73. $byday_days = explode(',', $rrulearr['BYDAY']);
  74. foreach($byday_days as $byday_day){
  75. if(strlen($byday_day) == 2){
  76. $repeat['weekdays'][] = $byday_day;
  77. }elseif(strlen($byday_day) == 3){
  78. $repeat['weekofmonth'] = substr($byday_day , 0, 1);
  79. $repeat['weekdays'][] = substr($byday_day , 1, 2);
  80. }elseif(strlen($byday_day) == 4){
  81. $repeat['weekofmonth'] = substr($byday_day , 0, 2);
  82. $repeat['weekdays'][] = substr($byday_day , 2, 2);
  83. }
  84. }
  85. }
  86. }
  87. if(array_key_exists('BYMONTHDAY', $rrulearr)){
  88. if(substr_count($rrulearr['BYMONTHDAY'], ',') == 0){
  89. $repeat['bymonthday'][] = $rrulearr['BYMONTHDAY'];
  90. }else{
  91. $bymonthdays = explode(',', $rrulearr['BYMONTHDAY']);
  92. foreach($bymonthdays as $bymonthday){
  93. $repeat['bymonthday'][] = $bymonthday;
  94. }
  95. }
  96. }
  97. if(array_key_exists('BYYEARDAY', $rrulearr)){
  98. if(substr_count($rrulearr['BYYEARDAY'], ',') == 0){
  99. $repeat['byyearday'][] = $rrulearr['BYYEARDAY'];
  100. }else{
  101. $byyeardays = explode(',', $rrulearr['BYYEARDAY']);
  102. foreach($byyeardays as $yearday){
  103. $repeat['byyearday'][] = $yearday;
  104. }
  105. }
  106. }
  107. if(array_key_exists('BYWEEKNO', $rrulearr)){
  108. if(substr_count($rrulearr['BYWEEKNO'], ',') == 0){
  109. $repeat['byweekno'][] = (string) $rrulearr['BYWEEKNO'];
  110. }else{
  111. $byweekno = explode(',', $rrulearr['BYWEEKNO']);
  112. foreach($byweekno as $weekno){
  113. $repeat['byweekno'][] = (string) $weekno;
  114. }
  115. }
  116. }
  117. if(array_key_exists('BYMONTH', $rrulearr)){
  118. $months = OC_Calendar_App::getByMonthOptions();
  119. if(substr_count($rrulearr['BYMONTH'], ',') == 0){
  120. $repeat['bymonth'][] = $months[$month];
  121. }else{
  122. $bymonth = explode(',', $rrulearr['BYMONTH']);
  123. foreach($bymonth as $month){
  124. $repeat['bymonth'][] = $months[$month];
  125. }
  126. }
  127. }
  128. switch($rrulearr['FREQ']){
  129. case 'DAILY':
  130. $repeat['repeat'] = 'daily';
  131. break;
  132. case 'WEEKLY':
  133. if($rrulearr['INTERVAL'] % 2 == 0){
  134. $repeat['repeat'] = 'biweekly';
  135. $rrulearr['INTERVAL'] = $rrulearr['INTERVAL'] / 2;
  136. }elseif($rrulearr['BYDAY'] == 'MO,TU,WE,TH,FR'){
  137. $repeat['repeat'] = 'weekday';
  138. }else{
  139. $repeat['repeat'] = 'weekly';
  140. }
  141. break;
  142. case 'MONTHLY':
  143. $repeat['repeat'] = 'monthly';
  144. if(array_key_exists('BYDAY', $rrulearr)){
  145. $repeat['month'] = 'weekday';
  146. }else{
  147. $repeat['month'] = 'monthday';
  148. }
  149. break;
  150. case 'YEARLY':
  151. $repeat['repeat'] = 'yearly';
  152. if(array_key_exists('BYMONTH', $rrulearr)){
  153. $repeat['year'] = 'bydaymonth';
  154. }elseif(array_key_exists('BYWEEKNO', $rrulearr)){
  155. $repeat['year'] = 'byweekno';
  156. }else{
  157. $repeat['year'] = 'byyearday';
  158. }
  159. }
  160. $repeat['interval'] = $rrulearr['INTERVAL'];
  161. if(array_key_exists('COUNT', $rrulearr)){
  162. $repeat['end'] = 'count';
  163. $repeat['count'] = $rrulearr['COUNT'];
  164. }elseif(array_key_exists('UNTIL', $rrulearr)){
  165. $repeat['end'] = 'date';
  166. $endbydate_day = substr($rrulearr['UNTIL'], 6, 2);
  167. $endbydate_month = substr($rrulearr['UNTIL'], 4, 2);
  168. $endbydate_year = substr($rrulearr['UNTIL'], 0, 4);
  169. $repeat['date'] = $endbydate_day . '-' . $endbydate_month . '-' . $endbydate_year;
  170. }else{
  171. $repeat['end'] = 'never';
  172. }
  173. if(array_key_exists('weekdays', $repeat)){
  174. $repeat_weekdays_ = array();
  175. $days = OC_Calendar_App::getWeeklyOptions();
  176. foreach($repeat['weekdays'] as $weekday){
  177. $repeat_weekdays_[] = $days[$weekday];
  178. }
  179. $repeat['weekdays'] = $repeat_weekdays_;
  180. }
  181. }else{
  182. $repeat['repeat'] = 'doesnotrepeat';
  183. }
  184. if($access == 'owner'){
  185. $calendar_options = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser());
  186. }else{
  187. $calendar_options = array(OC_Calendar_App::getCalendar($data['calendarid'], false));
  188. }
  189. $category_options = OC_Calendar_App::getCategoryOptions();
  190. $repeat_options = OC_Calendar_App::getRepeatOptions();
  191. $repeat_end_options = OC_Calendar_App::getEndOptions();
  192. $repeat_month_options = OC_Calendar_App::getMonthOptions();
  193. $repeat_year_options = OC_Calendar_App::getYearOptions();
  194. $repeat_weekly_options = OC_Calendar_App::getWeeklyOptions();
  195. $repeat_weekofmonth_options = OC_Calendar_App::getWeekofMonth();
  196. $repeat_byyearday_options = OC_Calendar_App::getByYearDayOptions();
  197. $repeat_bymonth_options = OC_Calendar_App::getByMonthOptions();
  198. $repeat_byweekno_options = OC_Calendar_App::getByWeekNoOptions();
  199. $repeat_bymonthday_options = OC_Calendar_App::getByMonthDayOptions();
  200. if($access == 'owner' || $access == 'rw'){
  201. $tmpl = new OCP\Template('calendar', 'part.editevent');
  202. }elseif($access == 'r'){
  203. $tmpl = new OCP\Template('calendar', 'part.showevent');
  204. }
  205. $tmpl->assign('eventid', $id);
  206. $tmpl->assign('access', $access);
  207. $tmpl->assign('lastmodified', $lastmodified);
  208. $tmpl->assign('calendar_options', $calendar_options);
  209. $tmpl->assign('repeat_options', $repeat_options);
  210. $tmpl->assign('repeat_month_options', $repeat_month_options);
  211. $tmpl->assign('repeat_weekly_options', $repeat_weekly_options);
  212. $tmpl->assign('repeat_end_options', $repeat_end_options);
  213. $tmpl->assign('repeat_year_options', $repeat_year_options);
  214. $tmpl->assign('repeat_byyearday_options', $repeat_byyearday_options);
  215. $tmpl->assign('repeat_bymonth_options', $repeat_bymonth_options);
  216. $tmpl->assign('repeat_byweekno_options', $repeat_byweekno_options);
  217. $tmpl->assign('repeat_bymonthday_options', $repeat_bymonthday_options);
  218. $tmpl->assign('repeat_weekofmonth_options', $repeat_weekofmonth_options);
  219. $tmpl->assign('title', $summary);
  220. $tmpl->assign('location', $location);
  221. $tmpl->assign('categories', $categories);
  222. $tmpl->assign('calendar', $data['calendarid']);
  223. $tmpl->assign('allday', $allday);
  224. $tmpl->assign('startdate', $startdate);
  225. $tmpl->assign('starttime', $starttime);
  226. $tmpl->assign('enddate', $enddate);
  227. $tmpl->assign('endtime', $endtime);
  228. $tmpl->assign('description', $description);
  229. $tmpl->assign('repeat', $repeat['repeat']);
  230. if($repeat['repeat'] != 'doesnotrepeat'){
  231. $tmpl->assign('repeat_month', $repeat['month']);
  232. $tmpl->assign('repeat_weekdays', $repeat['weekdays']);
  233. $tmpl->assign('repeat_interval', $repeat['interval']);
  234. $tmpl->assign('repeat_end', $repeat['end']);
  235. $tmpl->assign('repeat_count', $repeat['count']);
  236. $tmpl->assign('repeat_weekofmonth', $repeat['weekofmonth']);
  237. $tmpl->assign('repeat_date', $repeat['date']);
  238. $tmpl->assign('repeat_year', $repeat['year']);
  239. $tmpl->assign('repeat_byyearday', $repeat['byyearday']);
  240. $tmpl->assign('repeat_bymonthday', $repeat['bymonthday']);
  241. $tmpl->assign('repeat_bymonth', $repeat['bymonth']);
  242. $tmpl->assign('repeat_byweekno', $repeat['byweekno']);
  243. } else {
  244. $tmpl->assign('repeat_month', 'monthday');
  245. $tmpl->assign('repeat_weekdays', array());
  246. $tmpl->assign('repeat_interval', 1);
  247. $tmpl->assign('repeat_end', 'never');
  248. $tmpl->assign('repeat_count', '10');
  249. $tmpl->assign('repeat_weekofmonth', 'auto');
  250. $tmpl->assign('repeat_date', '');
  251. $tmpl->assign('repeat_year', 'bydate');
  252. }
  253. $tmpl->printpage();