Certificate - Problem with apostrophes

Certificate - Problem with apostrophes

by Rik Mertens -
Number of replies: 1
This may be a bigger Moodle bug, but does anyone know how to permanently fix this problem? 

I have a user who's last name has an apostrophe in it (like O'Grady).  When they go to print their certificate, it doesn't print their name and it prints the 1969 error date.

After lots of trial and error, I finally figured out that the apostrophe in their name wasn't escaped by a back-slash.  I added the slash manually and now it seems to work.

I don't want to patrol last names for slashes.  Is there anything I can do to the certificate code to avoid the problem?

Rik
Average of ratings: -
In reply to Rik Mertens

Re: Certificate - Problem with apostrophes

by Marion de Groot -

Hi Rik,

I don't know what you mean by "I don't want to patrol last names for slashes"?

To print names with apostrophes, change the check_cert_exist($course, $user) in certificate/lib.php to this:

function check_cert_exists($course, $user) {
 global $course;
 if (record_exists("certificate_viewed", "courseid", $course->id, "userid", $user->id)) {
  $CERT = get_record("certificate_viewed","courseid", $course->id, "userid", $user->id);
 } else {
  $CODE = generate_code();
  $view_time = time();
  $studentname = addslashes($user->firstname . " " . $user->lastname);
  insert_record("certificate_viewed", array("courseid" => $course->id, "userid" => $user->id, "studentname" => $studentname, "code" => $CODE, "cert_date" => $view_time, "classname" => $course->fullname), false);

  $CERT = get_record("certificate_viewed","courseid", $course->id, "userid", $user->id);  
 }
 return $CERT;
}

The certificate module makes a record in the certificate_viewed table when a certain user views a certificate in a certain course. Even if you have several certificates in one course, it will create just one record (the first time this user views one of these certificates in the course). When this record exists, the certificate module will retrieve the users' fullname from the certificate_viewed table, not from the users table. So when you've changed the check_cert_exist($course, $user), it will work only for users that have not yet viewed any certificate in the course. If you want to display the names of users who have viewed a certificate correctly you will have to change them manually, or delete their records in the certificate_viewed table and ask them to view their certificate again.

Marion