';
- echo '';
- echo '
';
- /// Print Section
- foreach ($issues as $issue) {
- if (!$certificate = $DB->get_record('certificate', array('id'=> $issue->certificateid))) {
- print_error('course module is incorrect');
- }
- if (!$course = $DB->get_record('course', array('id'=> $certificate->course))) {
- print_error('course is misconfigured');
- }
- if (!$user = $DB->get_record('user', array('id'=> $issue->userid))) {
- print_error('user is unreachable');
- }
-
- profile_load_data($user);
-
- $enrol_manager = new course_enrolment_manager($PAGE, $course);
- $user_enrols = $enrol_manager->get_user_enrolments($user->id);
- $start_date = 0;
- $end_date = 0;
- foreach ($user_enrols as $enrol) {
- if ($enrol->timestart > 0) {
- $start_date = $enrol->timestart;
- }
- if ($enrol->timeend > 0) {
- $end_date = $enrol->timeend;
- }
- }
- if (($start_date > 0 and $end_date > 0)) {
- $fmt = '%d/%m/%Y'; // Default format
- if ($certificate->datefmt == 1) {
- $fmt = '%B %d, %Y';
- $certificatedate = userdate($ts, '%B %d, %Y') . " a " . userdate($te, '%B %d, %Y');
- } else if ($certificate->datefmt == 2) {
- $suffix = certificate_get_ordinal_number_suffix(userdate($ts, '%d'));
- $fmt = '%B %d' . $suffix . ', %Y';
- $certificatedate = userdate($ts, '%B %d' . $suffix . ', %Y') . " a " . userdate($te, '%B %d' . $suffix . ', %Y');
- } else if ($certificate->datefmt == 3) {
- $fmt = '%d %B %Y';
- $certificatedate = userdate($ts, '%d %B %Y') . " a " . userdate($te, '%d %B %Y');
- } else if ($certificate->datefmt == 4) {
- $fmt = '%B %Y';
- $certificatedate = userdate($ts, '%B %Y') . " a " . userdate($te, '%B %Y');
- } else if ($certificate->datefmt == 5) {
- $fmt = get_string('strftimedate', 'langconfig');
- $certificatedate = userdate($ts, get_string('strftimedate', 'langconfig')) . " a " . userdate($te, get_string('strftimedate', 'langconfig'));
- }
- $start_date = userdate($start_date, $fmt);
- $end_date = userdate($end_date, $fmt);
- } else {
- $start_date = '';
- $end_date = '';
- }
-
- $certificatedate = userdate($issue->timecreated);
- echo '' . get_string('certificate', 'block_verify_certificate') . " {$issue->code}
";
- echo '' . get_string('to', 'block_verify_certificate') . ': ' . fullname($user) . '
';
- foreach ($profile_fields as $field) {
- $fieldname = "profile_field_{$field->shortname}";
- $fieldvalue = $user->$fieldname;
- echo "{$field->name}: {$fieldvalue}";
- }
- echo '' . get_string('course', 'block_verify_certificate') . ": {$course->fullname}
";
- echo '' . get_string('date', 'block_verify_certificate') . ": $certificatedate
";
- echo '' . get_string('enrol_period', 'block_verify_certificate') . ": $start_date - $end_date
";
- if ($certificate->printhours) {
- echo '' . get_string('printhours', 'block_verify_certificate') . ": {$certificate->printhours}
";
- }
- if ($certificate->customtext !== '') {
- echo '' . get_string('customtext', 'block_verify_certificate') . ':
';
- echo $certificate->customtext;
- }
- }
- }
-
- echo $OUTPUT->box_end();
- echo $OUTPUT->footer();
+.
+
+/**
+ * Version details
+ *
+ * Verify certificate block
+ * --------------------------
+ * Verify certificate based on the unique codes displayed on issued certificates.
+ * Full details of the issued certificate is displayed including profile picture.
+ * Mostly cosmetic changes to the original codes from Jean-Michel Védrine.
+ * Original Autor & Copyright - Jean-Michel Védrine | 2014
+ *
+ * @copyright 2015 onwards Manieer Chhettri | Marie Curie, UK |
+ * @author Manieer Chhettri | Marie Curie, UK | | 2015
+ * @package block_verify_certificate
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once("../../config.php");
+require_once($CFG->dirroot . '/mod/certificate/lib.php');
+require_once($CFG->dirroot.'/mod/certificate/locallib.php');
+require_once("$CFG->dirroot/completion/completion_completion.php");
+require_once("$CFG->dirroot/enrol/locallib.php");
+
+$id = required_param('certnumber', PARAM_ALPHANUM); // Certificate code to verify.
+
+$PAGE->set_pagelayout('standard');
+$strverify = get_string('verifycertificate', 'block_verify_certificate');
+$PAGE->set_url('/blocks/verify_certificate/index.php', array('certnumber' => $id));
+$context = context_system::instance();
+$PAGE->set_context($context);
+
+// Print the header.
+$PAGE->navbar->add($strverify);
+$PAGE->set_title($strverify);
+$PAGE->set_heading($strverify);
+$PAGE->requires->css('/blocks/verify_certificate/printstyle.css');
+$PAGE->requires->css('/blocks/verify_certificate/styles.css');
+echo $OUTPUT->header();
+
+$ufields = user_picture::fields('u');
+
+$sql = "SELECT ci.timecreated AS citimecreated,
+ ci.code, ci.certificateid, ci.userid, $ufields, c.*, u.id AS id, u.*
+ FROM {certificate_issues} ci
+ INNER JOIN {user} u
+ ON u.id = ci.userid
+ INNER JOIN {certificate} c
+ ON c.id = ci.certificateid
+ WHERE ci.code = ?";
+$certificates = $DB->get_records_sql($sql, array($id));
+
+function getFormattedCPFFromUsername($userid) {
+ global $DB;
+ $user = $DB->get_record("user", array("id" => $userid));
+ return mask($user->username, '###.###.###-##');
+}
+
+function mask($val, $mask)
+{
+ if(validatecpf($val)) {
+ $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;
+ } else {
+ return "";
+ }
+}
+
+
+function validatecpf($cpf) {
+ // Verifica se um numero foi informado.
+ if (is_null($cpf)) {
+ return false;
+ }
+ if (!is_numeric($cpf)) {
+ return false;
+ }
+ //$cpf = str_pad($cpf, 11, '0', STR_PAD_LEFT);
+
+ // Verifica se o numero de digitos informados eh igual a 11.
+ if (strlen($cpf) != 11) {
+ return false;
+ } else if ($cpf == '00000000000' || $cpf == '11111111111' || $cpf == '22222222222' ||
+ $cpf == '33333333333' || $cpf == '44444444444' || $cpf == '55555555555' ||
+ $cpf == '66666666666' || $cpf == '77777777777' || $cpf == '88888888888' ||
+ $cpf == '99999999999') {
+ return false;
+ } else {
+ // Calcula os digitos verificadores para verificar se o CPF eh valido.
+
+ $cpf = preg_replace('/[^0-9]/', '', (string) $cpf);
+ // Valida tamanho
+ if (strlen($cpf) != 11)
+ return false;
+ // Calcula e confere primeiro dígito verificador
+ for ($i = 0, $j = 10, $soma = 0; $i < 9; $i++, $j--)
+ $soma += $cpf{$i} * $j;
+ $resto = $soma % 11;
+ if ($cpf{9} != ($resto < 2 ? 0 : 11 - $resto))
+ return false;
+ // Calcula e confere segundo dígito verificador
+ for ($i = 0, $j = 11, $soma = 0; $i < 10; $i++, $j--)
+ $soma += $cpf{$i} * $j;
+ $resto = $soma % 11;
+
+ $resultado = $cpf{10} == ($resto < 2 ? 0 : 11 - $resto);
+ return $resultado;
+ }
+}
+
+
+if (! $certificates) {
+ echo $OUTPUT->box_start('generalbox boxaligncenter');
+ echo '';
+ echo '
' . get_string('certificate', 'block_verify_certificate')
+ . ' "' . $id . '" ' . '
';
+ echo '
';
+ echo '
' .get_string('notfound', 'block_verify_certificate').'
';
+ echo '
';
+ echo '
';
+ echo $OUTPUT->box_end();
+} else {
+ echo $OUTPUT->box_start('generalbox boxaligncenter');
+ echo "";
+ echo "
";
+
+ // Print Section.
+ foreach ($certificates as $certdata) {
+ echo '' . get_string('certificate', 'block_verify_certificate')
+ . ' "' . $certdata->code . '" ' . '
';
+ echo '';
+ echo '';
+ echo $OUTPUT->user_picture($certdata, array('size' => 150));
+ echo ' ';
+ echo ' | ';
+ echo ' ' . get_string('to', 'block_verify_certificate') . ': ' . fullname($certdata) . ' ';
+ // Date format.
+ $dateformat = get_string('strftimedate', 'langconfig');
+
+
+ $certdata->printdate = 1;
+ $certrecord = new stdClass();
+ $certrecord->timecreated = $certdata->citimecreated;
+ $certrecord->code = $certdata->code;
+ $certrecord->userid = $certdata->userid;
+ $certrecord->id = $certdata->id;
+ $userid = $certrecord->userid;
+
+ // Exibe CPF, se username for CPF
+ #require_once("$CFG->dirroot/user/profile/lib.php");
+ #require_once("$CFG->dirroot/user/profile/field/cpf/field.class.php");
+ #$formfield = new profile_field_cpf('8', $certdata->userid);
+ #$cpf = $formfield->display_data();
+ $cpf = getFormattedCPFFromUsername($userid);
+ if ($cpf) {
+ echo ' ' . "CPF" . ': ' . $cpf . '
';
+ }
+
+ // Exibe curso
+ $course = $DB->get_record('course', array('id' => $certdata->course));
+ if ($course) {
+ echo '' . get_string('course', 'block_verify_certificate') . ': ' . $course->fullname . ' ';
+ }
+
+ // Curso sem tutoria: início é matrícula, final é timeend de course_completions
+ // Curso com tutoria com turma: início e fim vem da matrícula da turma
+ // Curso com tutoria sem turma: início e fim vem da configuração do curso
+ // Demais cursos: início e fim vem da configuração do curso
+
+ $enrol_manager = new course_enrolment_manager($PAGE, $course);
+ $user_enrol = end($enrol_manager->get_user_enrolments($userid));
+ $enrol = $DB->get_record('enrol', array('id' => $user_enrol->enrolid));
+ if(substr( $course->idnumber, 0, 3 ) == 'ST-' ) {
+ $cc = new completion_completion(array('userid'=>$certrecord->userid, 'course'=>$certdata->course));
+ $start_date = $user_enrol->timestart;
+ $end_date = $cc->timecompleted;
+ $type = 'ST';
+ } elseif(substr( $course->idnumber, 0, 3 ) == 'CT-') {
+ /*$group = $DB->get_record('groups', array('courseid' => $course->id));
+ if( $group ) {
+ $start_date = $enrol->enrolstartdate;
+ $end_date = $enrol->enrolenddate;
+ } else {
+ $start_date = $course->startdate;
+ $end_date = $course->enddate;
+ }*/
+ $type = 'CT';
+ $start_date = $course->startdate;
+ $end_date = $course->enddate;
+ } else {
+ $type = '';
+ $start_date = $course->startdate;
+ $end_date = $course->enddate;
+ }
+
+ // Retrieving grade and date for each certificate.
+ $grade = certificate_get_grade($certdata, $course, $userid, $valueonly = true);
+ //$date = $start_date; //$certrecord->timecreated = $certdata->citimecreated;
+
+ if (($type = 'ST' || $type = 'CT') && $start_date && $end_date) {
+ echo " PERÍODO: " . userdate($start_date, $dateformat) . " a " . userdate($end_date, $dateformat) . '
';
+ } else {
+ echo "DATA: " . userdate($certdata->timecreated, $dateformat) . '
';
+ }
+
+
+ if ($course && $certdata->printgrade > 0) {
+ echo '' . get_string('grade', 'block_verify_certificate') . ': ' . $grade . '
';
+ }
+ if ($course->summary) {
+ echo "
$course->summary ";
+ }
+ echo ' | ';
+ echo "";
+ echo ' |
';
+ echo '' . get_string('check', 'block_verify_certificate') . '
';
+ }
+ echo $OUTPUT->box_end();
+}
+echo $OUTPUT->footer();
diff --git a/lang/en/block_verify_certificate.php b/lang/en/block_verify_certificate.php
index 9c1c5b7..351b415 100644
--- a/lang/en/block_verify_certificate.php
+++ b/lang/en/block_verify_certificate.php
@@ -1,15 +1,43 @@
-.
+
+/**
+ * Version details
+ *
+ * Verify certificate block
+ * --------------------------
+ * Verify certificate based on the unique codes displayed on issued certificates.
+ * Full details of the issued certificate is displayed including profile picture.
+ * Mostly cosmetic changes to the original codes from Jean-Michel Védrine.
+ * Original Autor & Copyright - Jean-Michel Védrine | 2014
+ *
+ * @copyright 2015 onwards Manieer Chhettri | Marie Curie, UK |
+ * @author Manieer Chhettri | Marie Curie, UK | | 2015
+ * @package block_verify_certificate
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['title'] = 'Verify certificate';
+$string['pluginname'] = 'Verify certificate';
+$string['certificate'] = 'VERIFICATION FOR CERTIFICATE CODE ::';
+$string['verifycertificate'] = 'Verify certificate';
+$string['verify_certificate:addinstance'] = 'Add a new Verify certificate block';
+$string['notfound'] = 'The certificate code you provided could not be validated.
Please make sure you have typed the code correctly as its case sensetive.';
+$string['to'] = 'AWARDED TO';
+$string['course'] = 'COURSE';
+$string['date'] = 'ON';
+$string['grade'] = 'GRADE';
+$string['check'] = 'Please make sure all the details on the certificate match the displayed results.';
diff --git a/logo/Certificate-unverified.png b/logo/Certificate-unverified.png
new file mode 100644
index 0000000..b2cbdac
Binary files /dev/null and b/logo/Certificate-unverified.png differ
diff --git a/logo/Certificate-verified.png b/logo/Certificate-verified.png
new file mode 100644
index 0000000..9093d7c
Binary files /dev/null and b/logo/Certificate-verified.png differ
diff --git a/logo/verify_block.png b/logo/verify_block.png
new file mode 100644
index 0000000..9482d51
Binary files /dev/null and b/logo/verify_block.png differ
diff --git a/pix/certnotverified.png b/pix/certnotverified.png
new file mode 100644
index 0000000..f221709
Binary files /dev/null and b/pix/certnotverified.png differ
diff --git a/pix/certverified.png b/pix/certverified.png
new file mode 100644
index 0000000..022ac8c
Binary files /dev/null and b/pix/certverified.png differ
diff --git a/pix/printicon.png b/pix/printicon.png
new file mode 100644
index 0000000..73bb70a
Binary files /dev/null and b/pix/printicon.png differ
diff --git a/printstyle.css b/printstyle.css
index 2891d83..80bfa11 100644
--- a/printstyle.css
+++ b/printstyle.css
@@ -1,21 +1,20 @@
-@media print {
-body {
- background:#FFFFFF;
-}
- #header, #header-home {
- display: none;
- }
-
- #footer {
- display: none;
- }
-
- .navbar {
- display:none;
- }
-
- .printicon {
- display:none;
- }
-
-}
\ No newline at end of file
+@media print {
+body {
+ background:#FFFFFF;
+}
+ #header, #header-home {
+ display: none;
+ }
+
+ #footer {
+ display: none;
+ }
+
+ .navbar {
+ display:none;
+ }
+
+ .printicon {
+ display:none;
+ }
+}
diff --git a/styles.css b/styles.css
new file mode 100644
index 0000000..3d11ef9
--- /dev/null
+++ b/styles.css
@@ -0,0 +1,65 @@
+/** 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 .
+ *
+ * Version details
+ *
+ * Verify certificate block
+ * --------------------------
+ * Verify certificate based on the unique codes displayed on issued certificates.
+ * Full details of the issued certificate is displayed including profile picture.
+ * Mostly cosmetic changes to the original codes from Jean-Michel Védrine.
+ * Original Autor & Copyright - Jean-Michel Védrine | 2014
+ *
+ * @copyright 2015 onwards Manieer Chhettri | Marie Curie, UK |
+ * @author Manieer Chhettri | Marie Curie, UK | | 2015
+ * @package block_verify_certificate
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+#block_verify_certificate p.notVerified {
+ color: #F00;
+ font-size:large;
+ font-weight:bold;
+}
+
+#block_verify_certificate p.verified {
+ color: #393;
+ font-size:large;
+ font-weight:bold;
+}
+
+#block_verify_certificate .left {
+ float: left;
+ width: 75%;
+ margin-top: 10px;
+}
+
+#block_verify_certificate .right {
+ float: right;
+ width: 25%;
+ margin-top: 10px;
+}
+
+#block_verify_certificate .wrapper-box:after {
+ content:"";
+ display: table;
+ clear: both;
+}
+
+@media screen and (max-width: 480px) {
+#block_verify_certificate .left, .right {
+ float: none;
+ width: auto;
+ }
+}
diff --git a/version.php b/version.php
index 02f4864..dfa7274 100644
--- a/version.php
+++ b/version.php
@@ -1,19 +1,43 @@
-.
-
-$plugin->version = 2009072901;
-
+.
+
+/**
+ * Version details
+ *
+ * Verify certificate block
+ * --------------------------
+ * Verify certificate based on the unique codes displayed on issued certificates.
+ * Full details of the issued certificate is displayed including profile picture.
+ * Mostly cosmetic changes to the original codes from Jean-Michel Védrine.
+ * Original Autor & Copyright - Jean-Michel Védrine | 2014
+ *
+ * @copyright 2015 onwards Manieer Chhettri | Marie Curie, UK |
+ * @author Manieer Chhettri | Marie Curie, UK | | 2015
+ * @package block_verify_certificate
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$plugin->version = 2016051200; // The current plugin version (Date: YYYYMMDDXX)
+$plugin->requires = 2014051203; // Requires this Moodle version 2.7.
+$plugin->cron = 0; // Period for cron to check this module (secs).
+$plugin->component = 'block_verify_certificate'; // To check on upgrade, that module sits in correct place.
+$plugin->maturity = MATURITY_STABLE;
+$plugin->release = 'v3.0';
+$plugin->dependencies = array(
+ 'mod_certificate' => 2014041801
+);