1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Prints a particular instance of eduplayer
|
|
|
19 |
*
|
|
|
20 |
*
|
|
|
21 |
* @package mod
|
|
|
22 |
* @subpackage eduplayer
|
|
|
23 |
* @author Humanage Srl <info@humanage.it>
|
|
|
24 |
* @copyright 2013 Humanage Srl <info@humanage.it>
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
26 |
*/
|
|
|
27 |
|
|
|
28 |
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
|
|
|
29 |
require_once(dirname(__FILE__).'/lib.php');
|
|
|
30 |
|
|
|
31 |
$id = optional_param('id', 0, PARAM_INT);
|
|
|
32 |
$n = optional_param('n', 0, PARAM_INT);
|
|
|
33 |
$forceDownload = optional_param('forceDownload', 0, PARAM_INT);
|
|
|
34 |
|
|
|
35 |
if ($id) {
|
|
|
36 |
$cm = get_coursemodule_from_id('eduplayer', $id, 0, false, MUST_EXIST);
|
|
|
37 |
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
|
|
38 |
$eduplayer = $DB->get_record('eduplayer', array('id' => $cm->instance), '*', MUST_EXIST);
|
|
|
39 |
} elseif ($n) {
|
|
|
40 |
$eduplayer = $DB->get_record('eduplayer', array('id' => $n), '*', MUST_EXIST);
|
|
|
41 |
$course = $DB->get_record('course', array('id' => $eduplayer->course), '*', MUST_EXIST);
|
|
|
42 |
$cm = get_coursemodule_from_instance('eduplayer', $eduplayer->id, $course->id, false, MUST_EXIST);
|
|
|
43 |
} else {
|
|
|
44 |
error('You must specify a course_module ID or an instance ID');
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
require_login($course, true, $cm);
|
|
|
49 |
//$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
|
50 |
$context = context_module::instance($cm->id); //Mihir moodle3.2
|
|
|
51 |
|
|
|
52 |
if( $forceDownload == 1 ){
|
|
|
53 |
eduplayer_pluginfile($course, $cm, $context, 'file', array('itemid'=>$id,'filename'=>$eduplayer->eduplayerfile), true, array()) ;
|
|
|
54 |
die();
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
add_to_log($course->id, 'eduplayer', 'view', "view.php?id={$cm->id}", $eduplayer->name, $cm->id);
|
|
|
58 |
|
|
|
59 |
$completion = new completion_info($course);
|
|
|
60 |
$completion->set_module_viewed($cm);
|
|
|
61 |
|
|
|
62 |
$PAGE->set_url('/mod/eduplayer/view.php', array('id' => $cm->id));
|
|
|
63 |
$PAGE->set_title(format_string($eduplayer->name));
|
|
|
64 |
$PAGE->set_heading(format_string($course->fullname));
|
|
|
65 |
$PAGE->set_context($context);
|
|
|
66 |
$PAGE->set_cacheable(true);
|
|
|
67 |
|
|
|
68 |
if ($eduplayer->sharelink) {
|
|
|
69 |
require_once('./share_form.php');
|
|
|
70 |
$f = new shareform_form('?id='.$id);
|
|
|
71 |
if( isset($_POST['ajax']) && $_POST['ajax'] == 1){
|
|
|
72 |
if ( $f->get_data() ){
|
|
|
73 |
if( $f->shareEmailLink( $eduplayer ) ){
|
|
|
74 |
die( json_encode( array('result'=>'success','message'=>get_string('emailsent','eduplayer',$f->get_data()->email) ) ) );
|
|
|
75 |
}else{
|
|
|
76 |
die( json_encode( array('result'=>'error','message'=>get_string('emailnotsent','eduplayer') ) ) );
|
|
|
77 |
}
|
|
|
78 |
}else{
|
|
|
79 |
die( json_encode( array('result'=>'error','message'=>get_string('emailnotcorrect','eduplayer') ) ) );
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
// Output starts here
|
|
|
85 |
echo $OUTPUT->header();
|
|
|
86 |
echo '<script type="text/javascript" src="./jwplayer/jwplayer.js"></script>';
|
|
|
87 |
if ($eduplayer->intro) {
|
|
|
88 |
echo $OUTPUT->box(format_module_intro('eduplayer', $eduplayer, $cm->id), 'generalbox mod_introbox', 'eduplayerintro');
|
|
|
89 |
}
|
|
|
90 |
?>
|
|
|
91 |
<style>
|
|
|
92 |
.yui3-panel{z-index: 1000 !important}
|
|
|
93 |
.hidden{display:none}
|
|
|
94 |
span#result{margin: 0 0 0 10px}
|
|
|
95 |
span#loading{margin: 0 0 0 10px}
|
|
|
96 |
span#loading img{margin: 0 10px 0 0}
|
|
|
97 |
a.button{ display: block; height: 30px; font-weight: bold; color: #fff !important; width: 142px; margin: 5px 10px 5px 0px; padding: 0; float:left; line-height: 30px; color: #000; text-indent: 18px; }
|
|
|
98 |
a.button:hover{ color: #F86F05 !important; text-decoration: none; }
|
|
|
99 |
a#share.button{ background: url('./pix/share_icon.png') no-repeat center left }
|
|
|
100 |
a#download.button{ background: url('./pix/download_icon.png') no-repeat center left }
|
|
|
101 |
div#sharebox{ clear:both; padding: 5px;}
|
|
|
102 |
</style>
|
|
|
103 |
<?php
|
|
|
104 |
|
|
|
105 |
echo eduplayer_video( $eduplayer );
|
|
|
106 |
if ($eduplayer->sharelink) {
|
|
|
107 |
echo '<a id="share" href="#" class="button">'. get_string('share','eduplayer') .'</a>';
|
|
|
108 |
}
|
|
|
109 |
if( $eduplayer->downloadenabled ){
|
|
|
110 |
echo '<a id="download" href="./view.php?id='.$id.'&forceDownload=1" class="button">'. get_string('download','eduplayer') .'</a>';
|
|
|
111 |
if( $eduplayer->disclaimer ){
|
|
|
112 |
?>
|
|
|
113 |
<script type='text/javascript'>
|
|
|
114 |
YUI().use('event','panel', function (Y) {
|
|
|
115 |
var downloadbutton = Y.one('#download');
|
|
|
116 |
downloadbutton.on('click', function(e) {
|
|
|
117 |
e.preventDefault();
|
|
|
118 |
try{
|
|
|
119 |
if( downloadpanel.get('visible') )
|
|
|
120 |
return false;
|
|
|
121 |
}catch(err){
|
|
|
122 |
}
|
|
|
123 |
downloadpanel = new Y.Panel({
|
|
|
124 |
bodyContent : '<?php echo addslashes( str_replace(array("\r\n", "\r", "\n"), '<br />', $eduplayer->disclaimer) ); ?>',
|
|
|
125 |
width : 400,
|
|
|
126 |
centered: true,
|
|
|
127 |
buttons: [
|
|
|
128 |
{ value: "no",
|
|
|
129 |
label:'<?php echo get_string('cancel','eduplayer'); ?>',
|
|
|
130 |
action: function(i) {
|
|
|
131 |
i.preventDefault();
|
|
|
132 |
downloadpanel.hide();
|
|
|
133 |
return false;
|
|
|
134 |
},
|
|
|
135 |
section: Y.WidgetStdMod.FOOTER
|
|
|
136 |
},
|
|
|
137 |
{ value: "yes",
|
|
|
138 |
label:'<?php echo get_string('download','eduplayer'); ?>',
|
|
|
139 |
action: function(i) {
|
|
|
140 |
i.preventDefault();
|
|
|
141 |
downloadpanel.hide();
|
|
|
142 |
location.href=downloadbutton.getAttribute('href');
|
|
|
143 |
},
|
|
|
144 |
section: Y.WidgetStdMod.FOOTER
|
|
|
145 |
}
|
|
|
146 |
]
|
|
|
147 |
});
|
|
|
148 |
|
|
|
149 |
downloadpanel.render();
|
|
|
150 |
});
|
|
|
151 |
});
|
|
|
152 |
</script>
|
|
|
153 |
<?php
|
|
|
154 |
}
|
|
|
155 |
}
|
|
|
156 |
if ( isset( $f ) ) {
|
|
|
157 |
echo '<div id="sharebox" class="hidden">';
|
|
|
158 |
if($f->is_cancelled()) {
|
|
|
159 |
$f->display();
|
|
|
160 |
} else if ( $f->get_data() && $f->shareEmailLink( $eduplayer ) ) {
|
|
|
161 |
echo get_string('emailsent','eduplayer',$f->get_data()->email);
|
|
|
162 |
} else if( $f->get_data() ) {
|
|
|
163 |
echo get_string('emailnotsent','eduplayer');
|
|
|
164 |
$f->display();
|
|
|
165 |
} else {
|
|
|
166 |
$f->displayCustom();
|
|
|
167 |
}
|
|
|
168 |
echo ('</div>');
|
|
|
169 |
?>
|
|
|
170 |
<script type='text/javascript'>
|
|
|
171 |
function makeajaxemail(){
|
|
|
172 |
YUI().use('transition','io-form','node', function(Y) {
|
|
|
173 |
var cfg = {
|
|
|
174 |
method: 'POST',
|
|
|
175 |
data: {ajax:'1'},
|
|
|
176 |
form: {id:'mform1'},
|
|
|
177 |
};
|
|
|
178 |
function complete(transactionid, response, arguments) {
|
|
|
179 |
var r = JSON.parse(response.responseText);
|
|
|
180 |
Y.one('span#loading').replace('<span id="result" class="'+ r.result +'">'+ r.message +'</span>');
|
|
|
181 |
setTimeout(function() {
|
|
|
182 |
Y.one('span#result').hide(true);
|
|
|
183 |
}, 5000);
|
|
|
184 |
}
|
|
|
185 |
function start(transactionid, arguments) {
|
|
|
186 |
if( Y.one('#loading') )
|
|
|
187 |
Y.one('#loading').remove();
|
|
|
188 |
if( Y.one('#result') )
|
|
|
189 |
Y.one('#result').remove();
|
|
|
190 |
Y.one('input[type=submit]').insert('<span id="loading"><img src="./pix/ajax-loader.gif" />loading ....</span>', 'after');
|
|
|
191 |
}
|
|
|
192 |
Y.on('io:start', start, Y, ['lorem', 'ipsum']);
|
|
|
193 |
Y.on('io:complete', complete, Y, ['lorem', 'ipsum']);
|
|
|
194 |
var request = Y.io(window.location.href, cfg);
|
|
|
195 |
});
|
|
|
196 |
}
|
|
|
197 |
YUI().use('node','event','panel', function (Y) {
|
|
|
198 |
Y.one('a#share').on('click', function(e) {
|
|
|
199 |
e.preventDefault();
|
|
|
200 |
Y.one('#sharebox').toggleClass('hidden');
|
|
|
201 |
});
|
|
|
202 |
|
|
|
203 |
var shareform = Y.one('#mform1');
|
|
|
204 |
shareform.on('submit', function(e) {
|
|
|
205 |
e.preventDefault();
|
|
|
206 |
if( Y.one('input[name=email]').get('value') == ''){
|
|
|
207 |
Y.one('input[name=email]').focus();
|
|
|
208 |
return false;
|
|
|
209 |
}
|
|
|
210 |
<?php if( $eduplayer->disclaimer ){ ?>
|
|
|
211 |
try{
|
|
|
212 |
if( sharepanel.get('visible') )
|
|
|
213 |
return false;
|
|
|
214 |
}catch(err){
|
|
|
215 |
}
|
|
|
216 |
sharepanel = new Y.Panel({
|
|
|
217 |
bodyContent : '<?php echo addslashes( str_replace(array("\r\n", "\r", "\n"), '<br />', $eduplayer->disclaimer) ); ?>',
|
|
|
218 |
width : 400,
|
|
|
219 |
centered: true,
|
|
|
220 |
buttons: [
|
|
|
221 |
{ value: "no",
|
|
|
222 |
label:'<?php echo get_string('cancel','eduplayer'); ?>',
|
|
|
223 |
action: function(i) {
|
|
|
224 |
i.preventDefault();
|
|
|
225 |
sharepanel.hide();
|
|
|
226 |
},
|
|
|
227 |
section: Y.WidgetStdMod.FOOTER
|
|
|
228 |
},
|
|
|
229 |
{ value: "yes",
|
|
|
230 |
label:'<?php echo get_string('share','eduplayer') ?>',
|
|
|
231 |
action: function(i) {
|
|
|
232 |
i.preventDefault();
|
|
|
233 |
sharepanel.hide();
|
|
|
234 |
makeajaxemail();
|
|
|
235 |
},
|
|
|
236 |
section: Y.WidgetStdMod.FOOTER
|
|
|
237 |
}
|
|
|
238 |
]
|
|
|
239 |
});
|
|
|
240 |
|
|
|
241 |
sharepanel.render();
|
|
|
242 |
<?php }else{?>
|
|
|
243 |
makeajaxemail();
|
|
|
244 |
<?php } ?>
|
|
|
245 |
});
|
|
|
246 |
|
|
|
247 |
});
|
|
|
248 |
</script>
|
|
|
249 |
<?php
|
|
|
250 |
|
|
|
251 |
}
|
|
|
252 |
echo $OUTPUT->footer();
|