$(document).ready(function() {
$("#password").keypress(function() {
$("#password").each(function(index, value) {
var value = $(this).attr("value");
if (value == 0) {
$("#password_progress").show();
$(".password-verdict").show();
$(".error-list").show();
} else {
$("#password_progress").hide();
$(".password-verdict").hide();
$(".error-list").hide();
}
});
});
});
';
}
$htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css');
$htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js');
$htmlHeadXtra[] = '
';
if (!empty($_GET['message'])) {
$message = urldecode($_GET['message']);
}
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
$interbreadcrumb[] = ["url" => 'user_list.php', "name" => get_lang('UserList')];
$tool_name = get_lang('AddUsers');
// Create the form
$form = new FormValidator('user_add');
$form->addElement('header', '', $tool_name);
if (api_is_western_name_order()) {
// Firstname
$form->addElement(
'text',
'firstname',
get_lang('FirstName'),
[
'id' => 'firstname'
]
);
$form->applyFilter('firstname', 'html_filter');
$form->applyFilter('firstname', 'trim');
$form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
// Lastname
$form->addElement(
'text',
'lastname',
get_lang('LastName'),
[
'id' => 'lastname'
]
);
$form->applyFilter('lastname', 'html_filter');
$form->applyFilter('lastname', 'trim');
$form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
} else {
// Lastname
$form->addElement(
'text',
'lastname',
get_lang('LastName'),
[
'id' => 'lastname'
]
);
$form->applyFilter('lastname', 'html_filter');
$form->applyFilter('lastname', 'trim');
$form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
// Firstname
$form->addElement(
'text',
'firstname',
get_lang('FirstName'),
[
'id' => 'firstname'
]
);
$form->applyFilter('firstname', 'html_filter');
$form->applyFilter('firstname', 'trim');
$form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
}
// Official code
$form->addElement(
'text',
'official_code',
get_lang('OfficialCode'),
[
'size' => '40',
'id' => 'official_code'
]
);
$form->applyFilter('official_code', 'html_filter');
$form->applyFilter('official_code', 'trim');
// Email
$form->addElement('text', 'email', get_lang('Email'), ['size' => '40', 'autocomplete' => 'off', 'id' => 'email']);
$form->addRule('email', get_lang('EmailWrong'), 'email');
if (api_get_setting('registration', 'email') == 'true') {
$form->addRule('email', get_lang('EmailWrong'), 'required');
}
if (api_get_setting('login_is_email') == 'true') {
$form->addRule('email', sprintf(get_lang('UsernameMaxXCharacters'), (string) USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
$form->addRule('email', get_lang('UserTaken'), 'username_available');
}
// Phone
$form->addElement('text', 'phone', get_lang('PhoneNumber'), ['autocomplete' => 'off', 'id' => 'phone']);
// Picture
$form->addFile(
'picture',
get_lang('AddImage'),
['id' => 'picture', 'class' => 'picture-form', 'crop_image' => true, 'crop_ratio' => '1 / 1']
);
$allowed_picture_types = api_get_supported_image_extensions(false);
$form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
// Username
if (api_get_setting('login_is_email') != 'true') {
$form->addElement('text', 'username', get_lang('LoginName'), ['id'=> 'username', 'maxlength' => USERNAME_MAX_LENGTH, 'autocomplete' => 'off']);
$form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('username', sprintf(get_lang('UsernameMaxXCharacters'), (string) USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
$form->addRule('username', get_lang('OnlyLettersAndNumbersAllowed'), 'username');
$form->addRule('username', get_lang('UserTaken'), 'username_available');
}
// Password
$group = [];
$auth_sources = 0; //make available wider as we need it in case of form reset (see below)
$nb_ext_auth_source_added = 0;
if (isset($extAuthSource) && count($extAuthSource) > 0) {
$auth_sources = [];
foreach ($extAuthSource as $key => $info) {
// @todo : make uniform external authentification configuration (ex : cas and external_login ldap)
// Special case for CAS. CAS is activated from Chamilo > Administration > Configuration > CAS
// extAuthSource always on for CAS even if not activated
// same action for file user_edit.php
if (($key == CAS_AUTH_SOURCE && api_get_setting('cas_activate') === 'true') || ($key != CAS_AUTH_SOURCE)) {
$auth_sources[$key] = $key;
$nb_ext_auth_source_added++;
}
}
if ($nb_ext_auth_source_added > 0) {
$group[] = $form->createElement('radio', 'password_auto', null, get_lang('ExternalAuthentication').' ', 2);
$group[] = $form->createElement('select', 'auth_source', null, $auth_sources);
$group[] = $form->createElement('static', '', '', '
');
}
}
$group[] = $form->createElement(
'radio',
'password_auto',
get_lang('Password'),
get_lang('AutoGeneratePassword').'
',
1
);
$group[] = $form->createElement(
'radio',
'password_auto',
'id="radio_user_password"',
get_lang('EnterPassword'),
0
);
$group[] = $form->createElement(
'password',
'password',
null,
[
'id' => 'password',
'autocomplete' => 'off',
'onkeydown' => 'javascript: password_switch_radio_button();',
//'required' => 'required'
]
);
$form->addGroup($group, 'password', get_lang('Password'));
$form->addPasswordRule('password', 'password');
$form->addGroupRule('password', get_lang('EnterPassword'), 'required', null, 1);
if ($checkPass) {
$strengthLabels = '