diff --git a/db/install.xml b/db/install.xml index 5e7bb22..1ec8331 100644 --- a/db/install.xml +++ b/db/install.xml @@ -12,6 +12,7 @@ + diff --git a/lang/en/customcert.php b/lang/en/customcert.php index 02ffec5..b6dd43c 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -25,6 +25,7 @@ $string['addcertpage'] = 'Add another certificate page'; $string['addelement'] = 'Add element'; +$string['copy'] = 'Copy'; $string['coursetimereq'] = 'Required minutes in course'; $string['coursetimereq_help'] = 'Enter here the minimum amount of time, in minutes, that a student must be logged into the course before they will be able to receive the certificate.'; $string['customcert:addinstance'] = 'Add a new custom certificate instance'; @@ -56,6 +57,7 @@ $string['landscape'] = 'Landscape'; $string['load'] = 'Load'; $string['loadtemplate'] = 'Load template'; $string['loadtemplatemsg'] = 'Are you sure you wish to load this template? This will remove any existing pages and elements for this certificate.'; +$string['modify'] = 'Modify'; $string['modulename'] = 'Custom Certificate'; $string['modulenameplural'] = 'Custom Certificates'; $string['name'] = 'Name'; @@ -66,6 +68,7 @@ $string['orientation_help'] = 'Choose whether you want your certificate orientat $string['page'] = 'Page {$a}'; $string['pluginadministration'] = 'Custom Certificate administration'; $string['pluginname'] = 'Custom Certificate'; +$string['print'] = 'Print'; $string['portrait'] = 'Portrait'; $string['posx'] = 'Position X'; $string['posx_help'] = 'This is the position in pixels from the top left corner you wish the element to display in the x direction.'; @@ -73,6 +76,8 @@ $string['posy'] = 'Postion Y'; $string['posy_help'] = 'This is the position in pixels from the top left corner you wish the element to display in the y direction.'; $string['save'] = 'Save'; $string['savetemplate'] = 'Save template'; +$string['setprotection'] = 'Set protection'; +$string['setprotection_help'] = 'Choose the actions you wish to prevent users from performing on this certificate.'; $string['summaryofissue'] = 'Summary of issue'; $string['templatename'] = 'Template name'; $string['templatenameexists'] = 'That template name is currently in use, please choose another.'; diff --git a/lib.php b/lib.php index edf2ccb..a78dc66 100644 --- a/lib.php +++ b/lib.php @@ -25,6 +25,21 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); +/** + * @var string the print protection variable + */ +define('PROTECTION_PRINT', 'print'); + +/** + * @var string the modify protection variable + */ +define('PROTECTION_MODIFY', 'modify'); + +/** + * @var string the copy protection variable + */ +define('PROTECTION_COPY', 'copy'); + /** * Add customcert instance. * @@ -35,6 +50,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); function customcert_add_instance($data, $mform) { global $DB; + $data->protection = customcert_set_protection($data); $data->timecreated = time(); $data->timemodified = $data->timecreated; @@ -51,13 +67,36 @@ function customcert_add_instance($data, $mform) { function customcert_update_instance($data, $mform) { global $DB; - // Update the time modified. + $data->protection = customcert_set_protection($data); $data->timemodified = time(); $data->id = $data->instance; return $DB->update_record('customcert', $data); } +/** + * Handles setting the protection field for the customcert + * + * @param stdClass $data + * @return string the value to insert into the protection field + */ +function customcert_set_protection($data) { + $protection = array(); + + if (!empty($data->protection_print)) { + $protection[] = PROTECTION_PRINT; + } + if (!empty($data->protection_modify)) { + $protection[] = PROTECTION_MODIFY; + } + if (!empty($data->protection_copy)) { + $protection[] = PROTECTION_COPY; + } + + // Return the protection string. + return implode(', ', $protection); +} + /** * Given an ID of an instance of this module, * this function will permanently delete the instance @@ -773,6 +812,10 @@ function customcert_generate_pdf($customcert, $userid) { if ($pages = $DB->get_records('customcert_pages', array('customcertid' => $customcert->id), 'pagenumber ASC')) { // Create the pdf object. $pdf = new pdf(); + if (!empty($customcert->protection)) { + $protection = explode(', ', $customcert->protection); + $pdf->SetProtection($protection); + } $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->SetTitle($customcert->name); diff --git a/mod_form.php b/mod_form.php index 90a16e2..c98d334 100644 --- a/mod_form.php +++ b/mod_form.php @@ -55,11 +55,39 @@ class mod_customcert_mod_form extends moodleform_mod { $mform->setType('requiredtime', PARAM_INT); $mform->addHelpButton('requiredtime', 'coursetimereq', 'customcert'); + $mform->addElement('checkbox', 'protection_print', get_string('setprotection', 'customcert'), get_string('print', 'customcert')); + $mform->addElement('checkbox', 'protection_modify', '', get_string('modify', 'customcert')); + $mform->addElement('checkbox', 'protection_copy', '', get_string('copy', 'customcert')); + $mform->addHelpButton('protection_print', 'setprotection', 'customcert'); + $this->standard_coursemodule_elements(); $this->add_action_buttons(); } + /** + * Any data processing needed before the form is displayed. + * + * @param array $defaultvalues + */ + public function data_preprocessing(&$defaultvalues) { + global $DB; + + if (!empty($defaultvalues['protection'])) { + $protection = explode(', ', $defaultvalues['protection']); + // Set the values in the form to what has been set in database. + if (in_array(PROTECTION_PRINT, $protection)) { + $defaultvalues['protection_print'] = 1; + } + if (in_array(PROTECTION_MODIFY, $protection)) { + $defaultvalues['protection_modify'] = 1; + } + if (in_array(PROTECTION_COPY, $protection)) { + $defaultvalues['protection_copy'] = 1; + } + } + } + /** * Some basic validation. *