MDL-48430 custom_menu: Malformed url in custom menu cannot break the platform
[moodle.git] / mod / feedback / mapcourse.php
blob1ea2d0d49610860a1f781785c0dd9202ea27767d
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 form to map courses for global feedbacks
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("$CFG->libdir/tablelib.php");
29 $id = required_param('id', PARAM_INT); // Course Module ID, or
30 $searchcourse = optional_param('searchcourse', '', PARAM_NOTAGS);
31 $coursefilter = optional_param('coursefilter', '', PARAM_INT);
32 $courseid = optional_param('courseid', false, PARAM_INT);
34 $url = new moodle_url('/mod/feedback/mapcourse.php', array('id'=>$id));
35 if ($searchcourse !== '') {
36 $url->param('searchcourse', $searchcourse);
38 if ($coursefilter !== '') {
39 $url->param('coursefilter', $coursefilter);
41 if ($courseid !== false) {
42 $url->param('courseid', $courseid);
44 $PAGE->set_url($url);
46 if (($formdata = data_submitted()) AND !confirm_sesskey()) {
47 print_error('invalidsesskey');
50 $current_tab = 'mapcourse';
52 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
53 print_error('invalidcoursemodule');
56 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
57 print_error('coursemisconf');
60 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
61 print_error('invalidcoursemodule');
64 $context = context_module::instance($cm->id);
66 require_login($course, true, $cm);
68 require_capability('mod/feedback:mapcourse', $context);
70 if ($coursefilter) {
71 $map = new stdClass;
72 $map->feedbackid = $feedback->id;
73 $map->courseid = $coursefilter;
74 // insert a map only if it does exists yet
75 $sql = "SELECT id, feedbackid
76 FROM {feedback_sitecourse_map}
77 WHERE feedbackid = ? AND courseid = ?";
78 if (!$DB->get_records_sql($sql, array($map->feedbackid, $map->courseid))) {
79 $DB->insert_record('feedback_sitecourse_map', $map);
83 /// Print the page header
84 $strfeedbacks = get_string("modulenameplural", "feedback");
85 $strfeedback = get_string("modulename", "feedback");
87 $PAGE->set_heading($course->fullname);
88 $PAGE->set_title($feedback->name);
89 echo $OUTPUT->header();
90 echo $OUTPUT->heading(format_string($feedback->name));
92 require('tabs.php');
94 echo $OUTPUT->box(get_string('mapcourseinfo', 'feedback'), 'generalbox boxaligncenter boxwidthwide');
95 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
96 echo '<form method="post">';
97 echo '<input type="hidden" name="id" value="'.$id.'" />';
98 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
100 $sql = "select c.id, c.shortname
101 from {course} c
102 where ".$DB->sql_like('c.shortname', '?', false)."
103 OR ".$DB->sql_like('c.fullname', '?', false);
104 $params = array("%{$searchcourse}%", "%{$searchcourse}%");
106 if (($courses = $DB->get_records_sql_menu($sql, $params)) && !empty($searchcourse)) {
107 echo ' '. html_writer::label(get_string('courses'), 'menucoursefilter', false). ': ';
108 echo html_writer::select($courses, 'coursefilter', $coursefilter);
109 echo '<input type="submit" value="'.get_string('mapcourse', 'feedback').'"/>';
110 echo $OUTPUT->help_icon('mapcourses', 'feedback');
111 echo '<input type="button" '.
112 'value="'.get_string('searchagain').'" '.
113 'onclick="document.location=\'mapcourse.php?id='.$id.'\'"/>';
115 echo '<input type="hidden" name="searchcourse" value="'.s($searchcourse).'"/>';
116 echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'"/>';
117 echo $OUTPUT->help_icon('searchcourses', 'feedback');
118 } else {
119 echo '<input type="text" name="searchcourse" value="'.s($searchcourse).'"/> ';
120 echo '<input type="submit" value="'.get_string('searchcourses').'"/>';
121 echo $OUTPUT->help_icon('searchcourses', 'feedback');
124 echo '</form>';
126 if ($coursemap = feedback_get_courses_from_sitecourse_map($feedback->id)) {
127 $table = new flexible_table('coursemaps');
128 $table->baseurl = $url;
129 $table->define_columns( array('course'));
130 $table->define_headers( array(get_string('mappedcourses', 'feedback')));
132 $table->setup();
134 $unmapurl = new moodle_url('/mod/feedback/unmapcourse.php');
135 foreach ($coursemap as $cmap) {
136 $coursecontext = context_course::instance($cmap->courseid);
137 $cmapshortname = format_string($cmap->shortname, true, array('context' => $coursecontext));
138 $cmapfullname = format_string($cmap->fullname, true, array('context' => $coursecontext));
139 $unmapurl->params(array('id'=>$id, 'cmapid'=>$cmap->id));
140 $anker = '<a href="'.$unmapurl->out().'">';
141 $anker .= '<img src="'.$OUTPUT->pix_url('t/delete').'" alt="Delete" />';
142 $anker .= '</a>';
143 $table->add_data(array($anker.' ('.$cmapshortname.') '.$cmapfullname));
146 $table->print_html();
147 } else {
148 echo $OUTPUT->heading(get_string('mapcoursenone', 'feedback'), 3);
152 echo $OUTPUT->box_end();
154 echo $OUTPUT->footer();