mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-25 08:09:02 +01:00
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.
This commit is contained in:
parent
3d3163faaa
commit
f1ac28bc71
@ -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','<b>' . substr(lang($this->days[$i]),0,2) . '</b>');
|
||||
$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'])."<br>\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'])."<br>\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');
|
||||
|
||||
|
@ -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)."<br>\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]."<br>\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."'<br>\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).')<br>'."\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'];
|
||||
|
@ -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)."', "
|
||||
|
@ -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));
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user