2
/* $Id: freebusy.php,v 1.30.2.6 2007/11/12 15:40:31 umcesrjones Exp $
5
* Creates the iCal free/busy schedule a single user.
6
* Free/busy schedules are specified in the iCal RFC 2445.
9
* URL should be the form of /xxx/freebusy.php/username.ifb
10
* or /xxx/freebusy.php?user=username
11
* Some servers seem to have problem with username.ifb version.
12
* If so, they should user the second form.
15
* For now, we use a date range of the start of the current
16
* month and include one year from there.
17
* Rather arbitrary, eh???
19
* To read the iCal specification:
20
* http://www.ietf.org/rfc/rfc2445.txt
22
* WebCalendar does not use freebusy info for scheduling right now.
23
* But, this may change in the future.
25
* We might want to cache this type of information after a calendar is updated.
26
* This would make conflict checking much faster,
27
* particularly for events with many participants.
29
* Developers/Debugging:
30
* You can test this script from the command line if you have the command-line PHP.
31
* Create a symbolic link with a valid username,
32
* and then invoke the PHP command using the link as a parameter:
33
* ln -s freebusy.php cknudsen.ifb
37
* Users do need to enable "Enable FreeBusy publishing" in their
38
* preferences or this page will generate a "You are not authorized"
41
* If $FREEBUSY_ENABLED is not 'Y' (set in each user' Preferences), do not allow.
44
include 'includes/translate.php';
45
require_once 'includes/classes/WebCalendar.class';
46
require_once 'includes/classes/Event.class';
47
require_once 'includes/classes/RptEvent.class';
49
$WebCalendar =& new WebCalendar ( __FILE__ );
51
include 'includes/config.php';
52
include 'includes/dbi4php.php';
53
include 'includes/formvars.php';
54
include 'includes/functions.php';
56
$WebCalendar->initializeFirstPhase ();
58
include 'includes/' . $user_inc;
59
include 'includes/validate.php';
60
include 'includes/site_extras.php';
61
include 'includes/xcal.php';
63
$WebCalendar->initializeSecondPhase ();
65
// Calculate username.
66
// If using http_auth, use those credentials.
67
if ( $use_http_auth && empty ( $user ) )
70
if ( empty ( $user ) ) {
71
$arr = explode ( '/', $PHP_SELF );
72
$user = $arr[count ( $arr )-1];
73
# Remove any trailing ".ifb" in user name.
74
$user = preg_replace ( '/\.[iI][fF][bB]$/', '', $user );
77
if ( $user == 'public' )
80
load_global_settings ();
82
// Load user preferences (to get the DISPLAY_UNAPPROVED and
83
// FREEBUSY_ENABLED pref for this user).
85
load_user_preferences ();
87
$WebCalendar->setLanguage ();
89
// Load user name, etc.
90
user_load_variables ( $user, 'publish_' );
92
if ( empty ( $FREEBUSY_ENABLED ) || $FREEBUSY_ENABLED != 'Y' ) {
93
header ( 'Content-Type: text/plain' );
94
echo 'user=' . $user . "\n" . print_not_auth (19);
98
// Make sure they specified a username.
99
$no_user = translate ( 'No user specified.' );
100
if ( empty ( $user ) )
101
die_miserable_death ( $no_user );
103
$get_unapproved = false;
104
$datem = date ( 'm' );
105
$dateY = date ( 'Y' );
106
// Start date is beginning of this month.
107
$startdate = mktime ( 0, 0, 0, $datem, 0, $dateY );
109
// End date is one year from now.
110
// Seems kind of arbitrary, eh?
111
$enddate = mktime ( 0, 0, 0, $datem, 1, $dateY + 1 );
113
/* Pre-Load the repeated events for quicker access. */
114
$repeated_events = read_repeated_events ( $user, $startdate, $enddate, '' );
116
/* Pre-load the non-repeating events for quicker access. */
117
$events = read_events ( $user, $startdate, $enddate );
119
// Loop from start date until we reach end date...
121
for ( $d = $startdate; $d <= $enddate; $d += 86400 ) {
122
$dYmd = date ( 'Ymd', $d );
123
$ev = get_entries ( $dYmd, $get_unapproved );
124
$evcnt = count ( $ev );
125
for ( $i = 0; $i < $evcnt; $i++ ) {
126
$event_text .= fb_export_time ( $dYmd, $ev[$i]->getDuration (),
127
$ev[$i]->getTime (), 'ical' );
129
$revents = get_repeating_entries ( $user, $dYmd, $get_unapproved );
130
$recnt = count ( $revents );
131
for ( $i = 0; $i < $recnt; $i++ ) {
132
$event_text .= fb_export_time ( $dYmd, $revents[$i]->getDuration (),
133
$revents[$i]->getTime (), 'ical' );
137
header ( 'Content-Type: text/calendar' );
138
header ( 'Content-Disposition: attachment; filename="' . $login . '.ifb"' );
139
echo 'BEGIN:VCALENDAR' . "\r\n"
140
. 'X-WR-CALNAME;VALUE=TEXT:' . str_replace ( ',', '\\,',
141
( empty ( $publish_fullname ) ? $user : translate ( $publish_fullname ) ) ) . "\r\n"
143
. 'VERSION:2.0' . "\r\n"
144
. 'METHOD:PUBLISH' . "\r\n"
145
. 'BEGIN:VFREEBUSY' . "\r\n"
146
. 'DTSTART:' . export_get_utc_date ( date ( 'Ymd', $startdate ), 0 ) . "\r\n"
147
. 'DTEND:' . export_get_utc_date ( date ( 'Ymd', $enddate ), '235959' ) . "\r\n"
149
. 'URL:' . $GLOBALS['SERVER_URL'] . 'freebusy.php/' . $user . '.ifb' . "\r\n"
150
. 'END:VFREEBUSY' . "\r\n"
151
. 'END:VCALENDAR' . "\r\n";