$("#status_select").ready(function() {
if ($(this).attr("value") != '.STUDENT.') {
$("#id_platform_admin").hide();
}
});
function enable_expiration_date() { //v2.0
document.user_add.radio_expiration_date[0].checked=false;
document.user_add.radio_expiration_date[1].checked=true;
}
function password_switch_radio_button() {
var input_elements = document.getElementsByTagName("input");
for (var i = 0; i < input_elements.length; i++) {
if (input_elements.item(i).name == "password[password_auto]" && input_elements.item(i).value == "0") {
input_elements.item(i).checked = true;
}
}
}
var is_platform_id = "'.$is_platform_admin.'";
function display_drh_list(){
if (document.getElementById("status_select").value=='.STUDENT.') {
document.getElementById("drh_list").style.display="block";
if (is_platform_id == 1)
document.getElementById("id_platform_admin").style.display="none";
} else if (document.getElementById("status_select").value=='.COURSEMANAGER.') {
document.getElementById("drh_list").style.display="none";
if (is_platform_id == 1)
document.getElementById("id_platform_admin").style.display="block";
} else {
document.getElementById("drh_list").style.display="none";
if (is_platform_id == 1)
document.getElementById("id_platform_admin").style.display="none";
}
}
';
if (!empty($_GET['message'])) {
$message = urldecode($_GET['message']);
}
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
$interbreadcrumb[] = ["url" => 'user_list.php', "name" => get_lang('User list')];
$tool_name = get_lang('Add a user');
// 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('First name'),
[
'id' => 'firstname',
]
);
$form->applyFilter('firstname', 'html_filter');
$form->applyFilter('firstname', 'trim');
$form->addRule('firstname', get_lang('Required field'), 'required');
// Lastname
$form->addElement(
'text',
'lastname',
get_lang('Last name'),
[
'id' => 'lastname',
]
);
$form->applyFilter('lastname', 'html_filter');
$form->applyFilter('lastname', 'trim');
$form->addRule('lastname', get_lang('Required field'), 'required');
} else {
// Lastname
$form->addElement(
'text',
'lastname',
get_lang('Last name'),
[
'id' => 'lastname',
]
);
$form->applyFilter('lastname', 'html_filter');
$form->applyFilter('lastname', 'trim');
$form->addRule('lastname', get_lang('Required field'), 'required');
// Firstname
$form->addElement(
'text',
'firstname',
get_lang('First name'),
[
'id' => 'firstname',
]
);
$form->applyFilter('firstname', 'html_filter');
$form->applyFilter('firstname', 'trim');
$form->addRule('firstname', get_lang('Required field'), 'required');
}
// Official code
$form->addElement(
'text',
'official_code',
get_lang('Code'),
[
'size' => '40',
'id' => 'official_code',
]
);
$form->applyFilter('official_code', 'html_filter');
$form->applyFilter('official_code', 'trim');
// e-mail
$form->addElement('text', 'email', get_lang('e-mail'), ['size' => '40', 'autocomplete' => 'off', 'id' => 'email']);
$form->addRule('email', get_lang('e-mailWrong'), 'email');
if (api_get_setting('registration', 'email') == 'true') {
$form->addRule('email', get_lang('e-mailWrong'), 'required');
}
if (api_get_setting('login_is_email') == 'true') {
$form->addRule('email', sprintf(get_lang('The login needs to be maximum %s characters long'), (string) USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
$form->addRule('email', get_lang('This login is already in use'), 'username_available');
}
// Phone
$form->addElement('text', 'phone', get_lang('Phone number'), ['autocomplete' => 'off', 'id' => 'phone']);
// Picture
$form->addFile(
'picture',
get_lang('Add image'),
['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('Only PNG, JPG or GIF images allowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
// Username
if (api_get_setting('login_is_email') != 'true') {
$form->addElement('text', 'username', get_lang('Login'), ['id' => 'username', 'maxlength' => USERNAME_MAX_LENGTH, 'autocomplete' => 'off']);
$form->addRule('username', get_lang('Required field'), 'required');
$form->addRule('username', sprintf(get_lang('The login needs to be maximum %s characters long'), (string) USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
$form->addRule('username', get_lang('Only letters and numbers allowed'), 'username');
$form->addRule('username', get_lang('This login is already in use'), '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('External authentification').' ', 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('Automatically generate a new password').'
',
1
);
$group[] = $form->createElement(
'radio',
'password_auto',
'id="radio_user_password"',
get_lang('Enter password'),
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('Enter password'), 'required', null, 1);
// Status
$status = [];
$status[COURSEMANAGER] = get_lang('Trainer');
$status[STUDENT] = get_lang('Learner');
$status[DRH] = get_lang('Human Resources Manager');
$status[SESSIONADMIN] = get_lang('Sessions administrator');
$status[STUDENT_BOSS] = get_lang('Student\'s superior');
$status[INVITEE] = get_lang('Invitee');
$form->addElement(
'select',
'status',
get_lang('Profile'),
$status,
[
'id' => 'status_select',
'onchange' => 'javascript: display_drh_list();',
]
);
//drh list (display only if student)
$display = (isset($_POST['status']) && $_POST['status'] == STUDENT) || !isset($_POST['status']) ? 'block' : 'none';
//@todo remove the drh list here. This code is unused
$form->addElement('html', '