streams/Code/Module/Tasks.php

123 lines
3.8 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
2021-12-03 03:01:39 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2016-04-19 03:38:38 +00:00
2019-05-28 23:42:32 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
2022-03-18 02:26:10 +00:00
use Code\Lib\Libsync;
2022-02-16 04:08:28 +00:00
use Code\Lib\Apps;
use Code\Widget\Tasklist;
2016-04-19 03:38:38 +00:00
2019-05-28 23:42:32 +00:00
require_once('include/event.php');
2016-04-19 03:38:38 +00:00
2021-12-02 23:02:31 +00:00
class Tasks extends Controller
{
public function init()
{
2021-12-03 03:01:39 +00:00
// logger('request: ' . print_r($_REQUEST,true));
2021-12-02 23:02:31 +00:00
$arr = [];
if (argc() > 1 && argv(1) === 'fetch') {
2021-12-03 03:01:39 +00:00
if (argc() > 2 && argv(2) === 'all') {
2021-12-02 23:02:31 +00:00
$arr['all'] = 1;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$x = tasks_fetch($arr);
$x['html'] = '';
if (isset($x['tasks']) && is_array($x['tasks'])) {
foreach ($x['tasks'] as $y) {
2021-12-23 09:50:41 +00:00
$x['html'] .= '<div class="tasklist-item"><input type="checkbox" onchange="taskComplete(' . $y['id'] . '); return false;" /> ' . $y['summary'] . '</div>';
2021-12-02 23:02:31 +00:00
}
}
json_return_and_die($x);
}
}
public function post()
{
2021-12-03 03:01:39 +00:00
// logger('post: ' . print_r($_POST,true));
2021-12-02 23:02:31 +00:00
if (!local_channel()) {
return;
}
$channel = App::get_channel();
if ((argc() > 2) && (argv(1) === 'complete') && intval(argv(2))) {
$ret = array('success' => false);
2021-12-03 03:01:39 +00:00
$r = q(
"select * from event where etype = 'task' and uid = %d and id = %d limit 1",
2021-12-02 23:02:31 +00:00
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) {
2022-03-18 02:26:10 +00:00
Libsync::build_sync_packet($channel['channel_id'], ['event' => [$x]]);
2021-12-02 23:02:31 +00:00
$ret['success'] = true;
}
}
json_return_and_die($ret);
}
if (argc() == 2 && argv(1) === 'new') {
$text = escape_tags(trim($_REQUEST['summary']));
if (!$text) {
return ['success' => false];
}
$event = [];
$event['account'] = $channel['channel_account_id'];
$event['uid'] = $channel['channel_id'];
$event['event_xchan'] = $channel['channel_hash'];
$event['etype'] = 'task';
$event['nofinish'] = true;
$event['created'] = $event['edited'] = $event['dtstart'] = datetime_convert();
$event['adjust'] = 1;
$event['allow_cid'] = '<' . $channel['channel_hash'] . '>';
$event['summary'] = escape_tags($_REQUEST['summary']);
$x = event_store_event($event);
if ($x) {
2022-03-18 02:26:10 +00:00
Libsync::build_sync_packet($channel['channel_id'], ['event' => [$x]]);
2021-12-02 23:02:31 +00:00
$x['success'] = true;
2022-03-18 02:26:10 +00:00
}
else {
2021-12-02 23:02:31 +00:00
$x = ['success' => false];
}
2022-03-18 02:26:10 +00:00
2021-12-02 23:02:31 +00:00
json_return_and_die($x);
}
}
public function get()
{
2019-06-30 02:23:31 +00:00
$desc = t('This app provides a simple personal and task list.');
$text = '<div class="section-content-info-wrapper">' . $desc . '</div>';
2021-12-02 23:02:31 +00:00
if (!(local_channel() && Apps::system_app_installed(local_channel(), 'Tasks'))) {
2019-06-30 02:23:31 +00:00
return $text;
}
2021-12-02 23:02:31 +00:00
$obj = new Tasklist();
return $obj->widget([]);
}
2016-04-19 03:38:38 +00:00
}