Merge branch 'MDL-31510_group_activities' of git://github.com/andyjdavis/moodle
[moodle.git] / mod / feedback / mapcourse.php
blob8014ca7d7dbe1b0aa1b55b7226d7bf37149fd91f
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 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 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
65 print_error('badcontext');
68 require_login($course, true, $cm);
70 require_capability('mod/feedback:mapcourse', $context);
72 if ($coursefilter) {
73 $map->feedbackid = $feedback->id;
74 $map->courseid = $coursefilter;
75 // insert a map only if it does exists yet
76 $sql = "SELECT id, feedbackid
77 FROM {feedback_sitecourse_map}
78 WHERE feedbackid = ? AND courseid = ?";
79 if (!$DB->get_records_sql($sql, array($map->feedbackid, $map->courseid))) {
80 $DB->insert_record('feedback_sitecourse_map', $map);
84 /// Print the page header
85 $strfeedbacks = get_string("modulenameplural", "feedback");
86 $strfeedback = get_string("modulename", "feedback");
88 $PAGE->set_heading(format_string($course->fullname));
89 $PAGE->set_title(format_string($feedback->name));
90 echo $OUTPUT->header();
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 ' ' . get_string('courses') . ': ';
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="'.$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="'.$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->define_columns( array('course'));
129 $table->define_headers( array(get_string('mappedcourses', 'feedback')));
131 $table->setup();
133 $unmapurl = new moodle_url('/mod/feedback/unmapcourse.php');
134 foreach ($coursemap as $cmap) {
135 $cmapcontext = get_context_instance(CONTEXT_COURSE, $cmap->id);
136 $cmapshortname = format_string($cmap->shortname, true, array('context' => $cmapcontext));
137 $coursecontext = get_context_instance(CONTEXT_COURSE, $cmap->courseid);
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 '<h3>'.get_string('mapcoursenone', 'feedback').'</h3>';
152 echo $OUTPUT->box_end();
154 echo $OUTPUT->footer();