function get_vcal_freebusy($user_focus, $cached = true) { global $locale; $str = "BEGIN:VCALENDAR\n"; $str .= "VERSION:2.0\n"; $str .= "PRODID:-//SugarCRM//SugarCRM Calendar//EN\n"; $str .= "BEGIN:VFREEBUSY\n"; $name = $locale->getLocaleFormattedName($user_focus->first_name, $user_focus->last_name); $email = $user_focus->email1; // get current date for the user $now_date_time = new DateTimeUtil(array(), true); // get start date GMT ( 1 day ago ) $date_arr = array('day' => $now_date_time->day - 1, 'month' => $now_date_time->month, 'hour' => $now_date_time->hour, 'min' => $now_date_time->min, 'year' => $now_date_time->year); $start_date_time = new DateTimeUtil($date_arr, true); // get date 2 months from start date global $sugar_config; $timeOffset = 0; if (isset($sugar_config['vcal_time']) && $sugar_config['vcal_time'] != 0 && $sugar_config['vcal_time'] < 13) { $timeOffset = $sugar_config['vcal_time']; } $date_arr = array('day' => $start_date_time->day, 'month' => $start_date_time->month + $timeOffset, 'hour' => $start_date_time->hour, 'min' => $start_date_time->min, 'year' => $start_date_time->year); $end_date_time = new DateTimeUtil($date_arr, true); // get UTC time format $utc_start_time = $start_date_time->get_utc_date_time(); $utc_end_time = $end_date_time->get_utc_date_time(); $utc_now_time = $now_date_time->get_utc_date_time(); $str .= "ORGANIZER;CN={$name}:{$email}\n"; $str .= "DTSTART:{$utc_start_time}\n"; $str .= "DTEND:{$utc_end_time}\n"; // now insert the freebusy lines // retrieve cached freebusy lines from vcals if ($timeOffset != 0) { if ($cached == true) { $str .= $this->get_freebusy_lines_cache($user_focus); } else { $str .= $this->create_sugar_freebusy($user_focus, $start_date_time, $end_date_time); } } // UID:20030724T213406Z-10358-1000-1-12@phoenix $str .= "DTSTAMP:{$utc_now_time}\n"; $str .= "END:VFREEBUSY\n"; $str .= "END:VCALENDAR\n"; return $str; }
function get_vcal_freebusy(&$user_focus, $cached = true) { $str = "BEGIN:VCALENDAR\n"; $str .= "VERSION:2.0\n"; $str .= "PRODID:-//SugarCRM//SugarCRM Calendar//EN\n"; $str .= "BEGIN:VFREEBUSY\n"; $name = $user_focus->first_name . " " . $user_focus->last_name; $email = $user_focus->email1; // get current time local $date_arr = array(); $now_date_time_local = new DateTimeUtil($date_arr, true); // get current time GMT $date_arr = array('ts' => $now_date_time_local->ts - $now_date_time_local->tz_offset); $now_date_time = new DateTimeUtil($date_arr, true); // get start date GMT ( 1 day ago ) $date_arr = array('day' => $now_date_time->day - 1, 'month' => $now_date_time->month, 'hour' => $now_date_time->hour, 'min' => $now_date_time->min, 'year' => $now_date_time->year); $start_date_time = new DateTimeUtil($date_arr, true); // get date 2 months from start date $date_arr = array('day' => $start_date_time->day, 'month' => $start_date_time->month + 2, 'hour' => $start_date_time->hour, 'min' => $start_date_time->min, 'year' => $start_date_time->year); $end_date_time = new DateTimeUtil($date_arr, true); // get UTC time format $utc_start_time = $start_date_time->get_utc_date_time(); $utc_end_time = $end_date_time->get_utc_date_time(); $utc_now_time = $now_date_time->get_utc_date_time(); $str .= "ORGANIZER;CN={$name}:{$email}\n"; $str .= "DTSTART:{$utc_start_time}\n"; $str .= "DTEND:{$utc_end_time}\n"; // now insert the freebusy lines // retrieve cached freebusy lines from vcals if ($cached == true) { $str .= $this->get_freebusy_lines_cache($user_focus); } else { $str .= $this->create_sugar_freebusy($user_focus, $start_date_time, $end_date_time); } // UID:20030724T213406Z-10358-1000-1-12@phoenix $str .= "DTSTAMP:{$utc_now_time}\n"; $str .= "END:VFREEBUSY\n"; $str .= "END:VCALENDAR\n"; return $str; }