source: trunk/calendar/inc/class.socalendar.inc.php @ 5132

Revision 5132, 13.6 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo calendar.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
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);
93                                $extra .= "AND (phpgw_cal.category".(count($cats) > 1 ? " IN ('".implode("','",$cats)."')" : '=\''.(int)$this->cat_id."'");
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_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                        $uid_ = substr($uid, strpos($uid,"-")+1);                               
196                        $uid_ = substr($uid_, 0, strpos($uid_,"-"));                           
197                       
198                        $sql = " AND (phpgw_cal.cal_id = '". (int)$uid_."') ";
199
200                        $found = $this->cal->get_event_ids(False,$sql);
201                        if(!$found)
202                        {
203                                $found = $this->cal->get_event_ids(True,$sql);
204                        }
205                        if(is_array($found))
206                        {
207                                return $found[0];
208                        }
209                        else
210                        {
211                                return False;
212                        }
213                }
214
215               
216                /*
217                 * @abstract: Retorna o email do organizer do evento.
218                 */
219                function get_mail_organizer($cal_id)
220                {
221                        $sql = 'SELECT organizer FROM phpgw_cal WHERE cal_id =' . $cal_id;     
222                        $this->cal->stream->query($sql,__LINE__,__FILE__);
223                       
224                        while($this->cal->stream->next_record())
225                        {
226                                $ret[0] = $this->cal->stream->f('organizer');
227                        }
228                       
229                        $return = $ret[0];
230                        $pos = strpos($return, "<");
231                        $return = substr($return, $pos);
232                        $return = str_replace('"','',$return);
233                        $return = str_replace('>','',$return);
234                        $return = str_replace('<','',$return);
235                       
236                        return $return;
237                }
238               
239               
240                /*
241                 * @abstract: Retorna os emails dos participantes do evento.
242                 */
243                function get_mail_participants($cal_id)
244                {
245               
246                }
247               
248               
249                /*
250                 * @abstract: busca no banco pra verificar se já existe um compromisso com o mesmo cal_id
251                 */
252                function find_cal_id($cal_id)
253                {
254
255                        $uid_ = substr($cal_id, strpos($cal_id,"-")+1);
256                        $uid_ = substr($uid_, 0, strpos($uid_,"-"));
257
258                        $sql = " AND phpgw_cal.cal_id = '". (int)$uid_."' OR phpgw_cal.uid = '". $cal_id."' ";
259
260                        $found = $this->cal->get_event_ids(False,$sql);
261                        if(!$found)
262                        {
263                                $found = $this->cal->get_event_ids(True,$sql);
264                        }
265                        if(is_array($found))
266                        {
267                                return $found[0];
268                        }
269                        else
270                        {
271                                return False;
272                        }
273                }
274               
275
276                function add_entry(&$event , $sendMail = true, $importAccount = false)
277                {
278                        return $this->cal->save_event($event,$sendMail,$importAccount);
279                }
280
281                function save_alarm($cal_id,$alarm,$id=0)
282                {
283                        return $this->cal->save_alarm($cal_id,$alarm,$id);
284                }
285
286                function delete_alarm($id)
287                {
288                        return $this->cal->delete_alarm($id);
289                }
290
291                function delete_alarms($cal_id)
292                {
293                        return $this->cal->delete_alarms($cal_id);
294                }
295
296                function delete_entry($id)
297                {
298                        return $this->cal->delete_event($id);
299                }
300
301                function expunge()
302                {
303                        $this->cal->expunge();
304                }
305
306                function delete_calendar($owner)
307                {
308                        $this->cal->delete_calendar($owner);
309                }
310
311                function change_owner($account_id,$new_owner)
312                {
313                        if($GLOBALS['phpgw_info']['server']['calendar_type'] == 'sql')
314                        {
315                                $db2 = $this->cal->stream;
316                                $this->cal->stream->query('SELECT cal_id FROM phpgw_cal_user WHERE cal_login='.$account_id,__LINE__,__FILE__);
317                                while($this->cal->stream->next_record())
318                                {
319                                        $id = $this->cal->stream->f('cal_id');
320                                        $db2->query('SELECT count(*) FROM phpgw_cal_user WHERE cal_id='.$id.' AND cal_login='.$new_owner,__LINE__,__FILE__);
321                                        $db2->next_record();
322                                        if($db2->f(0) == 0)
323                                        {
324                                                $db2->query('UPDATE phpgw_cal_user SET cal_login='.$new_owner.' WHERE cal_id='.$id.' AND cal_login='.$account_id,__LINE__,__FILE__);
325                                        }
326                                        else
327                                        {
328                                                $db2->query('DELETE FROM phpgw_cal_user WHERE cal_id='.$id.' AND cal_login='.$account_id,__LINE__,__FILE__);
329                                        }
330                                }
331                                $this->cal->stream->query('UPDATE phpgw_cal SET owner='.$new_owner.' WHERE owner='.$account_id,__LINE__,__FILE__);
332                        }
333                }
334
335                function set_status($id,$status,$user = false)
336                {
337                    if($user) $this->cal->set_status($id,$user,$status);
338                    else $this->cal->set_status($id,$this->owner,$status);
339                }
340
341                function get_alarm($cal_id)
342                {
343                        if (!method_exists($this->cal,'get_alarm'))
344                        {
345                                return False;
346                        }
347                        return $this->cal->get_alarm($cal_id);
348                }
349
350                function read_alarm($id)
351                {
352                        if (!method_exists($this->cal,'read_alarm'))
353                        {
354                                return False;
355                        }
356                        return $this->cal->read_alarm($id);
357                }
358
359                function read_alarms($cal_id)
360                {
361                        if (!method_exists($this->cal,'read_alarms'))
362                        {
363                                return False;
364                        }
365                        return $this->cal->read_alarms($cal_id);
366                }
367
368                function find_recur_exceptions($event_id)
369                {
370                        if($GLOBALS['phpgw_info']['server']['calendar_type'] == 'sql')
371                        {
372                                $arr = Array();
373                                $this->cal->query('SELECT datetime FROM phpgw_cal WHERE reference='.$event_id,__LINE__,__FILE__);
374                                if($this->cal->num_rows())
375                                {
376                                        while($this->cal->next_record())
377                                        {
378                                                $arr[] = (int)$this->cal->f('datetime');
379                                        }
380                                }
381                                if(count($arr) == 0)
382                                {
383                                        return False;
384                                }
385                                else
386                                {
387                                        return $arr;
388                                }
389                        }
390                        else
391                        {
392                                return False;
393                        }
394                }
395
396                /* Begin mcal equiv functions */
397                function get_cached_event()
398                {
399                        return $this->cal->event;
400                }
401               
402                function add_attribute($var,$value,$element='**(**')
403                {
404                        $this->cal->add_attribute($var,$value,$element);
405                }
406
407                function event_init()
408                {
409                        $this->cal->event_init();
410                }
411
412                function set_date($element,$year,$month,$day=0,$hour=0,$min=0,$sec=0)
413                {
414                        $this->cal->set_date($element,$year,$month,$day,$hour,$min,$sec);
415                }
416
417                function set_start($year,$month,$day=0,$hour=0,$min=0,$sec=0)
418                {
419                        $this->cal->set_start($year,$month,$day,$hour,$min,$sec);
420                }
421
422                function set_end($year,$month,$day=0,$hour=0,$min=0,$sec=0)
423                {
424                        $this->cal->set_end($year,$month,$day,$hour,$min,$sec);
425                }
426
427                function set_title($title='')
428                {
429                        $this->cal->set_title($title);
430                }
431
432                function set_description($description='')
433                {
434                        $this->cal->set_description($description);
435                }
436                function set_ex_participants($ex_participants='')
437                {
438                        $this->cal->set_ex_participants($ex_participants);
439                }
440
441                function set_class($class)
442                {
443                        $this->cal->set_class($class);
444                }
445
446                function set_category($category='')
447                {
448                        $this->cal->set_category($category);
449                }
450
451                function set_alarm($alarm)
452                {
453                        $this->cal->set_alarm($alarm);
454                }
455
456                function set_recur_none()
457                {
458                        $this->cal->set_recur_none();
459                }
460
461                function set_recur_daily($year,$month,$day,$interval)
462                {
463                        $this->cal->set_recur_daily($year,$month,$day,$interval);
464                }
465
466                function set_recur_weekly($year,$month,$day,$interval,$weekdays)
467                {
468                        $this->cal->set_recur_weekly($year,$month,$day,$interval,$weekdays);
469                }
470
471                function set_recur_monthly_mday($year,$month,$day,$interval)
472                {
473                        $this->cal->set_recur_monthly_mday($year,$month,$day,$interval);
474                }
475
476                function set_recur_monthly_wday($year,$month,$day,$interval)
477                {
478                        $this->cal->set_recur_monthly_wday($year,$month,$day,$interval);
479                }
480
481                function set_recur_yearly($year,$month,$day,$interval)
482                {
483                        $this->cal->set_recur_yearly($year,$month,$day,$interval);
484                }
485               
486                /* End mcal equiv functions */
487        }
488?>
Note: See TracBrowser for help on using the repository browser.