summaryrefslogtreecommitdiffstats
path: root/apps/tasks/index.php
blob: f0e6c2e4ddb3ada270463db8670f18e79ed7ee60 (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
<?php
/*************************************************
 * ownCloud - Tasks Plugin                        *
 *                                                *
 * (c) Copyright 2011 Bart Visscher               *
 * This file is licensed under the Affero General *
 * Public License version 3 or later.             *
 * See the COPYING-README file.                   *
 *************************************************/

require_once ('../../lib/base.php');
OC_Util::checkLoggedIn();
OC_Util::checkAppEnabled('tasks');

$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), true);
if( count($calendars) == 0 ) {
	header('Location: ' . OC_Helper::linkTo('calendar', 'index.php'));
	exit;
}

$id = isset( $_GET['id'] ) ? $_GET['id'] : null;

$tasks = array();
foreach( $calendars as $calendar ){
        $calendar_tasks = OC_Calendar_Object::all($calendar['id']);
        foreach( $calendar_tasks as $task ){
                if($task['objecttype']!='VTODO'){
                        continue;
                }
                if(is_null($task['summary'])){
                        continue;
                }
                $tasks[] = array( 'name' => $task['summary'], 'id' => $task['id'] );
        }
}

$details = null;
if( !is_null($id) || count($tasks)){
        if(is_null($id)) $id = $tasks[0]['id'];
        $task = OC_Calendar_Object::find($id);
        $details = Sabre_VObject_Reader::read($task['calendardata'])->VTODO;
}

OC_UTIL::addScript('tasks', 'tasks');
OC_UTIL::addStyle('tasks', 'style');
OC_APP::setActiveNavigationEntry('tasks_index');

$l10n = new OC_L10N('tasks');
$priority_options = OC_Task_App::getPriorityOptions();
$output = new OC_Template('tasks', 'tasks', 'user');
$output->assign('tasks', $tasks);
$output->assign('details', $details);
$output->assign('priority_options', $priority_options);
$output->assign('id',$id);
$output -> printPage();