MDL-19806 Converted print_box* to $OUTPUT->box*
[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
294ce987 20 if(($formdata = data_submitted()) AND !confirm_sesskey()) {
5d2edd1c 21 print_error('invalidsesskey');
c70ad9f7 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)) {
5d2edd1c 29 print_error('invalidcoursemodule');
c70ad9f7 30 }
31
0085fff8 32 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
5d2edd1c 33 print_error('coursemisconf');
c70ad9f7 34 }
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);
41
6178c62a 42 require_login($course->id, true, $cm);
c70ad9f7 43
44 if (!$capabilities->mapcourse) {
b149ffb4 45 print_error('invalidaccess');
c70ad9f7 46 }
47
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 }
59
60 /// Print the page header
61 // $strfeedbacks = get_string("modulenameplural", "feedback");
62 // $strfeedback = get_string("modulename", "feedback");
63 // $navigation = '';
64
65 // $feedbackindex = '<a href="'.htmlspecialchars('index.php?id='.$course->id).'">'.$strfeedbacks.'</a> ->';
66 // if ($course->category) {
67 // $navigation = '<a href="'.htmlspecialchars('../../course/view.php?id='.$course->id).'">'.$course->shortname.'</a> ->';
68 // }else if ($courseid > 0 AND $courseid != SITEID) {
0085fff8 69 // $usercourse = $DB->get_record('course', array('id'=>$courseid));
c70ad9f7 70 // $navigation = '<a href="'.htmlspecialchars('../../course/view.php?id='.$usercourse->id).'">'.$usercourse->shortname.'</a> ->';
71 // $feedbackindex = '';
72 // }
73
74 // print_header($course->shortname.': '.$feedback->name, $course->fullname,
75 // $navigation.' '.$feedbackindex.' <a href="'.htmlspecialchars('view.php?id='.$id).'">'.$feedback->name.'</a> -> '.get_string('mapcourses', 'feedback'),
76 // '', '', true, update_module_button($cm->id, $course->id, $strfeedback), navmenu($course, $cm));
77 /// Print the page header
78 $strfeedbacks = get_string("modulenameplural", "feedback");
79 $strfeedback = get_string("modulename", "feedback");
80 $buttontext = update_module_button($cm->id, $course->id, $strfeedback);
81
82 $navlinks = array();
83 $navlinks[] = array('name' => $strfeedbacks, 'link' => "index.php?id=$course->id", 'type' => 'activity');
84 $navlinks[] = array('name' => format_string($feedback->name), 'link' => "", 'type' => 'activityinstance');
85
86 $navigation = build_navigation($navlinks);
87
88 print_header_simple(format_string($feedback->name), "",
89 $navigation, "", "", true, $buttontext, navmenu($course, $cm));
90
91 include('tabs.php');
92
93 // print_simple_box(get_string('mapcourseinfo', 'feedback'), 'center', '80%');
94 print_box(get_string('mapcourseinfo', 'feedback'), 'generalbox boxaligncenter boxwidthwide');
95 // print_simple_box_start('center', '70%');
96 print_box_start('generalbox boxaligncenter boxwidthwide');
97 echo '<form method="post">';
98 echo '<input type="hidden" name="id" value="'.$id.'" />';
d4a1fcaf 99 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
c70ad9f7 100
c6307ef2 101 $sql = "select c.id, c.shortname
102 from {course} c
103 where c.shortname ".$DB->sql_ilike()." ?
104 OR c.fullname ".$DB->sql_ilike()." ?";
105 $params = array("%{$searchcourse}%", "%{$searchcourse}%");
c70ad9f7 106
c6307ef2 107 if (($courses = $DB->get_records_sql_menu($sql, $params)) && !empty($searchcourse)) {
c70ad9f7 108 echo ' ' . get_string('courses') . ': ';
109 choose_from_menu ($courses, 'coursefilter', $coursefilter, 'choose');
110 echo '<input type="submit" value="'.get_string('mapcourse', 'feedback').'"/>';
111 helpbutton('mapcourses', '', 'feedback', true, true);
112 echo '<input type="button" value="'.get_string('searchagain').'" onclick="document.location=\'mapcourse.php?id='.$id.'\'"/>';
113 echo '<input type="hidden" name="searchcourse" value="'.$searchcourse.'"/>';
114 echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'"/>';
115 helpbutton('searchcourses', '', 'feedback', true, true);
116 } else {
117 echo '<input type="text" name="searchcourse" value="'.$searchcourse.'"/> <input type="submit" value="'.get_string('searchcourses').'"/>';
118 helpbutton('searchcourses', '', 'feedback', true, true);
119 }
120
121 echo '</form>';
122
123 if($coursemap = feedback_get_courses_from_sitecourse_map($feedback->id)) {
124 $table = new flexible_table('coursemaps');
125 $table->define_columns( array('course'));
126 $table->define_headers( array(get_string('mappedcourses', 'feedback')));
127
128 $table->setup();
129
130 foreach ($coursemap as $cmap) {
f2a1963c 131 $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 132 }
133
134 $table->print_html();
135 } else {
136 echo '<h3>'.get_string('mapcoursenone', 'feedback').'</h3>';
137 }
138
139
140 // print_simple_box_end();
141 print_box_end();
142
c6ea0876 143 echo $OUTPUT->footer();
c70ad9f7 144
5d2edd1c 145?>