source: companies/serpro/calendar/inc/class.boalarm.inc.php @ 903

Revision 903, 5.8 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare - Calendar                                                    *
4  * http://www.egroupware.org                                                *
5  * Based on Webcalendar by Craig Knudsen <cknudsen@radix.net>               *
6  *          http://www.radix.net/~cknudsen                                  *
7  * Modified by Mark Peters <milosch@phpwhere.org>                           *
8  * --------------------------------------------                             *
9  *  This program is free software; you can redistribute it and/or modify it *
10  *  under the terms of the GNU General Public License as published by the   *
11  *  Free Software Foundation; either version 2 of the License, or (at your  *
12  *  option) any later version.                                              *
13  \**************************************************************************/
14
15
16        define('PHPGW_ACL_DELETEALARM',PHPGW_ACL_DELETE);       // for now
17        define('PHPGW_ACL_SETALARM',PHPGW_ACL_WRITE);
18        define('PHPGW_ACL_READALARM',PHPGW_ACL_READ);
19
20        class boalarm
21        {
22                var $so;
23                var $cal;
24                var $cal_id;
25
26                var $tz_offset;
27
28                var $debug = False;
29//              var $debug = True;
30
31                var $public_functions = array(
32                        'add'       => True,
33                        'delete'    => True
34                );
35
36                function boalarm()
37                {
38                        $cal_id = (isset($_POST['cal_id'])?(int)$_POST['cal_id']:'');
39                        if($cal_id)
40                        {
41                                $this->cal_id = $cal_id;
42                        }
43                        $this->bo = CreateObject('calendar.bocalendar',1);
44                        $this->so = CreateObject('calendar.socalendar',1);
45                        $this->tz_offset = $GLOBALS['phpgw']->datetime->tz_offset;
46
47                        if($this->debug)
48                        {
49                                echo "BO Owner : ".$this->bo->owner."<br>\n";
50                        }
51
52                        if($this->bo->use_session)
53                        {
54                                $this->save_sessiondata();
55                        }
56                }
57
58                function save_sessiondata()
59                {
60                        $data = array(
61                                'filter' => $this->bo->filter,
62                                'cat_id' => $this->bo->cat_id,
63                                'owner'  => $this->bo->owner,
64                                'year'   => $this->bo->year,
65                                'month'  => $this->bo->month,
66                                'day'    => $this->bo->day
67                        );
68                        $this->bo->save_sessiondata($data);
69                }
70
71                function read_entry($cal_id)
72                {
73                        return $this->bo->read_entry((int)$cal_id);
74                }
75
76                /*!
77                @function add
78                @abstract adds a new alarm to an event
79                @syntax add(&$event,$time,$login_id)
80                @param &$event event to add the alarm too
81                @param $time for the alarm in sec before the starttime of the event
82                @param $login_id user to alarm
83                @returns the alarm or False
84                */
85                function add(&$event,$time,$owner)
86                {
87                        //echo "<p>boalarm::add(event="; print_r($event); ",time=$time,owner=$owner)</p>\n";
88                        if (!$this->check_perms(PHPGW_ACL_SETALARM,$owner) || !($cal_id = $event['id']))
89                        {
90                                return False;
91                        }
92                        $alarm = Array(
93                                'time'    => ($etime=$this->bo->maketime($event['start'])) - $time,
94                                'offset'  => $time,
95                                'owner'   => $owner,
96                                'enabled' => 1
97                        );
98                        $alarm['id'] = $this->so->save_alarm($cal_id,$alarm);
99                        $event['alarm'][$alarm['id']] = $alarm;
100                        $event['alarm'][$alarm['id']]['time'] = $alarm['time'] + $this->tz_offset;      // allows viewing alarm time in users timezone
101
102                        return $alarm;
103                }
104
105                /*!
106                @function check_perms
107                @abstract checks if user has a certain grant from the owner of an alarm or event
108                @syntax check_perms($grant,$owner)
109                @param $grant PHPGW_ACL_{SET|READ|DELETE}ALARM (defined at the top of this file)
110                */
111                function check_perms($grant,$owner)
112                {
113                        return $this->bo->check_perms($grant,0,$owner);
114                }
115
116                /*!
117                @function participants
118                @abstract get the participants of an event, the user has grants to alarm
119                @syntax participants($event,$fullnames=True)
120                @param $event or cal_id of an event
121                @param $fullnames if true return array with fullnames as values
122                @returns array with account_ids as keys
123                */
124                function participants($event,$fullnames=True)
125                {
126                        if (!is_array($event))
127                        {
128                                $event = $this->read_entry($event);
129                        }
130                        if (!$event)
131                        {
132                                return False;
133                        }
134                        $participants = array();
135                        foreach ($event['participants'] as $uid => $status)
136                        {
137                                if ($this->check_perms(PHPGW_ACL_SETALARM,$uid))
138                                {
139                                        $participants[$uid] = $fullnames ? $GLOBALS['phpgw']->common->grab_owner_name($uid) : True;
140                                }
141                        }
142                        return $participants;
143                }
144
145                /*!
146                @function enable
147                @abstract enable or disable one or more alarms identified by its ids
148                @syntax enable($ids,$enable=True)
149                @param $ids array with alarm ids as keys (!)
150                @returns the number of alarms enabled or -1 for insuficent permission to do so
151                @note Not found alarms or insuficent perms stop the enableing of multiple alarms
152                */
153                function enable($alarms,$enable=True)
154                {
155                        $enabled = 0;
156                        foreach ($alarms as $id => $field)
157                        {
158                                if (!($alarm = $this->so->read_alarm($id)))
159                                {
160                                        return 0;       // alarm not found
161                                }
162                                if (!$alarm['enabled'] == !$enable)
163                                {
164                                        continue;       // nothing to do
165                                }
166                                if ($enable && !$this->check_perms(PHPGW_ACL_SETALARM,$alarm['owner']) ||
167                                        !$enable && !$this->check_perms(PHPGW_ACL_DELETEALARM,$alarm['owner']))
168                                {
169                                        return -1;
170                                }
171                                $alarm['enabled'] = (int)(!$alarm['enabled']);
172                                if ($this->so->save_alarm($alarm['cal_id'],$alarm))
173                                {
174                                        ++$enabled;
175                                }
176                        }
177                        return $enabled;
178                }
179
180                /*!
181                @function delete
182                @abstract delete one or more alarms identified by its ids
183                @syntax delete($ids)
184                @param $ids array with alarm ids as keys (!)
185                @returns the number of alarms deleted or -1 for insuficent permission to do so
186                @note Not found alarms or insuficent perms stop the deleting of multiple alarms
187                */
188                function delete($alarms)
189                {
190                        $deleted = 0;
191                        foreach ($alarms as $id => $field)
192                        {
193                                if (!($alarm = $this->so->read_alarm($id)))
194                                {
195                                        return 0;       // alarm not found
196                                }
197                                if (!$this->check_perms(PHPGW_ACL_DELETEALARM,$alarm['owner']))
198                                {
199                                        return -1;
200                                }
201                                if ($this->so->delete_alarm($id))
202                                {
203                                        ++$deleted;
204                                }
205                        }
206                        return $deleted;
207                }
208        }
209?>
Note: See TracBrowser for help on using the repository browser.