source: contrib/Timesheet/inc/class.sotimesheet.inc.php @ 3526

Revision 3526, 12.2 KB checked in by afernandes, 13 years ago (diff)

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