[2] | 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 | { |
---|
[1589] | 130 | $querymethod = " name LIKE ".$this->db->quote('%'.$query.'%'); |
---|
[2] | 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 | return "SELECT * FROM $this->table WHERE ".$querymethod; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | function get_locale_list($sort='', $order='', $query='') |
---|
| 141 | { |
---|
| 142 | $querymethod = ''; |
---|
| 143 | if($query) |
---|
| 144 | { |
---|
| 145 | $querymethod .= " WHERE locale LIKE ".$this->db->quote('%'.$query.'%'); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | if(preg_match('/[a-zA-Z0-9_,]+/',$order)) |
---|
| 149 | { |
---|
| 150 | $querymethod .= ' ORDER BY '.$order; |
---|
| 151 | } |
---|
| 152 | $this->db->query("SELECT DISTINCT locale FROM $this->table".$querymethod,__LINE__,__FILE__); |
---|
| 153 | while($this->db->next_record()) |
---|
| 154 | { |
---|
| 155 | $locale[] = $this->db->f('locale'); |
---|
| 156 | } |
---|
| 157 | return $locale; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | function holiday_total($locale,$query='',$year=0) |
---|
| 161 | { |
---|
| 162 | $querymethod=''; |
---|
| 163 | if($query) |
---|
| 164 | { |
---|
| 165 | $querymethod = ' AND name LIKE '.$this->db->quote('%'.$query.'%'); |
---|
| 166 | } |
---|
| 167 | if ($year >= 1900) |
---|
| 168 | { |
---|
| 169 | $querymethod .= ' AND (occurence < 1900 OR occurence = '.(int)$year.")"; |
---|
| 170 | } |
---|
| 171 | $sql = "SELECT count(*) FROM $this->table WHERE locale=".$this->db->quote($locale).$querymethod; |
---|
| 172 | |
---|
| 173 | if($this->debug) |
---|
| 174 | { |
---|
| 175 | echo 'HOLIDAY_TOTAL : '.$sql.'<br>'."\n"; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | $this->db->query($sql,__LINE__,__FILE__); |
---|
| 179 | $this->db->next_record(); |
---|
| 180 | $retval = (int)$this->db->f(0); |
---|
| 181 | if($this->debug) |
---|
| 182 | { |
---|
| 183 | echo 'Total Holidays for : '.$locale.' : '.$retval."<br>\n"; |
---|
| 184 | } |
---|
| 185 | return $retval; |
---|
| 186 | } |
---|
| 187 | } |
---|
| 188 | ?> |
---|