Compare commits

...

14 Commits

  1. 36
      lib.php
  2. 11
      locallib.php
  3. 7
      type/ILB_Sem_tutoria_2014/certificate.php
  4. BIN
      type/ILB_flex/Certificado-Brasão-Gradiênte-A4.xcf
  5. 245
      type/ILB_flex/certificate.php
  6. BIN
      type/ILB_flex/pix/Certificado-Brasão-Gradiênte-A4.xcf
  7. BIN
      type/ILB_flex/pix/Certificado-Brasão-Gradiênte-ESGA4.png
  8. BIN
      type/ILB_flex/pix/Certificado-Brasão-Gradiênte-ESGA4.xcf
  9. 228
      type/Oficinas/certificate.php

36
lib.php

@ -342,6 +342,42 @@ function certificate_get_post_actions() {
return array('received');
}
// TODO mover para outro local, usado também em certificado
function certificate_obtemCampoCustomizadoCurso($idCurso, $nomeCampo) {
global $DB;
$sql = "
SELECT d.value, f.configdata::json->>'options' as options
FROM mdl_course c
JOIN mdl_context ctx
ON c.id = ?
AND ctx.contextlevel = 50
AND ctx.instanceid = c.id
JOIN mdl_customfield_field f
ON f.shortname = ?
JOIN mdl_customfield_data d
ON d.fieldid = f.id
AND d.contextid = ctx.id
";
$valueArray = $DB->get_record_sql($sql, [$idCurso, $nomeCampo]);
if($valueArray) {
$value = $valueArray->value;
$options = $valueArray->options;
if($options == null) {
return $value;
} else {
$optionsArray = preg_split("/\s*\n\s*/", trim($options));
return $optionsArray[$value-1];
}
} else {
return '';
}
}
/**
* Function to be run periodically according to the moodle cron
* TODO:This needs to be done

11
locallib.php

@ -1161,14 +1161,19 @@ function certificate_draw_frame_letter($pdf, $certificate) {
* @param int $w the width
* @param int $h the height
*/
function certificate_print_image($pdf, $certificate, $type, $x, $y, $w, $h, $cert_date = null) {
function certificate_print_image($pdf, $certificate, $type, $x, $y, $w, $h, $cert_date = null, $verso = false) {
global $CFG, $DB;
switch($type) {
case CERT_IMAGE_BORDER :
$attr = 'borderstyle';
$path = "$CFG->dirroot/mod/certificate/pix/$type/$certificate->borderstyle";
$uploadpath = "$CFG->dataroot/mod/certificate/pix/$type/$certificate->borderstyle";
if(!$verso) {
$path = "$CFG->dirroot/mod/certificate/pix/$type/$certificate->borderstyle";
$uploadpath = "$CFG->dataroot/mod/certificate/pix/$type/$certificate->borderstyle";
} else {
$path = "$CFG->dirroot/mod/certificate/pix/$type/$verso-" . "$certificate->borderstyle";
$uploadpath = "$CFG->dataroot/mod/certificate/pix/$type/$verso-" . "$certificate->borderstyle";
}
break;
case CERT_IMAGE_SEAL :
$attr = 'printseal';

7
type/ILB_Sem_tutoria_2014/certificate.php

@ -39,11 +39,10 @@ $cc = new completion_completion(array('userid'=>$USER->id, 'course'=>$course->id
$enrol_manager = new course_enrolment_manager($PAGE, $course);
$enrolments = $enrol_manager->get_user_enrolments($USER->id);
//$enrolments = $enrol_manager->get_user_enrolments($USER->id);
$user_enrol = reset($enrol_manager->get_user_enrolments($USER->id));
//$user_enrol = isempty($enrolments)? end();
$start_date = (empty($enrolments))? $enrolments[0]->timestart : 0;
$start_date = $user_enrol->timestart;
$end_date = $cc->timecompleted;
$cert_date = $end_date;

BIN
type/ILB_flex/Certificado-Brasão-Gradiênte-A4.xcf

Binary file not shown.

245
type/ILB_flex/certificate.php

@ -0,0 +1,245 @@
<?php
// This file is part of the Certificate module for 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/>.
/**
* A4_embedded certificate type
*
* @package mod
* @subpackage certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from view.php
}
/**
* Gets the course start date (for ILB start date is the date of enrollment)
* and completion date from course completion framework.
* Finally format them to print
*/
require_once("$CFG->dirroot/completion/completion_completion.php");
// Obtem as preferências para exibição do período do certificado
$periodo_certificado = certificate_obtemCampoCustomizadoCurso($course->id, 'periodo_certificado');
if(empty(trim($periodo_certificado))) {
$periodo_certificado = 'Duração do curso';
}
if($periodo_certificado == 'Duração do curso') {
// Datas inicial e final são configuradas no curso
$start_date = $course->startdate;
$end_date = $course->enddate;
} else {
// $periodo_certificado == 'Sem período' ou 'Matrícula até conclusão'
require_once("$CFG->dirroot/enrol/locallib.php");
// Data inicial é a matrícula
$enrol_manager = new course_enrolment_manager($PAGE, $course);
$user_enrol = reset($enrol_manager->get_user_enrolments($USER->id));
$start_date = $user_enrol->timestart;
// Data final é quando completou o curso
$cc = new completion_completion(array('userid'=>$USER->id, 'course'=>$course->id));
$end_date = $cc->timecompleted;
}
$fmt = '%d/%m/%Y'; // Default format
if ($certificate->datefmt == 1) {
$fmt = '%B %d, %Y';
} else if ($certificate->datefmt == 2) {
$suffix = certificate_get_ordinal_number_suffix(userdate($ts, '%d'));
$fmt = '%B %d' . $suffix . ', %Y';
} else if ($certificate->datefmt == 3) {
$fmt = '%d de %B de %Y';
} else if ($certificate->datefmt == 4) {
$fmt = '%B de %Y';
} else if ($certificate->datefmt == 5) {
$fmt = get_string('strftimedate', 'langconfig');
}
$dataInicio = userdate($start_date, $fmt);
$dataFim = userdate($end_date, $fmt);
$cert_date = $end_date; // para fins de obtenção automática de assinatura (COTREN apenas)
$anoInicio = userdate($start_date, '%Y');
$anoFim = userdate($end_date, '%Y');
$mesInicio = userdate($start_date, '%B');
$mesFim = userdate($end_date, '%B');
$diaInicio = userdate($start_date, '%d');
$diaFim = userdate($end_date, '%d');
if($diaInicio == '1') {$diaInicio .= "º";}
if($diaFim == '1') {$diaFim .= "º";}
$nome_acao = certificate_obtemCampoCustomizadoCurso($course->id, 'nome_acao_certificado');
if(empty(trim($nome_acao))) {
$nome_acao = mb_strtoupper($course->fullname, 'UTF-8');
}
$verbo_acao = certificate_obtemCampoCustomizadoCurso($course->id, 'papel_acao_capacitacao');
if(empty($verbo_acao)) {
$verbo_acao = 'participou';
};
$tipo_acao = certificate_obtemCampoCustomizadoCurso($course->id, 'tipo_acao_capacitacao');
if($tipo_acao == "") {
$tipo_acao = 'do curso';
}
$modalidade_acao = certificate_obtemCampoCustomizadoCurso($course->id, 'modalidade_capacitacao');
$entidade_certificadora = certificate_obtemCampoCustomizadoCurso($course->id, 'entidade_certificadora');
if($entidade_certificadora == '') {
$entidade_certificadora = 'O Instituto Legislativo Brasileiro certifica que';
}
function montaPeriodo() {
global $anoInicio, $anoFim, $mesInicio, $mesFim, $diaInicio, $diaFim, $dataInicio, $dataFim;
if($anoInicio != $anoFim) {
// ano diferente
return "realizado no período de {$dataInicio} a {$dataFim}";
} else {
if($mesInicio != $mesFim) {
// mesmo ano, mês diferente
return "realizado no período de $diaInicio de $mesInicio a $diaFim de $mesFim de $anoInicio";
} else {
if($diaInicio != $diaFim) {
// mesmo mês, dia diferente
return "realizado no período de $diaInicio a $diaFim de $mesInicio de $anoInicio";
} else {
// evento de um dia
return "realizado em {$dataInicio}";
}
}
}
}
//MASK para CPF
function mask($val, $mask)
{
$maskared = '';
$k = 0;
for($i = 0; $i<=strlen($mask)-1; $i++){
if($mask[$i] == '#'){
if(isset($val[$k]))
$maskared .= $val[$k++];
}
else
{
if(isset($mask[$i]))
$maskared .= $mask[$i];
}
}
return $maskared;
}
$cpf = mask($USER->username, '###.###.###-##');
require_once($CFG->dirroot.'/user/profile/field/cpf/field.class.php');
$pdf = new PDF($certificate->orientation, 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle($certificate->name);
$pdf->SetProtection(array('modify'));
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetAutoPageBreak(false, 0);
$pdf->AddPage();
// Define variables
// Only Landscape
$x = 10;
$y = 60;
$sealx = 230;
$sealy = 150;
$sigx = 0;
$sigy = 135;
$sigw = 297;
$sigh = 44;
$custx = 15;
$custy = $y+25;
$wmarkx = 40;
$wmarky = 31;
$wmarkw = 212;
$wmarkh = 148;
$brdrx = 0;
$brdry = 0;
$brdrw = 297;
$brdrh = 210;
$codex = $x;
$codey = 165;
// Front page ------------------------------------------------------------------------------------------------------------
// Add images and lines
certificate_print_image($pdf, $certificate, CERT_IMAGE_BORDER, $brdrx, $brdry, $brdrw, $brdrh);
certificate_draw_frame($pdf, $certificate);
// Set alpha to semi-transparency
$pdf->SetAlpha(0.2);
certificate_print_image($pdf, $certificate, CERT_IMAGE_WATERMARK, $wmarkx, $wmarky, $wmarkw, $wmarkh);
$pdf->SetAlpha(1);
certificate_print_image($pdf, $certificate, CERT_IMAGE_SEAL, $sealx, $sealy, '', '');
// assinatura esperada: 1863x276
certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy, $sigw, $sigh, $cert_date);
// Add text
$pdf->SetTextColor(0, 0, 0);
// $entidade_certificadora = 'O Instituto Legislativo Brasileiro (ILB), do Senado Federal, em parceria com
// as escolas de governo da Câmara dos Deputados (CEFOR) e do Tribunal de Contas da União (ISC), certifica que';
$nome_aluno = mb_strtoupper(fullname($USER), 'UTF-8');
$dados_aluno = "CPF nº $cpf";
$periodo = montaPeriodo();
$carga_horaria = "com carga horária de {$certificate->printhours}";
$nota = (certificate_get_grade($certificate, $course)?certificate_get_grade($certificate, $course):'');
$texto_base_certificado = $entidade_certificadora . "<br><br>" .
"<b>" . $nome_aluno . "</b><br><br>" .
$dados_aluno . ", " . $verbo_acao . ($modalidade_acao? ", na modalidade " . $modalidade_acao . ',':"") . ' ' . $tipo_acao . ' ' .
"<i>" . $nome_acao . "</i>" .
($certificate->printhours?", com carga horária de $certificate->printhours":'') .
($periodo_certificado != 'Sem período'?', ' . $periodo:'') .
($nota?', ' . $nota:'') . '.';
certificate_print_text($pdf, $x, $y, 'C', 'freesans', '', 20, get_string('title', 'certificate'));
certificate_print_text($pdf, $x, $y + 15, 'C', 'freesans', '', 17, $texto_base_certificado);
// Deve ser fixo
certificate_print_text($pdf, $x, $y + 75, 'R', 'freesans', 'B', 14, "Brasília, {$dataFim}.");
// Verse page -----------------------------------------------------------------------------------------------------------
$pdf->AddPage();
// Add images and lines
certificate_print_image($pdf, $certificate, CERT_IMAGE_BORDER, $brdrx, $brdry, $brdrw, $brdrh);
certificate_draw_frame($pdf, $certificate);
// Set alpha to semi-transparency
$pdf->SetAlpha(0.2);
certificate_print_image($pdf, $certificate, CERT_IMAGE_WATERMARK, $wmarkx, $wmarky, $wmarkw, $wmarkh);
$pdf->SetAlpha(1);
certificate_print_image($pdf, $certificate, CERT_IMAGE_SEAL, $sealx, $sealy, '', '');
// Add text
$pdf->SetTextColor(0, 0, 0);
certificate_print_text($pdf, $x, $y, 'C', 'freesans', '', 20, 'PROGRAMA DO CURSO');
certificate_print_text($pdf, $x, $y + 10, 'C', 'freesans', '', 20, $nome_curso);
certificate_print_text($pdf, $custx, $custy, 'L', 'freesans', '', 10, $certificate->customtext);
certificate_print_text($pdf, $codex, $codey, 'C', 'freesans', '', 10, 'CÓDIGO DE VALIDAÇÃO');
certificate_print_text($pdf, $codex, $codey + 5, 'C', 'freesans', 'B', 12, certificate_get_code($certificate, $certrecord));
certificate_print_text($pdf, $codex, $codey + 10, 'C', 'freesans', '', 10, 'Para verificar a autenticidade deste certificado, acesse http://saberes.senado.leg.br/ e informe o código acima');
?>

BIN
type/ILB_flex/pix/Certificado-Brasão-Gradiênte-A4.xcf

Binary file not shown.

BIN
type/ILB_flex/pix/Certificado-Brasão-Gradiênte-ESGA4.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 KiB

BIN
type/ILB_flex/pix/Certificado-Brasão-Gradiênte-ESGA4.xcf

Binary file not shown.

228
type/Oficinas/certificate.php

@ -0,0 +1,228 @@
<?php
// This file is part of the Certificate module for 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/>.
/**
* A4_embedded certificate type
*
* @package mod
* @subpackage certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from view.php
}
/**
* Gets the course start date (for ILB start date is the date of enrollment)
* and completion date from course completion framework.
* Finally format them to print
*/
require_once("$CFG->dirroot/completion/completion_completion.php");
$start_date = $course->startdate;
$end_date = $course->enddate;
$emissao_date = $course->enddate;
function obtemCampoCustomizadoCurso($idCurso, $nomeCampo) {
global $DB;
$sql = "
SELECT d.value, f.configdata::json->>'options' as options
FROM mdl_course c
JOIN mdl_context ctx
ON c.id = ?
AND ctx.contextlevel = 50
AND ctx.instanceid = c.id
JOIN mdl_customfield_field f
ON f.shortname = ?
JOIN mdl_customfield_data d
ON d.fieldid = f.id
AND d.contextid = ctx.id
";
$valueArray = $DB->get_record_sql($sql, [$idCurso, $nomeCampo]);
$value = $valueArray->value;
$options = $valueArray->options;
if($options == null) {
return $value;
} else {
$optionsArray = preg_split("/\s*\n\s*/", trim($options));
return $optionsArray[$value-1];
}
}
// Campos customizados do curso
$cargahoraria = obtemCampoCustomizadoCurso($course->id, 'cargahoraria');
$instrutor = obtemCampoCustomizadoCurso($course->id, 'instrutor');
$monitor = obtemCampoCustomizadoCurso($course->id, 'monitor');
$municipio = obtemCampoCustomizadoCurso($course->id, 'municipio');
$senador = obtemCampoCustomizadoCurso($course->id, 'senador');
$tipooficina = obtemCampoCustomizadoCurso($course->id, 'tipooficina');
$cargahoraria = obtemCampoCustomizadoCurso($course->id, 'cargahoraria');
$fmt = '%d/%m/%Y'; // Default format
if ($certificate->datefmt == 1) {
$fmt = '%B %d, %Y';
} else if ($certificate->datefmt == 2) {
$suffix = certificate_get_ordinal_number_suffix(userdate($ts, '%d'));
$fmt = '%B %d' . $suffix . ', %Y';
} else if ($certificate->datefmt == 3) {
$fmt = '%d de %B de %Y';
} else if ($certificate->datefmt == 4) {
$fmt = '%B de %Y';
} else if ($certificate->datefmt == 5) {
$fmt = get_string('strftimedate', 'langconfig');
}
$start_date = userdate($start_date, $fmt);
$end_date = userdate($end_date, $fmt);
$emissao_date = userdate($emissao_date, $fmt);
//MASK para CPF
function mask($val, $mask)
{
$maskared = '';
$k = 0;
for($i = 0; $i<=strlen($mask)-1; $i++){
if($mask[$i] == '#'){
if(isset($val[$k]))
$maskared .= $val[$k++];
}
else
{
if(isset($mask[$i]))
$maskared .= $mask[$i];
}
}
return $maskared;
}
$cpf = mask($USER->username, '###.###.###-##');
require_once($CFG->dirroot.'/user/profile/field/cpf/field.class.php');
$pdf = new PDF($certificate->orientation, 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle($certificate->name);
$pdf->SetProtection(array('modify'));
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetAutoPageBreak(false, 0);
$pdf->AddPage();
// Define variables
// Landscape
if ($certificate->orientation == 'L') {
$x = 20;
$y = 60;
$sealx = 230;
$sealy = 150;
$sigx = 00;
$sigy = 165;
$custx = 15;
$custy = $y+25;
$wmarkx = 40;
$wmarky = 31;
$wmarkw = 212;
$wmarkh = 148;
$brdrx = 0;
$brdry = 0;
$brdrw = 297;
$brdrh = 210;
$codex = $x;
$codey = 175;
} else { // Portrait
$x = 10;
$y = 90;
$sealx = 150;
$sealy = 220;
$sigx = 10;
$sigy = 235;
$custx = 15;
$custy = $y+25;
$wmarkx = 26;
$wmarky = 58;
$wmarkw = 158;
$wmarkh = 170;
$brdrx = 0;
$brdry = 0;
$brdrw = 210;
$brdrh = 297;
$codex = $x;
$codey = 245;
}
// Front page ------------------------------------------------------------------------------------------------------------
// Add images and lines
certificate_print_image($pdf, $certificate, CERT_IMAGE_BORDER, $brdrx, $brdry, $brdrw, $brdrh);
certificate_draw_frame($pdf, $certificate);
// Set alpha to semi-transparency
$pdf->SetAlpha(0.2);
certificate_print_image($pdf, $certificate, CERT_IMAGE_WATERMARK, $wmarkx, $wmarky, $wmarkw, $wmarkh);
$pdf->SetAlpha(1);
certificate_print_image($pdf, $certificate, CERT_IMAGE_SEAL, $sealx, $sealy, '', '');
certificate_print_image($pdf, $certificate, CERT_IMAGE_SIGNATURE, $sigx, $sigy, '', '');
$certificador = 'O Instituto Legislativo Brasileiro, órgão gestor do Programa Interlegis, certifica que';
// Add text
$pdf->SetTextColor(0, 0, 0);
certificate_print_text($pdf, $x, $y, 'C', 'freesans', '', 20, get_string('title', 'certificate'));
//certificate_print_text($pdf, $x, $y + 15, 'C', 'freesans', '', 18, get_string('certify', 'certificate'));
certificate_print_text($pdf, $x, $y + 15, 'C', 'freesans', '', 18, $certificador);
certificate_print_text($pdf, $x, $y + 25, 'C', 'freesans', 'B', 18, mb_strtoupper(fullname($USER), 'UTF-8').", CPF nº $cpf");
certificate_print_text($pdf, $x, $y + 35, 'C', 'freesans', '', 18, "particicou da oficina de \"" . $tipooficina . "\"") ;
certificate_print_text($pdf, $x, $y + 45, 'C', 'freesans', '', 18, "na Câmara Municipal de $municipio");
certificate_print_text($pdf, $x, $y + 55, 'C', 'freesans', '', 18, "no período de {$start_date} a {$end_date}");
certificate_print_text($pdf, $x, $y + 65, 'C', 'freesans', '', 18, "com carga horária de $cargahoraria horas");
certificate_print_text($pdf, $x, $y + 75, 'C', 'freesans', '', 18, certificate_get_grade($certificate, $course));
certificate_print_text($pdf, $x, $y + 85, 'R', 'freesans', 'B', 14, "$municipio, {$emissao_date}.");
// Verse page -----------------------------------------------------------------------------------------------------------
$pdf->AddPage();
// Add images and lines
certificate_print_image($pdf, $certificate, CERT_IMAGE_BORDER, $brdrx, $brdry, $brdrw, $brdrh);
certificate_draw_frame($pdf, $certificate);
// Set alpha to semi-transparency
$pdf->SetAlpha(0.2);
certificate_print_image($pdf, $certificate, CERT_IMAGE_WATERMARK, $wmarkx, $wmarky, $wmarkw, $wmarkh);
$pdf->SetAlpha(1);
certificate_print_image($pdf, $certificate, CERT_IMAGE_SEAL, $sealx, $sealy, '', '');
// Add text
$pdf->SetTextColor(0, 0, 0);
certificate_print_text($pdf, $x, $y, 'C', 'freesans', '', 20, 'PROGRAMA DO CURSO');
certificate_print_text($pdf, $x, $y + 10, 'C', 'freesans', '', 20, mb_strtoupper($course->fullname, 'UTF-8'));
certificate_print_text($pdf, $custx, $custy, 'L', 'freesans', '', 10, $certificate->customtext);
certificate_print_text($pdf, $codex, $codey, 'C', 'freesans', '', 10, 'CÓDIGO DE VALIDAÇÃO');
certificate_print_text($pdf, $codex, $codey + 5, 'C', 'freesans', 'B', 12, certificate_get_code($certificate, $certrecord));
certificate_print_text($pdf, $codex, $codey + 10, 'C', 'freesans', '', 10, 'Para verificar a autenticidade deste certificado, acesse http://saberes.senado.leg.br/ e informe o código acima');
Loading…
Cancel
Save