Merge branch 'MDL-51292-master' of git://github.com/cameron1729/moodle
[moodle.git] / mod / feedback / use_templ.php
blob073b783a62100ce15605036ec094808a52b14edd
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);
31 $deleteolditems = optional_param('deleteolditems', 0, PARAM_INT);
33 if (!$templateid) {
34 redirect('edit.php?id='.$id);
37 $url = new moodle_url('/mod/feedback/use_templ.php', array('id'=>$id, 'templateid'=>$templateid));
38 if ($deleteolditems !== 0) {
39 $url->param('deleteolditems', $deleteolditems);
41 $PAGE->set_url($url);
43 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
44 print_error('invalidcoursemodule');
47 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
48 print_error('coursemisconf');
51 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
52 print_error('invalidcoursemodule');
55 $context = context_module::instance($cm->id);
57 require_login($course, true, $cm);
59 require_capability('mod/feedback:edititems', $context);
61 $mform = new mod_feedback_use_templ_form();
62 $newformdata = array('id'=>$id,
63 'templateid'=>$templateid,
64 'confirmadd'=>'1',
65 'deleteolditems'=>'1',
66 'do_show'=>'edit');
67 $mform->set_data($newformdata);
68 $formdata = $mform->get_data();
70 if ($mform->is_cancelled()) {
71 redirect('edit.php?id='.$id.'&do_show=templates');
74 if (isset($formdata->confirmadd) AND $formdata->confirmadd == 1) {
75 feedback_items_from_template($feedback, $templateid, $deleteolditems);
76 redirect('edit.php?id=' . $id);
79 /// Print the page header
80 $strfeedbacks = get_string("modulenameplural", "feedback");
81 $strfeedback = get_string("modulename", "feedback");
83 $PAGE->navbar->add($strfeedbacks, new moodle_url('/mod/feedback/index.php', array('id'=>$course->id)));
84 $PAGE->navbar->add(format_string($feedback->name));
85 $PAGE->set_heading($course->fullname);
86 $PAGE->set_title($feedback->name);
87 echo $OUTPUT->header();
89 /// Print the main part of the page
90 ///////////////////////////////////////////////////////////////////////////
91 ///////////////////////////////////////////////////////////////////////////
92 ///////////////////////////////////////////////////////////////////////////
93 echo $OUTPUT->heading(format_string($feedback->name));
95 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
96 echo $OUTPUT->heading(get_string('confirmusetemplate', 'feedback'), 3);
98 $mform->display();
100 echo $OUTPUT->box_end();
102 $templateitems = $DB->get_records('feedback_item', array('template'=>$templateid), 'position');
103 if (is_array($templateitems)) {
104 $templateitems = array_values($templateitems);
107 if (is_array($templateitems)) {
108 $itemnr = 0;
109 $align = right_to_left() ? 'right' : 'left';
110 echo $OUTPUT->box_start('feedback_items');
111 foreach ($templateitems as $templateitem) {
112 echo $OUTPUT->box_start('feedback_item_box_'.$align);
113 if ($templateitem->hasvalue == 1 AND $feedback->autonumbering) {
114 $itemnr++;
115 echo $OUTPUT->box_start('feedback_item_number_'.$align);
116 echo $itemnr;
117 echo $OUTPUT->box_end();
119 echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
120 if ($templateitem->typ != 'pagebreak') {
121 // echo '<div class="feedback_item_'.$align.'">';
122 feedback_print_item_preview($templateitem);
123 } else {
124 echo $OUTPUT->box_start('feedback_pagebreak');
125 echo get_string('pagebreak', 'feedback').'<hr class="feedback_pagebreak" />';
126 echo $OUTPUT->box_end();
128 echo $OUTPUT->box_end();
129 echo $OUTPUT->box_end();
131 echo $OUTPUT->box_end();
132 } else {
133 echo $OUTPUT->box(get_string('no_items_available_at_this_template', 'feedback'),
134 'generalbox boxaligncenter boxwidthwide');
137 echo $OUTPUT->footer();