Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / backup / bb / restore_bb.php
blob4e63c404478c0703755b22476c62d77a6baf8d62
1 <?php // $Id$
2 // This file facilitates the conversion of a Blackboard course export
3 // into a Moodle course export. It assumes an unzipped directory and makes in-place alterations.
5 defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
7 // Ziba Scott <ziba@linuxbox.com> 10-25-04
8 require_once($CFG->dirroot.'/backup/bb/xsl_emulate_xslt.inc');
10 function get_subdirs($directory){
11 $opendirectory = opendir( $directory );
12 while($filename = readdir($opendirectory)) {
13 if (is_dir($directory.$filename) and $filename != ".." and $filename != "."){
14 $subdirs[] = $filename;
17 closedir($opendirectory);
18 return $subdirs;
22 function choose_bb_xsl($manifest){
23 $f = fopen($manifest,"r");
24 $buffer = fgets($f, 400);
25 $buffer = fgets($f, 400);
26 fclose($f);
27 if (strstr($buffer,"xmlns:bb=\"http://www.blackboard.com/content-packaging/\"")){
28 return "bb6_to_moodle.xsl";
30 return "bb5.5_to_moodle.xsl";
34 function blackboard_convert($dir){
35 global $CFG;
38 // Check for a Blackboard manifest file
39 if (is_readable($dir.'/imsmanifest.xml') && !is_readable($dir.'/moodle.xml')){
41 if (!function_exists('xslt_create')) { // XSLT MUST be installed for this to work
42 notify('You need the XSLT library installed in PHP to open this Blackboard file');
43 return false;
46 //Select the proper XSL file
47 $xslt_file = choose_bb_xsl($dir.'/imsmanifest.xml');
50 //TODO: Use the get_string function for this
51 echo "<li>Converting Blackboard export</li>";
53 // The XSL file must be in the same directory as the Blackboard files when it is processed
54 if (!copy($CFG->dirroot."/backup/bb/$xslt_file", "$dir/$xslt_file")) {
55 notify('Could not copy the XSLT file to '."$dir/$xslt_file");
56 return false;
59 // Change to that directory
60 $startdir = getcwd();
61 chdir($dir);
64 // Process the Blackboard XML files with the chosen XSL file.
65 // The imsmanifest contains all the XML files and their relationships.
66 // The XSL processor will open them as needed.
67 $xsltproc = xslt_create();
68 if (!xslt_process($xsltproc, 'imsmanifest.xml', "$dir/$xslt_file", "$dir/moodle.xml")) {
69 notify('Failed writing xml file');
70 chdir($startdir);
71 return false;
75 // Copy the Blackboard course files into the moodle course_files structure
76 $subdirs = get_subdirs($dir."/");
77 mkdir("$dir/course_files");
78 foreach ($subdirs as $subdir){
79 rename($subdir, "course_files/$subdir");
82 chdir($startdir);
84 // Blackboard export successfully converted
85 return true;
87 // This is not a Blackboard export
88 return true;