source: trunk/calendar/inc/class.soholiday.inc.php @ 2

Revision 2, 5.5 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare - Holiday                                                     *
4  * http://www.egroupware.org                                                *
5  * Written by Mark Peters <skeeter@phpgroupware.org>                        *
6  * --------------------------------------------                             *
7  *  This program is free software; you can redistribute it and/or modify it *
8  *  under the terms of the GNU General Public License as published by the   *
9  *  Free Software Foundation; either version 2 of the License, or (at your  *
10  *  option) any later version.                                              *
11  \**************************************************************************/
12
13
14        class soholiday
15        {
16                var $debug = False;
17                var $db;
18
19                function soholiday()
20                {
21                        $this->db = $GLOBALS['phpgw']->db;
22                        $this->table = 'phpgw_cal_holidays';
23                        $this->table_definition = $this->db->get_table_definitions('calendar',$this->table);
24                        $this->db->set_column_definitions($this->table_definition['fd']);
25                }
26
27                /* Begin Holiday functions */
28                function save_holiday($holiday)
29                {
30                        if(@$holiday['hol_id'])
31                        {
32                                if($this->debug)
33                                {
34                                        echo "Updating LOCALE='".$holiday['locale']."' NAME='".$holiday['name']."' extra=(".$holiday['mday'].'/'.$holiday['month_num'].'/'.$holiday['occurence'].'/'.$holiday['dow'].'/'.$holiday['observance_rule'].")<br>\n";
35                                }
36                                $sql = "UPDATE $this->table SET ".$this->db->column_data_implode(',',$holiday,True,True).' WHERE hol_id='.(int)$holiday['hol_id'];
37                        }
38                        else
39                        {
40                                if($this->debug)
41                                {
42                                        echo "Inserting LOCALE='".$holiday['locale']."' NAME='".$holiday['name']."' extra=(".$holiday['mday'].'/'.$holiday['month_num'].'/'.$holiday['occurence'].'/'.$holiday['dow'].'/'.$holiday['observance_rule'].")<br>\n";
43                                }
44                                unset($holiday['hol_id']);      // in case its 0
45                                $holiday['locale'] = strtoupper($holiday['locale']);
46                                $sql = "INSERT INTO $this->table ".$this->db->column_data_implode(',',$holiday,'VALUES',True);
47                        }
48                        $this->db->query($sql,__LINE__,__FILE__);
49                }
50
51                function store_to_array(&$holidays)
52                {
53                        while($this->db->next_record())
54                        {
55                                $holidays[] = Array(
56                                        'index'                 => $this->db->f('hol_id'),
57                                        'locale'                => $this->db->f('locale'),
58                                        'name'                  => $GLOBALS['phpgw']->strip_html($this->db->f('name')),
59                                        'day'                   => (int)$this->db->f('mday'),
60                                        'month'                 => (int)$this->db->f('month_num'),
61                                        'occurence'             => (int)$this->db->f('occurence'),
62                                        'dow'                   => (int)$this->db->f('dow'),
63                                        'observance_rule'       => $this->db->f('observance_rule')
64                                );
65                                if($this->debug)
66                                {
67                                        echo 'Holiday ID: '.$this->db->f('hol_id').'<br>'."\n";
68                                }
69                        }
70                }
71
72                function read_holidays($locales='',$query='',$order='',$year=0)
73                {
74                        $holidays = Array();
75
76                        if($locales == '')
77                        {
78                                return $holidays;
79                        }
80
81                        $sql = $this->build_query($locales,$query,$order,$year);
82
83                        if($this->debug)
84                        {
85                                echo 'Read Holidays : '.$sql.'<br>'."\n";
86                        }
87
88                        $this->db->query($sql,__LINE__,__FILE__);
89                        $this->store_to_array($holidays);
90                        return $holidays;
91                }
92
93                function read_holiday($id)
94                {
95                        $holidays = Array();
96                        if($this->debug)
97                        {
98                                echo 'Reading Holiday ID : '.$id.'<br>'."\n";
99                        }
100                        $this->db->query("SELECT * FROM $this->table WHERE hol_id=".(int)$id,__LINE__,__FILE__);
101                        $this->store_to_array($holidays);
102                        @reset($holidays);
103                        return $holidays[0];
104                }
105
106                function delete_holiday($id)
107                {
108                        $this->db->query("DELETE FROM $this->table WHERE hol_id=".(int)$id,__LINE__,__FILE__);
109                }
110
111                function delete_locale($locale)
112                {
113                        $this->db->query("DELETE FROM $this->table WHERE locale=".$this->db->quote($locale),__LINE__,__FILE__);
114                }
115               
116                /* Private functions */
117                function build_query($locales,$query='',$order='',$year=0)
118                {
119                        $querymethod = 'locale';
120                        if (is_array($locales))
121                        {
122                                $querymethod .= ' IN ('.$this->db->column_data_implode(',',$locales,False).')';
123                        }
124                        else
125                        {
126                                $querymethod .= '='.$this->db->quote($locales);
127                        }
128                        if($query)
129                        {
130                                $querymethod = " AND name LIKE ".$this->db->quote('%'.$query.'%');
131                        }
132                        if ($year > 1900)
133                        {
134                                $querymethod .= " AND (occurence < 1900 OR occurence = ".(int)$year.")";
135                        }
136                        $querymethod .= ' ORDER BY '.(preg_match('/[a-zA-Z0-9_,]+/',$order) ? $order : 'month_num,mday');
137
138                        return "SELECT * FROM $this->table WHERE ".$querymethod;
139                }
140
141                function get_locale_list($sort='', $order='', $query='')
142                {
143                        $querymethod = '';
144                        if($query)
145                        {
146                                $querymethod .= " WHERE locale LIKE ".$this->db->quote('%'.$query.'%');
147                        }
148               
149                        if(preg_match('/[a-zA-Z0-9_,]+/',$order))
150                        {
151                                $querymethod .= ' ORDER BY '.$order;
152                        }
153                        $this->db->query("SELECT DISTINCT locale FROM $this->table".$querymethod,__LINE__,__FILE__);
154                        while($this->db->next_record())
155                        {
156                                $locale[] = $this->db->f('locale');
157                        }
158                        return $locale;
159                }
160               
161                function holiday_total($locale,$query='',$year=0)
162                {
163                        $querymethod='';
164                        if($query)
165                        {
166                                $querymethod = ' AND name LIKE '.$this->db->quote('%'.$query.'%');
167                        }
168                        if ($year >= 1900)
169                        {
170                                $querymethod .= ' AND (occurence < 1900 OR occurence = '.(int)$year.")";
171                        }
172                        $sql = "SELECT count(*) FROM $this->table WHERE locale=".$this->db->quote($locale).$querymethod;
173
174                        if($this->debug)
175                        {
176                                echo 'HOLIDAY_TOTAL : '.$sql.'<br>'."\n";
177                        }
178                       
179                        $this->db->query($sql,__LINE__,__FILE__);
180                        $this->db->next_record();
181                        $retval = (int)$this->db->f(0);
182                        if($this->debug)
183                        {
184                                echo 'Total Holidays for : '.$locale.' : '.$retval."<br>\n";
185                        }
186                        return $retval;
187                }
188        }
189?>
Note: See TracBrowser for help on using the repository browser.