2012-02-20 10:26:22 +00:00
|
|
|
<?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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Check if we are a user
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::checkLoggedIn();
|
|
|
|
OCP\JSON::checkAppEnabled('calendar');
|
2012-07-17 09:46:01 +00:00
|
|
|
OCP\JSON::callCheck();
|
2012-02-20 10:26:22 +00:00
|
|
|
|
2012-09-07 13:21:03 +00:00
|
|
|
if(trim($_POST['name']) == '') {
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::error(array('message'=>'empty'));
|
2012-02-20 10:26:22 +00:00
|
|
|
exit;
|
|
|
|
}
|
2012-05-01 16:50:31 +00:00
|
|
|
$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser());
|
2012-09-07 13:21:03 +00:00
|
|
|
foreach($calendars as $cal) {
|
|
|
|
if($cal['displayname'] == $_POST['name']) {
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::error(array('message'=>'namenotavailable'));
|
2012-02-20 10:26:22 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-01 16:50:31 +00:00
|
|
|
$userid = OCP\USER::getUser();
|
2012-02-20 10:26:22 +00:00
|
|
|
$calendarid = OC_Calendar_Calendar::addCalendar($userid, strip_tags($_POST['name']), 'VEVENT,VTODO,VJOURNAL', null, 0, $_POST['color']);
|
|
|
|
OC_Calendar_Calendar::setCalendarActive($calendarid, 1);
|
|
|
|
|
|
|
|
$calendar = OC_Calendar_Calendar::find($calendarid);
|
2012-05-06 21:00:36 +00:00
|
|
|
$tmpl = new OCP\Template('calendar', 'part.choosecalendar.rowfields');
|
2012-02-20 10:26:22 +00:00
|
|
|
$tmpl->assign('calendar', $calendar);
|
2012-09-02 16:16:03 +00:00
|
|
|
$tmpl->assign('shared', false);
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::success(array(
|
2012-02-20 10:26:22 +00:00
|
|
|
'page' => $tmpl->fetchPage(),
|
|
|
|
'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar),
|
2012-06-21 21:20:09 +00:00
|
|
|
));
|