2001-09-07 18:34:49 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2004-01-27 01:31:58 +01:00
|
|
|
* eGroupWare - Calendar *
|
|
|
|
* http://www.egroupware.org *
|
2001-09-07 18:34:49 +02:00
|
|
|
* Based on Webcalendar by Craig Knudsen <cknudsen@radix.net> *
|
|
|
|
* http://www.radix.net/~cknudsen *
|
2004-01-27 01:31:58 +01:00
|
|
|
* Modified by Mark Peters <milosch@phpwhere.org> *
|
2001-09-07 18:34:49 +02:00
|
|
|
* -------------------------------------------- *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
* option) any later version. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
define('PHPGW_ACL_DELETEALARM',PHPGW_ACL_DELETE); // for now
|
|
|
|
define('PHPGW_ACL_SETALARM',PHPGW_ACL_WRITE);
|
|
|
|
define('PHPGW_ACL_READALARM',PHPGW_ACL_READ);
|
|
|
|
|
2001-09-07 18:34:49 +02:00
|
|
|
class boalarm
|
|
|
|
{
|
|
|
|
var $so;
|
|
|
|
var $cal;
|
2001-10-26 01:54:21 +02:00
|
|
|
var $cal_id;
|
2001-09-07 18:34:49 +02:00
|
|
|
|
|
|
|
var $tz_offset;
|
|
|
|
|
|
|
|
var $debug = False;
|
|
|
|
// var $debug = True;
|
|
|
|
|
|
|
|
var $public_functions = array(
|
2003-08-28 16:31:11 +02:00
|
|
|
'add' => True,
|
|
|
|
'delete' => True
|
2001-09-07 18:34:49 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
function boalarm()
|
|
|
|
{
|
2004-01-04 01:47:37 +01:00
|
|
|
$cal_id = (isset($_POST['cal_id'])?(int)$_POST['cal_id']:'');
|
2001-10-26 01:54:21 +02:00
|
|
|
if($cal_id)
|
|
|
|
{
|
|
|
|
$this->cal_id = $cal_id;
|
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->bo = CreateObject('calendar.bocalendar',1);
|
|
|
|
$this->so = CreateObject('calendar.socalendar',1);
|
2003-09-11 14:01:16 +02:00
|
|
|
$this->tz_offset = $GLOBALS['phpgw']->datetime->tz_offset;
|
2001-09-07 18:34:49 +02:00
|
|
|
|
|
|
|
if($this->debug)
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
echo "BO Owner : ".$this->bo->owner."<br>\n";
|
2001-09-07 18:34:49 +02:00
|
|
|
}
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
if($this->bo->use_session)
|
2001-09-07 18:34:49 +02:00
|
|
|
{
|
|
|
|
$this->save_sessiondata();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function save_sessiondata()
|
|
|
|
{
|
|
|
|
$data = array(
|
2003-08-28 16:31:11 +02:00
|
|
|
'filter' => $this->bo->filter,
|
|
|
|
'cat_id' => $this->bo->cat_id,
|
|
|
|
'owner' => $this->bo->owner,
|
|
|
|
'year' => $this->bo->year,
|
|
|
|
'month' => $this->bo->month,
|
|
|
|
'day' => $this->bo->day
|
2001-09-07 18:34:49 +02:00
|
|
|
);
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->bo->save_sessiondata($data);
|
2001-09-07 18:34:49 +02:00
|
|
|
}
|
|
|
|
|
2001-12-28 16:53:33 +01:00
|
|
|
function read_entry($cal_id)
|
|
|
|
{
|
2004-01-04 01:47:37 +01:00
|
|
|
return $this->bo->read_entry((int)$cal_id);
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function add
|
|
|
|
@abstract adds a new alarm to an event
|
|
|
|
@syntax add(&$event,$time,$login_id)
|
|
|
|
@param &$event event to add the alarm too
|
|
|
|
@param $time for the alarm in sec before the starttime of the event
|
|
|
|
@param $login_id user to alarm
|
|
|
|
@returns the alarm or False
|
|
|
|
*/
|
|
|
|
function add(&$event,$time,$owner)
|
|
|
|
{
|
2003-09-14 14:51:31 +02:00
|
|
|
//echo "<p>boalarm::add(event="; print_r($event); ",time=$time,owner=$owner)</p>\n";
|
2003-08-28 16:31:11 +02:00
|
|
|
if (!$this->check_perms(PHPGW_ACL_SETALARM,$owner) || !($cal_id = $event['id']))
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
$alarm = Array(
|
|
|
|
'time' => ($etime=$this->bo->maketime($event['start'])) - $time,
|
|
|
|
'offset' => $time,
|
|
|
|
'owner' => $owner,
|
|
|
|
'enabled' => 1
|
|
|
|
);
|
|
|
|
$alarm['id'] = $this->so->save_alarm($cal_id,$alarm);
|
|
|
|
$event['alarm'][$alarm['id']] = $alarm;
|
2004-05-23 16:51:27 +02:00
|
|
|
$event['alarm'][$alarm['id']]['time'] = $alarm['time'] - $this->tz_offset; // allows viewing alarm time in users timezone
|
2003-08-28 16:31:11 +02:00
|
|
|
|
|
|
|
return $alarm;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function check_perms
|
|
|
|
@abstract checks if user has a certain grant from the owner of an alarm or event
|
|
|
|
@syntax check_perms($grant,$owner)
|
|
|
|
@param $grant PHPGW_ACL_{SET|READ|DELETE}ALARM (defined at the top of this file)
|
|
|
|
*/
|
|
|
|
function check_perms($grant,$owner)
|
|
|
|
{
|
|
|
|
return $this->bo->check_perms($grant,0,$owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function participants
|
|
|
|
@abstract get the participants of an event, the user has grants to alarm
|
|
|
|
@syntax participants($event,$fullnames=True)
|
|
|
|
@param $event or cal_id of an event
|
|
|
|
@param $fullnames if true return array with fullnames as values
|
|
|
|
@returns array with account_ids as keys
|
|
|
|
*/
|
|
|
|
function participants($event,$fullnames=True)
|
|
|
|
{
|
|
|
|
if (!is_array($event))
|
|
|
|
{
|
|
|
|
$event = $this->read_entry($event);
|
|
|
|
}
|
|
|
|
if (!$event)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
$participants = array();
|
|
|
|
foreach ($event['participants'] as $uid => $status)
|
|
|
|
{
|
|
|
|
if ($this->check_perms(PHPGW_ACL_SETALARM,$uid))
|
|
|
|
{
|
|
|
|
$participants[$uid] = $fullnames ? $GLOBALS['phpgw']->common->grab_owner_name($uid) : True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $participants;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function enable
|
|
|
|
@abstract enable or disable one or more alarms identified by its ids
|
|
|
|
@syntax enable($ids,$enable=True)
|
|
|
|
@param $ids array with alarm ids as keys (!)
|
|
|
|
@returns the number of alarms enabled or -1 for insuficent permission to do so
|
|
|
|
@note Not found alarms or insuficent perms stop the enableing of multiple alarms
|
|
|
|
*/
|
|
|
|
function enable($alarms,$enable=True)
|
|
|
|
{
|
|
|
|
$enabled = 0;
|
|
|
|
foreach ($alarms as $id => $field)
|
|
|
|
{
|
|
|
|
if (!($alarm = $this->so->read_alarm($id)))
|
|
|
|
{
|
|
|
|
return 0; // alarm not found
|
|
|
|
}
|
|
|
|
if (!$alarm['enabled'] == !$enable)
|
|
|
|
{
|
|
|
|
continue; // nothing to do
|
|
|
|
}
|
|
|
|
if ($enable && !$this->check_perms(PHPGW_ACL_SETALARM,$alarm['owner']) ||
|
|
|
|
!$enable && !$this->check_perms(PHPGW_ACL_DELETEALARM,$alarm['owner']))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2004-01-04 01:47:37 +01:00
|
|
|
$alarm['enabled'] = (int)(!$alarm['enabled']);
|
2003-08-28 16:31:11 +02:00
|
|
|
if ($this->so->save_alarm($alarm['cal_id'],$alarm))
|
|
|
|
{
|
|
|
|
++$enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function delete
|
|
|
|
@abstract delete one or more alarms identified by its ids
|
|
|
|
@syntax delete($ids)
|
|
|
|
@param $ids array with alarm ids as keys (!)
|
|
|
|
@returns the number of alarms deleted or -1 for insuficent permission to do so
|
|
|
|
@note Not found alarms or insuficent perms stop the deleting of multiple alarms
|
|
|
|
*/
|
|
|
|
function delete($alarms)
|
|
|
|
{
|
|
|
|
$deleted = 0;
|
|
|
|
foreach ($alarms as $id => $field)
|
|
|
|
{
|
|
|
|
if (!($alarm = $this->so->read_alarm($id)))
|
|
|
|
{
|
|
|
|
return 0; // alarm not found
|
|
|
|
}
|
|
|
|
if (!$this->check_perms(PHPGW_ACL_DELETEALARM,$alarm['owner']))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ($this->so->delete_alarm($id))
|
|
|
|
{
|
|
|
|
++$deleted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $deleted;
|
2001-12-28 16:53:33 +01:00
|
|
|
}
|
2001-09-07 18:34:49 +02:00
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
?>
|