2 /****************************************************************************/
4 /****************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Harris Wong */
6 /* Inclusive Design Institute */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************************/
16 $supported_media_type = array( 'gif', 'jpg', 'bmp', 'png', 'jpeg',
17 'txt', 'css', 'html', 'htm', 'csv', 'asc', 'tsv', 'xml', 'xsl',
18 'wav', 'au', 'mp3', 'mov');
21 * Create directory recursively based on the path.
22 * @param string URI of the path, separated by the directory separator.
25 function createDir($path){
30 preg_match('/(.*)[\/\\\\]([^\\\\\/]+)\/?$/', $path, $matches);
31 createDir($matches[1]);
32 //make directory if it's not a filename.
33 if (preg_match('/(.*)\.[\w]+$/', $matches[2])===0) {
34 mkdir($matches[0], 0700);
40 * Trimming the value (For array walk function)
41 * @param value reference
42 * @return value reference
44 function trim_value(&$value) {
45 $value = trim($value);
50 * Check if file exists, return true if it is, false otherwise
51 * @param array resources that each array items store the information of the resource, such as
53 * @return an array of existing filenames, return empty array otherwise.
55 function isQTIFileExist($attributes){
56 global $supported_media_type;
57 $existing_files = array();
59 foreach ($attributes as $resource=>$attrs){
60 if ($attrs['type'] == 'imsqti_xmlv1p1' || $attrs['type'] == 'imsqti_item_xmlv2p1'){
61 //loop through the file array
62 foreach($attrs['file'] as $file_id => $file_name){
63 $file_pathinfo = pathinfo($file_name);
64 // if ($file_pathinfo['basename'] == $attrs['href']){
65 // //This file will be parsed later
69 if (in_array($file_pathinfo['extension'], $supported_media_type)){
71 if (file_exists(AT_CONTENT_DIR . $_SESSION['course_id'] . '/' . $file_name)){
72 $existing_files[] = $file_name;
78 return $existing_files;