| +--------------------------------------------------------------------------+ | Author: Aleksander Machniak | +--------------------------------------------------------------------------+ */ class kolab_client_task_user extends kolab_client_task { protected $ajax_only = true; protected $menu = array( 'add' => 'user.add', ); protected $list_attribs = array('displayname', 'cn'); /** * Default action. */ public function action_default() { $this->output->set_object('content', 'user', true); $this->output->set_object('task_navigation', $this->menu()); $this->action_list(); // display form to add user if logged-in user has right to do so $caps = $this->get_capability('actions'); if (!empty($caps['user.add'])) { $this->action_add(); } else { $this->output->command('set_watermark', 'taskcontent'); } } /** * User information (form) action. */ public function action_info() { $id = $this->get_input('id', 'POST'); $result = $this->api_get('user.info', array('id' => $id)); $user = $result->get(); $output = $this->user_form(null, $user); $this->output->set_object('taskcontent', $output); } /** * Users adding (form) action. */ public function action_add() { $data = $this->get_input('data', 'POST'); $output = $this->user_form(null, $data, true); $this->output->set_object('taskcontent', $output); } private function user_form($attribs, $data = array()) { if (empty($attribs['id'])) { $attribs['id'] = 'user-form'; } // Form sections $sections = array( 'personal' => 'user.personal', 'contact_info' => 'user.contact_info', 'system' => 'user.system', 'config' => 'user.config', 'asterisk' => 'user.asterisk', 'other' => 'user.other', ); // field-to-section map and fields order $fields_map = array( 'type_id' => 'personal', 'type_id_name' => 'personal', /* Probably input */ 'givenname' => 'personal', 'sn' => 'personal', /* Possibly input */ 'initials' => 'personal', 'o' => 'personal', 'title' => 'personal', /* Probably generated */ 'cn' => 'personal', 'displayname' => 'personal', 'ou' => 'personal', 'preferredlanguage' => 'personal', /* Address lines together */ 'street' => 'contact_info', 'postofficebox' => 'contact_info', 'roomnumber' => 'contact_info', 'postalcode' => 'contact_info', 'l' => 'contact_info', 'c' => 'contact_info', /* Probably input */ 'mobile' => 'contact_info', 'facsimiletelephonenumber' => 'contact_info', 'telephonenumber' => 'contact_info', 'homephone' => 'contact_info', 'pager' => 'contact_info', 'mail' => 'contact_info', 'alias' => 'contact_info', 'mailalternateaddress' => 'contact_info', /* POSIX Attributes first */ 'uid' => 'system', 'userpassword' => 'system', 'userpassword2' => 'system', 'uidnumber' => 'system', 'gidnumber' => 'system', 'homedirectory' => 'system', 'loginshell' => 'system', 'nsrole' => 'system', 'nsroledn' => 'system', /* Kolab Settings */ 'kolabhomeserver' => 'config', 'mailhost' => 'config', 'mailquota' => 'config', 'cyrususerquota' => 'config', 'kolabfreebusyfuture' => 'config', 'kolabinvitationpolicy' => 'config', 'kolabdelegate' => 'config', 'kolaballowsmtprecipient' => 'config', 'kolaballowsmtpsender' => 'config', 'mailforwardingaddress' => 'config', /* Asterisk Settings */ 'astaccountallowedcodec' => 'asterisk', 'astaccountcallerid' => 'asterisk', 'astaccountcontext' => 'asterisk', 'astaccountdefaultuser' => 'asterisk', 'astaccountdeny' => 'asterisk', 'astaccounthost' => 'asterisk', 'astaccountmailbox' => 'asterisk', 'astaccountnat' => 'asterisk', 'astaccountname' => 'asterisk', 'astaccountqualify' => 'asterisk', 'astaccountrealmedpassword' => 'asterisk', 'astaccountregistrationexten' => 'asterisk', 'astaccountregistrationcontext' => 'asterisk', 'astaccountsecret' => 'asterisk', 'astaccounttype' => 'asterisk', 'astcontext' => 'asterisk', 'astextension' => 'asterisk', 'astvoicemailpassword' => 'asterisk', ); // Prepare fields list($fields, $types, $type) = $this->form_prepare('user', $data, array('userpassword2')); //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 user type id selector $fields['type_id'] = array( 'section' => 'personal', 'type' => kolab_form::INPUT_SELECT, 'options' => $accttypes, 'onchange' => "kadm.user_save(true, 'personal')", ); // Add password confirmation if (isset($fields['userpassword'])) { $fields['userpassword2'] = $fields['userpassword']; // Add 'Generate password' link if (empty($fields['userpassword']['readonly'])) { $fields['userpassword']['suffix'] = kolab_html::a(array( 'content' => $this->translate('password.generate'), 'href' => '#', 'onclick' => "kadm.generate_password('userpassword')", 'class' => 'nowrap', )); } } // 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) { // copy password to password confirm field $data['userpassword2'] = $data['userpassword']; // Page title $title = $this->translate('user.add'); } // Edit mode else { $title = $data['displayname']; if (empty($title)) { $title = $data['cn']; } // remove password $data['userpassword'] = ''; // Add user type name $fields['type_id_name'] = array( 'label' => 'user.type_id', 'section' => 'personal', 'value' => $accttypes[$type]['content'], ); } // Create form object and populate with fields $form = $this->form_create('user', $attribs, $sections, $fields, $fields_map, $data, $add_mode); $form->set_title(kolab_html::escape($title)); $this->output->add_translation('user.password.mismatch'); return $form->output(); } /** * List item handler */ protected function list_item_handler($item) { return empty($item['displayname']) ? $item['cn'] : $item['displayname']; } }