diff --git a/classes/load_template_form.php b/classes/load_template_form.php index bdf26f9..7bad0aa 100644 --- a/classes/load_template_form.php +++ b/classes/load_template_form.php @@ -38,15 +38,29 @@ class load_template_form extends \moodleform { $mform =& $this->_form; + // Get the context. + $context = $this->_customdata['context']; + $mform->addElement('header', 'loadtemplateheader', get_string('loadtemplate', 'customcert')); + // Display a link to the manage templates page. + if ($context->contextlevel != CONTEXT_SYSTEM && has_capability('mod/customcert:manage', \context_system::instance())) { + $link = \html_writer::link(new \moodle_url('/mod/customcert/manage_templates.php'), + get_string('managetemplates', 'customcert')); + $mform->addElement('static', 'managetemplates', '', $link); + } + $templates = $DB->get_records_menu('customcert_templates', array('contextid' => \context_system::instance()->id), 'name ASC', 'id, name'); - - $group = array(); - $group[] = $mform->createElement('select', 'ltid', '', $templates); - $group[] = $mform->createElement('submit', 'loadtemplatesubmit', get_string('load', 'customcert')); - $mform->addElement('group', 'loadtemplategroup', '', $group, '', false); - $mform->setType('ltid', PARAM_INT); + if ($templates) { + $group = array(); + $group[] = $mform->createElement('select', 'ltid', '', $templates); + $group[] = $mform->createElement('submit', 'loadtemplatesubmit', get_string('load', 'customcert')); + $mform->addElement('group', 'loadtemplategroup', '', $group, '', false); + $mform->setType('ltid', PARAM_INT); + } else { + $msg = \html_writer::tag('div', get_string('notemplates', 'customcert'), array('class' => 'alert')); + $mform->addElement('static', 'notemplates', '', $msg); + } } } diff --git a/edit.php b/edit.php index 248c21e..1293162 100644 --- a/edit.php +++ b/edit.php @@ -66,11 +66,6 @@ if ($context->contextlevel == CONTEXT_SYSTEM) { $PAGE->navbar->add(get_string('editcustomcert', 'customcert')); } -// The form for loading a customcert templates. -if ($tid && $DB->count_records('customcert_templates', array('contextid' => context_system::instance()->id)) > 0) { - $loadtemplateurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid)); - $loadtemplateform = new \mod_customcert\load_template_form($loadtemplateurl); -} // Flag to determine if we are deleting anything. $deleting = false; @@ -225,7 +220,9 @@ if ($data = $mform->get_data()) { echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('editcustomcert', 'customcert')); $mform->display(); -if (isset($loadtemplateform)) { +if ($tid) { + $loadtemplateurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid)); + $loadtemplateform = new \mod_customcert\load_template_form($loadtemplateurl, array('context' => $context)); $loadtemplateform->display(); } echo $OUTPUT->footer();