diff --git a/calendar/inc/class.calendar.inc.php b/calendar/inc/class.calendar.inc.php index 53c6701c68..dd519f7a30 100755 --- a/calendar/inc/class.calendar.inc.php +++ b/calendar/inc/class.calendar.inc.php @@ -55,6 +55,8 @@ class calendar extends calendar_ var $rowspan_arr = Array(); var $rowspan; + var $holidays; + function calendar($params=False) { global $phpgw, $phpgw_info; @@ -98,8 +100,8 @@ class calendar extends calendar_ { $this->users_timeformat = 'H:i'; } - $cal = CreateObject('calendar.calendar_holiday',$this->owner); - $cal->read_holiday(); + $this->holidays = CreateObject('calendar.calendar_holiday',$this->owner); + $this->holidays->read_holiday(); } // Generic functions that are derived from mcal functions. @@ -894,7 +896,8 @@ class calendar extends calendar_ 'month_day' => 'month_day.tpl', 'week_day_event' => 'week_day_event.tpl', 'week_day_events' => 'week_day_events.tpl', - 'link_pict' => 'link_pict.tpl' + 'link_pict' => 'link_pict.tpl', + 'month_filler' => 'month_filler.tpl' ); $p->set_file($templates); @@ -917,6 +920,11 @@ class calendar extends calendar_ ); $p->set_var($var); + $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)); + if ($weekly || ($date['full'] >= $monthstart && $date['full'] <= $monthend)) { if($weekly) @@ -931,12 +939,19 @@ class calendar extends calendar_ else { $extra = ' bgcolor="'.$phpgw_info['theme']['cal_today'].'"'; +// echo 'Today = '.$date['raw'].' '.$phpgw->common->show_date($date['raw'])."
\n"; } - $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)); + $holiday_found = $this->holidays->find_date($date['raw']); + if($holiday_found != False) + { + $extra = ' bgcolor="'.$phpgw_info['theme']['bg04'].'"'; + } + +// $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)); $new_event_link = ''; if (!$this->printer_friendly) { @@ -963,6 +978,15 @@ class calendar extends calendar_ $p->parse('column_data','month_day',True); + if($holiday_found != False) + { + while(list(,$value) = each($holiday_found)) + { + $p->set_var('month_filler_text',$this->holidays->get_name($value)); + $p->parse('column_data','month_filler',True); + } + } + $rep_events = $this->get_sorted_by_date($date['raw'],$owner); if ($this->sorted_events_matching) diff --git a/calendar/inc/class.calendar_holiday.inc.php b/calendar/inc/class.calendar_holiday.inc.php index d688efc154..d02df47b09 100755 --- a/calendar/inc/class.calendar_holiday.inc.php +++ b/calendar/inc/class.calendar_holiday.inc.php @@ -56,14 +56,14 @@ class calendar_holiday function load_from_network($locale) { - global $phpgw_info; + global $phpgw_info, $HTTP_HOST, $SERVER_PORT; @set_time_limit(0); // get the file that contains the calendar events for your locale // "http://www.phpgroupware.org/headlines.rdf"; $network = CreateObject('phpgwapi.network'); - if(isset($phpgw_info['server']['holidays_url_path'])) + if(isset($phpgw_info['server']['holidays_url_path']) && $phpgw_info['server']['holidays_url_path'] != 'localhost') { $load_from = $phpgw_info['server']['holidays_url_path']; } @@ -89,9 +89,21 @@ class calendar_holiday } $load_from = $server_host.'/calendar/setup'; } - $lines = $network->gethttpsocketfile($load_from.'/holidays.'.$locale); -// if (!$lines) return false; - +// 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++) + { +// echo 'Line #'.$i.' : '.$lines[$i]."
\n"; + $holiday = explode("\t",$lines[$i]); + $loc = $holiday[0]; + $name = addslashes($holiday[1]); + $date = $holiday[2]; +// echo "Inserting LOCALE='".$loc."' NAME='".$name."' DATE='".$date."'
\n"; + $sql = "INSERT INTO phpgw_cal_holidays(locale,name,date_time) VALUES('$loc','$name',$date)"; + $this->db->query($sql,__LINE__,__FILE__); + } } function read_holiday() @@ -107,7 +119,7 @@ class calendar_holiday { $i++; $this->holidays[$i]['locale'] = $this->db->f('locale'); - $this->holidays[$i]['name'] = $this->db->f('name'); + $this->holidays[$i]['name'] = $phpgw->strip_html($this->db->f('name')); $this->holidays[$i]['date'] = $this->db->f('date_time'); if(count($find_locale) == 2 && $find_locale[0] != $find_locale[1]) { @@ -125,6 +137,7 @@ class calendar_holiday $this->holidays[$i]['owner'] = 'user'; } } + $this->holidays = $this->sort_by_date($this->holidays); return $this->holidays; } @@ -145,5 +158,58 @@ class calendar_holiday return $sql; } + + function sort_by_date($holidays) + { + $c_holidays = count($this->holidays); + for($outer_loop=0;$outer_loop<($c_holidays - 1);$outer_loop++) + { + $outer_date = $holidays[$outer_loop]['date']; + for($inner_loop=$outer_loop;$inner_loop<$c_holidays;$inner_loop++) + { + $inner_date = $holidays[$inner_loop]['date']; + if($outer_date > $inner_date) + { + $temp = $holidays[$inner_loop]; + $holidays[$inner_loop] = $holidays[$outer_loop]; + $holidays[$outer_loop] = $temp; + } + } + } + return $holidays; + } + + + function find_date($date) + { + global $phpgw; + + $c_holidays = count($this->holidays); + for($i=0;$i<$c_holidays;$i++) + { + if($this->holidays[$i]['date'] > $date) + { + continue; + } + elseif($this->holidays[$i]['date'] == $date) + { + $return_value[] = $i; + } + } +// echo 'Searching for '.$phpgw->common->show_date($date).' Found = '.count($return_value)."
\n"; + if(isset($return_value)) + { + return $return_value; + } + else + { + return False; + } + } + + function get_name($id) + { + return $this->holidays[$id]['name']; + } } ?> diff --git a/calendar/setup/config.inc.php b/calendar/setup/config.inc.php new file mode 100755 index 0000000000..17b76bea0f --- /dev/null +++ b/calendar/setup/config.inc.php @@ -0,0 +1,22 @@ + + +   + + + +  Calendar settings + + + Do you wish to autoload calendar holidays files dynamically? + > + + + Location to autoload from: + + + + + diff --git a/calendar/setup/holidays.US b/calendar/setup/holidays.US new file mode 100755 index 0000000000..1f38fefe3e --- /dev/null +++ b/calendar/setup/holidays.US @@ -0,0 +1,2 @@ +US Presidents Day 988628400 +US Memorial Day 988714800