egroupware/calendar/inc/class.calendar_sql.inc.php

1689 lines
48 KiB
PHP
Raw Normal View History

2001-02-11 14:30:09 +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$ */
class calendar_ extends calendar__
2001-02-18 23:33:10 +01:00
{
var $deleted_events = Array();
2001-02-18 23:33:10 +01:00
var $cal_event;
var $today = Array('raw','day','month','year','full','dow','dm','bd');
function open($calendar='',$user='',$passwd='',$options='')
{
global $phpgw, $phpgw_info;
2001-02-11 14:30:09 +01:00
2001-02-18 23:33:10 +01:00
$this->stream = $phpgw->db;
if($user=='')
{
$this->user = $phpgw_info['user']['account_id'];
}
elseif(is_int($user))
{
$this->user = $user;
}
elseif(is_string($user))
{
$this->user = $phpgw->accounts->name2id($user);
}
return $this->stream;
}
function popen($calendar='',$user='',$passwd='',$options='')
{
return $this->open($calendar,$user,$passwd,$options);
2001-02-12 05:58:36 +01:00
}
2001-02-11 14:30:09 +01:00
2001-02-18 23:33:10 +01:00
function reopen($calendar,$options='')
{
return $this->stream;
}
2001-02-11 14:30:09 +01:00
2001-02-12 05:58:36 +01:00
function close($mcal_stream,$options='')
{
2001-02-18 23:33:10 +01:00
return True;
2001-02-12 05:58:36 +01:00
}
function create_calendar($stream='',$calendar='')
{
2001-02-18 23:33:10 +01:00
return $calendar;
2001-02-12 05:58:36 +01:00
}
2001-02-18 23:33:10 +01:00
function rename_calendar($stream='',$old_name='',$new_name='')
{
return $new_name;
}
2001-02-12 05:58:36 +01:00
2001-02-18 23:33:10 +01:00
function delete_calendar($stream='',$calendar='')
{
return $calendar;
}
2001-02-12 05:58:36 +01:00
function fetch_event($mcal_stream,$event_id,$options='')
{
2001-02-27 05:42:18 +01:00
global $phpgw;
2001-02-18 23:33:10 +01:00
if(!isset($this->stream))
{
return False;
}
2001-02-12 05:58:36 +01:00
2001-02-18 23:33:10 +01:00
$this->stream->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats'));
2001-02-12 05:58:36 +01:00
2001-02-27 05:42:18 +01:00
// This is the preferred method once everything is normalized...
//$this->stream->query('SELECT * FROM calendar_entry WHERE id='.$event_id,__LINE__,__FILE__);
// But until then, do it this way...
2001-02-18 23:33:10 +01:00
$this->stream->query('SELECT * FROM calendar_entry WHERE cal_id='.$event_id,__LINE__,__FILE__);
if($this->stream->num_rows() > 0)
{
2001-03-02 05:20:41 +01:00
$this->event = CreateObject('calendar.calendar_item');
$this->event->start = new calendar_time;
$this->event->end = new calendar_time;
$this->event->recur_enddate = new calendar_time;
2001-02-27 05:42:18 +01:00
2001-02-18 23:33:10 +01:00
$this->stream->next_record();
2001-02-27 05:42:18 +01:00
// Load the calendar event data from the db into $event structure
2001-02-18 23:33:10 +01:00
// Use http://www.php.net/manual/en/function.mcal-fetch-event.php as the reference
2001-02-27 05:42:18 +01:00
// This is the preferred method once everything is normalized...
2001-03-02 05:20:41 +01:00
//$this->event->owner = $this->user;
2001-02-27 05:42:18 +01:00
// But until then, do it this way...
//Legacy Support
2001-03-02 05:20:41 +01:00
$this->event->owner = $this->stream->f('cal_owner');
2001-02-27 05:42:18 +01:00
// This is the preferred method once everything is normalized...
2001-03-02 05:20:41 +01:00
//$this->event->id = $event_id;
2001-02-27 05:42:18 +01:00
// But until then, do it this way...
//Legacy Support
2001-03-02 05:20:41 +01:00
$this->event->id = intval($this->stream->f('cal_id'));
2001-02-27 05:42:18 +01:00
// This is the preferred method once everything is normalized...
2001-03-02 05:20:41 +01:00
//$this->event->public = $this->stream->f('public');
2001-02-27 05:42:18 +01:00
// But until then, do it this way...
//Legacy Support
2001-03-02 05:20:41 +01:00
$this->event->access = $this->stream->f('cal_access');
2001-02-27 05:42:18 +01:00
//Legacy Support (New)
2001-03-02 05:20:41 +01:00
$this->event->public = ($this->stream->f('cal_access')=='private'?0:1);
2001-02-27 05:42:18 +01:00
// This is the preferred method once everything is normalized...
2001-03-02 05:20:41 +01:00
//$this->event->category = $this->stream->f('category');
2001-02-27 05:42:18 +01:00
// But until then, do it this way...
//Legacy Support (New)
2001-03-02 05:20:41 +01:00
$this->event->category = 'Unfiled';
2001-02-27 05:42:18 +01:00
// This is the preferred method once everything is normalized...
2001-03-02 05:20:41 +01:00
//$this->event->title = $phpgw->strip_html($this->stream->f('title'));
2001-02-27 05:42:18 +01:00
// But until then, do it this way...
//Legacy Support
2001-03-02 05:20:41 +01:00
$this->event->name = $phpgw->strip_html($this->stream->f('cal_name'));
2001-02-27 05:42:18 +01:00
//Legacy Support (New)
2001-03-02 05:20:41 +01:00
$this->event->title = $phpgw->strip_html($this->stream->f('cal_name'));
2001-02-27 05:42:18 +01:00
// This is the preferred method once everything is normalized...
2001-03-02 05:20:41 +01:00
//$this->event->title = $phpgw->strip_html($this->stream->f('description'));
2001-02-27 05:42:18 +01:00
// But until then, do it this way...
//Legacy Support
//Legacy Support (New)
2001-03-02 05:20:41 +01:00
$this->event->description = $phpgw->strip_html($this->stream->f('cal_description'));
2001-02-27 05:42:18 +01:00
// This is the preferred method once everything is normalized...
2001-03-02 05:20:41 +01:00
//$this->event->alarm = intval($this->stream->f('alarm'));
2001-02-27 05:42:18 +01:00
// But until then, do it this way...
//Legacy Support (New)
2001-03-02 05:20:41 +01:00
$this->event->alarm = 0;
2001-02-27 05:42:18 +01:00
// This is the preferred method once everything is normalized...
2001-03-02 05:20:41 +01:00
//$this->event->start = unserialize($this->stream->f('start'));
2001-02-27 05:42:18 +01:00
// But until then, do it this way...
//Legacy Support
2001-03-02 05:20:41 +01:00
$this->event->datetime = $this->stream->f('cal_datetime');
$date = $this->localdates($this->event->datetime);
$this->event->day = $date['day'];
$this->event->month = $date['month'];
$this->event->year = $date['year'];
2001-02-27 05:42:18 +01:00
2001-03-02 05:20:41 +01:00
$time = $this->splittime($phpgw->common->show_date($this->event->datetime,'His'));
$this->event->hour = (int)$time['hour'];
$this->event->minute = (int)$time['minute'];
$this->event->ampm = $time['ampm'];
2001-02-27 05:42:18 +01:00
//Legacy Support (New)
$datetime = $this->localdates($this->stream->f('cal_datetime'));
2001-03-02 05:20:41 +01:00
$this->event->start->year = $datetime['year'];
$this->event->start->month = $datetime['month'];
$this->event->start->mday = $datetime['day'];
$this->event->start->hour = $datetime['hour'];
$this->event->start->min = $datetime['minute'];
$this->event->start->sec = $datetime['second'];
$this->event->start->alarm = 0;
2001-02-27 05:42:18 +01:00
//Legacy Support
2001-03-02 05:20:41 +01:00
$this->event->mdatetime = $this->stream->f('cal_mdatetime');
$date = $this->localdates($this->event->mdatetime);
$this->event->mod_day = $date['day'];
$this->event->mod_month = $date['month'];
$this->event->mod_year = $date['year'];
2001-02-27 05:42:18 +01:00
2001-03-02 05:20:41 +01:00
$time = $this->splittime($phpgw->common->show_date($this->event->mdatetime,'His'));
$this->event->mod_hour = (int)$time['hour'];
$this->event->mod_minute = (int)$time['minute'];
$this->event->mod_second = (int)$time['second'];
$this->event->mod_ampm = $time['ampm'];
2001-02-27 05:42:18 +01:00
// This is the preferred method once everything is normalized...
2001-03-02 05:20:41 +01:00
//$this->event->end = unserialize($this->stream->f('end'));
2001-02-27 05:42:18 +01:00
// But until then, do it this way...
//Legacy Support
2001-03-02 05:20:41 +01:00
$this->event->edatetime = $this->stream->f('cal_edatetime');
$date = $this->localdates($this->event->edatetime);
$this->event->end_day = $date['day'];
$this->event->end_month = $date['month'];
$this->event->end_year = $date['year'];
$time = $this->splittime($phpgw->common->show_date($this->event->edatetime,'His'));
$this->event->end_hour = (int)$time['hour'];
$this->event->end_minute = (int)$time['minute'];
$this->event->end_second = (int)$time['second'];
$this->event->end_ampm = $time['ampm'];
2001-02-27 05:42:18 +01:00
//Legacy Support (New)
$datetime = $this->localdates($this->stream->f('cal_edatetime'));
2001-03-02 05:20:41 +01:00
$this->event->end->year = $datetime['year'];
$this->event->end->month = $datetime['month'];
$this->event->end->mday = $datetime['day'];
$this->event->end->hour = $datetime['hour'];
$this->event->end->min = $datetime['minute'];
$this->event->end->sec = $datetime['second'];
$this->event->end->alarm = 0;
2001-02-27 05:42:18 +01:00
//Legacy Support
2001-03-02 05:20:41 +01:00
$this->event->priority = $this->stream->f('cal_priority');
2001-02-27 05:42:18 +01:00
if($this->stream->f('cal_group'))
{
$groups = explode(',',$this->stream->f('cal_group'));
for($j=1;$j<count($groups) - 1;$j++)
{
2001-03-02 05:20:41 +01:00
$this->event->groups[] = $groups[$j];
2001-02-27 05:42:18 +01:00
}
}
// This should all be one table,
// but for now we'll leave it separate...
// This is the preferred method once everything is normalized...
//$this->stream->query('SELECT * FROM calendar_entry_repeats WHERE id='.$event_id,__LINE__,__FILE__);
// But until then, do it this way...
//Legacy Support
$this->stream->query('SELECT * FROM calendar_entry_repeats WHERE cal_id='.$event_id,__LINE__,__FILE__);
if($this->stream->num_rows())
{
$this->stream->next_record();
// This is the preferred method once everything is normalized...
2001-03-02 05:20:41 +01:00
//$this->event->recur_type = intval($this->stream->f('recur_type'));
2001-02-27 05:42:18 +01:00
// But until then, do it this way...
//Legacy Support
$rpt_type = strtolower($this->stream->f('cal_type'));
2001-03-02 05:20:41 +01:00
$this->event->rpt_type = !$rpt_type?'none':$rpt_type;
2001-02-27 05:42:18 +01:00
//Legacy Support (New)
2001-03-02 05:20:41 +01:00
switch($this->event->rpt_type)
2001-02-27 05:42:18 +01:00
{
case 'none':
2001-03-02 05:20:41 +01:00
$this->event->recur_type = RECUR_NONE;
2001-02-27 05:42:18 +01:00
break;
case 'daily':
2001-03-02 05:20:41 +01:00
$this->event->recur_type = RECUR_DAILY;
2001-02-27 05:42:18 +01:00
break;
case 'weekly':
2001-03-02 05:20:41 +01:00
$this->event->recur_type = RECUR_WEEKLY;
2001-02-27 05:42:18 +01:00
break;
case 'monthlybydate':
2001-03-02 05:20:41 +01:00
$this->event->recur_type = RECUR_MONTHLY_MDAY;
2001-02-27 05:42:18 +01:00
break;
case 'monthlybyday':
2001-03-02 05:20:41 +01:00
$this->event->recur_type = RECUR_MONTHLY_WDAY;
2001-02-27 05:42:18 +01:00
break;
case 'yearly':
2001-03-02 05:20:41 +01:00
$this->event->recur_type = RECUR_YEARLY;
2001-02-27 05:42:18 +01:00
break;
}
// This is the preferred method once everything is normalized...
2001-03-02 05:20:41 +01:00
//$this->event->recur_interval = intval($this->stream->f('recur_interval'));
2001-02-27 05:42:18 +01:00
// But until then, do it this way...
//Legacy Support
2001-03-02 05:20:41 +01:00
$this->event->rpt_freq = (int)$this->stream->f('cal_frequency');
2001-02-27 05:42:18 +01:00
//Legacy Support (New)
2001-03-02 05:20:41 +01:00
$this->event->recur_interval = (int)$this->stream->f('cal_frequency');
2001-02-27 05:42:18 +01:00
// This is the preferred method once everything is normalized...
2001-03-02 05:20:41 +01:00
//$this->event->recur_enddate = unserialize($this->stream->f('recur_enddate'));
2001-02-27 05:42:18 +01:00
// But until then, do it this way...
//Legacy Support
2001-03-02 05:20:41 +01:00
$this->event->recur_use_end = $this->stream->f('cal_use_end');
if($this->event->recur_use_end == True)
2001-02-27 05:42:18 +01:00
{
$date = $this->localdates($this->stream->f('cal_end'));
2001-03-02 05:20:41 +01:00
//Legacy Support
$this->event->rpt_end = $this->stream->f('cal_end');
$this->event->rpt_end_day = (int)$date['day'];
$this->event->rpt_end_month = (int)$date['month'];
$this->event->rpt_end_year = (int)$date['year'];
2001-02-27 05:42:18 +01:00
//Legacy Support (New)
2001-03-02 05:20:41 +01:00
$this->event->recur_enddate->year = $date['year'];
$this->event->recur_enddate->month = $date['month'];
$this->event->recur_enddate->mday = $date['day'];
$this->event->recur_enddate->hour = $date['hour'];
$this->event->recur_enddate->min = $date['minute'];
$this->event->recur_enddate->sec = $date['second'];
$this->event->recur_enddate->alarm = 0;
2001-02-27 05:42:18 +01:00
}
else
{
//Legacy Support
2001-03-02 05:20:41 +01:00
$this->event->rpt_end = 0;
$this->event->rpt_end_day = 0;
$this->event->rpt_end_month = 0;
$this->event->rpt_end_year = 0;
2001-02-27 05:42:18 +01:00
//Legacy Support (New)
2001-03-02 05:20:41 +01:00
$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;
2001-02-27 05:42:18 +01:00
}
// This is the preferred method once everything is normalized...
2001-03-02 05:20:41 +01:00
//$this->event->recur_data = $this->stream->f('recur_data');
2001-02-27 05:42:18 +01:00
// But until then, do it this way...
//Legacy Support
$rpt_days = strtoupper($this->stream->f('cal_rpt_days'));
2001-03-02 05:20:41 +01:00
$this->event->rpt_days = $rpt_days;
$this->event->rpt_sun = (substr($rpt_days,0,1)=='Y'?1:0);
$this->event->rpt_mon = (substr($rpt_days,1,1)=='Y'?1:0);
$this->event->rpt_tue = (substr($rpt_days,2,1)=='Y'?1:0);
$this->event->rpt_wed = (substr($rpt_days,3,1)=='Y'?1:0);
$this->event->rpt_thu = (substr($rpt_days,4,1)=='Y'?1:0);
$this->event->rpt_fri = (substr($rpt_days,5,1)=='Y'?1:0);
$this->event->rpt_sat = (substr($rpt_days,6,1)=='Y'?1:0);
2001-02-27 05:42:18 +01:00
//Legacy Support (New)
2001-03-04 05:13:04 +01:00
$rpt_days = strtoupper($this->stream->f('cal_rpt_days'));
2001-03-02 05:20:41 +01:00
$this->event->recur_data = 0;
$this->event->recur_data += (substr($rpt_days,0,1)=='Y'?M_SUNDAY:0);
$this->event->recur_data += (substr($rpt_days,1,1)=='Y'?M_MONDAY:0);
$this->event->recur_data += (substr($rpt_days,2,1)=='Y'?M_TUESDAY:0);
$this->event->recur_data += (substr($rpt_days,3,1)=='Y'?M_WEDNESDAY:0);
$this->event->recur_data += (substr($rpt_days,4,1)=='Y'?M_THURSDAY:0);
$this->event->recur_data += (substr($rpt_days,5,1)=='Y'?M_FRIDAY:0);
$this->event->recur_data += (substr($rpt_days,6,1)=='Y'?M_SAYURDAY:0);
2001-02-27 05:42:18 +01:00
}
//Legacy Support
$this->stream->query('SELECT * FROM calendar_entry_user WHERE cal_id='.$event_id,__LINE__,__FILE__);
if($this->stream->num_rows())
{
while($this->stream->next_record())
{
2001-03-02 05:20:41 +01:00
$this->event->participants[] = $this->stream->f('cal_login');
$this->event->status[] = $this->stream->f('cal_status');
2001-02-27 05:42:18 +01:00
}
}
2001-02-18 23:33:10 +01:00
}
else
{
2001-03-02 05:20:41 +01:00
$this->event = False;
2001-02-18 23:33:10 +01:00
}
2001-02-12 05:58:36 +01:00
2001-02-18 23:33:10 +01:00
$this->stream->unlock();
2001-03-02 05:20:41 +01:00
return $this->event;
2001-02-12 05:58:36 +01:00
}
function list_events($mcal_stream,$startYear,$startMonth,$startDay,$endYear='',$endMonth='',$endYear='')
{
if(!isset($this->stream))
{
return False;
}
$datetime = $this->makegmttime(0,0,0,$startMonth,$startDay,$startYear);
2001-02-25 05:06:15 +01:00
$startDate = ' AND (calendar_entry.datetime >= '.$datetime.') ';
if($endYear != '' && $endMonth != '' && $endDay != '')
{
$edatetime = $this->makegmttime(23,59,59,intval($endMonth),intval($endDay),intval($endYear));
2001-02-25 05:06:15 +01:00
$endDate = 'AND (calendar_entry.edatetime <= '.$edatetime.') ';
}
else
{
$endDate = '';
}
2001-02-25 05:06:15 +01:00
return $this->get_event_ids(False,$startDate.$endDate);
}
2001-03-01 04:49:13 +01:00
function append_event($mcal_stream)
{
$this->save_event($this->event);
$this->send_update(MSG_ADDED,$this->event->participants,'',$this->event);
2001-03-01 04:49:13 +01:00
return $this->event->id;
}
function store_event($mcal_stream)
{
if($this->event->id != 0)
{
$new_event = $this->event;
$old_event = $this->fetch_event($this->stream,$new_event->id);
$this->prepare_recipients($new_event,$old_event);
$this->event = $new_event;
}
else
{
$this->send_update(MSG_ADDED,$this->event->participants,'',$this->event);
}
2001-03-01 04:49:13 +01:00
return $this->save_event($this->event);
}
2001-03-01 05:13:30 +01:00
function delete_event($mcal_stream,$event_id)
{
$this->deleted_events[] = $event_id;
2001-03-01 05:13:30 +01:00
}
function snooze($mcal_stream,$event_id)
{
//Turn off an alarm for an event
//Returns true.
}
function list_alarms($mcal_stream,$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
}
2001-03-01 04:49:13 +01:00
function event_init($stream)
{
$this->event = CreateObject('calendar.calendar_item');
2001-03-04 05:13:04 +01:00
$this->event->owner = $this->user;
// echo 'Initializing Calendar Event<br>'."\n";
// echo 'Setting Owner = '.$this->event->owner."<br>\n";
2001-03-01 04:49:13 +01:00
return True;
}
2001-03-02 05:20:41 +01:00
function event_set_category($stream,$category='')
{
$this->event->category = $category;
2001-03-04 05:13:04 +01:00
// echo 'Setting Calendar Category = '.$this->event->category.'<br>'."\n";
2001-03-02 05:20:41 +01:00
return True;
}
function event_set_title($stream,$title='')
{
$this->event->title = $title;
2001-03-04 05:13:04 +01:00
$this->event->name = $title;
// echo 'Setting Calendar Title = '.$this->event->title.'<br>'."\n";
2001-03-02 05:20:41 +01:00
return True;
}
function event_set_description($stream,$description='')
{
$this->event->description = $description;
2001-03-04 05:13:04 +01:00
// echo 'Setting Calendar Description = '.$this->event->description.'<br>'."\n";
2001-03-02 05:20:41 +01:00
return True;
}
function event_set_start($stream,$year,$month,$day=0,$hour=0,$min=0,$sec=0)
{
2001-03-04 05:13:04 +01:00
global $phpgw_info;
// Legacy Support
$this->event->year = intval($year);
$this->event->month = intval($month);
$this->event->day = intval($day);
$this->event->hour = intval($hour);
$this->event->minute = intval($min);
$this->event->datetime = mktime(intval($hour),intval($min),intval($sec),intval($month),intval($day),intval($year));
$this->event->datetime -= ((60 * 60) * intval($phpgw_info['user']['preferences']['common']['tz_offset']));
// Legacy Support (New)
$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);
// echo 'Setting Calendar Start = '.$this->event->start->year.$this->event->start->month.$this->event->start->mday.':'.$this->event->start->hour.$this->event->start->min.$this->event->start->sec.'<br>'."\n";
return True;
2001-03-02 05:20:41 +01:00
}
function event_set_end($stream,$year,$month,$day=0,$hour=0,$min=0,$sec=0)
{
2001-03-04 05:13:04 +01:00
global $phpgw_info;
// Legacy Support
$this->event->end_year = intval($year);
$this->event->end_month = intval($month);
$this->event->end_day = intval($day);
$this->event->end_hour = intval($hour);
$this->event->end_minute = intval($min);
$this->event->end_second = intval($sec);
$this->event->edatetime = mktime(intval($hour),intval($min),intval($sec),intval($month),intval($day),intval($year));
$this->event->edatetime -= ((60 * 60) * intval($phpgw_info['user']['preferences']['common']['tz_offset']));
// Legacy Support (New)
$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);
// echo 'Setting Calendar End = '.$this->event->end->year.$this->event->end->month.$this->event->end->mday.':'.$this->event->end->hour.$this->event->end->min.$this->event->end->sec.'<br>'."\n";
return True;
}
function event_set_alarm($stream,$alarm)
{
$this->event->alarm = intval($alarm);
return True;
}
function event_set_class($stream,$class)
{
$this->event->public = $class;
return True;
}
function is_leap_year($year)
{
if ((intval($year) % 4 == 0) && (intval($year) % 100 != 0) || (intval($year) % 400 == 0))
return 1;
else
return 0;
}
function days_in_month($month,$year)
{
$days = Array(
1 => 31,
2 => 28 + $this->is_leap_year(intval($year)),
3 => 31,
4 => 30,
5 => 31,
6 => 30,
7 => 31,
8 => 31,
9 => 30,
10 => 31,
11 => 30,
12 => 31
);
return $days[intval($month)];
}
function date_valid($year,$month,$day)
{
return checkdate(intval($month),intval($day),intval($year));
}
function time_valid($hour,$minutes,$seconds)
{
if(intval($hour) < 0 || intval($hour) > 24)
{
return False;
}
if(intval($minutes) < 0 || intval($minutes) > 59)
{
return False;
}
if(intval($seconds) < 0 || intval($seconds) > 59)
{
return False;
}
return True;
}
function day_of_week($year,$month,$day)
{
return date('w',mktime(0,0,0,intval($month),intval($day),intval($year)));
}
function day_of_year($year,$month,$day)
{
return date('w',mktime(0,0,0,intval($month),intval($day),intval($year)));
2001-03-02 05:20:41 +01:00
}
2001-03-04 05:13:04 +01:00
function date_compare($a_year,$a_month,$a_day,$b_year,$b_month,$b_day)
{
$a_date = mktime(0,0,0,intval($a_month),intval($a_day),intval($a_year));
$b_date = mktime(0,0,0,intval($b_month),intval($b_day),intval($b_year));
if($a_date == $b_date)
{
return 0;
}
elseif($a_date > $b_date)
{
return 1;
}
elseif($a_date < $b_date)
{
return -1;
}
}
// The function definition doesn't look correct...
// Need more information for this function
function next_recurrence($stream,$weekstart,$next)
{
// return next_recurrence (int stream, int weekstart, array next);
}
function event_set_recur_none($stream)
{
// Legacy Support
$this->event->rpt_type = 'none';
$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;
$this->event->rpt_days = 'nnnnnnn';
$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_freq = 0;
// Legacy Support (New)
$this->event->recur_type = RECUR_NONE;
$this->event->recur_interval = 0;
$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;
$this->event->recur_data = 0;
return True;
}
function event_recur_daily($stream,$year,$monh,$day,$interval)
{
// Legacy Support
$this->event->rpt_type = 'daily';
// Legacy Support (New)
$this->event->recur_type = RECUR_DAILY;
$this->set_common_recur(intval($year),intval($month),intval($day));
}
function event_set_recur_weekly($stream,$year,$month,$day,$interval,$weekdays)
{
// Legacy Support
$this->event->rpt_type = 'weekly';
$this->set_common_recur(intval($year),intval($month),intval($day));
$this->event->rpt_sun = (intval($weekdays) & M_SUNDAY ?1:0);
$this->event->rpt_mon = (intval($weekdays) & M_MONDAY ?1:0);
$this->event->rpt_tue = (intval($weekdays) & M_TUESDAY ?1:0);
$this->event->rpt_wed = (intval($weekdays) & M_WEDNESDAY?1:0);
$this->event->rpt_thu = (intval($weekdays) & M_THURSDAY ?1:0);
$this->event->rpt_fri = (intval($weekdays) & M_FRIDAY ?1:0);
$this->event->rpt_sat = (intval($weekdays) & M_SATURDAY ?1:0);
$this->event->rpt_days =
($this->event->rpt_sun == 1?'y':'n')
. ($this->event->rpt_mon == 1?'y':'n')
. ($this->event->rpt_tue == 1?'y':'n')
. ($this->event->rpt_wed == 1?'y':'n')
. ($this->event->rpt_thu == 1?'y':'n')
. ($this->event->rpt_fri == 1?'y':'n')
. ($this->event->rpt_sat == 1?'y':'n');
// Legacy Support (New)
$this->event->recur_type = RECUR_WEEKLY;
$this->event->recur_data = intval($weekdays);
}
function event_set_recur_monthly_mday($stream,$year,$month,$day,$interval)
{
// Legacy Support
$this->event->rpt_type = 'monthlybydate';
// Legacy Support
$this->event->recur_type = RECUR_MONTHLY_MDAY;
$this->set_common_recur(intval($year),intval($month),intval($day));
}
function event_set_recur_monthly_wday($stream,$year,$month,$day,$interval)
{
// Legacy Support
$this->event->rpt_type = 'monthlybyday';
// Legacy Support (New)
$this->event->recur_type = RECUR_MONTHLY_WDAY;
$this->set_common_recur(intval($year),intval($month),intval($day));
}
function event_set_recur_yearly($stream,$year,$month,$day,$interval)
{
// Legacy Support
$this->event->rpt_type = 'yearly';
// Legacy Support (New)
$this->event->recur_type = RECUR_YEARLY;
$this->set_common_recur(intval($year),intval($month),intval($day));
}
function fetch_current_stream_event($stream)
{
return $this->fetch_event($this->event->id);
}
function event_add_attribute($stream,$attribute,$value)
{
$this->event->$attribute = $value;
}
function expunge($stream)
{
if(count($this->deleted_events) <= 0)
{
return 1;
}
$this_event = $this->event;
$this->stream->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats'));
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);
$this->stream->query('DELETE FROM calendar_entry_user WHERE cal_id='.$event_id,__LINE__,__FILE__);
$this->stream->query('DELETE FROM calendar_entry_repeats WHERE cal_id='.$event_id,__LINE__,__FILE__);
$this->stream->query('DELETE FROM calendar_entry WHERE cal_id='.$event_id,__LINE__,__FILE__);
}
$this->stream->unlock();
$this->event = $this_event;
2001-03-04 05:13:04 +01:00
return 1;
}
2001-02-25 05:06:15 +01:00
/***************** Local functions for SQL based Calendar *****************/
function get_event_ids($search_repeats=False,$extra='')
{
2001-02-26 13:23:48 +01:00
$retval = Array();
2001-02-25 05:06:15 +01:00
if($search_repeats == True)
{
$repeats_from = ', calendar_entry_repeats ';
$repeats_where = 'AND (calendar_entry_repeats.cal_id = calendar_entry.cal_id) ';
}
else
{
$repeats_from = ' ';
$repeats_where = '';
}
2001-03-01 04:49:13 +01:00
$sql = 'SELECT DISTINCT calendar_entry.cal_id,'
. 'calendar_entry.cal_datetime,calendar_entry.cal_edatetime,'
. 'calendar_entry.cal_priority '
2001-02-25 05:06:15 +01:00
. 'FROM calendar_entry, calendar_entry_user'
. $repeats_from
. 'WHERE (calendar_entry_user.cal_id = calendar_entry.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;
}
2001-03-01 04:49:13 +01:00
function save_event(&$event)
{
global $phpgw_info;
$this->stream->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats'));
if($event->id == 0)
{
$temp_name = tempnam($phpgw_info['server']['temp_dir'],'cal');
$this->stream->query("INSERT INTO calendar_entry(cal_name) values('".$temp_name."')");
$this->stream->query("SELECT cal_id FROM calendar_entry WHERE cal_name='".$temp_name."'");
$this->stream->next_record();
$event->id = $this->stream->f('cal_id');
}
// if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12')
// {
// if ($event->ampm == 'pm' && ($event->hour < 12 && $event->hour <> 12))
// {
// $event->hour += 12;
// }
//
// if ($event->end_ampm == 'pm' && ($event->end_hour < 12 && $event->end_hour <> 12))
// {
// $event->end_hour += 12;
// }
// }
2001-03-04 05:13:04 +01:00
$tz_offset = ((60 * 60) * intval($phpgw_info['user']['preferences']['common']['tz_offset']));
$date = mktime($event->start->hour,$event->start->min,$event->start->sec,$event->start->month,$event->start->mday,$event->start->year) - $tz_offset;
$enddate = mktime($event->end->hour,$event->end->min,$event->end->sec,$event->end->month,$event->end->mday,$event->end->year) - $tz_offset;
$today = time() - $tz_offset;
2001-03-01 04:49:13 +01:00
2001-03-04 05:13:04 +01:00
if($event->recur_type != RECUR_NONE)
2001-03-01 04:49:13 +01:00
{
$type = 'M';
}
else
{
$type = 'E';
}
2001-03-04 05:13:04 +01:00
if($event->public == True)
{
$event->access = 'public';
}
else
{
$event->access = 'private';
}
$sql = 'UPDATE calendar_entry SET '
2001-03-01 04:49:13 +01:00
. 'cal_owner='.$event->owner.', '
2001-03-04 05:13:04 +01:00
. 'cal_datetime='.$date.', '
. 'cal_mdatetime='.$today.', '
. 'cal_edatetime='.$enddate.', '
2001-03-01 04:49:13 +01:00
. 'cal_priority='.$event->priority.', '
. "cal_type='".$type."', "
. "cal_access='".$event->access."', "
. "cal_name='".$event->name."', "
. "cal_description='".$event->description."' "
. 'WHERE cal_id='.$event->id;
$this->stream->query($sql,__LINE__,__FILE__);
$this->stream->query('DELETE FROM calendar_entry_user WHERE cal_id='.$event->id,__LINE__,__FILE__);
while ($participant = each($event->participants))
{
$status = 'U';
if(intval($participant[1]) == intval($this->user))
{
$status = 'A';
}
2001-03-01 04:49:13 +01:00
$this->stream->query('INSERT INTO calendar_entry_user(cal_id,cal_login,cal_status) '
. 'VALUES('.$event->id.','.$participant[1].",'".$status."')",__LINE__,__FILE__);
2001-03-01 04:49:13 +01:00
}
2001-03-04 05:13:04 +01:00
if($event->recur_type != RECUR_NONE)
2001-03-01 04:49:13 +01:00
{
if($event->rpt_use_end)
{
2001-03-04 05:13:04 +01:00
$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) - $tz_offset;
2001-03-01 04:49:13 +01:00
$use_end = 1;
}
else
{
$end = 'NULL';
$use_end = 0;
}
2001-03-04 05:13:04 +01:00
$days = $event->rpt_days;
2001-03-01 04:49:13 +01:00
$this->stream->query('SELECT count(cal_id) FROM calendar_entry_repeats WHERE cal_id='.$event->id,__LINE__,__FILE__);
$this->stream->next_record();
$num_rows = $this->stream->f(0);
if($num_rows == 0)
{
2001-03-03 04:55:01 +01:00
$this->stream->query('INSERT INTO calendar_entry_repeats(cal_id,'
.'cal_type,cal_use_end,cal_end,cal_days,cal_frequency) '
.'VALUES('.$event->id.",'".$event->rpt_type."',".$use_end.','
2001-03-04 05:13:04 +01:00
.$end.",'".$days."',".$event->recur_interval.')',__LINE__,__FILE__);
2001-03-01 04:49:13 +01:00
}
else
{
2001-03-03 04:55:01 +01:00
$this->stream->query('UPDATE calendar_entry_repeats '
."SET cal_type='".$event->rpt_type."', "
2001-03-04 05:13:04 +01:00
.'cal_use_end='.$use_end.", cal_end='".$end."', "
."cal_days='".$days."', cal_frequency=".$event->recur_interval.' '
2001-03-01 04:49:13 +01:00
.'WHERE cal_id='.$event->id,__LINE__,__FILE__);
}
}
else
{
$this->stream->query('DELETE FROM calendar_entry_repeats WHERE cal_id='.$event->id,__LINE__,__FILE__);
}
$this->stream->unlock();
2001-03-02 05:20:41 +01:00
return True;
2001-03-01 04:49:13 +01:00
}
2001-03-04 05:13:04 +01:00
function event_set_participants($stream,$participants)
{
$this->event->participants = Array();
reset($participants);
$this->event->participants = $participants;
return True;
2001-03-12 04:18:02 +01:00
}
function set_status($id,$owner,$status)
{
$status_code_short = Array(
REJECTED => 'R',
NO_RESPONSE => 'U',
TENTATIVE => 'T',
ACCEPTED => 'A'
);
$this->stream->query("UPDATE calendar_entry_user SET cal_status='".$status_code_short[$status]."' WHERE cal_id=".$id." AND cal_login=".$owner,__LINE__,__FILE__);
return True;
2001-03-04 05:13:04 +01:00
}
2001-02-17 15:22:33 +01:00
// End of ICal style support.......
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
function group_search($owner=0)
{
global $phpgw, $phpgw_info;
$owner = $owner==$phpgw_info['user']['account_id']?0:$owner;
$groups = substr($phpgw->common->sql_search('calendar_entry.cal_group',intval($owner)),4);
if (!$groups)
{
return '';
}
else
{
return "(calendar_entry.cal_access='group' AND (". $groups .')) ';
}
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
function normalizeminutes(&$minutes)
{
$hour = 0;
$min = intval($minutes);
if($min >= 60)
{
$hour += $min / 60;
$min %= 60;
}
settype($minutes,'integer');
$minutes = $min;
return $hour;
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
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;
}
2001-02-11 14:30:09 +01:00
function splittime($time,$follow_24_rule=True)
2001-02-17 15:22:33 +01:00
{
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)
2001-02-17 15:22:33 +01:00
{
if ($phpgw_info['user']['preferences']['common']['timeformat'] == '24')
{
return $temp;
}
2001-02-17 15:22:33 +01:00
$temp['ampm'] = 'am';
2001-02-17 15:22:33 +01:00
if ((int)$temp['hour'] > 12)
{
$temp['hour'] = (int)((int)$temp['hour'] - 12);
$temp['ampm'] = 'pm';
}
elseif ((int)$temp['hour'] == 12)
{
$temp['ampm'] = 'pm';
}
2001-02-17 15:22:33 +01:00
}
return $temp;
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
function makegmttime($hour,$minute,$second,$month,$day,$year)
{
global $phpgw, $phpgw_info;
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
return $this->gmtdate(mktime($hour, $minute, $second, $month, $day, $year));
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
function localdates($localtime)
{
global $phpgw, $phpgw_info;
$date = Array('raw','day','month','year','full','dow','dm','bd');
$date['raw'] = $localtime;
$date['year'] = intval($phpgw->common->show_date($date['raw'],'Y'));
$date['month'] = intval($phpgw->common->show_date($date['raw'],'m'));
$date['day'] = intval($phpgw->common->show_date($date['raw'],'d'));
$date['full'] = intval($phpgw->common->show_date($date['raw'],'Ymd'));
$date['bd'] = mktime(0,0,0,$date['month'],$date['day'],$date['year']);
$date['dm'] = intval($phpgw->common->show_date($date['raw'],'dm'));
$date['dow'] = intval($phpgw->common->show_date($date['raw'],'w'));
$date['hour'] = intval($phpgw->common->show_date($date['raw'],'H'));
$date['minute'] = intval($phpgw->common->show_date($date['raw'],'i'));
2001-02-27 05:42:18 +01:00
$date['second'] = intval($phpgw->common->show_date($date['raw'],'s'));
2001-02-17 15:22:33 +01:00
return $date;
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
function gmtdate($localtime)
{
global $phpgw_info;
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$localtime -= ((60 * 60) * intval($phpgw_info['user']['preferences']['common']['tz_offset']));
return $this->localdates($localtime);
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
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))));
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
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;
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
// Start from here to meet coding stds.......
// This function may be removed in the near future.....
function pretty_small_calendar($day,$month,$year,$link='')
{
global $phpgw, $phpgw_info, $view;
// $tz_offset = (-1 * ((60 * 60) * intval($phpgw_info['user']['preferences']['common']['tz_offset'])));
$date = $this->makegmttime(0,0,0,$month,$day,$year);
$month_ago = intval(date('Ymd',mktime(0,0,0,$month - 1,$day,$year)));
$month_ahead = intval(date('Ymd',mktime(0,0,0,$month + 1,$day,$year)));
$monthstart = intval(date('Ymd',mktime(0,0,0,$month,1,$year)));
$monthend = intval(date('Ymd',mktime(0,0,0,$month + 1,0,$year)));
$weekstarttime = $this->get_weekday_start($year,$month,1);
$str = '';
$str .= '<table border="0" cellspacing="0" cellpadding="0" valign="top">';
$str .= '<tr valign="top">';
$str .= '<td bgcolor="'.$phpgw_info['theme']['bg_text'].'">';
$str .= '<table border="0" width="100%" cellspacing="1" cellpadding="2" border="0" valign="top">';
if ($view == 'day')
{
$str .= '<tr><th colspan="7" bgcolor="'.$phpgw_info['theme']['th_bg'].'"><font size="+4" color="'.$phpgw_info['theme']['th_text'].'">'.$day.'</font></th></tr>';
}
$str .= '<tr>';
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if ($view == 'year')
{
$str .= '<td align="center" colspan="7" bgcolor="' . $phpgw_info['theme']['th_bg'] . '">';
}
else
{
$str .= '<td align="left" bgcolor="' . $phpgw_info['theme']['th_bg'] .'">';
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if ($view != 'year')
{
if (!$this->printer_friendly)
{
$str .= '<a href="'.$phpgw->link($phpgw_info['server']['webserver_url'].'/calendar/day.php','date='.$month_ago).'" class="monthlink">';
}
$str .= '&lt;';
if (!$this->printer_friendly)
{
$str .= '</a>';
}
$str .= '</td>';
$str .= '<th colspan="5" bgcolor="'.$phpgw_info['theme']['th_bg'].'"><font color="'.$phpgw_info['theme']['th_text'].'">';
}
if (!$this->printer_friendly)
{
$str .= '<a href="'.$phpgw->link($phpgw_info['server']['webserver_url'].'/calendar/index.php','year='.$year.'&month='.$month).'">';
}
$str .= lang($phpgw->common->show_date($date['raw'],'F')).' '.$year;
if(!$this->printer_friendly)
{
$str .= '</a>';
}
if ($view != 'year')
{
$str .= '</font></th>';
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if ($view != 'year')
{
$str .= '<td align="right" bgcolor="'.$phpgw_info['theme']['th_bg'].'">';
if (!$this->printer_friendly)
{
$str .= '<a href="'.$phpgw->link($phpgw_info['server']['webserver_url'].'/calendar/day.php','date='.$month_ahead).'" class="monthlink">';
}
$str .= '&gt;';
if (!$this->printer_friendly)
{
$str .= '</a>';
}
$str .= '</td>';
}
$str .= '</tr>';
$str .= '<tr>';
for($i=0;$i<7;$i++)
{
$str .= '<td bgcolor="'.$phpgw_info['theme']['cal_dayview'].'"><font size="-2">'.substr(lang($days[$i]),0,2).'</td>';
}
$str .= '</tr>';
for($i=$weekstarttime;date('Ymd',$i)<=$monthend;$i += (24 * 3600 * 7))
{
$str .= '<tr>';
for($j=0;$j<7;$j++)
{
$cal = $this->gmtdate($i + ($j * 24 * 3600));
if($cal['full'] >= $monthstart && $cal['full'] <= $monthend)
{
$str .= '<td align="center" bgcolor="';
if($cal['full'] == $this->today['full'])
{
$str .= $phpgw_info['theme']['cal_today'];
}
else
{
$str .= $phpgw_info['theme']['cal_dayview'];
}
$str .= '"><font size="-2">';
if(!$this->printer_friendly)
{
$str .= '<a href="'.$phpgw->link($phpgw_info['server']['webserver_url'].'/calendar/'.$link,'year='.$cal['year'].'&month='.$cal['month'].'&day='.$cal['day']).'" class="monthlink">';
}
$str .= $cal['day'];
if(!$this->printer_friendly)
{
$str .= '</a>';
}
$str .= '</font></td>';
}
else
{
$str .= '<td bgcolor="' . $phpgw_info['theme']['cal_dayview']
. '"><font size="-2" color="' . $phpgw_info['theme']['cal_dayview'] . '">.</font></td>';
}
}
$str .= '</tr>';
}
$str .= '</table>';
$str .= '</td>';
$str .= '</tr>';
$str .= '</table>';
return $str;
2001-02-11 14:30:09 +01:00
}
2001-02-17 15:22:33 +01:00
// This function may be removed in the near future.....
function display_small_month($month,$year,$showyear,$link='')
{
global $phpgw, $phpgw_info;
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$weekstarttime = $this->get_weekday_start($year,$month,1);
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$str = '';
$str .= '<table border="0" bgcolor="'.$phpgw_info['theme']['bg_color'].'">';
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$monthstart = $this->localdates(mktime(0,0,0,$month ,1,$year));
$monthend = $this->localdates(mktime(0,0,0,$month + 1,0,$year));
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$str .= '<tr><td colspan="7" align="center"><font size="2">';
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if(!$this->printer_friendly)
{
$str .= '<a href="'.$phpgw->link($phpgw_info['server']['webserver_url'].'/calendar/index.php',"year=$year&month=$month").'">';
}
$str .= lang(date('F',$monthstart['raw']));
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if($showyear)
{
$str .= ' '.$year;
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if(!$this->printer_friendly)
{
$str .= '</a>';
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$str .= '</font></td></tr><tr>';
2001-03-04 15:15:32 +01:00
for($i=0;$i<7;$i++)
2001-02-17 15:22:33 +01:00
{
$str .= '<td>'.lang($days[$i]).'</td>';
}
$str .= '</tr>';
for($i=$weekstarttime;date('Ymd',$i)<=$monthend['full'];$i+=604800)
{
$str .= '<tr>';
2001-03-04 15:15:32 +01:00
for($j=0;$j<7;$j++)
2001-02-17 15:22:33 +01:00
{
$date = $this->localdates($i + ($j * 86400));
if($date['full']>=$monthstart['full'] &&
$date['full']<=$monthend['full'])
{
$str .= '<td align="right">';
if(!$this->printer_friendly || $link)
{
$str .= '<a href="'.$phpgw->link($phpgw_info['server']['webserver_url'].'/calendar/'.$link,'year='.$date['year'].'&month='.$date['month'].'&day='.$date['day']).'">';
}
$str .= '<font size="2">'.date('j',$date['raw']);
if(!$this->printer_friendly || $link)
{
$str .= '</a>';
}
$str .= '</font></td>';
}
else
{
$str .= '<td></td>';
}
}
$str .= '</tr>';
}
$str .= '</table>';
return $str;
2001-02-11 14:30:09 +01:00
}
2001-02-17 15:22:33 +01:00
function prep($calid)
{
global $phpgw, $phpgw_info;
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if(!$phpgw_info['user']['apps']['calendar']) return false;
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$db2 = $phpgw->db;
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$cal_id = array();
if(is_long($calid))
{
if(!$calid)
{
return false;
}
$cal_id[0] = $calid;
}
elseif(is_string($calid))
{
$calid = $phpgw->account->name2id($calid);
$db2->query('SELECT cal_id FROM calendar_entry WHERE cal_owner='.$calid,__LINE__,__FILE__);
while($phpgw->db->next_record())
{
$cal_id[] = $db2->f('cal_id');
}
}
elseif(is_array($calid))
{
if(is_string($calid[0]))
{
for($i=0;$i<count($calid);$i++)
{
$db2->query('SELECT cal_id FROM calendar_entry WHERE cal_owner='.$calid[$i],__LINE__,__FILE__);
while($db2->next_record())
{
$cal_id[] = $db2->f('cal_id');
}
2001-02-11 14:30:09 +01:00
}
}
2001-02-17 15:22:33 +01:00
elseif(is_long($calid[0]))
{
$cal_id = $calid;
}
}
return $cal_id;
2001-02-11 14:30:09 +01:00
}
2001-02-17 15:22:33 +01:00
function getwithindates($from,$to)
{
global $phpgw, $phpgw_info;
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if(!$phpgw_info['user']['apps']['calendar'])
{
return false;
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$phpgw->db->query('SELECT cal_id FROM calendar_entry WHERE cal_date >= '.$from.' AND cal_date <= '.$to,__LINE__,__FILE__);
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if($phpgw->db->num_rows())
{
while($phpgw->db->next_record())
{
$calid[count($calid)] = intval($phpgw->db->f('cal_id'));
}
return $this->getevent($calid);
}
else
{
return false;
}
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
function add($calinfo,$calid=0)
{
global $phpgw, $phpgw_info;
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$db2 = $phpgw->db;
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if(!$phpgw_info['user']['apps']['calendar'])
{
return false;
}
if(!$calid)
{
$db2->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats'));
$db2->query("INSERT INTO calendar_entry(cal_name) VALUES('".addslashes($calinfo->name)."')",__LINE__,__FILE__);
$db2->query('SELECT MAX(cal_id) FROM calendar_entry',__LINE__,__FILE__);
$db2->next_record();
$calid = $db2->f(0);
$db2->unlock();
}
if($calid)
{
return $this->modify($calinfo,$calid);
}
2001-02-11 14:30:09 +01:00
}
2001-02-17 15:22:33 +01:00
function delete($calid=0)
{
global $phpgw;
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$cal_id = $this->prep($calid);
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if(!$cal_id)
{
return false;
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$db2 = $phpgw->db;
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$db2->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats'));
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
for($i=0;$i<count($cal_id);$i++)
{
$db2->query('DELETE FROM calendar_entry_user WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__);
$db2->query('DELETE FROM calendar_entry_repeats WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__);
$db2->query('DELETE FROM calendar_entry WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__);
}
$db2->unlock();
2001-02-11 14:30:09 +01:00
}
2001-02-17 15:22:33 +01:00
function modify($calinfo,$calid=0)
{
global $phpgw, $phpgw_info;
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if(!$phpgw_info['user']['apps']['calendar'])
{
return false;
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if(!$calid)
{
return false;
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$db2 = $phpgw->db;
$db2->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats'));
$owner = ($calinfo->owner?$calinfo->owner:$phpgw_info['user']['account_id']);
if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12')
{
if ($calinfo->ampm == 'pm' && ($calinfo->hour < 12 && $calinfo->hour <> 12))
{
$calinfo->hour += 12;
}
if ($calinfo->end_ampm == 'pm' && ($calinfo->end_hour < 12 && $calinfo->end_hour <> 12))
{
$calinfo->end_hour += 12;
}
}
$date = $this->makegmttime($calinfo->hour,$calinfo->minute,0,$calinfo->month,$calinfo->day,$calinfo->year);
$enddate = $this->makegmttime($calinfo->end_hour,$calinfo->end_minute,0,$calinfo->end_month,$calinfo->end_day,$calinfo->end_year);
$today = $this->gmtdate(time());
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if($calinfo->rpt_type != 'none')
{
$rpt_type = 'M';
}
else
{
$rpt_type = 'E';
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$query = 'UPDATE calendar_entry SET cal_owner='.$owner.", cal_name='".addslashes($calinfo->name)."', "
2001-02-18 23:33:10 +01:00
. "cal_description='".addslashes($calinfo->description)."', cal_datetime=".$date['raw'].', '
. 'cal_mdatetime='.$today['raw'].', cal_edatetime='.$enddate['raw'].', '
2001-02-17 15:22:33 +01:00
. 'cal_priority='.$calinfo->priority.", cal_type='".$rpt_type."' ";
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if(($calinfo->access == 'public' || $calinfo->access == 'group') && count($calinfo->groups))
{
$query .= ", cal_access='".$calinfo->access."', cal_group = '".$phpgw->accounts->array_to_string($calinfo->access,$calinfo->groups)."' ";
}
elseif(($calinfo->access == 'group') && !count($calinfo->groups))
{
$query .= ", cal_access='private', cal_group = '' ";
}
else
{
$query .= ", cal_access='".$calinfo->access."', cal_group = '' ";
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
$query .= 'WHERE cal_id='.$calid;
2001-02-12 05:58:36 +01:00
2001-02-17 15:22:33 +01:00
$db2->query($query,__LINE__,__FILE__);
2001-02-12 05:58:36 +01:00
2001-02-17 15:22:33 +01:00
$db2->query('DELETE FROM calendar_entry_user WHERE cal_id='.$calid,__LINE__,__FILE__);
2001-02-12 05:58:36 +01:00
2001-02-17 15:22:33 +01:00
while ($participant = each($calinfo->participants))
{
$phpgw->db->query('INSERT INTO calendar_entry_user(cal_id,cal_login,cal_status) '
2001-02-18 23:33:10 +01:00
. 'VALUES('.$calid.','.$participant[1].",'A')",__LINE__,__FILE__);
2001-02-17 15:22:33 +01:00
}
2001-02-12 05:58:36 +01:00
2001-02-17 15:22:33 +01:00
if(strcmp($calinfo->rpt_type,'none') <> 0)
{
$freq = ($calinfo->rpt_freq?$calinfo->rpt_freq:0);
if($calinfo->rpt_use_end)
{
$end = $this->makegmttime(0,0,0,$calinfo->rpt_month,$calinfo->rpt_day,$calinfo->rpt_year);
$use_end = 1;
}
else
{
$end = 'NULL';
$use_end = 0;
}
if($calinfo->rpt_type == 'weekly' || $calinfo->rpt_type == 'daily')
{
$days = ($calinfo->rpt_sun?'y':'n')
. ($calinfo->rpt_mon?'y':'n')
. ($calinfo->rpt_tue?'y':'n')
. ($calinfo->rpt_wed?'y':'n')
. ($calinfo->rpt_thu?'y':'n')
. ($calinfo->rpt_fri?'y':'n')
. ($calinfo->rpt_sat?'y':'n');
}
else
{
$days = 'nnnnnnn';
}
$db2->query('SELECT count(cal_id) FROM calendar_entry_repeats WHERE cal_id='.$calid,__LINE__,__FILE__);
$db2->next_record();
$num_rows = $db2->f(0);
if(!$num_rows)
{
$db2->query('INSERT INTO calendar_entry_repeats(cal_id,cal_type,cal_use_end,cal_end,cal_days,cal_frequency) '
."VALUES($calid,'".$calinfo->rpt_type."',$use_end,".$end['raw'].",'$days',$freq)",__LINE__,__FILE__);
}
else
{
$db2->query("UPDATE calendar_entry_repeats SET cal_type='".$calinfo->rpt_type."', cal_use_end=".$use_end.', '
2001-02-18 23:33:10 +01:00
."cal_end='".$end['raw']."', cal_days='".$days."', cal_frequency=".$freq.' '
2001-02-17 15:22:33 +01:00
.'WHERE cal_id='.$calid,__LINE__,__FILE__);
}
}
else
{
$db2->query('DELETE FROM calendar_entry_repeats WHERE cal_id='.$calid,__LINE__,__FILE__);
}
$db2->unlock();
}
2001-02-12 05:58:36 +01:00
2001-02-17 15:22:33 +01:00
function getevent($calid)
{
global $phpgw;
2001-02-12 05:58:36 +01:00
2001-02-17 15:22:33 +01:00
$cal_id = $this->prep($calid);
2001-02-12 05:58:36 +01:00
2001-02-17 15:22:33 +01:00
if(!$cal_id)
{
return false;
}
2001-02-12 05:58:36 +01:00
2001-02-17 15:22:33 +01:00
$db2 = $phpgw->db;
$db2->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats'));
$calendar = CreateObject('calendar.calendar_item');
for($i=0;$i<count($cal_id);$i++)
{
$db2->query('SELECT * FROM calendar_entry WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__);
$db2->next_record();
$calendar->id = (int)$db2->f('cal_id');
$calendar->owner = $db2->f('cal_owner');
$calendar->datetime = $db2->f('cal_datetime');
// $date = $this->date_to_epoch($phpgw->common->show_date($calendar->datetime,'Ymd'));
$date = $this->localdates($calendar->datetime);
$calendar->day = $date['day'];
$calendar->month = $date['month'];
$calendar->year = $date['year'];
$time = $this->splittime($phpgw->common->show_date($calendar->datetime,'His'));
$calendar->hour = (int)$time['hour'];
$calendar->minute = (int)$time['minute'];
$calendar->ampm = $time['ampm'];
$calendar->mdatetime = $db2->f('cal_mdatetime');
// $date = $this->date_to_epoch($phpgw->common->show_date($calendar->mdatetime,'Ymd'));
$date = $this->localdates($calendar->mdatetime);
$calendar->mod_day = $date['day'];
$calendar->mod_month = $date['month'];
$calendar->mod_year = $date['year'];
$time = $this->splittime($phpgw->common->show_date($calendar->mdatetime,'His'));
$calendar->mod_hour = (int)$time['hour'];
$calendar->mod_minute = (int)$time['minute'];
$calendar->mod_second = (int)$time['second'];
$calendar->mod_ampm = $time['ampm'];
$calendar->edatetime = $db2->f('cal_edatetime');
// $date = $this->date_to_epoch($phpgw->common->show_date($calendar->edatetime,'Ymd'));
$date = $this->localdates($calendar->edatetime);
$calendar->end_day = $date['day'];
$calendar->end_month = $date['month'];
$calendar->end_year = $date['year'];
$time = $this->splittime($phpgw->common->show_date($calendar->edatetime,'His'));
$calendar->end_hour = (int)$time['hour'];
$calendar->end_minute = (int)$time['minute'];
$calendar->end_second = (int)$time['second'];
$calendar->end_ampm = $time['ampm'];
$calendar->priority = $db2->f('cal_priority');
2001-02-11 14:30:09 +01:00
// not loading webcal_entry.cal_type
2001-02-17 15:22:33 +01:00
$calendar->access = $db2->f('cal_access');
$calendar->name = htmlspecialchars(stripslashes($db2->f('cal_name')));
$calendar->description = htmlspecialchars(stripslashes($db2->f('cal_description')));
if($db2->f('cal_group'))
{
$groups = explode(',',$db2->f('cal_group'));
for($j=1;$j<count($groups) - 1;$j++)
{
$calendar->groups[] = $groups[$j];
}
}
$db2->query('SELECT * FROM calendar_entry_repeats WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__);
if($db2->num_rows())
{
$db2->next_record();
$rpt_type = strtolower($db2->f('cal_type'));
$calendar->rpt_type = !$rpt_type?'none':$rpt_type;
$calendar->rpt_use_end = $db2->f('cal_use_end');
if($calendar->rpt_use_end)
{
$calendar->rpt_end = $db2->f('cal_end');
$date = $this->localdates($db2->f('cal_end'));
$calendar->rpt_end_day = (int)$date['day'];
$calendar->rpt_end_month = (int)$date['month'];
$calendar->rpt_end_year = (int)$date['year'];
}
else
{
$calendar->rpt_end = 0;
$calendar->rpt_end_day = 0;
$calendar->rpt_end_month = 0;
$calendar->rpt_end_year = 0;
}
$calendar->rpt_freq = (int)$db2->f('cal_frequency');
$rpt_days = strtoupper($db2->f('cal_days'));
$calendar->rpt_days = $rpt_days;
$calendar->rpt_sun = (substr($rpt_days,0,1)=='Y'?1:0);
$calendar->rpt_mon = (substr($rpt_days,1,1)=='Y'?1:0);
$calendar->rpt_tue = (substr($rpt_days,2,1)=='Y'?1:0);
$calendar->rpt_wed = (substr($rpt_days,3,1)=='Y'?1:0);
$calendar->rpt_thu = (substr($rpt_days,4,1)=='Y'?1:0);
$calendar->rpt_fri = (substr($rpt_days,5,1)=='Y'?1:0);
$calendar->rpt_sat = (substr($rpt_days,6,1)=='Y'?1:0);
}
$db2->query('SELECT * FROM calendar_entry_user WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__);
if($db2->num_rows())
{
while($db2->next_record())
{
$calendar->participants[] = $db2->f('cal_login');
$calendar->status[] = $db2->f('cal_status');
}
}
$calendar_item[$i] = $calendar;
}
$db2->unlock();
return $calendar_item;
}
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
function findevent()
{
global $phpgw_info;
2001-02-11 14:30:09 +01:00
2001-02-17 15:22:33 +01:00
if(!$phpgw_info['user']['apps']['calendar'])
{
return false;
}
}
}
2001-02-11 14:30:09 +01:00
?>