|
@ -1,38 +1,23 @@ |
|
|
<?php |
|
|
<?php |
|
|
|
|
|
|
|
|
class profile_field_cpf extends profile_field_base { |
|
|
class profile_field_cpf extends profile_field_base { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Overwrite the base class to display the data for this field |
|
|
* Overwrite the base class to display the data for this field |
|
|
*/ |
|
|
*/ |
|
|
function display_data() { |
|
|
function display_data() { |
|
|
/// Default formatting |
|
|
/// Default formatting |
|
|
$data = parent::display_data(); |
|
|
$data = parent::display_data(); |
|
|
|
|
|
$data = str_pad($data, 11, '0', STR_PAD_LEFT); // Prevent low digits formatting errors |
|
|
if ($data !== '') { |
|
|
if ($data !== '') { |
|
|
$data = substr($data,0,3).'.'.substr($data,3,3).'.'.substr($data,6,3).'-'.substr($data,9,2); |
|
|
$data = substr($data,0,3).'.'.substr($data,3,3).'.'.substr($data,6,3).'-'.substr($data,9,2); |
|
|
} |
|
|
} |
|
|
/* |
|
|
|
|
|
/// Are we creating a link? |
|
|
|
|
|
if (!empty($this->field->param4) and !empty($data)) { |
|
|
|
|
|
|
|
|
|
|
|
/// Define the target |
|
|
|
|
|
if (! empty($this->field->param5)) { |
|
|
|
|
|
$target = 'target="'.$this->field->param5.'"'; |
|
|
|
|
|
} else { |
|
|
|
|
|
$target = ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Create the link |
|
|
|
|
|
$data = '<a href="'.str_replace('$$', urlencode($data), $this->field->param4).'" '.$target.'>'.htmlspecialchars($data).'</a>'; |
|
|
|
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
return $data; |
|
|
return $data; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function edit_field_add($mform) { |
|
|
function edit_field_add($mform) { |
|
|
/// Create the form field |
|
|
/// Create the form field |
|
|
$mform->addElement('text', $this->inputname, format_string($this->field->name), 'maxlength="11" size="11"'); |
|
|
$mform->addElement('text', $this->inputname, format_string($this->field->name), 'maxlength="11" size="11"'); |
|
|
$mform->setType($this->inputname, PARAM_INT); |
|
|
$mform->setType($this->inputname, PARAM_TEXT); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function edit_validate_field($usernew) { |
|
|
function edit_validate_field($usernew) { |
|
@ -40,6 +25,9 @@ class profile_field_cpf extends profile_field_base { |
|
|
$errors = array(); |
|
|
$errors = array(); |
|
|
if (isset($usernew->{$this->inputname})) { |
|
|
if (isset($usernew->{$this->inputname})) { |
|
|
$cpf = $usernew->{$this->inputname}; |
|
|
$cpf = $usernew->{$this->inputname}; |
|
|
|
|
|
if (ctype_digit($cpf)) { |
|
|
|
|
|
return array($this->inputname => get_string('cpf_digits', 'profilefield_cpf')); |
|
|
|
|
|
} |
|
|
if (strlen($cpf) != 11) { |
|
|
if (strlen($cpf) != 11) { |
|
|
return array($this->inputname => get_string('cpf_size', 'profilefield_cpf')); |
|
|
return array($this->inputname => get_string('cpf_size', 'profilefield_cpf')); |
|
|
} |
|
|
} |
|
@ -62,5 +50,3 @@ class profile_field_cpf extends profile_field_base { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|