summaryrefslogtreecommitdiffstats
path: root/apps/tasks/ajax/update_property.php
blob: 46521cf6c585a2604f2ef3f6fa0993e7aa2cc6b1 (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
<?php
/**
 * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

// Init owncloud
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('tasks');

$id = $_POST['id'];
$property = $_POST['type'];
$vcalendar = OC_Calendar_App::getVCalendar( $id );

$vtodo = $vcalendar->VTODO;
switch($property) {
	case 'summary':
		$summary = $_POST['summary'];
		$vtodo->setString('SUMMARY', $summary);
		break;
	case 'description':
		$description = $_POST['description'];
		$vtodo->setString('DESCRIPTION', $description);
		break;
	case 'location':
		$location = $_POST['location'];
		$vtodo->setString('LOCATION', $location);
		break;
	case 'categories':
		$categories = $_POST['categories'];
		$vtodo->setString('CATEGORIES', $categories);
		break;
	case 'due':
		$due = $_POST['due'];
		$due_date_only = $_POST['date'];
		$type = null;
		if ($due != 'false') {
			try {
				$timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
				$timezone = new DateTimeZone($timezone);
				$due = new DateTime('@'.$due);
				$due->setTimezone($timezone);
				$type = Sabre_VObject_Element_DateTime::LOCALTZ;
				if ($due_date_only) {
					$type = Sabre_VObject_Element_DateTime::DATE;
				}
			} catch (Exception $e) {
				OCP\JSON::error(array('data'=>array('message'=>OC_Task_App::$l10n->t('Invalid date/time'))));
				exit();
			}
		}
		$vtodo->setDateTime('DUE', $due, $type);
		break;
	case 'complete':
		$checked = $_POST['checked'];
		OC_Task_App::setComplete($vtodo, $checked ? '100' : '0', null);
		break;
	default:
		OCP\JSON::error(array('data'=>array('message'=>'Unknown type')));
		exit();
}
OC_Calendar_Object::edit($id, $vcalendar->serialize());

$user_timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$task_info = OC_Task_App::arrayForJSON($id, $vtodo, $user_timezone);
OCP\JSON::success(array('data' => $task_info));