2001-03-09 13:23:12 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare - Calendar *
|
|
|
|
* http://www.phpgroupware.org *
|
|
|
|
* Based on Webcalendar by Craig Knudsen <cknudsen@radix.net> *
|
|
|
|
* http://www.radix.net/~cknudsen *
|
|
|
|
* Modified by Mark Peters <skeeter@phpgroupware.org> *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* 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$ */
|
|
|
|
|
2001-03-19 04:39:12 +01:00
|
|
|
include(PHPGW_SERVER_ROOT.'/calendar/version.inc.php');
|
2001-03-10 19:22:25 +01:00
|
|
|
|
2001-03-09 19:03:00 +01:00
|
|
|
if(extension_loaded('mcal') == False)
|
|
|
|
{
|
|
|
|
define(RECUR_NONE,0);
|
|
|
|
define(RECUR_DAILY,1);
|
|
|
|
define(RECUR_WEEKLY,2);
|
|
|
|
define(RECUR_MONTHLY_MDAY,3);
|
|
|
|
define(RECUR_MONTHLY_WDAY,4);
|
|
|
|
define(RECUR_YEARLY,5);
|
|
|
|
|
|
|
|
define(M_SUNDAY,1);
|
|
|
|
define(M_MONDAY,2);
|
|
|
|
define(M_TUESDAY,4);
|
|
|
|
define(M_WEDNESDAY,8);
|
|
|
|
define(M_THURSDAY,16);
|
|
|
|
define(M_FRIDAY,32);
|
|
|
|
define(M_SATURDAY,64);
|
|
|
|
|
|
|
|
define(M_WEEKDAYS,63);
|
|
|
|
define(M_WEEKEND,65);
|
|
|
|
define(M_ALLDAYS,127);
|
|
|
|
}
|
|
|
|
|
2001-03-12 05:30:15 +01:00
|
|
|
define(MSG_DELETED,0);
|
|
|
|
define(MSG_MODIFIED,1);
|
|
|
|
define(MSG_ADDED,2);
|
2001-03-09 13:23:12 +01:00
|
|
|
|
2001-03-12 05:30:15 +01:00
|
|
|
define(REJECTED,0);
|
|
|
|
define(NO_RESPONSE,1);
|
|
|
|
define(TENTATIVE,2);
|
|
|
|
define(ACCEPTED,3);
|
2001-03-12 04:18:02 +01:00
|
|
|
|
2001-03-09 13:23:12 +01:00
|
|
|
class calendar__
|
|
|
|
{
|
|
|
|
var $event;
|
|
|
|
var $stream;
|
|
|
|
var $user;
|
2001-03-12 05:30:15 +01:00
|
|
|
var $users_status;
|
2001-03-09 13:23:12 +01:00
|
|
|
var $modified;
|
|
|
|
var $deleted;
|
|
|
|
var $added;
|
|
|
|
|
|
|
|
function send_update($msg_type,$participants,$old_event=False,$new_event=False)
|
|
|
|
{
|
|
|
|
global $phpgw, $phpgw_info;
|
|
|
|
|
2001-03-15 06:36:48 +01:00
|
|
|
$phpgw_info['user']['preferences'] = $phpgw->common->create_emailpreferences($phpgw_info['user']['preferences']);
|
|
|
|
$sender = $phpgw_info['user']['preferences']['email']['address'];
|
|
|
|
|
2001-03-09 13:23:12 +01:00
|
|
|
$temp_tz_offset = $phpgw_info['user']['preferences']['common']['tz_offset'];
|
|
|
|
$temp_timeformat = $phpgw_info['user']['preferences']['common']['timeformat'];
|
|
|
|
$temp_dateformat = $phpgw_info['user']['preferences']['common']['dateformat'];
|
|
|
|
|
|
|
|
$tz_offset = ((60 * 60) * intval($temp_tz_offset));
|
2001-03-15 06:36:48 +01:00
|
|
|
|
2001-03-23 04:12:47 +01:00
|
|
|
$t_old_start_time = mktime($old_event->start->hour,$old_event->start->min,$old_event->start->sec,$old_event->start->month,$old_event->start->mday,$old_event->start->year);
|
|
|
|
if($t_old_start_time < (time() - 86400))
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2001-03-15 06:36:48 +01:00
|
|
|
$temp_user = $phpgw_info['user'];
|
|
|
|
|
|
|
|
if((is_int($this->user) && $this->user != $temp_user['account_id']) ||
|
|
|
|
(is_string($this->user) && $this->user != $temp_user['account_lid']))
|
|
|
|
{
|
|
|
|
if(is_string($this->user))
|
|
|
|
{
|
|
|
|
$user = $phpgw->accounts->name2id($this->user);
|
|
|
|
}
|
|
|
|
elseif(is_int($this->user))
|
|
|
|
{
|
|
|
|
$user = $this->user;
|
|
|
|
}
|
2001-03-09 13:23:12 +01:00
|
|
|
|
2001-03-15 06:36:48 +01:00
|
|
|
$accounts = CreateObject('phpgwapi.accounts',$user);
|
|
|
|
$phpgw_info['user'] = $accounts->read_repository();
|
|
|
|
|
|
|
|
$pref = CreateObject('phpgwapi.preferences',$user);
|
|
|
|
$phpgw_info['user']['preferences'] = $pref->read_repository();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$user = $phpgw_info['user']['account_id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$phpgw_info['user']['preferences'] = $phpgw->common->create_emailpreferences($phpgw_info['user']['preferences'],$user);
|
|
|
|
|
2001-03-09 13:23:12 +01:00
|
|
|
$send = CreateObject('phpgwapi.send');
|
|
|
|
|
|
|
|
switch($msg_type)
|
|
|
|
{
|
|
|
|
case MSG_DELETED:
|
2001-03-11 05:17:21 +01:00
|
|
|
$action = 'Deleted';
|
2001-03-09 13:23:12 +01:00
|
|
|
$event_id = $old_event->id;
|
2001-03-10 19:22:25 +01:00
|
|
|
$msgtype = '"calendar";';
|
2001-03-09 13:23:12 +01:00
|
|
|
break;
|
|
|
|
case MSG_MODIFIED:
|
2001-03-11 05:17:21 +01:00
|
|
|
$action = 'Modified';
|
2001-03-09 13:23:12 +01:00
|
|
|
$event_id = $old_event->id;
|
2001-03-10 19:22:25 +01:00
|
|
|
$msgtype = '"calendar"; Version="'.$phpgw_info['server']['versions']['calendar'].'"; Id="'.$new_event->id.'"';
|
2001-03-09 13:23:12 +01:00
|
|
|
break;
|
|
|
|
case MSG_ADDED:
|
2001-03-11 05:17:21 +01:00
|
|
|
$action = 'Added';
|
2001-03-09 13:23:12 +01:00
|
|
|
$event_id = $old_event->id;
|
2001-03-10 19:22:25 +01:00
|
|
|
$msgtype = '"calendar"; Version="'.$phpgw_info['server']['versions']['calendar'].'"; Id="'.$new_event->id.'"';
|
2001-03-09 13:23:12 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($old_event != False)
|
|
|
|
{
|
2001-03-23 04:12:47 +01:00
|
|
|
$old_event_datetime = $t_old_start_time - $tz_offset;
|
2001-03-09 13:23:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if($new_event != False)
|
|
|
|
{
|
|
|
|
$new_event_datetime = mktime($new_event->start->hour,$new_event->start->min,$new_event->start->sec,$new_event->start->month,$new_event->start->mday,$new_event->start->year) - $tz_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
for($i=0;$i<count($participants);$i++)
|
|
|
|
{
|
|
|
|
if($participants[$i] != $phpgw_info['user']['account_id'])
|
|
|
|
{
|
|
|
|
$preferences = CreateObject('phpgwapi.preferences',$participants[$i]);
|
|
|
|
$part_prefs = $preferences->read_repository();
|
|
|
|
if(!isset($part_prefs['calendar']['send_updates']) || $part_prefs['calendar']['send_updates'] == False)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$part_prefs = $phpgw->common->create_emailpreferences($part_prefs,$participants[$i]);
|
|
|
|
$to = $part_prefs['email']['address'];
|
|
|
|
|
|
|
|
$phpgw_info['user']['preferences']['common']['tz_offset'] = $part_prefs['common']['tz_offset'];
|
|
|
|
$phpgw_info['user']['preferences']['common']['timeformat'] = $part_prefs['common']['timeformat'];
|
|
|
|
$phpgw_info['user']['preferences']['common']['dateformat'] = $part_prefs['common']['dateformat'];
|
|
|
|
|
|
|
|
if($old_event != False)
|
|
|
|
{
|
|
|
|
$old_event_date = $phpgw->common->show_date($old_event_datetime);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($new_event != False)
|
|
|
|
{
|
|
|
|
$new_event_date = $phpgw->common->show_date($new_event_datetime);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch($msg_type)
|
|
|
|
{
|
|
|
|
case MSG_DELETED:
|
|
|
|
$action_date = $old_event_date;
|
|
|
|
$body = 'Your meeting scehduled for '.$old_event_date.' has been canceled';
|
|
|
|
break;
|
|
|
|
case MSG_MODIFIED:
|
|
|
|
$action_date = $new_event_date;
|
|
|
|
$body = 'Your meeting that had been scheduled for '.$old_event_date.' has been rescheduled to '.$new_event_date;
|
|
|
|
break;
|
|
|
|
case MSG_ADDED:
|
|
|
|
$action_date = $new_event_date;
|
|
|
|
$body = 'You have a meeting scheduled for '.$new_event_date;
|
|
|
|
break;
|
|
|
|
}
|
2001-03-10 19:22:25 +01:00
|
|
|
$subject = 'Calendar Event ('.$action.') #'.$event_id.': '.$action_date.' (L)';
|
2001-03-15 06:36:48 +01:00
|
|
|
$send->msg('email',$to,$subject,$body,$msgtype,'','','',$sender);
|
2001-03-09 13:23:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($send);
|
|
|
|
|
2001-03-15 06:36:48 +01:00
|
|
|
if((is_int($this->user) && $this->user != $temp_user['account_id']) ||
|
|
|
|
(is_string($this->user) && $this->user != $temp_user['account_lid']))
|
|
|
|
{
|
|
|
|
$phpgw_info['user'] = $temp_user;
|
|
|
|
}
|
|
|
|
|
2001-03-09 13:23:12 +01:00
|
|
|
$phpgw_info['user']['preferences']['common']['tz_offset'] = $temp_tz_offset;
|
|
|
|
$phpgw_info['user']['preferences']['common']['timeformat'] = $temp_timeformat;
|
|
|
|
$phpgw_info['user']['preferences']['common']['dateformat'] = $temp_dateformat;
|
|
|
|
}
|
|
|
|
|
2001-03-12 04:44:43 +01:00
|
|
|
function prepare_recipients(&$new_event,$old_event)
|
2001-03-09 13:23:12 +01:00
|
|
|
{
|
2001-04-19 03:33:52 +02:00
|
|
|
$old_part_count = count($old_event->participants);
|
|
|
|
for($i=0;$i<$old_part_count;$i++)
|
2001-03-09 13:23:12 +01:00
|
|
|
{
|
|
|
|
$delete = True;
|
2001-04-19 03:33:52 +02:00
|
|
|
$new_part_count = count($new_event->participants);
|
2001-04-19 03:44:58 +02:00
|
|
|
for($k=0;$k<$new_part_count;$k++)
|
2001-03-09 13:23:12 +01:00
|
|
|
{
|
|
|
|
if($new_event->participants[$k] == $old_event->participants[$i])
|
|
|
|
{
|
|
|
|
$delete = False;
|
|
|
|
$this->modified[] = $new_event->participants[$k];
|
2001-03-12 04:44:43 +01:00
|
|
|
$new_event->status[$k] = $old_event->status[$i];
|
2001-03-09 13:23:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if($delete == True)
|
|
|
|
{
|
|
|
|
$this->deleted[] = $old_event->participants[$i];
|
|
|
|
}
|
|
|
|
}
|
2001-04-19 03:33:52 +02:00
|
|
|
$new_part_count = count($new_event->participants);
|
|
|
|
for($i=0;$i<$new_part_count;$i++)
|
2001-03-09 13:23:12 +01:00
|
|
|
{
|
|
|
|
$add = True;
|
2001-04-19 03:44:58 +02:00
|
|
|
$old_part_count = count($old_event->participants);
|
|
|
|
for($k=0;$k<$old_part_count;$k++)
|
2001-03-09 13:23:12 +01:00
|
|
|
{
|
|
|
|
if($new_event->participants[$i] == $old_event->participants[$k])
|
|
|
|
{
|
|
|
|
$add = False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($add == True)
|
|
|
|
{
|
|
|
|
$this->added[] = $new_event->participants[$i];
|
2001-03-12 04:44:43 +01:00
|
|
|
$new_event->status[$i] = 'U';
|
2001-03-09 13:23:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(count($this->added) > 0 || count($this->modified) > 0 || count($this->deleted) > 0)
|
|
|
|
{
|
|
|
|
if(count($this->added) > 0)
|
|
|
|
{
|
|
|
|
$this->send_update(MSG_ADDED,$this->added,'',$new_event);
|
|
|
|
}
|
|
|
|
if(count($this->modified) > 0)
|
|
|
|
{
|
|
|
|
$this->send_update(MSG_MODIFIED,$this->modified,$old_event,$new_event);
|
|
|
|
}
|
|
|
|
if(count($this->deleted) > 0)
|
|
|
|
{
|
|
|
|
$this->send_update(MSG_DELETED,$this->deleted,$old_event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-31 16:33:40 +02:00
|
|
|
function set_common_recur($year,$month,$day,$interval)
|
2001-03-09 13:23:12 +01:00
|
|
|
{
|
|
|
|
if(intval($day) == 0 && intval($month) == 0 && intval($year) == 0)
|
|
|
|
{
|
|
|
|
$this->event->rpt_end_use = 0;
|
|
|
|
$this->event->rpt_end = 0;
|
|
|
|
$this->event->rpt_end_day = 0;
|
|
|
|
$this->event->rpt_end_month = 0;
|
|
|
|
$this->event->rpt_end_year = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->event->rpt_end_use = 1;
|
|
|
|
$this->event->rpt_end = mktime(0,0,0,intval($month),intval($day),intval($year));
|
|
|
|
$this->event->rpt_end -= ((60 * 60) * intval($phpgw_info['user']['preferences']['common']['tz_offset']));
|
|
|
|
$this->event->rpt_end_day = intval($day);
|
|
|
|
$this->event->rpt_end_month = intval($month);
|
|
|
|
$this->event->rpt_end_year = intval($year);
|
|
|
|
}
|
|
|
|
$this->event->rpt_sun = 0;
|
|
|
|
$this->event->rpt_mon = 0;
|
|
|
|
$this->event->rpt_tue = 0;
|
|
|
|
$this->event->rpt_wed = 0;
|
|
|
|
$this->event->rpt_thu = 0;
|
|
|
|
$this->event->rpt_fri = 0;
|
|
|
|
$this->event->rpt_sat = 0;
|
|
|
|
$this->event->rpt_days = 'nnnnnnn';
|
|
|
|
$this->event->rpt_freq = intval($interval);
|
|
|
|
|
|
|
|
// Legacy Support (New)
|
|
|
|
$this->event->recur_interval = intval($interval);
|
|
|
|
if(intval($day) == 0 && intval($month) == 0 && intval($year) == 0)
|
|
|
|
{
|
|
|
|
$this->event->recur_enddate->year = 0;
|
|
|
|
$this->event->recur_enddate->month = 0;
|
|
|
|
$this->event->recur_enddate->mday = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->event->recur_enddate->year = intval($year);
|
|
|
|
$this->event->recur_enddate->month = intval($month);
|
|
|
|
$this->event->recur_enddate->mday = intval($day);
|
|
|
|
}
|
|
|
|
$this->event->recur_enddate->hour = 0;
|
|
|
|
$this->event->recur_enddate->min = 0;
|
|
|
|
$this->event->recur_enddate->sec = 0;
|
|
|
|
$this->event->recur_enddate->alarm = 0;
|
|
|
|
$this->event->recur_data = 0;
|
|
|
|
}
|
|
|
|
}
|