No longer needed.

This commit is contained in:
skeeter 2001-09-04 05:43:17 +00:00
parent e247562fc7
commit be3fcc8a7c
4 changed files with 0 additions and 3112 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,407 +0,0 @@
<?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$ */
include(PHPGW_SERVER_ROOT.'/calendar/setup/setup.inc.php');
if(extension_loaded('mcal') == False)
{
define('MCAL_RECUR_NONE',0);
define('MCAL_RECUR_DAILY',1);
define('MCAL_RECUR_WEEKLY',2);
define('MCAL_RECUR_MONTHLY_MDAY',3);
define('MCAL_RECUR_MONTHLY_WDAY',4);
define('MCAL_RECUR_YEARLY',5);
define('MCAL_M_SUNDAY',1);
define('MCAL_M_MONDAY',2);
define('MCAL_M_TUESDAY',4);
define('MCAL_M_WEDNESDAY',8);
define('MCAL_M_THURSDAY',16);
define('MCAL_M_FRIDAY',32);
define('MCAL_M_SATURDAY',64);
define('MCAL_M_WEEKDAYS',63);
define('MCAL_M_WEEKEND',65);
define('MCAL_M_ALLDAYS',127);
}
define('MSG_DELETED',0);
define('MSG_MODIFIED',1);
define('MSG_ADDED',2);
define('MSG_REJECTED',3);
define('MSG_TENTATIVE',4);
define('MSG_ACCEPTED',5);
define('REJECTED',0);
define('NO_RESPONSE',1);
define('TENTATIVE',2);
define('ACCEPTED',3);
class calendar__
{
var $event;
var $stream;
var $user;
var $users_status;
var $modified;
var $deleted;
var $added;
var $datetime;
function calendar__()
{
$this->datetime = CreateObject('phpgwapi.datetime');
}
function send_update($msg_type,$participants,$old_event=False,$new_event=False)
{
global $phpgw, $phpgw_info;
$phpgw_info['user']['preferences'] = $phpgw->common->create_emailpreferences($phpgw_info['user']['preferences']);
$sender = $phpgw_info['user']['preferences']['email']['address'];
$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));
if($old_event != False)
{
$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;
}
}
$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;
}
$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);
$send = CreateObject('phpgwapi.send');
switch($msg_type)
{
case MSG_DELETED:
$action = 'Deleted';
$event_id = $old_event->id;
$msgtype = '"calendar";';
break;
case MSG_MODIFIED:
$action = 'Modified';
$event_id = $old_event->id;
$msgtype = '"calendar"; Version="'.$phpgw_info['server']['versions']['calendar'].'"; Id="'.$new_event->id.'"';
break;
case MSG_ADDED:
$action = 'Added';
$event_id = $old_event->id;
$msgtype = '"calendar"; Version="'.$phpgw_info['server']['versions']['calendar'].'"; Id="'.$new_event->id.'"';
break;
case MSG_REJECTED:
$action = 'Rejected';
$event_id = $old_event->id;
$msgtype = '"calendar";';
break;
case MSG_TENTATIVE:
$action = 'Tentative';
$event_id = $old_event->id;
$msgtype = '"calendar";';
break;
case MSG_ACCEPTED:
$action = 'Tentative';
$event_id = $old_event->id;
$msgtype = '"calendar";';
break;
}
if($old_event != False)
{
$old_event_datetime = $t_old_start_time - $this->datetime->tz_offset;
}
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) - $this->datetime->tz_offset;
}
while(list($userid,$statusid) = each($participants))
{
if(intval($userid) != $phpgw_info['user']['account_id'])
{
// echo "Msg Type = ".$msg_type."<br>\n";
// echo "userid = ".$userid."<br>\n";
$preferences = CreateObject('phpgwapi.preferences',intval($userid));
$part_prefs = $preferences->read_repository();
if(!isset($part_prefs['calendar']['send_updates']) || !$part_prefs['calendar']['send_updates'])
{
continue;
}
$part_prefs = $phpgw->common->create_emailpreferences($part_prefs,intval($userid));
$to = $part_prefs['email']['address'];
// echo "Email being sent to: ".$to."<br>\n";
$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'];
$new_tz_offset = ((60 * 60) * intval($phpgw_info['user']['preferences']['common']['tz_offset']));
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;
case MSG_REJECTED:
case MSG_TENTATIVE:
case MSG_ACCEPTED:
$action_date = $old_event_date;
$body = 'On '.$phpgw->common->show_date(time() - $new_tz_offset).' '.$phpgw->common->grab_owner_name($phpgw_info['user']['account_id']).' '.$action.' your meeting request for '.$old_event_date;
break;
}
$subject = 'Calendar Event ('.$action.') #'.$event_id.': '.$action_date.' (L)';
$returncode = $send->msg('email',$to,$subject,$body,$msgtype,'','','',$sender);
}
}
unset($send);
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;
}
$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;
}
function prepare_recipients(&$new_event,$old_event)
{
// Find modified and deleted users.....
while(list($old_userid,$old_status) = each($old_event->participants))
{
if(isset($new_event->participants[$old_userid]))
{
// echo "Modifying event for user ".$old_userid."<br>\n";
$this->modified[intval($old_userid)] = $new_status;
}
else
{
// echo "Deleting user ".$old_userid." from the event<br>\n";
$this->deleted[intval($old_userid)] = $old_status;
}
}
// Find new users.....
while(list($new_userid,$new_status) = each($new_event->participants))
{
if(!isset($old_event->participants[$new_userid]))
{
// echo "Adding event for user ".$new_userid."<br>\n";
$this->added[$new_userid] = 'U';
$new_event->participants[$new_userid] = 'U';
}
}
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);
}
}
}
function event_init()
{
$this->event = CreateObject('calendar.calendar_item');
$this->event->start = new calendar_time;
$this->event->end = new calendar_time;
$this->event->mod = new calendar_time;
$this->event->recur_enddate = new calendar_time;
$this->add_attribute('owner',intval($this->user));
}
function set_category($category='')
{
$this->event->category = $category;
}
function set_title($title='')
{
$this->event->title = $title;
}
function set_description($description='')
{
$this->event->description = $description;
}
function set_start($year,$month,$day=0,$hour=0,$min=0,$sec=0)
{
$this->event->start->year = intval($year);
$this->event->start->month = intval($month);
$this->event->start->mday = intval($day);
$this->event->start->hour = intval($hour);
$this->event->start->min = intval($min);
$this->event->start->sec = intval($sec);
$this->event->start->alarm = 0;
}
function set_end($year,$month,$day=0,$hour=0,$min=0,$sec=0)
{
$this->event->end->year = intval($year);
$this->event->end->month = intval($month);
$this->event->end->mday = intval($day);
$this->event->end->hour = intval($hour);
$this->event->end->min = intval($min);
$this->event->end->sec = intval($sec);
$this->event->end->alarm = 0;
}
function set_alarm($alarm)
{
$this->event->alarm = intval($alarm);
}
function set_class($class)
{
$this->event->public = $class;
}
function set_common_recur($year,$month,$day,$interval)
{
$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;
}
function set_recur_none()
{
$this->set_common_recur(0,0,0,0);
$this->event->recur_type = MCAL_RECUR_NONE;
}
function set_recur_daily($year,$month,$day,$interval)
{
$this->set_common_recur(intval($year),intval($month),intval($day),$interval);
$this->event->recur_type = MCAL_RECUR_DAILY;
}
function set_recur_weekly($year,$month,$day,$interval,$weekdays)
{
$this->set_common_recur(intval($year),intval($month),intval($day),$interval);
$this->event->recur_type = MCAL_RECUR_WEEKLY;
$this->event->recur_data = intval($weekdays);
}
function set_recur_monthly_mday($year,$month,$day,$interval)
{
$this->set_common_recur(intval($year),intval($month),intval($day),$interval);
$this->event->recur_type = MCAL_RECUR_MONTHLY_MDAY;
}
function set_recur_monthly_wday($year,$month,$day,$interval)
{
$this->set_common_recur(intval($year),intval($month),intval($day),$interval);
$this->event->recur_type = MCAL_RECUR_MONTHLY_WDAY;
}
function set_recur_yearly($year,$month,$day,$interval)
{
$this->set_common_recur(intval($year),intval($month),intval($day),$interval);
$this->event->recur_type = MCAL_RECUR_YEARLY;
}
function fetch_current_stream_event()
{
return $this->fetch_event($this->event->id);
}
function add_attribute($attribute,$value,$element='')
{
if(is_array($value))
{
reset($value);
}
eval("\$this->event->".$attribute." = ".$value.";");
}
}

View File

@ -1,61 +0,0 @@
<?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$ */
class calendar_time
{
var $year;
var $month;
var $mday;
var $hour;
var $min;
var $sec;
var $alarm = 0;
}
class calendar_item
{
//New ICal Support
var $id = 0;
var $category = 0;
var $title = "Unnamed Event";
var $description = "Unnamed Event";
var $public = 1;
var $alarm = 0;
var $start;
var $end;
var $mod;
var $recur_type = 0;
var $recur_interval = 0;
var $recur_enddate;
var $recur_data = 0;
var $users_status = 'U';
var $owner;
var $datetime = 0;
var $mdatetime = 0;
var $edatetime = 0;
var $priority = 0;
var $groups = array();
var $participants = array();
var $status = array();
function set($var,$val="")
{
$this->$var = $val;
}
}
?>

View File

@ -1,596 +0,0 @@
<?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$ */
if (@$phpgw_info['flags']['included_classes']['calendar_'])
{
return;
}
$phpgw_info['flags']['included_classes']['calendar_'] = True;
class calendar_ extends calendar__
{
var $deleted_events = Array();
var $cal_event;
var $today = Array('raw','day','month','year','full','dow','dm','bd');
function open($calendar='',$user='',$passwd='',$options='')
{
global $phpgw, $phpgw_info;
if($user=='')
{
settype($user,'integer');
$user = $phpgw_info['user']['account_id'];
}
elseif(is_int($user))
{
$this->user = $user;
}
elseif(is_string($user))
{
$this->user = $phpgw->accounts->name2id($user);
}
$this->stream = $phpgw->db;
return $this->stream;
}
function popen($calendar='',$user='',$passwd='',$options='')
{
return $this->open($calendar,$user,$passwd,$options);
}
function reopen($calendar,$options='')
{
return $this->stream;
}
function close($options='')
{
return True;
}
function create_calendar($calendar='')
{
return $calendar;
}
function rename_calendar($old_name='',$new_name='')
{
return $new_name;
}
function delete_calendar($calendar='')
{
$this->stream->query('SELECT cal_id FROM phpgw_cal WHERE owner='.intval($calendar),__LINE__,__FILE__);
if($this->stream->num_rows())
{
while($this->stream->next_record())
{
$this->delete_event(intval($this->stream->f('cal_id')));
}
$this->expunge();
}
$this->stream->lock(array('phpgw_cal_user'));
$this->stream->query('DELETE FROM phpgw_cal_user WHERE cal_login='.intval($calendar),__LINE__,__FILE__);
$this->stream->unlock();
return $calendar;
}
function fetch_event($event_id,$options='')
{
global $phpgw;
if(!isset($this->stream))
{
return False;
}
$this->stream->lock(array('phpgw_cal','phpgw_cal_user','phpgw_cal_repeats'));
$this->stream->query('SELECT * FROM phpgw_cal WHERE cal_id='.$event_id,__LINE__,__FILE__);
if($this->stream->num_rows() > 0)
{
$this->event_init();
$this->stream->next_record();
// Load the calendar event data from the db into $event structure
// Use http://www.php.net/manual/en/function.mcal-fetch-event.php as the reference
$this->add_attribute('owner',intval($this->stream->f('owner')));
$this->add_attribute('id',intval($this->stream->f('cal_id')));
$this->set_class(intval($this->stream->f('is_public')));
$this->set_category(intval($this->stream->f('category')));
$this->set_title($phpgw->strip_html($this->stream->f('title')));
$this->set_description($phpgw->strip_html($this->stream->f('description')));
// This is the preferred method once everything is normalized...
//$this->event->alarm = intval($this->stream->f('alarm'));
// But until then, do it this way...
//Legacy Support (New)
$this->event->alarm = 0;
$this->add_attribute('datetime',intval($this->stream->f('datetime')));
$datetime = $this->datetime->localdates($this->stream->f('datetime'));
$this->set_start($datetime['year'],$datetime['month'],$datetime['day'],$datetime['hour'],$datetime['minute'],$datetime['second']);
$datetime = $this->datetime->localdates($this->stream->f('mdatetime'));
$this->event->mod->year = $datetime['year'];
$this->event->mod->month = $datetime['month'];
$this->event->mod->mday = $datetime['day'];
$this->event->mod->hour = $datetime['hour'];
$this->event->mod->min = $datetime['minute'];
$this->event->mod->sec = $datetime['second'];
$this->event->mod->alarm = 0;
$this->add_attribute('edatetime',intval($this->stream->f('edatetime')));
$datetime = $this->datetime->localdates($this->stream->f('edatetime'));
$this->set_end($datetime['year'],$datetime['month'],$datetime['day'],$datetime['hour'],$datetime['minute'],$datetime['second']);
//Legacy Support
$this->add_attribute('priority',intval($this->stream->f('priority')));
if($this->stream->f('cal_group') || $this->stream->f('groups') != 'NULL')
{
$groups = explode(',',$this->stream->f('groups'));
for($j=1;$j<count($groups) - 1;$j++)
{
$this->event->groups[] = $groups[$j];
}
}
$this->stream->query('SELECT * FROM phpgw_cal_repeats WHERE cal_id='.$event_id,__LINE__,__FILE__);
if($this->stream->num_rows())
{
$this->stream->next_record();
$this->event->recur_type = intval($this->stream->f('recur_type'));
$this->event->recur_interval = intval($this->stream->f('recur_interval'));
$enddate = $this->stream->f('recur_enddate');
if($enddate != 0 && $enddate != Null)
{
$datetime = $this->datetime->localdates($enddate);
$this->event->recur_enddate->year = $datetime['year'];
$this->event->recur_enddate->month = $datetime['month'];
$this->event->recur_enddate->mday = $datetime['day'];
$this->event->recur_enddate->hour = $datetime['hour'];
$this->event->recur_enddate->min = $datetime['minute'];
$this->event->recur_enddate->sec = $datetime['second'];
$this->event->recur_enddate->alarm = 0;
}
else
{
$this->event->recur_enddate->year = 0;
$this->event->recur_enddate->month = 0;
$this->event->recur_enddate->mday = 0;
$this->event->recur_enddate->hour = 0;
$this->event->recur_enddate->min = 0;
$this->event->recur_enddate->sec = 0;
$this->event->recur_enddate->alarm = 0;
}
// echo 'Event ID#'.$this->event->id.' : Enddate = '.$enddate."<br>\n";
$this->event->recur_data = $this->stream->f('recur_data');
}
//Legacy Support
$this->stream->query('SELECT * FROM phpgw_cal_user WHERE cal_id='.$event_id,__LINE__,__FILE__);
if($this->stream->num_rows())
{
while($this->stream->next_record())
{
if(intval($this->stream->f('cal_login')) == intval($this->user))
{
$this->event->users_status = $this->stream->f('cal_status');
}
// $this->event->participants[$this->stream->f('cal_login')] = $this->stream->f('cal_status');
// $this->add_attribute('participants',$this->stream->f('cal_status'),intval($this->stream->f('cal_login')));
$this->add_attribute('participants['.intval($this->stream->f('cal_login')).']',$this->stream->f('cal_status'));
}
}
}
else
{
$this->event = False;
}
$this->stream->unlock();
return $this->event;
}
function list_events($startYear,$startMonth,$startDay,$endYear='',$endMonth='',$endYear='')
{
if(!isset($this->stream))
{
return False;
}
$datetime = $this->datetime->makegmttime(0,0,0,$startMonth,$startDay,$startYear);
$startDate = ' AND (phpgw_cal.datetime >= '.$datetime.') ';
if($endYear != '' && $endMonth != '' && $endDay != '')
{
$edatetime = $this->datetime->makegmttime(23,59,59,intval($endMonth),intval($endDay),intval($endYear));
$endDate = 'AND (phpgw_cal.edatetime <= '.$edatetime.') ';
}
else
{
$endDate = '';
}
return $this->get_event_ids(False,$startDate.$endDate);
}
function append_event()
{
$this->save_event($this->event);
$this->send_update(MSG_ADDED,$this->event->participants,'',$this->event);
return $this->event->id;
}
function store_event()
{
if($this->event->id != 0)
{
$new_event = $this->event;
$old_event = $this->fetch_event($new_event->id);
$this->prepare_recipients($new_event,$old_event);
$this->event = $new_event;
}
else
{
while(list($key,$value) = each($this->event->participants))
{
$this->add_attribute('participants['.intval($key).']','U');
}
$this->send_update(MSG_ADDED,$this->event->participants,'',$this->event);
}
return $this->save_event($this->event);
}
function delete_event($event_id)
{
$this->deleted_events[] = $event_id;
}
function snooze($event_id)
{
//Turn off an alarm for an event
//Returns true.
}
function list_alarms($begin_year='',$begin_month='',$begin_day='',$end_year='',$end_month='',$end_day='')
{
//Return a list of events that has an alarm triggered at the given datetime
//Returns an array of event ID's
}
// The function definition doesn't look correct...
// Need more information for this function
function next_recurrence($weekstart,$next)
{
// return next_recurrence (int stream, int weekstart, array next);
}
function expunge()
{
if(count($this->deleted_events) <= 0)
{
return 1;
}
$this_event = $this->event;
$locks = Array(
'phpgw_cal',
'phpgw_cal_user',
'phpgw_cal_repeats'
);
$this->stream->lock($locks);
for($i=0;$i<count($this->deleted_events);$i++)
{
$event_id = $this->deleted_events[$i];
$event = $this->fetch_event($event_id);
$this->send_update(MSG_DELETED,$event->participants,$event);
for($k=0;$k<count($locks);$k++)
{
$this->stream->query('DELETE FROM '.$locks[$k].' WHERE cal_id='.$event_id,__LINE__,__FILE__);
}
}
$this->stream->unlock();
$this->event = $this_event;
return 1;
}
/***************** Local functions for SQL based Calendar *****************/
function get_event_ids($search_repeats=False,$extra='')
{
if($search_repeats == True)
{
$repeats_from = ', phpgw_cal_repeats ';
$repeats_where = 'AND (phpgw_cal_repeats.cal_id = phpgw_cal.cal_id) ';
}
else
{
$repeats_from = ' ';
$repeats_where = '';
}
$sql = 'SELECT DISTINCT phpgw_cal.cal_id,'
. 'phpgw_cal.datetime,phpgw_cal.edatetime,'
. 'phpgw_cal.priority '
. 'FROM phpgw_cal, phpgw_cal_user'
. $repeats_from
. 'WHERE (phpgw_cal_user.cal_id = phpgw_cal.cal_id) '
. $repeats_where . $extra;
$this->stream->query($sql,__LINE__,__FILE__);
if($this->stream->num_rows() == 0)
{
return False;
}
$retval = Array();
while($this->stream->next_record())
{
$retval[] = intval($this->stream->f('cal_id'));
}
return $retval;
}
function save_event(&$event)
{
global $phpgw_info;
$locks = Array(
'phpgw_cal',
'phpgw_cal_user',
'phpgw_cal_repeats'
);
$this->stream->lock($locks);
if($event->id == 0)
{
$temp_name = tempnam($phpgw_info['server']['temp_dir'],'cal');
$this->stream->query('INSERT INTO phpgw_cal(title,owner,priority,is_public) '
. "values('".$temp_name."',".$event->owner.",".$event->priority.",".$event->public.")");
$this->stream->query("SELECT cal_id FROM phpgw_cal WHERE title='".$temp_name."'");
$this->stream->next_record();
$event->id = $this->stream->f('cal_id');
}
$date = mktime($event->start->hour,$event->start->min,$event->start->sec,$event->start->month,$event->start->mday,$event->start->year) - $this->datetime->tz_offset;
$enddate = mktime($event->end->hour,$event->end->min,$event->end->sec,$event->end->month,$event->end->mday,$event->end->year) - $this->datetime->tz_offset;
$today = time() - $this->datetime->tz_offset;
// $today = time();
if($event->recur_type != MCAL_RECUR_NONE)
{
$type = 'M';
}
else
{
$type = 'E';
}
$cat = '';
if($event->category != 0)
{
$cat = 'category='.$event->category.', ';
}
$sql = 'UPDATE phpgw_cal SET '
. 'owner='.$event->owner.', '
. 'datetime='.$date.', '
. 'mdatetime='.$today.', '
. 'edatetime='.$enddate.', '
. 'priority='.$event->priority.', '
. $cat
. "cal_type='".$type."', "
. 'is_public='.$event->public.', '
. "title='".addslashes($event->title)."', "
. "description='".addslashes($event->description)."' "
. 'WHERE cal_id='.$event->id;
$this->stream->query($sql,__LINE__,__FILE__);
$this->stream->query('DELETE FROM phpgw_cal_user WHERE cal_id='.$event->id,__LINE__,__FILE__);
reset($event->participants);
while (list($key,$value) = each($event->participants))
{
if(intval($key) == intval($this->user))
{
$value = 'A';
}
$this->stream->query('INSERT INTO phpgw_cal_user(cal_id,cal_login,cal_status) '
. 'VALUES('.$event->id.','.intval($key).",'".$value."')",__LINE__,__FILE__);
}
if($event->recur_type != MCAL_RECUR_NONE)
{
if($event->recur_enddate->month != 0 && $event->recur_enddate->mday != 0 && $event->recur_enddate->year != 0)
{
$end = mktime($event->recur_enddate->hour,$event->recur_enddate->min,$event->recur_enddate->sec,$event->recur_enddate->month,$event->recur_enddate->mday,$event->recur_enddate->year) - $this->datetime->tz_offset;
}
else
{
$end = 0;
}
$this->stream->query('SELECT count(cal_id) FROM phpgw_cal_repeats WHERE cal_id='.$event->id,__LINE__,__FILE__);
$this->stream->next_record();
$num_rows = $this->stream->f(0);
if($num_rows == 0)
{
$this->stream->query('INSERT INTO phpgw_cal_repeats(cal_id,recur_type,recur_enddate,recur_data,recur_interval) '
.'VALUES('.$event->id.','.$event->recur_type.','.$end.','.$event->recur_data.','.$event->recur_interval.')',__LINE__,__FILE__);
}
else
{
$this->stream->query('UPDATE phpgw_cal_repeats '
.'SET recur_type='.$event->recur_type.', '
.'recur_enddate='.$end.', '
.'recur_data='.$event->recur_data.', recur_interval='.$event->recur_interval.' '
.'WHERE cal_id='.$event->id,__LINE__,__FILE__);
}
}
else
{
$this->stream->query('DELETE FROM phpgw_cal_repeats WHERE cal_id='.$event->id,__LINE__,__FILE__);
}
$this->stream->unlock();
return True;
}
function set_status($id,$owner,$status)
{
$status_code_short = Array(
REJECTED => 'R',
NO_RESPONSE => 'U',
TENTATIVE => 'T',
ACCEPTED => 'A'
);
$temp_event = $this->event;
$old_event = $this->fetch_event($id);
switch($status)
{
case REJECTED:
$this->send_update(MSG_REJECTED,$old_event->participants,$old_event);
$this->stream->query("DELETE FROM phpgw_cal_user WHERE cal_id=".$id." AND cal_login=".$owner,__LINE__,__FILE__);
break;
case TENTATIVE:
$this->send_update(MSG_TENTATIVE,$old_event->participants,$old_event);
$this->stream->query("UPDATE phpgw_cal_user SET cal_status='".$status_code_short[$status]."' WHERE cal_id=".$id." AND cal_login=".$owner,__LINE__,__FILE__);
break;
case ACCEPTED:
$this->send_update(MSG_ACCEPTED,$old_event->participants,$old_event);
$this->stream->query("UPDATE phpgw_cal_user SET cal_status='".$status_code_short[$status]."' WHERE cal_id=".$id." AND cal_login=".$owner,__LINE__,__FILE__);
break;
}
$this->event = $temp_event;
return True;
}
// End of ICal style support.......
function group_search($owner=0)
{
global $phpgw, $phpgw_info;
$owner = $owner==$phpgw_info['user']['account_id']?0:$owner;
$groups = substr($phpgw->common->sql_search('phpgw_cal.groups',intval($owner)),4);
if (!$groups)
{
return '';
}
else
{
return "(phpgw_cal.is_public=2 AND (". $groups .')) ';
}
}
function normalizeminutes(&$minutes)
{
$hour = 0;
$min = intval($minutes);
if($min >= 60)
{
$hour += $min / 60;
$min %= 60;
}
settype($minutes,'integer');
$minutes = $min;
return $hour;
}
function splittime_($time)
{
global $phpgw_info;
$temp = array('hour','minute','second','ampm');
$time = strrev($time);
$second = (int)strrev(substr($time,0,2));
$minute = (int)strrev(substr($time,2,2));
$hour = (int)strrev(substr($time,4));
$temp['second'] = (int)$second;
$temp['minute'] = (int)$minute;
$temp['hour'] = (int)$hour;
$temp['ampm'] = ' ';
return $temp;
}
function splittime($time,$follow_24_rule=True)
{
global $phpgw_info;
$temp = array('hour','minute','second','ampm');
$time = strrev($time);
$second = intval(strrev(substr($time,0,2)));
$minute = intval(strrev(substr($time,2,2)));
$hour = intval(strrev(substr($time,4)));
$hour += $this->normalizeminutes(&$minute);
$temp['second'] = $second;
$temp['minute'] = $minute;
$temp['hour'] = $hour;
$temp['ampm'] = ' ';
if($follow_24_rule == True)
{
if ($phpgw_info['user']['preferences']['common']['timeformat'] == '24')
{
return $temp;
}
$temp['ampm'] = 'am';
if ((int)$temp['hour'] > 12)
{
$temp['hour'] = (int)((int)$temp['hour'] - 12);
$temp['ampm'] = 'pm';
}
elseif ((int)$temp['hour'] == 12)
{
$temp['ampm'] = 'pm';
}
}
return $temp;
}
function date_to_epoch($d)
{
return $this->localdates(mktime(0,0,0,intval(substr($d,4,2)),intval(substr($d,6,2)),intval(substr($d,0,4))));
}
function build_time_for_display($fixed_time)
{
global $phpgw_info;
$time = $this->splittime($fixed_time);
$str = '';
$str .= $time['hour'].':'.((int)$time['minute']<=9?'0':'').$time['minute'];
if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12')
{
$str .= ' ' . $time['ampm'];
}
return $str;
}
}
?>