MDL-14493 First checkin of Feedback module into HEAD.
[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");
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
20 if(($formdata = data_submitted('nomatch')) AND !confirm_sesskey()) {
21 error('no sesskey defined');
22 }
23
24 // $SESSION->feedback->current_tab = 'mapcourse';
25 $current_tab = 'mapcourse';
26
27 if ($id) {
28 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
29 error("Course Module ID was incorrect");
30 }
31
32 if (! $course = get_record("course", "id", $cm->course)) {
33 error("Course is misconfigured");
34 }
35
36 if (! $feedback = get_record("feedback", "id", $cm->instance)) {
37 error("Course module is incorrect");
38 }
39 }
40 $capabilities = feedback_load_capabilities($cm->id);
41
42 require_login($course->id);
43
44 if (!$capabilities->mapcourse) {
45 error ('access not allowed');
46 }
47
48 if ($coursefilter) {
49 $map->feedbackid = $feedback->id;
50 $map->courseid = $coursefilter;
51 // insert a map only if it does exists yet
52 $sql = "select id, feedbackid from {$CFG->prefix}feedback_sitecourse_map where feedbackid = $map->feedbackid and courseid = $map->courseid";
53 if (!get_records_sql($sql) && !insert_record('feedback_sitecourse_map', $map)) {
54 error("Database problem, unable to map feedback = $feedback->id to course = $course->id");
55 }
56 }
57
58 /// Print the page header
59 // $strfeedbacks = get_string("modulenameplural", "feedback");
60 // $strfeedback = get_string("modulename", "feedback");
61 // $navigation = '';
62
63 // $feedbackindex = '<a href="'.htmlspecialchars('index.php?id='.$course->id).'">'.$strfeedbacks.'</a> ->';
64 // if ($course->category) {
65 // $navigation = '<a href="'.htmlspecialchars('../../course/view.php?id='.$course->id).'">'.$course->shortname.'</a> ->';
66 // }else if ($courseid > 0 AND $courseid != SITEID) {
67 // $usercourse = get_record('course', 'id', $courseid);
68 // $navigation = '<a href="'.htmlspecialchars('../../course/view.php?id='.$usercourse->id).'">'.$usercourse->shortname.'</a> ->';
69 // $feedbackindex = '';
70 // }
71
72 // print_header($course->shortname.': '.$feedback->name, $course->fullname,
73 // $navigation.' '.$feedbackindex.' <a href="'.htmlspecialchars('view.php?id='.$id).'">'.$feedback->name.'</a> -> '.get_string('mapcourses', 'feedback'),
74 // '', '', true, update_module_button($cm->id, $course->id, $strfeedback), navmenu($course, $cm));
75 /// Print the page header
76 $strfeedbacks = get_string("modulenameplural", "feedback");
77 $strfeedback = get_string("modulename", "feedback");
78 $buttontext = update_module_button($cm->id, $course->id, $strfeedback);
79
80 $navlinks = array();
81 $navlinks[] = array('name' => $strfeedbacks, 'link' => "index.php?id=$course->id", 'type' => 'activity');
82 $navlinks[] = array('name' => format_string($feedback->name), 'link' => "", 'type' => 'activityinstance');
83
84 $navigation = build_navigation($navlinks);
85
86 print_header_simple(format_string($feedback->name), "",
87 $navigation, "", "", true, $buttontext, navmenu($course, $cm));
88
89 include('tabs.php');
90
91 // print_simple_box(get_string('mapcourseinfo', 'feedback'), 'center', '80%');
92 print_box(get_string('mapcourseinfo', 'feedback'), 'generalbox boxaligncenter boxwidthwide');
93 // print_simple_box_start('center', '70%');
94 print_box_start('generalbox boxaligncenter boxwidthwide');
95 echo '<form method="post">';
96 echo '<input type="hidden" name="id" value="'.$id.'" />';
97 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
98
99 $sql = "select c.id, c.shortname from {$CFG->prefix}course c
100 where
101 c.shortname ".sql_ilike()." '%{$searchcourse}%'
102 OR c.fullname ".sql_ilike()." '%{$searchcourse}%'";
103
104 if (($courses = get_records_sql_menu($sql)) && !empty($searchcourse)) {
105 echo ' ' . get_string('courses') . ': ';
106 choose_from_menu ($courses, 'coursefilter', $coursefilter, 'choose');
107 echo '<input type="submit" value="'.get_string('mapcourse', 'feedback').'"/>';
108 helpbutton('mapcourses', '', 'feedback', true, true);
109 echo '<input type="button" value="'.get_string('searchagain').'" onclick="document.location=\'mapcourse.php?id='.$id.'\'"/>';
110 echo '<input type="hidden" name="searchcourse" value="'.$searchcourse.'"/>';
111 echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'"/>';
112 helpbutton('searchcourses', '', 'feedback', true, true);
113 } else {
114 echo '<input type="text" name="searchcourse" value="'.$searchcourse.'"/> <input type="submit" value="'.get_string('searchcourses').'"/>';
115 helpbutton('searchcourses', '', 'feedback', true, true);
116 }
117
118 echo '</form>';
119
120 if($coursemap = feedback_get_courses_from_sitecourse_map($feedback->id)) {
121 $table = new flexible_table('coursemaps');
122 $table->define_columns( array('course'));
123 $table->define_headers( array(get_string('mappedcourses', 'feedback')));
124
125 $table->setup();
126
127 foreach ($coursemap as $cmap) {
128 $table->add_data(array('<a href="'.htmlspecialchars('unmapcourse.php?id='.$id.'&cmapid='.$cmap->id).'"><img src="'.$CFG->pixpath.'/t/delete.gif" alt="Delete" /></a> ('.$cmap->shortname.') '.$cmap->fullname));
129 }
130
131 $table->print_html();
132 } else {
133 echo '<h3>'.get_string('mapcoursenone', 'feedback').'</h3>';
134 }
135
136
137 // print_simple_box_end();
138 print_box_end();
139
140 print_footer($course);
141
142?>