MDL-21845 user profile: Fixed missing multilang support
[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
16$searchcourse = optional_param('searchcourse', '', PARAM_ALPHANUM);
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
39if ($id) {
40 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
41 print_error('invalidcoursemodule');
c70ad9f7 42 }
d4b1d58c 43
84973212 44 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
45 print_error('coursemisconf');
c70ad9f7 46 }
d4b1d58c 47
84973212 48 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
49 print_error('invalidcoursemodule');
c70ad9f7 50 }
84973212 51}
52$capabilities = feedback_load_capabilities($cm->id);
53
54require_login($course->id, true, $cm);
55
56if (!$capabilities->mapcourse) {
57 print_error('invalidaccess');
58}
59
60if ($coursefilter) {
61 $map->feedbackid = $feedback->id;
62 $map->courseid = $coursefilter;
63 // insert a map only if it does exists yet
64 $sql = "SELECT id, feedbackid
65 FROM {feedback_sitecourse_map}
66 WHERE feedbackid = ? AND courseid = ?";
67 if (!$DB->get_records_sql($sql, array($map->feedbackid, $map->courseid))) {
68 $DB->insert_record('feedback_sitecourse_map', $map);
c70ad9f7 69 }
84973212 70}
71
72/// Print the page header
73$strfeedbacks = get_string("modulenameplural", "feedback");
74$strfeedback = get_string("modulename", "feedback");
75
a6855934 76$PAGE->navbar->add($strfeedbacks, new moodle_url('/mod/feedback/index.php', array('id'=>$course->id)));
84973212 77$PAGE->navbar->add(format_string($feedback->name));
78
79$PAGE->set_title(format_string($feedback->name));
84973212 80echo $OUTPUT->header();
81
82include('tabs.php');
83
84echo $OUTPUT->box(get_string('mapcourseinfo', 'feedback'), 'generalbox boxaligncenter boxwidthwide');
85echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
86echo '<form method="post">';
87echo '<input type="hidden" name="id" value="'.$id.'" />';
88echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
89
90$sql = "select c.id, c.shortname
91 from {course} c
92 where c.shortname ".$DB->sql_ilike()." ?
93 OR c.fullname ".$DB->sql_ilike()." ?";
94$params = array("%{$searchcourse}%", "%{$searchcourse}%");
95
96if (($courses = $DB->get_records_sql_menu($sql, $params)) && !empty($searchcourse)) {
97 echo ' ' . get_string('courses') . ': ';
93af06be 98 echo html_writer::select($courses, 'coursefilter', $coursefilter);
84973212 99 echo '<input type="submit" value="'.get_string('mapcourse', 'feedback').'"/>';
4bcc5118 100 echo $OUTPUT->help_icon('mapcourses', '', 'feedback', true);
84973212 101 echo '<input type="button" value="'.get_string('searchagain').'" onclick="document.location=\'mapcourse.php?id='.$id.'\'"/>';
102 echo '<input type="hidden" name="searchcourse" value="'.$searchcourse.'"/>';
103 echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'"/>';
4bcc5118 104 echo $OUTPUT->help_icon('searchcourses', '', 'feedback', true);
84973212 105} else {
106 echo '<input type="text" name="searchcourse" value="'.$searchcourse.'"/> <input type="submit" value="'.get_string('searchcourses').'"/>';
4bcc5118 107 echo $OUTPUT->help_icon('searchcourses', '', 'feedback', true);
84973212 108}
109
110echo '</form>';
111
112if($coursemap = feedback_get_courses_from_sitecourse_map($feedback->id)) {
113 $table = new flexible_table('coursemaps');
114 $table->define_columns( array('course'));
115 $table->define_headers( array(get_string('mappedcourses', 'feedback')));
116
117 $table->setup();
118
5dee2210 119 $unmapurl = new moodle_url('/mod/feedback/unmapcourse.php');
84973212 120 foreach ($coursemap as $cmap) {
5dee2210
AG
121 $unmapurl->params(array('id'=>$id, 'cmapid'=>$cmap->id));
122 $table->add_data(array('<a href="'.$unmapurl->out().'"><img src="'.$OUTPUT->pix_url('t/delete') . '" alt="Delete" /></a> ('.$cmap->shortname.') '.$cmap->fullname));
c70ad9f7 123 }
d4b1d58c 124
84973212 125 $table->print_html();
126} else {
127 echo '<h3>'.get_string('mapcoursenone', 'feedback').'</h3>';
128}
d4b1d58c 129
130
84973212 131echo $OUTPUT->box_end();
d4b1d58c 132
84973212 133echo $OUTPUT->footer();
c70ad9f7 134