-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathget_word_audio.php
51 lines (44 loc) · 2.45 KB
/
get_word_audio.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* ************************************************************************
* * Speech Coach **
* ************************************************************************
* @package mod **
* @subpackage Speech Coach **
* @name Speech Coach **
* @copyright oohoo.biz **
* @link http://oohoo.biz **
* @author Andrew McCann **
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **
* ************************************************************************
* ************************************************************************ */
/**
* This page redirects the user to a link of the audio file that has the given
* word_id.
*/
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require_once(dirname(__FILE__) . '/lib.php');
$id = optional_param('id', 0, PARAM_INT); // course_module ID, or
$n = optional_param('n', 0, PARAM_INT); // speechcoach instance ID - it should be named as the first character of the module
if ($id) {
$cm = get_coursemodule_from_id('speechcoach', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$speechcoach = $DB->get_record('speechcoach', array('id' => $cm->instance), '*', MUST_EXIST);
} elseif ($n) {
$speechcoach = $DB->get_record('speechcoach', array('id' => $n), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $speechcoach->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('speechcoach', $speechcoach->id, $course->id, false, MUST_EXIST);
} else {
error('You must specify a course_module ID or an instance ID');
}
require_login($course, true, $cm);
$word_id = required_param('word_id', PARAM_INT);
$word = $DB->get_record('speechcoach_words', array('id' => $word_id));
$fs = get_file_storage();
$file = $fs->get_file_by_id($word->file_id);
$file_address = $CFG->wwwroot . '/pluginfile.php/' . $file->get_contextid()
. '/' . $file->get_component() . '/' . $file->get_filearea()
. '/' . $file->get_filepath() . $file->get_itemid()
. '/' . $file->get_filename();
header('location: ' . $file_address);
?>