### Eclipse Workspace Patch 1.0
#P moodle
Index: mod/hotpot/restorelib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/hotpot/restorelib.php,v
retrieving revision 1.24
diff -u -r1.24 restorelib.php
--- mod/hotpot/restorelib.php	4 Jan 2007 23:38:26 -0000	1.24
+++ mod/hotpot/restorelib.php	15 May 2008 21:11:28 -0000
@@ -298,8 +298,8 @@
     // maintain a cache of info on table columns
     static $table_columns = array();
     if (empty($table_columns[$table])) {
-        global $CFG, $db; 
-        $table_columns[$table] = $db->MetaColumns("$CFG->prefix$table");
+        global $CFG, $DB; 
+        $table_columns[$table] = $DB->get_columns($table);
     }
 
     // get values for fields in this record
Index: mod/hotpot/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/hotpot/lib.php,v
retrieving revision 1.88
diff -u -r1.88 lib.php
--- mod/hotpot/lib.php	1 May 2008 22:03:15 -0000	1.88
+++ mod/hotpot/lib.php	15 May 2008 21:11:28 -0000
@@ -2191,7 +2191,7 @@
     hotpot_add_response($attempt, $question, $response);
 }
 function hotpot_add_response(&$attempt, &$question, &$response) {
-    global $db, $next_url;
+    global $DB, $next_url;
 
     $loopcount = 1;
 
@@ -2206,7 +2206,7 @@
         if (!$question->id = get_field('hotpot_questions', 'id', 'hotpot', $attempt->hotpot, 'md5key', $question->md5key, 'name', $question->name)) {
             // add question record
             if (!$question->id = insert_record('hotpot_questions', $question)) {
-                print_error("Could not add question record (attempt_id=$attempt->id): ".$db->ErrorMsg(), '', $next_url);
+                print_error("Could not add question record (attempt_id=$attempt->id): ".$DB->get_last_error(), '', $next_url);
             }
         }
 
@@ -2231,7 +2231,7 @@
 
             // add response record
             if(!$response->id = insert_record('hotpot_responses', $response)) {
-                print_error("Could not add response record (attempt_id=$attempt->id, question_id=$question->id): ".$db->ErrorMsg(), '', $next_url);
+                print_error("Could not add response record (attempt_id=$attempt->id, question_id=$question->id): ".$DB->get_last_error(), '', $next_url);
             }
 
             // we can stop looping now
@@ -2384,8 +2384,8 @@
 
             // try and add the new string record
             if (!$id = insert_record('hotpot_strings', $record)) {
-                global $db;
-                print_error("Could not add string record for '".htmlspecialchars($str)."': ".$db->ErrorMsg());
+                global $DB;
+                print_error("Could not add string record for '".htmlspecialchars($str)."': ".$DB->get_last_error());
             }
         }
     }
Index: mod/hotpot/view.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/hotpot/view.php,v
retrieving revision 1.42
diff -u -r1.42 view.php
--- mod/hotpot/view.php	4 Apr 2008 02:54:42 -0000	1.42
+++ mod/hotpot/view.php	15 May 2008 21:11:29 -0000
@@ -146,7 +146,7 @@
 
                 $attemptid = hotpot_add_attempt($hotpot->id);
                 if (! is_numeric($attemptid)) {
-                    print_error('Could not insert attempt record: '.$db->ErrorMsg);
+                    print_error('Could not insert attempt record: '.$DB->get_last_error());
                 }
             }
             $hp->adjust_media_urls();
Index: mod/hotpot/attempt.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/hotpot/attempt.php,v
retrieving revision 1.20
diff -u -r1.20 attempt.php
--- mod/hotpot/attempt.php	4 Apr 2008 02:54:42 -0000	1.20
+++ mod/hotpot/attempt.php	15 May 2008 21:11:25 -0000
@@ -6,7 +6,7 @@
 
     // get attempt, hotpot, course and course_module records
     if (! $attempt = get_record("hotpot_attempts", "id", $attemptid)) {
-        print_error("Hot Potatoes attempt record $attemptid could not be accessed: ".$db->ErrorMsg());
+        print_error("Hot Potatoes attempt record $attemptid could not be accessed: ".$DB->get_last_error());
     }
     if ($attempt->userid != $USER->id) {
         print_error("User ID is incorrect");
@@ -82,7 +82,7 @@
             $attempt->id = insert_record("hotpot_attempts", $attempt);
 
             if (empty($attempt->id)) {
-                print_error("Could not insert attempt record: ".$db->ErrorMsg(), '', $next_url);
+                print_error("Could not insert attempt record: ".$DB->get_last_error(), '', $next_url);
             }
 
             // add attempt details record, if necessary
@@ -91,7 +91,7 @@
                 $details->attempt = $attempt->id;
                 $details->details = $attempt->details;
                 if (! insert_record("hotpot_details", $details, false)) {
-                    print_error("Could not insert attempt details record: ".$db->ErrorMsg(), '', $next_url);
+                    print_error("Could not insert attempt details record: ".$DB->get_last_error(), '', $next_url);
                 }
             }
         } else {
@@ -112,7 +112,7 @@
 
     // update the attempt record
     if (! update_record("hotpot_attempts", $attempt)) {
-        print_error("Could not update attempt record: ".$db->ErrorMsg(), '', $next_url);
+        print_error("Could not update attempt record: ".$DB->get_last_error(), '', $next_url);
     }
 
     // update grades for this user
@@ -134,7 +134,7 @@
             $details->attempt = $attempt->id;
             $details->details = $attempt->details;
             if (! insert_record("hotpot_details", $details)) {
-                print_error("Could not insert attempt details record: ".$db->ErrorMsg(), '', $next_url);
+                print_error("Could not insert attempt details record: ".$DB->get_last_error(), '', $next_url);
             }
         }
     }
Index: mod/hotpot/index.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/hotpot/index.php,v
retrieving revision 1.30
diff -u -r1.30 index.php
--- mod/hotpot/index.php	2 May 2008 04:37:06 -0000	1.30
+++ mod/hotpot/index.php	15 May 2008 21:11:25 -0000
@@ -163,7 +163,7 @@
                             if ($attempt->details) {
                                 hotpot_add_attempt_details($attempt);
                                 if (! update_record('hotpot_attempts', $attempt)) {
-                                    print_error("Could not update attempt record: ".$db->ErrorMsg(), '', $next_url);
+                                    print_error("Could not update attempt record: ".$DB->get_last_error(), '', $next_url);
                                 }
                             }
                             $attemptcount++;
Index: blocks/admin/block_admin.php
===================================================================
RCS file: /cvsroot/moodle/moodle/blocks/admin/block_admin.php,v
retrieving revision 1.109
diff -u -r1.109 block_admin.php
--- blocks/admin/block_admin.php	2 May 2008 06:07:51 -0000	1.109
+++ blocks/admin/block_admin.php	15 May 2008 21:10:40 -0000
@@ -8,7 +8,7 @@
 
     function get_content() {
 
-        global $CFG, $USER, $SITE, $COURSE;
+        global $CFG, $USER, $SITE, $COURSE, $DB;
 
         if ($this->content !== NULL) {
             return $this->content;
@@ -30,7 +30,7 @@
             if ($COURSE->id == $this->instance->pageid) {
                 $course = $COURSE;
             } else {
-                $course = get_record('course', 'id', $this->instance->pageid);
+                $course = $DB->get_record('course', array('id'=>$this->instance->pageid));
             }
         } else {
             $context = get_context_instance(CONTEXT_SYSTEM);
Index: admin/xmldb/index.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/xmldb/index.php,v
retrieving revision 1.11
diff -u -r1.11 index.php
--- admin/xmldb/index.php	2 May 2008 04:37:03 -0000	1.11
+++ admin/xmldb/index.php	15 May 2008 21:10:30 -0000
@@ -28,23 +28,21 @@
 /// all the actions supported will be launched.
 
 /// Add required XMLDB constants
-    require_once('../../lib/xmldb/classes/XMLDBConstants.php');
+    require_once('../../lib/xmldb/XMLDBConstants.php');
 
 /// Add required XMLDB action classes
     require_once('actions/XMLDBAction.class.php');
 
-/// Add main XMLDB Generator
-    require_once('../../lib/xmldb/classes/generators/XMLDBGenerator.class.php');
 
 /// Add required XMLDB DB classes
-    require_once('../../lib/xmldb/classes/XMLDBObject.class.php');
-    require_once('../../lib/xmldb/classes/XMLDBFile.class.php');
-    require_once('../../lib/xmldb/classes/XMLDBStructure.class.php');
-    require_once('../../lib/xmldb/classes/XMLDBTable.class.php');
-    require_once('../../lib/xmldb/classes/XMLDBField.class.php');
-    require_once('../../lib/xmldb/classes/XMLDBKey.class.php');
-    require_once('../../lib/xmldb/classes/XMLDBIndex.class.php');
-    require_once('../../lib/xmldb/classes/XMLDBStatement.class.php');
+    require_once('../../lib/xmldb/XMLDBObject.class.php');
+    require_once('../../lib/xmldb/XMLDBFile.class.php');
+    require_once('../../lib/xmldb/XMLDBStructure.class.php');
+    require_once('../../lib/xmldb/XMLDBTable.class.php');
+    require_once('../../lib/xmldb/XMLDBField.class.php');
+    require_once('../../lib/xmldb/XMLDBKey.class.php');
+    require_once('../../lib/xmldb/XMLDBIndex.class.php');
+    require_once('../../lib/xmldb/XMLDBStatement.class.php');
 
 /// Add Moodle config script (this is loaded AFTER all the rest
 /// of classes because it starts the SESSION and classes to be
@@ -59,12 +57,6 @@
 /// Add other used libraries
     require_once($CFG->libdir . '/xmlize.php');
 
-/// Add all the available SQL generators
-    $generators = get_list_of_plugins('lib/xmldb/classes/generators');
-    foreach($generators as $generator) {
-        require_once ('../../lib/xmldb/classes/generators/' . $generator . '/' . $generator . '.class.php');
-    }
-
 /// Handle session data
     global $XMLDB;
 /// The global SESSION object where everything will happen
Index: admin/multilangupgrade.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/multilangupgrade.php,v
retrieving revision 1.8
diff -u -r1.8 multilangupgrade.php
--- admin/multilangupgrade.php	10 Apr 2008 03:44:09 -0000	1.8
+++ admin/multilangupgrade.php	15 May 2008 21:10:30 -0000
@@ -24,7 +24,7 @@
 }
 
 
-if (!$tables = $db->Metatables() ) {    // No tables yet at all.
+if (!$tables = $DB->get_tables() ) {    // No tables yet at all.
     print_error('notables', 'debug');
 }
 
@@ -38,29 +38,28 @@
 
 echo '<strong>Progress:</strong>';
 $i = 0;
-$skiptables = array($CFG->prefix.'config', $CFG->prefix.'user_students', $CFG->prefix.'user_teachers');//, $CFG->prefix.'sessions2');
+$skiptables = array('config', 'user_students', 'user_teachers');//, 'sessions2');
 
 foreach ($tables as $table) {
-    if (($CFG->prefix && strpos($table, $CFG->prefix) !== 0)
-      or strpos($table, $CFG->prefix.'pma') === 0) { // Not our tables
+    if (strpos($table,'pma') === 0) { // Not our tables
         continue;
     }
     if (in_array($table, $skiptables)) { // Don't process these
         continue;
     }
-    if ($columns = $db->MetaColumns($table, false)) {
+    $fulltable = $DB->get_prefix().$table;
+    if ($columns = $DB->get_columns($table)) {
         if (!array_key_exists('id', $columns) and !array_key_exists('ID', $columns)) {
             continue; // moodle tables have id
         }
         foreach ($columns as $column => $data) {
             if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) {  // Text stuff only
                 // first find candidate records
-                $rs = get_recordset_sql("SELECT id, $column FROM $table WHERE $column LIKE '%</lang>%' OR $column LIKE '%<span lang=%'");
-                if ($rs) {
-                    while (!$rs->EOF) {
-                        $text = $rs->fields[$column];
-                        $id   = $rs->fields['id'];
-
+                $sql = "SELECT id, $column FROM $fulltable WHERE $column LIKE '%</lang>%' OR $column LIKE '%<span lang=%'";
+                if ($rs = $DB->get_recordset_sql($sql)) {
+                    foreach ($rs as $data) {
+                        $text = $data->$column;
+                        $id   = $data->id;
                         if ($i % 600 == 0) {
                             echo '<br />';
                         }
@@ -68,7 +67,6 @@
                             echo '.';
                         }
                         $i++;
-                        $rs->MoveNext();
 
                         if (empty($text) or is_numeric($text)) {
                             continue; // nothing to do
@@ -82,11 +80,10 @@
                         }
 
                         if ($newtext != $text) {
-                            $newtext = addslashes($newtext);
-                            execute_sql("UPDATE $table SET $column='$newtext' WHERE id=$id", false);
+                            $DB->execute("UPDATE $fulltable SET $column=? WHERE id=?", array($newtext, $id));
                         }
                     }
-                    rs_close($rs);
+                    $rs->close();
                 }
             }
         }
Index: admin/cliupgrade.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/cliupgrade.php,v
retrieving revision 1.11
diff -u -r1.11 cliupgrade.php
--- admin/cliupgrade.php	2 May 2008 09:47:20 -0000	1.11
+++ admin/cliupgrade.php	15 May 2008 21:10:28 -0000
@@ -860,16 +860,16 @@
         /// Both old .sql files and new install.xml are supported
         /// But we prioritise install.xml (XMLDB) if present
 
-        change_db_encoding(); // first try to change db encoding to utf8
-
-        if (!setup_is_unicodedb()) {
-            // If could not convert successfully, throw error, and prevent installation
-            console_write(STDERR,'unicoderequired', 'admin');
+        if (!$DB->setup_is_unicodedb()) {
+            if (!$DB->change_db_encoding()) {
+                // If could not convert successfully, throw error, and prevent installation
+                console_write(STDERR,'unicoderequired', 'admin');
+            }
         }
 
         $status = false;
         if (file_exists("$CFG->libdir/db/install.xml")) {
-            $status = install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
+            $status = $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
         } else {
             console_write(STDERR,"Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle or install.xml is not present.  See the lib/db directory.",'',false);
         }
Index: admin/cron.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/cron.php,v
retrieving revision 1.138
diff -u -r1.138 cron.php
--- admin/cron.php	1 May 2008 05:49:35 -0000	1.138
+++ admin/cron.php	15 May 2008 21:10:29 -0000
@@ -36,7 +36,7 @@
 
 /// Extra debugging (set in config.php)
     if (!empty($CFG->showcronsql)) {
-        $db->debug = true;
+        $DB->set_debug(true);
     }
     if (!empty($CFG->showcrondebugging)) {
         $CFG->debug = DEBUG_DEVELOPER;
Index: admin/index.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/index.php,v
retrieving revision 1.312
diff -u -r1.312 index.php
--- admin/index.php	2 May 2008 09:47:20 -0000	1.312
+++ admin/index.php	15 May 2008 21:10:30 -0000
@@ -61,14 +61,6 @@
         print_error('phpvaron', 'debug', '', array('file_uploads', $documentationlink));
     }
 
-    if (empty($CFG->prefix) && $CFG->dbfamily != 'mysql') {  //Enforce prefixes for everybody but mysql
-        print_error('prefixcannotbeempty', 'debug', '', array($CFG->prefix, $CFG->dbtype));
-    }
-
-    if ($CFG->dbfamily == 'oracle' && strlen($CFG->prefix) > 2) { //Max prefix length for Oracle is 2cc
-        print_error('prefixlimit', 'debug', '', $CFG->prefix);
-    }
-
 /// Check that config.php has been edited
 
     if ($CFG->wwwroot == "http://example.com/moodle") {
@@ -103,8 +95,7 @@
     }
 
 /// Check if the main tables have been installed yet or not.
-
-    if (! $tables = $db->Metatables() ) {    // No tables yet at all.
+    if (!$tables = $DB->get_tables() ) {    // No tables yet at all.
         $maintables = false;
 
     } else {                                 // Check for missing main tables
@@ -113,7 +104,7 @@
                          "course_sections", "log", "log_display", "modules",
                          "user");
         foreach ($mtables as $mtable) {
-            if (!in_array($CFG->prefix.$mtable, $tables)) {
+            if (!in_array($mtable, $tables)) {
                 $maintables = false;
                 break;
             }
@@ -164,20 +155,21 @@
         $CFG->debug = $origdebug;
         error_reporting($CFG->debug);
         upgrade_log_start();
-        $db->debug = true;
+        $DB->set_debug(true);
 
     /// Both old .sql files and new install.xml are supported
     /// But we prioritise install.xml (XMLDB) if present
 
-        change_db_encoding(); // first try to change db encoding to utf8
-        if (!setup_is_unicodedb()) {
-            // If could not convert successfully, throw error, and prevent installation
-            print_error('unicoderequired', 'admin');
+        if (!$DB->setup_is_unicodedb()) {
+            if (!$DB->change_db_encoding()) {
+                // If could not convert successfully, throw error, and prevent installation
+                print_error('unicoderequired', 'admin');
+            }
         }
 
         $status = false;
         if (file_exists("$CFG->libdir/db/install.xml")) {
-            $status = install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
+            $status = $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
         } else {
             print_error('dbnotsupport', 'debug', '', $CFG->dbtype);
         }
@@ -186,7 +178,7 @@
         set_config('unicodedb', 1);
 
     /// Continue with the instalation
-        $db->debug = false;
+        $DB->set_debug(false);
         if ($status) {
 
             /// Groups install is now in core above.
@@ -335,7 +327,7 @@
                 upgrade_language_pack();
 
                 print_heading($strdatabasechecking);
-                $db->debug=true;
+                $DB->set_debug(true);
             /// Launch the old main upgrade (if exists)
                 $status = true;
                 if (function_exists('main_upgrade')) {
@@ -345,7 +337,7 @@
                 if ($status && function_exists('xmldb_main_upgrade')) {
                     $status = xmldb_main_upgrade($CFG->version);
                 }
-                $db->debug=false;
+                $DB->set_debug(false);
             /// If successful, continue upgrading roles and setting everything properly
                 if ($status) {
                     if (!update_capabilities()) {
@@ -473,7 +465,7 @@
         $newsite->students = get_string("defaultcoursestudents");
         $newsite->timemodified = time();
 
-        if (!$newid = insert_record('course', $newsite)) {
+        if (!$newid = $DB->insert_record('course', $newsite)) {
             print_error('cannotsetupsite', 'error');
         }
         // make sure course context exists
@@ -486,7 +478,7 @@
         $cat = new object();
         $cat->name = get_string('miscellaneous');
         $cat->depth = 1;
-        if (!$catid = insert_record('course_categories', $cat)) {
+        if (!$catid = $DB->insert_record('course_categories', $cat)) {
             print_error('cannotsetupcategory', 'error');
         }
         // make sure category context exists
@@ -505,10 +497,10 @@
         blocks_repopulate_page($page);
 
         //add admin_tree block to site if not already present
-        if ($admintree = get_record('block', 'name', 'admin_tree')) {
+        if ($admintree = $DB->get_record('block', array('name'=>'admin_tree'))) {
             $page = page_create_object(PAGE_COURSE_VIEW, SITEID);
             blocks_execute_action($page, blocks_get_by_page($page), 'add', (int)$admintree->id, false, false);
-            if ($admintreeinstance = get_record('block_instance', 'pagetype', $page->type, 'pageid', SITEID, 'blockid', $admintree->id)) {
+            if ($admintreeinstance = $DB->get_record('block_instance', array('pagetype'=>$page->type, 'pageid'=>SITEID, 'blockid'=>$admintree->id))) {
                 blocks_execute_action($page, blocks_get_by_page($page), 'moveleft', $admintreeinstance, false, false);
             }
         }
@@ -522,7 +514,7 @@
     }
 
 /// Check if the guest user exists.  If not, create one.
-    if (! record_exists("user", "username", "guest")) {
+    if (!$DB->record_exists('user', array('username'=>'guest'))) {
         if (! $guest = create_guest_record()) {
             notify("Could not create guest user record !!!");
         }
Index: admin/timezone.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/timezone.php,v
retrieving revision 1.9
diff -u -r1.9 timezone.php
--- admin/timezone.php	2 May 2008 04:37:03 -0000	1.9
+++ admin/timezone.php	15 May 2008 21:10:30 -0000
@@ -2,7 +2,12 @@
 
     require_once('../config.php');
 
-    $zone = optional_param('zone', '', PARAM_PATH); //not a path, but it looks like it anyway
+    $zone = optional_param('zone', '', PARAM_RAW);
+
+    if (!is_numeric($zone)) {
+         //not a path, but it looks like it anyway
+         $zone = clean_param($zone, PARAM_PATH);
+    }    
 
     require_login();
 
@@ -17,24 +22,26 @@
 
     print_heading("");
 
-    if (!empty($zone) and confirm_sesskey()) {
-        $db->debug = true;
+    if (data_submitted() and !empty($zone) and confirm_sesskey()) {
         echo "<center>";
-        execute_sql("UPDATE {$CFG->prefix}user SET timezone = '$zone'");
-        $db->debug = false;
+        $DB->execute("UPDATE {user} SET timezone = ?", array($zone));
         echo "</center>";
 
         $USER->timezone = $zone;
+        $current = $zone;
+        notify('Timezone of all users changed', 'notifysuccess');
+    } else {
+        $current = 99;
     }
 
     require_once($CFG->dirroot.'/calendar/lib.php');
     $timezones = get_list_of_timezones();
 
-    echo '<center><form action="timezone.php" method="get">';
+    echo '<center><form action="timezone.php" method="post">';
     echo "$strusers ($strall): ";
-    choose_from_menu ($timezones, "zone", 99, get_string("serverlocaltime"), "", "99");
+    choose_from_menu ($timezones, "zone", $current, get_string("serverlocaltime"), "", "99");
     echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
-    echo "<input type=\"submit\" value=\"$strsavechanges\" />";
+    echo '<input type="submit" value="'.s($strsavechanges).'" />';
     echo "</form></center>";
 
     print_footer();
Index: admin/innodb.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/innodb.php,v
retrieving revision 1.9
diff -u -r1.9 innodb.php
--- admin/innodb.php	2 May 2008 04:37:02 -0000	1.9
+++ admin/innodb.php	15 May 2008 21:10:30 -0000
@@ -1,43 +1,44 @@
 <?php
 
-   require_once('../config.php');
-   require_once($CFG->libdir.'/adminlib.php');
+    require_once('../config.php');
+    require_once($CFG->libdir.'/adminlib.php');
 
-   admin_externalpage_setup('toinodb');
+    admin_externalpage_setup('toinodb');
 
-   $confirm = optional_param('confirm', 0, PARAM_BOOL);
+    $confirm = optional_param('confirm', 0, PARAM_BOOL);
 
-   require_login();
+    require_login();
 
-   require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
+    require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
 
-   admin_externalpage_print_header();
-   print_heading('Convert all MySQL tables from MYISAM to InnoDB');
+    admin_externalpage_print_header();
+    print_heading('Convert all MySQL tables from MYISAM to InnoDB');
 
-   if ($CFG->dbfamily != 'mysql') {
+    if ($CFG->dbfamily != 'mysql') {
         notice('This function is for MySQL databases only!', 'index.php');
-   }
+    }
 
-   if (data_submitted() and $confirm and confirm_sesskey()) {
+    if (data_submitted() and $confirm and confirm_sesskey()) {
 
-       notify('Please be patient and wait for this to complete...', 'notifysuccess');
+        notify('Please be patient and wait for this to complete...', 'notifysuccess');
 
-       if ($tables = $db->MetaTables()) {
-           $db->debug = true;
-           foreach ($tables as $table) {
-               execute_sql("ALTER TABLE $table TYPE=INNODB; ");
-           }
-           $db->debug = false;
-       }
-       notify('... done.', 'notifysuccess');
-       print_continue('index.php');
-       admin_externalpage_print_footer();
-
-   } else {
-       $optionsyes = array('confirm'=>'1', 'sesskey'=>sesskey());
-       notice_yesno('Are you sure you want convert all your tables to the InnoDB format?',
-                    'innodb.php', 'index.php', $optionsyes, NULL, 'post', 'get');
-       admin_externalpage_print_footer();
-   }
+        if ($tables = $DB->get_tables()) {
+            $DB->set_debug(true);
+            foreach ($tables as $table) {
+                $fulltable = $DB->get_prefix().$table;
+                $DB->change_database_structure("ALTER TABLE $fulltable TYPE=INNODB");
+            }
+            $DB->set_debug(false);
+        }
+        notify('... done.', 'notifysuccess');
+        print_continue('index.php');
+        admin_externalpage_print_footer();
+
+    } else {
+        $optionsyes = array('confirm'=>'1', 'sesskey'=>sesskey());
+        notice_yesno('Are you sure you want convert all your tables to the InnoDB format?',
+                     'innodb.php', 'index.php', $optionsyes, NULL, 'post', 'get');
+        admin_externalpage_print_footer();
+    }
 
 ?>
Index: admin/replace.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/replace.php,v
retrieving revision 1.11
diff -u -r1.11 replace.php
--- admin/replace.php	10 Apr 2008 03:44:09 -0000	1.11
+++ admin/replace.php	15 May 2008 21:10:30 -0000
@@ -34,16 +34,16 @@
 
 print_simple_box_start('center');
 
-if (!db_replace($search, $replace)) {
+if (!db_replace(stripslashes($search), stripslashes($replace))) {
     print_error('erroroccur', debug);
 }
 
 print_simple_box_end();
 
 /// Rebuild course cache which might be incorrect now
-notify('Rebuilding course cache...');
+notify('Rebuilding course cache...', 'notifysuccess');
 rebuild_course_cache();
-notify('...finished');
+notify('...finished', 'notifysuccess');
 
 print_continue('index.php');
 
Index: mod/glossary/edit.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/glossary/edit.php,v
retrieving revision 1.79
diff -u -r1.79 edit.php
--- mod/glossary/edit.php	4 Apr 2008 02:54:40 -0000	1.79
+++ mod/glossary/edit.php	15 May 2008 21:11:25 -0000
@@ -157,7 +157,7 @@
 
         $toform = new object();
 
-        if ($categoriesarr = get_records_menu("glossary_entries_categories", "entryid", $e, '', 'id, categoryid')){
+        if ($categoriesarr = $DB->get_records_menu("glossary_entries_categories", array("entryid"=>$e), '', 'id, categoryid')){
             $toform->categories = array_values($categoriesarr);
         } else {
             $toform->categories = array(0);
@@ -181,7 +181,7 @@
             die;
         }
 
-        if ( $aliases = get_records_menu("glossary_alias", "entryid", $e, '', 'id, alias') ) {
+        if ( $aliases = $DB->get_records_menu("glossary_alias", array("entryid"=>$e), '', 'id, alias') ) {
             $toform->aliases = implode("\n", $aliases) . "\n";
         }
         $mform->set_data($toform);
Index: mod/glossary/edit_form.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/glossary/edit_form.php,v
retrieving revision 1.8
diff -u -r1.8 edit_form.php
--- mod/glossary/edit_form.php	23 Nov 2007 22:15:09 -0000	1.8
+++ mod/glossary/edit_form.php	15 May 2008 21:11:25 -0000
@@ -5,7 +5,7 @@
 
     function definition() {
 
-        global $CFG, $COURSE;
+        global $CFG, $COURSE, $DB;
         $mform    =& $this->_form;
 
         $glossary =& $this->_customdata['glossary'];
@@ -29,7 +29,7 @@
         $mform->addElement('format');
 
         $categories = array();
-        if ($categories = get_records_menu('glossary_categories', 'glossaryid', $glossary->id, 'name ASC', 'id, name')){
+        if ($categories = $DB->get_records_menu('glossary_categories', array('glossaryid'=>$glossary->id), 'name ASC', 'id, name')){
             $categories = array(0 => get_string('notcategorised', 'glossary')) + $categories;
         } else {
             $categories = array(0 => get_string('notcategorised', 'glossary'));
Index: lib/grade/lib_wrapper.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/grade/lib_wrapper.php,v
retrieving revision 1.2
diff -u -r1.2 lib_wrapper.php
--- lib/grade/lib_wrapper.php	15 Nov 2007 06:44:27 -0000	1.2
+++ lib/grade/lib_wrapper.php	15 May 2008 21:11:22 -0000
@@ -24,6 +24,7 @@
 ///////////////////////////////////////////////////////////////////////////
 
 class grade_lib_wrapper {
+/*
     function get_records_sql($sql, $limitfrom='', $limitnum='') {
         return get_records_sql($sql, $limitfrom, $limitnum);
     }
@@ -107,7 +108,7 @@
     function rs_close(&$rs) {
         return;
     }
-    
+*/    
     function get_coursemodule_from_instance($modulename, $instance, $courseid=0) {
         return get_coursemodule_from_instance($modulename, $instance, $courseid);
     }
Index: lib/grade/grade_item.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/grade/grade_item.php,v
retrieving revision 1.169
diff -u -r1.169 grade_item.php
--- lib/grade/grade_item.php	4 Apr 2008 02:54:33 -0000	1.169
+++ lib/grade/grade_item.php	15 May 2008 21:11:22 -0000
@@ -774,10 +774,12 @@
      * @return void
      */
     function force_regrading() {
+        global $DB;
         $this->needsupdate = 1;
         //mark this item and course item only - categories and calculated items are always regraded
-        $wheresql = "(itemtype='course' OR id={$this->id}) AND courseid={$this->courseid}";
-        set_field_select('grade_items', 'needsupdate', 1, $wheresql);
+        $wheresql = "(itemtype='course' OR id=?) AND courseid=?";
+        $params   = array($this->id, $this->courseid);
+        $DB->set_field_select('grade_items', 'needsupdate', 1, $wheresql, $params);
     }
 
     /**
Index: lib/xmldb/classes/XMLDBField.class.php
===================================================================
RCS file: lib/xmldb/classes/XMLDBField.class.php
diff -N lib/xmldb/classes/XMLDBField.class.php
--- lib/xmldb/classes/XMLDBField.class.php	2 Jan 2008 16:49:11 -0000	1.14
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,912 +0,0 @@
-<?php // $Id: XMLDBField.class.php,v 1.14 2008/01/02 16:49:11 stronk7 Exp $
-
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.com                                            //
-//                                                                       //
-// Copyright (C) 1999 onwards Martin Dougiamas        http://dougiamas.com  //
-//           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //
-//                                                                       //
-// This program is free software; you can redistribute it and/or modify  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
-
-/// This class represent one XMLDB Field
-
-class XMLDBField extends XMLDBObject {
-
-    var $type;
-    var $length;
-    var $unsigned;
-    var $notnull;
-    var $default;
-    var $sequence;
-    var $enum;
-    var $enumvalues;
-    var $decimals;
-
-    /**
-     * Creates one new XMLDBField
-     */
-    function XMLDBField($name) {
-        parent::XMLDBObject($name);
-        $this->type = NULL;
-        $this->length = NULL;
-        $this->unsigned = true;
-        $this->notnull = false;
-        $this->default = NULL;
-        $this->sequence = false;
-        $this->enum = false;
-        $this->enumvalues = NULL;
-        $this->decimals = NULL;
-    }
-
-    /**
-     * Set all the attributes of one XMLDBField
-     *
-     * @param string type XMLDB_TYPE_INTEGER, XMLDB_TYPE_NUMBER, XMLDB_TYPE_CHAR, XMLDB_TYPE_TEXT, XMLDB_TYPE_BINARY
-     * @param string precision length for integers and chars, two-comma separated numbers for numbers and 'small', 'medium', 'big' for texts and binaries
-     * @param string unsigned XMLDB_UNSIGNED or null (or false)
-     * @param string notnull XMLDB_NOTNULL or null (or false)
-     * @param string sequence XMLDB_SEQUENCE or null (or false)
-     * @param string enum XMLDB_ENUM or null (or false)
-     * @param array enumvalues an array of possible values if XMLDB_ENUM is set
-     * @param string default meaningful default o null (or false)
-     */
-    function setAttributes($type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $enum=null, $enumvalues=null, $default=null, $previous=null) {
-        $this->type = $type;
-    /// Try to split the precision into length and decimals and apply
-    /// each one as needed
-        $precisionarr = explode(',', $precision);
-        if (isset($precisionarr[0])) {
-            $this->length = trim($precisionarr[0]);
-        }
-        if (isset($precisionarr[1])) {
-            $this->decimals = trim($precisionarr[1]);
-        }
-        $this->precision = $type;
-        $this->unsigned = !empty($unsigned) ? true : false;
-        $this->notnull = !empty($notnull) ? true : false;
-        $this->sequence = !empty($sequence) ? true : false;
-        $this->enum = !empty($enum) ? true : false;
-    /// Accept both quoted and non-quoted vales (quoting them)a
-        if (is_array($enumvalues)) {
-            $this->enumvalues = array();
-            foreach ($enumvalues as $value) {
-            /// trim each value quotes
-                $value = trim($value, "'");
-            /// add them back
-                $value = "'" . $value . "'";
-                $this->enumvalues[] = $value;
-            }
-        }
-        $this->setDefault($default);
-
-        $this->previous = $previous;
-    }
-
-    /**
-     * Get the type
-     */
-    function getType() {
-        return $this->type;
-    }
-
-    /**
-     * Get the length
-     */
-    function getLength() {
-        return $this->length;
-    }
-
-    /**
-     * Get the decimals
-     */
-    function getDecimals() {
-        return $this->decimals;
-    }
-
-    /**
-     * Get the notnull
-     */
-    function getNotNull() {
-        return $this->notnull;
-    }
-
-    /**
-     * Get the unsigned
-     */
-    function getUnsigned() {
-        return $this->unsigned;
-    }
-
-    /**
-     * Get the sequence
-     */
-    function getSequence() {
-        return $this->sequence;
-    }
-
-    /**
-     * Get the enum
-     */
-    function getEnum() {
-        return $this->enum;
-    }
-
-    /**
-     * Get the enumvalues
-     */
-    function getEnumValues() {
-        return $this->enumvalues;
-    }
-
-    /**
-     * Get the default
-     */
-    function getDefault() {
-        return $this->default;
-    }
-
-    /**
-     * Set the field type
-     */
-    function setType($type) {
-        $this->type = $type;
-    }
-
-    /**
-     * Set the field length
-     */
-    function setLength($length) {
-        $this->length = $length;
-    }
-
-    /**
-     * Set the field decimals
-     */
-    function setDecimals($decimals) {
-        $this->decimals = $decimals;
-    }
-
-    /**
-     * Set the field unsigned
-     */
-    function setUnsigned($unsigned=true) {
-        $this->unsigned = $unsigned;
-    }
-
-    /**
-     * Set the field notnull
-     */
-    function setNotNull($notnull=true) {
-        $this->notnull = $notnull;
-    }
-
-    /**
-     * Set the field sequence
-     */
-    function setSequence($sequence=true) {
-        $this->sequence = $sequence;
-    }
-
-    /**
-     * Set the field enum
-     */
-    function setEnum($enum=true) {
-        $this->enum = $enum;
-    }
-
-    /**
-     * Set the field enumvalues, quoting unquoted values
-     */
-    function setEnumValues($enumvalues) {
-        if (is_array($enumvalues)) {
-            $this->enumvalues = array();
-            foreach ($enumvalues as $value) {
-            /// trim each value quotes
-                $value = trim($value, "'");
-            /// add them back
-                $value = "'" . $value . "'";
-                $this->enumvalues[] = $value;
-            }
-        }
-    }
-
-    /**
-     * Set the field default
-     */
-    function setDefault($default) {
-    /// Check, warn and auto-fix '' (empty) defaults for CHAR NOT NULL columns, changing them
-    /// to NULL so XMLDB will apply the proper default
-        if ($this->type == XMLDB_TYPE_CHAR && $this->notnull && $default === '') {
-            $this->errormsg = 'XMLDB has detected one CHAR NOT NULL column (' . $this->name . ") with '' (empty string) as DEFAULT value. This type of columns must have one meaningful DEFAULT declared or none (NULL). XMLDB have fixed it automatically changing it to none (NULL). The process will continue ok and proper defaults will be created accordingly with each DB requirements. Please fix it in source (XML and/or upgrade script) to avoid this message to be displayed.";
-            $this->debug($this->errormsg);
-            $default = NULL;
-        }
-        $this->default = $default;
-    }
-
-    /**
-     * Load data from XML to the table
-     */
-    function arr2XMLDBField($xmlarr) {
-
-        $result = true;
-
-    /// Debug the table
-    /// traverse_xmlize($xmlarr);                   //Debug
-    /// print_object ($GLOBALS['traverse_array']);  //Debug
-    /// $GLOBALS['traverse_array']="";              //Debug
-
-    /// Process table attributes (name, type, length, unsigned,
-    /// notnull, sequence, enum, enumvalues, decimals, comment,
-    /// previous, next)
-        if (isset($xmlarr['@']['NAME'])) {
-            $this->name = trim($xmlarr['@']['NAME']);
-        } else {
-            $this->errormsg = 'Missing NAME attribute';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-
-        if (isset($xmlarr['@']['TYPE'])) {
-        /// Check for valid type
-            $type = $this->getXMLDBFieldType(trim($xmlarr['@']['TYPE']));
-            if ($type) {
-                $this->type = $type;
-            } else {
-                $this->errormsg = 'Invalid TYPE attribute';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        } else {
-            $this->errormsg = 'Missing TYPE attribute';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-
-        if (isset($xmlarr['@']['LENGTH'])) {
-            $length = trim($xmlarr['@']['LENGTH']);
-        /// Check for integer values
-            if ($this->type == XMLDB_TYPE_INTEGER ||
-                $this->type == XMLDB_TYPE_NUMBER ||
-                $this->type == XMLDB_TYPE_CHAR) {
-                if (!(is_numeric($length)&&(intval($length)==floatval($length)))) {
-                    $this->errormsg = 'Incorrect LENGTH attribute for int, number or char fields';
-                    $this->debug($this->errormsg);
-                    $result = false;
-                } else if (!$length) {
-                    $this->errormsg = 'Zero LENGTH attribute';
-                    $this->debug($this->errormsg);
-                    $result = false;
-                }
-            }
-        /// Check for big, medium, small to be applied to text and binary
-            if ($this->type == XMLDB_TYPE_TEXT ||
-                $this->type == XMLDB_TYPE_BINARY) {
-                if (!$length) {
-                    $length == 'big';
-                }
-                if ($length != 'big' &&
-                    $length != 'medium' &&
-                    $length != 'small') {
-                    $this->errormsg = 'Incorrect LENGTH attribute for text and binary fields (only big, medium and small allowed)';
-                    $this->debug($this->errormsg);
-                    $result = false;
-                }
-            }
-        /// Finally, set the length
-            $this->length = $length;
-        }
-
-        if (isset($xmlarr['@']['UNSIGNED'])) {
-            $unsigned = strtolower(trim($xmlarr['@']['UNSIGNED']));
-            if ($unsigned == 'true') {
-                $this->unsigned = true;
-            } else if ($unsigned == 'false') {
-                $this->unsigned = false;
-            } else {
-                $this->errormsg = 'Incorrect UNSIGNED attribute (true/false allowed)';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        }
-
-        if (isset($xmlarr['@']['NOTNULL'])) {
-            $notnull = strtolower(trim($xmlarr['@']['NOTNULL']));
-            if ($notnull == 'true') {
-                $this->notnull = true;
-            } else if ($notnull == 'false') {
-                $this->notnull = false;
-            } else {
-                $this->errormsg = 'Incorrect NOTNULL attribute (true/false allowed)';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        }
-
-        if (isset($xmlarr['@']['SEQUENCE'])) {
-            $sequence = strtolower(trim($xmlarr['@']['SEQUENCE']));
-            if ($sequence == 'true') {
-                $this->sequence = true;
-            } else if ($sequence == 'false') {
-                $this->sequence = false;
-            } else {
-                $this->errormsg = 'Incorrect SEQUENCE attribute (true/false allowed)';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        }
-
-        if (isset($xmlarr['@']['DEFAULT'])) {
-            $this->setDefault(trim($xmlarr['@']['DEFAULT']));
-        }
-
-        if (isset($xmlarr['@']['ENUM'])) {
-            $enum = strtolower(trim($xmlarr['@']['ENUM']));
-            if ($enum == 'true') {
-                $this->enum = true;
-            } else if ($enum == 'false') {
-                $this->enum = false;
-            } else {
-                $this->errormsg = 'Incorrect ENUM attribute (true/false allowed)';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        }
-
-        if (isset($xmlarr['@']['ENUMVALUES'])) {
-            $enumvalues = trim($xmlarr['@']['ENUMVALUES']);
-            if (!$this->enum) {
-                $this->errormsg = 'Wrong ENUMVALUES attribute (not ENUM)';
-                $this->debug($this->errormsg);
-                $result = false;
-                $this->enumvalues = $enumvalues;
-            } else {
-            /// Check we have a valid list (comma separated of quoted values)
-                $enumarr = explode(',',$enumvalues);
-                if ($enumarr) {
-                    foreach ($enumarr as $key => $enumelement) {
-                    /// Clear some spaces
-                        $enumarr[$key] = trim($enumelement);
-                        $enumelement = trim($enumelement);
-                    /// Skip if under error
-                        if (!$result) {
-                            continue;
-                        }
-                    /// Look for quoted strings
-                        if (substr($enumelement, 0, 1) != "'" ||
-                            substr($enumelement, -1, 1) != "'") {
-                            $this->errormsg = 'Incorrect ENUMVALUES attribute (some value is not properly quoted)';
-                            $this->debug($this->errormsg);
-                            $result = false;
-                        }
-                    }
-                } else {
-                    $this->errormsg = 'Incorrect ENUMVALUES attribute (comma separated of quoted values)';
-                    $this->debug($this->errormsg);
-                    $result = false;
-                }
-            }
-        } else if ($this->enum) {
-            $this->errormsg = 'Incorrect ENUMVALUES attribute (field is not declared as ENUM)';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-    /// Finally, set the value
-        if ($this->enum) {
-            $this->enumvalues = $enumarr;
-        }
-
-        $decimals = NULL;
-        if (isset($xmlarr['@']['DECIMALS'])) {
-            $decimals = trim($xmlarr['@']['DECIMALS']);
-        /// Check for integer values
-            if ($this->type == XMLDB_TYPE_NUMBER ||
-                $this->type == XMLDB_TYPE_FLOAT) {
-                if (!(is_numeric($decimals)&&(intval($decimals)==floatval($decimals)))) {
-                    $this->errormsg = 'Incorrect DECIMALS attribute for number field';
-                    $this->debug($this->errormsg);
-                    $result = false;
-                } else if ($this->length <= $decimals){
-                    $this->errormsg = 'Incorrect DECIMALS attribute (bigget than length)';
-                    $this->debug($this->errormsg);
-                    $result = false;
-                }
-            } else {
-                $this->errormsg = 'Incorrect DECIMALS attribute for non-number field';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        } else {
-            if ($this->type == XMLDB_TYPE_NUMBER) {
-                $decimals = 0;
-            }
-        }
-     // Finally, set the decimals
-        if ($this->type == XMLDB_TYPE_NUMBER ||
-            $this->type == XMLDB_TYPE_FLOAT) {
-            $this->decimals = $decimals;
-        }
-
-        if (isset($xmlarr['@']['COMMENT'])) {
-            $this->comment = trim($xmlarr['@']['COMMENT']);
-        }
-
-        if (isset($xmlarr['@']['PREVIOUS'])) {
-            $this->previous = trim($xmlarr['@']['PREVIOUS']);
-        }
-
-        if (isset($xmlarr['@']['NEXT'])) {
-            $this->next = trim($xmlarr['@']['NEXT']);
-        }
-
-    /// Set some attributes
-        if ($result) {
-            $this->loaded = true;
-        }
-        $this->calculateHash();
-        return $result;
-    }
-
-    /**
-     * This function returns the correct XMLDB_TYPE_XXX value for the
-     * string passed as argument
-     */
-    function getXMLDBFieldType($type) {
-
-        $result = XMLDB_TYPE_INCORRECT;
-
-        switch (strtolower($type)) {
-            case 'int':
-                $result = XMLDB_TYPE_INTEGER;
-                break;
-            case 'number':
-                $result = XMLDB_TYPE_NUMBER;
-                break;
-            case 'float':
-                $result = XMLDB_TYPE_FLOAT;
-                break;
-            case 'char':
-                $result = XMLDB_TYPE_CHAR;
-                break;
-            case 'text':
-                $result = XMLDB_TYPE_TEXT;
-                break;
-            case 'binary':
-                $result = XMLDB_TYPE_BINARY;
-                break;
-            case 'datetime':
-                $result = XMLDB_TYPE_DATETIME;
-                break;
-        }
-    /// Return the normalized XMLDB_TYPE
-        return $result;
-    }
-
-    /**
-     * This function returns the correct name value for the
-     * XMLDB_TYPE_XXX passed as argument
-     */
-    function getXMLDBTypeName($type) {
-
-        $result = "";
-
-        switch (strtolower($type)) {
-            case XMLDB_TYPE_INTEGER:
-                $result = 'int';
-                break;
-            case XMLDB_TYPE_NUMBER:
-                $result = 'number';
-                break;
-            case XMLDB_TYPE_FLOAT:
-                $result = 'float';
-                break;
-            case XMLDB_TYPE_CHAR:
-                $result = 'char';
-                break;
-            case XMLDB_TYPE_TEXT:
-                $result = 'text';
-                break;
-            case XMLDB_TYPE_BINARY:
-                $result = 'binary';
-                break;
-            case XMLDB_TYPE_DATETIME:
-                $result = 'datetime';
-                break;
-        }
-    /// Return the normalized name
-        return $result;
-    }
-
-    /**
-     * This function calculate and set the hash of one XMLDBField
-     */
-     function calculateHash($recursive = false) {
-        if (!$this->loaded) {
-            $this->hash = NULL;
-        } else {
-            $key = $this->name . $this->type . $this->length .
-                   $this->unsigned . $this->notnull . $this->sequence .
-                   $this->decimals . $this->comment;
-            if ($this->enum) {
-                $key .= implode(', ',$this->enumvalues);
-            }
-            $this->hash = md5($key);
-        }
-    }
-
-    /**
-     *This function will output the XML text for one field
-     */
-    function xmlOutput() {
-        $o = '';
-        $o.= '        <FIELD NAME="' . $this->name . '"';
-        $o.= ' TYPE="' . $this->getXMLDBTypeName($this->type) . '"';
-        if ($this->length) {
-            $o.= ' LENGTH="' . $this->length . '"';
-        }
-        if ($this->notnull) {
-            $notnull = 'true';
-        } else {
-            $notnull = 'false';
-        }
-        $o.= ' NOTNULL="' . $notnull . '"';
-        if ($this->unsigned) {
-            $unsigned = 'true';
-        } else {
-            $unsigned = 'false';
-        }
-        if ($this->type == XMLDB_TYPE_INTEGER ||
-            $this->type == XMLDB_TYPE_NUMBER ||
-            $this->type == XMLDB_TYPE_FLOAT) {
-            if ($this->unsigned) {
-                $unsigned = 'true';
-            } else {
-                $unsigned = 'false';
-            }
-            $o.= ' UNSIGNED="' . $unsigned . '"';
-        }
-        if (!$this->sequence && $this->default !== NULL) {
-            $o.= ' DEFAULT="' . $this->default . '"';
-        }
-        if ($this->sequence) {
-            $sequence = 'true';
-        } else {
-            $sequence = 'false';
-        }
-        $o.= ' SEQUENCE="' . $sequence . '"';
-        if ($this->enum) {
-            $enum = 'true';
-        } else {
-            $enum = 'false';
-        }
-        $o.= ' ENUM="' . $enum . '"';
-        if ($this->enum) {
-            $o.= ' ENUMVALUES="' . implode(', ', $this->enumvalues) . '"';
-        }
-        if ($this->decimals !== NULL) {
-            $o.= ' DECIMALS="' . $this->decimals . '"';
-        }
-        if ($this->comment) {
-            $o.= ' COMMENT="' . htmlspecialchars($this->comment) . '"';
-        }
-        if ($this->previous) {
-            $o.= ' PREVIOUS="' . $this->previous . '"';
-        }
-        if ($this->next) {
-            $o.= ' NEXT="' . $this->next . '"';
-        }
-        $o.= '/>' . "\n";
-
-        return $o;
-    }
-
-    /**
-     * This function will set all the attributes of the XMLDBField object
-     * based on information passed in one ADOField
-     */
-    function setFromADOField($adofield) {
-
-    /// Calculate the XMLDB_TYPE
-        switch (strtolower($adofield->type)) {
-            case 'int':
-            case 'tinyint':
-            case 'smallint':
-            case 'bigint':
-            case 'integer':
-                $this->type = XMLDB_TYPE_INTEGER;
-                break;
-            case 'number':
-            case 'decimal':
-            case 'dec':
-            case 'numeric':
-                $this->type = XMLDB_TYPE_NUMBER;
-                break;
-            case 'float':
-            case 'double':
-                $this->type = XMLDB_TYPE_FLOAT;
-                break;
-            case 'char':
-            case 'varchar':
-            case 'enum':
-                $this->type = XMLDB_TYPE_CHAR;
-                break;
-            case 'text':
-            case 'tinytext':
-            case 'mediumtext':
-            case 'longtext':
-                $this->type = XMLDB_TYPE_TEXT;
-                break;
-            case 'blob':
-            case 'tinyblob':
-            case 'mediumblob':
-            case 'longblob':
-                $this->type = XMLDB_TYPE_BINARY;
-                break;
-            case 'datetime':
-            case 'timestamp':
-                $this->type = XMLDB_TYPE_DATETIME;
-                break;
-            default:
-                $this->type = XMLDB_TYPE_TEXT;
-        }
-    /// Calculate the length of the field
-        if ($adofield->max_length > 0 &&
-               ($this->type == XMLDB_TYPE_INTEGER ||
-                $this->type == XMLDB_TYPE_NUMBER  ||
-                $this->type == XMLDB_TYPE_FLOAT   ||
-                $this->type == XMLDB_TYPE_CHAR)) {
-            $this->length = $adofield->max_length;
-        }
-        if ($this->type == XMLDB_TYPE_TEXT) {
-            switch (strtolower($adofield->type)) {
-                case 'tinytext':
-                case 'text':
-                    $this->length = 'small';
-                    break;
-                case 'mediumtext':
-                    $this->length = 'medium';
-                    break;
-                case 'longtext':
-                    $this->length = 'big';
-                    break;
-                default:
-                    $this->length = 'small';
-            }
-        }
-        if ($this->type == XMLDB_TYPE_BINARY) {
-            switch (strtolower($adofield->type)) {
-                case 'tinyblob':
-                case 'blob':
-                    $this->length = 'small';
-                    break;
-                case 'mediumblob':
-                    $this->length = 'medium';
-                    break;
-                case 'longblob':
-                    $this->length = 'big';
-                    break;
-                default:
-                    $this->length = 'small';
-            }
-        }
-    /// Calculate the decimals of the field
-        if ($adofield->max_length > 0 &&
-            $adofield->scale &&
-               ($this->type == XMLDB_TYPE_NUMBER ||
-                $this->type == XMLDB_TYPE_FLOAT)) {
-            $this->decimals = $adofield->scale;
-        }
-    /// Calculate the unsigned field
-        if ($adofield->unsigned &&
-               ($this->type == XMLDB_TYPE_INTEGER ||
-                $this->type == XMLDB_TYPE_NUMBER  ||
-                $this->type == XMLDB_TYPE_FLOAT)) {
-            $this->unsigned = true;
-        }
-    /// Calculate the notnull field
-        if ($adofield->not_null) {
-            $this->notnull = true;
-        }
-    /// Calculate the default field
-        if ($adofield->has_default) {
-            $this->default = $adofield->default_value;
-        }
-    /// Calculate the sequence field
-        if ($adofield->auto_increment) {
-            $this->sequence = true;
-        /// Sequence fields are always unsigned
-            $this->unsigned = true;
-        }
-    /// Calculate the enum and enumvalues field
-        if ($adofield->type == 'enum') {
-            $this->enum = true;
-            $this->enumvalues = $adofield->enums;
-        }
-    /// Some more fields
-        $this->loaded = true;
-        $this->changed = true;
-    }
-
-    /**
-     * Returns the PHP code needed to define one XMLDBField
-     */
-    function getPHP($includeprevious=true) {
-
-        $result = '';
-
-    /// The XMLDBTYPE
-        switch ($this->getType()) {
-            case XMLDB_TYPE_INTEGER:
-                $result .= 'XMLDB_TYPE_INTEGER' . ', ';
-                break;
-            case XMLDB_TYPE_NUMBER:
-                $result .= 'XMLDB_TYPE_NUMBER' . ', ';
-                break;
-            case XMLDB_TYPE_FLOAT:
-                $result .= 'XMLDB_TYPE_FLOAT' . ', ';
-                break;
-            case XMLDB_TYPE_CHAR:
-                $result .= 'XMLDB_TYPE_CHAR' . ', ';
-                break;
-            case XMLDB_TYPE_TEXT:
-                $result .= 'XMLDB_TYPE_TEXT' . ', ';
-                break;
-            case XMLDB_TYPE_BINARY:
-                $result .= 'XMLDB_TYPE_BINARY' . ', ';
-                break;
-            case XMLDB_TYPE_DATETIME:
-                $result .= 'XMLDB_TYPE_DATETIME' . ', ';
-                break;
-            case XMLDB_TYPE_TIMESTAMP:
-                $result .= 'XMLDB_TYPE_TIMESTAMP' . ', ';
-                break;
-        }
-    /// The length
-        $length = $this->getLength();
-        $decimals = $this->getDecimals();
-        if (!empty($length)) {
-            $result .= "'" . $length;
-            if (!empty($decimals)) {
-                $result .= ', ' . $decimals;
-            }
-            $result .= "', ";
-        } else {
-            $result .= 'null, ';
-        }
-    /// Unsigned (only applicable to numbers)
-        $unsigned = $this->getUnsigned();
-        if (!empty($unsigned) &&
-           ($this->getType() == XMLDB_TYPE_INTEGER || $this->getType() == XMLDB_TYPE_NUMBER || $this->getType() == XMLDB_TYPE_FLOAT)) {
-            $result .= 'XMLDB_UNSIGNED' . ', ';
-        } else {
-            $result .= 'null, ';
-        }
-    /// Not Null
-        $notnull = $this->getNotnull();
-        if (!empty($notnull)) {
-            $result .= 'XMLDB_NOTNULL' . ', ';
-        } else {
-            $result .= 'null, ';
-        }
-    /// Sequence
-        $sequence = $this->getSequence();
-        if (!empty($sequence)) {
-            $result .= 'XMLDB_SEQUENCE' . ', ';
-        } else {
-            $result .= 'null, ';
-        }
-    /// Enum
-        $enum = $this->getEnum();
-        if (!empty($enum)) {
-            $result .= 'XMLDB_ENUM' . ', ';
-        } else {
-            $result .= 'null, ';
-        }
-    /// Enumvalues
-        $enumvalues = $this->getEnumValues();
-        if (!empty($enumvalues)) {
-            $result .= 'array(' . implode(', ', $enumvalues) . '), ';
-        } else {
-            $result .= 'null, ';
-        }
-    /// Default
-        $default =  $this->getDefault();
-        if ($default !== null && !$this->getSequence()) {
-            $result .= "'" . $default . "'";
-        } else {
-            $result .= 'null';
-        }
-    /// Previous (decided by parameter)
-        if ($includeprevious) {
-            $previous = $this->getPrevious();
-            if (!empty($previous)) {
-                $result .= ", '" . $previous . "'";
-            } else {
-                $result .= ', null';
-            }
-        }
-    /// Return result
-        return $result;
-    }
-
-    /**
-     * Shows info in a readable format
-     */
-    function readableInfo() {
-        $o = '';
-    /// type
-        $o .= $this->getXMLDBTypeName($this->type);
-    /// length
-        if ($this->type == XMLDB_TYPE_INTEGER ||
-            $this->type == XMLDB_TYPE_NUMBER  ||
-            $this->type == XMLDB_TYPE_FLOAT   ||
-            $this->type == XMLDB_TYPE_CHAR) {
-            if ($this->length) {
-                $o .= ' (' . $this->length;
-                if ($this->type == XMLDB_TYPE_NUMBER  ||
-                    $this->type == XMLDB_TYPE_FLOAT) {
-                    if ($this->decimals !== NULL) {
-                        $o .= ', ' . $this->decimals;
-                    }
-                }
-                $o .= ')';
-            }
-        }
-        if ($this->type == XMLDB_TYPE_TEXT ||
-            $this->type == XMLDB_TYPE_BINARY) {
-                $o .= ' (' . $this->length . ')';
-        }
-    /// enum
-        if ($this->enum) {
-            $o .= ' enum(' . implode(', ', $this->enumvalues) . ')';
-        }
-    /// unsigned
-        if ($this->type == XMLDB_TYPE_INTEGER ||
-            $this->type == XMLDB_TYPE_NUMBER ||
-            $this->type == XMLDB_TYPE_FLOAT) {
-            if ($this->unsigned) {
-                $o .= ' unsigned';
-            } else {
-                $o .= ' signed';
-            }
-        }
-    /// not null
-        if ($this->notnull) {
-            $o .= ' not null';
-        }
-    /// default
-        if ($this->default !== NULL) {
-            $o .= ' default ';
-            if ($this->type == XMLDB_TYPE_CHAR ||
-                $this->type == XMLDB_TYPE_TEXT) {
-                    $o .= "'" . $this->default . "'";
-            } else {
-                $o .= $this->default;
-            }
-        }
-    /// sequence
-        if ($this->sequence) {
-            $o .= ' auto-numbered';
-        }
-
-        return $o;
-    }
-}
-
-?>
Index: lib/xmldb/classes/XMLDBConstants.php
===================================================================
RCS file: lib/xmldb/classes/XMLDBConstants.php
diff -N lib/xmldb/classes/XMLDBConstants.php
--- lib/xmldb/classes/XMLDBConstants.php	10 Oct 2007 05:25:14 -0000	1.5
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,74 +0,0 @@
-<?php // $Id: XMLDBConstants.php,v 1.5 2007/10/10 05:25:14 nicolasconnault Exp $
-
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.com                                            //
-//                                                                       //
-// Copyright (C) 1999 onwards Martin Dougiamas        http://dougiamas.com  //
-//           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //
-//                                                                       //
-// This program is free software; you can redistribute it and/or modify  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
-
-/// This file contains all the constants and variables used
-/// by the XMLDB interface
-
-/// First, some constants to be used by actions
-    define('ACTION_NONE',             0);  //Default flags for class
-    define('ACTION_GENERATE_HTML',    1);  //The invoke function will return HTML
-    define('ACTION_GENERATE_XML',     2);  //The invoke function will return HTML
-    define('ACTION_HAVE_SUBACTIONS',  1);  //The class can have subaction
-
-/// Now the allowed DB Field Types
-    define ('XMLDB_TYPE_INCORRECT',   0);  //Wrong DB Type
-    define ('XMLDB_TYPE_INTEGER',     1);  //Integer
-    define ('XMLDB_TYPE_NUMBER',      2);  //Decimal number
-    define ('XMLDB_TYPE_FLOAT',       3);  //Floating Point number
-    define ('XMLDB_TYPE_CHAR',        4);  //String
-    define ('XMLDB_TYPE_TEXT',        5);  //Text
-    define ('XMLDB_TYPE_BINARY',      6);  //Binary
-    define ('XMLDB_TYPE_DATETIME',    7);  //Datetime
-    define ('XMLDB_TYPE_TIMESTAMP',   8);  //Timestamp
-
-/// Now the allowed DB Keys
-    define ('XMLDB_KEY_INCORRECT',     0);  //Wrong DB Key
-    define ('XMLDB_KEY_PRIMARY',       1);  //Primary Keys
-    define ('XMLDB_KEY_UNIQUE',        2);  //Unique Keys
-    define ('XMLDB_KEY_FOREIGN',       3);  //Foreign Keys
-    define ('XMLDB_KEY_CHECK',         4);  //Check Constraints - NOT USED!
-    define ('XMLDB_KEY_FOREIGN_UNIQUE',5);  //Foreign Key + Unique Key
-
-/// Now the allowed Statement Types
-    define ('XMLDB_STATEMENT_INCORRECT',   0);  //Wrong Statement Type
-    define ('XMLDB_STATEMENT_INSERT',      1);  //Insert Statements
-    define ('XMLDB_STATEMENT_UPDATE',      2);  //Update Statements
-    define ('XMLDB_STATEMENT_DELETE',      3);  //Delete Statements
-    define ('XMLDB_STATEMENT_CUSTOM',      4);  //Custom Statements
-
-/// Some other useful Constants
-    define ('XMLDB_UNSIGNED',        true);  //If the field is going to be unsigned
-    define ('XMLDB_NOTNULL',         true);  //If the field is going to be not null
-    define ('XMLDB_SEQUENCE',        true);  //If the field is going to be a sequence
-    define ('XMLDB_ENUM',            true);  //If the field is going to be a enumeration of possible fields
-    define ('XMLDB_INDEX_UNIQUE',    true);  //If the index is going to be unique
-    define ('XMLDB_INDEX_NOTUNIQUE',false);  //If the index is NOT going to be unique
-
-/// Some strings used widely
-    define ('XMLDB_LINEFEED', "\n");
-    define ('XMLDB_PHP_HEADER', '    if ($result && $oldversion < XXXXXXXXXX) {' . XMLDB_LINEFEED);
-    define ('XMLDB_PHP_FOOTER', '    }' . XMLDB_LINEFEED);
-?>
Index: lib/xmldb/classes/XMLDBIndex.class.php
===================================================================
RCS file: lib/xmldb/classes/XMLDBIndex.class.php
diff -N lib/xmldb/classes/XMLDBIndex.class.php
--- lib/xmldb/classes/XMLDBIndex.class.php	10 Oct 2007 05:25:14 -0000	1.9
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,264 +0,0 @@
-<?php // $Id: XMLDBIndex.class.php,v 1.9 2007/10/10 05:25:14 nicolasconnault Exp $
-
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.com                                            //
-//                                                                       //
-// Copyright (C) 1999 onwards Martin Dougiamas        http://dougiamas.com  //
-//           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //
-//                                                                       //
-// This program is free software; you can redistribute it and/or modify  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
-
-/// This class represent one XMLDB Index
-
-class XMLDBIndex extends XMLDBObject {
-
-    var $unique;
-    var $fields;
-
-    /**
-     * Creates one new XMLDBIndex
-     */
-    function XMLDBIndex($name) {
-        parent::XMLDBObject($name);
-        $this->unique = false;
-        $this->fields = array();
-    }
-
-    /**
-     * Set all the attributes of one XMLDBIndex
-     *
-     * @param string type XMLDB_INDEX_UNIQUE, XMLDB_INDEX_NOTUNIQUE
-     * @param array fields an array of fieldnames to build the index over
-     */
-    function setAttributes($type, $fields) {
-        $this->unique = !empty($type) ? true : false;
-        $this->fields = $fields;
-    }
-
-    /**
-     * Get the index unique
-     */
-    function getUnique() {
-        return $this->unique;
-    }
-
-    /**
-     * Set the index unique
-     */
-    function setUnique($unique = true) {
-        $this->unique = $unique;
-    }
-
-    /**
-     * Set the index fields
-     */
-    function setFields($fields) {
-        $this->fields = $fields;
-    }
-
-    /**
-     * Get the index fields
-     */
-    function &getFields() {
-        return $this->fields;
-    }
-
-    /**
-     * Load data from XML to the index
-     */
-    function arr2XMLDBIndex($xmlarr) {
-
-        $result = true;
-
-    /// Debug the table
-    /// traverse_xmlize($xmlarr);                   //Debug
-    /// print_object ($GLOBALS['traverse_array']);  //Debug
-    /// $GLOBALS['traverse_array']="";              //Debug
-
-    /// Process key attributes (name, unique, fields, comment, previous, next)
-        if (isset($xmlarr['@']['NAME'])) {
-            $this->name = trim($xmlarr['@']['NAME']);
-        } else {
-            $this->errormsg = 'Missing NAME attribute';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-
-        if (isset($xmlarr['@']['UNIQUE'])) {
-            $unique = strtolower(trim($xmlarr['@']['UNIQUE']));
-            if ($unique == 'true') {
-                $this->unique = true;
-            } else if ($unique == 'false') {
-                $this->unique = false;
-            } else {
-                $this->errormsg = 'Incorrect UNIQUE attribute (true/false allowed)';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        } else {
-                $this->errormsg = 'Undefined UNIQUE attribute';
-                $this->debug($this->errormsg);
-                $result = false;
-        }
-
-        if (isset($xmlarr['@']['FIELDS'])) {
-            $fields = strtolower(trim($xmlarr['@']['FIELDS']));
-            if ($fields) {
-                $fieldsarr = explode(',',$fields);
-                if ($fieldsarr) {
-                    foreach ($fieldsarr as $key => $element) {
-                        $fieldsarr [$key] = trim($element);
-                    }
-                } else {
-                    $this->errormsg = 'Incorrect FIELDS attribute (comma separated of fields)';
-                    $this->debug($this->errormsg);
-                    $result = false;
-                }
-            } else {
-                $this->errormsg = 'Empty FIELDS attribute';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        } else {
-            $this->errormsg = 'Missing FIELDS attribute';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-    /// Finally, set the array of fields
-        $this->fields = $fieldsarr;
-
-        if (isset($xmlarr['@']['COMMENT'])) {
-            $this->comment = trim($xmlarr['@']['COMMENT']);
-        }
-
-        if (isset($xmlarr['@']['PREVIOUS'])) {
-            $this->previous = trim($xmlarr['@']['PREVIOUS']);
-        }
-
-        if (isset($xmlarr['@']['NEXT'])) {
-            $this->next = trim($xmlarr['@']['NEXT']);
-        }
-
-    /// Set some attributes
-        if ($result) {
-            $this->loaded = true;
-        }
-        $this->calculateHash();
-        return $result;
-    }
-
-    /**
-     * This function calculate and set the hash of one XMLDBIndex
-     */
-     function calculateHash($recursive = false) {
-        if (!$this->loaded) {
-            $this->hash = NULL;
-        } else {
-            $key = $this->unique . implode (', ', $this->fields);
-            $this->hash = md5($key);
-        }
-    }
-
-    /**
-     *This function will output the XML text for one index
-     */
-    function xmlOutput() {
-        $o = '';
-        $o.= '        <INDEX NAME="' . $this->name . '"';
-        if ($this->unique) {
-            $unique = 'true';
-        } else {
-            $unique = 'false';
-        }
-        $o.= ' UNIQUE="' . $unique . '"';
-        $o.= ' FIELDS="' . implode(', ', $this->fields) . '"';
-        if ($this->comment) {
-            $o.= ' COMMENT="' . htmlspecialchars($this->comment) . '"';
-        }
-        if ($this->previous) {
-            $o.= ' PREVIOUS="' . $this->previous . '"';
-        }
-        if ($this->next) {
-            $o.= ' NEXT="' . $this->next . '"';
-        }
-        $o.= '/>' . "\n";
-
-        return $o;
-    }
-
-    /**
-     * This function will set all the attributes of the XMLDBIndex object
-     * based on information passed in one ADOindex
-     */
-    function setFromADOIndex($adoindex) {
-
-    /// Set the unique field
-        $this->unique = false;
-    /// Set the fields, converting all them to lowercase
-        $fields = array_flip(array_change_key_case(array_flip($adoindex['columns'])));
-        $this->fields = $fields;
-    /// Some more fields
-        $this->loaded = true;
-        $this->changed = true;
-    }
-
-    /**
-     * Returns the PHP code needed to define one XMLDBIndex
-     */
-    function getPHP() {
-
-        $result = '';
-
-    /// The type
-        $unique = $this->getUnique();
-        if (!empty($unique)) {
-            $result .= 'XMLDB_INDEX_UNIQUE, ';
-        } else {
-            $result .= 'XMLDB_INDEX_NOTUNIQUE, ';
-        }
-    /// The fields
-        $indexfields = $this->getFields();
-        if (!empty($indexfields)) {
-            $result .= 'array(' . "'".  implode("', '", $indexfields) . "')";
-        } else {
-            $result .= 'null';
-        }
-    /// Return result
-        return $result;
-    }
-
-    /**
-     * Shows info in a readable format
-     */
-    function readableInfo() {
-        $o = '';
-    /// unique
-        if ($this->unique) {
-            $o .= 'unique';
-        } else {
-            $o .= 'not unique';
-        }
-    /// fields
-        $o .= ' (' . implode(', ', $this->fields) . ')';
-
-        return $o;
-    }
-}
-
-?>
Index: lib/xmldb/classes/XMLDBFile.class.php
===================================================================
RCS file: lib/xmldb/classes/XMLDBFile.class.php
diff -N lib/xmldb/classes/XMLDBFile.class.php
--- lib/xmldb/classes/XMLDBFile.class.php	10 Oct 2007 05:25:14 -0000	1.6
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,201 +0,0 @@
-<?php // $Id: XMLDBFile.class.php,v 1.6 2007/10/10 05:25:14 nicolasconnault Exp $
-
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.com                                            //
-//                                                                       //
-// Copyright (C) 1999 onwards Martin Dougiamas        http://dougiamas.com  //
-//           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //
-//                                                                       //
-// This program is free software; you can redistribute it and/or modify  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
-
-/// This class represents an entire XMLDB file
-
-class XMLDBFile extends XMLDBObject {
-
-    var $path;
-    var $schema;
-    var $dtd;
-    var $xmldb_structure;
-
-    /**
-     * Constructor of the XMLDBFile
-     */
-    function XMLDBFile ($path) {
-        parent::XMLDBObject($path);
-        $this->path = $path;
-        $this->xmldb_structure = NULL;
-    }
-
-    /**
-     * Determine if the XML file exists
-     */
-    function fileExists() {
-        if (file_exists($this->path) && is_readable($this->path)) {
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * Determine if the XML is writeable
-     */
-    function fileWriteable() {
-        if (is_writeable(dirname($this->path))) {
-            return true;
-        }
-        return false;
-    }
-
-    function &getStructure() {
-        return $this->xmldb_structure;
-    }
-
-    /**
-     * This function will check/validate the XML file for correctness 
-     * Dinamically if will use the best available checker/validator
-     * (expat syntax checker or DOM schema validator
-     */
-    function validateXMLStructure() {
-
-    /// Going to perform complete DOM schema validation
-        if (extension_loaded('dom')) {
-        /// Let's capture errors
-        if (function_exists('libxml_use_internal_errors')) {
-            libxml_use_internal_errors(true); // This function is PHP5 only (MDL-8730)
-        }
-
-        /// Create and load XML file
-            $parser = new DOMDocument();
-            $parser->load($this->path);
-        /// Only validate if we have a schema
-            if (!empty($this->schema) && file_exists($this->schema)) {
-                $parser->schemaValidate($this->schema);
-            }
-        /// Check for errors
-            $errors = false;
-            if (function_exists('libxml_get_errors')) {
-                $errors = libxml_get_errors();
-            }
-
-        /// Prepare errors
-            if (!empty($errors)) {
-            /// Create one structure to store errors
-                $structure = new XMLDBStructure($this->path);
-            /// Add errors to structure
-                $structure->errormsg = 'XML Error: ';
-                foreach ($errors as $error) {
-                    $structure->errormsg .= sprintf("%s at line %d. ", 
-                                                     trim($error->message, "\n\r\t ."),
-                                                     $error->line);
-                }
-            /// Add structure to file
-                $this->xmldb_structure = $structure;
-            /// Check has failed
-                return false;
-            }
-        }
-    /// Going to perform expat simple check (no validation)
-        else if (function_exists('xml_parser_create')) {
-            $parser = xml_parser_create();
-            if (!xml_parse($parser, file_get_contents($this->path))) {
-            /// Create one structure to store errors
-                $structure = new XMLDBStructure($this->path);
-            /// Add error to structure
-                $structure->errormsg = sprintf("XML Error: %s at line %d", 
-                         xml_error_string(xml_get_error_code($parser)),
-                         xml_get_current_line_number($parser));
-            /// Add structure to file
-                $this->xmldb_structure = $structure;
-            /// Check has failed
-                return false;
-            }
-        /// Free parser resources
-            xml_parser_free($parser);
-        }
-    /// Arriving here, something is really wrong because nor dom not expat are present
-        else {
-            return false;
-        }
-        return true;
-    }
-
-    /**
-     * Load and the XMLDB structure from file
-     */
-    function loadXMLStructure() {
-        if ($this->fileExists()) {
-        /// Let's validate the XML file
-            if (!$this->validateXMLStructure()) {
-                return false;
-            }
-        /// File exists, so let's process it
-        /// Load everything to a big array
-            $xmlarr = xmlize(file_get_contents($this->path));
-        /// Convert array to xmldb structure
-            $this->xmldb_structure = $this->arr2XMLDBStructure($xmlarr);
-        /// Analize results
-            if ($this->xmldb_structure->isLoaded()) {
-                $this->loaded = true;
-                return true;
-            } else {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    /**
-     * This function takes an xmlized array and put it into one XMLDBStructure
-     */
-    function arr2XMLDBStructure ($xmlarr) {
-        $structure = new XMLDBStructure($this->path);
-        $structure->arr2XMLDBStructure($xmlarr);
-        return $structure;
-    }
-
-    /**
-     * This function sets the DTD of the XML file
-     */
-    function setDTD($path) {
-        $this->dtd = $path;
-    }
-
-    /**
-     * This function sets the schema of the XML file
-     */
-    function setSchema($path) {
-        $this->schema = $path;
-    }
-
-    /**
-     * This function saves the whole XMLDBStructure to its file
-     */
-    function saveXMLFile() {
-
-        $result = true;
-
-        $structure =& $this->getStructure();
-
-        $result = file_put_contents($this->path, $structure->xmlOutput());
-
-        return $result;
-    }
-}
-
-?>
Index: lib/xmldb/classes/XMLDBStatement.class.php
===================================================================
RCS file: lib/xmldb/classes/XMLDBStatement.class.php
diff -N lib/xmldb/classes/XMLDBStatement.class.php
--- lib/xmldb/classes/XMLDBStatement.class.php	10 Oct 2007 05:25:14 -0000	1.7
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,423 +0,0 @@
-<?php // $Id: XMLDBStatement.class.php,v 1.7 2007/10/10 05:25:14 nicolasconnault Exp $
-
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.com                                            //
-//                                                                       //
-// Copyright (C) 1999 onwards Martin Dougiamas        http://dougiamas.com  //
-//           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //
-//                                                                       //
-// This program is free software; you can redistribute it and/or modify  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
-
-/// This class represent one XMLDB Statement
-/// (a group of SQL arbitrary sentences)
-/// (only INSERT is allowed for now)
-
-class XMLDBStatement extends XMLDBObject {
-
-    var $table;     // Table we are handling
-    var $type;      // XMLDB_STATEMENT_TYPE
-    var $sentences; // Collection of sentences in the statement
-
-    /**
-     * Creates one new XMLDBStatement
-     */
-    function XMLDBStatement($name) {
-        parent::XMLDBObject($name);
-        $this->table     = NULL;
-        $this->type      = XMLDB_STATEMENT_INCORRECT;
-        $this->sentences = array();
-    }
-
-    /**
-     * Get the statement table
-     */
-    function getTable() {
-        return $this->table;
-    }
-
-    /**
-     * Get the statement type
-     */
-    function getType() {
-        return $this->type;
-    }
-
-    /**
-     * Get the statement sentences
-     */
-    function &getSentences() {
-        return $this->sentences;
-    }
-
-    /**
-     * Set the statement table
-     */
-    function setTable($table) {
-        $this->table = $table;
-    }
-
-    /**
-     * Set the statement type
-     */
-    function setType($type) {
-        $this->type = $type;
-    }
-
-    /**
-     * Add one statement sentence
-     */
-    function addSentence($sentence) {
-        $this->sentences[] = $sentence;
-    }
-
-    /**
-     * Load data from XML to the index
-     */
-    function arr2XMLDBStatement($xmlarr) {
-
-        $result = true;
-
-    /// Debug the table
-    /// traverse_xmlize($xmlarr);                   //Debug
-    /// print_object ($GLOBALS['traverse_array']);  //Debug
-    /// $GLOBALS['traverse_array']="";              //Debug
-
-    /// Process key attributes (table, type, comment, previous, next)
-        if (isset($xmlarr['@']['TABLE'])) {
-            $this->table = strtolower(trim($xmlarr['@']['TABLE']));
-        } else {
-            $this->errormsg = 'Missing TABLE attribute';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-
-        if (isset($xmlarr['@']['TYPE'])) {
-        /// Check for valid type
-            $type = $this->getXMLDBStatementType(trim($xmlarr['@']['TYPE']));
-            if ($type) {
-                $this->type = $type;
-            } else {
-                $this->errormsg = 'Invalid TYPE attribute';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        } else {
-            $this->errormsg = 'Missing TYPE attribute';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-
-    /// Look for sentences
-        $sentencesarr = array();
-
-        if (isset($xmlarr['#']['SENTENCES'])) {
-            $sentences = $xmlarr['#']['SENTENCES'][0]['#']['SENTENCE'];
-            if ($sentences) {
-                foreach ($sentences as $sentence) {
-                    if (isset($sentence['@']['TEXT'])) {
-                        $sentencesarr[] = trim($sentence['@']['TEXT']);
-                    } else {
-                        $this->errormsg = 'Missing TEXT attribute in sentence';
-                        $this->debug($this->errormsg);
-                        $result = false;
-                    }
-                }
-            }
-        }
-
-    /// Finally, set the array of sentences
-        $this->sentences = $sentencesarr;
-
-    /// Now, perform some validations over sentences
-    /// XMLDB_STATEMENT_INSERT checks
-        if ($this->type == XMLDB_STATEMENT_INSERT) {
-        /// Separate fields and values into two arrays
-            if ($this->sentences) {
-                foreach ($this->sentences as $sentence) {
-                    $fields = $this->getFieldsFromInsertSentence($sentence);
-                    $values = $this->getValuesFromInsertSentence($sentence);
-                /// Check that we aren't inserting the id field
-                    if (in_array('id', $fields)) {
-                        $this->errormsg = 'Cannot insert the "id" field. It is an autonumeric column';
-                        $this->debug($this->errormsg);
-                        $result = false;
-                    }
-                    if ($result && count($fields) == 0) {
-                        $this->errormsg = 'Missing fields in sentence "' . $sentence . '"';
-                        $this->debug($this->errormsg);
-                        $result = false;
-                    }
-                    if ($result && count($values) == 0) {
-                        $this->errormsg = 'Missing values in sentence "' . $sentence . '"';
-                        $this->debug($this->errormsg);
-                        $result = false;
-                    }
-                    if ($result && count($fields) != count($values)) {
-                        $this->errormsg = 'Incorrect number of fields (' .implode(', ', $fields) . ') or values (' . implode(', ', $values) . ')';
-                        $this->debug($this->errormsg);
-                        $result = false;
-                    }
-                }
-            }
-        } else {
-        /// Sentences different from INSERT are not valid for now
-            $this->errormsg = 'Only INSERT statements are supported';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-
-        if (isset($xmlarr['@']['COMMENT'])) {
-            $this->comment = trim($xmlarr['@']['COMMENT']);
-        }
-
-        if (isset($xmlarr['@']['PREVIOUS'])) {
-            $this->previous = trim($xmlarr['@']['PREVIOUS']);
-        }
-
-        if (isset($xmlarr['@']['NEXT'])) {
-            $this->next = trim($xmlarr['@']['NEXT']);
-        }
-
-    /// Set some attributes
-        if ($result) {
-            $this->loaded = true;
-        }
-        $this->calculateHash();
-        return $result;
-    }
-
-    /**
-     * This function returns the correct XMLDB_STATEMENT_XXX value for the
-     * string passed as argument
-     */
-    function getXMLDBStatementType($type) {
-
-        $result = XMLDB_STATEMENT_INCORRECT;
-
-        switch (strtolower($type)) {
-            case 'insert':
-                $result = XMLDB_STATEMENT_INSERT;
-                break;
-            case 'update':
-                $result = XMLDB_STATEMENT_UPDATE;
-                break;
-            case 'delete':
-                $result = XMLDB_STATEMENT_DELETE;
-                break;
-            case 'custom':
-                $result = XMLDB_STATEMENT_CUSTOM;
-                break;
-        }
-    /// Return the normalized XMLDB_STATEMENT
-        return $result;
-    }
-
-    /**
-     * This function returns the correct name value for the
-     * XMLDB_STATEMENT_XXX passed as argument
-     */
-    function getXMLDBStatementName($type) {
-
-        $result = '';
-
-        switch (strtolower($type)) {
-            case XMLDB_STATEMENT_INSERT:
-                $result = 'insert';
-                break;
-            case XMLDB_STATEMENT_UPDATE:
-                $result = 'update';
-                break;
-            case XMLDB_STATEMENT_DELETE:
-                $result = 'delete';
-                break;
-            case XMLDB_STATEMENT_CUSTOM:
-                $result = 'custom';
-                break;
-        }
-    /// Return the normalized name
-        return $result;
-    }
-
-    /**
-     * This function calculate and set the hash of one XMLDBStatement
-     */
-     function calculateHash($recursive = false) {
-        if (!$this->loaded) {
-            $this->hash = NULL;
-        } else {
-            $key = $this->table . $this->type . implode (', ', $this->sentences);
-            $this->hash = md5($key);
-        }
-    }
-
-    /**
-     * This function will output the XML text for one statement
-     */
-    function xmlOutput() {
-        $o = '';
-        $o.= '    <STATEMENT NAME="' . $this->name . '" TYPE="' . XMLDBStatement::getXMLDBStatementName($this->type) . '" TABLE="' . $this->table . '"';
-        if ($this->comment) {
-            $o.= ' COMMENT="' . htmlspecialchars($this->comment) . '"';
-        }
-        if ($this->previous) {
-            $o.= ' PREVIOUS="' . $this->previous . '"';
-        }
-        if ($this->next) {
-            $o.= ' NEXT="' . $this->next . '"';
-        }
-        if ($this->sentences) {
-            $o.= '>' . "\n";
-            $o.= '      <SENTENCES>' . "\n";
-            foreach ($this->sentences as $sentence) {
-                $o.= '        <SENTENCE TEXT="' . htmlspecialchars($sentence) . '" />' . "\n";
-            }
-            $o.= '      </SENTENCES>' . "\n";
-            $o.= '    </STATEMENT>' . "\n";
-        } else {
-            $o.= '/>' . "\n";
-        }
-
-        return $o;
-    }
-
-    /**
-     * This function will set all the attributes of the XMLDBIndex object
-     * based on information passed in one ADOindex
-     */
-    function setFromADOIndex($adoindex) {
-
-    /// Set the unique field
-        $this->unique = false;
-    /// Set the fields
-        $this->fields = $adoindex['columns'];
-    /// Some more fields
-        $this->loaded = true;
-        $this->changed = true;
-    }
-
-    /**
-     * Shows info in a readable format
-     */
-    function readableInfo() {
-        $o = '';
-    /// unique
-        if ($this->unique) {
-            $o .= 'unique';
-        } else {
-            $o .= 'not unique';
-        }
-    /// fields
-        $o .= ' (' . implode(', ', $this->fields) . ')';
-
-        return $o;
-    }
-
-    /**
-     * This function will return an array of fields from one INSERT sentence
-     */
-    function getFieldsFromInsertSentence($sentence) {
-
-        $fields = array();
-
-    /// Get first part from the sentence (before VALUES)
-        preg_match('/^\((.*)\)\s+VALUES/is', $sentence, $matches);
-        if (isset($matches[1])) {
-            $part = $matches[1];
-        /// Convert the comma separated string to an array
-            $arr = $this->comma2array($part);
-            if ($arr) {
-                $fields = $arr;
-            }
-        }
-
-        return $fields;
-    }
-
-    /**
-     * This function will return an array of values from one INSERT sentence
-     */
-    function getValuesFromInsertSentence($sentence) {
-
-        $values = array();
-
-    /// Get second part from the sentence (after VALUES)
-        preg_match('/VALUES\s*\((.*)\)$/is', $sentence, $matches);
-        if (isset($matches[1])) {
-            $part = $matches[1];
-        /// Convert the comma separated string to an array
-            $arr = $this->comma2array($part);
-            if ($arr) {
-                $values = $arr;
-            }
-        }
-
-        return $values;
-    }
-
-    /**
-     * This function will return the code needed to execute a collection
-     * of sentences present inside one statement for the specified BD
-     * and prefix.
-     * For now it only supports INSERT statements
-     */
-    function getExecuteStatementSQL ($dbtype, $prefix, $statement_end=true) {
-
-        $results = array();
-
-    /// Based on statement type
-        switch ($this->type) {
-            case XMLDB_STATEMENT_INSERT:
-                $results = $this->getExecuteInsertSQL($dbtype, $prefix, $statement_end);
-                break;
-            case XMLDB_STATEMENT_UPDATE:
-                break;
-            case XMLDB_STATEMENT_DELETE:
-                break;
-            case XMLDB_STATEMENT_CUSTOM:
-                break;
-        }
-
-        return $results;
-    }
-
-    /**
-     * This function will return the code needed to execute a collection
-     * of insert sentences present inside the statement for the specified BD
-     * and prefix. Just one simple wrapper over generators.
-     */
-    function getExecuteInsertSQL ($dbtype, $prefix, $statement_end=true) {
-
-        $results = array();
-
-        $classname = 'XMLDB' . $dbtype;
-        $generator = new $classname();
-        $generator->setPrefix($prefix);
-
-        $results = $generator->getExecuteInsertSQL($this);
-
-        if ($statement_end) {
-            $results = $generator->getEndedStatements($results);
-        }
-
-        return $results;
-    }
-
-}
-
-?>
Index: lib/xmldb/classes/XMLDBKey.class.php
===================================================================
RCS file: lib/xmldb/classes/XMLDBKey.class.php
diff -N lib/xmldb/classes/XMLDBKey.class.php
--- lib/xmldb/classes/XMLDBKey.class.php	10 Oct 2007 05:25:14 -0000	1.8
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,457 +0,0 @@
-<?php // $Id: XMLDBKey.class.php,v 1.8 2007/10/10 05:25:14 nicolasconnault Exp $
-
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.com                                            //
-//                                                                       //
-// Copyright (C) 1999 onwards Martin Dougiamas        http://dougiamas.com  //
-//           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //
-//                                                                       //
-// This program is free software; you can redistribute it and/or modify  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
-
-/// This class represent one XMLDB Key
-
-class XMLDBKey extends XMLDBObject {
-
-    var $type;
-    var $fields;
-    var $reftable;
-    var $reffields;
-
-    /**
-     * Creates one new XMLDBKey
-     */
-    function XMLDBKey($name) {
-        parent::XMLDBObject($name);
-        $this->type = NULL;
-        $this->fields = array();
-        $this->reftable = NULL;
-        $this->reffields = array();
-    }
-
-    /**
-     * Set all the attributes of one XMLDBKey
-     *
-     * @param string type XMLDB_KEY_PRIMARY, XMLDB_KEY_UNIQUE, XMLDB_KEY_FOREIGN
-     * @param array fields an array of fieldnames to build the key over
-     * @param string reftable name of the table the FK points to or null
-     * @param array reffields an array of fieldnames in the FK table or null
-     */
-    function setAttributes($type, $fields, $reftable=null, $reffields=null) {
-        $this->type = $type;
-        $this->fields = $fields;
-        $this->reftable = $reftable;
-        $this->reffields = $reffields;
-    }
-
-    /**
-     * Get the key type
-     */
-    function getType() {
-        return $this->type;
-    }
-
-    /**
-     * Set the key type
-     */
-    function setType($type) {
-        $this->type = $type;
-    }
-
-    /**
-     * Set the key fields
-     */
-    function setFields($fields) {
-        $this->fields = $fields;
-    }
-
-    /**
-     * Set the key reftable
-     */
-    function setRefTable($reftable) {
-        $this->reftable = $reftable;
-    }
-
-    /**
-     * Set the key reffields
-     */
-    function setRefFields($reffields) {
-        $this->reffields = $reffields;
-    }
-
-    /**
-     * Get the key fields
-     */
-    function &getFields() {
-        return $this->fields;
-    }
-
-    /**
-     * Get the key reftable
-     */
-    function &getRefTable() {
-        return $this->reftable;
-    }
-
-    /**
-     * Get the key reffields
-     */
-    function &getRefFields() {
-        return $this->reffields;
-    }
-
-    /**
-     * Load data from XML to the key
-     */
-    function arr2XMLDBKey($xmlarr) {
-
-        $result = true;
-
-    /// Debug the table
-    /// traverse_xmlize($xmlarr);                   //Debug
-    /// print_object ($GLOBALS['traverse_array']);  //Debug
-    /// $GLOBALS['traverse_array']="";              //Debug
-
-    /// Process key attributes (name, type, fields, reftable,
-    /// reffields, comment, previous, next)
-        if (isset($xmlarr['@']['NAME'])) {
-            $this->name = trim($xmlarr['@']['NAME']);
-        } else {
-            $this->errormsg = 'Missing NAME attribute';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-
-        if (isset($xmlarr['@']['TYPE'])) {
-        /// Check for valid type
-            $type = $this->getXMLDBKeyType(trim($xmlarr['@']['TYPE']));
-            if ($type) {
-                $this->type = $type;
-            } else {
-                $this->errormsg = 'Invalid TYPE attribute';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        } else {
-            $this->errormsg = 'Missing TYPE attribute';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-
-        if (isset($xmlarr['@']['FIELDS'])) {
-            $fields = strtolower(trim($xmlarr['@']['FIELDS']));
-            if ($fields) {
-                $fieldsarr = explode(',',$fields);
-                if ($fieldsarr) {
-                    foreach ($fieldsarr as $key => $element) {
-                        $fieldsarr [$key] = trim($element);
-                    }
-                } else {
-                    $this->errormsg = 'Incorrect FIELDS attribute (comma separated of fields)';
-                    $this->debug($this->errormsg);
-                    $result = false;
-                }
-            } else {
-                $this->errormsg = 'Empty FIELDS attribute';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        } else {
-            $this->errormsg = 'Missing FIELDS attribute';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-    /// Finally, set the array of fields
-        $this->fields = $fieldsarr;
-
-        if (isset($xmlarr['@']['REFTABLE'])) {
-        /// Check we are in a FK
-            if ($this->type == XMLDB_KEY_FOREIGN ||
-                $this->type == XMLDB_KEY_FOREIGN_UNIQUE) {
-                $reftable = strtolower(trim($xmlarr['@']['REFTABLE']));
-                if (!$reftable) {
-                    $this->errormsg = 'Empty REFTABLE attribute';
-                    $this->debug($this->errormsg);
-                    $result = false;
-                }
-            } else {
-                $this->errormsg = 'Wrong REFTABLE attribute (only FK can have it)';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        } else if ($this->type == XMLDB_KEY_FOREIGN ||
-                   $this->type == XMLDB_KEY_FOREIGN_UNIQUE) {
-            $this->errormsg = 'Missing REFTABLE attribute';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-    /// Finally, set the reftable
-        if ($this->type == XMLDB_KEY_FOREIGN ||
-            $this->type == XMLDB_KEY_FOREIGN_UNIQUE) {
-            $this->reftable = $reftable;
-        }
-
-        if (isset($xmlarr['@']['REFFIELDS'])) {
-        /// Check we are in a FK
-            if ($this->type == XMLDB_KEY_FOREIGN ||
-                $this->type == XMLDB_KEY_FOREIGN_UNIQUE) {
-                $reffields = strtolower(trim($xmlarr['@']['REFFIELDS']));
-                if ($reffields) {
-                    $reffieldsarr = explode(',',$reffields);
-                    if ($reffieldsarr) {
-                        foreach ($reffieldsarr as $key => $element) {
-                            $reffieldsarr [$key] = trim($element);
-                        }
-                    } else {
-                        $this->errormsg = 'Incorrect REFFIELDS attribute (comma separated of fields)';
-                        $this->debug($this->errormsg);
-                        $result = false;
-                    }
-                } else {
-                    $this->errormsg = 'Empty REFFIELDS attribute';
-                    $this->debug($this->errormsg);
-                    $result = false;
-                }
-            } else {
-                $this->errormsg = 'Wrong REFFIELDS attribute (only FK can have it)';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        } else if ($this->type == XMLDB_KEY_FOREIGN ||
-                   $this->type == XMLDB_KEY_FOREIGN_UNIQUE) {
-            $this->errormsg = 'Missing REFFIELDS attribute';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-    /// Finally, set the array of reffields
-        if ($this->type == XMLDB_KEY_FOREIGN ||
-            $this->type == XMLDB_KEY_FOREIGN_UNIQUE) {
-            $this->reffields = $reffieldsarr;
-        }
-
-        if (isset($xmlarr['@']['COMMENT'])) {
-            $this->comment = trim($xmlarr['@']['COMMENT']);
-        }
-
-        if (isset($xmlarr['@']['PREVIOUS'])) {
-            $this->previous = trim($xmlarr['@']['PREVIOUS']);
-        }
-
-        if (isset($xmlarr['@']['NEXT'])) {
-            $this->next = trim($xmlarr['@']['NEXT']);
-        }
-
-    /// Set some attributes
-        if ($result) {
-            $this->loaded = true;
-        }
-        $this->calculateHash();
-        return $result;
-    }
-
-    /**
-     * This function returns the correct XMLDB_KEY_XXX value for the
-     * string passed as argument
-     */
-    function getXMLDBKeyType($type) {
-
-        $result = XMLDB_KEY_INCORRECT;
-
-        switch (strtolower($type)) {
-            case 'primary':
-                $result = XMLDB_KEY_PRIMARY;
-                break;
-            case 'unique':
-                $result = XMLDB_KEY_UNIQUE;
-                break;
-            case 'foreign':
-                $result = XMLDB_KEY_FOREIGN;
-                break;
-            case 'foreign-unique':
-                $result = XMLDB_KEY_FOREIGN_UNIQUE;
-                break;
-        /// case 'check':  //Not supported
-        ///     $result = XMLDB_KEY_CHECK;
-        ///     break;
-        }
-    /// Return the normalized XMLDB_KEY
-        return $result;
-    }
-
-    /**
-     * This function returns the correct name value for the
-     * XMLDB_KEY_XXX passed as argument
-     */
-    function getXMLDBKeyName($type) {
-
-        $result = '';
-
-        switch (strtolower($type)) {
-            case XMLDB_KEY_PRIMARY:
-                $result = 'primary';
-                break;
-            case XMLDB_KEY_UNIQUE:
-                $result = 'unique';
-                break;
-            case XMLDB_KEY_FOREIGN:
-                $result = 'foreign';
-                break;
-            case XMLDB_KEY_FOREIGN_UNIQUE:
-                $result = 'foreign-unique';
-                break;
-        /// case XMLDB_KEY_CHECK:  //Not supported
-        ///     $result = 'check';
-        ///     break;
-        }
-    /// Return the normalized name
-        return $result;
-    }
-
-    /**
-     * This function calculate and set the hash of one XMLDBKey
-     */
-     function calculateHash($recursive = false) {
-        if (!$this->loaded) {
-            $this->hash = NULL;
-        } else {
-            $key = $this->type . implode(', ', $this->fields);
-            if ($this->type == XMLDB_KEY_FOREIGN ||
-                $this->type == XMLDB_KEY_FOREIGN_UNIQUE) {
-                $key .= $this->reftable . implode(', ', $this->reffields);
-            }
-                    ;
-            $this->hash = md5($key);
-        }
-    }
-
-    /**
-     *This function will output the XML text for one key
-     */
-    function xmlOutput() {
-        $o = '';
-        $o.= '        <KEY NAME="' . $this->name . '"';
-        $o.= ' TYPE="' . $this->getXMLDBKeyName($this->type) . '"';
-        $o.= ' FIELDS="' . implode(', ', $this->fields) . '"';
-        if ($this->type == XMLDB_KEY_FOREIGN ||
-            $this->type == XMLDB_KEY_FOREIGN_UNIQUE) {
-            $o.= ' REFTABLE="' . $this->reftable . '"';
-            $o.= ' REFFIELDS="' . implode(', ', $this->reffields) . '"';
-        }
-        if ($this->comment) {
-            $o.= ' COMMENT="' . htmlspecialchars($this->comment) . '"';
-        }
-        if ($this->previous) {
-            $o.= ' PREVIOUS="' . $this->previous . '"';
-        }
-        if ($this->next) {
-            $o.= ' NEXT="' . $this->next . '"';
-        }
-        $o.= '/>' . "\n";
-
-        return $o;
-    }
-
-    /**
-     * This function will set all the attributes of the XMLDBKey object
-     * based on information passed in one ADOkey
-     */
-    function setFromADOKey($adokey) {
-
-    /// Calculate the XMLDB_KEY
-        switch (strtolower($adokey['name'])) {
-            case 'primary':
-                $this->type = XMLDB_KEY_PRIMARY;
-                break;
-            default:
-                $this->type = XMLDB_KEY_UNIQUE;
-        }
-    /// Set the fields, converting all them to lowercase
-        $fields = array_flip(array_change_key_case(array_flip($adokey['columns'])));
-        $this->fields = $fields;
-    /// Some more fields
-        $this->loaded = true;
-        $this->changed = true;
-    }
-
-    /**
-     * Returns the PHP code needed to define one XMLDBKey
-     */
-    function getPHP() {
-
-        $result = '';
-
-    /// The type
-        switch ($this->getType()) {
-            case XMLDB_KEY_PRIMARY:
-                $result .= 'XMLDB_KEY_PRIMARY' . ', ';
-                break;
-            case XMLDB_KEY_UNIQUE:
-                $result .= 'XMLDB_KEY_UNIQUE' . ', ';
-                break;
-            case XMLDB_KEY_FOREIGN:
-                $result .= 'XMLDB_KEY_FOREIGN' . ', ';
-                break;
-        }
-    /// The fields
-        $keyfields = $this->getFields();
-        if (!empty($keyfields)) {
-            $result .= 'array(' . "'".  implode("', '", $keyfields) . "')";
-        } else {
-            $result .= 'null';
-        }
-    /// The FKs attributes
-        if ($this->getType() == XMLDB_KEY_FOREIGN) {
-        /// The reftable
-            $reftable = $this->getRefTable();
-            if (!empty($reftable)) {
-                $result .= ", '" . $reftable . "', ";
-            } else {
-                $result .= 'null, ';
-            }
-        /// The reffields
-            $reffields = $this->getRefFields();
-            if (!empty($reffields)) {
-                $result .= 'array(' . "'".  implode("', '", $reffields) . "')";
-            } else {
-                $result .= 'null';
-            }
-        }
-    /// Return result
-        return $result;
-    }
-
-    /**
-     * Shows info in a readable format
-     */
-    function readableInfo() {
-        $o = '';
-    /// type
-        $o .= $this->getXMLDBKeyName($this->type);
-    /// fields
-        $o .= ' (' . implode(', ', $this->fields) . ')';
-    /// foreign key
-        if ($this->type == XMLDB_KEY_FOREIGN ||
-            $this->type == XMLDB_KEY_FOREIGN_UNIQUE) {
-            $o .= ' references ' . $this->reftable . ' (' . implode(', ', $this->reffields) . ')';
-        }
-
-        return $o;
-    }
-}
-
-?>
Index: lib/xmldb/classes/XMLDBStructure.class.php
===================================================================
RCS file: lib/xmldb/classes/XMLDBStructure.class.php
diff -N lib/xmldb/classes/XMLDBStructure.class.php
--- lib/xmldb/classes/XMLDBStructure.class.php	10 Oct 2007 05:25:14 -0000	1.12
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,741 +0,0 @@
-<?php // $Id: XMLDBStructure.class.php,v 1.12 2007/10/10 05:25:14 nicolasconnault Exp $
-
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.com                                            //
-//                                                                       //
-// Copyright (C) 1999 onwards Martin Dougiamas        http://dougiamas.com  //
-//           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //
-//                                                                       //
-// This program is free software; you can redistribute it and/or modify  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
-
-/// This class represent one XMLDB structure
-
-class XMLDBStructure extends XMLDBObject {
-
-    var $path;
-    var $version;
-    var $tables;
-    var $statements;
-
-    /**
-     * Creates one new XMLDBStructure
-     */
-    function XMLDBStructure($name) {
-        parent::XMLDBObject($name);
-        $this->path = NULL;
-        $this->version = NULL;
-        $this->tables = array();
-        $this->statements = array();
-    }
-
-    /**
-     * Returns the path of the structure
-     */
-    function getPath() {
-        return $this->path;
-    }
-
-    /**
-     * Returns the version of the structure
-     */
-    function getVersion() {
-        return $this->version;
-    }
-
-    /**
-     * Returns one XMLDBTable
-     */
-    function &getTable($tablename) {
-        $i = $this->findTableInArray($tablename);
-        if ($i !== NULL) {
-            return $this->tables[$i];
-        }
-        $null = NULL;
-        return $null;
-    }
-
-    /**
-     * Returns the position of one table in the array.
-     */
-    function &findTableInArray($tablename) {
-        foreach ($this->tables as $i => $table) {
-            if ($tablename == $table->getName()) {
-                return $i;
-            }
-        }
-        $null = NULL;
-        return $null;
-    }
-
-    /**
-     * Returns the position of one statement in the array.
-     */
-    function &findStatementInArray($statementname) {
-        foreach ($this->statements as $i => $statement) {
-            if ($statementname == $statement->getName()) {
-                return $i;
-            }
-        }
-        $null = NULL;
-        return $null;
-    }
-
-    /**
-     * This function will reorder the array of tables
-     */
-    function orderTables() {
-        $result = $this->orderElements($this->tables);
-        if ($result) {
-            $this->setTables($result);
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * This function will reorder the array of statements
-     */
-    function orderStatements() {
-        $result = $this->orderElements($this->statements);
-        if ($result) {
-            $this->setStatements($result);
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * Returns the tables of the structure
-     */
-    function &getTables() {
-        return $this->tables;
-    }
-
-    /**
-     * Returns one XMLDBStatement
-     */
-    function &getStatement($statementname) {
-        $i = $this->findStatementInArray($statementname);
-        if ($i !== NULL) {
-            return $this->statements[$i];
-        }
-        $null = NULL;
-        return $null;
-    }
-
-    /**
-     * Returns the statements of the structure
-     */
-    function &getStatements() {
-        return $this->statements;
-    }
-
-    /**
-     * Set the structure version
-     */
-    function setVersion($version) {
-        $this->version = $version;
-    }
-
-    /**
-     * Add one table to the structure, allowing to specify the desired order
-     * If it's not specified, then the table is added at the end.
-     */
-    function addTable(&$table, $after=NULL) {
-
-    /// Calculate the previous and next tables
-        $prevtable = NULL;
-        $nexttable = NULL;
-
-        if (!$after) {
-            $alltables =& $this->getTables();
-            if ($alltables) {
-                end($alltables);
-                $prevtable =& $alltables[key($alltables)];
-            }
-        } else {
-            $prevtable =& $this->getTable($after);
-        }
-        if ($prevtable && $prevtable->getNext()) {
-            $nexttable =& $this->getTable($prevtable->getNext());
-        }
-
-    /// Set current table previous and next attributes
-        if ($prevtable) {
-            $table->setPrevious($prevtable->getName());
-            $prevtable->setNext($table->getName());
-        }
-        if ($nexttable) {
-            $table->setNext($nexttable->getName());
-            $nexttable->setPrevious($table->getName());
-        }
-    /// Some more attributes
-        $table->setLoaded(true);
-        $table->setChanged(true);
-    /// Add the new table
-        $this->tables[] =& $table;
-    /// Reorder the whole structure
-        $this->orderTables($this->tables);
-    /// Recalculate the hash
-        $this->calculateHash(true);
-    /// We have one new table, so the structure has changed
-        $this->setVersion(userdate(time(), '%Y%m%d', 99, false));
-        $this->setChanged(true);
-    }
-
-    /**
-     * Add one statement to the structure, allowing to specify the desired order
-     * If it's not specified, then the statement is added at the end.
-     */
-    function addStatement(&$statement, $after=NULL) {
-
-    /// Calculate the previous and next tables
-        $prevstatement = NULL;
-        $nextstatement = NULL;
-
-        if (!$after) {
-            $allstatements =& $this->getStatements();
-            if ($allstatements) {
-                end($allstatements);
-                $prevstatement =& $allstatements[key($allstatements)];
-            }
-        } else {
-            $prevstatement =& $this->getStatement($after);
-        }
-        if ($prevstatement && $prevstatement->getNext()) {
-            $nextstatement =& $this->getStatement($prevstatement->getNext());
-        }
-
-    /// Set current statement previous and next attributes
-        if ($prevstatement) {
-            $statement->setPrevious($prevstatement->getName());
-            $prevstatement->setNext($statement->getName());
-        }
-        if ($nextstatement) {
-            $statement->setNext($nextstatement->getName());
-            $nextstatement->setPrevious($statement->getName());
-        }
-    /// Some more attributes
-        $statement->setLoaded(true);
-        $statement->setChanged(true);
-    /// Add the new statement
-        $this->statements[] =& $statement;
-    /// Reorder the whole structure
-        $this->orderStatements($this->statements);
-    /// Recalculate the hash
-        $this->calculateHash(true);
-    /// We have one new statement, so the structure has changed
-        $this->setVersion(userdate(time(), '%Y%m%d', 99, false));
-        $this->setChanged(true);
-    }
-
-    /**
-     * Delete one table from the Structure
-     */
-    function deleteTable($tablename) {
-
-        $table =& $this->getTable($tablename);
-        if ($table) {
-            $i = $this->findTableInArray($tablename);
-            $prevtable = NULL;
-            $nexttable = NULL;
-        /// Look for prev and next table
-            $prevtable =& $this->getTable($table->getPrevious());
-            $nexttable =& $this->getTable($table->getNext());
-        /// Change their previous and next attributes
-            if ($prevtable) {
-                $prevtable->setNext($table->getNext());
-            }
-            if ($nexttable) {
-                $nexttable->setPrevious($table->getPrevious());
-            }
-        /// Delete the table
-            unset($this->tables[$i]);
-        /// Reorder the tables
-            $this->orderTables($this->tables);
-        /// Recalculate the hash
-            $this->calculateHash(true);
-        /// We have one deleted table, so the structure has changed
-            $this->setVersion(userdate(time(), '%Y%m%d', 99, false));
-            $this->setChanged(true);
-        }
-    }
-
-    /**
-     * Delete one statement from the Structure
-     */
-    function deleteStatement($statementname) {
-
-        $statement =& $this->getStatement($statementname);
-        if ($statement) {
-            $i = $this->findStatementInArray($statementname);
-            $prevstatement = NULL;
-            $nextstatement = NULL;
-        /// Look for prev and next statement
-            $prevstatement =& $this->getStatement($statement->getPrevious());
-            $nextstatement =& $this->getStatement($statement->getNext());
-        /// Change their previous and next attributes
-            if ($prevstatement) {
-                $prevstatement->setNext($statement->getNext());
-            }
-            if ($nextstatement) {
-                $nextstatement->setPrevious($statement->getPrevious());
-            }
-        /// Delete the statement
-            unset($this->statements[$i]);
-        /// Reorder the statements
-            $this->orderStatements($this->statements);
-        /// Recalculate the hash
-            $this->calculateHash(true);
-        /// We have one deleted statement, so the structure has changed
-            $this->setVersion(userdate(time(), '%Y%m%d', 99, false));
-            $this->setChanged(true);
-        }
-    }
-
-    /**
-     * Set the tables
-     */
-    function setTables(&$tables) {
-        $this->tables = $tables;
-    }
-
-    /**
-     * Set the statements
-     */
-    function setStatements(&$statements) {
-        $this->statements = $statements;
-    }
-
-    /**
-     * Load data from XML to the structure
-     */
-    function arr2XMLDBStructure($xmlarr) {
-
-        global $CFG;
-
-        $result = true;
-
-    /// Debug the structure
-    /// traverse_xmlize($xmlarr);                   //Debug
-    /// print_object ($GLOBALS['traverse_array']);  //Debug
-    /// $GLOBALS['traverse_array']="";              //Debug
-
-    /// Process structure attributes (path, comment and version)
-        if (isset($xmlarr['XMLDB']['@']['PATH'])) {
-            $this->path = trim($xmlarr['XMLDB']['@']['PATH']);
-        } else {
-            $this->errormsg = 'Missing PATH attribute';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-        if (isset($xmlarr['XMLDB']['@']['VERSION'])) {
-            $this->version = trim($xmlarr['XMLDB']['@']['VERSION']);
-        } else {
-            $this->errormsg = 'Missing VERSION attribute';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-        if (isset($xmlarr['XMLDB']['@']['COMMENT'])) {
-            $this->comment = trim($xmlarr['XMLDB']['@']['COMMENT']);
-        } else if (!empty($CFG->xmldbdisablecommentchecking)) {
-            $this->comment = '';
-        } else {
-            $this->errormsg = 'Missing COMMENT attribute';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-
-    /// Iterate over tables
-        if (isset($xmlarr['XMLDB']['#']['TABLES']['0']['#']['TABLE'])) {
-            foreach ($xmlarr['XMLDB']['#']['TABLES']['0']['#']['TABLE'] as $xmltable) {
-                if (!$result) { //Skip on error
-                    continue;
-                }
-                $name = trim($xmltable['@']['NAME']);
-                $table = new XMLDBTable($name);
-                $table->arr2XMLDBTable($xmltable);
-                $this->tables[] = $table;
-                if (!$table->isLoaded()) {
-                    $this->errormsg = 'Problem loading table ' . $name;
-                    $this->debug($this->errormsg);
-                    $result = false;
-                }
-            }
-        } else {
-            $this->errormsg = 'Missing TABLES section';
-            $this->debug($this->errormsg);
-            $result = false;
-        }
-
-    /// Perform some general checks over tables
-        if ($result && $this->tables) {
-        /// Check tables names are ok (lowercase, a-z _-)
-            if (!$this->checkNameValues($this->tables)) {
-                $this->errormsg = 'Some TABLES name values are incorrect';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        /// Check previous & next are ok (duplicates and existing tables)
-            $this->fixPrevNext($this->tables);
-            if ($result && !$this->checkPreviousNextValues($this->tables)) {
-                $this->errormsg = 'Some TABLES previous/next values are incorrect';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        /// Order tables
-            if ($result && !$this->orderTables($this->tables)) {
-                $this->errormsg = 'Error ordering the tables';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        }
-
-    /// Iterate over statements
-        if (isset($xmlarr['XMLDB']['#']['STATEMENTS']['0']['#']['STATEMENT'])) {
-            foreach ($xmlarr['XMLDB']['#']['STATEMENTS']['0']['#']['STATEMENT'] as $xmlstatement) {
-                if (!$result) { //Skip on error
-                    continue;
-                }
-                $name = trim($xmlstatement['@']['NAME']);
-                $statement = new XMLDBStatement($name);
-                $statement->arr2XMLDBStatement($xmlstatement);
-                $this->statements[] = $statement;
-                if (!$statement->isLoaded()) {
-                    $this->errormsg = 'Problem loading statement ' . $name;
-                    $this->debug($this->errormsg);
-                    $result = false;
-                }
-            }
-        }
-
-    /// Perform some general checks over statements
-        if ($result && $this->statements) {
-        /// Check statements names are ok (lowercase, a-z _-)
-            if (!$this->checkNameValues($this->statements)) {
-                $this->errormsg = 'Some STATEMENTS name values are incorrect';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        /// Check previous & next are ok (duplicates and existing statements)
-            $this->fixPrevNext($this->statements);
-            if ($result && !$this->checkPreviousNextValues($this->statements)) {
-                $this->errormsg = 'Some STATEMENTS previous/next values are incorrect';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        /// Order statements
-            if ($result && !$this->orderStatements($this->statements)) {
-                $this->errormsg = 'Error ordering the statements';
-                $this->debug($this->errormsg);
-                $result = false;
-            }
-        }
-
-    /// Set some attributes
-        if ($result) {
-            $this->loaded = true;
-        }
-        $this->calculateHash();
-        return $result;
-    }
-
-    /**
-     * This function calculate and set the hash of one XMLDBStructure
-     */
-     function calculateHash($recursive = false) {
-        if (!$this->loaded) {
-            $thi