2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
14 $supported_media_type = array( 'gif', 'jpg', 'bmp', 'png', 'jpeg',
15 'txt', 'css', 'html', 'htm', 'csv', 'asc', 'tsv', 'xml', 'xsl',
16 'wav', 'au', 'mp3', 'mov');
19 * Create directory recursively based on the path.
20 * @param string URI of the path, separated by the directory separator.
23 function createDir($path){
28 preg_match('/(.*)[\/\\\\]([^\\\\\/]+)\/?$/', $path, $matches);
29 createDir($matches[1]);
30 //make directory if it's not a filename.
31 if (preg_match('/(.*)\.[\w]+$/', $matches[2])===0) {
32 mkdir($matches[0], 0700);
38 * Trimming the value (For array walk function)
39 * @param value reference
40 * @return value reference
42 function trim_value(&$value) {
43 $value = trim($value);
48 * Check if file exists, return true if it is, false otherwise
49 * @param array resources that each array items store the information of the resource, such as
51 * @return an array of existing filenames, return empty array otherwise.
53 function isQTIFileExist($attributes){
54 global $supported_media_type;
55 $existing_files = array();
57 foreach ($attributes as $resource=>$attrs){
58 if ($attrs['type'] == 'imsqti_xmlv1p1' || $attrs['type'] == 'imsqti_item_xmlv2p1'){
59 //loop through the file array
60 foreach($attrs['file'] as $file_id => $file_name){
61 $file_pathinfo = pathinfo($file_name);
62 // if ($file_pathinfo['basename'] == $attrs['href']){
63 // //This file will be parsed later
67 if (in_array($file_pathinfo['extension'], $supported_media_type)){
69 if (file_exists(TR_CONTENT_DIR . $_SESSION['course_id'] . '/' . $file_name)){
70 $existing_files[] = $file_name;
76 return $existing_files;