diff --git a/backup/moodle2/backup_customcert_stepslib.php b/backup/moodle2/backup_customcert_stepslib.php index 772c323..dfac81c 100644 --- a/backup/moodle2/backup_customcert_stepslib.php +++ b/backup/moodle2/backup_customcert_stepslib.php @@ -49,7 +49,7 @@ class backup_customcert_activity_structure_step extends backup_activity_structur // The pages. $pages = new backup_nested_element('pages'); $page = new backup_nested_element('page', array('id'), array( - 'customcertid', 'width', 'height', 'margin', + 'customcertid', 'width', 'height', 'leftmargin', 'rightmargin', 'pagenumber', 'timecreated', 'timemodified')); // The elements. diff --git a/db/install.xml b/db/install.xml index 265472e..913765a 100644 --- a/db/install.xml +++ b/db/install.xml @@ -39,7 +39,8 @@ - + + @@ -89,7 +90,8 @@ - + + diff --git a/db/upgrade.php b/db/upgrade.php index 5d18b3a..033528f 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -100,5 +100,34 @@ function xmldb_customcert_upgrade($oldversion=0) { upgrade_mod_savepoint(true, 2015120800, 'customcert'); } + if ($oldversion < 2015120801) { + // Rename the 'margin' field to 'rightmargin' in the 'customcert_pages' and 'customcert_template_pages' tables. + $table = new xmldb_table('customcert_pages'); + $field = new xmldb_field('margin', XMLDB_TYPE_INTEGER, 10, null, null, null, 0, 'height'); + if ($dbman->field_exists($table, $field)) { + $dbman->rename_field($table, $field, 'rightmargin'); + } + + $table = new xmldb_table('customcert_template_pages'); + if ($dbman->field_exists($table, $field)) { + $dbman->rename_field($table, $field, 'rightmargin'); + } + + // Add 'leftmargin' fields to the 'customcert_pages' and 'customcert_template_pages' tables. + $table = new xmldb_table('customcert_pages'); + $field = new xmldb_field('leftmargin', XMLDB_TYPE_INTEGER, 10, null, null, null, 0, 'height'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + $table = new xmldb_table('customcert_template_pages'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Customcert savepoint reached. + upgrade_mod_savepoint(true, 2015120801, 'customcert'); + } + return true; } diff --git a/edit_form.php b/edit_form.php index 3ef344b..92b9aaa 100644 --- a/edit_form.php +++ b/edit_form.php @@ -99,9 +99,12 @@ class mod_customcert_edit_form extends moodleform { // Set the height. $element = $mform->getElement('pageheight_' . $p->id); $element->setValue($p->height); - // Set the margin. - $element = $mform->getElement('pagemargin_' . $p->id); - $element->setValue($p->margin); + // Set the left margin. + $element = $mform->getElement('pageleftmargin_' . $p->id); + $element->setValue($p->leftmargin); + // Set the right margin. + $element = $mform->getElement('pagerightmargin_' . $p->id); + $element->setValue($p->rightmargin); } } } @@ -135,8 +138,14 @@ class mod_customcert_edit_form extends moodleform { $errors[$heightid] = get_string('invalidheight', 'customcert'); } } - if (strpos($key, 'pagemargin_') !== false) { - // Validate that the margin is a valid value. + if (strpos($key, 'pageleftmargin_') !== false) { + // Validate that the left margin is a valid value. + if (isset($data[$key]) && ($data[$key] < 0)) { + $errors[$key] = get_string('invalidmargin', 'customcert'); + } + } + if (strpos($key, 'pagerightmargin_') !== false) { + // Validate that the right margin is a valid value. if (isset($data[$key]) && ($data[$key] < 0)) { $errors[$key] = get_string('invalidmargin', 'customcert'); } @@ -183,9 +192,13 @@ class mod_customcert_edit_form extends moodleform { $mform->addRule('pageheight_' . $page->id, null, 'required', null, 'client'); $mform->addHelpButton('pageheight_' . $page->id, 'height', 'customcert'); - $mform->addElement('text', 'pagemargin_' . $page->id, get_string('margin', 'customcert')); - $mform->setType('pagemargin_' . $page->id, PARAM_INT); - $mform->addHelpButton('pagemargin_' . $page->id, 'margin', 'customcert'); + $mform->addElement('text', 'pageleftmargin_' . $page->id, get_string('leftmargin', 'customcert')); + $mform->setType('pageleftmargin_' . $page->id, PARAM_INT); + $mform->addHelpButton('pageleftmargin_' . $page->id, 'leftmargin', 'customcert'); + + $mform->addElement('text', 'pagerightmargin_' . $page->id, get_string('rightmargin', 'customcert')); + $mform->setType('pagerightmargin_' . $page->id, PARAM_INT); + $mform->addHelpButton('pagerightmargin_' . $page->id, 'rightmargin', 'customcert'); $group = array(); $group[] = $mform->createElement('select', 'element_' . $page->id, '', customcert_get_elements()); diff --git a/lang/en/customcert.php b/lang/en/customcert.php index 8f44531..ed75cc1 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -68,11 +68,11 @@ $string['invalidmargin'] = 'The margin has to be a valid number greater than 0.' $string['invalidwidth'] = 'The width has to be a valid number greater than 0.'; $string['issued'] = 'Issued'; $string['landscape'] = 'Landscape'; +$string['leftmargin'] = 'Left margin'; +$string['leftmargin_help'] = 'This is the left margin of the certificate PDF in mm.'; $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['margin'] = 'Right margin'; -$string['margin_help'] = 'This is the right margin of the certificate PDF in mm.'; $string['modify'] = 'Modify'; $string['modulename'] = 'Custom Certificate'; $string['modulenameplural'] = 'Custom Certificates'; @@ -97,6 +97,8 @@ $string['refpoint'] = 'Reference point location'; $string['refpoint_help'] = 'This specifies which location of the element to be located at position X and position Y.'; $string['replacetemplate'] = 'Replace'; $string['report'] = 'Report'; +$string['rightmargin'] = 'Right margin'; +$string['rightmargin_help'] = 'This is the right margin of the certificate PDF in mm.'; $string['save'] = 'Save'; $string['saveandclose'] = 'Save and close'; $string['saveandcontinue'] = 'Save and continue'; diff --git a/locallib.php b/locallib.php index 7dd89e7..1d1ce4e 100644 --- a/locallib.php +++ b/locallib.php @@ -222,13 +222,15 @@ function customcert_save_page_data($data) { // Get the name of the fields we want from the form. $width = 'pagewidth_' . $page->id; $height = 'pageheight_' . $page->id; - $margin = 'pagemargin_' . $page->id; + $leftmargin = 'pageleftmargin_' . $page->id; + $rightmargin = 'pagerightmargin_' . $page->id; // Create the page data to update the DB with. $p = new stdClass(); $p->id = $page->id; $p->width = $data->$width; $p->height = $data->$height; - $p->margin = $data->$margin; + $p->leftmargin = $data->$leftmargin; + $p->rightmargin = $data->$rightmargin; $p->timemodified = $time; // Update the page. $DB->update_record('customcert_pages', $p); @@ -622,7 +624,7 @@ function customcert_generate_pdf($customcert, $preview = false) { $orientation = 'P'; } $pdf->AddPage($orientation, array($page->width, $page->height)); - $pdf->SetMargins(0, 0, $page->margin); + $pdf->SetMargins($page->leftmargin, 0, $page->rightmargin); // Get the elements for the page. if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id), 'sequence ASC')) { // Loop through and display. diff --git a/rearrange.php b/rearrange.php index f211ff8..8ab5640 100644 --- a/rearrange.php +++ b/rearrange.php @@ -50,7 +50,7 @@ $module = array( 'fullpath' => '/mod/customcert/yui/src/rearrange.js', 'requires' => array('dd-delegate', 'dd-drag') ); -$PAGE->requires->js_init_call('M.mod_customcert.rearrange.init', array($cm->id, $elements), false, $module); +$PAGE->requires->js_init_call('M.mod_customcert.rearrange.init', array($cm->id, $page, $elements), false, $module); // Create the buttons to save the position of the elements. $html = html_writer::start_tag('div', array('class' => 'buttons')); @@ -62,19 +62,14 @@ $html .= $OUTPUT->single_button(new moodle_url('/mod/customcert/edit.php', array get_string('cancel'), 'get', array('class' => 'cancelbtn')); $html .= html_writer::end_tag('div'); -$style = 'height: ' . $page->height . 'mm; line-height: normal;'; -if ($page->margin) { - $style .= 'width: ' . ($page->width - $page->margin) . 'mm;'; - $style .= 'background-image: url(' . new moodle_url('/mod/customcert/pix/dash') . ');'; - $style .= 'background-repeat: repeat-y;'; - $style .= 'background-position-x: ' . ($page->width - $page->margin) . 'mm;'; - $style .= 'padding-right: ' . $page->margin . 'mm;'; -} else { - $style .= 'width: ' . $page->width . 'mm;'; -} - // Create the div that represents the PDF. +$style = 'height: ' . $page->height . 'mm; line-height: normal; width: ' . $page->width . 'mm;'; +$marginstyle = 'height: ' . $page->height . 'mm; width:1px; float:left; position:relative;'; $html .= html_writer::start_tag('div', array('id' => 'pdf', 'style' => $style)); +if ($page->leftmargin) { + $position = 'left:' . $page->leftmargin . 'mm;'; + $html .= "
"; +} if ($elements) { foreach ($elements as $element) { // Get an instance of the element class. @@ -94,6 +89,10 @@ if ($elements) { } } } +if ($page->rightmargin) { + $position = 'left:' . ($page->width - $page->rightmargin) . 'mm;'; + $html .= "
"; +} $html .= html_writer::end_tag('div'); echo $OUTPUT->header(); diff --git a/styles.css b/styles.css index c84261a..a893056 100644 --- a/styles.css +++ b/styles.css @@ -56,4 +56,12 @@ clear:both; border-style:solid; border-width:1px; -} \ No newline at end of file +} + +#page-mod-customcert-position div#leftmargin { + border-left: 1px dotted black; +} + +#page-mod-customcert-position div#rightmargin { + border-right: 1px dotted black; +} diff --git a/version.php b/version.php index 17e8634..c94ea2b 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2015120800; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015120801; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015051100; // Requires this Moodle version (2.9). $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_customcert'; diff --git a/yui/src/rearrange.js b/yui/src/rearrange.js index 773b0fa..279cb0c 100644 --- a/yui/src/rearrange.js +++ b/yui/src/rearrange.js @@ -8,6 +8,11 @@ M.mod_customcert.rearrange = { */ cmid : 0, + /** + * The customcert page we are displaying. + */ + page : Array(), + /** * The custom certificate elements to display. */ @@ -38,6 +43,17 @@ M.mod_customcert.rearrange = { */ elementxy : 0, + /** + * Store the left boundary of the pdf div. + */ + pdfleftboundary : 0, + + /** + * Store the right boundary of the pdf div. + */ + pdfrightboundary : 0, + + /** * The number of pixels in a mm. */ @@ -47,11 +63,15 @@ M.mod_customcert.rearrange = { * Initialise. * * @param Y + * @param cmid + * @param page * @param elements */ - init : function(Y, cmid, elements) { + init : function(Y, cmid, page, elements) { // Set the course module id. this.cmid = cmid; + // Set the page. + this.page = page; // Set the elements. this.elements = elements; @@ -61,6 +81,17 @@ M.mod_customcert.rearrange = { this.pdfwidth = parseFloat(Y.one('#pdf').getComputedStyle('width'), 10); this.pdfheight = parseFloat(Y.one('#pdf').getComputedStyle('height'), 10); + // Set the boundaries. + this.pdfleftboundary = this.pdfx; + if (this.page['leftmargin']) { + this.pdfleftboundary += parseInt(this.page['leftmargin'] * this.pixelsinmm); + } + + this.pdfrightboundary = this.pdfx + this.pdfwidth; + if (this.page['rightmargin']) { + this.pdfrightboundary -= parseInt(this.page['rightmargin'] * this.pixelsinmm); + } + this.set_data(Y); this.set_positions(Y); this.create_events(Y); @@ -248,7 +279,7 @@ M.mod_customcert.rearrange = { var bottom = top + nodeheight; // Check if it is out of bounds horizontally. - if ((left < this.pdfx) || (right > (this.pdfx + this.pdfwidth))) { + if ((left < this.pdfleftboundary) || (right > this.pdfrightboundary)) { return true; }