2000-08-18 05:24:22 +02:00
< ? php
/************************************************************************** \
* phpGroupWare - Calendar *
* http :// www . phpgroupware . org *
* Based on Webcalendar by Craig Knudsen < cknudsen @ radix . net > *
* http :// www . radix . net /~ cknudsen *
2001-01-17 13:35:43 +01:00
* Modified by Mark Peters < skeeter @ phpgroupware . org > *
2000-08-18 05:24:22 +02:00
* -------------------------------------------- *
* This program is free software ; you can redistribute it and / or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation ; either version 2 of the License , or ( at your *
* option ) any later version . *
\ **************************************************************************/
/* $Id$ */
2001-02-18 23:33:10 +01:00
$phpgw_flags = Array (
2001-04-27 04:20:55 +02:00
'currentapp' => 'calendar' ,
'noheader' => True ,
'nonavbar' => True ,
'enable_nextmatchs_class' => True ,
'enable_categories_class' => True ,
'noappheader' => True ,
'noappfooter' => True
2001-02-18 23:33:10 +01:00
);
$phpgw_info [ 'flags' ] = $phpgw_flags ;
include ( '../header.inc.php' );
2001-03-31 16:30:13 +02:00
$event = CreateObject ( 'calendar.calendar_item' );
2001-02-18 23:33:10 +01:00
2001-03-10 05:48:19 +01:00
function validate ( $event )
2001-02-18 23:33:10 +01:00
{
2001-03-04 05:13:04 +01:00
global $phpgw ;
2001-02-18 23:33:10 +01:00
$error = 0 ;
// do a little form verifying
2001-03-10 05:48:19 +01:00
if ( $event -> title == '' )
2001-02-18 23:33:10 +01:00
{
$error = 40 ;
}
2001-05-20 23:11:52 +02:00
elseif (( $phpgw -> calendar -> datetime -> time_valid ( $event -> start -> hour , $event -> start -> min , 0 ) == False ) || ( $phpgw -> calendar -> datetime -> time_valid ( $event -> end -> hour , $event -> end -> min , 0 ) == False ))
2001-02-18 23:33:10 +01:00
{
$error = 41 ;
}
2001-05-20 23:11:52 +02:00
elseif (( $phpgw -> calendar -> datetime -> date_valid ( $event -> start -> year , $event -> start -> month , $event -> start -> mday ) == False ) || ( $phpgw -> calendar -> datetime -> date_valid ( $event -> end -> year , $event -> end -> month , $event -> end -> mday ) == False ) || ( $phpgw -> calendar -> datetime -> date_compare ( $event -> start -> year , $event -> start -> month , $event -> start -> mday , $event -> end -> year , $event -> end -> month , $event -> end -> mday ) == 1 ))
2001-02-18 23:33:10 +01:00
{
$error = 42 ;
}
2001-05-20 23:11:52 +02:00
elseif ( $phpgw -> calendar -> datetime -> date_compare ( $event -> start -> year , $event -> start -> month , $event -> start -> mday , $event -> end -> year , $event -> end -> month , $event -> end -> mday ) == 0 )
2001-02-18 23:33:10 +01:00
{
2001-05-20 23:11:52 +02:00
if ( $phpgw -> calendar -> datetime -> time_compare ( $event -> start -> hour , $event -> start -> min , 0 , $event -> end -> hour , $event -> end -> min , 0 ) == 1 )
2001-02-18 23:33:10 +01:00
{
$error = 42 ;
}
}
return $error ;
}
if ( ! isset ( $readsess ))
{
2001-03-10 05:48:19 +01:00
if ( $phpgw_info [ 'user' ][ 'preferences' ][ 'common' ][ 'timeformat' ] == '12' )
{
if ( $start [ ampm ] == 'pm' )
{
if ( $start [ hour ] <> 12 )
{
$start [ hour ] += 12 ;
}
}
elseif ( $start [ ampm ] == 'am' )
{
if ( $start [ hour ] == 12 )
{
$start [ hour ] -= 12 ;
}
}
2001-03-22 02:36:47 +01:00
if ( $start [ hour ] > 24 )
{
$start [ hour ] -= 12 ;
}
2001-03-10 05:48:19 +01:00
if ( $end [ ampm ] == 'pm' )
{
if ( $end [ hour ] <> 12 )
{
$end [ hour ] += 12 ;
}
}
elseif ( $end [ ampm ] == 'am' )
{
if ( $end [ hour ] == 12 )
{
$end [ hour ] -= 12 ;
}
}
2001-03-22 02:36:47 +01:00
if ( $end [ hour ] > 24 )
{
$end [ hour ] -= 12 ;
}
2001-03-10 05:48:19 +01:00
}
2001-03-15 03:46:04 +01:00
if ( ! isset ( $private ))
{
$private = 'public' ;
}
2001-04-27 19:37:59 +02:00
$is_public = ( $private == 'public' ? 1 : 0 );
2001-05-20 23:11:52 +02:00
$phpgw -> calendar -> open ( 'INBOX' , intval ( $owner ), '' );
$phpgw -> calendar -> event_init ();
$phpgw -> calendar -> set_category ( $category );
$phpgw -> calendar -> set_title ( $title );
$phpgw -> calendar -> set_description ( $description );
$phpgw -> calendar -> set_start ( $start [ year ], $start [ month ], $start [ mday ], $start [ hour ], $start [ min ], 0 );
$phpgw -> calendar -> set_end ( $end [ year ], $end [ month ], $end [ mday ], $end [ hour ], $end [ min ], 0 );
$phpgw -> calendar -> set_class ( $is_public );
2001-03-10 05:48:19 +01:00
if ( $id != 0 )
2001-02-18 23:33:10 +01:00
{
2001-05-20 23:11:52 +02:00
$phpgw -> calendar -> add_attribute ( 'id' , $id );
2001-02-18 23:33:10 +01:00
}
2001-04-14 04:05:54 +02:00
if ( $rpt_use_end != 'y' )
{
$recur_enddate [ year ] = 0 ;
$recur_enddate [ month ] = 0 ;
$recur_enddate [ mday ] = 0 ;
}
2001-04-14 04:57:51 +02:00
$recur_data = $cal [ rpt_sun ] + $cal [ rpt_mon ] + $cal [ rpt_tue ] + $cal [ rpt_wed ] + $cal [ rpt_thu ] + $cal [ rpt_fri ] + $cal [ rpt_sat ];
2001-03-10 05:48:19 +01:00
switch ( $recur_type )
{
2001-06-16 21:07:12 +02:00
case MCAL_RECUR_NONE :
2001-05-20 23:11:52 +02:00
$phpgw -> calendar -> set_recur_none ();
2001-03-10 05:48:19 +01:00
break ;
2001-06-16 21:07:12 +02:00
case MCAL_RECUR_DAILY :
2001-05-20 23:11:52 +02:00
$phpgw -> calendar -> set_recur_daily ( $recur_enddate [ year ], $recur_enddate [ month ], $recur_enddate [ mday ], $recur_interval );
2001-03-10 05:48:19 +01:00
break ;
2001-06-16 21:07:12 +02:00
case MCAL_RECUR_WEEKLY :
2001-05-20 23:11:52 +02:00
$phpgw -> calendar -> set_recur_weekly ( $recur_enddate [ year ], $recur_enddate [ month ], $recur_enddate [ mday ], $recur_interval , $recur_data );
2001-03-10 05:48:19 +01:00
break ;
2001-06-16 21:07:12 +02:00
case MCAL_RECUR_MONTHLY_MDAY :
2001-05-20 23:11:52 +02:00
$phpgw -> calendar -> set_recur_monthly_mday ( $recur_enddate [ year ], $recur_enddate [ month ], $recur_enddate [ mday ], $recur_interval );
2001-03-10 05:48:19 +01:00
break ;
2001-06-16 21:07:12 +02:00
case MCAL_RECUR_MONTHLY_WDAY :
2001-05-20 23:11:52 +02:00
$phpgw -> calendar -> set_recur_monthly_wday ( $recur_enddate [ year ], $recur_enddate [ month ], $recur_enddate [ mday ], $recur_interval );
2001-03-10 05:48:19 +01:00
break ;
2001-06-16 21:07:12 +02:00
case MCAL_RECUR_YEARLY :
2001-05-20 23:11:52 +02:00
$phpgw -> calendar -> set_recur_yearly ( $recur_enddate [ year ], $recur_enddate [ month ], $recur_enddate [ mday ], $recur_interval );
2001-03-10 05:48:19 +01:00
break ;
}
2001-02-19 00:29:12 +01:00
2001-03-10 05:48:19 +01:00
$parts = $participants ;
2001-02-19 00:29:12 +01:00
$part = Array ();
for ( $i = 0 ; $i < count ( $parts ); $i ++ )
{
$acct_type = $phpgw -> accounts -> get_type ( intval ( $parts [ $i ]));
if ( $acct_type == 'u' )
{
$part [ $parts [ $i ]] = 1 ;
}
elseif ( $acct_type == 'g' )
{
$acct = CreateObject ( 'phpgwapi.accounts' , intval ( $parts [ $i ]));
$members = $acct -> members ( intval ( $parts [ $i ]));
unset ( $acct );
if ( $members == False )
{
continue ;
}
while ( $member = each ( $members ))
{
$part [ $member [ 1 ][ 'account_id' ]] = 1 ;
}
}
}
2001-06-16 21:07:12 +02:00
@ reset ( $part );
2001-05-31 06:34:00 +02:00
while ( list ( $key , $value ) = each ( $part ))
2001-02-19 00:29:12 +01:00
{
2001-05-31 06:34:00 +02:00
$phpgw -> calendar -> add_attribute ( 'participants[' . $key . ']' , 'U' );
2001-02-19 00:29:12 +01:00
}
2001-03-04 05:13:04 +01:00
2001-06-29 02:24:21 +02:00
reset ( $participants );
if ( !@ $phpgw -> calendar -> event -> participants [ $owner ])
{
2001-07-22 02:03:19 +02:00
$phpgw -> calendar -> add_attribute ( 'owner' , min ( $part ));
2001-06-29 02:24:21 +02:00
}
2001-05-20 23:11:52 +02:00
$phpgw -> calendar -> add_attribute ( 'priority' , $priority );
2001-03-10 05:48:19 +01:00
$event = $phpgw -> calendar -> event ;
2001-02-18 23:33:10 +01:00
2001-03-10 05:48:19 +01:00
$phpgw -> session -> appsession ( 'entry' , 'calendar' , $event );
2001-02-18 23:33:10 +01:00
2001-03-10 05:48:19 +01:00
$datetime_check = validate ( $event );
2001-06-16 21:07:12 +02:00
if ( $datetime_check )
{
Header ( 'Location: ' . $phpgw -> link ( '/calendar/edit_entry.php' , 'readsess=' . $event -> id . '&cd=' . $datetime_check ));
}
2001-05-20 23:11:52 +02:00
$start = mktime ( $event -> start -> hour , $event -> start -> min , $event -> start -> sec , $event -> start -> month , $event -> start -> mday , $event -> start -> year ) - $phpgw -> calendar -> datetime -> tz_offset ;
$end = mktime ( $event -> end -> hour , $event -> end -> min , $event -> end -> sec , $event -> end -> month , $event -> end -> mday , $event -> end -> year ) - $phpgw -> calendar -> datetime -> tz_offset ;
2001-03-10 05:48:19 +01:00
$overlapping_events = $phpgw -> calendar -> overlap ( $start , $end , $event -> participants , $event -> owner , $event -> id );
2001-06-16 21:07:12 +02:00
2001-02-18 23:33:10 +01:00
}
else
{
2001-05-20 23:11:52 +02:00
$phpgw -> calendar -> open ( 'INBOX' , intval ( $owner ), '' );
$phpgw -> calendar -> event_init ();
2001-07-10 02:26:33 +02:00
$event = unserialize ( str_replace ( 'O:8:"stdClass"' , 'O:13:"calendar_time"' , serialize ( $phpgw -> session -> appsession ( 'entry' , 'calendar' ))));
2001-03-18 19:32:54 +01:00
$phpgw -> calendar -> event = $event ;
2001-03-31 16:30:13 +02:00
$datetime_check = validate ( $event );
2001-06-16 21:07:12 +02:00
if ( $datetime_check )
{
Header ( 'Location: ' . $phpgw -> link ( '/calendar/edit_entry.php' , 'readsess=' . $event -> id . '&cd=' . $datetime_check ));
}
2001-02-18 23:33:10 +01:00
}
2001-06-16 21:07:12 +02:00
if ( count ( $overlapping_events ) > 0 && $overlapping_events != False )
{
2001-02-18 23:33:10 +01:00
$phpgw -> common -> phpgw_header ();
echo parse_navbar ();
$p = CreateObject ( 'phpgwapi.Template' , $phpgw -> common -> get_tpl_dir ( 'calendar' ));
$templates = Array (
'overlap' => 'overlap.tpl' ,
'form_button' => 'form_button_script.tpl'
);
$p -> set_file ( $templates );
$p -> set_var ( 'color' , $phpgw_info [ 'theme' ][ 'bg_text' ]);
2001-05-17 03:14:29 +02:00
$p -> set_var ( 'overlap_title' , lang ( 'Scheduling Conflict' ));
2001-02-18 23:33:10 +01:00
2001-05-21 05:20:31 +02:00
$phpgw -> calendar -> open ( 'INBOX' , intval ( $owner ), '' );
2001-02-18 23:33:10 +01:00
$overlap = '' ;
2001-03-10 05:48:19 +01:00
for ( $i = 0 ; $i < count ( $overlapping_events ); $i ++ )
2001-02-18 23:33:10 +01:00
{
2001-05-21 05:20:31 +02:00
$over = $phpgw -> calendar -> fetch_event ( $overlapping_events [ $i ]);
2001-05-13 05:54:17 +02:00
$overlap .= '<li>' . $phpgw -> calendar -> link_to_entry ( $over , $event -> start -> month , $event -> start -> mday , $event -> start -> year );
2001-02-18 23:33:10 +01:00
}
2001-03-10 05:48:19 +01:00
if ( strlen ( $overlap ) > 0 )
2001-02-18 23:33:10 +01:00
{
$var = Array (
2001-03-10 05:48:19 +01:00
'overlap_text' => lang ( 'Your suggested time of <B> x - x </B> conflicts with the following existing calendar entries:' , $phpgw -> common -> show_date ( $start ), $phpgw -> common -> show_date ( $end )),
2001-02-18 23:33:10 +01:00
'overlap_list' => $overlap
);
}
else
{
$var = Array (
'overlap_text' => '' ,
'overlap_list' => ''
);
}
$p -> set_var ( $var );
2001-03-10 05:48:19 +01:00
$phpgw -> calendar -> event = $event ;
2001-02-18 23:33:10 +01:00
$var = Array (
2001-04-28 23:56:24 +02:00
'action_url_button' => $phpgw -> link ( '/calendar/edit_entry_handler.php' , 'readsess=' . $event -> id . '&year=' . $event -> start -> year . '&month=' . $event -> start -> month . '&day=' . $event -> start -> mday ),
'action_text_button' => lang ( 'Ignore Conflict' ),
'action_confirm_button' => '' ,
2001-05-01 00:00:22 +02:00
'action_extra_field' => ''
2001-02-18 23:33:10 +01:00
);
$p -> set_var ( $var );
$p -> parse ( 'resubmit_button' , 'form_button' );
$var = Array (
2001-04-28 23:56:24 +02:00
'action_url_button' => $phpgw -> link ( '/calendar/edit_entry.php' , 'readsess=' . $event -> id . '&year=' . $event -> start -> year . '&month=' . $event -> start -> month . '&day=' . $event -> start -> mday ),
'action_text_button' => lang ( 'Re-Edit Event' ),
'action_confirm_button' => '' ,
'action_extra_field' => ''
2001-02-18 23:33:10 +01:00
);
$p -> set_var ( $var );
$p -> parse ( 'reedit_button' , 'form_button' );
$p -> pparse ( 'out' , 'overlap' );
2001-05-14 05:58:11 +02:00
$phpgw_info [ 'flags' ][ 'nofooter' ] = False ;
$phpgw -> common -> phpgw_footer ();
2001-02-18 23:33:10 +01:00
}
else
{
2001-05-20 23:11:52 +02:00
$phpgw -> calendar -> store_event ();
2001-03-10 05:48:19 +01:00
Header ( 'Location: ' . $phpgw -> link ( '/' . $phpgw_info [ 'flags' ][ 'currentapp' ] . '/index.php' , 'year=' . $event -> start -> year . '&month=' . $event -> start -> month . '&day=' . $event -> start -> mday . '&cd=14&owner=' . $owner ));
2001-02-18 23:33:10 +01:00
}
2000-10-09 21:09:44 +02:00
?>