Freeze inputs if changeable is on fixes #1603 ~Requires testing

pull/2487/head
jmontoyaa 8 years ago
parent 73e95d51ce
commit bcab2ee6ac
  1. 11
      main/admin/user_edit.php
  2. 5
      main/auth/profile.php
  3. 172
      main/inc/lib/extra_field.lib.php

@ -316,7 +316,16 @@ $form->addElement('advmultiselect', 'student_boss', get_lang('StudentBoss'), $st
// EXTRA FIELDS
$extraField = new ExtraField('user');
$returnParams = $extraField->addElements($form, $user_data['user_id']);
$returnParams = $extraField->addElements(
$form,
$user_data['user_id'],
[],
false,
false,
[],
[],
true
);
$jquery_ready_content = $returnParams['jquery_ready_content'];
// the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function

@ -322,7 +322,10 @@ if (is_platform_authentication() &&
}
$extraField = new ExtraField('user');
$return = $extraField->addElements($form, api_get_user_id());
$return = $extraField->addElements(
$form,
api_get_user_id()
);
$jquery_ready_content = $return['jquery_ready_content'];

@ -449,6 +449,7 @@ class ExtraField extends Model
* @param bool $useTagAsSelect
* @param array $showOnlyThisFields
* @param array $orderFields
* @param bool $adminPermissions
*
* @return array|bool
*/
@ -459,7 +460,8 @@ class ExtraField extends Model
$filter = false,
$useTagAsSelect = false,
$showOnlyThisFields = [],
$orderFields = []
$orderFields = [],
$adminPermissions = false
) {
if (empty($form)) {
return false;
@ -480,11 +482,12 @@ class ExtraField extends Model
if ($filter) {
$conditions = ['filter = ?' => 1];
}
$extraFields = $this->get_all($conditions, 'option_order');
$extra = $this->set_extra_fields_in_form(
$form,
$extraData,
false,
$adminPermissions,
$extraFields,
$itemId,
$exclude,
@ -803,6 +806,9 @@ class ExtraField extends Model
* @param bool $useTagAsSelect
* @param array $showOnlyThisFields
* @param array $orderFields
* @param bool $canModify
* @param bool $visibleToSelf
*
* @return array If relevant, returns a one-element array with JS code to be added to the page HTML headers
*/
public function set_extra_fields_in_form(
@ -867,6 +873,11 @@ class ExtraField extends Model
}
}
$freezeElement = false;
if (!$admin_permissions) {
$freezeElement = $field_details['visible_to_self'] == 0 || $field_details['changeable'] == 0;
}
switch ($field_details['field_type']) {
case ExtraField::FIELD_TYPE_TEXT:
$form->addElement(
@ -877,12 +888,8 @@ class ExtraField extends Model
);
$form->applyFilter('extra_'.$field_details['variable'], 'stripslashes');
$form->applyFilter('extra_'.$field_details['variable'], 'trim');
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_'.$field_details['variable']
);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_TEXTAREA:
@ -895,12 +902,8 @@ class ExtraField extends Model
);
$form->applyFilter('extra_'.$field_details['variable'], 'stripslashes');
$form->applyFilter('extra_'.$field_details['variable'], 'trim');
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_'.$field_details['variable']
);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_RADIO:
@ -922,12 +925,8 @@ class ExtraField extends Model
'extra_'.$field_details['variable'],
$field_details['display_text']
);
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_'.$field_details['variable']
);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_CHECKBOX:
@ -968,12 +967,8 @@ class ExtraField extends Model
'extra_'.$field_details['variable'],
$field_details['display_text']
);
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_'.$field_details['variable']
);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_SELECT:
@ -1000,7 +995,6 @@ class ExtraField extends Model
if ($optionsExists) {
if (isset($userInfo['status']) && !empty($userInfo['status'])) {
$fieldWorkFlow = $app['orm.em']->getRepository('ChamiloLMS\Entity\ExtraFieldOptionRelFieldOption')
->findBy(
array(
@ -1138,10 +1132,8 @@ class ExtraField extends Model
}
*/
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze('extra_' . $field_details['variable']);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_SELECT_MULTIPLE:
@ -1156,18 +1148,14 @@ class ExtraField extends Model
$options,
array('multiple' => 'multiple', 'id' => 'extra_'.$field_details['variable'])
);
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze('extra_'.$field_details['variable']);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_DATE:
$form->addDatePicker('extra_'.$field_details['variable'], $field_details['display_text']);
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze('extra_'.$field_details['variable']);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_DATETIME:
@ -1180,10 +1168,8 @@ class ExtraField extends Model
if (!isset($form->_defaultValues['extra_'.$field_details['variable']])) {
$form->setDefaults($defaults);
}
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze('extra_'.$field_details['variable']);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_DOUBLE_SELECT:
@ -1261,10 +1247,8 @@ class ExtraField extends Model
$field_details['display_text']
);
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze('extra_'.$field_details['variable']);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_DIVIDER:
@ -1390,10 +1374,8 @@ EOF;
api_get_timezones(),
''
);
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_'.$field_details['variable']
);
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_SOCIAL_PROFILE:
@ -1424,7 +1406,7 @@ EOF;
);
$form->applyFilter('extra_'.$field_details['variable'], 'stripslashes');
$form->applyFilter('extra_'.$field_details['variable'], 'trim');
if ($field_details['visible_to_self'] == 0) {
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
@ -1443,7 +1425,7 @@ EOF;
get_lang('MobilePhoneNumberWrong'),
'mobile_phone_number'
);
if ($field_details['visible_to_self'] == 0) {
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
@ -1459,17 +1441,12 @@ EOF;
$form->applyFilter('extra_'.$field_details['variable'], 'trim');
$form->applyFilter('extra_'.$field_details['variable'], 'intval');
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_'.$field_details['variable']
);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_FILE_IMAGE:
$fieldVariable = "extra_{$field_details['variable']}";
$fieldTexts = [
$field_details['display_text']
];
@ -1505,12 +1482,8 @@ EOF;
$allowed_picture_types
);
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_'.$field_details['variable']
);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_FLOAT:
@ -1525,12 +1498,8 @@ EOF;
$form->applyFilter('extra_'.$field_details['variable'], 'trim');
$form->applyFilter('extra_'.$field_details['variable'], 'floatval');
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_'.$field_details['variable']
);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_FILE:
@ -1564,12 +1533,8 @@ EOF;
$form->applyFilter('extra_'.$field_details['variable'], 'stripslashes');
$form->applyFilter('extra_'.$field_details['variable'], 'trim');
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_'.$field_details['variable']
);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_VIDEO_URL:
@ -1579,6 +1544,9 @@ EOF;
false,
['placeholder' => 'https://']
);
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_LETTERS_ONLY:
$form->addTextLettersOnly(
@ -1587,12 +1555,8 @@ EOF;
);
$form->applyFilter('extra_' . $field_details['variable'], 'stripslashes');
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_' . $field_details['variable']
);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_ALPHANUMERIC:
@ -1604,12 +1568,8 @@ EOF;
'extra_' . $field_details['variable'],
'stripslashes'
);
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_' . $field_details['variable']
);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_LETTERS_SPACE:
@ -1619,12 +1579,8 @@ EOF;
);
$form->applyFilter('extra_' . $field_details['variable'], 'stripslashes');
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_' . $field_details['variable']
);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_ALPHANUMERIC_SPACE:
@ -1636,12 +1592,8 @@ EOF;
'extra_' . $field_details['variable'],
'stripslashes'
);
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_' . $field_details['variable']
);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
break;
case ExtraField::FIELD_TYPE_GEOLOCALIZATION:
@ -1656,12 +1608,8 @@ EOF;
);
$form->applyFilter('extra_'.$field_details['variable'], 'stripslashes');
$form->applyFilter('extra_'.$field_details['variable'], 'trim');
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_'.$field_details['variable']
);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
$form->addHtml(
@ -1800,12 +1748,8 @@ EOF;
);
$form->applyFilter('extra_'.$field_details['variable'], 'stripslashes');
$form->applyFilter('extra_'.$field_details['variable'], 'trim');
if (!$admin_permissions) {
if ($field_details['visible_to_self'] == 0) {
$form->freeze(
'extra_'.$field_details['variable']
);
}
if ($freezeElement) {
$form->freeze('extra_'.$field_details['variable']);
}
$latLag = explode(",", $dataValue);

Loading…
Cancel
Save