mod-data MDL-19806 Added set_url calls, replaced deprecated functions, and added...
[moodle.git] / mod / feedback / mapcourse.php
CommitLineData
c70ad9f7 1<?php // $Id$
2/**
3* print the form to map courses for global feedbacks
4*
5* @version $Id$
6* @author Andreas Grabs
7* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8* @package feedback
9*/
10
11 require_once("../../config.php");
12 require_once("lib.php");
13 require_once("$CFG->libdir/tablelib.php");
d4b1d58c 14
c70ad9f7 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);
d4b1d58c 19
294ce987 20 if(($formdata = data_submitted()) AND !confirm_sesskey()) {
5d2edd1c 21 print_error('invalidsesskey');
c70ad9f7 22 }
d4b1d58c 23
c70ad9f7 24 // $SESSION->feedback->current_tab = 'mapcourse';
25 $current_tab = 'mapcourse';
d4b1d58c 26
c70ad9f7 27 if ($id) {
28 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
5d2edd1c 29 print_error('invalidcoursemodule');
c70ad9f7 30 }
d4b1d58c 31
0085fff8 32 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
5d2edd1c 33 print_error('coursemisconf');
c70ad9f7 34 }
d4b1d58c 35
0085fff8 36 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
5d2edd1c 37 print_error('invalidcoursemodule');
c70ad9f7 38 }
39 }
40 $capabilities = feedback_load_capabilities($cm->id);
d4b1d58c 41
6178c62a 42 require_login($course->id, true, $cm);
d4b1d58c 43
c70ad9f7 44 if (!$capabilities->mapcourse) {
b149ffb4 45 print_error('invalidaccess');
c70ad9f7 46 }
d4b1d58c 47
c70ad9f7 48 if ($coursefilter) {
49 $map->feedbackid = $feedback->id;
50 $map->courseid = $coursefilter;
51 // insert a map only if it does exists yet
0085fff8 52 $sql = "SELECT id, feedbackid
53 FROM {feedback_sitecourse_map}
54 WHERE feedbackid = ? AND courseid = ?";
fc29e51b 55 if (!$DB->get_records_sql($sql, array($map->feedbackid, $map->courseid))) {
56 $DB->insert_record('feedback_sitecourse_map', $map);
c70ad9f7 57 }
58 }
d4b1d58c 59
c70ad9f7 60 /// Print the page header
61 $strfeedbacks = get_string("modulenameplural", "feedback");
62 $strfeedback = get_string("modulename", "feedback");
63 $buttontext = update_module_button($cm->id, $course->id, $strfeedback);
d4b1d58c 64
84f797db 65 $PAGE->navbar->add($strfeedbacks, new moodle_url($CFG->wwwroot.'/mod/feedback/index.php', array('id'=>$course->id)));
66 $PAGE->navbar->add(format_string($feedback->name));
d4b1d58c 67
84f797db 68 $PAGE->set_title(format_string($feedback->name));
69 $PAGE->set_button($buttontext);
70 echo $OUTPUT->header();
c70ad9f7 71
72 include('tabs.php');
73
d4b1d58c 74 echo $OUTPUT->box(get_string('mapcourseinfo', 'feedback'), 'generalbox boxaligncenter boxwidthwide');
d4b1d58c 75 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
c70ad9f7 76 echo '<form method="post">';
77 echo '<input type="hidden" name="id" value="'.$id.'" />';
d4a1fcaf 78 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
d4b1d58c 79
c6307ef2 80 $sql = "select c.id, c.shortname
81 from {course} c
82 where c.shortname ".$DB->sql_ilike()." ?
83 OR c.fullname ".$DB->sql_ilike()." ?";
84 $params = array("%{$searchcourse}%", "%{$searchcourse}%");
d4b1d58c 85
c6307ef2 86 if (($courses = $DB->get_records_sql_menu($sql, $params)) && !empty($searchcourse)) {
c70ad9f7 87 echo ' ' . get_string('courses') . ': ';
17881fe2 88 echo $OUTPUT->select(html_select::make ($courses, 'coursefilter', $coursefilter));
c70ad9f7 89 echo '<input type="submit" value="'.get_string('mapcourse', 'feedback').'"/>';
9fad7b20 90 echo $OUTPUT->help_icon(moodle_help_icon::make('mapcourses', '', 'feedback', true));
c70ad9f7 91 echo '<input type="button" value="'.get_string('searchagain').'" onclick="document.location=\'mapcourse.php?id='.$id.'\'"/>';
92 echo '<input type="hidden" name="searchcourse" value="'.$searchcourse.'"/>';
93 echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'"/>';
9fad7b20 94 echo $OUTPUT->help_icon(moodle_help_icon::make('searchcourses', '', 'feedback', true));
c70ad9f7 95 } else {
96 echo '<input type="text" name="searchcourse" value="'.$searchcourse.'"/> <input type="submit" value="'.get_string('searchcourses').'"/>';
9fad7b20 97 echo $OUTPUT->help_icon(moodle_help_icon::make('searchcourses', '', 'feedback', true));
c70ad9f7 98 }
d4b1d58c 99
c70ad9f7 100 echo '</form>';
d4b1d58c 101
c70ad9f7 102 if($coursemap = feedback_get_courses_from_sitecourse_map($feedback->id)) {
103 $table = new flexible_table('coursemaps');
104 $table->define_columns( array('course'));
105 $table->define_headers( array(get_string('mappedcourses', 'feedback')));
d4b1d58c 106
c70ad9f7 107 $table->setup();
d4b1d58c 108
c70ad9f7 109 foreach ($coursemap as $cmap) {
f2a1963c 110 $table->add_data(array('<a href="'.htmlspecialchars('unmapcourse.php?id='.$id.'&cmapid='.$cmap->id).'"><img src="'.$OUTPUT->old_icon_url('t/delete') . '" alt="Delete" /></a> ('.$cmap->shortname.') '.$cmap->fullname));
c70ad9f7 111 }
d4b1d58c 112
c70ad9f7 113 $table->print_html();
114 } else {
115 echo '<h3>'.get_string('mapcoursenone', 'feedback').'</h3>';
116 }
d4b1d58c 117
118
d4b1d58c 119 echo $OUTPUT->box_end();
120
c6ea0876 121 echo $OUTPUT->footer();
c70ad9f7 122
5d2edd1c 123?>