Sesostris Vieira
11 years ago
5 changed files with 165 additions and 0 deletions
@ -0,0 +1,14 @@ |
|||
<?php |
|||
|
|||
class profile_define_cpf extends profile_define_base { |
|||
|
|||
function define_form_specific($form) { |
|||
/// Default data |
|||
$form->addElement('text', 'defaultdata', get_string('profiledefaultdata', 'admin'), 'size="50"'); |
|||
$form->setType('defaultdata', PARAM_TEXT); |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
|
@ -0,0 +1,66 @@ |
|||
<?php |
|||
|
|||
class profile_field_cpf extends profile_field_base { |
|||
|
|||
/** |
|||
* Overwrite the base class to display the data for this field |
|||
*/ |
|||
function display_data() { |
|||
/// Default formatting |
|||
$data = parent::display_data(); |
|||
if ($data !== '') { |
|||
$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; |
|||
} |
|||
|
|||
function edit_field_add($mform) { |
|||
/// Create the form field |
|||
$mform->addElement('text', $this->inputname, format_string($this->field->name), 'maxlength="11" size="11"'); |
|||
$mform->setType($this->inputname, PARAM_INT); |
|||
} |
|||
|
|||
function edit_validate_field($usernew) { |
|||
// Based on script by Moacir, in http://codigofonte.uol.com.br/codigos/validacao-de-cpf-com-php |
|||
$errors = array(); |
|||
if (isset($usernew->{$this->inputname})) { |
|||
$cpf = $usernew->{$this->inputname}; |
|||
if (strlen($cpf) != 11) { |
|||
return array($this->inputname => get_string('cpf_size', 'profilefield_cpf')); |
|||
} |
|||
if (in_array($cpf, array('00000000000', '11111111111', '22222222222', '33333333333', '44444444444', '55555555555', '66666666666', '77777777777', '88888888888', '99999999999'))) { |
|||
return array($this->inputname => get_string('cpf_invalid', 'profilefield_cpf')); |
|||
} |
|||
for ($t = 9; $t < 11; $t++) { |
|||
for ($d = 0, $c = 0; $c < $t; $c++) { |
|||
$v = substr($cpf,$c,1); |
|||
$d += $v * (($t + 1) - $c); |
|||
} |
|||
$v = substr($cpf,$c,1); |
|||
$d = ((10 * $d) % 11) % 10; |
|||
if ($v != $d) { |
|||
return array($this->inputname => get_string('cpf_invalid', 'profilefield_cpf')); |
|||
} |
|||
} |
|||
} |
|||
return $errors; |
|||
} |
|||
|
|||
} |
|||
|
|||
|
@ -0,0 +1,28 @@ |
|||
<?php |
|||
|
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* Strings for component 'profilefield_text', language 'en', branch 'MOODLE_20_STABLE' |
|||
* |
|||
* @package profilefield_text |
|||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
$string['pluginname'] = 'Brazilian CPF'; |
|||
$string['cpf_size'] = 'CPF must have 11 digits'; |
|||
$string['cpf_invalid'] = 'Invalid CPF'; |
@ -0,0 +1,28 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* @package profilefield |
|||
* @subpackage text |
|||
* @copyright 2007 onwards Shane Elliot {@link http://pukunui.com} |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$plugin->version = 2013050100; // The current plugin version (Date: YYYYMMDDXX) |
|||
$plugin->requires = 2013050100; // Requires this Moodle version |
|||
$plugin->component = 'profilefield_cpf'; // Full name of the plugin (used for diagnostics) |
Loading…
Reference in new issue