summaryrefslogtreecommitdiffstats
path: root/apps/calendar/ajax/categories/rescan.php
blob: 9273986cad4816db90c5ea98793eba19ba822ba5 (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
<?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.
 */

 
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('calendar');

foreach ($_POST as $key=>$element) {
	debug('_POST: '.$key.'=>'.print_r($element, true));
}

function bailOut($msg) {
	OC_JSON::error(array('data' => array('message' => $msg)));
	OC_Log::write('calendar','ajax/categories/rescan.php: '.$msg, OC_Log::DEBUG);
	exit();
}
function debug($msg) {
	OC_Log::write('calendar','ajax/categories/rescan.php: '.$msg, OC_Log::DEBUG);
}

$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser());
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();

OC_JSON::success(array('data' => array('categories'=>$categories)));