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$ */
2001-05-20 03:20:40 +02:00
if ( @ $phpgw_info [ 'flags' ][ 'included_classes' ][ 'calendar_' ])
2001-03-17 20:39:56 +01:00
{
return ;
}
$phpgw_info [ 'flags' ][ 'included_classes' ][ 'calendar_' ] = True ;
2001-03-09 13:23:12 +01:00
class calendar_ extends calendar__
2001-02-18 23:33:10 +01:00
{
2001-03-10 05:48:19 +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
if ( $user == '' )
{
2001-03-13 06:03:50 +01:00
settype ( $user , 'integer' );
$user = $phpgw_info [ 'user' ][ 'account_id' ];
2001-02-18 23:33:10 +01:00
}
elseif ( is_int ( $user ))
{
$this -> user = $user ;
}
elseif ( is_string ( $user ))
{
$this -> user = $phpgw -> accounts -> name2id ( $user );
}
2001-03-13 06:03:50 +01:00
2001-06-01 05:55:05 +02:00
$this -> stream = $phpgw -> db ;
2001-02-18 23:33:10 +01:00
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-05-20 03:20:40 +02:00
function close ( $options = '' )
2001-02-12 05:58:36 +01:00
{
2001-02-18 23:33:10 +01:00
return True ;
2001-02-12 05:58:36 +01:00
}
2001-05-20 03:20:40 +02:00
function create_calendar ( $calendar = '' )
2001-02-12 05:58:36 +01:00
{
2001-02-18 23:33:10 +01:00
return $calendar ;
2001-02-12 05:58:36 +01:00
}
2001-05-20 03:20:40 +02:00
function rename_calendar ( $old_name = '' , $new_name = '' )
2001-02-18 23:33:10 +01:00
{
return $new_name ;
}
2001-02-12 05:58:36 +01:00
2001-05-20 03:20:40 +02:00
function delete_calendar ( $calendar = '' )
2001-02-18 23:33:10 +01:00
{
2001-05-09 05:21:14 +02:00
$this -> stream -> query ( 'SELECT cal_id FROM phpgw_cal WHERE owner=' . intval ( $calendar ), __LINE__ , __FILE__ );
2001-03-23 04:13:23 +01:00
if ( $this -> stream -> num_rows ())
{
while ( $this -> stream -> next_record ())
{
2001-05-20 03:20:40 +02:00
$this -> delete_event ( intval ( $this -> stream -> f ( 'cal_id' )));
2001-03-23 04:13:23 +01:00
}
2001-05-20 03:20:40 +02:00
$this -> expunge ();
2001-03-23 04:13:23 +01:00
}
2001-04-27 04:20:55 +02:00
$this -> stream -> lock ( array ( 'phpgw_cal_user' ));
2001-05-09 05:21:14 +02:00
$this -> stream -> query ( 'DELETE FROM phpgw_cal_user WHERE cal_login=' . intval ( $calendar ), __LINE__ , __FILE__ );
2001-03-23 04:13:23 +01:00
$this -> stream -> unlock ();
2001-02-18 23:33:10 +01:00
return $calendar ;
}
2001-02-12 05:58:36 +01:00
2001-05-20 03:20:40 +02:00
function fetch_event ( $event_id , $options = '' )
2001-02-12 05:58:36 +01:00
{
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-05-20 23:11:52 +02:00
2001-04-27 04:20:55 +02:00
$this -> stream -> lock ( array ( 'phpgw_cal' , 'phpgw_cal_user' , 'phpgw_cal_repeats' ));
2001-02-12 05:58:36 +01:00
2001-04-27 19:37:59 +02:00
$this -> stream -> query ( 'SELECT * FROM phpgw_cal WHERE cal_id=' . $event_id , __LINE__ , __FILE__ );
2001-02-18 23:33:10 +01:00
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 ;
2001-04-27 04:20:55 +02:00
$this -> event -> mod = new calendar_time ;
2001-03-02 05:20:41 +01:00
$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-05-20 23:11:52 +02:00
$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' )));
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-05-20 23:11:52 +02:00
$this -> add_attribute ( 'datetime' , intval ( $this -> stream -> f ( 'datetime' )));
2001-05-20 03:20:40 +02:00
$datetime = $this -> datetime -> localdates ( $this -> stream -> f ( 'datetime' ));
2001-05-20 23:11:52 +02:00
$this -> set_start ( $datetime [ 'year' ], $datetime [ 'month' ], $datetime [ 'day' ], $datetime [ 'hour' ], $datetime [ 'minute' ], $datetime [ 'second' ]);
2001-05-20 03:20:40 +02:00
$datetime = $this -> datetime -> localdates ( $this -> stream -> f ( 'mdatetime' ));
2001-04-27 04:20:55 +02:00
$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 ;
2001-05-20 23:11:52 +02:00
$this -> add_attribute ( 'edatetime' , intval ( $this -> stream -> f ( 'edatetime' )));
2001-05-20 03:20:40 +02:00
$datetime = $this -> datetime -> localdates ( $this -> stream -> f ( 'edatetime' ));
2001-05-20 23:11:52 +02:00
$this -> set_end ( $datetime [ 'year' ], $datetime [ 'month' ], $datetime [ 'day' ], $datetime [ 'hour' ], $datetime [ 'minute' ], $datetime [ 'second' ]);
2001-02-27 05:42:18 +01:00
//Legacy Support
2001-05-20 23:11:52 +02:00
$this -> add_attribute ( 'priority' , intval ( $this -> stream -> f ( 'priority' )));
2001-04-27 04:20:55 +02:00
if ( $this -> stream -> f ( 'cal_group' ) || $this -> stream -> f ( 'groups' ) != 'NULL' )
2001-02-27 05:42:18 +01:00
{
2001-04-27 04:20:55 +02:00
$groups = explode ( ',' , $this -> stream -> f ( 'groups' ));
2001-02-27 05:42:18 +01:00
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
}
}
2001-05-20 23:11:52 +02:00
2001-04-27 19:37:59 +02:00
$this -> stream -> query ( 'SELECT * FROM phpgw_cal_repeats WHERE cal_id=' . $event_id , __LINE__ , __FILE__ );
2001-02-27 05:42:18 +01:00
if ( $this -> stream -> num_rows ())
{
$this -> stream -> next_record ();
2001-04-27 04:20:55 +02:00
$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 )
2001-02-27 05:42:18 +01:00
{
2001-05-20 03:20:40 +02:00
$datetime = $this -> datetime -> localdates ( $enddate );
2001-04-27 04:20:55 +02:00
$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' ];
2001-03-02 05:20:41 +01:00
$this -> event -> recur_enddate -> alarm = 0 ;
2001-02-27 05:42:18 +01:00
}
else
{
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
}
2001-06-14 03:31:02 +02:00
// echo 'Event ID#'.$this->event->id.' : Enddate = '.$enddate."<br>\n";
2001-04-27 04:20:55 +02:00
$this -> event -> recur_data = $this -> stream -> f ( 'recur_data' );
2001-02-27 05:42:18 +01:00
}
//Legacy Support
2001-04-27 19:37:59 +02:00
$this -> stream -> query ( 'SELECT * FROM phpgw_cal_user WHERE cal_id=' . $event_id , __LINE__ , __FILE__ );
2001-02-27 05:42:18 +01:00
if ( $this -> stream -> num_rows ())
{
while ( $this -> stream -> next_record ())
{
2001-05-21 05:20:31 +02:00
if ( intval ( $this -> stream -> f ( 'cal_login' )) == intval ( $this -> user ))
2001-03-12 05:30:15 +01:00
{
2001-04-27 19:37:59 +02:00
$this -> event -> users_status = $this -> stream -> f ( 'cal_status' );
2001-03-12 05:30:15 +01:00
}
2001-05-31 06:34:00 +02:00
// $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' ));
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-02-24 16:56:52 +01:00
2001-03-02 05:20:41 +01:00
return $this -> event ;
2001-02-12 05:58:36 +01:00
}
2001-05-20 03:20:40 +02:00
function list_events ( $startYear , $startMonth , $startDay , $endYear = '' , $endMonth = '' , $endYear = '' )
2001-02-24 16:56:52 +01:00
{
if ( ! isset ( $this -> stream ))
{
return False ;
}
2001-05-20 03:20:40 +02:00
$datetime = $this -> datetime -> makegmttime ( 0 , 0 , 0 , $startMonth , $startDay , $startYear );
2001-04-27 04:20:55 +02:00
$startDate = ' AND (phpgw_cal.datetime >= ' . $datetime . ') ' ;
2001-02-24 16:56:52 +01:00
if ( $endYear != '' && $endMonth != '' && $endDay != '' )
{
2001-05-20 03:20:40 +02:00
$edatetime = $this -> datetime -> makegmttime ( 23 , 59 , 59 , intval ( $endMonth ), intval ( $endDay ), intval ( $endYear ));
2001-04-27 04:20:55 +02:00
$endDate = 'AND (phpgw_cal.edatetime <= ' . $edatetime . ') ' ;
2001-02-24 16:56:52 +01:00
}
else
{
$endDate = '' ;
}
2001-02-25 05:06:15 +01:00
return $this -> get_event_ids ( False , $startDate . $endDate );
}
2001-05-20 03:20:40 +02:00
function append_event ()
2001-03-01 04:49:13 +01:00
{
$this -> save_event ( $this -> event );
2001-03-09 13:23:12 +01:00
$this -> send_update ( MSG_ADDED , $this -> event -> participants , '' , $this -> event );
2001-03-01 04:49:13 +01:00
return $this -> event -> id ;
}
2001-05-20 03:20:40 +02:00
function store_event ()
2001-03-01 04:49:13 +01:00
{
2001-03-09 13:23:12 +01:00
if ( $this -> event -> id != 0 )
{
$new_event = $this -> event ;
2001-05-20 03:20:40 +02:00
$old_event = $this -> fetch_event ( $new_event -> id );
2001-03-09 13:23:12 +01:00
$this -> prepare_recipients ( $new_event , $old_event );
$this -> event = $new_event ;
}
else
{
2001-05-31 06:34:00 +02:00
while ( list ( $key , $value ) = each ( $this -> event -> participants ))
2001-04-19 19:45:54 +02:00
{
2001-05-31 06:34:00 +02:00
$this -> add_attribute ( 'participants[' . intval ( $key ) . ']' , 'U' );
2001-04-19 19:45:54 +02:00
}
2001-03-09 13:23:12 +01:00
$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-05-20 03:20:40 +02:00
function delete_event ( $event_id )
2001-03-01 05:13:30 +01:00
{
2001-03-10 05:48:19 +01:00
$this -> deleted_events [] = $event_id ;
2001-03-01 05:13:30 +01:00
}
2001-05-20 03:20:40 +02:00
function snooze ( $event_id )
2001-03-01 05:13:30 +01:00
{
//Turn off an alarm for an event
//Returns true.
}
2001-05-20 03:20:40 +02:00
function list_alarms ( $begin_year = '' , $begin_month = '' , $begin_day = '' , $end_year = '' , $end_month = '' , $end_day = '' )
2001-03-01 05:13:30 +01:00
{
//Return a list of events that has an alarm triggered at the given datetime
//Returns an array of event ID's
}
2001-03-04 05:13:04 +01:00
// The function definition doesn't look correct...
// Need more information for this function
2001-05-20 23:11:52 +02:00
function next_recurrence ( $weekstart , $next )
2001-03-04 05:13:04 +01:00
{
// return next_recurrence (int stream, int weekstart, array next);
}
2001-05-31 06:34:00 +02:00
function expunge ()
2001-03-04 05:13:04 +01:00
{
2001-03-10 05:48:19 +01:00
if ( count ( $this -> deleted_events ) <= 0 )
{
return 1 ;
}
$this_event = $this -> event ;
2001-04-27 04:20:55 +02:00
$locks = Array (
'phpgw_cal' ,
'phpgw_cal_user' ,
'phpgw_cal_repeats'
);
$this -> stream -> lock ( $locks );
2001-03-10 05:48:19 +01:00
for ( $i = 0 ; $i < count ( $this -> deleted_events ); $i ++ )
{
$event_id = $this -> deleted_events [ $i ];
2001-05-31 06:34:00 +02:00
$event = $this -> fetch_event ( $event_id );
2001-03-10 05:48:19 +01:00
$this -> send_update ( MSG_DELETED , $event -> participants , $event );
2001-04-27 04:20:55 +02:00
for ( $k = 0 ; $k < count ( $locks ); $k ++ )
{
2001-04-27 19:37:59 +02:00
$this -> stream -> query ( 'DELETE FROM ' . $locks [ $k ] . ' WHERE cal_id=' . $event_id , __LINE__ , __FILE__ );
2001-04-27 04:20:55 +02:00
}
2001-03-10 05:48:19 +01:00
}
$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 = '' )
{
if ( $search_repeats == True )
{
2001-04-27 04:20:55 +02:00
$repeats_from = ', phpgw_cal_repeats ' ;
2001-04-27 19:37:59 +02:00
$repeats_where = 'AND (phpgw_cal_repeats.cal_id = phpgw_cal.cal_id) ' ;
2001-02-25 05:06:15 +01:00
}
else
{
$repeats_from = ' ' ;
$repeats_where = '' ;
}
2001-04-27 19:37:59 +02:00
$sql = 'SELECT DISTINCT phpgw_cal.cal_id,'
2001-04-27 04:20:55 +02:00
. 'phpgw_cal.datetime,phpgw_cal.edatetime,'
. 'phpgw_cal.priority '
. 'FROM phpgw_cal, phpgw_cal_user'
2001-02-25 05:06:15 +01:00
. $repeats_from
2001-04-27 19:37:59 +02:00
. 'WHERE (phpgw_cal_user.cal_id = phpgw_cal.cal_id) '
2001-02-25 05:06:15 +01:00
. $repeats_where . $extra ;
$this -> stream -> query ( $sql , __LINE__ , __FILE__ );
if ( $this -> stream -> num_rows () == 0 )
{
return False ;
}
$retval = Array ();
while ( $this -> stream -> next_record ())
{
2001-04-27 19:37:59 +02:00
$retval [] = intval ( $this -> stream -> f ( 'cal_id' ));
2001-02-25 05:06:15 +01:00
}
return $retval ;
2001-02-24 16:56:52 +01:00
}
2001-03-01 04:49:13 +01:00
function save_event ( & $event )
{
global $phpgw_info ;
2001-04-27 04:20:55 +02:00
$locks = Array (
'phpgw_cal' ,
'phpgw_cal_user' ,
'phpgw_cal_repeats'
);
$this -> stream -> lock ( $locks );
2001-03-01 04:49:13 +01:00
if ( $event -> id == 0 )
{
$temp_name = tempnam ( $phpgw_info [ 'server' ][ 'temp_dir' ], 'cal' );
2001-05-03 01:23:48 +02:00
$this -> stream -> query ( 'INSERT INTO phpgw_cal(title,owner,priority,is_public) '
. " values(' " . $temp_name . " ', " . $event -> owner . " , " . $event -> priority . " , " . $event -> public . " ) " );
2001-04-27 19:37:59 +02:00
$this -> stream -> query ( " SELECT cal_id FROM phpgw_cal WHERE title=' " . $temp_name . " ' " );
2001-03-01 04:49:13 +01:00
$this -> stream -> next_record ();
2001-04-27 19:37:59 +02:00
$event -> id = $this -> stream -> f ( 'cal_id' );
2001-03-01 04:49:13 +01:00
}
2001-05-20 03:20:40 +02:00
$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 ;
2001-06-16 21:10:26 +02:00
// $today = time();
2001-03-01 04:49:13 +01:00
2001-06-14 03:31:02 +02:00
if ( $event -> recur_type != MCAL_RECUR_NONE )
2001-03-01 04:49:13 +01:00
{
$type = 'M' ;
}
else
{
$type = 'E' ;
}
2001-05-03 01:23:48 +02:00
$cat = '' ;
if ( $event -> category != 0 )
{
$cat = 'category=' . $event -> category . ', ' ;
}
2001-04-27 04:20:55 +02:00
$sql = 'UPDATE phpgw_cal SET '
. 'owner=' . $event -> owner . ', '
. 'datetime=' . $date . ', '
. 'mdatetime=' . $today . ', '
. 'edatetime=' . $enddate . ', '
. 'priority=' . $event -> priority . ', '
2001-05-03 01:23:48 +02:00
. $cat
2001-04-27 19:37:59 +02:00
. " cal_type=' " . $type . " ', "
. 'is_public=' . $event -> public . ', '
. " title=' " . addslashes ( $event -> title ) . " ', "
2001-04-27 04:20:55 +02:00
. " description=' " . addslashes ( $event -> description ) . " ' "
2001-04-27 19:37:59 +02:00
. 'WHERE cal_id=' . $event -> id ;
2001-03-01 04:49:13 +01:00
$this -> stream -> query ( $sql , __LINE__ , __FILE__ );
2001-04-27 19:37:59 +02:00
$this -> stream -> query ( 'DELETE FROM phpgw_cal_user WHERE cal_id=' . $event -> id , __LINE__ , __FILE__ );
2001-03-01 04:49:13 +01:00
2001-03-12 04:44:43 +01:00
reset ( $event -> participants );
2001-04-19 19:45:54 +02:00
while ( list ( $key , $value ) = each ( $event -> participants ))
2001-03-01 04:49:13 +01:00
{
2001-05-31 06:34:00 +02:00
if ( intval ( $key ) == intval ( $this -> user ))
2001-03-07 02:28:52 +01:00
{
2001-05-31 06:34:00 +02:00
$value = 'A' ;
2001-03-12 04:44:43 +01:00
}
2001-04-27 19:37:59 +02:00
$this -> stream -> query ( 'INSERT INTO phpgw_cal_user(cal_id,cal_login,cal_status) '
2001-05-31 06:34:00 +02:00
. 'VALUES(' . $event -> id . ',' . intval ( $key ) . " ,' " . $value . " ') " , __LINE__ , __FILE__ );
2001-03-01 04:49:13 +01:00
}
2001-06-14 03:31:02 +02:00
if ( $event -> recur_type != MCAL_RECUR_NONE )
2001-03-01 04:49:13 +01:00
{
2001-04-27 04:20:55 +02:00
if ( $event -> recur_enddate -> month != 0 && $event -> recur_enddate -> mday != 0 && $event -> recur_enddate -> year != 0 )
2001-03-01 04:49:13 +01:00
{
2001-05-20 03:20:40 +02: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 ) - $this -> datetime -> tz_offset ;
2001-03-01 04:49:13 +01:00
}
else
{
2001-06-16 21:10:26 +02:00
$end = 0 ;
2001-03-01 04:49:13 +01:00
}
2001-04-27 19:37:59 +02:00
$this -> stream -> query ( 'SELECT count(cal_id) FROM phpgw_cal_repeats WHERE cal_id=' . $event -> id , __LINE__ , __FILE__ );
2001-03-01 04:49:13 +01:00
$this -> stream -> next_record ();
$num_rows = $this -> stream -> f ( 0 );
if ( $num_rows == 0 )
{
2001-04-27 19:37:59 +02:00
$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__ );
2001-03-01 04:49:13 +01:00
}
else
{
2001-04-27 04:20:55 +02:00
$this -> stream -> query ( 'UPDATE phpgw_cal_repeats '
2001-04-27 19:37:59 +02:00
. '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__ );
2001-03-01 04:49:13 +01:00
}
}
else
{
2001-04-27 19:37:59 +02:00
$this -> stream -> query ( 'DELETE FROM phpgw_cal_repeats WHERE cal_id=' . $event -> id , __LINE__ , __FILE__ );
2001-03-01 04:49:13 +01:00
}
$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
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'
);
2001-05-16 19:40:20 +02:00
$temp_event = $this -> event ;
2001-05-21 05:20:31 +02:00
$old_event = $this -> fetch_event ( $id );
2001-05-16 19:40:20 +02:00
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 ;
2001-03-12 04:18:02 +01:00
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 ;
2001-04-27 04:20:55 +02:00
$groups = substr ( $phpgw -> common -> sql_search ( 'phpgw_cal.groups' , intval ( $owner )), 4 );
2001-02-17 15:22:33 +01:00
if ( ! $groups )
{
return '' ;
}
else
{
2001-04-27 04:47:54 +02:00
return " (phpgw_cal.is_public=2 AND ( " . $groups . ')) ' ;
2001-02-17 15:22:33 +01:00
}
}
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
2001-03-11 05:17:58 +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' ] = ' ' ;
2001-03-11 05:17:58 +01:00
if ( $follow_24_rule == True )
2001-02-17 15:22:33 +01:00
{
2001-03-11 05:17:58 +01:00
if ( $phpgw_info [ 'user' ][ 'preferences' ][ 'common' ][ 'timeformat' ] == '24' )
{
return $temp ;
}
2001-02-17 15:22:33 +01:00
2001-03-11 05:17:58 +01:00
$temp [ 'ampm' ] = 'am' ;
2001-02-17 15:22:33 +01:00
2001-03-11 05:17:58 +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 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
?>