Skip to content

Commit

Permalink
Add support for phone numbers to extra fields - refs #7252
Browse files Browse the repository at this point in the history
  • Loading branch information
ilosada committed Aug 29, 2014
1 parent 07eda14 commit 5720f35
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main/auth/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ function show_icon_edit(element_html) {
} else {
$form->freeze();
}

var_dump($extra_data);
$user_data = array_merge($user_data, $extra_data);
$form->setDefaults($user_data);

Expand Down
13 changes: 13 additions & 0 deletions main/inc/lib/extra_field.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ExtraField extends Model
const FIELD_TYPE_TIMEZONE = 11;
const FIELD_TYPE_SOCIAL_PROFILE = 12;
const FIELD_TYPE_CHECKBOX = 13;
const FIELD_TYPE_TELEPHONE = 14;

public $type = 'user'; //or session or course
public $handler_id = 'user_id';
Expand Down Expand Up @@ -204,6 +205,7 @@ public static function get_extra_fields_by_handler($handler)
$types[self::FIELD_TYPE_TAG] = get_lang('FieldTypeTag');
$types[self::FIELD_TYPE_TIMEZONE] = get_lang('FieldTypeTimezone');
$types[self::FIELD_TYPE_SOCIAL_PROFILE] = get_lang('FieldTypeSocialProfile');
$types[self::FIELD_TYPE_TELEPHONE] = get_lang('FieldTypeTelephone');

switch ($handler) {
case 'course':
Expand Down Expand Up @@ -1036,6 +1038,17 @@ public function set_extra_fields_in_form(
$form->freeze('extra_'.$field_details['field_variable']);
}
break;
case ExtraField::FIELD_TYPE_TELEPHONE:
$form->addElement('text', 'extra_'.$field_details['field_variable'], $field_details['field_display_text'],
array('placeholder' => '(xx)xxxxxxxxx'));
$form->applyFilter('extra_'.$field_details['field_variable'], 'stripslashes');
$form->applyFilter('extra_'.$field_details['field_variable'], 'trim');
$form->applyFilter('extra_'.$field_details['field_variable'], 'telephone');
$form->addRule('extra_'.$field_details[1], get_lang('TelephoneWrong'), 'telephone');
if ($field_details['field_visible'] == 0) {
$form->freeze('extra_'.$field_details['field_variable']);
}
break;
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions main/inc/lib/formvalidator/FormValidator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ function __construct($form_name, $method = 'post', $action = '', $target = '', $
$this->registerRule('filetype', null, 'HTML_QuickForm_Rule_Filetype', $dir . 'Rule/Filetype.php');
$this->registerRule('multiple_required', 'required', 'HTML_QuickForm_Rule_MultipleRequired', $dir . 'Rule/MultipleRequired.php');
$this->registerRule('url', null, 'HTML_QuickForm_Rule_Url', $dir . 'Rule/Url.php');
$this->registerRule('telephone', null, 'HTML_QuickForm_Rule_Telephone', $dir . 'Rule/Telephone.php');
$this->registerRule('compare_fields', null, 'HTML_QuickForm_Compare_Fields', $dir . 'Rule/CompareFields.php');
$this->registerRule('CAPTCHA', 'rule', 'HTML_QuickForm_Rule_CAPTCHA', 'HTML/QuickForm/Rule/CAPTCHA.php');

Expand Down Expand Up @@ -638,3 +639,17 @@ function html_filter_student_fullpage($html)
{
return html_filter($html, STUDENT_HTML_FULLPAGE);
}

/**
* Cleans telephone text
* @param string $telephone Telephone to clean
* @return string The cleaned telephone
*/
function telephone_filter($telephone)
{
$telephone= trim ($telephone,'(');
$telephone= trim ($telephone,')');
$telephone= ltrim ($telephone,'+');
$telephone= ltrim ($telephone,'0');
return $telephone;
}
15 changes: 15 additions & 0 deletions main/inc/lib/usermanager.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class UserManager
const USER_FIELD_TYPE_TIMEZONE = 11;
const USER_FIELD_TYPE_SOCIAL_PROFILE = 12;
const USER_FIELD_TYPE_FILE = 13;
const USER_FIELD_TYPE_TELEPHONE = 14;

/**
* The default constructor only instanciates an empty user object
Expand Down Expand Up @@ -4556,6 +4557,19 @@ static function set_extra_fields_in_form($form, $extra_data, $form_name, $admin_
$form->freeze($extra_field);
}
break;

case self::USER_FIELD_TYPE_TELEPHONE:
$form->addElement('text', 'extra_'.$field_details[1], $field_details[3]." (".get_lang('TelephonePrefix').")",
array('size' => 40, 'placeholder' => '(xx)xxxxxxxxx'));
$form->applyFilter('extra_'.$field_details[1], 'stripslashes');
$form->applyFilter('extra_'.$field_details[1], 'trim');
$form->applyFilter('extra_'.$field_details[1], 'telephone_filter');
$form->addRule('extra_'.$field_details[1], get_lang('TelephoneWrong'), 'telephone');
if (!$admin_permissions) {
if ($field_details[7] == 0)
$form->freeze('extra_'.$field_details[1]);
}
break;
}
}
$return = array();
Expand All @@ -4582,6 +4596,7 @@ static function get_user_field_types()
$types[self::USER_FIELD_TYPE_TIMEZONE] = get_lang('FieldTypeTimezone');
$types[self::USER_FIELD_TYPE_SOCIAL_PROFILE] = get_lang('FieldTypeSocialProfile');
$types[self::USER_FIELD_TYPE_FILE] = get_lang('FieldTypeFile');
$types[self::USER_FIELD_TYPE_TELEPHONE] = get_lang('FieldTypeTelephone');

return $types;
}
Expand Down

0 comments on commit 5720f35

Please sign in to comment.