Upgraded to latest version now expiration date does not show correctly...

Upgraded to latest version now expiration date does not show correctly...

by Richard Bakos -
Number of replies: 5

Hello all,

I upgraded to version 2012062101 of the certificate module and since then my custom field for expiration date does not display the correct date. I initially was receiving 500 error with my custom certificates after the upgrade but figuring out how to fix that was simple enough but this I can't seem to figure out for some reason. Below is my a code which I have placed on line 7 of the certificate.php in my custom certificate type folder along with a screen cap of the date that is displayed... It should show two years from the date issued.

// Set expiration date
$expdate = str_replace(' 0', ' ', strftime('%B %d, %Y',(strtotime("+2 years", $certificatedate))));

And this is how the expdate is placed on the certificate:

certificate_print_text($pdf, 158, 170 + 10, 'L', 'Helvetica', '', 11, utf8_decode("Expires: ".$expdate));

What it displays:

Average of ratings: -
In reply to Richard Bakos

Re: Upgraded to latest version now expiration date does not show correctly...

by Jean-Michel Védrine -

Hello Richard,

The code has changed and $certificatedate is no more used so it is undefined so you are adding 2 years to nothing = unix date's origin wich produce December 31 1971

I suggest you upgrade you code looking in mod/certificate/lib.php how the certificate_get_date function is written and use a similar code to get the date you want.

If you don't use completion date, you can somewhat simplify the code starting from $certrecord->timecreated wich is a unix timestamp

In reply to Jean-Michel Védrine

Re: Upgraded to latest version now expiration date does not show correctly...

by Richard Bakos -

Hmm... Strange cause in the lib file I found this:

if ($certificate->printdate > 0) {
if ($certificate->datefmt == 1) {
$certificatedate = str_replace(' 0', ' ', strftime('%B %d, %Y', $date));
} else if ($certificate->datefmt == 2) {
$certificatedate = date('F jS, Y', $date);
} else if ($certificate->datefmt == 3) {
$certificatedate = str_replace(' 0', '', strftime('%d %B %Y', $date));
} else if ($certificate->datefmt == 4) {
$certificatedate = strftime('%B %Y', $date);
} else if ($certificate->datefmt == 5) {
$certificatedate = userdate($date, get_string('strftimedate', 'langconfig'));
}

return $certificatedate;
}

return '';
}

Since return $certificatedate I figured that was what I needed to call... But I figured it out none-the-less... Here is the fix:

$expdate = str_replace(' 0', ' ', strftime('%B %d, %Y',(strtotime("+2 years" .certificate_get_date($certificate, $certrecord, $course)))));

In reply to Richard Bakos

Re: Upgraded to latest version now expiration date does not show correctly...

by Jean-Michel Védrine -

$certificatedate is undefined outside of the certificate_get_date function.

If some other users of certificate read this thread I still think it would be better to use $certrecord->timecreated than the result of the certificate_get_date function because I don't think your method will works if the date is formatted in any other language than english. As $certrecord->timecreated is a unix timestamp, this problem doesn't exist.

My code (untested !) would be :

$expdate = str_replace(' 0', ' ', strftime('%B %d, %Y', strtotime("+2 years" , $certrecord->timecreated)));

In reply to Jean-Michel Védrine

Re: Upgraded to latest version now expiration date does not show correctly...

by Richard Bakos -

That makes sense... I tested your method... Works fine... Thanks!

In reply to Richard Bakos

Re: Upgraded to latest version now expiration date does not show correctly...

by Mark Nelson -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Glad Jean was able to help you Richard.

Thanks Jean! smile