Ejemplo n.º 1
0
 /**
  * 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)
 {
     $cal_id = $calendar["id"];
     $props = $this->_get_ical_props($cal_id, self::OBJ_TYPE_ICAL);
     $protected = array();
     $preinstalled_calendars = $this->rc->config->get('calendar_preinstalled_calendars', array());
     foreach ($preinstalled_calendars as $idx => $properties) {
         if ($properties['driver'] == 'ical') {
             $url = str_replace('@', urlencode('@'), str_replace('%u', $this->rc->get_user_name(), $properties['ical_url']));
             if (stripos($props['url'], $url) === 0) {
                 $protected = $properties['protected'];
                 break;
             }
         }
     }
     if ($protected['name']) {
         $formfields['name'] = str_replace('<input ', '<input readonly="readonly" ', $formfields['name']);
     }
     if ($protected['color']) {
         unset($formfields['color']);
     }
     if ($protected['showalarms']) {
         $formfields['showalarms'] = str_replace('<input ', '<input disabled="disabled" ', $formfields['showalarms']);
     }
     if ($this->freebusy) {
         $enabled = $action == 'form-new' ? true : $this->calendars[$cal_id]['freebusy'];
         $readonly = array();
         if ($protected['freebusy']) {
             $readonly = array('disabled' => 'disabled');
         }
         $input_freebusy = new html_checkbox(array_merge(array("name" => "freebusy", "title" => $this->cal->gettext("allowfreebusy"), "id" => "chbox_freebusy", "value" => 1), $readonly));
         $formfields['freebusy'] = array("label" => $this->cal->gettext('freebusy'), "value" => $input_freebusy->show($enabled ? 1 : 0), "id" => "freebusy");
     }
     if (!$this->rc->config->get('calendar_disable_tasks', false)) {
         $enabled = $action == 'form-new' ? true : $this->calendars[$cal_id]['tasks'];
         $readonly = array();
         if ($protected['tasks']) {
             $readonly = array('disabled' => 'disabled');
         }
         $input_tasks = new html_checkbox(array_merge(array("name" => "tasks", "id" => "chbox_tasks", "value" => 1), $readonly));
         $formfields["tasks"] = array("label" => $this->cal->gettext("tasks"), "value" => $input_tasks->show($enabled ? 1 : 0), "id" => "tasks");
     }
     if ($protected['ical_url']) {
         $readonly = array('readonly' => 'readonly');
     } else {
         $readonly = array();
     }
     $input_ical_url = new html_inputfield(array_merge(array("name" => "ical_url", "id" => "ical_url_input", "size" => 45, "placeholder" => "http://dav.mydomain.tld/calendars/john.doh@mydomain.tld"), $readonly));
     $formfields["ical_url"] = array("label" => $this->cal->gettext("url"), "value" => $input_ical_url->show($props["url"]), "id" => "ical_url");
     $readonly = array();
     if ($protected['ical_user']) {
         $readonly = array('readonly' => 'readonly');
     }
     $input_ical_user = new html_inputfield(array_merge(array("name" => "ical_user", "id" => "ical_user_input", "size" => 30, "placeholder" => "*****@*****.**"), $readonly));
     $formfields["ical_user"] = array("label" => $this->cal->gettext("username"), "value" => $input_ical_user->show($props["user"]), "id" => "ical_user");
     $readonly = array();
     if ($protected['ical_pass']) {
         $readonly = array('readonly' => 'readonly');
     }
     $input_ical_pass = new html_passwordfield(array_merge(array("name" => "ical_pass", "id" => "ical_pass_input", "size" => 30, "placeholder" => "******"), $readonly));
     $formfields["ical_pass"] = array("label" => $this->cal->gettext("password"), "value" => $input_ical_pass->show(null), "id" => "ical_pass");
     $readonly = array();
     if ($protected['sync']) {
         $readonly = array('disabled' => 'disabled');
     }
     $field_id = 'sync_interval_select';
     $select = new html_select(array_merge(array('name' => 'sync', 'id' => $field_id), $readonly));
     $intervals = array(5 => 5, 10 => 10, 15 => 15, 30 => 30, 45 => 45, 60 => 60, 90 => 90, 120 => 120, 1800 => 1800, 3600 => 3600);
     foreach ($intervals as $interval => $text) {
         $select->add($text, $interval);
     }
     $formfields["sync_interval"] = array("label" => $this->cal->gettext("sync_interval"), "value" => $select->show((int) ($props["sync"] ? $props['sync'] : 60)) . '&nbsp;' . $this->cal->gettext('minute_s'), "id" => "sync_interval");
     return parent::calendar_form($action, $calendar, $formfields);
 }
Ejemplo n.º 2
0
 /**
  * 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)
 {
     $cal_id = $calendar['id'];
     $props = $this->_get_caldav_props($cal_id, self::OBJ_TYPE_VCAL);
     $protected = array();
     $preinstalled_calendars = $this->rc->config->get('calendar_preinstalled_calendars', array());
     foreach ($preinstalled_calendars as $idx => $properties) {
         if ($properties['driver'] == 'caldav') {
             $url = str_replace('@', urlencode('@'), str_replace('%u', $this->rc->get_user_name(), $properties['caldav_url']));
             if (stripos($props['url'], $url) === 0) {
                 $protected = $properties['protected'];
                 break;
             }
         }
     }
     if ($protected['name']) {
         $formfields['name'] = str_replace('<input ', '<input readonly="readonly" ', $formfields['name']);
     }
     if ($protected['color']) {
         unset($formfields['color']);
     }
     if ($protected['showalarms']) {
         $formfields['showalarms'] = str_replace('<input ', '<input disabled="disabled" ', $formfields['showalarms']);
     }
     if ($this->freebusy) {
         $enabled = $action == 'form-new' ? true : $this->calendars[$cal_id]['freebusy'];
         $readonly = array();
         if ($protected['freebusy']) {
             $readonly = array('disabled' => 'disabled');
         }
         $input_freebusy = new html_checkbox(array_merge(array("name" => "freebusy", "title" => $this->cal->gettext("allowfreebusy"), "id" => "chbox_freebusy", "value" => 1), $readonly));
         $formfields['freebusy'] = array("label" => $this->cal->gettext('freebusy'), "value" => $input_freebusy->show($enabled ? 1 : 0), "id" => "freebusy");
     }
     $enabled = $action == 'form-new' ? true : $this->calendars[$cal_id]['evts'];
     $readonly = array();
     if ($protected['events']) {
         $readonly = array('disabled' => 'disabled');
     }
     $input_events = new html_checkbox(array_merge(array("name" => "events", "id" => "chbox_events", "value" => 1), $readonly));
     $formfields["events"] = array("label" => $this->cal->gettext('events'), "value" => $input_events->show($enabled ? 1 : 0), "id" => "events");
     if (!$this->rc->config->get('calendar_disable_tasks', false)) {
         $enabled = $action == 'form-new' ? true : $this->calendars[$cal_id]['tasks'];
         $readonly = array();
         if ($protected['tasks']) {
             $readonly = array('disabled' => 'disabled');
         }
         $input_tasks = new html_checkbox(array_merge(array("name" => "tasks", "id" => "chbox_tasks", "value" => 1), $readonly));
         $formfields["tasks"] = array("label" => $this->cal->gettext("tasks"), "value" => $input_tasks->show($enabled ? 1 : 0), "id" => "tasks");
     }
     if (!isset($formfields['caldav_url'])) {
         $readonly = array();
         if (stripos($props['url'], 'https://apidata.googleusercontent.com/caldav/v2/') === 0 || $protected['caldav_url']) {
             $readonly = array('readonly' => 'readonly');
         }
         $input_caldav_url = new html_inputfield(array_merge(array("name" => "caldav_url", "id" => "caldav_url_input", "size" => 45, "placeholder" => "http://dav.mydomain.tld/calendars/john.doh@mydomain.tld"), $readonly));
         $formfields["caldav_url"] = array("label" => $this->cal->gettext("url"), "value" => $input_caldav_url->show($props["url"]), "id" => "caldav_url");
     }
     if (!isset($formfields['caldav_user'])) {
         $readonly = array();
         if (stripos($props['url'], 'https://apidata.googleusercontent.com/caldav/v2/') === 0 || $protected['caldav_user']) {
             $readonly = array('readonly' => 'readonly');
         }
         $input_caldav_user = new html_inputfield(array_merge(array("name" => "caldav_user", "id" => "caldav_user_input", "size" => 30, "placeholder" => "*****@*****.**"), $readonly));
         $formfields["caldav_user"] = array("label" => $this->cal->gettext("username"), "value" => $input_caldav_user->show($props["user"]), "id" => "caldav_user");
     }
     if (!isset($formfields['caldav_pass'])) {
         $readonly = array();
         if (stripos($props['url'], 'https://apidata.googleusercontent.com/caldav/v2/') === 0 || $protected['caldav_pass']) {
             $readonly = array('readonly' => 'readonly');
         }
         $input_caldav_pass = new html_passwordfield(array_merge(array("name" => "caldav_pass", "id" => "caldav_pass_input", "size" => 30, "placeholder" => "******"), $readonly));
         $formfields["caldav_pass"] = array("label" => $this->cal->gettext("password"), "value" => $input_caldav_pass->show(null), "id" => "caldav_pass");
     }
     if (!isset($formfields['authtype'])) {
         $readonly = array();
         if (stripos($props['url'], 'https://apidata.googleusercontent.com/caldav/v2/') === 0 || $protected['authtype']) {
             $readonly = array('disabled' => 'disabled');
         }
         $field_id = 'authtype_select';
         $select = new html_select(array_merge(array('name' => 'authtype', 'id' => $field_id), $readonly));
         $types = array('detect' => 'detect', 'basic' => 'basic', 'digest' => 'digest');
         foreach ($types as $type => $text) {
             $select->add($this->cal->gettext('libgpl.' . $text), $type);
         }
         $formfields['authtype'] = array('label' => $this->cal->gettext('libgpl.authtype'), 'value' => $select->show($props['authtype'] ? $props['authtype'] : 'detect'), 'id' => 'sync_interval');
     }
     if (!isset($formfields['sync_interval'])) {
         $readonly = array();
         if ($protected['sync']) {
             $readonly = array('disabled' => 'disabled');
         }
         $field_id = 'sync_interval_select';
         $select = new html_select(array_merge(array('name' => 'sync', 'id' => $field_id), $readonly));
         $intervals = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 10 => 10, 15 => 15, 30 => 30, 45 => 45, 60 => 60);
         foreach ($intervals as $interval => $text) {
             $select->add($text, $interval);
         }
         $formfields['sync_interval'] = array('label' => $this->cal->gettext('sync_interval'), 'value' => $select->show((int) ($props['sync'] ? $props['sync'] : 5)) . '&nbsp;' . $this->cal->gettext('minute_s'), 'id' => 'sync_interval');
     }
     foreach ($formfields as $key => $val) {
         if (empty($val)) {
             unset($formfields[$key]);
         }
     }
     return parent::calendar_form($action, $calendar, $formfields);
 }