diff --git a/calendar/inc/class.bocalendar.inc.php b/calendar/inc/class.bocalendar.inc.php index 5cc23fe905..edbe8f630b 100755 --- a/calendar/inc/class.bocalendar.inc.php +++ b/calendar/inc/class.bocalendar.inc.php @@ -121,7 +121,7 @@ { $this->grants = $GLOBALS['phpgw']->acl->get_grants('calendar'); - if($this->debug) { echo "Read Use_Session : (".$session.")
\n"; } + if($this->debug) { echo ''."\n"; } if($session) { @@ -131,8 +131,8 @@ if($this->debug) { - echo "BO Filter : (".$this->filter.")
\n"; - echo "Owner : ".$this->owner."
\n"; + echo ''."\n"; + echo ''."\n"; } $owner = (isset($GLOBALS['owner'])?$GLOBALS['owner']:''); @@ -244,8 +244,8 @@ if($this->debug) { - echo "BO Filter : (".$this->filter.")
\n"; - echo "Owner : ".$this->owner."
\n"; + echo ''."\n"; + echo ''."\n"; } } @@ -358,7 +358,7 @@ $event = $this->so->read_entry($id); if(!isset($event['participants'][$this->owner]) && $this->user_is_a_member($event,$this->owner)) { - $this->add_attribute('participants','U',intval($this->owner)); + $this->so->add_attribute('participants','U',intval($this->owner)); $this->so->add_entry($event); $event = $this->get_cached_event(); } @@ -437,7 +437,7 @@ if($this->debug) { - echo "ID : ".$l_cal['id']."
\n"; + echo ''."\n"; } if(isset($GLOBALS['HTTP_GET_VARS']['readsess'])) @@ -460,12 +460,7 @@ } else { - if(!$l_cal['id'] && !$this->check_perms(PHPGW_ACL_ADD)) - { - ExecMethod('calendar.uicalendar.index'); - $GLOBALS['phpgw']->common->phpgw_exit(); - } - elseif($l_cal['id'] && !$this->check_perms(PHPGW_ACL_EDIT)) + if((!$l_cal['id'] && !$this->check_perms(PHPGW_ACL_ADD)) || ($l_cal['id'] && !$this->check_perms(PHPGW_ACL_EDIT))) { ExecMethod('calendar.uicalendar.index'); $GLOBALS['phpgw']->common->phpgw_exit(); @@ -615,7 +610,6 @@ ); } - $event_ids = Array(); if($event['id']) { $event_ids[] = $event['id']; @@ -626,8 +620,10 @@ } $overlapping_events = $this->overlap( - $this->maketime($event['start']) - $this->datetime->tz_offset, - $this->maketime($event['end']) - $this->datetime->tz_offset, +// $this->maketime($event['start']) - $this->datetime->tz_offset, +// $this->maketime($event['end']) - $this->datetime->tz_offset, + $this->maketime($event['start']), + $this->maketime($event['end']), $event['participants'], $event['owner'], $event_ids @@ -791,85 +787,207 @@ return $error; } - function overlap($starttime,$endtime,$participants,$owner=0,$id=0) + function overlap($starttime,$endtime,$participants,$owner=0,$id=0,$restore_cache=False) { - $retval = Array(); - $ok = False; +// $retval = Array(); +// $ok = False; /* This needs some attention.. by commenting this chunk of code it will fix bug #444265 */ - if($starttime == $endtime && $GLOBALS['phpgw']->common->show_date($starttime,'Hi') == 0) + + if($restore_cache) { - $endtime = mktime(23,59,59,$GLOBALS['phpgw']->common->show_date($starttime,'m'),$GLOBALS['phpgw']->common->show_date($starttime,'d') + 1,$GLOBALS['phpgw']->common->show_date($starttime,'Y')) - $this->datetime->tz_offset; + $temp_cache_events = $this->cached_events; } - $sql = 'AND ((('.$starttime.' <= phpgw_cal.datetime) AND ('.$endtime.' >= phpgw_cal.datetime) AND ('.$endtime.' <= phpgw_cal.edatetime)) ' - . 'OR (('.$starttime.' >= phpgw_cal.datetime) AND ('.$starttime.' < phpgw_cal.edatetime) AND ('.$endtime.' >= phpgw_cal.edatetime)) ' - . 'OR (('.$starttime.' <= phpgw_cal.datetime) AND ('.$endtime.' >= phpgw_cal.edatetime)) ' - . 'OR (('.$starttime.' >= phpgw_cal.datetime) AND ('.$endtime.' <= phpgw_cal.edatetime))) '; - - if(count($participants) > 0) +// $temp_start = intval($GLOBALS['phpgw']->common->show_date($starttime,'Ymd')); +// $temp_start_time = intval($GLOBALS['phpgw']->common->show_date($starttime,'Hi')); +// $temp_end = intval($GLOBALS['phpgw']->common->show_date($endtime,'Ymd')); +// $temp_end_time = intval($GLOBALS['phpgw']->common->show_date($endtime,'Hi')); + $temp_start = intval(date('Ymd',$starttime)); + $temp_start_time = intval(date('Hi',$starttime)); + $temp_end = intval(date('Ymd',$endtime)); + $temp_end_time = intval(date('Hi',$endtime)); + if($this->debug) { - $p_g = ''; - if(count($participants)) + echo ''."\n"; + echo ''."\n"; + } + + $users = Array(); + if(count($participants)) + { + while(list($user,$status) = each($participants)) { - $users = Array(); - while(list($user,$status) = each($participants)) - { - $users[] = $user; - } - if($users) - { - $p_g .= 'phpgw_cal_user.cal_login IN ('.implode(',',$users).')'; - } + $users[] = $user; } - if($p_g) - { - $sql .= ' AND (' . $p_g . ')'; - } - } - - if(count($id) >= 1) - { - @reset($id); - $sql .= ' AND phpgw_cal.cal_id NOT IN ('.(count($id)==1?$id[0]:implode(',',$id)).')'; - } - - $sql .= ' ORDER BY phpgw_cal.datetime ASC, phpgw_cal.edatetime ASC, phpgw_cal.priority ASC'; - - $events = $this->so->get_event_ids(False,$sql); - if($events == False) - { - return false; - } - - $db2 = $GLOBALS['phpgw']->db; - - for($i=0;$iquery('SELECT recur_type FROM phpgw_cal_repeats WHERE cal_id='.$events[$i],__LINE__,__FILE__); - if($db2->num_rows() == 0) - { - $retval[] = $events[$i]; - $ok = True; - } - else - { - $db2->next_record(); - if($db2->f('recur_type') <> MCAL_RECUR_MONTHLY_MDAY) - { - $retval[] = $events[$i]; - $ok = True; - } - } - } - if($ok == True) - { - return $retval; } else { - return False; + $users[] = $this->owner; } + + $possible_conflicts = $this->store_to_cache( + Array( + 'smonth' => substr(strval($temp_start),4,2), + 'sday' => substr(strval($temp_start),6,2), + 'syear' => substr(strval($temp_start),0,4), + 'emonth' => substr(strval($temp_end),4,2), + 'eday' => substr(strval($temp_end),6,2), + 'eyear' => substr(strval($temp_end),0,4), + 'owner' => $users + ) + ); + + if($this->debug) + { + echo ''."\n"; + echo ''."\n"; + } + + if($possible_conflicts[$temp_start] || $possible_conflicts[$temp_end]) + { + if($temp_start == $temp_end) + { + if($this->debug) + { + echo ''."\n"; + } + @reset($possible_conflicts[$temp_start]); + while(list($key,$event) = each($possible_conflicts[$temp_start])) + { + $found = False; + if($id) + { + @reset($id); + while(list($key,$event_id) = each($id)) + { + if($this->debug) + { + echo ''."\n"; + echo ''."\n"; + } + if($event['id'] == $event_id) + { + $found = True; + } + } + } + if($this->debug) + { + echo ''."
\n"; + } + if(!$found) + { + if($this->debug) + { + echo ''."\n"; + } + } + } + } + } + else + { + $retval = False; + } + + if($restore_cache) + { + $this->cached_events = $temp_cache_events; + } + + return $retval; + +// if($starttime == $endtime && $GLOBALS['phpgw']->common->show_date($starttime,'Hi') == 0) +// { +// $endtime = mktime(23,59,59,$GLOBALS['phpgw']->common->show_date($starttime,'m'),$GLOBALS['phpgw']->common->show_date($starttime,'d') + 1,$GLOBALS['phpgw']->common->show_date($starttime,'Y')) - $this->datetime->tz_offset; +// } +// +// - $sql = 'AND ((('.$starttime.' <= phpgw_cal.datetime) AND ('.$endtime.' >= phpgw_cal.datetime) AND ('.$endtime.' <= phpgw_cal.edatetime)) ' +// . 'OR (('.$starttime.' >= phpgw_cal.datetime) AND ('.$starttime.' < phpgw_cal.edatetime) AND ('.$endtime.' >= phpgw_cal.edatetime)) ' +// - . 'OR (('.$starttime.' <= phpgw_cal.datetime) AND ('.$endtime.' >= phpgw_cal.edatetime)) ' +// - . 'OR (('.$starttime.' >= phpgw_cal.datetime) AND ('.$endtime.' <= phpgw_cal.edatetime))) '; +// +// if(count($participants) > 0) +// { +// $p_g = ''; +// if(count($participants)) +// { +// $users = Array(); +// while(list($user,$status) = each($participants)) +// { +// $users[] = $user; +// } +// if($users) +// { +// $p_g .= 'phpgw_cal_user.cal_login IN ('.implode(',',$users).')'; +// } +// } +// if($p_g) +// { +// $sql .= ' AND (' . $p_g . ')'; +// } +// } +// +// if(count($id) >= 1) +// { +// @reset($id); +// $sql .= ' AND phpgw_cal.cal_id NOT IN ('.(count($id)==1?$id[0]:implode(',',$id)).')'; +// } +// +// $sql .= ' ORDER BY phpgw_cal.datetime ASC, phpgw_cal.edatetime ASC, phpgw_cal.priority ASC'; +// +// $events = $this->so->get_event_ids(False,$sql); +// if($events == False) +// { +// return false; +// } +// +// $db2 = $GLOBALS['phpgw']->db; +// +// for($i=0;$iquery('SELECT recur_type FROM phpgw_cal_repeats WHERE cal_id='.$events[$i],__LINE__,__FILE__); +// if($db2->num_rows() == 0) +// { +// $retval[] = $events[$i]; +// $ok = True; +// } +// else +// { +// $db2->next_record(); +// if($db2->f('recur_type') <> MCAL_RECUR_MONTHLY_MDAY) +// { +// $retval[] = $events[$i]; +// $ok = True; +// } +// } +// } +// if($ok == True) +// { +// return $retval; +// } +// else +// { +// return False; +// } } function check_perms($needed,$user=0) @@ -1069,13 +1187,18 @@ $inserted = False; if($this->cached_events[$date]) { + + if($this->debug) + { + echo ''."\n"; + } $year = substr($date,0,4); $month = substr($date,4,2); $day = substr($date,6,2); if($this->debug) { - echo "Date : ".$date." Count : ".count($this->cached_events[$date])."
\n"; + echo ''."\n"; } for($i=0;$icached_events[$date]);$i++) @@ -1085,7 +1208,7 @@ { if($this->debug) { - echo "Item already inserted!
\n"; + echo ''."\n"; } $inserted = True; break; @@ -1104,6 +1227,10 @@ { $this->cached_events[$date][$j] = $this->cached_events[$date][$j-1]; } + if($this->debug) + { + echo ''."\n"; + } $inserted = True; $this->cached_events[$date][$i] = $event; break; @@ -1112,6 +1239,10 @@ } if(!$inserted) { + if($this->debug) + { + echo ''."\n"; + } $this->cached_events[$date][] = $event; } } @@ -1125,6 +1256,10 @@ $search_date_day = date('d',$datetime); $search_date_dow = date('w',$datetime); $search_beg_day = mktime(0,0,0,$search_date_month,$search_date_day,$search_date_year); + if($this->debug) + { + echo ''."\n"; + } $repeated = $this->repeating_events; $r_events = count($repeated); for ($i=0;$i<$r_events;$i++) @@ -1142,7 +1277,13 @@ } $end_recur_date = date('Ymd',$event_recur_time); $full_event_date = date('Ymd',$event_beg_day); - + + if($this->debug) + { + echo ''."\n"; + echo ''."\n"; + } + // only repeat after the beginning, and if there is an rpt_end before the end date if (($search_date_full > $end_recur_date) || ($search_date_full < $full_event_date)) { @@ -1161,7 +1302,15 @@ switch($type) { case MCAL_RECUR_DAILY: - if (floor(($search_beg_day - $event_beg_day)/86400) % $freq) + if($this->debug) + { + echo ''."\n"; + } + if ($freq == 1 && $rep_events['recur_enddate']['month'] != 0 && $rep_events['recur_enddate']['mday'] != 0 && $rep_events['recur_enddate']['year'] != 0 && $search_date_full <= $end_recur_date) + { + $this->sort_event($rep_events,$search_date_full); + } + elseif (floor(($search_beg_day - $event_beg_day)/86400) % $freq) { continue; } @@ -1260,7 +1409,10 @@ { unset($owner_id); $owner_id = $this->g_owner; - echo ''."\n"; + if($this->debug) + { + echo ''."\n"; + } } if(!$eyear && !$emonth && !$eday) @@ -1294,8 +1446,8 @@ if($this->debug) { - echo "Start Date : ".sprintf("%04d%02d%02d",$syear,$smonth,$sday)."
\n"; - echo "End Date : ".sprintf("%04d%02d%02d",$eyear,$emonth,$eday)."
\n"; + echo ''."\n"; + echo ''."\n"; } if($owner_id) @@ -1314,8 +1466,8 @@ if($this->debug) { - echo "events cached : $c_cached_ids : for : ".sprintf("%04d%02d%02d",$syear,$smonth,$sday)."
\n"; - echo "repeating events cached : $c_cached_ids_repeating : for : ".sprintf("%04d%02d%02d",$syear,$smonth,$sday)."
\n"; + echo ''."\n"; + echo ''."\n"; } $this->cached_events = Array(); @@ -1325,7 +1477,6 @@ return; } - $this->cached_events = Array(); if($c_cached_ids) { for($i=0;$i<$c_cached_ids;$i++) @@ -1348,13 +1499,13 @@ } if($this->debug) { - echo "Date: ".$j." Count : ".$c_evt_day."
\n"; + echo ''."\n"; } if($this->cached_events[$j][$c_evt_day]['id'] != $event['id']) { if($this->debug) { - echo "Adding Event for Date: ".$j."
\n"; + echo ''."\n"; } $this->cached_events[$j][] = $event; } @@ -1369,11 +1520,30 @@ for($i=0;$i<$c_cached_ids_repeating;$i++) { $this->repeating_events[$i] = $this->so->read_entry($cached_event_ids_repeating[$i]); + if($this->debug) + { + echo ''."\n"; + } } - $edate -= $this->datetime->tz_offset; - for($date=mktime(0,0,0,$smonth,$sday,$syear) - $this->datetime->tz_offset;$date<$edate;$date += 86400) +// $edate -= $this->datetime->tz_offset; +// for($date=mktime(0,0,0,$smonth,$sday,$syear) - $this->datetime->tz_offset;$date<=$edate;$date += 86400) + for($date=mktime(0,0,0,$smonth,$sday,$syear);$date<=$edate;$date += 86400) { + if($this->debug) + { +// $search_date = $GLOBALS['phpgw']->common->show_date($date,'Ymd'); + $search_date = date('Ymd',$date); + echo ''."\n"; + } $this->check_repeating_events($date); + if($this->debug) + { + echo ''."\n"; + for($i=0;$icached_events[$search_date]);$i++) + { + echo ''."\n"; + } + } } } $retval = Array(); @@ -1409,7 +1579,7 @@ return $this->so->get_cached_event(); } - function add_attribute($var,$value,$index='') + function add_attribute($var,$value,$index='False') { $this->so->add_attribute($var,$value,$index); } @@ -1685,8 +1855,8 @@ { if($this->debug) { - echo "Msg Type = ".$msg_type."
\n"; - echo "userid = ".$userid."
\n"; + echo ''."\n"; + echo ''."\n"; } if(!is_object($send)) { @@ -1704,7 +1874,7 @@ if($this->debug) { - echo "Email being sent to: ".$to."
\n"; + echo ''."\n"; } $GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'] = $part_prefs['common']['tz_offset']; @@ -1810,7 +1980,7 @@ { if($this->debug) { - echo "Modifying event for user ".$old_userid."
\n"; + echo ''."\n"; } $this->modified[intval($old_userid)] = $new_status; } @@ -1818,7 +1988,7 @@ { if($this->debug) { - echo "Deleting user ".$old_userid." from the event
\n"; + echo ''."\n"; } $this->deleted[intval($old_userid)] = $old_status; } @@ -1830,7 +2000,7 @@ { if($this->debug) { - echo "Adding event for user ".$new_userid."
\n"; + echo ''."\n"; } $this->added[$new_userid] = 'U'; $new_event['participants'][$new_userid] = 'U'; @@ -1869,7 +2039,7 @@ if($this->debug) { echo "

Event:
"; print_r($event); echo "

"; - echo "

start='$start', v='$v' "; + echo ' remove it @@ -1904,7 +2074,7 @@ $already_moved[$event['id']] = 1; if($this->debug) { - echo "moved

\n"; + echo 'moved --> '."\n"; } } else @@ -1912,18 +2082,18 @@ $already_moved[$event['id']] = 2; if($this->debug) { - echo "removed (not moved)

\n"; + echo 'removed (not moved) -->'."\n"; } } } elseif($this->debug) { - echo "removed

\n"; + echo 'removed -->'."\n"; } } elseif($this->debug) { - echo "ok

\n"; + echo 'ok -->'."\n"; } } flush(); diff --git a/calendar/inc/class.socalendar.inc.php b/calendar/inc/class.socalendar.inc.php index 9b4ca80a82..1dc873b4f9 100755 --- a/calendar/inc/class.socalendar.inc.php +++ b/calendar/inc/class.socalendar.inc.php @@ -16,6 +16,7 @@ class socalendar { +// var $debug = True; var $debug = False; var $cal; var $db; @@ -41,8 +42,8 @@ } if($this->debug) { - echo 'SO Filter : '.$this->filter."
\n"; - echo 'SO cat_id : '.$this->cat_id."
\n"; + echo ''."\n"; + echo ''."\n"; } $this->cal = CreateObject('calendar.socalendar_'); $this->cal->open('INBOX',intval($this->owner)); @@ -88,7 +89,14 @@ . 'AND (phpgw_cal_user.cal_login in ('; if($owner_id) { - $sql .= implode(',',$owner_id); + if(is_array($owner_id)) + { + $sql .= implode(',',$owner_id); + } + else + { + $sql .= $owner_id; + } } else { @@ -102,18 +110,17 @@ $member[] = $group_info['account_id']; } @reset($member); - $sql .= ','.implode(',',$member); - - $sql .= ') '; -// $sql .= 'AND (phpgw_cal.datetime <= '.$starttime.') ' - $sql .= 'AND (((phpgw_cal_repeats.recur_enddate >= '.$starttime.') AND (phpgw_cal_repeats.recur_enddate <= '.$endtime.')) OR (phpgw_cal_repeats.recur_enddate=0))) ' + $sql .= ','.implode(',',$member).') '; +// $sql .= 'AND (phpgw_cal.datetime <= '.$starttime.') '; +// $sql .= 'AND (((phpgw_cal_repeats.recur_enddate >= '.$starttime.') AND (phpgw_cal_repeats.recur_enddate <= '.$endtime.')) OR (phpgw_cal_repeats.recur_enddate=0))) ' + $sql .= 'AND ((phpgw_cal_repeats.recur_enddate >= '.$starttime.') OR (phpgw_cal_repeats.recur_enddate=0))) ' . (strpos($this->filter,'private')?'AND phpgw_cal.is_public=0 ':'') . ($this->cat_id?"AND phpgw_cal.category like '%".$this->cat_id."%' ":'') . 'ORDER BY phpgw_cal.datetime ASC, phpgw_cal.edatetime ASC, phpgw_cal.priority ASC'; if($this->debug) { - echo "SO list_repeated_events : SQL : ".$sql."
\n"; + echo ''."\n"; } return $this->get_event_ids(True,$sql); diff --git a/calendar/inc/class.socalendar_sql.inc.php b/calendar/inc/class.socalendar_sql.inc.php index e6c5a036b2..0df121bc77 100755 --- a/calendar/inc/class.socalendar_sql.inc.php +++ b/calendar/inc/class.socalendar_sql.inc.php @@ -259,7 +259,10 @@ class socalendar_ extends socalendar__ $user_where .= ','.implode(',',$member); $user_where .= ')) '; - echo ''."\n"; + if($this->debug) + { + echo ''."\n"; + } $startDate = 'AND ( ( (phpgw_cal.datetime >= '.$datetime.') '; diff --git a/calendar/inc/class.uicalendar.inc.php b/calendar/inc/class.uicalendar.inc.php index 1d513b0bdb..e040020a68 100755 --- a/calendar/inc/class.uicalendar.inc.php +++ b/calendar/inc/class.uicalendar.inc.php @@ -610,14 +610,37 @@ if ($this->bo->check_perms(PHPGW_ACL_DELETE)) { - $var = Array( - 'action_url_button' => $this->page('delete','&cal_id='.$cal_id), - '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_extra_field' => '' - ); - $p->set_var($var); - echo $p->fp('out','form_button'); + if($event['recur_type'] != MCAL_RECUR_NONE) + { + $var = Array( + 'action_url_button' => $this->page('delete','&cal_id='.$cal_id), + 'action_text_button' => lang('Delete Single'), + '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' => '' + ); + $p->set_var($var); + echo $p->fp('out','form_button'); + + $var = Array( + 'action_url_button' => $this->page('delete','&cal_id='.$cal_id), + 'action_text_button' => lang('Delete Series'), + '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' => '' + ); + $p->set_var($var); + echo $p->fp('out','form_button'); + } + else + { + $var = Array( + 'action_url_button' => $this->page('delete','&cal_id='.$cal_id), + '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_extra_field' => '' + ); + $p->set_var($var); + echo $p->fp('out','form_button'); + } } } @@ -764,8 +787,15 @@ { $date = sprintf("%04d%02d%02d",$event['start']['year'],$event['start']['month'],$event['start']['mday']); - $cd = $this->bo->delete_entry(intval($GLOBALS['HTTP_GET_VARS']['cal_id'])); - $this->bo->expunge(); + if(isset($GLOBALS['HTTP_GET_VARS']['delete_type']) && $GLOBALS['HTTP_GET_VARS']['delete_type'] == 'delete_series') + { + $cd = $this->bo->delete_entry(intval($GLOBALS['HTTP_GET_VARS']['cal_id'])); + $this->bo->expunge(); + } + else + { + // Still need to create a function to handle the deletion of a single day in a repeating serires. + } } else { @@ -2415,13 +2445,15 @@ $this->index(); } + echo ''."\n"; + $this->bo->store_to_cache( Array( 'syear' => $params['year'], - 'smomth'=> $params['month'], + 'smonth' => $params['month'], 'sday' => $params['day'], 'eyear' => $params['year'], - 'emonth'=> $params['month'], + 'emonth' => $params['month'], 'eday' => $params['day'] ) );