Changeset View
Changeset View
Standalone View
Standalone View
plugins/calendar/calendar.php
Show First 20 Lines • Show All 2,179 Lines • ▼ Show 20 Lines | public function freebusy_status() | ||||
if (!$start) $start = time(); | if (!$start) $start = time(); | ||||
if (!$end) $end = $start + 3600; | if (!$end) $end = $start + 3600; | ||||
$fbtypemap = array(calendar::FREEBUSY_UNKNOWN => 'UNKNOWN', calendar::FREEBUSY_FREE => 'FREE', calendar::FREEBUSY_BUSY => 'BUSY', calendar::FREEBUSY_TENTATIVE => 'TENTATIVE', calendar::FREEBUSY_OOF => 'OUT-OF-OFFICE'); | $fbtypemap = array(calendar::FREEBUSY_UNKNOWN => 'UNKNOWN', calendar::FREEBUSY_FREE => 'FREE', calendar::FREEBUSY_BUSY => 'BUSY', calendar::FREEBUSY_TENTATIVE => 'TENTATIVE', calendar::FREEBUSY_OOF => 'OUT-OF-OFFICE'); | ||||
$status = 'UNKNOWN'; | $status = 'UNKNOWN'; | ||||
// if the backend has free-busy information | // if the backend has free-busy information | ||||
$fblist = $this->driver->get_freebusy_list($email, $start, $end); | $fblist = $this->driver->get_freebusy_list($email, $start, $end); | ||||
if (is_array($fblist)) { | if (is_array($fblist)) { | ||||
$status = 'FREE'; | $status = 'FREE'; | ||||
foreach ($fblist as $slot) { | foreach ($fblist as $slot) { | ||||
list($from, $to, $type) = $slot; | list($from, $to, $type) = $slot; | ||||
if ($from < $end && $to > $start) { | if ($from < $end && $to > $start) { | ||||
$status = isset($type) && $fbtypemap[$type] ? $fbtypemap[$type] : 'BUSY'; | $status = isset($type) && $fbtypemap[$type] ? $fbtypemap[$type] : 'BUSY'; | ||||
break; | break; | ||||
Show All 33 Lines | public function freebusy_times() | ||||
if (!$start) $start = time(); | if (!$start) $start = time(); | ||||
if (!$end) $end = $start + 86400 * 30; | if (!$end) $end = $start + 86400 * 30; | ||||
if (!$interval) $interval = 60; // 1 hour | if (!$interval) $interval = 60; // 1 hour | ||||
if (!$dte) { | if (!$dte) { | ||||
$dts = new DateTime('@'.$start); | $dts = new DateTime('@'.$start); | ||||
$dts->setTimezone($this->timezone); | $dts->setTimezone($this->timezone); | ||||
} | } | ||||
$fblist = $this->driver->get_freebusy_list($email, $start, $end); | $fblist = $this->driver->get_freebusy_list($email, $start, $end); | ||||
$slots = array(); | $slots = ''; | ||||
// prepare freebusy list before use (for better performance) | |||||
if (is_array($fblist)) { | |||||
foreach ($fblist as $idx => $slot) { | |||||
list($from, $to, ) = $slot; | |||||
// check for possible all-day times | |||||
if (gmdate('His', $from) == '000000' && gmdate('His', $to) == '235959') { | |||||
// shift into the user's timezone for sane matching | |||||
$fblist[$idx][0] -= $this->gmt_offset; | |||||
$fblist[$idx][1] -= $this->gmt_offset; | |||||
} | |||||
} | |||||
} | |||||
// build a list from $start till $end with blocks representing the fb-status | // build a list from $start till $end with blocks representing the fb-status | ||||
for ($s = 0, $t = $start; $t <= $end; $s++) { | for ($s = 0, $t = $start; $t <= $end; $s++) { | ||||
$status = self::FREEBUSY_UNKNOWN; | |||||
$t_end = $t + $interval * 60; | $t_end = $t + $interval * 60; | ||||
$dt = new DateTime('@'.$t); | $dt = new DateTime('@'.$t); | ||||
$dt->setTimezone($this->timezone); | $dt->setTimezone($this->timezone); | ||||
// determine attendee's status | // determine attendee's status | ||||
if (is_array($fblist)) { | if (is_array($fblist)) { | ||||
$status = self::FREEBUSY_FREE; | $status = self::FREEBUSY_FREE; | ||||
foreach ($fblist as $slot) { | foreach ($fblist as $slot) { | ||||
list($from, $to, $type) = $slot; | list($from, $to, $type) = $slot; | ||||
// check for possible all-day times | |||||
if (gmdate('His', $from) == '000000' && gmdate('His', $to) == '235959') { | |||||
// shift into the user's timezone for sane matching | |||||
$from -= $this->gmt_offset; | |||||
$to -= $this->gmt_offset; | |||||
} | |||||
if ($from < $t_end && $to > $t) { | if ($from < $t_end && $to > $t) { | ||||
$status = isset($type) ? $type : self::FREEBUSY_BUSY; | $status = isset($type) ? $type : self::FREEBUSY_BUSY; | ||||
if ($status == self::FREEBUSY_BUSY) // can't get any worse :-) | if ($status == self::FREEBUSY_BUSY) // can't get any worse :-) | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
else { | |||||
$status = self::FREEBUSY_UNKNOWN; | |||||
} | |||||
$slots[$s] = $status; | // use most compact format, assume $status is one digit/character | ||||
$times[$s] = intval($dt->format($strformat)); | $slots .= $status; | ||||
$t = $t_end; | $t = $t_end; | ||||
} | } | ||||
$dte = new DateTime('@'.$t_end); | $dte = new DateTime('@'.$t_end); | ||||
$dte->setTimezone($this->timezone); | $dte->setTimezone($this->timezone); | ||||
// let this information be cached for 5min | // let this information be cached for 5min | ||||
$this->rc->output->future_expire_header(300); | $this->rc->output->future_expire_header(300); | ||||
echo rcube_output::json_serialize(array( | echo rcube_output::json_serialize(array( | ||||
'email' => $email, | 'email' => $email, | ||||
'start' => $dts->format('c'), | 'start' => $dts->format('c'), | ||||
'end' => $dte->format('c'), | 'end' => $dte->format('c'), | ||||
'interval' => $interval, | 'interval' => $interval, | ||||
'slots' => $slots, | 'slots' => $slots, | ||||
'times' => $times, | |||||
)); | )); | ||||
exit; | exit; | ||||
} | } | ||||
/** | /** | ||||
* Handler for printing calendars | * Handler for printing calendars | ||||
*/ | */ | ||||
public function print_view() | public function print_view() | ||||
▲ Show 20 Lines • Show All 1,102 Lines • Show Last 20 Lines |