From f1ac28bc7140c72613c5dcc3b3037fbfd24afcff Mon Sep 17 00:00:00 2001 From: skeeter Date: Wed, 2 May 2001 23:23:48 +0000 Subject: [PATCH] Fix for bug #420708. Also, restructured the holiday support. I think this will be the final structure. This gives the most flexibility, a single file to handle all future years. This does not care about previous years rules. --- calendar/inc/class.calendar.inc.php | 15 ++---- calendar/inc/class.calendar_holiday.inc.php | 53 ++++++++++++++++++--- calendar/inc/class.calendar_sql.inc.php | 16 ++++--- calendar/inc/functions.inc.php | 5 +- calendar/setup/holidays.US | 15 +++++- setup/sql/mysql_newtables.inc.php | 7 ++- setup/sql/mysql_upgrade_beta.inc.php | 21 ++++++++ setup/sql/pgsql_newtables.inc.php | 7 ++- setup/sql/pgsql_upgrade_beta.inc.php | 20 ++++++++ 9 files changed, 128 insertions(+), 31 deletions(-) diff --git a/calendar/inc/class.calendar.inc.php b/calendar/inc/class.calendar.inc.php index 9b577866f6..26f3da79a2 100755 --- a/calendar/inc/class.calendar.inc.php +++ b/calendar/inc/class.calendar.inc.php @@ -101,7 +101,6 @@ class calendar extends calendar_ $this->users_timeformat = 'H:i'; } $this->holidays = CreateObject('calendar.calendar_holiday',$this->owner); - $this->holidays->read_holiday(); } // Generic functions that are derived from mcal functions. @@ -403,8 +402,8 @@ class calendar extends calendar_ $full_event_date = date('Ymd',$event_beg_day); // only repeat after the beginning, and if there is an rpt_end before the end date - if (($rep_events->rpt_end_use && ($search_date_full > $end_recur_date)) || - ($search_date_full < $full_event_date)) + if ((($rep_events->recur_enddate->month && $rep_events->recur_enddate->mday && $rep_events->recur_enddate->year) && + ($search_date_full > $end_recur_date)) || ($search_date_full < $full_event_date)) { continue; } @@ -695,7 +694,6 @@ class calendar extends calendar_ $p->set_var('dayname','' . substr(lang($this->days[$i]),0,2) . ''); $p->parse('daynames','mini_day',True); } - for($i=$weekstarttime;date('Ymd',$i)<=$monthend;$i += (24 * 3600 * 7)) { for($j=0;$j<7;$j++) @@ -910,7 +908,6 @@ class calendar extends calendar_ $str = ''; $gr_events = CreateObject('calendar.calendar_item'); $lr_events = CreateObject('calendar.calendar_item'); - $p = CreateObject('phpgwapi.Template',$this->template_dir); $p->set_unknowns('keep'); @@ -934,7 +931,6 @@ class calendar extends calendar_ $p->parse('column_header','month_column',True); $p->set_var('col_width','12'); } - for ($j=0;$j<7;$j++) { $date = $this->gmtdate($startdate + ($j * 86400)); @@ -947,8 +943,8 @@ class calendar extends calendar_ $day = $phpgw->common->show_date($date['raw'],'d'); $month = $phpgw->common->show_date($date['raw'],'m'); $year = $phpgw->common->show_date($date['raw'],'Y'); - $date = $this->gmtdate(mktime(0,0,0,$month,$day,$year)); - + $date = $this->gmtdate(mktime(0,0,0,$date['month'],$date['day'],$date['year'])); + if ($weekly || ($date['full'] >= $monthstart && $date['full'] <= $monthend)) { if($weekly) @@ -956,6 +952,7 @@ class calendar extends calendar_ $cellcolor = $phpgw->nextmatchs->alternate_row_color($cellcolor); } +// echo 'Date = '.$date['raw'].' '.date('Y.m.d H:i:s',$date['raw'])."
\n"; if ($date['full'] != $this->today['full']) { $extra = ' bgcolor="'.$cellcolor.'"'; @@ -963,7 +960,6 @@ class calendar extends calendar_ else { $extra = ' bgcolor="'.$phpgw_info['theme']['cal_today'].'"'; -// echo 'Today = '.$date['raw'].' '.$phpgw->common->show_date($date['raw'])."
\n"; } $holiday_found = $this->holidays->find_date($date['raw']); @@ -1326,7 +1322,6 @@ class calendar extends calendar_ $this->end_repeat_day = intval(date('Ymd',$date['raw'])); $this->read_repeated_events($this->owner); - $p = CreateObject('phpgwapi.Template',$this->template_dir); $p->set_unknowns('keep'); diff --git a/calendar/inc/class.calendar_holiday.inc.php b/calendar/inc/class.calendar_holiday.inc.php index 33e396fa09..105318f756 100755 --- a/calendar/inc/class.calendar_holiday.inc.php +++ b/calendar/inc/class.calendar_holiday.inc.php @@ -15,14 +15,18 @@ class calendar_holiday { var $db; + var $year; + var $tz_offset; var $holidays; var $users; +// var $cal; function calendar_holiday($owner='') { global $phpgw, $phpgw_info; $this->db = $phpgw->db; +// $this->cal = CreateObject('calendar.calendar'); // $phpgw_info['user']['preferences']['calendar']['locale'] = 'US'; $this->users['user'] = $phpgw_info['user']['preferences']['calendar']['locale']; $owner_id = get_account_id($owner); @@ -92,23 +96,56 @@ class calendar_holiday // echo 'Loading from: '.$load_from.'/holidays.'.strtoupper($locale)."
\n"; $lines = $network->gethttpsocketfile($load_from.'/holidays.'.strtoupper($locale)); if (!$lines) return false; - $c_lines = count($lines); - for($i=10;$i<$c_lines;$i++) + $c_lines = count($lines) - 4; + for($i=10;$i=$c_lines;$i++) { // echo 'Line #'.$i.' : '.$lines[$i]."
\n"; $holiday = explode("\t",$lines[$i]); $loc = $holiday[0]; $name = addslashes($holiday[1]); - $date = $holiday[2]; + $day = intval($holiday[2]); + $month = intval($holiday[3]); + $occurence = intval($holiday[4]); + $dow = intval($holiday[5]); // echo "Inserting LOCALE='".$loc."' NAME='".$name."' DATE='".$date."'
\n"; - $sql = "INSERT INTO phpgw_cal_holidays(locale,name,date_time) VALUES('$loc','$name',$date)"; + $sql = "INSERT INTO phpgw_cal_holidays(locale,name,mday,month_num,occurence,dow) VALUES('$loc','$name',$day,$month,$occurence,$dow)"; $this->db->query($sql,__LINE__,__FILE__); } } + function calculate_date($holiday) + { + global $phpgw; + + if($holiday['mday'] == 0 && $holiday['dow'] != 0 && $holiday['occurence'] != 0) + { + if($holiday['occurence'] != 99) + { + $dow = $phpgw->calendar->day_of_week($this->year,$holiday['month'],1); + $day = (7 * $holiday['occurence'] - 6 + ($holiday['dow'] - $dow) % 7); + } + else + { + $ld = $phpgw->calendar->days_in_month($holiday['month'],$this->year); + $dow = $phpgw->calendar->day_of_week($this->year,$holiday['month'],$ld); + $day = $ld - ($dow - $holiday['dow']) % 7 ; + } + } + else + { + $day = $holiday['day']; + } + $datetime = mktime(0,0,0,$holiday['month'],$day,$this->year) - $this->tz_offset; +// echo 'Calculating for year('.$this->year.') month('.$holiday['month'].') dow('.$holiday['dow'].') occurence('.$holiday['occurence'].') datetime('.$datetime.') DATE('.date('Y.m.d H:i:s',$datetime).')
'."\n"; + return $datetime; + } + function read_holiday() { global $phpgw; + + $this->year = intval($phpgw->calendar->today['year']); + $this->tz_offset = intval($phpgw->calendar->tz_offset); $sql = $this->build_holiday_query(); $this->holidays = Null; @@ -120,7 +157,11 @@ class calendar_holiday $i++; $this->holidays[$i]['locale'] = $this->db->f('locale'); $this->holidays[$i]['name'] = $phpgw->strip_html($this->db->f('name')); - $this->holidays[$i]['date'] = $this->db->f('date_time'); + $this->holidays[$i]['day'] = intval($this->db->f('mday')); + $this->holidays[$i]['month'] = intval($this->db->f('month_num')); + $this->holidays[$i]['occurence'] = intval($this->db->f('occurence')); + $this->holidays[$i]['dow'] = intval($this->db->f('dow')); + $this->holidays[$i]['date'] = $this->calculate_date($this->holidays[$i]); if(count($find_locale) == 2 && $find_locale[0] != $find_locale[1]) { if($this->holidays[$i]['locale'] == $find_locale[1]) @@ -161,7 +202,7 @@ class calendar_holiday function sort_by_date($holidays) { - $c_holidays = count($this->holidays); + $c_holidays = count($holidays); for($outer_loop=0;$outer_loop<($c_holidays - 1);$outer_loop++) { $outer_date = $holidays[$outer_loop]['date']; diff --git a/calendar/inc/class.calendar_sql.inc.php b/calendar/inc/class.calendar_sql.inc.php index d1b2199317..456b5466c5 100755 --- a/calendar/inc/class.calendar_sql.inc.php +++ b/calendar/inc/class.calendar_sql.inc.php @@ -606,10 +606,6 @@ class calendar_ extends calendar__ { global $phpgw_info; - $cat = CreateObject('phpgwapi.categories'); - $categ = $cat->return_single($event->category); - $category = $categ[0]['name']; - $locks = Array( 'phpgw_cal', 'phpgw_cal_user', @@ -619,8 +615,8 @@ class calendar_ extends calendar__ if($event->id == 0) { $temp_name = tempnam($phpgw_info['server']['temp_dir'],'cal'); - $this->stream->query('INSERT INTO phpgw_cal(title,owner,category,priority,is_public) ' - . "values('".$temp_name."',".$event->owner.",'".$category."',".$event->priority.",".$event->public.")"); + $this->stream->query('INSERT INTO phpgw_cal(title,owner,priority,is_public) ' + . "values('".$temp_name."',".$event->owner.",".$event->priority.",".$event->public.")"); $this->stream->query("SELECT cal_id FROM phpgw_cal WHERE title='".$temp_name."'"); $this->stream->next_record(); $event->id = $this->stream->f('cal_id'); @@ -640,13 +636,19 @@ class calendar_ extends calendar__ $type = 'E'; } + $cat = ''; + if($event->category != 0) + { + $cat = 'category='.$event->category.', '; + } + $sql = 'UPDATE phpgw_cal SET ' . 'owner='.$event->owner.', ' . 'datetime='.$date.', ' . 'mdatetime='.$today.', ' . 'edatetime='.$enddate.', ' . 'priority='.$event->priority.', ' - . 'category='.$event->category.', ' + . $cat . "cal_type='".$type."', " . 'is_public='.$event->public.', ' . "title='".addslashes($event->title)."', " diff --git a/calendar/inc/functions.inc.php b/calendar/inc/functions.inc.php index f63b202a98..1e2249c472 100755 --- a/calendar/inc/functions.inc.php +++ b/calendar/inc/functions.inc.php @@ -68,14 +68,15 @@ 'rights' => intval($rights) ); - $phpgw->calendar = CreateObject('calendar.calendar',$parameters); - if(!isset($phpgw_info['user']['preferences']['calendar']['weekdaystarts'])) { $phpgw_info['user']['preferences']['calendar']['weekdaystarts'] = 'Sunday'; $phpgw->preferences->save_repository(); } + $phpgw->calendar = CreateObject('calendar.calendar',$parameters); + $phpgw->calendar->holidays->read_holiday(); + if (isset($date) && strlen($date) > 0) { $thisyear = intval(substr($date, 0, 4)); diff --git a/calendar/setup/holidays.US b/calendar/setup/holidays.US index 1f38fefe3e..51abdfac27 100755 --- a/calendar/setup/holidays.US +++ b/calendar/setup/holidays.US @@ -1,2 +1,13 @@ -US Presidents Day 988628400 -US Memorial Day 988714800 +US New Years 1 1 0 0 +US Martin Luther King's Birthday 0 1 3 1 +US Inaugeration Day 20 1 0 0 +US Armed Forces Day 0 5 3 6 +US Memorial Day 0 5 99 1 +US Flag Day 14 6 0 0 +US Independence Day 4 7 0 0 +US Labor Day 0 9 1 1 +US Columbus Day 0 10 2 1 +US Veterans Day 11 11 0 0 +US Thanksgiving Day 0 11 4 4 +US Christmas Day 25 12 0 0 + diff --git a/setup/sql/mysql_newtables.inc.php b/setup/sql/mysql_newtables.inc.php index 1b882cd44e..07e9a7a178 100644 --- a/setup/sql/mysql_newtables.inc.php +++ b/setup/sql/mysql_newtables.inc.php @@ -250,8 +250,11 @@ $sql = "CREATE TABLE phpgw_cal_holidays ( hol_id int(11) NOT NULL auto_increment, locale char(2) NOT NULL, - name varchar(50) NOT NULL, - date_time int(11) DEFAULT '0' NOT NULL, + name varchar(50) NOT NULL, + mday int DEFAULT '0' NOT NULL, + month_num int DEFAULT '0' NOT NULL, + occurence int DEFAULT '0' NOT NULL, + dow int DEFAULT '0' NOT NULL, PRIMARY KEY (hol_id) )"; $phpgw_setup->db->query($sql); diff --git a/setup/sql/mysql_upgrade_beta.inc.php b/setup/sql/mysql_upgrade_beta.inc.php index 40bd720cf8..fac585bd02 100644 --- a/setup/sql/mysql_upgrade_beta.inc.php +++ b/setup/sql/mysql_upgrade_beta.inc.php @@ -1629,6 +1629,27 @@ $phpgw_info['setup']['currentver']['phpgwapi'] = '0.9.11.007'; } + $test[] = '0.9.11.007'; + function upgrade0_9_11_007() + { + global $phpgw_info,$phpgw_setup; + + $phpgw_setup->db->query("drop table phpgw_cal_holidays",__LINE__,__FILE__); + $sql = "CREATE TABLE phpgw_cal_holidays ( + hol_id int(11) NOT NULL auto_increment, + locale char(2) NOT NULL, + name varchar(50) NOT NULL, + mday int DEFAULT '0' NOT NULL, + month_num int DEFAULT '0' NOT NULL, + occurence int DEFAULT '0' NOT NULL, + dow int DEFAULT '0' NOT NULL, + PRIMARY KEY (hol_id) + )"; + $phpgw_setup->db->query($sql); + + $phpgw_info['setup']['currentver']['phpgwapi'] = '0.9.11.008'; + } + reset ($test); while (list ($key, $value) = each ($test)){ if ($phpgw_info["setup"]["currentver"]["phpgwapi"] == $value) { diff --git a/setup/sql/pgsql_newtables.inc.php b/setup/sql/pgsql_newtables.inc.php index 0e01c4d797..18e86eb93d 100644 --- a/setup/sql/pgsql_newtables.inc.php +++ b/setup/sql/pgsql_newtables.inc.php @@ -221,10 +221,13 @@ $phpgw_setup->db->query($sql); $sql = "CREATE TABLE phpgw_cal_holidays ( - hol_id serial, + hol_id serial, locale char(2) NOT NULL, name varchar(50) NOT NULL, - date_time int4 DEFAULT 0 NOT NULL + mday int DEFAULT 0, + month_num int DEFAULT 0, + occurence int DEFAULT 0, + dow int DEFAULT 0 )"; $phpgw_setup->db->query($sql); diff --git a/setup/sql/pgsql_upgrade_beta.inc.php b/setup/sql/pgsql_upgrade_beta.inc.php index b477491fd2..de2b5b8a32 100644 --- a/setup/sql/pgsql_upgrade_beta.inc.php +++ b/setup/sql/pgsql_upgrade_beta.inc.php @@ -2144,6 +2144,26 @@ $phpgw_info['setup']['currentver']['phpgwapi'] = '0.9.11.007'; } + $test[] = '0.9.11.007'; + function upgrade0_9_11_007() + { + global $phpgw_info, $phpgw_setup; + + $phpgw_setup->db->query("drop table phpgw_cal_holidays",__LINE__,__FILE__); + $sql = "CREATE TABLE phpgw_cal_holidays ( + hol_id serial, + locale char(2) NOT NULL, + name varchar(50) NOT NULL, + mday int DEFAULT 0, + month_num int DEFAULT 0, + occurence int DEFAULT 0, + dow int DEFAULT 0 + )"; + $phpgw_setup->db->query($sql); + + $phpgw_info['setup']['currentver']['phpgwapi'] = '0.9.11.008'; + } + reset ($test); while (list ($key, $value) = each ($test)){ if ($phpgw_info["setup"]["currentver"]["phpgwapi"] == $value) {