2001-07-18 19:30:24 +02:00
|
|
|
<?php
|
2004-08-04 00:52:13 +02:00
|
|
|
/**************************************************************************\
|
|
|
|
* eGroupWare - Holiday *
|
|
|
|
* http://www.egroupware.org *
|
|
|
|
* Maintained and further developed by RalfBecker@outdoor-training.de *
|
|
|
|
* Originaly written by Mark Peters <skeeter@phpgroupware.org> *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* 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. *
|
|
|
|
\**************************************************************************/
|
2001-07-18 19:30:24 +02:00
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2005-11-09 00:15:14 +01:00
|
|
|
/**
|
|
|
|
* Storage layer for calendar holidays
|
|
|
|
*
|
|
|
|
* @package calendar
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @author Mark Peters <skeeter@phpgroupware.org>
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
*/
|
2001-07-18 19:30:24 +02:00
|
|
|
class soholiday
|
|
|
|
{
|
2001-07-28 15:17:30 +02:00
|
|
|
var $debug = False;
|
2001-07-18 19:30:24 +02:00
|
|
|
var $db;
|
|
|
|
|
|
|
|
function soholiday()
|
|
|
|
{
|
2005-11-09 00:15:14 +01:00
|
|
|
$this->db = clone($GLOBALS['egw']->db);
|
2004-08-04 00:52:13 +02:00
|
|
|
$this->db->set_app('calendar');
|
2005-11-09 00:15:14 +01:00
|
|
|
$this->table = 'egw_cal_holidays';
|
2001-07-18 19:30:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Begin Holiday functions */
|
|
|
|
function save_holiday($holiday)
|
|
|
|
{
|
2004-05-25 13:36:32 +02:00
|
|
|
// observance_rule is either "True" or unset !
|
|
|
|
$holiday['observance_rule'] = @$holiday['observance_rule'] ? 1 : 0;
|
|
|
|
$holiday['locale'] = strtoupper($holiday['locale']);
|
|
|
|
|
2004-08-04 00:52:13 +02:00
|
|
|
foreach($holiday as $name => $val)
|
|
|
|
{
|
2004-08-04 01:22:35 +02:00
|
|
|
if (substr($name,0,4) != 'hol_')
|
2004-08-04 00:52:13 +02:00
|
|
|
{
|
2004-08-04 01:22:35 +02:00
|
|
|
if (!is_numeric($name))
|
|
|
|
{
|
|
|
|
$holiday['hol_'.$name] = $holiday[$name];
|
|
|
|
}
|
2004-08-04 00:52:13 +02:00
|
|
|
unset($holiday[$name]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$hol_id = $holiday['hol_id'];
|
|
|
|
unset($holiday['hol_id']);
|
2005-06-07 11:51:18 +02:00
|
|
|
unset($holiday['hol_locales']);
|
2004-08-04 00:52:13 +02:00
|
|
|
|
|
|
|
if ($hol_id)
|
2001-07-18 19:30:24 +02:00
|
|
|
{
|
2001-07-28 15:17:30 +02:00
|
|
|
if($this->debug)
|
|
|
|
{
|
|
|
|
echo "Updating LOCALE='".$holiday['locale']."' NAME='".$holiday['name']."' extra=(".$holiday['mday'].'/'.$holiday['month_num'].'/'.$holiday['occurence'].'/'.$holiday['dow'].'/'.$holiday['observance_rule'].")<br>\n";
|
|
|
|
}
|
2004-08-04 00:52:13 +02:00
|
|
|
$this->db->update($this->table,$holiday,array('hol_id' => $hol_id),__LINE__,__FILE__);
|
2001-07-18 19:30:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-28 15:17:30 +02:00
|
|
|
if($this->debug)
|
|
|
|
{
|
|
|
|
echo "Inserting LOCALE='".$holiday['locale']."' NAME='".$holiday['name']."' extra=(".$holiday['mday'].'/'.$holiday['month_num'].'/'.$holiday['occurence'].'/'.$holiday['dow'].'/'.$holiday['observance_rule'].")<br>\n";
|
|
|
|
}
|
2004-08-04 00:52:13 +02:00
|
|
|
$this->db->insert($this->table,$holiday,False,__LINE__,__FILE__);
|
2001-07-18 19:30:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-28 15:17:30 +02:00
|
|
|
function store_to_array(&$holidays)
|
|
|
|
{
|
|
|
|
while($this->db->next_record())
|
|
|
|
{
|
|
|
|
$holidays[] = Array(
|
|
|
|
'index' => $this->db->f('hol_id'),
|
2004-08-04 00:52:13 +02:00
|
|
|
'locale' => $this->db->f('hol_locale'),
|
2005-11-09 00:15:14 +01:00
|
|
|
'name' => $GLOBALS['egw']->strip_html($this->db->f('hol_name')),
|
2004-08-04 00:52:13 +02:00
|
|
|
'day' => (int)$this->db->f('hol_mday'),
|
|
|
|
'month' => (int)$this->db->f('hol_month_num'),
|
|
|
|
'occurence' => (int)$this->db->f('hol_occurence'),
|
|
|
|
'dow' => (int)$this->db->f('hol_dow'),
|
|
|
|
'observance_rule' => $this->db->f('hol_observance_rule')
|
2001-07-28 15:17:30 +02:00
|
|
|
);
|
|
|
|
if($this->debug)
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
echo 'Holiday ID: '.$this->db->f('hol_id').'<br>'."\n";
|
2001-07-28 15:17:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-27 20:28:25 +01:00
|
|
|
function read_holidays($locales='',$query='',$order='',$year=0)
|
2001-07-18 19:30:24 +02:00
|
|
|
{
|
|
|
|
$holidays = Array();
|
|
|
|
|
|
|
|
if($locales == '')
|
|
|
|
{
|
|
|
|
return $holidays;
|
|
|
|
}
|
2001-07-28 15:17:30 +02:00
|
|
|
|
2004-08-04 00:52:13 +02:00
|
|
|
$where = $this->_build_where($locales,$query,$order,$year);
|
2001-07-28 15:17:30 +02:00
|
|
|
|
|
|
|
if($this->debug)
|
|
|
|
{
|
2004-08-04 00:52:13 +02:00
|
|
|
echo 'Read Holidays : '.$where.'<br>'."\n";
|
2001-07-28 15:17:30 +02:00
|
|
|
}
|
|
|
|
|
2004-08-04 00:52:13 +02:00
|
|
|
$this->db->select($this->table,'*',$where,__LINE__,__FILE__);
|
2001-07-28 15:17:30 +02:00
|
|
|
$this->store_to_array($holidays);
|
|
|
|
return $holidays;
|
|
|
|
}
|
|
|
|
|
|
|
|
function read_holiday($id)
|
|
|
|
{
|
|
|
|
$holidays = Array();
|
|
|
|
if($this->debug)
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
echo 'Reading Holiday ID : '.$id.'<br>'."\n";
|
2001-07-28 15:17:30 +02:00
|
|
|
}
|
2004-08-04 00:52:13 +02:00
|
|
|
$this->db->select($this->table,'*',array('hol_id'=>$id),__LINE__,__FILE__);
|
2001-07-28 15:17:30 +02:00
|
|
|
$this->store_to_array($holidays);
|
|
|
|
return $holidays[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete_holiday($id)
|
|
|
|
{
|
2004-08-04 00:52:13 +02:00
|
|
|
$this->db->delete($this->table,array('hol_id' => $id),__LINE__,__FILE__);
|
2001-07-28 15:17:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function delete_locale($locale)
|
|
|
|
{
|
2005-11-09 00:15:14 +01:00
|
|
|
$this->db->delete($this->table,array('hol_locale' => $locale),__LINE__,__FILE__);
|
2001-07-28 15:17:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Private functions */
|
2004-08-04 01:22:35 +02:00
|
|
|
function _build_where($locales,$query='',$order='',$year=0,$add_order_by=True)
|
2001-07-28 15:17:30 +02:00
|
|
|
{
|
2004-08-04 00:52:13 +02:00
|
|
|
$querymethod = 'hol_locale';
|
2004-04-12 09:20:40 +02:00
|
|
|
if (is_array($locales))
|
2001-07-18 19:30:24 +02:00
|
|
|
{
|
2004-04-12 09:20:40 +02:00
|
|
|
$querymethod .= ' IN ('.$this->db->column_data_implode(',',$locales,False).')';
|
2001-07-18 19:30:24 +02:00
|
|
|
}
|
2004-04-12 09:20:40 +02:00
|
|
|
else
|
2001-07-18 19:30:24 +02:00
|
|
|
{
|
2004-04-12 09:20:40 +02:00
|
|
|
$querymethod .= '='.$this->db->quote($locales);
|
2001-07-18 19:30:24 +02:00
|
|
|
}
|
2001-07-28 15:17:30 +02:00
|
|
|
if($query)
|
|
|
|
{
|
2005-02-10 02:09:06 +01:00
|
|
|
$querymethod .= " AND hol_name LIKE ".$this->db->quote('%'.$query.'%');
|
2001-07-28 15:17:30 +02:00
|
|
|
}
|
2004-04-12 09:20:40 +02:00
|
|
|
if ($year > 1900)
|
2001-07-28 15:17:30 +02:00
|
|
|
{
|
2004-08-04 00:52:13 +02:00
|
|
|
$querymethod .= " AND (hol_occurence < 1900 OR hol_occurence = ".(int)$year.")";
|
2001-07-28 15:17:30 +02:00
|
|
|
}
|
2004-08-04 01:22:35 +02:00
|
|
|
if ($add_order_by)
|
|
|
|
{
|
2004-08-07 12:40:10 +02:00
|
|
|
$querymethod .= ' ORDER BY '.(preg_match('/^[a-zA-Z0-9_,]+$/',$order) ? $order : 'hol_month_num,hol_mday');
|
2004-08-04 01:22:35 +02:00
|
|
|
}
|
2004-08-04 00:52:13 +02:00
|
|
|
return $querymethod;
|
2001-07-28 15:17:30 +02:00
|
|
|
}
|
2001-07-18 19:30:24 +02:00
|
|
|
|
2001-07-28 15:17:30 +02:00
|
|
|
function get_locale_list($sort='', $order='', $query='')
|
|
|
|
{
|
|
|
|
$querymethod = '';
|
|
|
|
if($query)
|
|
|
|
{
|
2005-06-15 15:04:35 +02:00
|
|
|
$querymethod = 'hol_locale LIKE '.$this->db->quote('%'.$query.'%');
|
2001-07-28 15:17:30 +02:00
|
|
|
}
|
|
|
|
|
2005-06-15 15:04:35 +02:00
|
|
|
if(preg_match('/^[a-zA-Z0-9_,]+$/',$order))
|
2001-07-28 15:17:30 +02:00
|
|
|
{
|
|
|
|
$querymethod .= ' ORDER BY '.$order;
|
|
|
|
}
|
2004-08-04 00:52:13 +02:00
|
|
|
$this->db->select($this->table,'DISTINCT hol_locale',$querymethod,__LINE__,__FILE__);
|
2001-07-18 19:30:24 +02:00
|
|
|
while($this->db->next_record())
|
|
|
|
{
|
2005-06-07 11:51:18 +02:00
|
|
|
$locale[] = $this->db->f('hol_locale');
|
2001-07-18 19:30:24 +02:00
|
|
|
}
|
2001-07-28 15:17:30 +02:00
|
|
|
return $locale;
|
2001-07-18 19:30:24 +02:00
|
|
|
}
|
2001-07-28 15:17:30 +02:00
|
|
|
|
2003-02-27 20:28:25 +01:00
|
|
|
function holiday_total($locale,$query='',$year=0)
|
2001-07-18 19:30:24 +02:00
|
|
|
{
|
2004-08-04 01:22:35 +02:00
|
|
|
$where = $this->_build_where($locale,$query,'',$year,False);
|
2001-07-28 15:17:30 +02:00
|
|
|
|
|
|
|
if($this->debug)
|
|
|
|
{
|
2004-08-04 00:52:13 +02:00
|
|
|
echo 'HOLIDAY_TOTAL : '.$where.'<br>'."\n";
|
2001-07-28 15:17:30 +02:00
|
|
|
}
|
|
|
|
|
2004-08-04 00:52:13 +02:00
|
|
|
$this->db->select($this->table,'count(*)',$where,__LINE__,__FILE__);
|
2001-07-18 19:30:24 +02:00
|
|
|
$this->db->next_record();
|
2004-01-04 01:47:37 +01:00
|
|
|
$retval = (int)$this->db->f(0);
|
2001-07-28 15:17:30 +02:00
|
|
|
if($this->debug)
|
|
|
|
{
|
|
|
|
echo 'Total Holidays for : '.$locale.' : '.$retval."<br>\n";
|
|
|
|
}
|
|
|
|
return $retval;
|
2001-07-18 19:30:24 +02:00
|
|
|
}
|
|
|
|
}
|