Ejemplo n.º 1
0
 /**
  * Return a list of free/busy time slots within the given period
  * Echo data in JSON encoding
  */
 public function freebusy_times()
 {
     $email = rcube_utils::get_input_value('email', rcube_utils::INPUT_GPC);
     $start = rcube_utils::get_input_value('start', rcube_utils::INPUT_GPC);
     $end = rcube_utils::get_input_value('end', rcube_utils::INPUT_GPC);
     $interval = intval(rcube_utils::get_input_value('interval', rcube_utils::INPUT_GPC));
     $strformat = $interval > 60 ? 'Ymd' : 'YmdHis';
     // convert dates into unix timestamps
     if (!empty($start) && !is_numeric($start)) {
         $dts = rcube_utils::anytodatetime($start, $this->timezone);
         $start = $dts ? $dts->format('U') : null;
     }
     if (!empty($end) && !is_numeric($end)) {
         $dte = rcube_utils::anytodatetime($end, $this->timezone);
         $end = $dte ? $dte->format('U') : null;
     }
     if (!$start) {
         $start = time();
     }
     if (!$end) {
         $end = $start + 86400 * 30;
     }
     if (!$interval) {
         $interval = 60;
     }
     // 1 hour
     if (!$dte) {
         $dts = new DateTime('@' . $start);
         $dts->setTimezone($this->timezone);
     }
     $fblist = $this->driver->get_freebusy_list($email, $start, $end);
     $slots = array();
     // build a list from $start till $end with blocks representing the fb-status
     for ($s = 0, $t = $start; $t <= $end; $s++) {
         $status = self::FREEBUSY_UNKNOWN;
         $t_end = $t + $interval * 60;
         $dt = new DateTime('@' . $t);
         $dt->setTimezone($this->timezone);
         // determine attendee's status
         if (is_array($fblist)) {
             $status = self::FREEBUSY_FREE;
             foreach ($fblist as $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) {
                     $status = isset($type) ? $type : self::FREEBUSY_BUSY;
                     if ($status == self::FREEBUSY_BUSY) {
                         // can't get any worse :-)
                         break;
                     }
                 }
             }
         }
         $slots[$s] = $status;
         $times[$s] = intval($dt->format($strformat));
         $t = $t_end;
     }
     $dte = new DateTime('@' . $t_end);
     $dte->setTimezone($this->timezone);
     // let this information be cached for 5min
     send_future_expire_header(300);
     echo json_encode(array('email' => $email, 'start' => $dts->format('c'), 'end' => $dte->format('c'), 'interval' => $interval, 'slots' => $slots, 'times' => $times));
     exit;
 }
Ejemplo n.º 2
0
 /**
  * Return a list of free/busy time slots within the given period
  * Echo data in JSON encoding
  */
 public function freebusy_times()
 {
     $email = get_input_value('email', RCUBE_INPUT_GPC);
     $name = get_input_value('name', RCUBE_INPUT_GPC);
     $start = get_input_value('start', RCUBE_INPUT_GPC);
     $end = get_input_value('end', RCUBE_INPUT_GPC);
     $interval = intval(get_input_value('interval', RCUBE_INPUT_GPC));
     $strformat = $interval > 60 ? 'Ymd' : 'YmdHis';
     // convert dates into unix timestamps
     if (!empty($start) && !is_numeric($start)) {
         $dts = new DateTime($start, $this->timezone);
         $start = $dts->format('U');
     }
     if (!empty($end) && !is_numeric($end)) {
         $dte = new DateTime($end, $this->timezone);
         $end = $dte->format('U');
     }
     if (!$start) {
         $start = time();
     }
     if (!$end) {
         $end = $start + 86400 * 30;
     }
     if (!$interval) {
         $interval = 60;
     }
     // 1 hour
     if (!$dte) {
         $dts = new DateTime('@' . $start);
         $dts->setTimezone($this->timezone);
     }
     $fblist = $this->_get_freebusy_list($email, $name, $start, $end);
     $slots = array();
     // build a list from $start till $end with blocks representing the fb-status
     for ($s = 0, $t = $start; $t <= $end; $s++) {
         $status = self::FREEBUSY_UNKNOWN;
         $t_end = $t + $interval * 60;
         $dt = new DateTime('@' . $t);
         $dt->setTimezone($this->timezone);
         // determine attendee's status
         if (is_array($fblist)) {
             $status = self::FREEBUSY_FREE;
             foreach ($fblist as $slot) {
                 list($from, $to, $type) = $slot;
                 if ($from < $t_end && $to > $t) {
                     $status = isset($type) ? $type : self::FREEBUSY_BUSY;
                     if ($status == self::FREEBUSY_BUSY) {
                         // can't get any worse :-)
                         break;
                     }
                 }
             }
         }
         $slots[$s] = $status;
         $times[$s] = $dt->format($strformat);
         // Mod by Rosali (remove intval)
         $t = $t_end;
     }
     $dte = new DateTime('@' . $t_end);
     $dte->setTimezone($this->timezone);
     // let this information be cached for 5min
     send_future_expire_header(300);
     echo json_encode(array('email' => $email, 'start' => $dts->format('c'), 'end' => $dte->format('c'), 'interval' => $interval, 'slots' => $slots, 'times' => $times));
     exit;
 }