source: contrib/Resources/inc/class.soresources.inc.php @ 4362

Revision 4362, 13.5 KB checked in by afernandes, 13 years ago (diff)

Ticket #1416 - Disponibilizado módulo de recursos para a comunidade

  • Property svn:executable set to *
Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare - infolog                                                    *
4  * http://www.eGroupWare.org                                                *
5  * Maintained and further developed by RalfBecker@outdoor-training.de       *
6  * Based on Webinfolog 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 soinfolog
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 soinfolog($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('infolog.soinfolog_');
52                        $this->cal = CreateObject('calendar.socalendar_');
53                        //$this->open_box($this->owner);
54                }
55               
56                // It returns uidNumber and cn ( Retorna o uidNumber e o cn )
57                function search_uidNumber($mail)
58                {
59                        $connection = $GLOBALS['phpgw']->common->ldapConnect();
60                        $justthese = array("uidNumber","cn","mail");
61                        $search = ldap_search($connection, $GLOBALS['phpgw_info']['server']['ldap_context'], "mail=" . $mail, $justthese);
62                        $result = ldap_get_entries($connection, $search);
63                        ldap_close($connection);
64                        return $result;
65                }
66
67               
68
69                function maketime($time)
70                {
71                        return mktime($time['hour'],$time['min'],$time['sec'],$time['month'],$time['mday'],$time['year']);
72                }
73
74                function read_entry($id)
75                {
76                        return $this->cal->get_event_ids($id);
77                }
78
79        function read_entry2($id)
80                {
81                        return $this->cal->fetch_event($id);
82                }
83               
84                function list_events($startYear,$startMonth,$startDay,$endYear=0,$endMonth=0,$endDay=0,$owner_id=0)
85                {
86                        $extra = '';
87                        $extra .= (strpos($this->filter,'private')?'AND phpgw_cal.is_public=0 ':'');
88                        //$extra .= ($this->cat_id?"AND phpgw_cal.category like '%".$this->cat_id."%' ":'');
89                        if ($this->cat_id)
90                        {
91                                if (!is_object($GLOBALS['phpgw']->categories))
92                                {
93                                        $GLOBALS['phpgw']->categories = CreateObject('phpgwapi.categories');
94                                }
95                                $cats = $GLOBALS['phpgw']->categories->return_all_children($this->cat_id);
96                                $extra .= "AND (phpgw_cal.category".(count($cats) > 1 ? " IN ('".implode("','",$cats)."')" : '=\''.(int)$this->cat_id."'");
97                                foreach($cats as $cat)
98                                {
99                                        $extra .= " OR phpgw_cal.category LIKE '$cat,%' OR phpgw_cal.category LIKE '%,$cat,%' OR phpgw_cal.category LIKE '%,$cat'";
100                                }
101                                $extra .= ') ';
102                        }
103                        if($owner_id)
104                        {
105                                return $this->cal->list_events($startYear,$startMonth,$startDay,$endYear,$endMonth,$endDay,$extra,$GLOBALS['phpgw']->datetime->tz_offset,$owner_id);
106                        }
107                        else
108                        {
109                                return $this->cal->list_events($startYear,$startMonth,$startDay,$endYear,$endMonth,$endDay,$extra,$GLOBALS['phpgw']->datetime->tz_offset);
110                        }
111                }
112
113                function list_repeated_events($syear,$smonth,$sday,$eyear,$emonth,$eday,$owner_id=0)
114                {
115                        if(!$owner_id)
116                        {
117                                $owner_id = $this->is_group ? $this->g_owner : $this->owner;
118                        }
119                        if($GLOBALS['phpgw_info']['server']['infolog_type'] != 'sql' ||
120                                !count($owner_id))      // happens with empty groups
121                        {
122                                return Array();
123                        }
124
125                        $starttime = mktime(0,0,0,$smonth,$sday,$syear) - $GLOBALS['phpgw']->datetime->tz_offset;
126                        $endtime = mktime(23,59,59,$emonth,$eday,$eyear) - $GLOBALS['phpgw']->datetime->tz_offset;
127                        $sql = "AND phpgw_cal.cal_type='M' AND phpgw_cal_user.cal_login IN (".
128                                (is_array($owner_id) ? implode(',',$owner_id) : $owner_id).')';
129
130//                      $member_groups = $GLOBALS['phpgw']->accounts->membership($this->user);
131//                      @reset($member_groups);
132//                      while(list($key,$group_info) = each($member_groups))
133//                      {
134//                              $member[] = $group_info['account_id'];
135//                      }
136//                      @reset($member);
137//                      $sql .= ','.implode(',',$member).') ';
138//                      $sql .= 'AND (phpgw_cal.datetime <= '.$starttime.') ';
139//                      $sql .= 'AND (((phpgw_cal_repeats.recur_enddate >= '.$starttime.') AND (phpgw_cal_repeats.recur_enddate <= '.$endtime.')) OR (phpgw_cal_repeats.recur_enddate=0))) '
140                        $sql .= ' AND (phpgw_cal_repeats.recur_enddate >= '.$starttime.' OR phpgw_cal_repeats.recur_enddate=0) '
141                                . (strpos($this->filter,'private')?'AND phpgw_cal.is_public=0 ':'')
142                                . ($this->cat_id?"AND phpgw_cal.category like '%".$this->cat_id."%' ":'')
143                                . 'ORDER BY phpgw_cal.datetime ASC, phpgw_cal.edatetime ASC, phpgw_cal.priority ASC';
144
145                        if($this->debug)
146                        {
147                                echo '<!-- SO list_repeated_events : SQL : '.$sql.' -->'."\n";
148                        }
149
150                        return $this->get_event_ids(True,$sql);
151                }
152
153                function list_events_keyword($keywords,$members='')
154                {
155                        if (!$members)
156                        {
157                                $members[] = $this->owner;
158                        }
159                        $sql = 'AND (phpgw_cal_user.cal_login IN ('.implode(',',$members).')) AND '.
160                                '(phpgw_cal_user.cal_login=' . (int)$this->owner . ' OR phpgw_cal.is_public=1) AND (';
161
162                        $words = split(' ',$keywords);
163                        foreach($words as $i => $word)
164                        {
165                                $sql .= $i > 0 ? ' OR ' : '';
166                                $sql .= "(UPPER(phpgw_cal.title) LIKE UPPER('%".addslashes($word)."%') OR "
167                                                . "UPPER(phpgw_cal.description) LIKE UPPER('%".addslashes($word)."%') OR "
168                                                . "UPPER(phpgw_cal.location) LIKE UPPER('%".addslashes($word)."%') OR "
169                                                . "UPPER(phpgw_cal_extra.cal_extra_value) LIKE UPPER('%".addslashes($word)."%'))";
170                        }
171                        $sql .= ') ';
172
173                        $sql .= (strpos($this->filter,'private')?'AND phpgw_cal.is_public=0 ':'');
174                        $sql .= ($this->cat_id? "AND (phpgw_cal.category='$this->cat_id' OR phpgw_cal.category like '%,".$this->cat_id.",%') ":'');
175                        $sql .= 'ORDER BY phpgw_cal.datetime DESC, phpgw_cal.edatetime DESC, phpgw_cal.priority ASC';
176
177                        return $this->get_event_ids(False,$sql,True);
178                }
179
180                function read_from_store($startYear,$startMonth,$startDay,$endYear='',$endMonth='',$endDay='')
181                {
182                        $events = $this->list_events($startYear,$startMonth,$startDay,$endYear,$endMonth,$endDay);
183                        $events_cached = Array();
184                        for($i=0;$i<count($events);$i++)
185                        {
186                                $events_cached[] = $this->read_entry($events[$i]);
187                        }
188                        return $events_cached;
189                }
190
191                function get_event_ids($search_repeats=False, $sql='',$search_extra=False)
192                {
193                        return $this->cal->get_event_ids($search_repeats,$sql,$search_extra);
194                }
195
196                function find_uid($uid)
197                {
198                        $sql = " AND (phpgw_cal.uid = '".$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                function add_entry(&$event)
216                {
217                        return $this->cal->save_event($event);
218                }
219
220                function save_alarm($cal_id,$alarm,$id=0)
221                {
222                        return $this->cal->save_alarm($cal_id,$alarm,$id);
223                }
224
225                function delete_alarm($id)
226                {
227                        return $this->cal->delete_alarm($id);
228                }
229
230                function delete_alarms($cal_id)
231                {
232                        return $this->cal->delete_alarms($cal_id);
233                }
234
235                function delete_entry($id)
236                {
237                        return $this->cal->delete_event($id);
238                }
239
240                function expunge()
241                {
242                        $this->cal->expunge();
243                }
244
245                function delete_infolog($owner)
246                {
247                        $this->cal->delete_infolog($owner);
248                }
249
250                function change_owner($account_id,$new_owner)
251                {
252                        if($GLOBALS['phpgw_info']['server']['infolog_type'] == 'sql')
253                        {
254                                $db2 = $this->cal->stream;
255                                $this->cal->stream->query('SELECT cal_id FROM phpgw_cal_user WHERE cal_login='.$account_id,__LINE__,__FILE__);
256                                while($this->cal->stream->next_record())
257                                {
258                                        $id = $this->cal->stream->f('cal_id');
259                                        $db2->query('SELECT count(*) FROM phpgw_cal_user WHERE cal_id='.$id.' AND cal_login='.$new_owner,__LINE__,__FILE__);
260                                        $db2->next_record();
261                                        if($db2->f(0) == 0)
262                                        {
263                                                $db2->query('UPDATE phpgw_cal_user SET cal_login='.$new_owner.' WHERE cal_id='.$id.' AND cal_login='.$account_id,__LINE__,__FILE__);
264                                        }
265                                        else
266                                        {
267                                                $db2->query('DELETE FROM phpgw_cal_user WHERE cal_id='.$id.' AND cal_login='.$account_id,__LINE__,__FILE__);
268                                        }
269                                }
270                                $this->cal->stream->query('UPDATE phpgw_cal SET owner='.$new_owner.' WHERE owner='.$account_id,__LINE__,__FILE__);
271                        }
272                }
273
274                function set_status($id,$status)
275                {
276                        $this->cal->set_status($id,$this->owner,$status);
277                }
278
279                function get_alarm($cal_id)
280                {
281                        if (!method_exists($this->cal,'get_alarm'))
282                        {
283                                return False;
284                        }
285                        return $this->cal->get_alarm($cal_id);
286                }
287
288                function read_alarm($id)
289                {
290                        if (!method_exists($this->cal,'read_alarm'))
291                        {
292                                return False;
293                        }
294                        return $this->cal->read_alarm($id);
295                }
296
297                function read_alarms($cal_id)
298                {
299                        if (!method_exists($this->cal,'read_alarms'))
300                        {
301                                return False;
302                        }
303                        return $this->cal->read_alarms($cal_id);
304                }
305
306                function find_recur_exceptions($event_id)
307                {
308                        if($GLOBALS['phpgw_info']['server']['infolog_type'] == 'sql')
309                        {
310                                $arr = Array();
311                                $this->cal->query('SELECT datetime FROM phpgw_cal WHERE reference='.$event_id,__LINE__,__FILE__);
312                                if($this->cal->num_rows())
313                                {
314                                        while($this->cal->next_record())
315                                        {
316                                                $arr[] = (int)$this->cal->f('datetime');
317                                        }
318                                }
319                                if(count($arr) == 0)
320                                {
321                                        return False;
322                                }
323                                else
324                                {
325                                        return $arr;
326                                }
327                        }
328                        else
329                        {
330                                return False;
331                        }
332                }
333
334                /* Begin mcal equiv functions */
335                function get_cached_event()
336                {
337                        return $this->cal->event;
338                }
339               
340                function add_attribute($var,$value,$element='**(**')
341                {
342                        $this->cal->add_attribute($var,$value,$element);
343                }
344
345                function event_init()
346                {
347                        $this->cal->event_init();
348                }
349
350                function set_date($element,$year,$month,$day=0,$hour=0,$min=0,$sec=0)
351                {
352                        $this->cal->set_date($element,$year,$month,$day,$hour,$min,$sec);
353                }
354
355                function set_start($year,$month,$day=0,$hour=0,$min=0,$sec=0)
356                {
357                        $this->cal->set_start($year,$month,$day,$hour,$min,$sec);
358                }
359
360                function set_end($year,$month,$day=0,$hour=0,$min=0,$sec=0)
361                {
362                        $this->cal->set_end($year,$month,$day,$hour,$min,$sec);
363                }
364
365                function set_title($title='')
366                {
367                        $this->cal->set_title($title);
368                }
369function set_access($access='')
370                {
371                        $this->cal->set_access($access);
372                }
373
374                function set_description($description='')
375                {
376                        $this->cal->set_description($description);
377                }
378function set_description1($description1='')
379                {
380                        $this->cal->set_description1($description1);
381                }
382function set_participants1($participants1='')
383                {
384                        $this->cal->set_participants1($participants1);
385                }
386                function set_ex_participants($ex_participants='')
387                {
388                        $this->cal->set_ex_participants($ex_participants);
389                }
390
391                function set_class($class)
392                {
393                        $this->cal->set_class($class);
394                }
395
396                function set_category($category='')
397                {
398                        $this->cal->set_category($category);
399                }
400
401                function set_alarm($alarm)
402                {
403                        $this->cal->set_alarm($alarm);
404                }
405
406                function set_recur_none()
407                {
408                        $this->cal->set_recur_none();
409                }
410
411                function set_recur_daily($year,$month,$day,$interval)
412                {
413                        $this->cal->set_recur_daily($year,$month,$day,$interval);
414                }
415
416                function set_recur_weekly($year,$month,$day,$interval,$weekdays)
417                {
418                        $this->cal->set_recur_weekly($year,$month,$day,$interval,$weekdays);
419                }
420
421                function set_recur_monthly_mday($year,$month,$day,$interval)
422                {
423                        $this->cal->set_recur_monthly_mday($year,$month,$day,$interval);
424                }
425
426                function set_recur_monthly_wday($year,$month,$day,$interval)
427                {
428                        $this->cal->set_recur_monthly_wday($year,$month,$day,$interval);
429                }
430
431                function set_recur_yearly($year,$month,$day,$interval)
432                {
433                        $this->cal->set_recur_yearly($year,$month,$day,$interval);
434                }
435function list_eventsa($startYear,$startMonth,$startDay,$endYear=0,$endMonth=0,$endDay=0,$owner_id=0,$location='n/a')
436                {
437
438                        $extra = '';
439                        $extra .= (strpos($this->filter,'private')?'AND phpgw_cal.is_public=0 ':'');
440                        //$extra .= ($this->cat_id?"AND phpgw_cal.category like '%".$this->cat_id."%' ":'');
441                        if ($this->cat_id)
442                        {
443                                if (!is_object($GLOBALS['phpgw']->categories))
444                                {
445                                        $GLOBALS['phpgw']->categories = CreateObject('phpgwapi.categories');
446                                }
447                                $cats = $GLOBALS['phpgw']->categories->return_all_children($this->cat_id);
448                                $extra .= "AND (phpgw_cal.category".(count($cats) > 1 ? " IN ('".implode("','",$cats)."')" : '=\''.(int)$this->cat_id."'");
449                                foreach($cats as $cat)
450                                {
451                                        $extra .= " OR phpgw_cal.category LIKE '$cat,%' OR phpgw_cal.category LIKE '%,$cat,%' OR phpgw_cal.category LIKE '%,$cat'";
452                                }
453                                $extra .= ') ';
454                        }
455                        if($owner_id)
456                        {
457                                return $this->cal->list_events($startYear,$startMonth,$startDay,$endYear,$endMonth,$endDay,$extra,$GLOBALS['phpgw']->datetime->tz_offset,$owner_id,$location);
458                        }
459                        else
460                        {
461                                return $this->cal->list_events($startYear,$startMonth,$startDay,$endYear,$endMonth,$endDay,$extra,$GLOBALS['phpgw']->datetime->tz_offset);
462                        }
463                }
464               
465                /* End mcal equiv functions */
466        }
467?>
Note: See TracBrowser for help on using the repository browser.