Skip to content

Commit

Permalink
Add allow_fields_inscription field see BT#10102
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Jul 16, 2015
1 parent fb8b7ab commit e97a2d8
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 16 deletions.
84 changes: 68 additions & 16 deletions main/auth/inscription.php
Expand Up @@ -13,9 +13,21 @@
$_GET['language'] = $_POST['language'];
}
require_once '../inc/global.inc.php';

$hideHeaders = isset($_GET['hide_headers']);

$allowedFields = [
'official_code',
'phone',
'status',
'language',
'extra_fields'
];

$allowedFieldsConfiguration = api_get_configuration_value('allow_fields_inscription');
if ($allowedFieldsConfiguration != false) {
$allowedFields = $allowedFieldsConfiguration;
}

$htmlHeadXtra[] = api_get_password_checker_js('#username', '#pass1');

// User is not allowed if Terms and Conditions are disabled and
Expand Down Expand Up @@ -88,13 +100,20 @@

// OFFICIAL CODE
if (CONFVAL_ASK_FOR_OFFICIAL_CODE) {
$form->addElement('text', 'official_code', get_lang('OfficialCode'), array('size' => 40));
if (api_get_setting('registration', 'officialcode') == 'true') {
$form->addRule(
if (in_array('official_code', $allowedFields)) {
$form->addElement(
'text',
'official_code',
get_lang('ThisFieldIsRequired'),
'required'
get_lang('OfficialCode'),
array('size' => 40)
);
if (api_get_setting('registration', 'officialcode') == 'true') {
$form->addRule(
'official_code',
get_lang('ThisFieldIsRequired'),
'required'
);
}
}
}

Expand Down Expand Up @@ -131,19 +150,50 @@
}

// PHONE
$form->addElement('text', 'phone', get_lang('Phone'), array('size' => 20));
if (api_get_setting('registration', 'phone') == 'true') {
$form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required');
if (in_array('phone', $allowedFields)) {
$form->addElement(
'text',
'phone',
get_lang('Phone'),
array('size' => 20)
);
if (api_get_setting('registration', 'phone') == 'true') {
$form->addRule(
'phone',
get_lang('ThisFieldIsRequired'),
'required'
);
}
}

// LANGUAGE
if (api_get_setting('registration', 'language') == 'true') {
$form->addElement('select_language', 'language', get_lang('Language'));
if (in_array('language', $allowedFields)) {
if (api_get_setting('registration', 'language') == 'true') {
$form->addElement(
'select_language',
'language',
get_lang('Language')
);
}
}
// STUDENT/TEACHER
if (api_get_setting('allow_registration_as_teacher') != 'false') {
$form->addElement('radio', 'status', get_lang('Profile'), get_lang('RegStudent'), STUDENT);
$form->addElement('radio', 'status', null, get_lang('RegAdmin'), COURSEMANAGER);
if (in_array('status', $allowedFields)) {
$form->addElement(
'radio',
'status',
get_lang('Profile'),
get_lang('RegStudent'),
STUDENT
);
$form->addElement(
'radio',
'status',
null,
get_lang('RegAdmin'),
COURSEMANAGER
);
}
}

$captcha = api_get_setting('allow_captcha');
Expand Down Expand Up @@ -218,8 +268,10 @@
}

// EXTRA FIELDS
$extraField = new ExtraField('user');
$returnParams = $extraField->addElements($form);
if (in_array('extra_fields', $allowedFields)) {
$extraField = new ExtraField('user');
$returnParams = $extraField->addElements($form);
}
}

if (isset($_SESSION['user_language_choice']) && $_SESSION['user_language_choice'] != '') {
Expand Down Expand Up @@ -405,7 +457,7 @@

$status = isset($values['status']) ? $values['status'] : STUDENT;
$phone = isset($values['phone']) ? $values['phone'] : null;

$values['language'] = isset($values['language']) ? $values['language'] : api_get_interface_language();
// Creates a new user
$user_id = UserManager::create_user(
$values['firstname'],
Expand Down
8 changes: 8 additions & 0 deletions main/install/configuration.dist.php
Expand Up @@ -215,3 +215,11 @@

// Allow anonymous users to see the courses/sessions catalogue
//$_configuration['course_catalog_published'] = 'false';
// Only shows the fields in this list
/*$_configuration['allow_fields_inscription'] = [
'official_code',
'phone',
'status',
'language',
'extra_fields'
];*/

0 comments on commit e97a2d8

Please sign in to comment.