Holiday support is now working... Still need to add a mangement page

This commit is contained in:
skeeter 2001-05-01 03:26:17 +00:00
parent 0f2df213fd
commit a4064929a9
4 changed files with 127 additions and 13 deletions

View File

@ -55,6 +55,8 @@ class calendar extends calendar_
var $rowspan_arr = Array(); var $rowspan_arr = Array();
var $rowspan; var $rowspan;
var $holidays;
function calendar($params=False) function calendar($params=False)
{ {
global $phpgw, $phpgw_info; global $phpgw, $phpgw_info;
@ -98,8 +100,8 @@ class calendar extends calendar_
{ {
$this->users_timeformat = 'H:i'; $this->users_timeformat = 'H:i';
} }
$cal = CreateObject('calendar.calendar_holiday',$this->owner); $this->holidays = CreateObject('calendar.calendar_holiday',$this->owner);
$cal->read_holiday(); $this->holidays->read_holiday();
} }
// Generic functions that are derived from mcal functions. // Generic functions that are derived from mcal functions.
@ -894,7 +896,8 @@ class calendar extends calendar_
'month_day' => 'month_day.tpl', 'month_day' => 'month_day.tpl',
'week_day_event' => 'week_day_event.tpl', 'week_day_event' => 'week_day_event.tpl',
'week_day_events' => 'week_day_events.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); $p->set_file($templates);
@ -917,6 +920,11 @@ class calendar extends calendar_
); );
$p->set_var($var); $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 || ($date['full'] >= $monthstart && $date['full'] <= $monthend))
{ {
if($weekly) if($weekly)
@ -931,12 +939,19 @@ class calendar extends calendar_
else else
{ {
$extra = ' bgcolor="'.$phpgw_info['theme']['cal_today'].'"'; $extra = ' bgcolor="'.$phpgw_info['theme']['cal_today'].'"';
// echo 'Today = '.$date['raw'].' '.$phpgw->common->show_date($date['raw'])."<br>\n";
} }
$day = $phpgw->common->show_date($date['raw'],'d'); $holiday_found = $this->holidays->find_date($date['raw']);
$month = $phpgw->common->show_date($date['raw'],'m'); if($holiday_found != False)
$year = $phpgw->common->show_date($date['raw'],'Y'); {
$date = $this->gmtdate(mktime(0,0,0,$month,$day,$year)); $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 = ''; $new_event_link = '';
if (!$this->printer_friendly) if (!$this->printer_friendly)
{ {
@ -963,6 +978,15 @@ class calendar extends calendar_
$p->parse('column_data','month_day',True); $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); $rep_events = $this->get_sorted_by_date($date['raw'],$owner);
if ($this->sorted_events_matching) if ($this->sorted_events_matching)

View File

@ -56,14 +56,14 @@ class calendar_holiday
function load_from_network($locale) function load_from_network($locale)
{ {
global $phpgw_info; global $phpgw_info, $HTTP_HOST, $SERVER_PORT;
@set_time_limit(0); @set_time_limit(0);
// get the file that contains the calendar events for your locale // get the file that contains the calendar events for your locale
// "http://www.phpgroupware.org/headlines.rdf"; // "http://www.phpgroupware.org/headlines.rdf";
$network = CreateObject('phpgwapi.network'); $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']; $load_from = $phpgw_info['server']['holidays_url_path'];
} }
@ -89,9 +89,21 @@ class calendar_holiday
} }
$load_from = $server_host.'/calendar/setup'; $load_from = $server_host.'/calendar/setup';
} }
$lines = $network->gethttpsocketfile($load_from.'/holidays.'.$locale); // echo 'Loading from: '.$load_from.'/holidays.'.strtoupper($locale)."<br>\n";
// if (!$lines) return false; $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]."<br>\n";
$holiday = explode("\t",$lines[$i]);
$loc = $holiday[0];
$name = addslashes($holiday[1]);
$date = $holiday[2];
// echo "Inserting LOCALE='".$loc."' NAME='".$name."' DATE='".$date."'<br>\n";
$sql = "INSERT INTO phpgw_cal_holidays(locale,name,date_time) VALUES('$loc','$name',$date)";
$this->db->query($sql,__LINE__,__FILE__);
}
} }
function read_holiday() function read_holiday()
@ -107,7 +119,7 @@ class calendar_holiday
{ {
$i++; $i++;
$this->holidays[$i]['locale'] = $this->db->f('locale'); $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'); $this->holidays[$i]['date'] = $this->db->f('date_time');
if(count($find_locale) == 2 && $find_locale[0] != $find_locale[1]) 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[$i]['owner'] = 'user';
} }
} }
$this->holidays = $this->sort_by_date($this->holidays);
return $this->holidays; return $this->holidays;
} }
@ -145,5 +158,58 @@ class calendar_holiday
return $sql; 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)."<br>\n";
if(isset($return_value))
{
return $return_value;
}
else
{
return False;
}
}
function get_name($id)
{
return $this->holidays[$id]['name'];
}
} }
?> ?>

22
calendar/setup/config.inc.php Executable file
View File

@ -0,0 +1,22 @@
<!-- BEGIN calendar/setup/config.inc.php -->
<tr bgcolor="FFFFFF">
<td colspan="2">&nbsp;</td>
</tr>
<tr bgcolor="486591">
<td colspan="2"><font color="fefefe">&nbsp;<b>Calendar settings</b></font></td>
</tr>
<tr bgcolor="e6e6e6">
<td>Do you wish to autoload calendar holidays files dynamically?</td>
<td><input type="checkbox" name="newsettings[auto_load_holidays]" value="True"<?php echo ($current_config['auto_load_holidays']?" checked":""); ?>></td>
</tr>
<tr bgcolor="e6e6e6">
<td>Location to autoload from:</td>
<td>
<select name="newsettings[holidays_url_path]">
<option value="localhost"<?php echo ($current_config['holidays_url_path']=='localhost'?' selected':''); ?>>localhost</option>
<option value="http://www.phpgroupware.org/cal"<?php echo ($current_config['holidays_url_path']=='http://www.phpgroupware.org/cal'?' selected':''); ?>>www.phpgroupware.org</option>
</select>
</td>
</tr>

2
calendar/setup/holidays.US Executable file
View File

@ -0,0 +1,2 @@
US Presidents Day 988628400
US Memorial Day 988714800