diff --git a/edit.php b/edit.php index f5aacd5..6327a58 100644 --- a/edit.php +++ b/edit.php @@ -181,6 +181,11 @@ if ($data = $mform->get_data()) { } } + // Check if we want to preview this custom certificate. + if (!empty($data->previewbtn)) { + customcert_generate_pdf($customcert, $USER->id); + } + // Redirect to the editing page to show form with recent updates. $url = new moodle_url('/mod/customcert/edit.php', array('cmid' => $cmid)); redirect($url); diff --git a/edit_form.php b/edit_form.php index b66f003..2acc2c1 100644 --- a/edit_form.php +++ b/edit_form.php @@ -83,6 +83,7 @@ class mod_customcert_edit_form extends moodleform { // Add the submit buttons. $group = array(); $group[] = $mform->createElement('submit', 'submitbtn', get_string('savechanges')); + $group[] = $mform->createElement('submit', 'previewbtn', get_string('savechangespreview', 'customcert')); $mform->addElement('group', 'submitbtngroup', '', $group, '', false); $mform->addElement('hidden', 'id'); diff --git a/elements/element.class.php b/elements/element.class.php index 8927665..90069b9 100644 --- a/elements/element.class.php +++ b/elements/element.class.php @@ -15,6 +15,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +require_once($CFG->dirroot . '/mod/customcert/includes/tcpdf_colors.php'); + /** * The base class for the customcert elements. * diff --git a/lang/en/customcert.php b/lang/en/customcert.php index b6dd43c..f3feba7 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -75,6 +75,7 @@ $string['posx_help'] = 'This is the position in pixels from the top left corner $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['savechangespreview'] = 'Save changes and preview'; $string['savetemplate'] = 'Save template'; $string['setprotection'] = 'Set protection'; $string['setprotection_help'] = 'Choose the actions you wish to prevent users from performing on this certificate.'; diff --git a/lib.php b/lib.php index c510bc8..c0e4e6f 100644 --- a/lib.php +++ b/lib.php @@ -802,6 +802,8 @@ function customcert_generate_code() { function customcert_generate_pdf($customcert, $userid) { global $CFG, $DB; + require_once($CFG->libdir . '/pdflib.php'); + // Get the pages for the customcert, there should always be at least one page for each customcert. if ($pages = $DB->get_records('customcert_pages', array('customcertid' => $customcert->id), 'pagenumber ASC')) { // Create the pdf object. diff --git a/view.php b/view.php index aa1884b..5a87c15 100644 --- a/view.php +++ b/view.php @@ -25,8 +25,6 @@ require_once('../../config.php'); require_once($CFG->dirroot . '/mod/customcert/lib.php'); -require_once($CFG->libdir . '/pdflib.php'); -require_once($CFG->dirroot . '/mod/customcert/includes/tcpdf_colors.php'); $id = required_param('id', PARAM_INT); $action = optional_param('action', '', PARAM_ALPHA);