Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 * Manage customcert templates.
19
 *
20
 * @package    mod_customcert
21
 * @copyright  2016 Mark Nelson <markn@moodle.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require_once('../../config.php');
26
 
27
$contextid = optional_param('contextid', context_system::instance()->id, PARAM_INT);
28
$action = optional_param('action', '', PARAM_ALPHA);
29
$confirm = optional_param('confirm', 0, PARAM_INT);
30
$page = optional_param('page', 0, PARAM_INT);
31
$perpage = optional_param('perpage', 10, PARAM_INT);
32
 
33
if ($action) {
34
    $tid = required_param('tid', PARAM_INT);
35
} else {
36
    $tid = optional_param('tid', 0, PARAM_INT);
37
}
38
 
39
if ($tid) {
40
    $template = $DB->get_record('customcert_templates', ['id' => $tid], '*', MUST_EXIST);
41
    $template = new \mod_customcert\template($template);
42
}
43
 
44
$context = context::instance_by_id($contextid);
45
 
46
require_login();
47
require_capability('mod/customcert:manage', $context);
48
 
49
$title = $SITE->fullname;
50
 
51
// Set up the page.
52
$pageurl = new moodle_url('/mod/customcert/manage_templates.php');
53
\mod_customcert\page_helper::page_setup($pageurl, $context, $title);
54
 
55
// Additional page setup.
56
if ($tid && $action && confirm_sesskey()) {
57
    $PAGE->navbar->add(get_string('managetemplates', 'customcert'),
58
        new moodle_url('/mod/customcert/manage_templates.php'));
59
} else {
60
    $PAGE->navbar->add(get_string('managetemplates', 'customcert'));
61
}
62
 
63
if ($tid) {
64
    if ($action && confirm_sesskey()) {
65
        $nourl = new moodle_url('/mod/customcert/manage_templates.php');
66
        $yesurl = new moodle_url('/mod/customcert/manage_templates.php',
67
            [
68
                'tid' => $tid,
69
                'action' => $action,
70
                'confirm' => 1,
71
                'sesskey' => sesskey(),
72
            ]
73
        );
74
 
75
        // Check if we are deleting a template.
76
        if ($action == 'delete') {
77
            if (!$confirm) {
78
                // Show a confirmation page.
79
                $PAGE->navbar->add(get_string('deleteconfirm', 'customcert'));
80
                $message = get_string('deletetemplateconfirm', 'customcert');
81
                echo $OUTPUT->header();
82
                echo $OUTPUT->confirm($message, $yesurl, $nourl);
83
                echo $OUTPUT->footer();
84
                exit();
85
            }
86
 
87
            // Delete the template.
88
            $template->delete();
89
 
90
            // Redirect back to the manage templates page.
91
            redirect(new moodle_url('/mod/customcert/manage_templates.php'));
92
        } else if ($action == 'duplicate') {
93
            if (!$confirm) {
94
                // Show a confirmation page.
95
                $PAGE->navbar->add(get_string('duplicateconfirm', 'customcert'));
96
                $message = get_string('duplicatetemplateconfirm', 'customcert');
97
                echo $OUTPUT->header();
98
                echo $OUTPUT->confirm($message, $yesurl, $nourl);
99
                echo $OUTPUT->footer();
100
                exit();
101
            }
102
 
103
            // Create another template to copy the data to.
104
            $name = $template->get_name() . ' (' . strtolower(get_string('duplicate', 'customcert')) . ')';
105
            $newtemplate = \mod_customcert\template::create($name, $template->get_contextid());
106
 
107
            // Copy the data to the new template.
108
            $template->copy_to_template($newtemplate);
109
 
110
            // Redirect back to the manage templates page.
111
            redirect(new moodle_url('/mod/customcert/manage_templates.php'));
112
        }
113
    }
114
}
115
 
116
$table = new \mod_customcert\manage_templates_table($context);
117
$table->define_baseurl($pageurl);
118
 
119
echo $OUTPUT->header();
120
$table->out($perpage, false);
121
$url = new moodle_url('/mod/customcert/edit.php?contextid=' . $contextid);
122
echo $OUTPUT->single_button($url, get_string('createtemplate', 'customcert'), 'get');
123
echo $OUTPUT->footer();