scorm.lib.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php //$id:$
  2. //TODO migrate this into the scorm.class.php file
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2004 Denes Nagy
  8. Copyright (c) 2003 Ghent University (UGent)
  9. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium,
  18. info@dokeos.com
  19. =============================================================================
  20. */
  21. /**
  22. =============================================================================
  23. * This file is a container for functions related to SCORM and other
  24. * standard or common course content types. It might later become a class
  25. * instead of a functions library, as several components are likely to be
  26. * re-used for different content types.
  27. * @package dokeos.learnpath.scorm
  28. * @author Yannick Warnier <ywarnier@beeznest.org>
  29. * @author Based on work from Denes NAgy, Isthvan Mandak and Roan Embrechts
  30. =============================================================================
  31. */
  32. /**
  33. * Delete a scorm directory (check for imsmanifest and if found, deletes the related rows in scorm tables also)
  34. * @param string Dir path
  35. * @return boolean True on success, false otherwise
  36. */
  37. function removescormDir($dir)
  38. {
  39. global $_course;
  40. if(!@$opendir = opendir($dir))
  41. {
  42. return false;
  43. }
  44. while($readdir = readdir($opendir))
  45. {
  46. if($readdir != '..' && $readdir != '.')
  47. {
  48. if(is_file($dir.'/'.$readdir))
  49. {
  50. $pos=strpos('/'.$readdir, 'imsmanifest.xml');
  51. if ($pos) { //so we have the imsmanifest in this dir
  52. //from d:/myworks/dokeos/dokeos_cvs/dokeos/dokeos/courses/CVSCODE4/scorm/LP2/LP2
  53. //we have to get /LP2/LP2
  54. $path=api_get_path('SYS_COURSE_PATH').$_course['official_code'].'/scorm';
  55. $pos=strpos($dir,$path);
  56. if ($pos==0) {
  57. $scormdir=substr($dir,strlen($path),strlen($dir)-strlen($path));
  58. $courseid=$_course['official_code'];
  59. $sql="SELECT * FROM ".Database::get_scorm_table(TABLE_SCORM_MAIN)." where (contentTitle='$scormdir' and dokeosCourse='$courseid')";
  60. $result=Database::query($sql,__FILE__,__LINE__);
  61. while ($row=Database::fetch_array($result))
  62. {
  63. $c=$row['contentId'];
  64. $sql2="DELETE FROM ".Database::get_scorm_table(TABLE_SCORM_SCO_DATA)." where contentId=$c";
  65. $result2=Database::query($sql2,__FILE__,__LINE__);
  66. }
  67. $sql="DELETE FROM ".Database::get_scorm_table(TABLE_SCORM_MAIN)." where (contentTitle='$scormdir' and dokeosCourse='$courseid')";
  68. $result=Database::query($sql,__FILE__,__LINE__);
  69. }
  70. }
  71. if(!@unlink($dir.'/'.$readdir))
  72. {
  73. return false;
  74. }
  75. } elseif(is_dir($dir.'/'.$readdir)) {
  76. if(!removescormDir($dir.'/'.$readdir))
  77. {
  78. return false;
  79. }
  80. }
  81. }
  82. }
  83. closedir($opendir);
  84. if(!@rmdir($dir)) {
  85. return false;
  86. }
  87. return true;
  88. }
  89. /**
  90. * This function removes a directory if it exists
  91. * @param string Dir path
  92. * @return boolean True on success, false otherwise
  93. * @uses removescormDir() to actually remove the directory
  94. */
  95. function scorm_delete($file)
  96. {
  97. if ( check_name_exist($file) )
  98. {
  99. if ( is_dir($file) )
  100. {
  101. return removescormDir($file);
  102. }
  103. }
  104. else
  105. {
  106. return false; // no file or directory to delete
  107. }
  108. }
  109. /**
  110. * This function gets a list of scorm paths located in a given directory
  111. * @param string Base directory path
  112. * @param string Current directory
  113. * @param array Reference to a list of paths that exist in the database
  114. * @return array Array(type=>array(),size=>array(),date=>array())
  115. */
  116. function get_scorm_paths_from_dir($basedir, $curdir, &$attribute){
  117. $scormcontent=false;
  118. $saved_dir = getcwd();
  119. $res = @chdir (realpath($basedir.$curdir));
  120. if($res === false){ return(null);}
  121. $handle = opendir(".");
  122. define('A_DIRECTORY', 1);
  123. define('A_FILE', 2);
  124. $fileList = array();
  125. // fill up $fileList for displaying the files list later on
  126. while ($file = readdir($handle))
  127. {
  128. if ($file == "." || $file == ".." || $file == '.htaccess')
  129. {
  130. continue; // Skip current and parent directories
  131. }
  132. $fileList['name'][] = $file;
  133. //if ($file=='imsmanifest.xml') { $scormcontent=true; }
  134. if(is_dir($file))
  135. {
  136. $fileList['type'][] = A_DIRECTORY;
  137. $fileList['size'][] = false;
  138. $fileList['date'][] = false;
  139. }
  140. elseif(is_file($file))
  141. {
  142. $fileList['type'][] = A_FILE;
  143. $fileList['size'][] = filesize($file);
  144. $fileList['date'][] = filectime($file);
  145. }
  146. /*
  147. * Make the correspondance between
  148. * info given by the file system
  149. * and info given by the DB
  150. */
  151. if (is_array($attribute) && count($attribute['path'])>0)
  152. {
  153. $keyAttribute = array_search($curdir."/".$file, $attribute['path']);
  154. }
  155. if ($keyAttribute !== false)
  156. {
  157. $fileList['comment' ][] = $attribute['comment' ][$keyAttribute];
  158. $fileList['visibility'][] = $attribute['visibility'][$keyAttribute];
  159. unset ($attribute['comment' ][$keyAttribute],
  160. $attribute['visibility'][$keyAttribute],
  161. $attribute['path' ][$keyAttribute]);
  162. }
  163. else
  164. {
  165. $fileList['comment' ][] = false;
  166. $fileList['visibility'][] = false;
  167. }
  168. }
  169. closedir($handle);
  170. chdir($saved_dir);
  171. return $fileList;
  172. }
  173. /**
  174. * Detects the SCORM version from an imsmanifest.xml file
  175. * @param string Path to imsmanifest.xml
  176. * @return string SCORM version (1.0,1.1,1.2,1.3)
  177. * @todo Implement this function
  178. */
  179. function get_scorm_version($path){
  180. return '1.2';
  181. }
  182. ?>