|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00025 require_once("../../config.php"); 00026 require_once("lib.php"); 00027 require_once("$CFG->libdir/tablelib.php"); 00028 00029 $id = required_param('id', PARAM_INT); // Course Module ID, or 00030 $searchcourse = optional_param('searchcourse', '', PARAM_NOTAGS); 00031 $coursefilter = optional_param('coursefilter', '', PARAM_INT); 00032 $courseid = optional_param('courseid', false, PARAM_INT); 00033 00034 $url = new moodle_url('/mod/feedback/mapcourse.php', array('id'=>$id)); 00035 if ($searchcourse !== '') { 00036 $url->param('searchcourse', $searchcourse); 00037 } 00038 if ($coursefilter !== '') { 00039 $url->param('coursefilter', $coursefilter); 00040 } 00041 if ($courseid !== false) { 00042 $url->param('courseid', $courseid); 00043 } 00044 $PAGE->set_url($url); 00045 00046 if (($formdata = data_submitted()) AND !confirm_sesskey()) { 00047 print_error('invalidsesskey'); 00048 } 00049 00050 $current_tab = 'mapcourse'; 00051 00052 if (! $cm = get_coursemodule_from_id('feedback', $id)) { 00053 print_error('invalidcoursemodule'); 00054 } 00055 00056 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { 00057 print_error('coursemisconf'); 00058 } 00059 00060 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { 00061 print_error('invalidcoursemodule'); 00062 } 00063 00064 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) { 00065 print_error('badcontext'); 00066 } 00067 00068 require_login($course->id, true, $cm); 00069 00070 require_capability('mod/feedback:mapcourse', $context); 00071 00072 if ($coursefilter) { 00073 $map->feedbackid = $feedback->id; 00074 $map->courseid = $coursefilter; 00075 // insert a map only if it does exists yet 00076 $sql = "SELECT id, feedbackid 00077 FROM {feedback_sitecourse_map} 00078 WHERE feedbackid = ? AND courseid = ?"; 00079 if (!$DB->get_records_sql($sql, array($map->feedbackid, $map->courseid))) { 00080 $DB->insert_record('feedback_sitecourse_map', $map); 00081 } 00082 } 00083 00085 $strfeedbacks = get_string("modulenameplural", "feedback"); 00086 $strfeedback = get_string("modulename", "feedback"); 00087 00088 $PAGE->set_heading(format_string($course->fullname)); 00089 $PAGE->set_title(format_string($feedback->name)); 00090 echo $OUTPUT->header(); 00091 00092 require('tabs.php'); 00093 00094 echo $OUTPUT->box(get_string('mapcourseinfo', 'feedback'), 'generalbox boxaligncenter boxwidthwide'); 00095 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); 00096 echo '<form method="post">'; 00097 echo '<input type="hidden" name="id" value="'.$id.'" />'; 00098 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; 00099 00100 $sql = "select c.id, c.shortname 00101 from {course} c 00102 where ".$DB->sql_like('c.shortname', '?', false)." 00103 OR ".$DB->sql_like('c.fullname', '?', false); 00104 $params = array("%{$searchcourse}%", "%{$searchcourse}%"); 00105 00106 if (($courses = $DB->get_records_sql_menu($sql, $params)) && !empty($searchcourse)) { 00107 echo ' ' . get_string('courses') . ': '; 00108 echo html_writer::select($courses, 'coursefilter', $coursefilter); 00109 echo '<input type="submit" value="'.get_string('mapcourse', 'feedback').'"/>'; 00110 echo $OUTPUT->help_icon('mapcourses', 'feedback'); 00111 echo '<input type="button" '. 00112 'value="'.get_string('searchagain').'" '. 00113 'onclick="document.location=\'mapcourse.php?id='.$id.'\'"/>'; 00114 00115 echo '<input type="hidden" name="searchcourse" value="'.$searchcourse.'"/>'; 00116 echo '<input type="hidden" name="feedbackid" value="'.$feedback->id.'"/>'; 00117 echo $OUTPUT->help_icon('searchcourses', 'feedback'); 00118 } else { 00119 echo '<input type="text" name="searchcourse" value="'.$searchcourse.'"/> '; 00120 echo '<input type="submit" value="'.get_string('searchcourses').'"/>'; 00121 echo $OUTPUT->help_icon('searchcourses', 'feedback'); 00122 } 00123 00124 echo '</form>'; 00125 00126 if ($coursemap = feedback_get_courses_from_sitecourse_map($feedback->id)) { 00127 $table = new flexible_table('coursemaps'); 00128 $table->define_columns( array('course')); 00129 $table->define_headers( array(get_string('mappedcourses', 'feedback'))); 00130 00131 $table->setup(); 00132 00133 $unmapurl = new moodle_url('/mod/feedback/unmapcourse.php'); 00134 foreach ($coursemap as $cmap) { 00135 $cmapcontext = get_context_instance(CONTEXT_COURSE, $cmap->id); 00136 $cmapshortname = format_string($cmap->shortname, true, array('context' => $cmapcontext)); 00137 $coursecontext = get_context_instance(CONTEXT_COURSE, $cmap->courseid); 00138 $cmapfullname = format_string($cmap->fullname, true, array('context' => $coursecontext)); 00139 $unmapurl->params(array('id'=>$id, 'cmapid'=>$cmap->id)); 00140 $anker = '<a href="'.$unmapurl->out().'">'; 00141 $anker .= '<img src="'.$OUTPUT->pix_url('t/delete').'" alt="Delete" />'; 00142 $anker .= '</a>'; 00143 $table->add_data(array($anker.' ('.$cmapshortname.') '.$cmapfullname)); 00144 } 00145 00146 $table->print_html(); 00147 } else { 00148 echo '<h3>'.get_string('mapcoursenone', 'feedback').'</h3>'; 00149 } 00150 00151 00152 echo $OUTPUT->box_end(); 00153 00154 echo $OUTPUT->footer();