summaryrefslogtreecommitdiffstats
path: root/apps/calendar/lib/app.php
blob: 27129e77e35774c83f5cc348c38d8c612d7c288c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
 * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

/**
 * This class manages our app actions
 */
OC_Calendar_App::$l10n = new OC_L10N('calendar');
class OC_Calendar_App{
	public static $l10n;

	public static function getCalendar($id){
		$calendar = OC_Calendar_Calendar::find( $id );
		if( $calendar === false || $calendar['userid'] != OC_User::getUser()){
			OC_JSON::error(array('data' => array('message' => self::$l10n->t('Wrong calendar'))));
			exit();
		}
		return $calendar;
	}

	public static function getEventObject($id){
		$event_object = OC_Calendar_Object::find( $id );
		if( $event_object === false ){
			OC_JSON::error();
			exit();
		}

		self::getCalendar( $event_object['calendarid'] );//access check
		return $event_object;
	}

	public static function getVCalendar($id){
		$event_object = self::getEventObject( $id );

		$vcalendar = OC_VObject::parse($event_object['calendardata']);
		// Check if the vcalendar is valid
		if(is_null($vcalendar)){
			OC_JSON::error();
			exit();
		}
		return $vcalendar;
	}

	public static function isNotModified($vevent, $lastmodified)
	{
		$last_modified = $vevent->__get('LAST-MODIFIED');
		if($last_modified && $lastmodified != $last_modified->getDateTime()->format('U')){
			OC_JSON::error(array('modified'=>true));
			exit;
		}
	}

	public static function getCategoryOptions()
	{
		return array(
			self::$l10n->t('Birthday'),
			self::$l10n->t('Business'),
			self::$l10n->t('Call'),
			self::$l10n->t('Clients'),
			self::$l10n->t('Deliverer'),
			self::$l10n->t('Holidays'),
			self::$l10n->t('Ideas'),
			self::$l10n->t('Journey'),
			self::$l10n->t('Jubilee'),
			self::$l10n->t('Meeting'),
			self::$l10n->t('Other'),
			self::$l10n->t('Personal'),
			self::$l10n->t('Projects'),
			self::$l10n->t('Questions'),
			self::$l10n->t('Work'),
		);
	}

	public static function getRepeatOptions(){
		return OC_Calendar_Object::getRepeatOptions(self::$l10n);
	}

	public static function getEndOptions(){
		return OC_Calendar_Object::getEndOptions(self::$l10n);
	}

	public static function getMonthOptions(){
		return OC_Calendar_Object::getMonthOptions(self::$l10n);
	}

	public static function getWeeklyOptions(){
		return OC_Calendar_Object::getWeeklyOptions(self::$l10n);
	}

	public static function getYearOptions(){
		return OC_Calendar_Object::getYearOptions(self::$l10n);
	}

	public static function getByYearDayOptions(){
		return OC_Calendar_Object::getByYearDayOptions();
	}

	public static function getByMonthOptions(){
		return OC_Calendar_Object::getByMonthOptions(self::$l10n);
	}
	
	public static function getByWeekNoOptions(){
		return OC_Calendar_Object::getByWeekNoOptions();
	}

	public static function getByMonthDayOptions(){
		return OC_Calendar_Object::getByMonthDayOptions();
	}
	
	public static function getWeekofMonth(){
		return OC_Calendar_Object::getWeekofMonth(self::$l10n);
	}
	
	public static function prepareForOutput($event, $vevent, $return_event){
		$return_event['id'] = (int)$event['id'];
		$return_event['title'] = htmlspecialchars($event['summary']);
		$return_event['description'] = isset($vevent->DESCRIPTION)?htmlspecialchars($vevent->DESCRIPTION->value):'';
		$last_modified = $vevent->__get('LAST-MODIFIED');
		if ($last_modified){
			$lastmodified = $last_modified->getDateTime()->format('U');
		}else{
			$lastmodified = 0;
		}
		$return_event['lastmodified'] = (int)$lastmodified;
		return $return_event;
		
	}
}