some event related fixes and some base work for implementing native tasks (to-do lists); which should already be importable and exportable.

This commit is contained in:
redmatrix 2015-08-20 16:49:13 -07:00
parent a322254f2a
commit 6590ca02de
3 changed files with 100 additions and 18 deletions

View File

@ -89,14 +89,14 @@ function events_post(&$a) {
$summary = escape_tags(trim($_POST['summary']));
$desc = escape_tags(trim($_POST['desc']));
$location = escape_tags(trim($_POST['location']));
$type = 'event';
$type = escape_tags(trim($_POST['type']));
require_once('include/text.php');
linkify_tags($a, $desc, local_channel());
linkify_tags($a, $location, local_channel());
$action = ($event_hash == '') ? 'new' : "event/" . $event_hash;
$onerror_url = $a->get_baseurl() . "/events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish";
$onerror_url = $a->get_baseurl() . "/events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish&type=$type";
if(strcmp($finish,$start) < 0 && !$nofinish) {
notice( t('Event can not end before it has started.') . EOL);
if(intval($_REQUEST['preview'])) {
@ -400,7 +400,7 @@ function events_content(&$a) {
$r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan
from event left join item on event_hash = resource_id
where resource_type = 'event' and event.uid = %d $ignored
where resource_type in ( 'event', 'birthday' ) and event.uid = %d $ignored
AND (( `adjust` = 0 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' )
OR ( `adjust` = 1 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' )) ",
intval(local_channel()),
@ -409,7 +409,6 @@ function events_content(&$a) {
dbesc($adjust_start),
dbesc($adjust_finish)
);
}
$links = array();
@ -572,9 +571,7 @@ function events_content(&$a) {
if(x($_REQUEST,'location')) $orig_event['location'] = $_REQUEST['location'];
if(x($_REQUEST,'start')) $orig_event['start'] = $_REQUEST['start'];
if(x($_REQUEST,'finish')) $orig_event['finish'] = $_REQUEST['finish'];
}
if($mode === 'edit' || $mode === 'new') {
if(x($_REQUEST,'type')) $orig_event['type'] = $_REQUEST['type'];
$n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : '');
$a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : '');
@ -593,9 +590,6 @@ function events_content(&$a) {
if($orig_event['event_xchan'])
$sh_checked .= ' disabled="disabled" ';
$sdt = ((x($orig_event)) ? $orig_event['start'] : 'now');
$fdt = ((x($orig_event)) ? $orig_event['finish'] : 'now');
@ -621,6 +615,7 @@ function events_content(&$a) {
$fminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0);
$ftext = datetime_convert('UTC',$tz,$fdt);
$ftext = substr($ftext,0,14) . "00:00";
$type = ((x($orig_event)) ? $orig_event['type'] : 'event');
$f = get_config('system','event_input_format');
if(! $f)
@ -660,6 +655,7 @@ function events_content(&$a) {
$o .= replace_macros($tpl,array(
'$post' => $a->get_baseurl() . '/events',
'$eid' => $eid,
'$type' => $type,
'$xchan' => $event_xchan,
'$mid' => $mid,
'$event_hash' => $event_id,

93
mod/tasks.php Normal file
View File

@ -0,0 +1,93 @@
<?php
function tasks_post(&$a) {
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['aid'] = $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;
$ret = array();
$sql_extra = " and event_status != 'COMPLETED' ";
if(argc() > 1 && argv(1) === 'all')
$sql_extra = '';
$r = q("select * from event where type = 'task' and uid = %d $sql_extra ",
intval(local_channel())
);
$ret['success'] = (($r) ? true : false);
if($r) {
$ret['tasks'] = $r;
}
json_return_and_die($r);
}

View File

@ -12,6 +12,7 @@
<input type="hidden" name="event_hash" value="{{$event_hash}}" />
<input type="hidden" name="xchan" value="{{$xchan}}" />
<input type="hidden" name="mid" value="{{$mid}}" />
<input type="hidden" name="type" value="{{$type}}" />
<input type="hidden" name="preview" id="event-edit-preview" value="0" />
<div id="event-summary-text">{{$t_text}}</div>
@ -92,14 +93,6 @@
</div>
</div>
<!-- <div class="btn-group pull-right" id="comment-edit-submit-wrapper-desc">
{{if $preview}}
<button id="comment-edit-submit-desc" class="btn btn-default btn-xs" onclick="preview_comment(desc); return false;" title="{{$preview}}">
<i class="icon-eye-open comment-icon" ></i>
</button>
{{/if}}
-->
</div>
<div class="clear"></div>