Merge pull request #363 from ilosada/7252b

Add mobile phone field, filter, validation and translations - refs #7252
1.9.x
Julio 10 years ago
commit c196f2a13e
  1. 24
      main/inc/lib/extra_field.lib.php
  2. 19
      main/inc/lib/formvalidator/FormValidator.class.php
  3. 26
      main/inc/lib/formvalidator/Rule/MobilePhoneNumber.php
  4. 22
      main/inc/lib/usermanager.lib.php
  5. 3
      main/lang/english/trad4all.inc.php
  6. 3
      main/lang/spanish/trad4all.inc.php

@ -51,7 +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;
const FIELD_TYPE_MOBILE_PHONE_NUMBER = 14;
public $type = 'user'; //or session or course
public $handler_id = 'user_id';
@ -205,7 +205,7 @@ class ExtraField extends Model
$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');
$types[self::FIELD_TYPE_MOBILE_PHONE_NUMBER] = get_lang('FieldTypeMobilePhoneNumber');
switch ($handler) {
case 'course':
@ -1038,17 +1038,21 @@ EOF;
$form->freeze('extra_'.$field_details['field_variable']);
}
break;
case ExtraField::FIELD_TYPE_TELEPHONE:
case ExtraField::FIELD_TYPE_MOBILE_PHONE_NUMBER:
$form->addElement(
'text',
'extra_'.$field_details['field_variable'],
$field_details['field_display_text'],
array('placeholder' => '(xx)xxxxxxxxx')
'extra_'.$field_details[1],
$field_details[3]." (".get_lang('CountryDialCode').")",
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], 'mobile_phone_number_filter');
$form->addRule(
'extra_'.$field_details[1],
get_lang('MobilePhoneNumberWrong'),
'mobile_phone_number'
);
$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('TelephoneNumberIsWrong'), 'telephone');
if ($field_details['field_visible'] == 0) {
$form->freeze('extra_'.$field_details['field_variable']);
}

@ -150,7 +150,7 @@ class FormValidator extends HTML_QuickForm
$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('mobile_phone_number', null, 'HTML_QuickForm_Rule_Mobile_Phone_Number', $dir . 'Rule/MobilePhoneNumber.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');
@ -641,15 +641,12 @@ function html_filter_student_fullpage($html)
}
/**
* Cleans telephone text
* @param string $telephone Telephone number to clean
* @return string The cleaned telephone number
* Cleans mobile phone number text
* @param string $mobilePhoneNumber Mobile phone number to clean
* @return string The cleaned mobile phone number
*/
function telephone_filter($telephone)
{
$telephone= trim ($telephone,'(');
$telephone= trim ($telephone,')');
$telephone= ltrim ($telephone,'+');
$telephone= ltrim ($telephone,'0');
return $telephone;
function mobile_phone_number_filter($mobilePhoneNumber)
{
$mobilePhoneNumber = str_replace(array('+', '(', ')'), '', $mobilePhoneNumber);
return ltrim($mobilePhoneNumber,'0');
}

@ -0,0 +1,26 @@
<?php
/**
* Abstract base class for QuickForm validation rules
*/
require_once 'HTML/QuickForm/Rule.php';
/**
* Validate telephones
*
*/
class HTML_QuickForm_Rule_Mobile_Phone_Number extends HTML_QuickForm_Rule
{
/**
* Validates mobile phone number
*
* @param string $mobilePhoneNumber
* @return boolean Returns true if valid, false otherwise.
*/
function validate($mobilePhoneNumber)
{
$rule = "/^\d{11}$/";
return preg_match($rule, $mobilePhoneNumber);
}
}

@ -30,7 +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;
const USER_FIELD_TYPE_MOBILE_PHONE_NUMBER = 14;
/**
* The default constructor only instanciates an empty user object
@ -4596,13 +4596,21 @@ EOF;
}
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'));
case self::USER_FIELD_TYPE_MOBILE_PHONE_NUMBER:
$form->addElement(
'text',
'extra_'.$field_details[1],
$field_details[3]." (".get_lang('CountryDialCode').")",
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('TelephoneNumberIsWrong'), 'telephone');
$form->applyFilter('extra_'.$field_details[1], 'mobile_phone_number_filter');
$form->addRule(
'extra_'.$field_details[1],
get_lang('MobilePhoneNumberWrong'),
'mobile_phone_number'
);
if (!$admin_permissions) {
if ($field_details[7] == 0) {
$form->freeze('extra_'.$field_details[1]);
@ -4635,7 +4643,7 @@ EOF;
$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');
$types[self::USER_FIELD_TYPE_MOBILE_PHONE_NUMBER] = get_lang('FieldTypeMobilePhoneNumber');
return $types;
}

@ -1621,4 +1621,7 @@ $DataTableSearch = "Search";
$HideColumn = "Hide column";
$DisplayColumn = "Show column";
$LegalAgreementAccepted = "Legal agreement accepted";
$FieldTypeMobilePhoneNumber = "Mobile phone";
$CountryDialCode = "Include the country dial code";
$MobilePhoneNumberWrong = "Mobile phone number is incomplete or contains not valid characters";
?>

@ -1613,4 +1613,7 @@ $DataTableSearch = "Buscar";
$HideColumn = "Ocultar columna";
$DisplayColumn = "Mostrar columna";
$LegalAgreementAccepted = "Condiciones legales aceptadas";
$FieldTypeMobilePhoneNumber = "Número de móvil";
$CountryDialCode = "Incluya el prefijo de llamada del país";
$MobilePhoneNumberWrong = "El número de móvil que ha escrito está incompleto o contiene caracteres no válidos.";
?>
Loading…
Cancel
Save