File: restore_bb.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (92 lines) | stat: -rw-r--r-- 2,932 bytes parent folder | download | duplicates (2)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php // $Id: restore_bb.php,v 1.7 2006/03/07 23:41:22 skodak Exp $
// This file facilitates the conversion of a Blackboard course export
// into a Moodle course export.  It assumes an unzipped directory and makes in-place alterations.

defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');

// Ziba Scott <ziba@linuxbox.com> 10-25-04
require_once($CFG->dirroot.'/backup/bb/xsl_emulate_xslt.inc');
  
function get_subdirs($directory){
    $opendirectory = opendir( $directory );
    while($filename = readdir($opendirectory)) {
        if (is_dir($directory.$filename) and $filename != ".." and $filename != "."){
            $subdirs[] = $filename;
        }
    }
    closedir($opendirectory);
    return $subdirs;
}


function choose_bb_xsl($manifest){
    $f = fopen($manifest,"r");
    $buffer = fgets($f, 400);
    $buffer = fgets($f, 400);
    fclose($f);
    if (strstr($buffer,"xmlns:bb=\"http://www.blackboard.com/content-packaging/\"")){
        return "bb6_to_moodle.xsl";
    }
    return "bb5.5_to_moodle.xsl";
}


function blackboard_convert($dir){
    global $CFG;


    // Check for a Blackboard manifest file
    if (is_readable($dir.'/imsmanifest.xml') && !is_readable($dir.'/moodle.xml')){

        if (!function_exists('xslt_create')) {  // XSLT MUST be installed for this to work
            notify('You need the XSLT library installed in PHP to open this Blackboard file');
            return false;
        }

        //Select the proper XSL file
        $xslt_file = choose_bb_xsl($dir.'/imsmanifest.xml');


        //TODO: Use the get_string function for this
        echo "<li>Converting Blackboard export</li>";

        // The XSL file must be in the same directory as the Blackboard files when it is processed
        if (!copy($CFG->dirroot."/backup/bb/$xslt_file", "$dir/$xslt_file")) {
            notify('Could not copy the XSLT file to '."$dir/$xslt_file");
            return false;
        }

        // Change to that directory
        $startdir = getcwd();
        chdir($dir);


        // Process the Blackboard XML files with the chosen XSL file.
        // The imsmanifest contains all the XML files and their relationships. 
        // The XSL processor will open them as needed.
        $xsltproc = xslt_create();
        if (!xslt_process($xsltproc, 'imsmanifest.xml', "$dir/$xslt_file", "$dir/moodle.xml")) {
            notify('Failed writing xml file');
            chdir($startdir);
            return false;
        }


        // Copy the Blackboard course files into the moodle course_files structure
        $subdirs = get_subdirs($dir."/");
        mkdir("$dir/course_files");
        foreach ($subdirs as $subdir){
            rename($subdir, "course_files/$subdir");
        }

        chdir($startdir);

        // Blackboard export successfully converted
        return true;
    }
    // This is not a Blackboard export
    return true;

}

?>