| +--------------------------------------------------------------------------+ | Author: Aleksander Machniak | +--------------------------------------------------------------------------+ */ class kolab_client_task_role extends kolab_client_task { protected $ajax_only = true; protected $menu = array( 'add' => 'role.add', ); protected $list_attribs = array('cn'); /** * Default action. */ public function action_default() { $this->output->set_object('content', 'role', true); $this->output->set_object('task_navigation', $this->menu()); $this->action_list(); // display form to add role if logged-in user has right to do so $caps = $this->get_capability('actions'); if (!empty($caps['role.add'])) { $this->action_add(); } else { $this->output->command('set_watermark', 'taskcontent'); } } /** * Role information (form) action. */ public function action_info() { $id = $this->get_input('id', 'POST'); $result = $this->api_get('role.info', array('id' => $id)); $role = $result->get(); $output = $this->role_form(null, $role); $this->output->set_object('taskcontent', $output); } /** * Roles adding (form) action. */ public function action_add() { $data = $this->get_input('data', 'POST'); $output = $this->role_form(null, $data, true); $this->output->set_object('taskcontent', $output); } /** * Role edit/add form. */ private function role_form($attribs, $data = array()) { if (empty($attribs['id'])) { $attribs['id'] = 'role-form'; } // Form sections $sections = array( 'system' => 'role.system', 'other' => 'role.other', ); // field-to-section map and fields order $fields_map = array( 'type_id' => 'system', 'type_id_name' => 'system', 'cn' => 'system', 'description' => 'system', ); //console("role_form \$data", $data); // Prepare fields list($fields, $types, $type) = $this->form_prepare('role', $data); //console("role_form \$types", $types); $add_mode = empty($data['id']); $accttypes = array(); foreach ($types as $idx => $elem) { $accttypes[$idx] = array('value' => $idx, 'content' => $elem['name']); } // Add user type id selector $fields['type_id'] = array( 'section' => 'system', 'type' => kolab_form::INPUT_SELECT, 'options' => $accttypes, 'onchange' => "kadm.role_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('role.add'); } // Edit mode else { $title = $data['cn']; // Add user type name $fields['type_id_name'] = array( 'label' => 'role.type_id', 'section' => 'system', 'value' => $accttypes[$type]['content'], ); } // Create form object and populate with fields $form = $this->form_create('role', $attribs, $sections, $fields, $fields_map, $data, $add_mode); $form->set_title(kolab_html::escape($title)); return $form->output(); } private function parse_members($list) { // convert to key=>value array, see kolab_api_service_form_value::list_options_uniquemember() foreach ($list as $idx => $value) { if (!empty($value['displayname'])) { $list[$idx] = $value['displayname']; } elseif (!empty($value['cn'])) { $list[$idx] = $value['cn']; } else { //console("No display name or cn for $idx"); } if (!empty($value['mail'])) { $list[$idx] .= ' <' . $value['mail'] . '>'; } } return $list; } }