aboutsummaryrefslogtreecommitdiffstats
path: root/mod/tasks.php
blob: b1b81473b63bfc63740c262edf22250256fbfc87 (plain) (blame)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php

require_once('include/event.php');


function tasks_init(&$a) {


//	logger('request: ' . print_r($_REQUEST,true));

	$arr = array();

	if(argc() > 1 && argv(1) === 'fetch') {		
		if(argc() > 2 && argv(2) === 'all')
			$arr['all'] = 1;
		
		$x = tasks_fetch($arr);
		if($x['tasks']) {
			$x['html'] = '';
			foreach($x['tasks'] as $y) {
				$x['html'] .= '<div class="tasklist-item"><input type="checkbox" onchange="taskComplete(' . $y['id'] . '); return false;" /> ' . $y['summary'] . '</div>';
			}
		}
		json_return_and_die($x);
	}

}



function tasks_post(&$a) {


//	logger('post: ' . print_r($_POST,true));


	if(! local_channel())
		return;

	$channel = $a->get_channel();

	if((argc() > 2) && (argv(1) === 'complete') && intval(argv(2))) {
		$ret = array('success' => false);
		$r = q("select * from event where `type` = 'task' and uid = %d and id = %d limit 1",
			intval(local_channel()),
			intval(argv(2))
		);
		if($r) {
			$event = $r[0];
			if($event['event_status'] === 'COMPLETED') {
				$event['event_status'] = 'IN-PROCESS';
				$event['event_status_date'] = NULL_DATE;
				$event['event_percent'] = 0;
				$event['event_sequence'] = $event['event_sequence'] + 1;
				$event['edited'] = datetime_convert();
			}
			else {
				$event['event_status'] = 'COMPLETED';
				$event['event_status_date'] = datetime_convert();
				$event['event_percent'] = 100;
				$event['event_sequence'] = $event['event_sequence'] + 1;
				$event['edited'] = datetime_convert();
			}
			$x = event_store_event($event);
			if($x)
				$ret['success'] = true;
		}
		json_return_and_die($ret);
	}

	if(argc() == 2 && argv(1) === 'new') {
		$text = escape_tags(trim($_REQUEST['summary']));
		if(! $text)
			return array('success' => false);
		$event = array();
		$event['account'] = $channel['channel_account_id'];
		$event['uid'] = $channel['channel_id'];
		$event['event_xchan'] = $channel['channel_hash'];
		$event['type'] = 'task';
		$event['nofinish'] = true;
		$event['created'] = $event['edited'] = $event['start'] = datetime_convert();
		$event['adjust'] = 1;
		$event['allow_cid'] = '<' . $channel['channel_hash'] . '>';
		$event['summary'] = escape_tags($_REQUEST['summary']);
		$x = event_store_event($event);
		if($x)
			$x['success'] = true;
		else
			$x = array('success' => false);
		json_return_and_die($x);
	}

	
}





function tasks_content(&$a) {

	if(! local_channel())
		return;


	return '';
}