1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of the customcert module for Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* This file contains the form for loading customcert templates.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_customcert
|
|
|
21 |
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
namespace mod_customcert;
|
|
|
26 |
|
|
|
27 |
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
|
|
28 |
|
|
|
29 |
require_once($CFG->libdir . '/formslib.php');
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* The form for loading customcert templates.
|
|
|
33 |
*
|
|
|
34 |
* @package mod_customcert
|
|
|
35 |
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
|
36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
37 |
*/
|
|
|
38 |
class load_template_form extends \moodleform {
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Form definition.
|
|
|
42 |
*/
|
|
|
43 |
public function definition() {
|
|
|
44 |
global $DB;
|
|
|
45 |
|
|
|
46 |
$mform =& $this->_form;
|
|
|
47 |
|
|
|
48 |
// Get the context.
|
|
|
49 |
$context = $this->_customdata['context'];
|
|
|
50 |
$syscontext = \context_system::instance();
|
|
|
51 |
|
|
|
52 |
$mform->addElement('header', 'loadtemplateheader', get_string('loadtemplate', 'customcert'));
|
|
|
53 |
|
|
|
54 |
// Display a link to the manage templates page.
|
|
|
55 |
if ($context->contextlevel != CONTEXT_SYSTEM && has_capability('mod/customcert:manage', $syscontext)) {
|
|
|
56 |
$link = \html_writer::link(new \moodle_url('/mod/customcert/manage_templates.php'),
|
|
|
57 |
get_string('managetemplates', 'customcert'));
|
|
|
58 |
$mform->addElement('static', 'managetemplates', '', $link);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
$arrtemplates = $DB->get_records_menu('customcert_templates', ['contextid' => $syscontext->id], 'name ASC', 'id, name');
|
|
|
62 |
if ($arrtemplates) {
|
|
|
63 |
$templates = [];
|
|
|
64 |
foreach ($arrtemplates as $key => $template) {
|
|
|
65 |
$templates[$key] = format_string($template, true, ['context' => $context]);
|
|
|
66 |
}
|
|
|
67 |
$group = [];
|
|
|
68 |
$group[] = $mform->createElement('select', 'ltid', '', $templates);
|
|
|
69 |
$group[] = $mform->createElement('submit', 'loadtemplatesubmit', get_string('load', 'customcert'));
|
|
|
70 |
$mform->addElement('group', 'loadtemplategroup', '', $group, '', false);
|
|
|
71 |
$mform->setType('ltid', PARAM_INT);
|
|
|
72 |
} else {
|
|
|
73 |
$msg = \html_writer::tag('div', get_string('notemplates', 'customcert'), ['class' => 'alert']);
|
|
|
74 |
$mform->addElement('static', 'notemplates', '', $msg);
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
}
|