2012-04-13 18:50:11 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2012-04-17 21:31:29 +04:00
|
|
|
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::checkLoggedIn();
|
|
|
|
OCP\JSON::checkAppEnabled('calendar');
|
2012-07-17 13:46:01 +04:00
|
|
|
OCP\JSON::callCheck();
|
2012-04-13 18:50:11 +04:00
|
|
|
|
|
|
|
foreach ($_POST as $key=>$element) {
|
|
|
|
debug('_POST: '.$key.'=>'.print_r($element, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
function bailOut($msg) {
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::error(array('data' => array('message' => $msg)));
|
2012-05-01 19:38:27 +04:00
|
|
|
OCP\Util::writeLog('calendar','ajax/categories/rescan.php: '.$msg, OCP\Util::DEBUG);
|
2012-04-13 18:50:11 +04:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
function debug($msg) {
|
2012-05-01 19:38:27 +04:00
|
|
|
OCP\Util::writeLog('calendar','ajax/categories/rescan.php: '.$msg, OCP\Util::DEBUG);
|
2012-04-13 18:50:11 +04:00
|
|
|
}
|
|
|
|
|
2012-05-01 20:50:31 +04:00
|
|
|
$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser());
|
2012-04-13 18:50:11 +04:00
|
|
|
if(count($calendars) == 0) {
|
|
|
|
bailOut(OC_Calendar_App::$l10n->t('No calendars found.'));
|
|
|
|
}
|
|
|
|
$events = array();
|
|
|
|
foreach($calendars as $calendar) {
|
|
|
|
$calendar_events = OC_Calendar_Object::all($calendar['id']);
|
|
|
|
$events = $events + $calendar_events;
|
|
|
|
}
|
|
|
|
if(count($events) == 0) {
|
|
|
|
bailOut(OC_Calendar_App::$l10n->t('No events found.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
OC_Calendar_App::scanCategories($events);
|
|
|
|
$categories = OC_Calendar_App::getCategoryOptions();
|
|
|
|
|
2012-06-16 11:45:17 +04:00
|
|
|
OCP\JSON::success(array('data' => array('categories'=>$categories)));
|