MDL-29189 course Minor fixups after code review
[moodle.git] / mod / feedback / mapcourse.php
CommitLineData
84973212 1<?php
2
c70ad9f7 3/**
84973212 4 * print the form to map courses for global feedbacks
5 *
6 * @author Andreas Grabs
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package feedback
9 */
10
11require_once("../../config.php");
12require_once("lib.php");
13require_once("$CFG->libdir/tablelib.php");
14
15$id = required_param('id', PARAM_INT); // Course Module ID, or
e3844271 16$searchcourse = optional_param('searchcourse', '', PARAM_NOTAGS);
84973212 17$coursefilter = optional_param('coursefilter', '', PARAM_INT);
18$courseid = optional_param('courseid', false, PARAM_INT);
19
a6855934 20$url = new moodle_url('/mod/feedback/mapcourse.php', array('id'=>$id));
84973212 21if ($searchcourse !== '') {
22 $url->param('searchcourse', $searchcourse);
23}
24if ($coursefilter !== '') {
25 $url->param('coursefilter', $coursefilter);
26}
27if ($courseid !== false) {
28 $url->param('courseid', $courseid);
29}
30$PAGE->set_url($url);
31
32if(($formdata = data_submitted()) AND !confirm_sesskey()) {
33 print_error('invalidsesskey');
34}
35
36// $SESSION->feedback->current_tab = 'mapcourse';
37$current_tab = 'mapcourse';
38
b6f26001
AG
39if (! $cm = get_coursemodule_from_id('feedback', $id)) {
40 print_error('invalidcoursemodule');
41}
42
43if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
44 print_error('coursemisconf');
45}
46
47if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
48 print_error('invalidcoursemodule');
84973212 49}
c987dbad
AG
50
51if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
52 print_error('badcontext');
53}
84973212 54
55require_login($course->id, true, $cm);
56
53ba55ec 57require_capability('mod/feedback:mapcourse', $context);
84973212 58
59if ($coursefilter) {
60 $map->feedbackid = $feedback->id;
61 $map->courseid = $coursefilter;
62 // insert a map only if it does exists yet
63 $sql = "SELECT id, feedbackid
64 FROM {feedback_sitecourse_map}
65 WHERE feedbackid = ? AND courseid = ?";
66 if (!$DB->get_records_sql($sql, array($map->feedbackid, $map->courseid))) {
67 $DB->insert_record('feedback_sitecourse_map', $map);
c70ad9f7 68 }
84973212 69}
70
71/// Print the page header
72$strfeedbacks = get_string("modulenameplural", "feedback");
73$strfeedback = get_string("modulename", "feedback");
74
9d092aa9 75$PAGE->set_heading(format_string($course->fullname));
84973212 76$PAGE->set_title(format_string($feedback->name));
84973212 77echo $OUTPUT->header();
78
79include('tabs.php');
80
81echo $OUTPUT->box(get_string('mapcourseinfo', 'feedback'), 'generalbox boxaligncenter boxwidthwide');
82echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
83echo '<form method="post">';
84echo '<input type="hidden" name="id" value="'.$id.'" />';
85echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
86
87$sql = "select c.id, c.shortname
88 from {course} c
0f1b6a5e
PS
89 where ".$DB->sql_like('c.shortname', '?', false)."
90 OR ".$DB->sql_like('c.fullname', '?', false);
84973212 91$params = array("%{$searchcourse}%", "%{$searchcourse}%");
92
93if (($courses = $DB->get_records_sql_menu($sql, $params)) && !empty($searchcourse)) {
94 echo ' ' . get_string('courses') . ': ';
93af06be 95 echo html_writer::select($courses, 'coursefilter', $coursefilter);
84973212 96 echo '<input type="submit" value="'.get_string('mapcourse', 'feedback').'"/>';
e8790d59 97 echo $OUTPUT->help_icon('mapcourses', 'feedback');
84973212 98 echo '<input type="button" value="'.get_string('searchagain').'" onclick="document.location=\'mapcourse.php?id='.$id.'\'"/>';
99 echo '<input type="hidden" name="searchcourse" value="'.$searchcourse.'"/>';
100 echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'"/>';
e8790d59 101 echo $OUTPUT->help_icon('searchcourses', 'feedback');
84973212 102} else {
103 echo '<input type="text" name="searchcourse" value="'.$searchcourse.'"/> <input type="submit" value="'.get_string('searchcourses').'"/>';
e8790d59 104 echo $OUTPUT->help_icon('searchcourses', 'feedback');
84973212 105}
106
107echo '</form>';
108
109if($coursemap = feedback_get_courses_from_sitecourse_map($feedback->id)) {
110 $table = new flexible_table('coursemaps');
111 $table->define_columns( array('course'));
112 $table->define_headers( array(get_string('mappedcourses', 'feedback')));
113
114 $table->setup();
115
5dee2210 116 $unmapurl = new moodle_url('/mod/feedback/unmapcourse.php');
84973212 117 foreach ($coursemap as $cmap) {
8ebbb06a 118 $cmapcontext = get_context_instance(CONTEXT_COURSE, $cmap->id);
eb38d45b 119 $cmapshortname = format_string($cmap->shortname, true, array('context' => $cmapcontext));
5dee2210 120 $unmapurl->params(array('id'=>$id, 'cmapid'=>$cmap->id));
8ebbb06a 121 $table->add_data(array('<a href="'.$unmapurl->out().'"><img src="'.$OUTPUT->pix_url('t/delete') . '" alt="Delete" /></a> ('.$cmapshortname.') '.$cmap->fullname));
c70ad9f7 122 }
d4b1d58c 123
84973212 124 $table->print_html();
125} else {
126 echo '<h3>'.get_string('mapcoursenone', 'feedback').'</h3>';
127}
d4b1d58c 128
129
84973212 130echo $OUTPUT->box_end();
d4b1d58c 131
84973212 132echo $OUTPUT->footer();
c70ad9f7 133