commit e79270040bfb806ea3de4b624ed37b51d0c9f8e5
Author: Francois Marier <francois@catalyst.net.nz>
Date:   Mon Feb 25 17:39:25 2008 +1300

    mod/certificate: Add two new course-based settings (title and coursename)
    The "title" setting controls what is displayed at the top of the certificate (by default "CERTIFICATE of ACHIEVEMENT").
    
    The "coursename" setting is what gets displayed instead of the course name on the certificate.  An example use case of this is when you have multiple activities on a page and want to display a certificate for all three activities:
    
    e.g. In a course called "Powerpoint Courses" which includes activities "Powerpoint 101" and "Powerpoint 102", a teacher might want to issue a certificate for the whole couse where the course name is "Powerpoint", not "Powerpoint Courses".

diff --git a/mod/certificate/db/install.xml b/mod/certificate/db/install.xml
index 3651f5b..cea52e7 100644
--- a/mod/certificate/db/install.xml
+++ b/mod/certificate/db/install.xml
@@ -29,7 +29,9 @@
         <FIELD NAME="customtext" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="printteacher" NEXT="printsignature"/>
         <FIELD NAME="printsignature" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="customtext" NEXT="printseal"/>
         <FIELD NAME="printseal" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="printsignature" NEXT="timemodified"/>
-        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="printseal"/>
+        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="printseal" NEXT="title"/>
+        <FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="Title to be displayed at the top of the certificate" PREVIOUS="timemodified" NEXT="coursename"/>
+        <FIELD NAME="coursename" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="Text to show instead of the course name on the certificate" PREVIOUS="title"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for certificate"/>
@@ -79,4 +81,4 @@
       </SENTENCES>
     </STATEMENT>
   </STATEMENTS>
-</XMLDB>
\ No newline at end of file
+</XMLDB>
diff --git a/mod/certificate/db/upgrade.php b/mod/certificate/db/upgrade.php
index a8ba057..7ed93a8 100644
--- a/mod/certificate/db/upgrade.php
+++ b/mod/certificate/db/upgrade.php
@@ -87,6 +87,18 @@ function xmldb_certificate_upgrade($oldversion=0) {
         $result = change_field_unsigned($table, $field);
     }
 
+    if ($result && $oldversion < 2007061304) {
+        $table = new XMLDBTable('certificate');
+
+        $field1 = new XMLDBField('title');
+        $field1->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, '', 'timemodified');
+        $result = $result && add_field($table, $field1);
+
+        $field2 = new XMLDBField('coursename');
+        $field2->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, '', 'title');
+        $result = $result && add_field($table, $field2);
+    }
+
     return $result;
 }
 
diff --git a/mod/certificate/lang/en_utf8/certificate.php b/mod/certificate/lang/en_utf8/certificate.php
index db5f5ed..bfc4ae0 100644
--- a/mod/certificate/lang/en_utf8/certificate.php
+++ b/mod/certificate/lang/en_utf8/certificate.php
@@ -3,7 +3,9 @@
 //General functions
 $string['modulename'] = 'Certificate';
 $string['modulenameplural'] = 'Certificates';
+$string['certificatecoursename'] = 'Course Name';
 $string['certificatename'] = 'Certificate Name';
+$string['certificatetitle'] = 'Certificate Title';
 $string['certificate:view'] = 'View Certificate';
 $string['certificate:manage'] = 'Manage Certificate';
 $string['certificate:printteacher'] = 'Print Teacher';
@@ -128,25 +130,23 @@ $string['typeletter_landscape'] = 'Landscape (letter)';
 $string['typeunicode_landscape'] = 'Unicode (landscape)';
 $string['typeunicode_portrait'] = 'Unicode (portrait)';
 
+$string['titledefault'] = 'CERTIFICATE of ACHIEVEMENT';
+
 //Print to certificate strings
 $string['grade'] = 'Grade';
 $string['coursegrade'] = 'Course Grade';
 $string['credithours'] = 'Credit Hours';
 
-$string['titlelandscape'] = 'CERTIFICATE of ACHIEVEMENT';
 $string['introlandscape'] = 'This is to certify that';
 $string['statementlandscape'] = 'has completed the course';
 
-$string['titleletterlandscape'] = 'CERTIFICATE of ACHIEVEMENT';
 $string['introletterlandscape'] = 'This is to certify that';
 $string['statementletterlandscape'] = 'has completed the course';
 
-$string['titleportrait'] = 'CERTIFICATE of ACHIEVEMENT';
 $string['introportrait'] = 'This is to certify that';
 $string['statementportrait'] = 'has completed the course';
 $string['ondayportrait'] = 'on this day';
 
-$string['titleletterportrait'] = 'CERTIFICATE of ACHIEVEMENT';
 $string['introletterportrait'] = 'This is to certify that';
 $string['statementletterportrait'] = 'has completed the course';
 ?>
\ No newline at end of file
diff --git a/mod/certificate/lang/en_utf8/help/certificate/coursename.html b/mod/certificate/lang/en_utf8/help/certificate/coursename.html
new file mode 100644
index 0000000..33f4621
--- /dev/null
+++ b/mod/certificate/lang/en_utf8/help/certificate/coursename.html
@@ -0,0 +1,3 @@
+<p align="center"><b>Course Name</b></p>
+<p>If set, this text will be displayed where the course name would normally
+  be shown.</p>
diff --git a/mod/certificate/lang/en_utf8/help/certificate/title.html b/mod/certificate/lang/en_utf8/help/certificate/title.html
new file mode 100644
index 0000000..5e3157e
--- /dev/null
+++ b/mod/certificate/lang/en_utf8/help/certificate/title.html
@@ -0,0 +1,2 @@
+<p align="center"><b>Certificate Title</b></p>
+<p>This is the text to be displayed at the top of the certificate.</p>
diff --git a/mod/certificate/mod_form.php b/mod/certificate/mod_form.php
index cb7d663..ee09c71 100644
--- a/mod/certificate/mod_form.php
+++ b/mod/certificate/mod_form.php
@@ -64,6 +64,16 @@ class mod_certificate_mod_form extends moodleform_mod {
 //-------------------------------------------------------------------------------
         $mform->addElement('header', 'textoptions', get_string('textoptions', 'certificate'));		
 
+        $mform->addElement('text', 'title', get_string('certificatetitle', 'certificate'), array('size'=>'64'));
+        $mform->setType('title', PARAM_TEXT);
+        $mform->setDefault('title', get_string('titledefault', 'certificate'));
+        $mform->addRule('title', null, 'required', null, 'client');
+        $mform->setHelpButton('title', array('title', get_string('certificatetitle', 'certificate'), 'certificate'));
+
+        $mform->addElement('text', 'coursename', get_string('certificatecoursename', 'certificate'), array('size'=>'64'));
+        $mform->setType('coursename', PARAM_TEXT);
+        $mform->setHelpButton('coursename', array('coursename', get_string('certificatecoursename', 'certificate'), 'certificate'));
+
         $dateoptions = array( 0 => get_string('no'), 1 => get_string('receiveddate', 'certificate'), 2 => get_string('courseenddate', 'certificate'));
         $mform->addElement('select', 'printdate', get_string('printdate', 'certificate'), $dateoptions);
         $mform->setDefault('printdate', 0);
diff --git a/mod/certificate/type/landscape/certificate.php b/mod/certificate/type/landscape/certificate.php
index 5a7515e..95d1e3a 100644
--- a/mod/certificate/type/landscape/certificate.php
+++ b/mod/certificate/type/landscape/certificate.php
@@ -122,6 +122,14 @@ $credithours =  $strcredithours.': '.$certificate->printhours;
 //Print the html text
 $customtext = $certificate->customtext;
 
+// Print the title at the top of the certificate
+$certificatetitle = $certificate->title;
+
+// Replace the course name with a string if applicable
+if (!empty($certificate->coursename)) {
+    $classname = $certificate->coursename;
+}
+
 //Add pdf page
     $orientation = "L";
     $pdf=new PDF($orientation, 'pt', 'A4');
@@ -139,7 +147,7 @@ $customtext = $certificate->customtext;
 
 // Add text
     $pdf->SetTextColor(0,0,120);
-    cert_printtext(170, 125, 'C', 'Helvetica', 'B', 30, utf8_decode(get_string('titlelandscape', 'certificate')));
+    cert_printtext(170, 125, 'C', 'Helvetica', 'B', 30, utf8_decode($certificatetitle));
     $pdf->SetTextColor(0,0,0);
     cert_printtext(170, 180, 'C', 'Times', 'B', 20, utf8_decode(get_string('introlandscape', 'certificate')));
     cert_printtext(170, 230, 'C', 'Helvetica', '', 30, utf8_decode($studentname));
diff --git a/mod/certificate/type/letter_landscape/certificate.php b/mod/certificate/type/letter_landscape/certificate.php
index 47947ae..f04517b 100644
--- a/mod/certificate/type/letter_landscape/certificate.php
+++ b/mod/certificate/type/letter_landscape/certificate.php
@@ -122,6 +122,14 @@ $credithours =  $strcredithours.': '.$certificate->printhours;
 //Print the html text
 $customtext = $certificate->customtext;
 
+// Print the title at the top of the certificate
+$certificatetitle = $certificate->title;
+
+// Replace the course name with a string if applicable
+if (!empty($certificate->coursename)) {
+    $classname = $certificate->coursename;
+}
+
 // Add pdf page
     $orientation = "L";
     $pdf=new PDF($orientation, 'pt', 'Letter');
@@ -139,7 +147,7 @@ $customtext = $certificate->customtext;
 
 // Add text
     $pdf->SetTextColor(0,0,120);
-    cert_printtext(150, 125, 'C', 'Helvetica', 'B', 30, utf8_decode(get_string("titleletterlandscape", "certificate")));
+    cert_printtext(150, 125, 'C', 'Helvetica', 'B', 30, utf8_decode($certificatetitle));
     $pdf->SetTextColor(0,0,0);
     cert_printtext(150, 180, 'C', 'Times', 'B', 20, utf8_decode(get_string("introletterlandscape", "certificate")));
     cert_printtext(150, 230, 'C', 'Helvetica', '', 30, utf8_decode($studentname));
diff --git a/mod/certificate/type/letter_portrait/certificate.php b/mod/certificate/type/letter_portrait/certificate.php
index 4ce3cd9..f32658d 100644
--- a/mod/certificate/type/letter_portrait/certificate.php
+++ b/mod/certificate/type/letter_portrait/certificate.php
@@ -122,6 +122,14 @@ $credithours =  $strcredithours.': '.$certificate->printhours;
 //Print the html text
 $customtext = $certificate->customtext;
 
+// Print the title at the top of the certificate
+$certificatetitle = $certificate->title;
+
+// Replace the course name with a string if applicable
+if (!empty($certificate->coursename)) {
+    $classname = $certificate->coursename;
+}
+
 // Add pdf page
     $orientation = "P";
     $pdf=new PDF($orientation, 'pt', 'Letter');
@@ -139,7 +147,7 @@ $customtext = $certificate->customtext;
 
 // Add text
     $pdf->SetTextColor(0,0,128);
-    cert_printtext(58, 170, 'C', 'Helvetica', 'B', 28, utf8_decode(get_string("titleportrait", "certificate")));
+    cert_printtext(58, 170, 'C', 'Helvetica', 'B', 28, utf8_decode($certificatetitle));
     $pdf->SetTextColor(0,0,0);
     cert_printtext(58, 230, 'C', 'Times', 'B', 20, utf8_decode(get_string("introportrait", "certificate")));
     cert_printtext(58, 280, 'C', 'Helvetica', '', 30, utf8_decode($studentname));
diff --git a/mod/certificate/type/portrait/certificate.php b/mod/certificate/type/portrait/certificate.php
index bc82e42..4424948 100644
--- a/mod/certificate/type/portrait/certificate.php
+++ b/mod/certificate/type/portrait/certificate.php
@@ -122,6 +122,14 @@ $credithours =  $strcredithours.': '.$certificate->printhours;
 //Print the html text
 $customtext = $certificate->customtext;
 
+// Print the title at the top of the certificate
+$certificatetitle = $certificate->title;
+
+// Replace the course name with a string if applicable
+if (!empty($certificate->coursename)) {
+    $classname = $certificate->coursename;
+}
+
 //Add pdf page
     $orientation = "P";
     $pdf = new PDF($orientation, 'pt', 'A4');
@@ -139,7 +147,7 @@ $customtext = $certificate->customtext;
     
 // Add text
     $pdf->SetTextColor(0,0,128);
-    cert_printtext(48, 170, 'C', 'Helvetica', 'B', 26, utf8_decode(get_string("titleportrait", "certificate")));
+    cert_printtext(48, 170, 'C', 'Helvetica', 'B', 26, utf8_decode($certificatetitle));
     $pdf->SetTextColor(0,0,0);
     cert_printtext(45, 230, 'C', 'Times', 'B', 20, utf8_decode(get_string("introportrait", "certificate")));
     cert_printtext(45, 280, 'C', 'Helvetica', '', 30, utf8_decode($studentname));
diff --git a/mod/certificate/type/unicode_landscape/certificate.php b/mod/certificate/type/unicode_landscape/certificate.php
index 056dfe9..8aa9d26 100644
--- a/mod/certificate/type/unicode_landscape/certificate.php
+++ b/mod/certificate/type/unicode_landscape/certificate.php
@@ -125,6 +125,14 @@ $credithours =  $strcredithours.': '.$certificate->printhours;
 //Print the html text
 $customtext = $certificate->customtext;
 
+// Print the title at the top of the certificate
+$certificatetitle = $certificate->title;
+
+// Replace the course name with a string if applicable
+if (!empty($certificate->coursename)) {
+    $classname = $certificate->coursename;
+}
+
 //Create new PDF document 
 
     $pdf = new TCPDF_Protection('L', 'pt', 'A4', true); 
@@ -147,7 +155,7 @@ $customtext = $certificate->customtext;
 	
 // Add text
     $pdf->SetTextColor(0,0,120);
-    cert_printtext(170, 125, 'C', 'FreeSerif', 'B', 30, get_string('titlelandscape', 'certificate'));
+    cert_printtext(170, 125, 'C', 'FreeSerif', 'B', 30, $certificatetitle);
     $pdf->SetTextColor(0,0,0);
     cert_printtext(170, 180, 'C', 'FreeSerif', '', 20, get_string('introlandscape', 'certificate'));
     cert_printtext(170, 230, 'C', 'FreeSerif', 'I', 30, $studentname);
diff --git a/mod/certificate/type/unicode_portrait/certificate.php b/mod/certificate/type/unicode_portrait/certificate.php
index a5dd960..356233d 100644
--- a/mod/certificate/type/unicode_portrait/certificate.php
+++ b/mod/certificate/type/unicode_portrait/certificate.php
@@ -124,6 +124,14 @@ $credithours =  $strcredithours.': '.$certificate->printhours;
 //Print the html text
 $customtext = $certificate->customtext;
 
+// Print the title at the top of the certificate
+$certificatetitle = $certificate->title;
+
+// Replace the course name with a string if applicable
+if (!empty($certificate->coursename)) {
+    $classname = $certificate->coursename;
+}
+
 //Create new PDF document 
 
     $pdf = new TCPDF_Protection('P', 'pt', 'A4', true); 
@@ -146,7 +154,7 @@ $customtext = $certificate->customtext;
 	
 // Add text
     $pdf->SetTextColor(0,0,128);
-    cert_printtext(48, 170, 'C', 'FreeSerif', 'B', 26, get_string("titleportrait", "certificate"));
+    cert_printtext(48, 170, 'C', 'FreeSerif', 'B', 26, $certificatetitle);
     $pdf->SetTextColor(0,0,0);
     cert_printtext(45, 230, 'C', 'FreeSerif', 'B', 20, get_string("introportrait", "certificate"));
     cert_printtext(45, 280, 'C', 'FreeSerif', '', 30, $studentname);
diff --git a/mod/certificate/version.php b/mod/certificate/version.php
index d9d5c63..de847ca 100644
--- a/mod/certificate/version.php
+++ b/mod/certificate/version.php
@@ -5,7 +5,7 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 ///////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2007061303;  // The current module version (Date: YYYYMMDDXX)
+$module->version  = 2007061304;  // The current module version (Date: YYYYMMDDXX)
 $module->requires = 2007021503;  // Requires this Moodle version
 $module->cron     = 0;           // Period for cron to check this module (secs)
 

