some fixes for recuring events:

- they show up in the planner now
- you are able to delete single occurantses of recuring events
applied patch #774 from mishas: dayview sometimes not showing 1. event
This commit is contained in:
Ralf Becker 2003-02-26 16:42:04 +00:00
parent 07ec4382e2
commit bb797132fe
2 changed files with 84 additions and 87 deletions

View File

@ -461,13 +461,15 @@
print_debug('count event exceptions',count($event['recur_exception'])); print_debug('count event exceptions',count($event['recur_exception']));
$this->so->add_entry($event); $this->so->add_entry($event);
$cd = 16; $cd = 16;
$this->so->cal->event = $temp_event;
unset($temp_event);
} }
else else
{ {
$cd = 60; $cd = 60;
} }
$this->so->cal->event = $temp_event; // }
unset($temp_event);
return $cd; return $cd;
} }
@ -879,6 +881,45 @@
return mktime($time['hour'],$time['min'],$time['sec'],$time['month'],$time['mday'],$time['year']); return mktime($time['hour'],$time['min'],$time['sec'],$time['month'],$time['mday'],$time['year']);
} }
/*!
@function time2array
@abstract returns a date-array suitable for the start- or endtime of an event from a timestamp
@syntax time2array($time,$alarm=0)
@param $time the timestamp for the values of the array
@param $alarm (optional) alarm field of the array, defaults to 0
@author ralfbecker
*/
function time2array($time,$alarm = 0)
{
return array(
'year' => intval(date('Y',$time)),
'month' => intval(date('m',$time)),
'mday' => intval(date('d',$time)),
'hour' => intval(date('H',$time)),
'min' => intval(date('i',$time)),
'sec' => intval(date('s',$time)),
'alarm' => intval($alarm)
);
}
/*!
@function set_recur_date
@abstract set the start- and enddates of a recuring event for a recur-date
@syntax set_recur_date(&$event,$date)
@param $event the event which fields to set (has to be the original event for start-/end-times)
@param $date the recuring date in form 'Ymd', eg. 20030226
@author ralfbecker
*/
function set_recur_date(&$event,$date)
{
$org_start = $this->maketime($event['start']);
$org_end = $this->maketime($event['end']);
$start = mktime($event['start']['hour'],$event['start']['min'],0,substr($date,4,2),substr($date,6,2),substr($date,0,4));
$end = $org_end + $start - $org_start;
$event['start'] = $this->time2array($start);
$event['end'] = $this->time2array($end);
}
function fix_update_time(&$time_param) function fix_update_time(&$time_param)
{ {
if ($this->prefs['common']['timeformat'] == '12') if ($this->prefs['common']['timeformat'] == '12')
@ -2201,79 +2242,28 @@
function remove_doubles_in_cache($firstday,$lastday) function remove_doubles_in_cache($firstday,$lastday)
{ {
$already_moved = Array(); $already_moved = Array();
$has_category = Array(); // remove only multiple occurences of a category per event/day
for($v=$firstday;$v<=$lastday;$v++) for($v=$firstday;$v<=$lastday;$v++)
{ {
if (!$this->cached_events[$v]) if (!$this->cached_events[$v])
{ {
continue; continue;
} }
while (list($g,$event) = each($this->cached_events[$v])) $cached = $this->cached_events[$v];
$this->cached_events[$v] = array();
while (list($g,$event) = each($cached))
{ {
$start = sprintf('%04d%02d%02d',$event['start']['year'],$event['start']['month'],$event['start']['mday']); $end = date('Ymd',$this->maketime($event['end']));
print_debug('EVENT',_debug_array($event,False)); print_debug('EVENT',_debug_array($event,False));
print_debug('start',$start); print_debug('start',$start);
print_debug('v',$v); print_debug('v',$v);
if($start < $firstday) if (!isset($already_moved[$event['id']]) || $event['recur_type'] && $v > $end)
{ {
$start = $firstday; // event continues into current month/year $this->cached_events[$v][] = $event;
} $already_moved[$event['id']] = 1;
print_debug('Event moved');
// if ($start != $v && $event['recur_type'] == MCAL_RECUR_NONE) // this is an enddate-entry --> remove it
if ($start != $v) // this is an enddate-entry --> remove it
{
unset($this->cached_events[$v][$g]);
if($g != count($this->cached_events[$v]))
{
if ($has_category[$event['id']]['category'] != True)
{
continue; // we need at least one evidence for this category
}
for($h=$g + 1;$h<$c_daily;$h++)
{
$this->cached_events[$v][$h - 1] = $this->cached_events[$v][$h];
}
unset($this->cached_events[$v][$h]);
$has_category[$event['id']]['category'] = True;
}
// if ($start < $firstday && $event['recur_type'] == MCAL_RECUR_NONE) // start before period --> move it to the beginning
if ($start < $firstday) // start before period --> move it to the beginning
{
if($already_moved[$event['id']] > 0)
{
continue;
}
$add_event = True;
$c_events = count($this->cached_events[$firstday]);
for($i=0;$i<$c_events;$i++)
{
$add_event = ($this->cached_events[$firstday][$i]['id'] == $event['id']?False:$add_event);
}
if($add_event)
{
$this->cached_events[$firstday][] = $event;
$already_moved[$event['id']] = 1;
print_debug('Event moved');
}
else
{
$already_moved[$event['id']] = 2;
print_debug('Event removed (not moved)');
}
}
else
{
print_debug('Event removed');
}
}
else
{
print_debug('Event OK');
} }
} }
flush();
} }
} }

View File

@ -1028,6 +1028,7 @@
'action_text_button' => lang('Delete Single'), 'action_text_button' => lang('Delete Single'),
'action_confirm_button' => "onClick=\"return confirm('".lang("Are you sure\\nyou want to\\ndelete this single occurence ?\\n\\nThis will delete\\nthis entry for all users.")."')\"", 'action_confirm_button' => "onClick=\"return confirm('".lang("Are you sure\\nyou want to\\ndelete this single occurence ?\\n\\nThis will delete\\nthis entry for all users.")."')\"",
'action_extra_field' => '<input type="hidden" name="delete_type" value="single">' 'action_extra_field' => '<input type="hidden" name="delete_type" value="single">'
. '<input type="hidden" name="date" value="'.sprintf('%04d%02d%02d',$this->bo->year,$this->bo->month,$this->bo->day).'">'
); );
$p->set_var($var); $p->set_var($var);
$p->parse('phpgw_body','form_button',True); $p->parse('phpgw_body','form_button',True);
@ -1093,10 +1094,11 @@
function edit($params='') function edit($params='')
{ {
if(!$this->bo->check_perms(PHPGW_ACL_EDIT)) // No event loaded, so what to check?
{ // if(!$this->bo->check_perms(PHPGW_ACL_EDIT))
$this->no_edit(); // {
} // $this->no_edit();
// }
if($this->debug) if($this->debug)
{ {
@ -1140,18 +1142,14 @@
if(@isset($GLOBALS['HTTP_POST_VARS']['edit_type']) && $GLOBALS['HTTP_POST_VARS']['edit_type'] == 'single') if(@isset($GLOBALS['HTTP_POST_VARS']['edit_type']) && $GLOBALS['HTTP_POST_VARS']['edit_type'] == 'single')
{ {
$event['id'] = 0; $event['id'] = 0;
$event['start']['month'] = $this->bo->month; $this->bo->set_recur_date($event,$GLOBALS['HTTP_POST_VARS']['date']);
$event['start']['mday'] = $this->bo->day;
$event['start']['year'] = $this->bo->year;
$event['end']['month'] = $this->bo->month;
$event['end']['mday'] = $this->bo->day;
$event['end']['year'] = $this->bo->year;
$event['recur_type'] = MCAL_RECUR_NONE; $event['recur_type'] = MCAL_RECUR_NONE;
$event['recur_interval'] = 0; $event['recur_interval'] = 0;
$event['recur_data'] = 0; $event['recur_data'] = 0;
$event['recur_enddate']['month'] = 0; $event['recur_enddate']['month'] = 0;
$event['recur_enddate']['mday'] = 0; $event['recur_enddate']['mday'] = 0;
$event['recur_enddate']['year'] = 0; $event['recur_enddate']['year'] = 0;
$event['recur_execption'] = array();
} }
$this->edit_form( $this->edit_form(
Array( Array(
@ -1427,12 +1425,13 @@
$delete_type = get_var('delete_type',Array('POST')); $delete_type = get_var('delete_type',Array('POST'));
if($deleted_type && $delete_type == 'single') if($deleted_type && $delete_type == 'single')
{ {
$date = $GLOBALS['HTTP_POST_VARS']['date'];
$cd = $this->bo->delete_single( $cd = $this->bo->delete_single(
Array( Array(
'id' => intval($cal_id), 'id' => intval($cal_id),
'year' => $this->bo->year, 'year' => substr($date,0,4),
'month' => $this->bo->month, 'month' => substr($date,4,2),
'day' => $this->bo->day 'day' => substr($date,6,2)
) )
); );
} }
@ -1838,7 +1837,8 @@
$view = $this->planner_html->link('/index.php', $view = $this->planner_html->link('/index.php',
array( array(
'menuaction' => 'calendar.uicalendar.view', 'menuaction' => 'calendar.uicalendar.view',
'cal_id' => $event['id'] 'cal_id' => $event['id'],
'date' => date('Ymd',$this->bo->maketime($event['start']))
) )
); );
@ -1869,13 +1869,14 @@
$akt_cell = &$rows[$ka]; $akt_cell = &$rows[$ka];
} while ($akt_cell > $start_cell); } while ($akt_cell > $start_cell);
$id = $event['id'].'-'.date('Ymd',$this->bo->maketime($event['start']));
if ($akt_cell < $start_cell) if ($akt_cell < $start_cell)
{ {
$row[$event['id'].'_1'] = '&nbsp;'; $row[$id.'_1'] = '&nbsp;';
$row['.'.$event['id'].'_1'] = 'colspan="'.($start_cell-$akt_cell).'"'; $row['.'.$id.'_1'] = 'colspan="'.($start_cell-$akt_cell).'"';
} }
$opt = &$row['.'.$event['id'].'_2']; $opt = &$row['.'.$id.'_2'];
$cel = &$row[$event['id'].'_2']; $cel = &$row[$id.'_2'];
// if possible, display information about event within cells representing it // if possible, display information about event within cells representing it
// //
@ -1955,6 +1956,10 @@
{ {
$cel .= $this->planner_html->image('calendar','mini-calendar-bar.gif','','border="0"'); $cel .= $this->planner_html->image('calendar','mini-calendar-bar.gif','','border="0"');
} }
if ($event['recur_type'])
{
$cel .= $this->planner_html->image('calendar','recur.gif','','border="0"');
}
$cel .= $this->planner_html->image('calendar',count($event['participants'])>1?'multi_3.gif':'single.gif',$this->planner_participants($event['participants']),'border="0"'); $cel .= $this->planner_html->image('calendar',count($event['participants'])>1?'multi_3.gif':'single.gif',$this->planner_participants($event['participants']),'border="0"');
$cel .= '</a>'; $cel .= '</a>';
@ -2006,7 +2011,6 @@
if ($event_end <= $this->planner_lastday) if ($event_end <= $this->planner_lastday)
{ {
$days_between = $GLOBALS['phpgw']->datetime->days_between($this->bo->month,1,$this->bo->year,$event['end']['month'],$event['end']['mday'],$event['end']['year']); $days_between = $GLOBALS['phpgw']->datetime->days_between($this->bo->month,1,$this->bo->year,$event['end']['month'],$event['end']['mday'],$event['end']['year']);
$end_cell = $intervals_per_day * $days_between + $interval[$event['end']['hour']]; $end_cell = $intervals_per_day * $days_between + $interval[$event['end']['hour']];
if ($end_cell == $start_cell && $end_cell < $last_cell) if ($end_cell == $start_cell && $end_cell < $last_cell)
{ {
@ -2017,7 +2021,6 @@
{ {
$end_cell = $last_cell; $end_cell = $last_cell;
} }
// get the categories associated with event // get the categories associated with event
// //
if ($c = $event['category']) if ($c = $event['category'])
@ -2156,8 +2159,12 @@
// process all events on day $v // process all events on day $v
// //
while (list($nul,$event) = @each($daily)) while (list(,$event) = @each($daily))
{ {
if ($event['recur_type']) // calculate start- + end-datetime for recuring events
{
$this->bo->set_recur_date($event,$v);
}
$this->planner_process_event($event); $this->planner_process_event($event);
} }
} }
@ -3719,7 +3726,7 @@
if((($ind <> 99) && ($ind <> 0)) && (($starttime <> 0) && ($endtime <> 0))) if((($ind <> 99) && ($ind <> 0)) && (($starttime <> 0) && ($endtime <> 0)))
{ {
print_debug('IND before',$ind); print_debug('IND before',$ind);
if($ind <= date('H',$last_endtime-1)) // -1 to allow events to end on a full hour, without blocking the next hour-slot if($ind <= date('H',$last_endtime-1) && $last_ind) // -1 to allow events to end on a full hour, without blocking the next hour-slot
{ {
$ind = $last_ind; $ind = $last_ind;
$interval_start = $last_interval_start; $interval_start = $last_interval_start;
@ -4379,7 +4386,7 @@
$var = Array( $var = Array(
'action_url_button' => $this->page('delete','&cal_id='.$event['id']), 'action_url_button' => $this->page('delete','&cal_id='.$event['id']),
'action_text_button' => lang('Delete'), 'action_text_button' => lang('Delete'),
'action_confirm_button' => "onClick=\"return confirm('".lang("Are you sure\\nyou want to \\ndelete this entry?\\n\\nThis will delete\\nthis entry for all users.")."')\"", 'action_confirm_button' => "onClick=\"return confirm('".lang("Are you sure\\nyou want to \\ndelete this entry ?\\n\\nThis will delete\\nthis entry for all users.")."')\"",
'action_extra_field' => '' 'action_extra_field' => ''
); );
$p->set_var($var); $p->set_var($var);