WebCalendar PHP Cross Reference Groupware Applications

Source: /freebusy.php - 155 lines - 4929 bytes - Summary - Text - Print

   1  <?php
   2  /* $Id: freebusy.php,v 1.30.2.7 2011/04/27 00:27:35 rjones6061 Exp $
   3   *
   4   * Description:
   5   * Creates the iCal free/busy schedule a single user.
   6   * Free/busy schedules are specified in the iCal RFC 2445.
   7   *
   8   * Input parameters:
   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.
  13   *
  14   * Notes:
  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???
  18   *
  19   * To read the iCal specification:
  20   *   http://www.ietf.org/rfc/rfc2445.txt
  21   *
  22   * WebCalendar does not use freebusy info for scheduling right now.
  23   * But, this may change in the future.
  24   *
  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.
  28   *
  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
  34   *  php cknudsen.ifb
  35   *
  36   * Security:
  37   * Users do need to enable "Enable FreeBusy publishing" in their
  38   * preferences or this page will generate a "You are not authorized"
  39   * error message.
  40   *
  41   * If $FREEBUSY_ENABLED is not 'Y' (set in each user' Preferences), do not allow.
  42   */
  43  
  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';
  48  
  49  $WebCalendar = new WebCalendar ( __FILE__ );
  50  
  51  include  'includes/config.php';
  52  include  'includes/dbi4php.php';
  53  include  'includes/formvars.php';
  54  include  'includes/functions.php';
  55  
  56  $WebCalendar->initializeFirstPhase ();
  57  
  58  include 'includes/' . $user_inc;
  59  include  'includes/validate.php';
  60  include  'includes/site_extras.php';
  61  include  'includes/xcal.php';
  62  
  63  $WebCalendar->initializeSecondPhase ();
  64  
  65  // Calculate username.
  66  // If using http_auth, use those credentials.
  67  if ( $use_http_auth && empty ( $user ) )
  68    $user = $login;
  69  
  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 );
  75  }
  76  
  77  if ( $user == 'public' )
  78    $user = '__public__';
  79  
  80  load_global_settings ();
  81  
  82  // Load user preferences (to get the DISPLAY_UNAPPROVED and
  83  // FREEBUSY_ENABLED pref for this user).
  84  $login = $user;
  85  load_user_preferences ();
  86  
  87  $WebCalendar->setLanguage ();
  88  
  89  // Load user name, etc.
  90  user_load_variables ( $user, 'publish_' );
  91  
  92  if ( empty ( $FREEBUSY_ENABLED ) || $FREEBUSY_ENABLED != 'Y' ) {
  93    header ( 'Content-Type: text/plain' );
  94    echo 'user=' . $user . "\n" . print_not_auth (19);
  95    exit;
  96  }
  97  
  98  // Make sure they specified a username.
  99  $no_user = translate ( 'No user specified.' );
 100  if ( empty ( $user ) )
 101    die_miserable_death ( $no_user );
 102  
 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 );
 108  
 109  // End date is one year from now.
 110  // Seems kind of arbitrary, eh?
 111  $enddate = mktime ( 0, 0, 0, $datem, 1, $dateY + 1 );
 112  
 113  /* Pre-Load the repeated events for quicker access. */
 114  $repeated_events = read_repeated_events ( $user, $startdate, $enddate, '' );
 115  
 116  /* Pre-load the non-repeating events for quicker access. */
 117  $events = read_events ( $user, $startdate, $enddate );
 118  
 119  // Loop from start date until we reach end date...
 120  $event_text = '';
 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' );
 128    }
 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' );
 134    }
 135  }
 136  
 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"
 142   . generate_prodid ()
 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"
 148   . $event_text
 149   . 'URL:' . $GLOBALS['SERVER_URL'] . 'freebusy.php/' . $user . '.ifb' . "\r\n"
 150   . 'END:VFREEBUSY' . "\r\n"
 151   . 'END:VCALENDAR' . "\r\n";
 152  
 153  exit;
 154  
 155  ?>

title

Description

title

Description

title

Description

title

title

Body