/** * Helper method to fetch free/busy data for the user and turn it into calendar data */ private function fetch_freebusy($limit_changed = null) { // ask kolab server first try { $request_config = array('store_body' => true, 'follow_redirects' => true); $request = libkolab::http_request(kolab_storage::get_freebusy_url($this->userdata['mail']), 'GET', $request_config); $response = $request->send(); // authentication required if ($response->getStatus() == 401) { $request->setAuth($this->rc->user->get_username(), $this->rc->decrypt($_SESSION['password'])); $response = $request->send(); } if ($response->getStatus() == 200) { $fbdata = $response->getBody(); } unset($request, $response); } catch (Exception $e) { rcube::raise_error(array('code' => 900, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Error fetching free/busy information: " . $e->getMessage()), true, false); return false; } $statusmap = array('FREE' => 'free', 'BUSY' => 'busy', 'BUSY-TENTATIVE' => 'tentative', 'X-OUT-OF-OFFICE' => 'outofoffice', 'OOF' => 'outofoffice'); $titlemap = array('FREE' => $this->cal->gettext('availfree'), 'BUSY' => $this->cal->gettext('availbusy'), 'BUSY-TENTATIVE' => $this->cal->gettext('availtentative'), 'X-OUT-OF-OFFICE' => $this->cal->gettext('availoutofoffice')); // console('_fetch_freebusy', kolab_storage::get_freebusy_url($this->userdata['mail']), $fbdata); // parse free-busy information $count = 0; if ($fbdata) { $ical = $this->cal->get_ical(); $ical->import($fbdata); if ($fb = $ical->freebusy) { // consider 'changed >= X' queries if ($limit_changed && $fb['created'] && $fb['created'] < $limit_changed) { return 0; } foreach ($fb['periods'] as $tuple) { list($from, $to, $type) = $tuple; $event = array('id' => md5($this->id . $from->format('U') . '/' . $to->format('U')), 'calendar' => $this->id, 'changed' => $fb['created'] ?: new DateTime(), 'title' => $this->get_name() . ' ' . ($titlemap[$type] ?: $type), 'start' => $from, 'end' => $to, 'free_busy' => $statusmap[$type] ?: 'busy', 'className' => 'fc-type-freebusy', 'organizer' => array('email' => $this->userdata['mail'], 'name' => $this->userdata['displayname'])); // avoid duplicate entries $key = $this->time_key($event); if (!$this->timeindex[$key]) { $this->events[$event['id']] = $event; $this->timeindex[$key] = $event['id']; $count++; } } } } return $count; }
/** * Callback function to produce driver-specific calendar create/edit form * * @param string Request action 'form-edit|form-new' * @param array Calendar properties (e.g. id, color) * @param array Edit form fields * * @return string HTML content of the form */ public function calendar_form($action, $calendar, $formfields) { // show default dialog for birthday calendar if (in_array($calendar['id'], array(self::BIRTHDAY_CALENDAR_ID, self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED))) { if ($calendar['id'] != self::BIRTHDAY_CALENDAR_ID) { unset($formfields['showalarms']); } return parent::calendar_form($action, $calendar, $formfields); } if ($calendar['id'] && ($cal = $this->calendars[$calendar['id']])) { $folder = $cal->get_realname(); // UTF7 $color = $cal->get_color(); } else { $folder = ''; $color = ''; } $hidden_fields[] = array('name' => 'oldname', 'value' => $folder); $storage = $this->rc->get_storage(); $delim = $storage->get_hierarchy_delimiter(); $form = array(); if (strlen($folder)) { $path_imap = explode($delim, $folder); array_pop($path_imap); // pop off name part $path_imap = implode($path_imap, $delim); $options = $storage->folder_info($folder); } else { $path_imap = ''; } // General tab $form['props'] = array('name' => $this->rc->gettext('properties')); // Disable folder name input if (!empty($options) && ($options['norename'] || $options['protected'])) { $input_name = new html_hiddenfield(array('name' => 'name', 'id' => 'calendar-name')); $formfields['name']['value'] = kolab_storage::object_name($folder) . $input_name->show($folder); } // calendar name (default field) $form['props']['fieldsets']['location'] = array('name' => $this->rc->gettext('location'), 'content' => array('name' => $formfields['name'])); if (!empty($options) && ($options['norename'] || $options['protected'])) { // prevent user from moving folder $hidden_fields[] = array('name' => 'parent', 'value' => $path_imap); } else { $select = kolab_storage::folder_selector('event', array('name' => 'parent', 'id' => 'calendar-parent'), $folder); $form['props']['fieldsets']['location']['content']['path'] = array('id' => 'calendar-parent', 'label' => $this->cal->gettext('parentcalendar'), 'value' => $select->show(strlen($folder) ? $path_imap : '')); } // calendar color (default field) $form['props']['fieldsets']['settings'] = array('name' => $this->rc->gettext('settings'), 'content' => array('color' => $formfields['color'], 'showalarms' => $formfields['showalarms'])); if ($action != 'form-new') { $form['sharing'] = array('name' => rcube::Q($this->cal->gettext('tabsharing')), 'content' => html::tag('iframe', array('src' => $this->cal->rc->url(array('_action' => 'calendar-acl', 'id' => $calendar['id'], 'framed' => 1)), 'width' => '100%', 'height' => 350, 'border' => 0, 'style' => 'border:0'), '')); } $this->form_html = ''; if (is_array($hidden_fields)) { foreach ($hidden_fields as $field) { $hiddenfield = new html_hiddenfield($field); $this->form_html .= $hiddenfield->show() . "\n"; } } // Create form output foreach ($form as $tab) { if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) { $content = ''; foreach ($tab['fieldsets'] as $fieldset) { $subcontent = $this->get_form_part($fieldset); if ($subcontent) { $content .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($fieldset['name'])) . $subcontent) . "\n"; } } } else { $content = $this->get_form_part($tab); } if ($content) { $this->form_html .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($tab['name'])) . $content) . "\n"; } } // Parse form template for skin-dependent stuff $this->rc->output->add_handler('calendarform', array($this, 'calendar_form_html')); return $this->rc->output->parse('calendar.kolabform', false, false); }
/** * Update properties of this calendar folder * * @see calendar_driver::edit_calendar() */ public function update(&$prop) { $prop['oldname'] = $this->get_realname(); $newfolder = kolab_storage::folder_update($prop); if ($newfolder === false) { $this->cal->last_error = $this->cal->gettext(kolab_storage::$last_error); return false; } // create ID return kolab_storage::folder_id($newfolder); }
/** * * @param integer Date range start (unix timestamp) * @param integer Date range end (unix timestamp) * @return integer Count */ public function count_events($start, $end = null) { // get email addresses of the current user $user_emails = $this->cal->get_user_emails(); $subquery = array(); foreach ($user_emails as $email) { foreach ($this->partstats as $partstat) { $subquery[] = array('tags', '=', 'x-partstat:' . $email . ':' . strtolower($partstat)); } } // aggregate counts from all calendar folders $count = 0; foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) { $cal = new kolab_calendar($foldername, $this->cal); if ($cal->get_namespace() == 'other') { continue; } $count += $cal->count_events($start, $end, array(array($subquery, 'OR'))); } return $count; }
/** * */ public function tasklist_edit_form($fieldprop) { $select = kolab_storage::folder_selector('task', array('name' => 'parent', 'id' => 'taskedit-parentfolder'), null); $fieldprop['parent'] = array('id' => 'taskedit-parentfolder', 'label' => $this->plugin->gettext('parentfolder'), 'value' => $select->show('')); $formfields = array(); foreach (array('name', 'parent', 'showalarms') as $f) { $formfields[$f] = $fieldprop[$f]; } return parent::tasklist_edit_form($formfields); }
/** * */ public function tasklist_edit_form($action, $list, $fieldprop) { if ($list['id'] && ($list = $this->lists[$list['id']])) { $folder_name = $this->get_folder($list['id'])->name; // UTF7 } else { $folder_name = ''; } $storage = $this->rc->get_storage(); $delim = $storage->get_hierarchy_delimiter(); $form = array(); if (strlen($folder_name)) { $path_imap = explode($delim, $folder_name); array_pop($path_imap); // pop off name part $path_imap = implode($path_imap, $delim); $options = $storage->folder_info($folder_name); } else { $path_imap = ''; } $hidden_fields[] = array('name' => 'oldname', 'value' => $folder_name); // folder name (default field) $input_name = new html_inputfield(array('name' => 'name', 'id' => 'taskedit-tasklistame', 'size' => 20)); $fieldprop['name']['value'] = $input_name->show($list['editname'], array('disabled' => $options['norename'] || $options['protected'])); // prevent user from moving folder if (!empty($options) && ($options['norename'] || $options['protected'])) { $hidden_fields[] = array('name' => 'parent', 'value' => $path_imap); } else { $select = kolab_storage::folder_selector('task', array('name' => 'parent', 'id' => 'taskedit-parentfolder'), $folder_name); $fieldprop['parent'] = array('id' => 'taskedit-parentfolder', 'label' => $this->plugin->gettext('parentfolder'), 'value' => $select->show($path_imap)); } // General tab $form['properties'] = array('name' => $this->rc->gettext('properties'), 'fields' => array()); foreach (array('name', 'parent', 'showalarms') as $f) { $form['properties']['fields'][$f] = $fieldprop[$f]; } // add folder ACL tab if ($action != 'form-new') { $form['sharing'] = array('name' => rcube::Q($this->plugin->gettext('tabsharing')), 'content' => html::tag('iframe', array('src' => $this->rc->url(array('_action' => 'folder-acl', '_folder' => $folder_name, 'framed' => 1)), 'width' => '100%', 'height' => 280, 'border' => 0, 'style' => 'border:0'), '')); } $form_html = ''; if (is_array($hidden_fields)) { foreach ($hidden_fields as $field) { $hiddenfield = new html_hiddenfield($field); $form_html .= $hiddenfield->show() . "\n"; } } // create form output foreach ($form as $tab) { if (is_array($tab['fields']) && empty($tab['content'])) { $table = new html_table(array('cols' => 2)); foreach ($tab['fields'] as $col => $colprop) { $label = !empty($colprop['label']) ? $colprop['label'] : $this->plugin->gettext($col); $table->add('title', html::label($colprop['id'], rcube::Q($label))); $table->add(null, $colprop['value']); } $content = $table->show(); } else { $content = $tab['content']; } if (!empty($content)) { $form_html .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($tab['name'])) . $content) . "\n"; } } return $form_html; }