diff --git a/calendar/inc/class.boholiday.inc.php b/calendar/inc/class.boholiday.inc.php new file mode 100755 index 0000000000..c6dae0c70d --- /dev/null +++ b/calendar/inc/class.boholiday.inc.php @@ -0,0 +1,219 @@ + * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ + + /* $Id$ */ + + class boholiday + { + var $public_functions = Array( + 'read_entries' => True, + 'read_entry' => True, + 'add_entry' => True, + 'update_entry' => True + ); + + var $debug = False; + + var $so; + + var $owner; + + var $year; + + var $locales = Array(); + var $holidays; + var $cached_holidays; + + function boholiday($year,$owner=0) + { + global $phpgw_info; + + $this->so = CreateObject('calendar.soholiday'); + + $this->year = $year; + + if($owner == 0) + { + $this->owner = $phpgw_info['user']['account_id']; + } + else + { + $this->owner = $owner; + } + + if(@$phpgw_info['user']['preferences']['common']['country']) + { + $this->locales[] = $phpgw_info['user']['preferences']['common']['country']; + } + elseif(@$phpgw_info['user']['preferences']['calendar']['locale']) + { + $this->locales[] = $phpgw_info['user']['preferences']['calendar']['locale']; + } + + if($this->owner != $phpgw_info['user']['account_id']) + { + $owner_pref = CreateObject('phpgwapi.preferences',$owner); + $owner_prefs = $owner_pref->read_repository(); + if(@$owner_prefs['common']['country']) + { + $this->locales[] = $owner_prefs['common']['country']; + } + elseif(@$owner_prefs['calendar']['locale']) + { + $this->locales[] = $owner_prefs['calendar']['locale']; + } + unset($owner_pref); + } + + @reset($this->locales); + if($phpgw_info['server']['auto_load_holidays'] == True) + { + while(list($key,$value) = each($this->locales)) + { + $this->auto_load_holidays($value); + } + } + } + + /* Begin Calendar functions */ + function auto_load_holidays($locale) + { + if($this->so->count_of_holidays($locale) == 0) + { + 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/cal/holidays.US"; */ + $network = CreateObject('phpgwapi.network'); + if(isset($phpgw_info['server']['holidays_url_path']) && $phpgw_info['server']['holidays_url_path'] != 'localhost') + { + $load_from = $phpgw_info['server']['holidays_url_path']; + } + else + { + $pos = strpos(' '.$phpgw_info['server']['webserver_url'],$HTTP_HOST); + if($pos == 0) + { + switch($SERVER_PORT) + { + case 80: + $http_protocol = 'http://'; + break; + case 443: + $http_protocol = 'https://'; + break; + } + $server_host = $http_protocol.$HTTP_HOST.$phpgw_info['server']['webserver_url']; + } + else + { + $server_host = $phpgw_info['server']['webserver_url']; + } + $load_from = $server_host.'/calendar/setup'; + } +// 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=0;$i<$c_lines;$i++) + { +// echo 'Line #'.$i.' : '.$lines[$i]."
\n"; + $holiday = explode("\t",$lines[$i]); + if(count($holiday) == 7) + { + $holiday['locale'] = $holiday[0]; + $holiday['name'] = addslashes($holiday[1]); + $holiday['mday'] = intval($holiday[2]); + $holiday['month_num'] = intval($holiday[3]); + $holiday['occurence'] = intval($holiday[4]); + $holiday['dow'] = intval($holiday[5]); + $holiday['observance_rule'] = intval($holiday[6]); + $holiday['hol_id'] = 0; + $this->so->save_holiday($holiday); + } + } + } + } + + function sort_holidays_by_date($holidays) + { + $c_holidays = count($holidays); + for($outer_loop=0;$outer_loop<($c_holidays - 1);$outer_loop++) + { + for($inner_loop=$outer_loop;$inner_loop<$c_holidays;$inner_loop++) + { + if($holidays[$outer_loop]['date'] > $holidays[$inner_loop]['date']) + { + $temp = $holidays[$inner_loop]; + $holidays[$inner_loop] = $holidays[$outer_loop]; + $holidays[$outer_loop] = $temp; + } + } + } + return $holidays; + } + + function set_holidays_to_date($holidays) + { + $new_holidays = Array(); + for($i=0;$i\n"; + $new_holidays[date('Ymd',$holidays[$i]['date'])][] = $holidays[$i]; + } + return $new_holidays; + } + + function read_holiday() + { + if(isset($this->cached_holidays)) + { + return $this->cached_holidays; + } + + $holidays = $this->so->read_holidays($this->locales); + + if(count($holidays) == 0) + { + return $holidays; + } + + global $phpgw_info; + + $temp_locale = $phpgw_info['user']['preferences']['common']['country']; + $datetime = CreateObject('phpgwapi.datetime'); + for($i=0;$icalculate_date($holidays[$i], $holidays, $this->year, $datetime, $c); + unset($holidaycalc); + if($c != $i) + { + $i = $c; + } + } + unset($datetime); + $this->holidays = $this->sort_holidays_by_date($holidays); + $this->cached_holidays = $this->set_holidays_to_date($this->holidays); + $phpgw_info['user']['preferences']['common']['country'] = $temp_locale; + return $this->cached_holidays; + } + /* End Calendar functions */ + } +?> diff --git a/calendar/inc/class.soholiday.inc.php b/calendar/inc/class.soholiday.inc.php new file mode 100755 index 0000000000..e8a6b0a583 --- /dev/null +++ b/calendar/inc/class.soholiday.inc.php @@ -0,0 +1,99 @@ + * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ + + /* $Id$ */ + + class soholiday + { + var $db; + + function soholiday() + { + global $phpgw; + + $this->db = $phpgw->db; + } + + /* Begin Holiday functions */ + function save_holiday($holiday) + { + if(isset($holiday['hol_id']) && $holiday['hol_id']) + { +// echo "Updating LOCALE='".$holiday['locale']."' NAME='".$holiday['name']."' extra=(".$holiday['mday'].'/'.$holiday['month_num'].'/'.$holiday['occurence'].'/'.$holiday['dow'].'/'.$holiday['observance_rule'].")
\n"; + $sql = "UPDATE phpgw_cal_holidays SET name='".$holiday['name']."', mday=".$holiday['mday'].', month_num='.$holiday['month_num'].', occurence='.$holiday['occurence'].', dow='.$holiday['dow'].', observance_rule='.intval($holiday['observance_rule']).' WHERE hol_id='.$holiday['hol_id']; + } + else + { +// echo "Inserting LOCALE='".$holiday['locale']."' NAME='".$holiday['name']."' extra=(".$holiday['mday'].'/'.$holiday['month_num'].'/'.$holiday['occurence'].'/'.$holiday['dow'].'/'.$holiday['observance_rule'].")
\n"; + $sql = 'INSERT INTO phpgw_cal_holidays(locale,name,mday,month_num,occurence,dow,observance_rule) ' + . "VALUES('".strtoupper($holiday['locale'])."','".$holiday['name']."',".$holiday['mday'].','.$holiday['month_num'].','.$holiday['occurence'].','.$holiday['dow'].','.intval($holiday['observance_rule']).")"; + } + $this->db->query($sql,__LINE__,__FILE__); + } + + function read_holidays($locales='') + { + global $phpgw; + + $holidays = Array(); + + if($locales == '') + { + return $holidays; + } + + if(is_string($locales)) + { + $find = "'".$locales."'"; + } + elseif(is_array($locales)) + { + $find = ''; + while(list($key,$value) = each($locales)) + { + if($find) + { + $find .= ','; + } + $find .= "'".$value."'"; + } + } + + $sql = 'SELECT * FROM phpgw_cal_holidays WHERE locale in ('.$find.')'; + + $this->db->query($sql,__LINE__,__FILE__); + while($this->db->next_record()) + { + $holidays[] = Array( + 'index' => $this->db->f('hol_id'), + 'locale' => $this->db->f('locale'), + 'name' => $phpgw->strip_html($this->db->f('name')), + 'day' => intval($this->db->f('mday')), + 'month' => intval($this->db->f('month_num')), + 'occurence' => intval($this->db->f('occurence')), + 'dow' => intval($this->db->f('dow')), + 'observance_rule' => $this->db->f('observance_rule') + ); + } + return $holidays; + } + + /* Private functions */ + function count_of_holidays($locale) + { + $sql = "SELECT count(*) FROM phpgw_cal_holidays WHERE locale='".$locale."'"; + $this->db->query($sql,__LINE__,__FILE__); + $this->db->next_record(); + return $this->db->f(0); + } + } +?>