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 print_header($course->shortname
);
35 if ($printclose) { // this is for framesets
36 if ($lesson->mediaclose
) {
37 echo '<div class="lessonmediafilecontrol">
40 <input type="button" onclick="top.close();" value="'.get_string("closewindow").'" />
49 require_login($course->id
, false, $cm);
51 if (is_url($lesson->mediafile
)) {
52 $fullurl = $lesson->mediafile
;
54 // get the full url to the file while taking into consideration $CFG->slasharguments
55 if ($CFG->slasharguments
) {
56 $relativeurl = "/file.php/{$course->id}/{$lesson->mediafile}";
58 $relativeurl = "/file.php?file=/{$course->id}/{$lesson->mediafile}";
60 $fullurl = "$CFG->wwwroot$relativeurl";
64 $mimetype = mimeinfo("type", $lesson->mediafile
);
66 // find the correct type and print it out
67 if ($mimetype == "audio/mp3") { // It's an MP3 audio file
69 if (!empty($THEME->resource_mp3player_colors
)) {
70 $c = $THEME->resource_mp3player_colors
; // You can set this up in your theme/xxx/config.php
72 $c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&'.
73 'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&'.
74 'font=Arial&fontColour=3333FF&buffer=10&waitForPlay=no&autoPlay=yes';
76 $c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource');
77 $c = htmlentities($c);
78 echo '<div class="mp3player" class="lessonmediafilecontrol">';
79 echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
80 echo ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
81 echo ' width="600" height="70" id="mp3player" align="">';
82 echo '<param name="movie" value="'.$CFG->wwwroot
.'/lib/mp3player/mp3player.swf?src='.$fullurl.'">';
83 echo '<param name="quality" value="high">';
84 echo '<param name="bgcolor" value="#333333">';
85 echo '<param name="flashvars" value="'.$c.'&" />';
86 echo '<embed src="'.$CFG->wwwroot
.'/lib/mp3player/mp3player.swf?src='.$fullurl.'" ';
87 echo ' quality="high" bgcolor="#333333" width="600" height="70" name="mp3player" ';
88 echo ' type="application/x-shockwave-flash" ';
89 echo ' flashvars="'.$c.'&" ';
90 echo ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
95 } else if (substr($mimetype, 0, 10) == "video/x-ms") { // It's a Media Player file
97 echo "<div class=\"lessonmediafilecontrol\"><p>";
98 echo '<object classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"';
99 echo ' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ';
100 echo ' standby="Loading Microsoft(R) Windows(R) Media Player components..." ';
101 echo ' id="msplayer" align="" type="application/x-oleobject">';
102 echo "<param name=\"Filename\" value=\"$fullurl\">";
103 echo '<param name="ShowControls" value="true" />';
104 echo '<param name="AutoRewind" value="true" />';
105 echo '<param name="AutoStart" value="true" />';
106 echo '<param name="Autosize" value="true" />';
107 echo '<param name="EnableContextMenu" value="true" />';
108 echo '<param name="TransparentAtStart" value="false" />';
109 echo '<param name="AnimationAtStart" value="false" />';
110 echo '<param name="ShowGotoBar" value="false" />';
111 echo '<param name="EnableFullScreenControls" value="true" />';
112 echo "\n<embed src=\"$fullurl\" name=\"msplayer\" type=\"$mimetype\" ";
113 echo ' ShowControls="1" AutoRewind="1" AutoStart="1" Autosize="0" EnableContextMenu="1"';
114 echo ' TransparentAtStart="0" AnimationAtStart="0" ShowGotoBar="0" EnableFullScreenControls="1"';
115 echo ' pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/">';
120 } else if ($mimetype == "video/quicktime") { // It's a Quicktime file
122 echo "<div class=\"lessonmediafilecontrol\"><p>";
123 echo '<object classid="CLSID:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
124 echo ' codebase="http://www.apple.com/qtactivex/qtplugin.cab" ';
125 echo ' height="450" width="600"';
126 echo ' id="quicktime" align="" type="application/x-oleobject">';
127 echo "<param name=\"src\" value=\"$fullurl\" />";
128 echo '<param name="autoplay" value="true" />';
129 echo '<param name="loop" value="true" />';
130 echo '<param name="controller" value="true" />';
131 echo '<param name="scale" value="aspect" />';
132 echo "\n<embed src=\"$fullurl\" name=\"quicktime\" type=\"$mimetype\" ";
133 echo ' height="450" width="600" scale="aspect"';
134 echo ' autoplay="true" controller="true" loop="true" ';
135 echo ' pluginspage="http://quicktime.apple.com/">';
140 //} else if ($mimetype == "application/x-shockwave-flash") { // It's a flash file
142 // error('Flash is not supported yet');
144 } else if ($mimetype == "audio/x-pn-realaudio") { // It's a realmedia file
146 echo '<object id="rvocx" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="600" height="50">';
147 echo "<param name=\"src\" value=\"$fullurl\">";
148 echo '<param name="console" value="video">'; // not sure what the console param should equal
149 echo '<param name="controls" value="ControlPanel">';
150 echo '<param name="autostart" value="true">';
151 echo '<param name="loop" value="true">';
152 echo '<embed name="rvocx" src="'.$fullurl.'" height="50" width="600" autostart="true" loop="true" nojava="true" console="video" controls="ControlPanel"></embed>';
153 echo '<noembed></noembed>';
156 } else if (is_url($lesson->mediafile
) or $mimetype == 'text/html' or $mimetype == 'text/plain') {
157 // might be dangerous to handle all of these in the same fasion. It is being set by a teacher though.
159 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
160 echo "<html dir=\"ltr\">\n";
162 echo '<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />';
163 echo "<title>{$course->shortname}</title></head>\n";
165 if ($lesson->mediaclose
) {
166 echo "<frameset rows=\"90%,*\">";
167 echo "<frame src=\"$fullurl\" />";
168 echo "<frame src=\"mediafile.php?id=$cm->id&printclose=1\" />";
171 echo "<frameset rows=\"100%\">";
172 echo "<frame src=\"$fullurl\" />";
178 } else if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // Image
180 echo "<div class=\"lessonmediafilecontrol\"><p>";
181 echo '<img class="lessonimage" src="'.s($fullurl).'" alt="" />';
187 $file = pathinfo($lesson->mediafile
);
188 $filename = basename($file['basename'], '.'.$file['extension']);
190 echo "<div class=\"lessonmediafilecontrol\"><p>";
191 notify(get_string('clicktodownload', 'lesson'));
192 echo "<a href=\"$fullurl\">".format_string($filename).'</a>';
197 function is_url($test_url) {
198 // the following is barrowed from resource code. Thanks!
199 if (strpos($test_url, '://')) { // eg http:// https:// ftp:// etc
202 if (strpos($test_url, '/') === 0) { // Starts with slash
208 if ($lesson->mediaclose
) {
209 echo '<div class="lessonmediafilecontrol">';
210 close_window_button();