nextcloud/apps/tasks/ajax/addtask.php

38 lines
1.2 KiB
PHP
Raw Normal View History

2011-09-12 23:28:28 +04:00
<?php
// Init owncloud
require_once('../../../lib/base.php');
$l10n = new OC_L10N('tasks');
// Check if we are a user
if( !OC_User::isLoggedIn()){
echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
exit();
}
$cid = $_POST['id'];
$calendar = OC_Calendar_Calendar::findCalendar( $cid );
if( $calendar === false || $calendar['userid'] != OC_USER::getUser()){
echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your calendar!'))));
exit();
}
2011-09-14 00:44:15 +04:00
$errors = OC_Task_VTodo::validateRequest($_POST, $l10n);
if (!empty($errors)) {
echo json_encode( array( 'status' => 'error', 'data' => array( 'errors' => $errors )));
exit();
}
$vcalendar = OC_Task_VTodo::createVCalendarFromRequest($_POST);
2011-09-12 23:28:28 +04:00
$id = OC_Calendar_Object::add($cid, $vcalendar->serialize());
2011-09-14 00:44:15 +04:00
$priority_options = OC_Task_VTodo::getPriorityOptions($l10n);
2011-09-12 23:28:28 +04:00
$tmpl = new OC_Template('tasks','part.details');
2011-09-14 00:44:15 +04:00
$tmpl->assign('priority_options', $priority_options);
$tmpl->assign('details',$vcalendar->VTODO);
2011-09-12 23:28:28 +04:00
$tmpl->assign('id',$id);
$page = $tmpl->fetchPage();
echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id, 'page' => $page )));