Merge branch 'MDL-49032' of https://github.com/stronk7/moodle
[moodle.git] / mod / feedback / print.php
blobd5dfd8179130068fcb31e0ffde2d00bc4c818e37
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 a printview of feedback-items
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");
28 $id = required_param('id', PARAM_INT);
30 $PAGE->set_url('/mod/feedback/print.php', array('id'=>$id));
32 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
33 print_error('invalidcoursemodule');
36 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
37 print_error('coursemisconf');
40 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
41 print_error('invalidcoursemodule');
44 $context = context_module::instance($cm->id);
46 require_login($course, true, $cm);
48 require_capability('mod/feedback:view', $context);
49 $PAGE->set_pagelayout('embedded');
51 /// Print the page header
52 $strfeedbacks = get_string("modulenameplural", "feedback");
53 $strfeedback = get_string("modulename", "feedback");
55 $feedback_url = new moodle_url('/mod/feedback/index.php', array('id'=>$course->id));
56 $PAGE->navbar->add($strfeedbacks, $feedback_url);
57 $PAGE->navbar->add(format_string($feedback->name));
59 $PAGE->set_title($feedback->name);
60 $PAGE->set_heading($course->fullname);
61 echo $OUTPUT->header();
63 /// Print the main part of the page
64 ///////////////////////////////////////////////////////////////////////////
65 ///////////////////////////////////////////////////////////////////////////
66 ///////////////////////////////////////////////////////////////////////////
67 echo $OUTPUT->heading(format_text($feedback->name));
69 $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
70 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
71 echo $OUTPUT->continue_button('view.php?id='.$id);
72 if (is_array($feedbackitems)) {
73 $itemnr = 0;
74 $align = right_to_left() ? 'right' : 'left';
76 echo $OUTPUT->box_start('feedback_items printview');
77 //check, if there exists required-elements
78 $params = array('feedback'=>$feedback->id, 'required'=>1);
79 $countreq = $DB->count_records('feedback_item', $params);
80 if ($countreq > 0) {
81 echo '<div class="fdescription required">';
82 echo get_string('somefieldsrequired', 'form', '<img alt="'.get_string('requiredelement', 'form').
83 '" src="'.$OUTPUT->pix_url('req') .'" class="req" />');
84 echo '</div>';
86 //print the inserted items
87 $itempos = 0;
88 foreach ($feedbackitems as $feedbackitem) {
89 echo $OUTPUT->box_start('feedback_item_box_'.$align);
90 $itempos++;
91 //Items without value only are labels
92 if ($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
93 $itemnr++;
94 echo $OUTPUT->box_start('feedback_item_number_'.$align);
95 echo $itemnr;
96 echo $OUTPUT->box_end();
98 echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
99 if ($feedbackitem->typ != 'pagebreak') {
100 feedback_print_item_complete($feedbackitem, false, false);
101 } else {
102 echo $OUTPUT->box_start('feedback_pagebreak');
103 echo '<hr class="feedback_pagebreak" />';
104 echo $OUTPUT->box_end();
106 echo $OUTPUT->box_end();
107 echo $OUTPUT->box_end();
109 echo $OUTPUT->box_end();
110 } else {
111 echo $OUTPUT->box(get_string('no_items_available_yet', 'feedback'),
112 'generalbox boxaligncenter boxwidthwide');
114 echo $OUTPUT->continue_button('view.php?id='.$id);
115 echo $OUTPUT->box_end();
116 /// Finish the page
117 ///////////////////////////////////////////////////////////////////////////
118 ///////////////////////////////////////////////////////////////////////////
119 ///////////////////////////////////////////////////////////////////////////
121 echo $OUTPUT->footer();