diff --git a/README.md b/README.md index 4765880..ff82e0f 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,32 @@ moodle_profilefield_cpf ======================= Moodle user profile field for brazilian CPF +------------------------------------------- + +A Moodle plugin that validates a Brazilian CPF + +Instalation instructions: +''''''''''''''''''''''''' + +1. Clone the repository to a folder named cpf; +2. Copy the folder cpf to user/profile/field directory on your moodle installation; +3. Open custom field editor (Site administration->Users->Accounts->User profile fields); +4. Choose Brazilian CPF in "Create new profile field" dropdown; +5. Configure and save the field. + +In portuguese: +============= + +Campo de perfil do Moodle para CPF brasileiro +--------------------------------------------- + +Um plugin Moodle que valida um CPF brasileiro + +Instruções de instalação: +''''''''''''''''''''''''' + +1. Clone o repositório para uma pasta denominada cpf; +2. Copie a pasta cpf para o diretório user/profile/field na sua instalação Moodle; +3. Abra o editor de campos de perfil (Administração do site -> Usuários -> Contas -> Campos de perfil do usuário); +4. Escolha Brazilian CPF na caixa de seleção "Criar um novo campo de perfil"; +5. Configure e salve o campo. diff --git a/define.class.php b/define.class.php new file mode 100644 index 0000000..b7a89c1 --- /dev/null +++ b/define.class.php @@ -0,0 +1,14 @@ +addElement('text', 'defaultdata', get_string('profiledefaultdata', 'admin'), 'size="50"'); + $form->setType('defaultdata', PARAM_TEXT); + + } + +} + + diff --git a/field.class.php b/field.class.php new file mode 100644 index 0000000..f761b96 --- /dev/null +++ b/field.class.php @@ -0,0 +1,66 @@ +field->param4) and !empty($data)) { + + /// Define the target + if (! empty($this->field->param5)) { + $target = 'target="'.$this->field->param5.'"'; + } else { + $target = ''; + } + + /// Create the link + $data = ''.htmlspecialchars($data).''; + } +*/ + 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; + } + +} + + diff --git a/lang/en/profilefield_cpf.php b/lang/en/profilefield_cpf.php new file mode 100644 index 0000000..155f114 --- /dev/null +++ b/lang/en/profilefield_cpf.php @@ -0,0 +1,28 @@ +. + +/** + * 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'; diff --git a/version.php b/version.php new file mode 100644 index 0000000..d1288b2 --- /dev/null +++ b/version.php @@ -0,0 +1,28 @@ +. + +/** + * @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)