$("#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('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);
// Status
$status = [];
$status[COURSEMANAGER] = get_lang('Teacher');
$status[STUDENT] = get_lang('Learner');
$status[DRH] = get_lang('Drh');
$status[SESSIONADMIN] = get_lang('SessionsAdmin');
$status[STUDENT_BOSS] = get_lang('RoleStudentBoss');
$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', '