[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare - Calendar * |
---|
| 4 | * http://www.eGroupWare.org * |
---|
| 5 | * Maintained and further developed by RalfBecker@outdoor-training.de * |
---|
| 6 | * Based on Webcalendar by Craig Knudsen <cknudsen@radix.net> * |
---|
| 7 | * http://www.radix.net/~cknudsen * |
---|
| 8 | * Originaly modified by Mark Peters <skeeter@phpgroupware.org> * |
---|
| 9 | * -------------------------------------------- * |
---|
| 10 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 11 | * under the terms of the GNU General Public License as published by the * |
---|
| 12 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 13 | * option) any later version. * |
---|
| 14 | \**************************************************************************/ |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | class socalendar |
---|
| 18 | { |
---|
| 19 | // var $debug = True; |
---|
| 20 | var $debug = False; |
---|
| 21 | var $cal; |
---|
| 22 | var $db; |
---|
| 23 | var $owner; |
---|
| 24 | var $g_owner; |
---|
| 25 | var $is_group = False; |
---|
| 26 | var $datetime; |
---|
| 27 | var $filter; |
---|
| 28 | var $cat_id; |
---|
| 29 | |
---|
| 30 | function socalendar($param) |
---|
| 31 | { |
---|
| 32 | $this->db = $GLOBALS['phpgw']->db; |
---|
| 33 | if(!is_object($GLOBALS['phpgw']->datetime)) |
---|
| 34 | { |
---|
| 35 | $GLOBALS['phpgw']->datetime = createobject('phpgwapi.date_time'); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | $this->owner = (!isset($param['owner']) || $param['owner'] == 0?$GLOBALS['phpgw_info']['user']['account_id']:$param['owner']); |
---|
| 39 | $this->filter = (isset($param['filter']) && $param['filter'] != ''?$param['filter']:$this->filter); |
---|
| 40 | $this->cat_id = (isset($param['category']) && $param['category'] != ''?$param['category']:$this->cat_id); |
---|
| 41 | if(isset($param['g_owner']) && is_array($param['g_owner'])) |
---|
| 42 | { |
---|
| 43 | $this->is_group = True; |
---|
| 44 | $this->g_owner = $param['g_owner']; |
---|
| 45 | } |
---|
| 46 | if($this->debug) |
---|
| 47 | { |
---|
| 48 | echo '<!-- SO Filter : '.$this->filter.' -->'."\n"; |
---|
| 49 | echo '<!-- SO cat_id : '.$this->cat_id.' -->'."\n"; |
---|
| 50 | } |
---|
| 51 | $this->cal = CreateObject('calendar.socalendar_'); |
---|
| 52 | $this->open_box($this->owner); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | // It returns uidNumber and cn ( Retorna o uidNumber e o cn ) |
---|
| 56 | function search_uidNumber($mail) |
---|
| 57 | { |
---|
| 58 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 59 | $justthese = array("uidNumber","cn","mail"); |
---|
| 60 | $search = ldap_search($connection, $GLOBALS['phpgw_info']['server']['ldap_context'], "mail=" . $mail, $justthese); |
---|
| 61 | $result = ldap_get_entries($connection, $search); |
---|
| 62 | ldap_close($connection); |
---|
| 63 | return $result; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | function open_box($owner) |
---|
| 67 | { |
---|
| 68 | $this->cal->open('INBOX',(int)$owner); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | function maketime($time) |
---|
| 72 | { |
---|
| 73 | return mktime($time['hour'],$time['min'],$time['sec'],$time['month'],$time['mday'],$time['year']); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | function read_entry($id) |
---|
| 77 | { |
---|
| 78 | return $this->cal->fetch_event($id); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | function list_events($startYear,$startMonth,$startDay,$endYear=0,$endMonth=0,$endDay=0,$owner_id=0) |
---|
| 82 | { |
---|
| 83 | $extra = ''; |
---|
| 84 | $extra .= (strpos($this->filter,'private')?'AND phpgw_cal.is_public=0 ':''); |
---|
| 85 | //$extra .= ($this->cat_id?"AND phpgw_cal.category like '%".$this->cat_id."%' ":''); |
---|
| 86 | if ($this->cat_id) |
---|
| 87 | { |
---|
| 88 | if (!is_object($GLOBALS['phpgw']->categories)) |
---|
| 89 | { |
---|
| 90 | $GLOBALS['phpgw']->categories = CreateObject('phpgwapi.categories'); |
---|
| 91 | } |
---|
| 92 | $cats = $GLOBALS['phpgw']->categories->return_all_children($this->cat_id); |
---|
[1729] | 93 | $extra .= "AND (phpgw_cal.category".(count($cats) > 1 ? " IN ('".implode("','",$cats)."')" : '=\''.(int)$this->cat_id."'"); |
---|
[2] | 94 | foreach($cats as $cat) |
---|
| 95 | { |
---|
| 96 | $extra .= " OR phpgw_cal.category LIKE '$cat,%' OR phpgw_cal.category LIKE '%,$cat,%' OR phpgw_cal.category LIKE '%,$cat'"; |
---|
| 97 | } |
---|
| 98 | $extra .= ') '; |
---|
| 99 | } |
---|
| 100 | if($owner_id) |
---|
| 101 | { |
---|
| 102 | return $this->cal->list_events($startYear,$startMonth,$startDay,$endYear,$endMonth,$endDay,$extra,$GLOBALS['phpgw']->datetime->tz_offset,$owner_id); |
---|
| 103 | } |
---|
| 104 | else |
---|
| 105 | { |
---|
| 106 | return $this->cal->list_events($startYear,$startMonth,$startDay,$endYear,$endMonth,$endDay,$extra,$GLOBALS['phpgw']->datetime->tz_offset); |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | function list_repeated_events($syear,$smonth,$sday,$eyear,$emonth,$eday,$owner_id=0) |
---|
| 111 | { |
---|
| 112 | if(!$owner_id) |
---|
| 113 | { |
---|
| 114 | $owner_id = $this->is_group ? $this->g_owner : $this->owner; |
---|
| 115 | } |
---|
| 116 | if($GLOBALS['phpgw_info']['server']['calendar_type'] != 'sql' || |
---|
| 117 | !count($owner_id)) // happens with empty groups |
---|
| 118 | { |
---|
| 119 | return Array(); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | $starttime = mktime(0,0,0,$smonth,$sday,$syear) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
| 123 | $endtime = mktime(23,59,59,$emonth,$eday,$eyear) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
| 124 | $sql = "AND phpgw_cal.cal_type='M' AND phpgw_cal_user.cal_login IN (". |
---|
| 125 | (is_array($owner_id) ? implode(',',$owner_id) : $owner_id).')'; |
---|
| 126 | |
---|
| 127 | // $member_groups = $GLOBALS['phpgw']->accounts->membership($this->user); |
---|
| 128 | // @reset($member_groups); |
---|
| 129 | // while(list($key,$group_info) = each($member_groups)) |
---|
| 130 | // { |
---|
| 131 | // $member[] = $group_info['account_id']; |
---|
| 132 | // } |
---|
| 133 | // @reset($member); |
---|
| 134 | // $sql .= ','.implode(',',$member).') '; |
---|
| 135 | // $sql .= 'AND (phpgw_cal.datetime <= '.$starttime.') '; |
---|
| 136 | // $sql .= 'AND (((phpgw_cal_repeats.recur_enddate >= '.$starttime.') AND (phpgw_cal_repeats.recur_enddate <= '.$endtime.')) OR (phpgw_cal_repeats.recur_enddate=0))) ' |
---|
| 137 | $sql .= ' AND (phpgw_cal_repeats.recur_enddate >= '.$starttime.' OR phpgw_cal_repeats.recur_enddate=0) ' |
---|
| 138 | . (strpos($this->filter,'private')?'AND phpgw_cal.is_public=0 ':'') |
---|
| 139 | . ($this->cat_id?"AND phpgw_cal.category like '%".$this->cat_id."%' ":'') |
---|
| 140 | . 'ORDER BY phpgw_cal.datetime ASC, phpgw_cal.edatetime ASC, phpgw_cal.priority ASC'; |
---|
| 141 | |
---|
| 142 | if($this->debug) |
---|
| 143 | { |
---|
| 144 | echo '<!-- SO list_repeated_events : SQL : '.$sql.' -->'."\n"; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | return $this->get_event_ids(True,$sql); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | function list_events_keyword($keywords,$members='') |
---|
| 151 | { |
---|
| 152 | if (!$members) |
---|
| 153 | { |
---|
| 154 | $members[] = $this->owner; |
---|
| 155 | } |
---|
| 156 | $sql = 'AND (phpgw_cal_user.cal_login IN ('.implode(',',$members).')) AND '. |
---|
| 157 | '(phpgw_cal_user.cal_login=' . (int)$this->owner . ' OR phpgw_cal.is_public=1) AND ('; |
---|
| 158 | |
---|
| 159 | $words = split(' ',$keywords); |
---|
| 160 | foreach($words as $i => $word) |
---|
| 161 | { |
---|
| 162 | $sql .= $i > 0 ? ' OR ' : ''; |
---|
| 163 | $sql .= "(UPPER(phpgw_cal.title) LIKE UPPER('%".addslashes($word)."%') OR " |
---|
| 164 | . "UPPER(phpgw_cal.description) LIKE UPPER('%".addslashes($word)."%') OR " |
---|
| 165 | . "UPPER(phpgw_cal.location) LIKE UPPER('%".addslashes($word)."%') OR " |
---|
| 166 | . "UPPER(phpgw_cal_extra.cal_extra_value) LIKE UPPER('%".addslashes($word)."%'))"; |
---|
| 167 | } |
---|
| 168 | $sql .= ') '; |
---|
| 169 | |
---|
| 170 | $sql .= (strpos($this->filter,'private')?'AND phpgw_cal.is_public=0 ':''); |
---|
| 171 | $sql .= ($this->cat_id? "AND (phpgw_cal.category='$this->cat_id' OR phpgw_cal.category like '%,".$this->cat_id.",%') ":''); |
---|
| 172 | $sql .= 'ORDER BY phpgw_cal.datetime DESC, phpgw_cal.edatetime DESC, phpgw_cal.priority ASC'; |
---|
| 173 | |
---|
| 174 | return $this->get_event_ids(False,$sql,True); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | function read_from_store($startYear,$startMonth,$startDay,$endYear='',$endMonth='',$endDay='') |
---|
| 178 | { |
---|
| 179 | $events = $this->list_events($startYear,$startMonth,$startDay,$endYear,$endMonth,$endDay); |
---|
| 180 | $events_cached = Array(); |
---|
| 181 | for($i=0;$i<count($events);$i++) |
---|
| 182 | { |
---|
| 183 | $events_cached[] = $this->read_entry($events[$i]); |
---|
| 184 | } |
---|
| 185 | return $events_cached; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | function get_event_ids($search_repeats=False, $sql='',$search_extra=False) |
---|
| 189 | { |
---|
| 190 | return $this->cal->get_event_ids($search_repeats,$sql,$search_extra); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | function find_uid($uid) |
---|
| 194 | { |
---|
| 195 | $sql = " AND (phpgw_cal.uid = '".$uid."') "; |
---|
| 196 | |
---|
| 197 | $found = $this->cal->get_event_ids(False,$sql); |
---|
| 198 | if(!$found) |
---|
| 199 | { |
---|
| 200 | $found = $this->cal->get_event_ids(True,$sql); |
---|
| 201 | } |
---|
| 202 | if(is_array($found)) |
---|
| 203 | { |
---|
| 204 | return $found[0]; |
---|
| 205 | } |
---|
| 206 | else |
---|
| 207 | { |
---|
| 208 | return False; |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | function add_entry(&$event) |
---|
| 213 | { |
---|
| 214 | return $this->cal->save_event($event); |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | function save_alarm($cal_id,$alarm,$id=0) |
---|
| 218 | { |
---|
| 219 | return $this->cal->save_alarm($cal_id,$alarm,$id); |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | function delete_alarm($id) |
---|
| 223 | { |
---|
| 224 | return $this->cal->delete_alarm($id); |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | function delete_alarms($cal_id) |
---|
| 228 | { |
---|
| 229 | return $this->cal->delete_alarms($cal_id); |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | function delete_entry($id) |
---|
| 233 | { |
---|
| 234 | return $this->cal->delete_event($id); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | function expunge() |
---|
| 238 | { |
---|
| 239 | $this->cal->expunge(); |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | function delete_calendar($owner) |
---|
| 243 | { |
---|
| 244 | $this->cal->delete_calendar($owner); |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | function change_owner($account_id,$new_owner) |
---|
| 248 | { |
---|
| 249 | if($GLOBALS['phpgw_info']['server']['calendar_type'] == 'sql') |
---|
| 250 | { |
---|
| 251 | $db2 = $this->cal->stream; |
---|
| 252 | $this->cal->stream->query('SELECT cal_id FROM phpgw_cal_user WHERE cal_login='.$account_id,__LINE__,__FILE__); |
---|
| 253 | while($this->cal->stream->next_record()) |
---|
| 254 | { |
---|
| 255 | $id = $this->cal->stream->f('cal_id'); |
---|
| 256 | $db2->query('SELECT count(*) FROM phpgw_cal_user WHERE cal_id='.$id.' AND cal_login='.$new_owner,__LINE__,__FILE__); |
---|
| 257 | $db2->next_record(); |
---|
| 258 | if($db2->f(0) == 0) |
---|
| 259 | { |
---|
| 260 | $db2->query('UPDATE phpgw_cal_user SET cal_login='.$new_owner.' WHERE cal_id='.$id.' AND cal_login='.$account_id,__LINE__,__FILE__); |
---|
| 261 | } |
---|
| 262 | else |
---|
| 263 | { |
---|
| 264 | $db2->query('DELETE FROM phpgw_cal_user WHERE cal_id='.$id.' AND cal_login='.$account_id,__LINE__,__FILE__); |
---|
| 265 | } |
---|
| 266 | } |
---|
| 267 | $this->cal->stream->query('UPDATE phpgw_cal SET owner='.$new_owner.' WHERE owner='.$account_id,__LINE__,__FILE__); |
---|
| 268 | } |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | function set_status($id,$status) |
---|
| 272 | { |
---|
| 273 | $this->cal->set_status($id,$this->owner,$status); |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | function get_alarm($cal_id) |
---|
| 277 | { |
---|
| 278 | if (!method_exists($this->cal,'get_alarm')) |
---|
| 279 | { |
---|
| 280 | return False; |
---|
| 281 | } |
---|
| 282 | return $this->cal->get_alarm($cal_id); |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | function read_alarm($id) |
---|
| 286 | { |
---|
| 287 | if (!method_exists($this->cal,'read_alarm')) |
---|
| 288 | { |
---|
| 289 | return False; |
---|
| 290 | } |
---|
| 291 | return $this->cal->read_alarm($id); |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | function read_alarms($cal_id) |
---|
| 295 | { |
---|
| 296 | if (!method_exists($this->cal,'read_alarms')) |
---|
| 297 | { |
---|
| 298 | return False; |
---|
| 299 | } |
---|
| 300 | return $this->cal->read_alarms($cal_id); |
---|
| 301 | } |
---|
| 302 | |
---|
| 303 | function find_recur_exceptions($event_id) |
---|
| 304 | { |
---|
| 305 | if($GLOBALS['phpgw_info']['server']['calendar_type'] == 'sql') |
---|
| 306 | { |
---|
| 307 | $arr = Array(); |
---|
| 308 | $this->cal->query('SELECT datetime FROM phpgw_cal WHERE reference='.$event_id,__LINE__,__FILE__); |
---|
| 309 | if($this->cal->num_rows()) |
---|
| 310 | { |
---|
| 311 | while($this->cal->next_record()) |
---|
| 312 | { |
---|
| 313 | $arr[] = (int)$this->cal->f('datetime'); |
---|
| 314 | } |
---|
| 315 | } |
---|
| 316 | if(count($arr) == 0) |
---|
| 317 | { |
---|
| 318 | return False; |
---|
| 319 | } |
---|
| 320 | else |
---|
| 321 | { |
---|
| 322 | return $arr; |
---|
| 323 | } |
---|
| 324 | } |
---|
| 325 | else |
---|
| 326 | { |
---|
| 327 | return False; |
---|
| 328 | } |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | /* Begin mcal equiv functions */ |
---|
| 332 | function get_cached_event() |
---|
| 333 | { |
---|
| 334 | return $this->cal->event; |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | function add_attribute($var,$value,$element='**(**') |
---|
| 338 | { |
---|
| 339 | $this->cal->add_attribute($var,$value,$element); |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | function event_init() |
---|
| 343 | { |
---|
| 344 | $this->cal->event_init(); |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | function set_date($element,$year,$month,$day=0,$hour=0,$min=0,$sec=0) |
---|
| 348 | { |
---|
| 349 | $this->cal->set_date($element,$year,$month,$day,$hour,$min,$sec); |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | function set_start($year,$month,$day=0,$hour=0,$min=0,$sec=0) |
---|
| 353 | { |
---|
| 354 | $this->cal->set_start($year,$month,$day,$hour,$min,$sec); |
---|
| 355 | } |
---|
| 356 | |
---|
| 357 | function set_end($year,$month,$day=0,$hour=0,$min=0,$sec=0) |
---|
| 358 | { |
---|
| 359 | $this->cal->set_end($year,$month,$day,$hour,$min,$sec); |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | function set_title($title='') |
---|
| 363 | { |
---|
| 364 | $this->cal->set_title($title); |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | function set_description($description='') |
---|
| 368 | { |
---|
| 369 | $this->cal->set_description($description); |
---|
| 370 | } |
---|
| 371 | function set_ex_participants($ex_participants='') |
---|
| 372 | { |
---|
| 373 | $this->cal->set_ex_participants($ex_participants); |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | function set_class($class) |
---|
| 377 | { |
---|
| 378 | $this->cal->set_class($class); |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | function set_category($category='') |
---|
| 382 | { |
---|
| 383 | $this->cal->set_category($category); |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | function set_alarm($alarm) |
---|
| 387 | { |
---|
| 388 | $this->cal->set_alarm($alarm); |
---|
| 389 | } |
---|
| 390 | |
---|
| 391 | function set_recur_none() |
---|
| 392 | { |
---|
| 393 | $this->cal->set_recur_none(); |
---|
| 394 | } |
---|
| 395 | |
---|
| 396 | function set_recur_daily($year,$month,$day,$interval) |
---|
| 397 | { |
---|
| 398 | $this->cal->set_recur_daily($year,$month,$day,$interval); |
---|
| 399 | } |
---|
| 400 | |
---|
| 401 | function set_recur_weekly($year,$month,$day,$interval,$weekdays) |
---|
| 402 | { |
---|
| 403 | $this->cal->set_recur_weekly($year,$month,$day,$interval,$weekdays); |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | function set_recur_monthly_mday($year,$month,$day,$interval) |
---|
| 407 | { |
---|
| 408 | $this->cal->set_recur_monthly_mday($year,$month,$day,$interval); |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | function set_recur_monthly_wday($year,$month,$day,$interval) |
---|
| 412 | { |
---|
| 413 | $this->cal->set_recur_monthly_wday($year,$month,$day,$interval); |
---|
| 414 | } |
---|
| 415 | |
---|
| 416 | function set_recur_yearly($year,$month,$day,$interval) |
---|
| 417 | { |
---|
| 418 | $this->cal->set_recur_yearly($year,$month,$day,$interval); |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | /* End mcal equiv functions */ |
---|
| 422 | } |
---|
| 423 | ?> |
---|