/* Primary group management */ if ($FH->isUpdated("primary")) { $primaryGroup = getUserPrimaryGroup($uid); if ($FH->getValue("primary") != $primaryGroup) { /* Update the primary group */ $ret = callPluginFunction("changeUserPrimaryGroup", array($uid, $FH->getValue("primary"), $primaryGroup)); foreach ($ret as $plugin => $err) { if ($err != 0 && $err != NULL) { $result .= sprintf(_("Failed to change primary group in %s plugin"), $plugin) . "<br />"; } } } } /* Secondary groups management */ if ($FH->isUpdated("secondary")) { $old = getUserSecondaryGroups($uid); $new = $FH->getValue('secondary'); foreach (array_diff($old, $new) as $group) { del_member($group, $uid); callPluginFunction("delUserFromGroup", array($uid, $group)); } foreach (array_diff($new, $old) as $group) { add_member($group, $uid); callPluginFunction("addUserToGroup", array($uid, $group)); } } /* Password change management */ if ($mode == 'edit' && $FH->getValue('pass')) { $ret = callPluginFunction("changeUserPasswd", array(array($uid, prepare_string($FH->getValue('pass'))))); if (isXMLRPCError()) { $error .= _("Password not updated") . "<br />";
/** * Form on user edit page * @param $FH FormHandler of the page * @param $mode add or edit mode */ function _base_baseEdit($FH, $mode) { $uid = $FH->getArrayOrPostValue("uid"); $f = new DivForModule(_("User attributes"), "#F4F4F4"); $f->push(new Table()); if ($mode == "add") { $loginTpl = new InputTpl("uid", '/^[a-zA-Z0-9][A-Za-z0-9_.\\-]*$/'); } else { $loginTpl = new HiddenTpl("uid"); } $f->add(new TrFormElement(_("Login") . "*", $loginTpl), array("value" => $uid)); /*if($mode == "edit") { $lastlog = get_last_log_user($uid); if ($lastlog[0] != 0) { $f->add( new LinkTrFormElement(_("Last action"), new HiddenTpl("lastaction")), array("value" => urlStr("base/users/loguser", array("user" => $uid)), "name" => $lastlog[1][0]["date"]) ); } }*/ $f->add(new TrFormElement(_("Password") . "*", new PasswordTpl("pass")), array("value" => "")); $f->add(new TrFormElement(_("Confirm password") . "*", new PasswordTpl("confpass")), array("value" => "")); $f->add(new TrFormElement(_("Photo"), new ImageTpl("jpegPhoto")), array("value" => $FH->getArrayOrPostValue("jpegPhoto"), "action" => $mode)); $f->add(new TrFormElement(_("Last name") . "*", new InputTpl("sn")), array("value" => $FH->getArrayOrPostValue("sn"))); $f->add(new TrFormElement(_("First name") . "*", new InputTpl("givenName")), array("value" => $FH->getArrayOrPostValue("givenName"))); $f->add(new TrFormElement(_("Title") . "*", new InputTpl("title")), array("value" => $FH->getArrayOrPostValue("title"))); $f->add(new TrFormElement(_("Email address"), new MailInputTpl("mail")), array("value" => $FH->getArrayOrPostValue("mail"))); $f->pop(); $phoneregexp = "/^[a-zA-Z0-9(/ +\\-]*\$/"; $tn = new MultipleInputTpl("telephoneNumber", _("Telephone number")); $tn->setRegexp($phoneregexp); $f->add(new FormElement(_("Telephone number"), $tn), $FH->getArrayOrPostValue("telephoneNumber", "array")); $f->push(new Table()); $f->add(new TrFormElement(_("Mobile number"), new InputTpl("mobile", $phoneregexp)), array("value" => $FH->getArrayOrPostValue("mobile"))); $f->add(new TrFormElement(_("Fax number"), new InputTpl("facsimileTelephoneNumber", $phoneregexp)), array("value" => $FH->getArrayOrPostValue("facsimileTelephoneNumber"))); $f->add(new TrFormElement(_("Home phone number"), new InputTpl("homePhone", $phoneregexp)), array("value" => $FH->getArrayOrPostValue("homePhone"))); $languages = new SelectItem("preferredLanguage"); $labels = array(_("Choose language")) + array_values(getLanguages()); $values = array("") + array_keys(getLanguages()); $languages->setElements($labels); $languages->setElementsVal($values); $f->add(new TrFormElement(_("Preferred language"), $languages), array("value" => $FH->getArrayOrPostValue("preferredLanguage"))); $checked = "checked"; if ($FH->getArrayOrPostValue("loginShell") != '/bin/false') { $checked = ""; } $f->add(new TrFormElement(_("Disable user's shell"), new CheckboxTpl("isBaseDesactive"), array("tooltip" => _("A disabled user can't log in any UNIX services.<br/>\n His login shell command is replaced by /bin/false"))), array("value" => $checked)); /* Primary group */ $groupsTpl = new SelectItem("primary"); $all_groups = search_groups(); $groups = array(); foreach ($all_groups as $key => $infos) { $groups[] = $infos[0]; } $groupsTpl->setElements($groups); if ($mode == "add") { $primary = getUserDefaultPrimaryGroup(); } else { if ($mode == "edit") { /* In case of error, display the POST values */ if ($FH->isUpdated("primary")) { $primary = $FH->getValue("primary"); } else { $primary = getUserPrimaryGroup($uid); /* If the group is not an LDAP group */ if (!in_array($primary, $groups)) { $primaryGroups = $groups; $primaryGroups[] = $primary; $groupsTpl->setElements($primaryGroups); } } } } $f->add(new TrFormElement(_("Primary group"), $groupsTpl), array("value" => $primary)); /* Secondary groups */ $groupsTpl = new MembersTpl("secondary"); $groupsTpl->setTitle(_("User's groups"), _("All groups")); // get the user's groups /* In case of error, display the POST values */ if ($FH->getPostValue("secondary")) { $user_groups = $FH->getPostValue("secondary"); } else { if ($mode == 'edit') { $user_groups = getUserSecondaryGroups($uid); } else { $user_groups = array(); } } $member = array(); foreach ($user_groups as $group) { $member[$group] = $group; } // get all groups $available = array(); foreach ($groups as $group) { if (!in_array($group, $member)) { $available[$group] = $group; } } $f->add(new TrFormElement(_("Secondary groups"), $groupsTpl), array("member" => $member, "available" => $available)); $f->pop(); $f->push(new DivExpertMode()); $f->push(new Table()); $f->add(new TrFormElement(_("Home directory"), new InputTpl("homeDirectory")), array("value" => $FH->getArrayOrPostValue("homeDirectory"))); if ($mode == "add") { $f->add(new TrFormElement(_("Create home directory on filesystem"), new CheckboxTpl("createHomeDir")), array("value" => "checked")); $f->add(new TrFormElement(_("Force to use the home directory if it exists"), new CheckboxTpl("ownHomeDir"), array("tooltip" => _("Warning: an existing directory may belong to another user !"))), array("value" => "")); } $f->add(new TrFormElement(_("Login shell"), new InputTpl("loginShell")), array("value" => $FH->getArrayOrPostValue("loginShell"))); $f->add(new TrFormElement(_("Common name"), new InputTpl("cn"), array("tooltip" => _("This field is used by some LDAP clients (for example Thunderbird address book) to display user entries."))), array("value" => $FH->getArrayOrPostValue("cn"))); $f->add(new TrFormElement(_("Preferred name to be used"), new InputTpl("displayName"), array("tooltip" => _("This field is used by SAMBA (and other LDAP clients) to display user name."))), array("value" => $FH->getArrayOrPostValue("displayName"))); if ($mode == "edit") { $f->add(new TrFormElement(_("UID"), new HiddenTpl("uidNumber")), array("value" => $FH->getArrayOrPostValue("uidNumber"))); $f->add(new TrFormElement(_("GID"), new HiddenTpl("gidNumber")), array("value" => $FH->getArrayOrPostValue("gidNumber"))); } $f->pop(); $f->pop(); return $f; }