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