Merge branch 'MDL-54741-master' of git://github.com/mihailges/moodle
[moodle.git] / mod / feedback / use_templ.php
blob3fb38f8361a679de2879e698ba8a3f07fd3cc8f4
1 <?php
2 // This file is part of 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.
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/>.
17 /**
18 * print the confirm dialog to use template and create new items from template
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package mod_feedback
25 require_once("../../config.php");
26 require_once("lib.php");
27 require_once('use_templ_form.php');
29 $id = required_param('id', PARAM_INT);
30 $templateid = optional_param('templateid', false, PARAM_INT);
32 if (!$templateid) {
33 redirect('edit.php?id='.$id);
36 $url = new moodle_url('/mod/feedback/use_templ.php', array('id'=>$id, 'templateid'=>$templateid));
37 $PAGE->set_url($url);
39 list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
40 $context = context_module::instance($cm->id);
42 require_login($course, true, $cm);
44 $feedback = $PAGE->activityrecord;
45 $feedbackstructure = new mod_feedback_structure($feedback, $cm, 0, $templateid);
47 require_capability('mod/feedback:edititems', $context);
49 $mform = new mod_feedback_use_templ_form();
50 $mform->set_data(array('id' => $id, 'templateid' => $templateid));
52 if ($mform->is_cancelled()) {
53 redirect('edit.php?id='.$id.'&do_show=templates');
54 } else if ($formdata = $mform->get_data()) {
55 feedback_items_from_template($feedback, $templateid, $formdata->deleteolditems);
56 redirect('edit.php?id=' . $id);
59 /// Print the page header
60 $strfeedbacks = get_string("modulenameplural", "feedback");
61 $strfeedback = get_string("modulename", "feedback");
63 navigation_node::override_active_url(new moodle_url('/mod/feedback/edit.php',
64 array('id' => $id, 'do_show' => 'templates')));
65 $PAGE->set_heading($course->fullname);
66 $PAGE->set_title($feedback->name);
67 echo $OUTPUT->header();
69 /// Print the main part of the page
70 ///////////////////////////////////////////////////////////////////////////
71 ///////////////////////////////////////////////////////////////////////////
72 ///////////////////////////////////////////////////////////////////////////
73 echo $OUTPUT->heading(format_string($feedback->name));
75 echo $OUTPUT->heading(get_string('confirmusetemplate', 'feedback'), 4);
77 $mform->display();
79 $form = new mod_feedback_complete_form(mod_feedback_complete_form::MODE_VIEW_TEMPLATE,
80 $feedbackstructure, 'feedback_preview_form', ['templateid' => $templateid]);
81 $form->display();
83 echo $OUTPUT->footer();