2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
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
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
);
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);
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 if (!$context = get_context_instance(CONTEXT_MODULE
, $cm->id
)) {
56 print_error('badcontext');
59 require_login($course, true, $cm);
61 require_capability('mod/feedback:edititems', $context);
63 $mform = new mod_feedback_use_templ_form();
64 $newformdata = array('id'=>$id,
65 'templateid'=>$templateid,
67 'deleteolditems'=>'1',
69 $mform->set_data($newformdata);
70 $formdata = $mform->get_data();
72 if ($mform->is_cancelled()) {
73 redirect('edit.php?id='.$id.'&do_show=templates');
76 if (isset($formdata->confirmadd
) AND $formdata->confirmadd
== 1) {
77 feedback_items_from_template($feedback, $templateid, $deleteolditems);
78 redirect('edit.php?id=' . $id);
81 /// Print the page header
82 $strfeedbacks = get_string("modulenameplural", "feedback");
83 $strfeedback = get_string("modulename", "feedback");
85 $PAGE->navbar
->add($strfeedbacks, new moodle_url('/mod/feedback/index.php', array('id'=>$course->id
)));
86 $PAGE->navbar
->add(format_string($feedback->name
));
87 $PAGE->set_heading(format_string($course->fullname
));
88 $PAGE->set_title(format_string($feedback->name
));
89 echo $OUTPUT->header();
91 /// Print the main part of the page
92 ///////////////////////////////////////////////////////////////////////////
93 ///////////////////////////////////////////////////////////////////////////
94 ///////////////////////////////////////////////////////////////////////////
95 echo $OUTPUT->heading(format_text($feedback->name
));
97 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
98 echo $OUTPUT->heading(get_string('confirmusetemplate', 'feedback'));
102 echo $OUTPUT->box_end();
104 $templateitems = $DB->get_records('feedback_item', array('template'=>$templateid), 'position');
105 if (is_array($templateitems)) {
106 $templateitems = array_values($templateitems);
109 if (is_array($templateitems)) {
111 $align = right_to_left() ?
'right' : 'left';
112 echo $OUTPUT->box_start('feedback_items');
113 foreach ($templateitems as $templateitem) {
114 echo $OUTPUT->box_start('feedback_item_box_'.$align);
115 if ($templateitem->hasvalue
== 1 AND $feedback->autonumbering
) {
117 echo $OUTPUT->box_start('feedback_item_number_'.$align);
119 echo $OUTPUT->box_end();
121 echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
122 if ($templateitem->typ
!= 'pagebreak') {
123 // echo '<div class="feedback_item_'.$align.'">';
124 feedback_print_item_preview($templateitem);
126 echo $OUTPUT->box_start('feedback_pagebreak');
127 echo get_string('pagebreak', 'feedback').'<hr class="feedback_pagebreak" />';
128 echo $OUTPUT->box_end();
130 echo $OUTPUT->box_end();
131 echo $OUTPUT->box_end();
133 echo $OUTPUT->box_end();
135 echo $OUTPUT->box(get_string('no_items_available_at_this_template', 'feedback'),
136 'generalbox boxaligncenter boxwidthwide');
139 echo $OUTPUT->footer();