3 * This file plays the mediafile set in lesson settings.
5 * Almost all of this code is from /mod/resource/type/file/resource.class.php so major props for resource
7 * If there is a way to use the resource class instead of this code, please change to do so
11 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
15 require_once('../../config.php');
16 require_once($CFG->libdir
.'/filelib.php');
18 $id = required_param('id', PARAM_INT
); // Course Module ID
19 $printclose = optional_param('printclose', 0, PARAM_INT
);
21 if (! $cm = get_coursemodule_from_id('lesson', $id)) {
22 error('Course Module ID was incorrect');
25 if (! $course = get_record('course', 'id', $cm->course
)) {
26 error('Course is misconfigured');
29 if (! $lesson = get_record('lesson', 'id', $cm->instance
)) {
30 error('Course module is incorrect');
33 require_login($course->id
, false, $cm);
36 $mimetype = mimeinfo("type", $lesson->mediafile
);
38 if (!is_url($lesson->mediafile
) and !in_array($mimetype, array('text/plain', 'text/html'))) {
39 print_header($course->shortname
);
42 if ($printclose) { // this is for framesets
43 if ($lesson->mediaclose
) {
44 print_header($course->shortname
);
45 echo '<div class="lessonmediafilecontrol">
48 <input type="button" onclick="top.close();" value="'.get_string("closewindow").'" />
57 if (is_url($lesson->mediafile
)) {
58 $fullurl = $lesson->mediafile
;
60 $fullurl = get_file_url($course->id
.'/'. $lesson->mediafile
);
63 // find the correct type and print it out
64 if ($mimetype == "audio/mp3") { // It's an MP3 audio file
66 if (!empty($THEME->resource_mp3player_colors
)) {
67 $c = $THEME->resource_mp3player_colors
; // You can set this up in your theme/xxx/config.php
69 $c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&'.
70 'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&'.
71 'font=Arial&fontColour=3333FF&buffer=10&waitForPlay=no&autoPlay=yes';
73 $c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource');
74 $c = htmlentities($c);
75 echo '<div class="mp3player" class="lessonmediafilecontrol">';
76 echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
77 echo ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
78 echo ' width="600" height="70" id="mp3player" align="">';
79 echo '<param name="movie" value="'.$CFG->wwwroot
.'/lib/mp3player/mp3player.swf?src='.$fullurl.'">';
80 echo '<param name="quality" value="high">';
81 echo '<param name="bgcolor" value="#333333">';
82 echo '<param name="flashvars" value="'.$c.'&" />';
83 echo '<embed src="'.$CFG->wwwroot
.'/lib/mp3player/mp3player.swf?src='.$fullurl.'" ';
84 echo ' quality="high" bgcolor="#333333" width="600" height="70" name="mp3player" ';
85 echo ' type="application/x-shockwave-flash" ';
86 echo ' flashvars="'.$c.'&" ';
87 echo ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
92 } else if (substr($mimetype, 0, 10) == "video/x-ms") { // It's a Media Player file
94 echo "<div class=\"lessonmediafilecontrol\"><p>";
95 echo '<object classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"';
96 echo ' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ';
97 echo ' standby="Loading Microsoft(R) Windows(R) Media Player components..." ';
98 echo ' id="msplayer" align="" type="application/x-oleobject">';
99 echo "<param name=\"Filename\" value=\"$fullurl\">";
100 echo '<param name="ShowControls" value="true" />';
101 echo '<param name="AutoRewind" value="true" />';
102 echo '<param name="AutoStart" value="true" />';
103 echo '<param name="Autosize" value="true" />';
104 echo '<param name="EnableContextMenu" value="true" />';
105 echo '<param name="TransparentAtStart" value="false" />';
106 echo '<param name="AnimationAtStart" value="false" />';
107 echo '<param name="ShowGotoBar" value="false" />';
108 echo '<param name="EnableFullScreenControls" value="true" />';
109 echo "\n<embed src=\"$fullurl\" name=\"msplayer\" type=\"$mimetype\" ";
110 echo ' ShowControls="1" AutoRewind="1" AutoStart="1" Autosize="0" EnableContextMenu="1"';
111 echo ' TransparentAtStart="0" AnimationAtStart="0" ShowGotoBar="0" EnableFullScreenControls="1"';
112 echo ' pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/">';
117 } else if ($mimetype == "video/quicktime") { // It's a Quicktime file
119 echo "<div class=\"lessonmediafilecontrol\"><p>";
120 echo '<object classid="CLSID:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
121 echo ' codebase="http://www.apple.com/qtactivex/qtplugin.cab" ';
122 echo ' height="450" width="600"';
123 echo ' id="quicktime" align="" type="application/x-oleobject">';
124 echo "<param name=\"src\" value=\"$fullurl\" />";
125 echo '<param name="autoplay" value="true" />';
126 echo '<param name="loop" value="true" />';
127 echo '<param name="controller" value="true" />';
128 echo '<param name="scale" value="aspect" />';
129 echo "\n<embed src=\"$fullurl\" name=\"quicktime\" type=\"$mimetype\" ";
130 echo ' height="450" width="600" scale="aspect"';
131 echo ' autoplay="true" controller="true" loop="true" ';
132 echo ' pluginspage="http://quicktime.apple.com/">';
137 //} else if ($mimetype == "application/x-shockwave-flash") { // It's a flash file
139 // error('Flash is not supported yet');
141 } else if ($mimetype == "audio/x-pn-realaudio") { // It's a realmedia file
143 echo '<object id="rvocx" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="600" height="50">';
144 echo "<param name=\"src\" value=\"$fullurl\">";
145 echo '<param name="console" value="video">'; // not sure what the console param should equal
146 echo '<param name="controls" value="ControlPanel">';
147 echo '<param name="autostart" value="true">';
148 echo '<param name="loop" value="true">';
149 echo '<embed name="rvocx" src="'.$fullurl.'" height="50" width="600" autostart="true" loop="true" nojava="true" console="video" controls="ControlPanel"></embed>';
150 echo '<noembed></noembed>';
153 } else if (is_url($lesson->mediafile
) or $mimetype == 'text/html' or $mimetype == 'text/plain') {
154 // might be dangerous to handle all of these in the same fasion. It is being set by a teacher though.
155 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
156 echo "<html dir=\"ltr\">\n";
158 echo '<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />';
159 echo "<title>{$course->shortname}</title></head>\n";
160 if ($lesson->mediaclose
) {
161 echo "<frameset rows=\"90%,*\">";
162 echo "<frame src=\"$fullurl\" />";
163 echo "<frame src=\"mediafile.php?id=$cm->id&printclose=1\" />";
166 echo "<frameset rows=\"100%\">";
167 echo "<frame src=\"$fullurl\" />";
173 } else if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // Image
175 echo "<div class=\"lessonmediafilecontrol\"><p>";
176 echo '<img class="lessonimage" src="'.s($fullurl).'" alt="" />';
182 $file = pathinfo($lesson->mediafile
);
183 $filename = basename($file['basename'], '.'.$file['extension']);
185 echo "<div class=\"lessonmediafilecontrol\"><p>";
186 notify(get_string('clicktodownload', 'lesson'));
187 echo "<a href=\"$fullurl\">".format_string($filename).'</a>';
192 function is_url($test_url) {
193 // the following is barrowed from resource code. Thanks!
194 if (strpos($test_url, '://')) { // eg http:// https:// ftp:// etc
197 if (strpos($test_url, '/') === 0) { // Starts with slash
203 if ($lesson->mediaclose
) {
204 echo '<div class="lessonmediafilecontrol">';
205 close_window_button();