diff --git a/lang/en/customcert.php b/lang/en/customcert.php index f21ef32..484667f 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -86,6 +86,7 @@ $string['posx_help'] = 'This is the position in mm from the top left corner you $string['posy'] = 'Postion Y'; $string['posy_help'] = 'This is the position in mm from the top left corner you wish the element to display in the y direction.'; $string['receiveddate'] = 'Received date'; +$string['replacetemplate'] = 'Replace'; $string['report'] = 'Report'; $string['save'] = 'Save'; $string['savechangespreview'] = 'Save changes and preview'; diff --git a/save_template.php b/save_template.php index 2b720e6..d61dc36 100644 --- a/save_template.php +++ b/save_template.php @@ -41,12 +41,23 @@ require_capability('mod/customcert:manage', $context); // Store the current time in a variable. $time = time(); -// Create the template. -$template = new stdClass(); -$template->name = $name; -$template->timecreated = $time; +if (!$template = $DB->get_record('customcert_template', array('name' => $name))) { + // Create the template. + $template = new stdClass(); + $template->name = $name; + $template->timecreated = $time; +} + $template->timemodified = $time; -$template->id = $DB->insert_record('customcert_template', $template); + +if (empty($template->id)) { + $template->id = $DB->insert_record('customcert_template', $template); +} else { + $DB->update_record('customcert_template', $template); + $templatepages = $DB->get_records_menu('customcert_template_pages', array('templateid' => $template->id)); + $DB->delete_records_list('customcert_template_elements', 'templatepageid', array_keys($templatepages)); + $DB->delete_records('customcert_template_pages', array('templateid' => $template->id)); +} // Get the pages of the customcert we are copying. if ($pages = $DB->get_records('customcert_pages', array('customcertid' => $customcert->id))) { diff --git a/save_template_form.php b/save_template_form.php index ca75190..2127e20 100644 --- a/save_template_form.php +++ b/save_template_form.php @@ -38,6 +38,7 @@ class mod_customcert_save_template_form extends moodleform { $group = array(); $group[] = $mform->createElement('text', 'name'); $group[] = $mform->createElement('submit', 'savetemplatesubmit', get_string('save', 'customcert')); + $group[] = $mform->createElement('checkbox', 'replace', null, get_string('replacetemplate', 'customcert')); $mform->addElement('group', 'savetemplategroup', get_string('templatename', 'customcert'), $group, '', false); @@ -66,9 +67,11 @@ class mod_customcert_save_template_form extends moodleform { $errors = parent::validation($data, $files); - // Ensure the name does not already exist. - if ($DB->record_exists('customcert_template', array('name' => $data['name']))) { - $errors['savetemplategroup'] = get_string('templatenameexists', 'customcert'); + if (empty($data['replace'])) { + // Ensure the name does not already exist. + if ($DB->record_exists('customcert_template', array('name' => $data['name']))) { + $errors['savetemplategroup'] = get_string('templatenameexists', 'customcert'); + } } return $errors; diff --git a/styles.css b/styles.css index e054eb3..13edcb2 100644 --- a/styles.css +++ b/styles.css @@ -2,6 +2,10 @@ text-align:right; } +#page-mod-customcert-edit #id_replace { + margin-left: 10px; +} + #page-mod-customcert-report .centre { margin-left: auto; margin-right: auto;