| +--------------------------------------------------------------------------+ | Author: Aleksander Machniak | +--------------------------------------------------------------------------+ */ class kolab_client_task_domain extends kolab_client_task { protected $ajax_only = true; protected $menu = array( 'add' => 'domain.add', ); protected $search_attribs = array( 'name' => array('associateddomain'), ); protected $list_attribs = array('associateddomain'); /** * Default action. */ public function action_default() { $this->output->set_object('content', 'domain', true); $this->output->set_object('task_navigation', $this->menu()); $this->action_list(); // display form to add domain if logged-in user has right to do so $caps = $this->get_capability('actions'); if (!empty($caps['domain.add'])) { $this->action_add(); } else { $this->output->command('set_watermark', 'taskcontent'); } } /** * Groups list action. */ public function action_list() { if (!empty($_POST['refresh'])) { // refresh domains list if ($domains = $this->get_domains(true)) { sort($domains, SORT_LOCALE_STRING); $this->output->set_env('domains', $domains); } } parent::action_list(); } /** * Domain information (form) action. */ public function action_info() { $id = $this->get_input('id', 'POST'); //console("action_info() on", $id); $result = $this->api_get('domain.info', array('id' => $id)); //console("action_info() \$result", $result); $domain = $result->get(); //console("action_info() \$domain", $domain); $output = $this->domain_form(array_keys($domain), $domain); $this->output->set_object('taskcontent', $output); } /** * Domain adding (form) action. */ public function action_add() { $data = $this->get_input('data', 'POST'); $output = $this->domain_form(null, $data, true); $this->output->set_object('taskcontent', $output); } /** * Domain edit/add form. */ private function domain_form($attribs, $data = array()) { if (empty($attribs['id'])) { $attribs['id'] = 'domain-form'; } // Form sections $sections = array( 'system' => 'domain.system', 'other' => 'domain.other', ); // field-to-section map and fields order $fields_map = array( 'type_id' => 'system', 'type_id_name' => 'system', 'associateddomain' => 'system', ); //console("domain_form() \$data", $data); // Prepare fields list($fields, $types, $type) = $this->form_prepare('domain', $data); //console("Result from form_prepare", $fields, $types, $type); $add_mode = empty($data['id']); $accttypes = array(); foreach ($types as $idx => $elem) { $accttypes[$idx] = array('value' => $idx, 'content' => $elem['name']); } // Add domain type id selector $fields['type_id'] = array( 'section' => 'system', 'type' => kolab_form::INPUT_SELECT, 'options' => $accttypes, 'onchange' => "kadm.domain_save(true, 'system')", ); // Hide account type selector if there's only one type if (count($accttypes) < 2 || !$add_mode) { $fields['type_id']['type'] = kolab_form::INPUT_HIDDEN; } // Create mode if ($add_mode) { // Page title $title = $this->translate('domain.add'); } // Edit mode else { if (array_key_exists('primary_domain', $data)) { $title = $data['primary_domain']; } // TODO: Domain name attribute. else if (!is_array($data['associateddomain'])) { $title = $data['associateddomain']; } else { $title = $data['associateddomain'][0]; } // Add domain type name $fields['type_id_name'] = array( 'label' => 'domain.type_id', 'section' => 'system', 'value' => $accttypes[$type]['content'], ); } // Create form object and populate with fields $form = $this->form_create('domain', $attribs, $sections, $fields, $fields_map, $data, $add_mode); //console("domain_form() \$form", $form); $form->set_title(kolab_html::escape($title)); return $form->output(); } /** * List item handler */ protected function list_item_handler($item) { if (is_array($item['associateddomain'])) { return $item['associateddomain'][0]; } return $item['associateddomain']; } }