2004-09-12 01:34:24 +00:00
< ? php //$Id$
2003-05-16 21:52:49 +00:00
//Functions used in restore
2007-07-28 09:23:32 +00:00
2003-05-16 23:57:35 +00:00
//This function unzips a zip file in the same directory that it is
2003-05-16 21:52:49 +00:00
//It automatically uses pclzip or command line unzip
2003-08-01 14:34:11 +00:00
function restore_unzip ( $file ) {
2007-07-28 09:23:32 +00:00
2004-10-16 17:34:56 +00:00
return unzip_file ( $file , '' , false );
2003-05-16 21:52:49 +00:00
}
//This function checks if moodle.xml seems to be a valid xml file
//(exists, has an xml header and a course main tag
function restore_check_moodle_file ( $file ) {
2007-07-28 09:23:32 +00:00
2003-05-16 21:52:49 +00:00
$status = true ;
//Check if it exists
if ( $status = is_file ( $file )) {
//Open it and read the first 200 bytes (chars)
$handle = fopen ( $file , " r " );
$first_chars = fread ( $handle , 200 );
$status = fclose ( $handle );
//Chek if it has the requires strings
if ( $status ) {
$status = strpos ( $first_chars , " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> " );
if ( $status !== false ) {
$status = strpos ( $first_chars , " <MOODLE_BACKUP> " );
}
}
2007-07-28 09:23:32 +00:00
}
2003-05-16 21:52:49 +00:00
2007-07-28 09:23:32 +00:00
return $status ;
}
2003-05-16 23:57:35 +00:00
2004-04-09 23:40:37 +00:00
//This function iterates over all modules in backup file, searching for a
//MODNAME_refresh_events() to execute. Perhaps it should ve moved to central Moodle...
function restore_refresh_events ( $restore ) {
2007-07-28 09:23:32 +00:00
2004-04-09 23:40:37 +00:00
global $CFG ;
$status = true ;
2007-07-28 09:23:32 +00:00
2004-04-09 23:40:37 +00:00
//Take all modules in backup
$modules = $restore -> mods ;
//Iterate
foreach ( $modules as $name => $module ) {
//Only if the module is being restored
2006-10-12 08:33:52 +00:00
if ( isset ( $module -> restore ) && $module -> restore == 1 ) {
2004-04-09 23:40:37 +00:00
//Include module library
include_once ( " $CFG->dirroot /mod/ $name /lib.php " );
//If module_refresh_events exists
$function_name = $name . " _refresh_events " ;
if ( function_exists ( $function_name )) {
$status = $function_name ( $restore -> course_id );
}
}
}
return $status ;
}
2004-04-24 00:40:45 +00:00
//This function makes all the necessary calls to xxxx_decode_content_links_caller()
//function in each module, passing them the desired contents to be decoded
//from backup format to destination site/course in order to mantain inter-activities
//working in the backup/restore process
function restore_decode_content_links ( $restore ) {
2006-07-11 10:01:33 +00:00
global $CFG ;
2004-04-24 00:40:45 +00:00
$status = true ;
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <ul> " ;
}
2007-04-18 15:56:21 +00:00
// Restore links in modules.
2004-04-24 00:40:45 +00:00
foreach ( $restore -> mods as $name => $info ) {
//If the module is being restored
2006-10-12 08:33:52 +00:00
if ( isset ( $info -> restore ) && $info -> restore == 1 ) {
2004-04-24 00:40:45 +00:00
//Check if the xxxx_decode_content_links_caller exists
2006-09-20 20:31:09 +00:00
include_once ( " $CFG->dirroot /mod/ $name /restorelib.php " );
2004-04-24 00:40:45 +00:00
$function_name = $name . " _decode_content_links_caller " ;
if ( function_exists ( $function_name )) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " from " ) . " " . get_string ( " modulenameplural " , $name );
}
2004-04-24 00:40:45 +00:00
$status = $function_name ( $restore );
2007-03-01 02:46:04 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2004-04-24 00:40:45 +00:00
}
}
}
2007-04-18 15:56:21 +00:00
2007-11-14 17:03:32 +00:00
// Process all html text also in blocks too
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<li>' . get_string ( 'from' ) . ' ' . get_string ( 'blocks' );
}
if ( ! empty ( $restore -> blockinstanceids )) {
$blocks = blocks_get_record ();
$instances = get_records_list ( 'block_instance' , 'id' , implode ( ',' , $restore -> blockinstanceids ), '' , 'id,blockid,configdata' );
foreach ( $instances as $instance ) {
if ( ! isset ( $blocks [ $instance -> blockid ] -> blockobject )) {
$blocks [ $instance -> blockid ] -> blockobject = block_instance ( $blocks [ $instance -> blockid ] -> name );
}
$config = unserialize ( base64_decode ( $instance -> configdata ));
if ( $blocks [ $instance -> blockid ] -> blockobject -> restore_decode_absolute_links_in_config ( $config )) {
echo '<p>Updating config for block ' , $instance -> id , '.</p>' ;
$instance -> configdata = base64_encode ( serialize ( $config ));
$status = $status && update_record ( 'block_instance' , $instance );
}
}
}
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2007-04-18 15:56:21 +00:00
// Restore links in questions.
2007-04-21 12:38:56 +00:00
require_once ( " $CFG->dirroot /question/restorelib.php " );
2007-04-18 15:56:21 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<li>' . get_string ( 'from' ) . ' ' . get_string ( 'questions' , 'quiz' );
}
$status = question_decode_content_links_caller ( $restore );
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " </ul> " ;
}
2007-04-18 15:56:21 +00:00
2004-04-24 00:40:45 +00:00
return $status ;
}
2007-07-28 09:23:32 +00:00
2005-07-04 17:48:59 +00:00
//This function is called from all xxxx_decode_content_links_caller(),
//its task is to ask all modules (maybe other linkable objects) to restore
//links to them.
function restore_decode_content_links_worker ( $content , $restore ) {
foreach ( $restore -> mods as $name => $info ) {
$function_name = $name . " _decode_content_links " ;
if ( function_exists ( $function_name )) {
$content = $function_name ( $content , $restore );
}
}
return $content ;
}
2004-04-24 00:40:45 +00:00
2005-04-12 16:10:47 +00:00
//This function converts all the wiki texts in the restored course
//to the Markdown format. Used only for backup files prior 2005041100.
//It calls every module xxxx_convert_wiki2markdown function
function restore_convert_wiki2markdown ( $restore ) {
$status = true ;
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <ul> " ;
}
2005-04-12 16:10:47 +00:00
foreach ( $restore -> mods as $name => $info ) {
//If the module is being restored
if ( $info -> restore == 1 ) {
2005-04-12 23:40:40 +00:00
//Check if the xxxx_restore_wiki2markdown exists
$function_name = $name . " _restore_wiki2markdown " ;
2005-04-12 16:10:47 +00:00
if ( function_exists ( $function_name )) {
$status = $function_name ( $restore );
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " modulenameplural " , $name );
echo '</li>' ;
}
2005-04-12 16:10:47 +00:00
}
}
}
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " </ul> " ;
}
2004-05-14 00:17:29 +00:00
return $status ;
}
//This function receives a wiki text in the restore process and
//return it with every link to modules " modulename:moduleid"
//converted if possible. See the space before modulename!!
function restore_decode_wiki_content ( $content , $restore ) {
global $CFG ;
2007-07-28 09:23:32 +00:00
2004-05-14 00:17:29 +00:00
$result = $content ;
2007-07-28 09:23:32 +00:00
2004-05-14 00:17:29 +00:00
$searchstring = '/ ([a-zA-Z]+):([0-9]+)\(([^)]+)\)/' ;
//We look for it
preg_match_all ( $searchstring , $content , $foundset );
//If found, then we are going to look for its new id (in backup tables)
2007-07-28 09:23:32 +00:00
if ( $foundset [ 0 ]) {
2004-05-14 00:17:29 +00:00
//print_object($foundset); //Debug
2007-07-28 09:23:32 +00:00
//Iterate over foundset[2]. They are the old_ids
2004-05-14 00:17:29 +00:00
foreach ( $foundset [ 2 ] as $old_id ) {
//We get the needed variables here (course id)
$rec = backup_getid ( $restore -> backup_unique_code , " course_modules " , $old_id );
//Personalize the searchstring
$searchstring = '/ ([a-zA-Z]+):' . $old_id . '\(([^)]+)\)/' ;
//If it is a link to this course, update the link to its new location
if ( $rec -> new_id ) {
//Now replace it
$result = preg_replace ( $searchstring , ' $1:' . $rec -> new_id . '($2)' , $result );
} else {
//It's a foreign link so redirect it to its original URL
$result = preg_replace ( $searchstring , $restore -> original_wwwroot . '/mod/$1/view.php?id=' . $old_id . '($2)' , $result );
}
}
}
return $result ;
}
2003-05-17 17:34:30 +00:00
//This function read the xml file and store it data from the info zone in an object
2003-05-16 23:57:35 +00:00
function restore_read_xml_info ( $xml_file ) {
//We call the main read_xml function, with todo = INFO
$info = restore_read_xml ( $xml_file , " INFO " , false );
return $info ;
}
2007-07-28 09:23:32 +00:00
//This function read the xml file and store it data from the course header zone in an object
2003-05-17 17:34:30 +00:00
function restore_read_xml_course_header ( $xml_file ) {
//We call the main read_xml function, with todo = COURSE_HEADER
$info = restore_read_xml ( $xml_file , " COURSE_HEADER " , false );
return $info ;
}
2003-05-18 15:51:20 +00:00
2005-02-18 16:57:58 +00:00
//This function read the xml file and store its data from the blocks in a object
2007-11-15 05:00:44 +00:00
function restore_read_xml_blocks ( $restore , $xml_file ) {
2004-10-29 17:07:11 +00:00
//We call the main read_xml function, with todo = BLOCKS
2007-11-15 05:00:44 +00:00
$info = restore_read_xml ( $xml_file , 'BLOCKS' , $restore );
2004-10-29 17:07:11 +00:00
return $info ;
}
2003-05-24 00:27:45 +00:00
//This function read the xml file and store its data from the sections in a object
function restore_read_xml_sections ( $xml_file ) {
//We call the main read_xml function, with todo = SECTIONS
$info = restore_read_xml ( $xml_file , " SECTIONS " , false );
2003-05-25 22:58:13 +00:00
return $info ;
}
2007-07-28 09:23:32 +00:00
2006-12-11 15:47:23 +00:00
//This function read the xml file and store its data from the course format in an object
function restore_read_xml_formatdata ( $xml_file ) {
//We call the main read_xml function, with todo = FORMATDATA
$info = restore_read_xml ( $xml_file , 'FORMATDATA' , false );
return $info ;
}
2007-07-28 09:23:32 +00:00
2005-02-07 17:52:58 +00:00
//This function read the xml file and store its data from the metacourse in a object
function restore_read_xml_metacourse ( $xml_file ) {
//We call the main read_xml function, with todo = METACOURSE
$info = restore_read_xml ( $xml_file , " METACOURSE " , false );
return $info ;
}
2005-04-22 00:26:22 +00:00
//This function read the xml file and store its data from the gradebook in a object
function restore_read_xml_gradebook ( $restore , $xml_file ) {
//We call the main read_xml function, with todo = GRADEBOOK
$info = restore_read_xml ( $xml_file , " GRADEBOOK " , $restore );
2007-07-28 09:23:32 +00:00
2005-04-22 00:26:22 +00:00
return $info ;
}
2007-07-28 09:23:32 +00:00
//This function read the xml file and store its data from the users in
2003-05-25 22:58:13 +00:00
//backup_ids->info db (and user's id in $info)
function restore_read_xml_users ( $restore , $xml_file ) {
//We call the main read_xml function, with todo = USERS
$info = restore_read_xml ( $xml_file , " USERS " , $restore );
2003-05-24 00:27:45 +00:00
return $info ;
}
2005-02-13 19:09:41 +00:00
//This function read the xml file and store its data from the messages in
//backup_ids->message backup_ids->message_read and backup_ids->contact and db (and their counters in info)
function restore_read_xml_messages ( $restore , $xml_file ) {
//We call the main read_xml function, with todo = MESSAGES
$info = restore_read_xml ( $xml_file , " MESSAGES " , $restore );
return $info ;
}
2003-06-28 23:18:37 +00:00
//This function read the xml file and store its data from the questions in
//backup_ids->info db (and category's id in $info)
function restore_read_xml_questions ( $restore , $xml_file ) {
//We call the main read_xml function, with todo = QUESTIONS
$info = restore_read_xml ( $xml_file , " QUESTIONS " , $restore );
return $info ;
}
2003-08-18 00:00:22 +00:00
//This function read the xml file and store its data from the scales in
//backup_ids->info db (and scale's id in $info)
function restore_read_xml_scales ( $restore , $xml_file ) {
//We call the main read_xml function, with todo = SCALES
$info = restore_read_xml ( $xml_file , " SCALES " , $restore );
return $info ;
}
2004-01-25 20:57:58 +00:00
//This function read the xml file and store its data from the groups in
//backup_ids->info db (and group's id in $info)
function restore_read_xml_groups ( $restore , $xml_file ) {
//We call the main read_xml function, with todo = GROUPS
$info = restore_read_xml ( $xml_file , " GROUPS " , $restore );
return $info ;
}
2007-01-20 09:28:26 +00:00
//This function read the xml file and store its data from the groupings in
//backup_ids->info db (and grouping's id in $info)
function restore_read_xml_groupings ( $restore , $xml_file ) {
//We call the main read_xml function, with todo = GROUPINGS
$info = restore_read_xml ( $xml_file , " GROUPINGS " , $restore );
return $info ;
}
2007-08-14 00:50:00 +00:00
//This function read the xml file and store its data from the groupings in
//backup_ids->info db (and grouping's id in $info)
function restore_read_xml_groupings_groups ( $restore , $xml_file ) {
//We call the main read_xml function, with todo = GROUPINGS
$info = restore_read_xml ( $xml_file , " GROUPINGSGROUPS " , $restore );
return $info ;
}
2004-02-21 01:30:22 +00:00
//This function read the xml file and store its data from the events (course) in
//backup_ids->info db (and event's id in $info)
function restore_read_xml_events ( $restore , $xml_file ) {
//We call the main read_xml function, with todo = EVENTS
$info = restore_read_xml ( $xml_file , " EVENTS " , $restore );
return $info ;
}
2003-05-30 21:32:04 +00:00
//This function read the xml file and store its data from the modules in
//backup_ids->info
function restore_read_xml_modules ( $restore , $xml_file ) {
//We call the main read_xml function, with todo = MODULES
$info = restore_read_xml ( $xml_file , " MODULES " , $restore );
return $info ;
}
2004-02-13 23:28:45 +00:00
//This function read the xml file and store its data from the logs in
//backup_ids->info
function restore_read_xml_logs ( $restore , $xml_file ) {
//We call the main read_xml function, with todo = LOGS
$info = restore_read_xml ( $xml_file , " LOGS " , $restore );
return $info ;
}
2006-10-02 08:49:07 +00:00
function restore_read_xml_roles ( $xml_file ) {
2006-09-25 09:10:19 +00:00
//We call the main read_xml function, with todo = ROLES
2006-10-02 08:49:07 +00:00
$info = restore_read_xml ( $xml_file , " ROLES " , false );
2006-09-25 09:10:19 +00:00
2007-07-28 09:23:32 +00:00
return $info ;
2006-09-25 09:10:19 +00:00
}
2003-05-18 15:51:20 +00:00
//This function prints the contents from the info parammeter passed
function restore_print_info ( $info ) {
2006-05-03 02:00:32 +00:00
global $CFG ;
2003-05-18 15:51:20 +00:00
$status = true ;
if ( $info ) {
2007-08-15 10:43:25 +00:00
$table = new object ();
2007-07-28 09:23:32 +00:00
//This is tha align to every ingo table
2005-02-07 23:28:52 +00:00
$table -> align = array ( " right " , " left " );
2007-07-28 09:23:32 +00:00
//This is the nowrap clause
2005-02-07 23:28:52 +00:00
$table -> wrap = array ( " " , " nowrap " );
2003-05-18 15:51:20 +00:00
//The width
$table -> width = " 70% " ;
//Put interesting info in table
//The backup original name
$tab [ 0 ][ 0 ] = " <b> " . get_string ( " backuporiginalname " ) . " :</b> " ;
$tab [ 0 ][ 1 ] = $info -> backup_name ;
//The moodle version
$tab [ 1 ][ 0 ] = " <b> " . get_string ( " moodleversion " ) . " :</b> " ;
$tab [ 1 ][ 1 ] = $info -> backup_moodle_release . " ( " . $info -> backup_moodle_version . " ) " ;
//The backup version
$tab [ 2 ][ 0 ] = " <b> " . get_string ( " backupversion " ) . " :</b> " ;
$tab [ 2 ][ 1 ] = $info -> backup_backup_release . " ( " . $info -> backup_backup_version . " ) " ;
//The backup date
$tab [ 3 ][ 0 ] = " <b> " . get_string ( " backupdate " ) . " :</b> " ;
$tab [ 3 ][ 1 ] = userdate ( $info -> backup_date );
//Print title
print_heading ( get_string ( " backup " ) . " : " );
$table -> data = $tab ;
//Print backup general info
print_table ( $table );
2006-05-03 02:00:32 +00:00
2006-11-11 17:23:20 +00:00
if ( $info -> backup_backup_version <= 2005070500 ) {
2006-05-03 02:00:32 +00:00
notify ( get_string ( 'backupnonisowarning' )); // Message informing that this backup may not work!
}
2003-05-18 15:51:20 +00:00
//Now backup contents in another table
$tab = array ();
//First mods info
$mods = $info -> mods ;
$elem = 0 ;
foreach ( $mods as $key => $mod ) {
$tab [ $elem ][ 0 ] = " <b> " . get_string ( " modulenameplural " , $key ) . " :</b> " ;
if ( $mod -> backup == " false " ) {
$tab [ $elem ][ 1 ] = get_string ( " notincluded " );
} else {
if ( $mod -> userinfo == " true " ) {
$tab [ $elem ][ 1 ] = get_string ( " included " ) . " " . get_string ( " withuserdata " );
} else {
$tab [ $elem ][ 1 ] = get_string ( " included " ) . " " . get_string ( " withoutuserdata " );
}
2006-10-12 02:13:58 +00:00
if ( isset ( $mod -> instances ) && is_array ( $mod -> instances ) && count ( $mod -> instances )) {
2006-01-13 03:45:31 +00:00
foreach ( $mod -> instances as $instance ) {
if ( $instance -> backup ) {
$elem ++ ;
$tab [ $elem ][ 0 ] = $instance -> name ;
if ( $instance -> userinfo == 'true' ) {
$tab [ $elem ][ 1 ] = get_string ( " included " ) . " " . get_string ( " withuserdata " );
} else {
$tab [ $elem ][ 1 ] = get_string ( " included " ) . " " . get_string ( " withoutuserdata " );
}
}
}
}
2003-05-18 15:51:20 +00:00
}
$elem ++ ;
}
2005-02-07 17:52:58 +00:00
//Metacourse info
$tab [ $elem ][ 0 ] = " <b> " . get_string ( " metacourse " ) . " :</b> " ;
if ( $info -> backup_metacourse == " true " ) {
$tab [ $elem ][ 1 ] = get_string ( " yes " );
} else {
$tab [ $elem ][ 1 ] = get_string ( " no " );
}
$elem ++ ;
2003-05-18 15:51:20 +00:00
//Users info
$tab [ $elem ][ 0 ] = " <b> " . get_string ( " users " ) . " :</b> " ;
$tab [ $elem ][ 1 ] = get_string ( $info -> backup_users );
$elem ++ ;
//Logs info
$tab [ $elem ][ 0 ] = " <b> " . get_string ( " logs " ) . " :</b> " ;
if ( $info -> backup_logs == " true " ) {
$tab [ $elem ][ 1 ] = get_string ( " yes " );
} else {
$tab [ $elem ][ 1 ] = get_string ( " no " );
}
$elem ++ ;
//User Files info
$tab [ $elem ][ 0 ] = " <b> " . get_string ( " userfiles " ) . " :</b> " ;
if ( $info -> backup_user_files == " true " ) {
$tab [ $elem ][ 1 ] = get_string ( " yes " );
} else {
$tab [ $elem ][ 1 ] = get_string ( " no " );
}
$elem ++ ;
//Course Files info
$tab [ $elem ][ 0 ] = " <b> " . get_string ( " coursefiles " ) . " :</b> " ;
if ( $info -> backup_course_files == " true " ) {
$tab [ $elem ][ 1 ] = get_string ( " yes " );
} else {
$tab [ $elem ][ 1 ] = get_string ( " no " );
}
$elem ++ ;
2007-08-09 21:50:59 +00:00
//site Files info
$tab [ $elem ][ 0 ] = " <b> " . get_string ( " sitefiles " ) . " :</b> " ;
2007-08-17 09:53:00 +00:00
if ( isset ( $info -> backup_site_files ) && $info -> backup_site_files == " true " ) {
2007-08-09 21:50:59 +00:00
$tab [ $elem ][ 1 ] = get_string ( " yes " );
} else {
$tab [ $elem ][ 1 ] = get_string ( " no " );
}
$elem ++ ;
2005-02-13 23:34:54 +00:00
//Messages info (only showed if present)
2005-02-13 19:09:41 +00:00
if ( $info -> backup_messages == 'true' ) {
2005-02-13 23:34:54 +00:00
$tab [ $elem ][ 0 ] = " <b> " . get_string ( 'messages' , 'message' ) . " :</b> " ;
2005-02-13 19:09:41 +00:00
$tab [ $elem ][ 1 ] = get_string ( 'yes' );
2005-02-13 23:34:54 +00:00
$elem ++ ;
2005-02-13 19:09:41 +00:00
} else {
2005-02-13 23:34:54 +00:00
//Do nothing
2005-02-13 19:09:41 +00:00
}
2003-05-18 15:51:20 +00:00
$table -> data = $tab ;
//Print title
print_heading ( get_string ( " backupdetails " ) . " : " );
//Print backup general info
print_table ( $table );
} else {
$status = false ;
}
return $status ;
}
//This function prints the contents from the course_header parammeter passed
function restore_print_course_header ( $course_header ) {
$status = true ;
if ( $course_header ) {
2007-08-15 12:21:45 +00:00
$table = new object ();
2003-05-18 15:51:20 +00:00
//This is tha align to every ingo table
2005-02-07 23:28:52 +00:00
$table -> align = array ( " right " , " left " );
2003-05-18 15:51:20 +00:00
//The width
$table -> width = " 70% " ;
//Put interesting course header in table
//The course name
$tab [ 0 ][ 0 ] = " <b> " . get_string ( " name " ) . " :</b> " ;
$tab [ 0 ][ 1 ] = $course_header -> course_fullname . " ( " . $course_header -> course_shortname . " ) " ;
//The course summary
$tab [ 1 ][ 0 ] = " <b> " . get_string ( " summary " ) . " :</b> " ;
$tab [ 1 ][ 1 ] = $course_header -> course_summary ;
$table -> data = $tab ;
//Print title
print_heading ( get_string ( " course " ) . " : " );
//Print backup course header info
print_table ( $table );
} else {
2007-07-28 09:23:32 +00:00
$status = false ;
2003-05-18 15:51:20 +00:00
}
return $status ;
}
2003-05-24 00:27:45 +00:00
//This function create a new course record.
//When finished, course_header contains the id of the new course
function restore_create_new_course ( $restore , & $course_header ) {
global $CFG ;
2007-07-28 09:23:32 +00:00
2003-05-24 00:27:45 +00:00
$status = true ;
$fullname = $course_header -> course_fullname ;
$shortname = $course_header -> course_shortname ;
$currentfullname = " " ;
$currentshortname = " " ;
$counter = 0 ;
//Iteratere while the name exists
do {
if ( $counter ) {
2006-04-12 21:53:45 +00:00
$suffixfull = " " . get_string ( " copyasnoun " ) . " " . $counter ;
2003-12-29 20:20:03 +00:00
$suffixshort = " _ " . $counter ;
2003-05-24 00:27:45 +00:00
} else {
$suffixfull = " " ;
$suffixshort = " " ;
}
2003-06-03 16:32:38 +00:00
$currentfullname = $fullname . $suffixfull ;
2007-08-08 19:39:56 +00:00
// Limit the size of shortname - database column accepts <= 100 chars
$currentshortname = substr ( $shortname , 0 , 100 - strlen ( $suffixshort )) . $suffixshort ;
2006-01-19 00:23:01 +00:00
$coursefull = get_record ( " course " , " fullname " , addslashes ( $currentfullname ));
$courseshort = get_record ( " course " , " shortname " , addslashes ( $currentshortname ));
2003-05-24 00:27:45 +00:00
$counter ++ ;
2006-01-19 00:23:01 +00:00
} while ( $coursefull || $courseshort );
2003-05-24 00:27:45 +00:00
//New name = currentname
$course_header -> course_fullname = $currentfullname ;
$course_header -> course_shortname = $currentshortname ;
2007-07-28 09:23:32 +00:00
2007-04-03 09:19:09 +00:00
// first try to get it from restore
if ( $restore -> restore_restorecatto ) {
$category = get_record ( 'course_categories' , 'id' , $restore -> restore_restorecatto );
}
2007-07-28 09:23:32 +00:00
2007-04-03 09:19:09 +00:00
// else we try to get it from the xml file
2003-05-24 00:27:45 +00:00
//Now calculate the category
2007-04-03 09:19:09 +00:00
if ( ! $category ) {
$category = get_record ( " course_categories " , " id " , $course_header -> category -> id ,
" name " , addslashes ( $course_header -> category -> name ));
}
2007-07-28 09:23:32 +00:00
2003-05-24 00:27:45 +00:00
//If no exists, try by name only
if ( ! $category ) {
$category = get_record ( " course_categories " , " name " , addslashes ( $course_header -> category -> name ));
}
2007-07-28 09:23:32 +00:00
2003-05-24 00:27:45 +00:00
//If no exists, get category id 1
if ( ! $category ) {
$category = get_record ( " course_categories " , " id " , " 1 " );
}
2007-04-03 09:19:09 +00:00
2003-09-23 16:40:44 +00:00
//If category 1 doesn'exists, lets create the course category (get it from backup file)
if ( ! $category ) {
2007-08-15 10:43:25 +00:00
$ins_category = new object ();
2003-09-23 16:40:44 +00:00
$ins_category -> name = addslashes ( $course_header -> category -> name );
$ins_category -> parent = 0 ;
$ins_category -> sortorder = 0 ;
$ins_category -> coursecount = 0 ;
$ins_category -> visible = 0 ; //To avoid interferences with the rest of the site
$ins_category -> timemodified = time ();
$newid = insert_record ( " course_categories " , $ins_category );
$category -> id = $newid ;
$category -> name = $course_header -> category -> name ;
}
2003-05-24 00:27:45 +00:00
//If exists, put new category id
if ( $category ) {
$course_header -> category -> id = $category -> id ;
$course_header -> category -> name = $category -> name ;
//Error, cannot locate category
} else {
$course_header -> category -> id = 0 ;
2003-08-09 12:40:08 +00:00
$course_header -> category -> name = get_string ( " unknowncategory " );
2003-05-24 00:27:45 +00:00
$status = false ;
}
//Create the course_object
if ( $status ) {
2007-08-14 20:35:04 +00:00
$course = new object ();
2003-05-24 00:27:45 +00:00
$course -> category = addslashes ( $course_header -> category -> id );
$course -> password = addslashes ( $course_header -> course_password );
$course -> fullname = addslashes ( $course_header -> course_fullname );
$course -> shortname = addslashes ( $course_header -> course_shortname );
2004-06-24 22:41:00 +00:00
$course -> idnumber = addslashes ( $course_header -> course_idnumber );
2004-12-17 03:04:24 +00:00
$course -> idnumber = '' ; //addslashes($course_header->course_idnumber); // we don't want this at all.
2007-08-10 05:22:20 +00:00
$course -> summary = backup_todb ( $course_header -> course_summary );
2003-05-24 00:27:45 +00:00
$course -> format = addslashes ( $course_header -> course_format );
2003-08-20 07:32:24 +00:00
$course -> showgrades = addslashes ( $course_header -> course_showgrades );
2003-05-24 00:27:45 +00:00
$course -> newsitems = addslashes ( $course_header -> course_newsitems );
$course -> teacher = addslashes ( $course_header -> course_teacher );
$course -> teachers = addslashes ( $course_header -> course_teachers );
$course -> student = addslashes ( $course_header -> course_student );
$course -> students = addslashes ( $course_header -> course_students );
$course -> guest = addslashes ( $course_header -> course_guest );
$course -> startdate = addslashes ( $course_header -> course_startdate );
2006-09-13 09:40:55 +00:00
$course -> startdate += $restore -> course_startdateoffset ;
2003-05-24 00:27:45 +00:00
$course -> numsections = addslashes ( $course_header -> course_numsections );
2004-05-07 22:39:37 +00:00
//$course->showrecent = addslashes($course_header->course_showrecent); INFO: This is out in 1.3
2003-10-07 11:58:56 +00:00
$course -> maxbytes = addslashes ( $course_header -> course_maxbytes );
2003-10-31 05:57:30 +00:00
$course -> showreports = addslashes ( $course_header -> course_showreports );
2005-06-19 18:29:33 +00:00
if ( isset ( $course_header -> course_groupmode )) {
$course -> groupmode = addslashes ( $course_header -> course_groupmode );
}
if ( isset ( $course_header -> course_groupmodeforce )) {
$course -> groupmodeforce = addslashes ( $course_header -> course_groupmodeforce );
}
2007-08-14 20:35:04 +00:00
if ( isset ( $course_header -> course_defaultgroupingid )) {
//keep the original now - convert after groupings restored
$course -> defaultgroupingid = addslashes ( $course_header -> course_defaultgroupingid );
}
2004-02-09 22:24:34 +00:00
$course -> lang = addslashes ( $course_header -> course_lang );
2005-02-15 18:37:08 +00:00
$course -> theme = addslashes ( $course_header -> course_theme );
2004-06-26 12:36:55 +00:00
$course -> cost = addslashes ( $course_header -> course_cost );
2006-10-12 06:58:14 +00:00
$course -> currency = isset ( $course_header -> course_currency ) ? addslashes ( $course_header -> course_currency ) : '' ;
2003-05-24 00:27:45 +00:00
$course -> marker = addslashes ( $course_header -> course_marker );
2003-07-21 07:35:58 +00:00
$course -> visible = addslashes ( $course_header -> course_visible );
2004-05-02 22:34:13 +00:00
$course -> hiddensections = addslashes ( $course_header -> course_hiddensections );
2003-05-24 00:27:45 +00:00
$course -> timecreated = addslashes ( $course_header -> course_timecreated );
$course -> timemodified = addslashes ( $course_header -> course_timemodified );
2005-02-07 17:52:58 +00:00
$course -> metacourse = addslashes ( $course_header -> course_metacourse );
2007-07-16 20:18:26 +00:00
$course -> expirynotify = isset ( $course_header -> course_expirynotify ) ? addslashes ( $course_header -> course_expirynotify ) : 0 ;
$course -> notifystudents = isset ( $course_header -> course_notifystudents ) ? addslashes ( $course_header -> course_notifystudents ) : 0 ;
$course -> expirythreshold = isset ( $course_header -> course_expirythreshold ) ? addslashes ( $course_header -> course_expirythreshold ) : 0 ;
$course -> enrollable = isset ( $course_header -> course_enrollable ) ? addslashes ( $course_header -> course_enrollable ) : 1 ;
$course -> enrolstartdate = isset ( $course_header -> course_enrolstartdate ) ? addslashes ( $course_header -> course_enrolstartdate ) : 0 ;
if ( $course -> enrolstartdate ) { //Roll course dates
$course -> enrolstartdate += $restore -> course_startdateoffset ;
}
$course -> enrolenddate = isset ( $course_header -> course_enrolenddate ) ? addslashes ( $course_header -> course_enrolenddate ) : 0 ;
if ( $course -> enrolenddate ) { //Roll course dates
$course -> enrolenddate += $restore -> course_startdateoffset ;
}
$course -> enrolperiod = addslashes ( $course_header -> course_enrolperiod );
2004-11-27 23:33:39 +00:00
//Calculate sortorder field
$sortmax = get_record_sql ( ' SELECT MAX ( sortorder ) AS max
FROM ' . $CFG->prefix . ' course
2005-02-24 21:14:32 +00:00
WHERE category = ' . $course -> category );
2004-11-27 23:33:39 +00:00
if ( ! empty ( $sortmax -> max )) {
$course -> sortorder = $sortmax -> max + 1 ;
unset ( $sortmax );
} else {
$course -> sortorder = 100 ;
}
2005-01-23 23:24:58 +00:00
//Now, recode some languages (Moodle 1.5)
if ( $course -> lang == 'ma_nt' ) {
$course -> lang = 'mi_nt' ;
}
2005-02-07 17:52:58 +00:00
//Disable course->metacourse if avoided in restore config
if ( ! $restore -> metacourse ) {
$course -> metacourse = 0 ;
}
2005-02-15 18:37:08 +00:00
//Check if the theme exists in destination server
$themes = get_list_of_themes ();
if ( ! in_array ( $course -> theme , $themes )) {
$course -> theme = '' ;
2007-07-28 09:23:32 +00:00
}
2005-02-15 18:37:08 +00:00
2003-05-24 00:27:45 +00:00
//Now insert the record
$newid = insert_record ( " course " , $course );
if ( $newid ) {
//save old and new course id
backup_putid ( $restore -> backup_unique_code , " course " , $course_header -> course_id , $newid );
//Replace old course_id in course_header
$course_header -> course_id = $newid ;
} else {
$status = false ;
}
}
return $status ;
}
2007-07-28 09:23:32 +00:00
2005-05-14 23:32:32 +00:00
2005-01-27 19:07:51 +00:00
//This function creates all the block stuff when restoring courses
2007-07-28 09:23:32 +00:00
//It calls selectively to restore_create_block_instances() for 1.5
2005-01-27 19:07:51 +00:00
//and above backups. Upwards compatible with old blocks.
function restore_create_blocks ( $restore , $backup_block_format , $blockinfo , $xml_file ) {
$status = true ;
2005-01-31 02:18:15 +00:00
delete_records ( 'block_instance' , 'pageid' , $restore -> course_id , 'pagetype' , PAGE_COURSE_VIEW );
2005-01-27 19:07:51 +00:00
if ( empty ( $backup_block_format )) { // This is a backup from Moodle < 1.5
if ( empty ( $blockinfo )) {
// Looks like it's from Moodle < 1.3. Let's give the course default blocks...
2005-01-31 02:18:15 +00:00
$newpage = page_create_object ( PAGE_COURSE_VIEW , $restore -> course_id );
2005-01-27 19:07:51 +00:00
blocks_repopulate_page ( $newpage );
} else {
// We just have a blockinfo field, this is a legacy 1.4 or 1.3 backup
$blockrecords = get_records_select ( 'block' , '' , '' , 'name, id' );
$temp_blocks_l = array ();
$temp_blocks_r = array ();
@ list ( $temp_blocks_l , $temp_blocks_r ) = explode ( ':' , $blockinfo );
$temp_blocks = array ( BLOCK_POS_LEFT => explode ( ',' , $temp_blocks_l ), BLOCK_POS_RIGHT => explode ( ',' , $temp_blocks_r ));
foreach ( $temp_blocks as $blockposition => $blocks ) {
$blockweight = 0 ;
2007-07-28 09:23:32 +00:00
foreach ( $blocks as $blockname ) {
2005-01-27 19:07:51 +00:00
if ( ! isset ( $blockrecords [ $blockname ])) {
// We don't know anything about this block!
continue ;
}
$blockinstance = new stdClass ;
// Remove any - prefix before doing the name-to-id mapping
if ( substr ( $blockname , 0 , 1 ) == '-' ) {
$blockname = substr ( $blockname , 1 );
$blockinstance -> visible = 0 ;
} else {
$blockinstance -> visible = 1 ;
}
$blockinstance -> blockid = $blockrecords [ $blockname ] -> id ;
$blockinstance -> pageid = $restore -> course_id ;
2005-01-31 02:18:15 +00:00
$blockinstance -> pagetype = PAGE_COURSE_VIEW ;
2005-01-27 19:07:51 +00:00
$blockinstance -> position = $blockposition ;
$blockinstance -> weight = $blockweight ;
if ( ! $status = insert_record ( 'block_instance' , $blockinstance )) {
$status = false ;
}
++ $blockweight ;
}
}
}
2005-01-27 19:43:42 +00:00
} else if ( $backup_block_format == 'instances' ) {
$status = restore_create_block_instances ( $restore , $xml_file );
2005-01-27 19:07:51 +00:00
}
return $status ;
2007-07-28 09:23:32 +00:00
}
2005-01-27 19:07:51 +00:00
2004-10-29 17:07:11 +00:00
//This function creates all the block_instances from xml when restoring in a
//new course
function restore_create_block_instances ( $restore , $xml_file ) {
2007-11-15 05:00:44 +00:00
global $CFG ;
2004-10-29 17:07:11 +00:00
$status = true ;
2007-11-15 05:00:44 +00:00
$CFG -> restore_blockinstanceids = array ();
2007-11-14 17:03:32 +00:00
// Tracks which blocks we create during the restore.
// This is used in restore_decode_content_links.
$restore -> blockinstanceids = array ();
2004-10-29 17:07:11 +00:00
//Check it exists
if ( ! file_exists ( $xml_file )) {
$status = false ;
}
//Get info from xml
if ( $status ) {
2007-11-15 05:00:44 +00:00
$info = restore_read_xml_blocks ( $restore , $xml_file );
2004-10-29 17:07:11 +00:00
}
2005-02-28 04:50:36 +00:00
if ( empty ( $info -> instances )) {
return $status ;
}
2004-10-29 17:07:11 +00:00
2005-02-28 04:50:36 +00:00
// First of all, iterate over the blocks to see which distinct pages we have
// in our hands and arrange the blocks accordingly.
$pageinstances = array ();
foreach ( $info -> instances as $instance ) {
2005-02-28 16:03:05 +00:00
//pagetype and pageid black magic, we have to handle the case of blocks for the
//course, blocks from other pages in that course etc etc etc.
if ( $instance -> pagetype == PAGE_COURSE_VIEW ) {
// This one's easy...
$instance -> pageid = $restore -> course_id ;
}
else {
$parts = explode ( '-' , $instance -> pagetype );
if ( $parts [ 0 ] == 'mod' ) {
if ( ! $restore -> mods [ $parts [ 1 ]] -> restore ) {
continue ;
}
$getid = backup_getid ( $restore -> backup_unique_code , $parts [ 1 ], $instance -> pageid );
$instance -> pageid = $getid -> new_id ;
}
else {
// Not invented here ;-)
continue ;
}
}
2005-02-28 04:50:36 +00:00
if ( ! isset ( $pageinstances [ $instance -> pagetype ])) {
$pageinstances [ $instance -> pagetype ] = array ();
}
if ( ! isset ( $pageinstances [ $instance -> pagetype ][ $instance -> pageid ])) {
$pageinstances [ $instance -> pagetype ][ $instance -> pageid ] = array ();
}
2004-10-29 17:07:11 +00:00
2005-02-28 04:50:36 +00:00
$pageinstances [ $instance -> pagetype ][ $instance -> pageid ][] = $instance ;
}
2004-10-29 17:07:11 +00:00
2005-02-28 04:50:36 +00:00
$blocks = get_records_select ( 'block' , '' , '' , 'name, id, multiple' );
2004-10-29 17:07:11 +00:00
2005-02-28 04:50:36 +00:00
// For each type of page we have restored
foreach ( $pageinstances as $thistypeinstances ) {
2004-10-29 17:07:11 +00:00
2005-02-28 04:50:36 +00:00
// For each page id of that type
foreach ( $thistypeinstances as $thisidinstances ) {
$addedblocks = array ();
$maxweights = array ();
// For each block instance in that page
foreach ( $thisidinstances as $instance ) {
if ( ! isset ( $blocks [ $instance -> name ])) {
//We are trying to restore a block we don't have...
continue ;
}
2007-07-28 09:23:32 +00:00
2005-02-28 04:50:36 +00:00
//If we have already added this block once and multiples aren't allowed, disregard it
if ( ! $blocks [ $instance -> name ] -> multiple && isset ( $addedblocks [ $instance -> name ])) {
continue ;
}
//If its the first block we add to a new position, start weight counter equal to 0.
if ( empty ( $maxweights [ $instance -> position ])) {
$maxweights [ $instance -> position ] = 0 ;
}
2007-07-28 09:23:32 +00:00
2005-02-28 04:50:36 +00:00
//If the instance weight is greater than the weight counter (we skipped some earlier
//blocks most probably), bring it back in line.
if ( $instance -> weight > $maxweights [ $instance -> position ]) {
$instance -> weight = $maxweights [ $instance -> position ];
}
2004-10-29 17:07:11 +00:00
2005-02-28 04:50:36 +00:00
//Add this instance
$instance -> blockid = $blocks [ $instance -> name ] -> id ;
2007-07-28 09:23:32 +00:00
2007-11-15 05:00:44 +00:00
// This will only be set if we come from 1.7 and above backups
// Also, must do this before insert (insert_record unsets id)
if ( ! empty ( $instance -> id )) {
$oldid = $instance -> id ;
} else {
$oldid = 0 ;
}
if ( $instance -> id = insert_record ( 'block_instance' , $instance )) {
// Save the new ID for later+
$CFG -> restore_blockinstanceids [] = $instance -> id ;
// Create block instance
if ( ! $blockobj = block_instance ( $instance -> name , $instance )) {
$status = false ;
break ;
}
// Run the block restore if needed
if ( $blockobj -> backuprestore_enabled ()) {
// Get restore information
$data = backup_getid ( $restore -> backup_unique_code , 'block_instance' , $oldid );
$data -> new_id = $instance -> id ; // For completeness
if ( ! $blockobj -> instance_restore ( $restore , $data )) {
$status = false ;
break ;
}
}
// Save oldid after block restore process because info will be over-written with blank string
if ( $oldid ) {
backup_putid ( $restore -> backup_unique_code , " block_instance " , $oldid , $instance -> id );
2006-10-04 09:01:50 +00:00
}
2007-11-14 17:03:32 +00:00
$restore -> blockinstanceids [] = $newid ;
2006-09-27 08:59:27 +00:00
} else {
2005-02-28 04:50:36 +00:00
$status = false ;
2007-07-28 09:23:32 +00:00
break ;
2005-02-28 04:50:36 +00:00
}
2007-07-28 09:23:32 +00:00
2006-09-21 12:07:15 +00:00
//Get an object for the block and tell it it's been restored so it can update dates
//etc. if necessary
2007-11-15 05:00:44 +00:00
if ( $blockobj = block_instance ( $instance -> name , $instance )) {
$blockobj -> after_restore ( $restore );
}
2007-07-28 09:23:32 +00:00
2005-02-28 04:50:36 +00:00
//Now we can increment the weight counter
++ $maxweights [ $instance -> position ];
2007-07-28 09:23:32 +00:00
2005-02-28 04:50:36 +00:00
//Keep track of block types we have already added
$addedblocks [ $instance -> name ] = true ;
2004-10-29 17:07:11 +00:00
2005-02-28 04:50:36 +00:00
}
2004-10-29 17:07:11 +00:00
}
}
return $status ;
}
2003-05-24 00:27:45 +00:00
//This function creates all the course_sections and course_modules from xml
2003-05-28 23:41:56 +00:00
//when restoring in a new course or simply checks sections and create records
//in backup_ids when restoring in a existing course
2006-08-25 02:37:54 +00:00
function restore_create_sections ( & $restore , $xml_file ) {
2003-05-24 00:27:45 +00:00
2003-05-28 23:41:56 +00:00
global $CFG , $db ;
2003-05-24 00:27:45 +00:00
$status = true ;
//Check it exists
if ( ! file_exists ( $xml_file )) {
$status = false ;
}
//Get info from xml
if ( $status ) {
$info = restore_read_xml_sections ( $xml_file );
}
//Put the info in the DB, recoding ids and saving the in backup tables
$sequence = " " ;
if ( $info ) {
//For each, section, save it to db
foreach ( $info -> sections as $key => $sect ) {
$sequence = " " ;
2007-08-15 10:43:25 +00:00
$section = new object ();
2003-05-24 00:27:45 +00:00
$section -> course = $restore -> course_id ;
$section -> section = $sect -> number ;
2007-08-10 05:22:20 +00:00
$section -> summary = backup_todb ( $sect -> summary );
2003-05-24 00:27:45 +00:00
$section -> visible = $sect -> visible ;
$section -> sequence = " " ;
2003-05-28 23:41:56 +00:00
//Now calculate the section's newid
$newid = 0 ;
2003-08-02 23:37:41 +00:00
if ( $restore -> restoreto == 2 ) {
2006-08-25 02:37:54 +00:00
//Save it to db (only if restoring to new course)
2003-05-28 23:41:56 +00:00
$newid = insert_record ( " course_sections " , $section );
} else {
//Get section id when restoring in existing course
$rec = get_record ( " course_sections " , " course " , $restore -> course_id ,
" section " , $section -> section );
//If that section doesn't exist, get section 0 (every mod will be
//asigned there
if ( ! $rec ) {
$rec = get_record ( " course_sections " , " course " , $restore -> course_id ,
" section " , " 0 " );
}
2003-09-22 08:30:22 +00:00
//New check. If section 0 doesn't exist, insert it here !!
//Teorically this never should happen but, in practice, some users
2006-08-25 02:37:54 +00:00
//have reported this issue.
2003-09-22 08:30:22 +00:00
if ( ! $rec ) {
2007-08-15 10:43:25 +00:00
$zero_sec = new object ();
2003-09-22 08:30:22 +00:00
$zero_sec -> course = $restore -> course_id ;
$zero_sec -> section = 0 ;
$zero_sec -> summary = " " ;
$zero_sec -> sequence = " " ;
$newid = insert_record ( " course_sections " , $zero_sec );
$rec -> id = $newid ;
$rec -> sequence = " " ;
}
2003-05-28 23:41:56 +00:00
$newid = $rec -> id ;
$sequence = $rec -> sequence ;
}
2003-05-24 00:27:45 +00:00
if ( $newid ) {
//save old and new section id
backup_putid ( $restore -> backup_unique_code , " course_sections " , $key , $newid );
} else {
$status = false ;
}
//If all is OK, go with associated mods
if ( $status ) {
//If we have mods in the section
2003-08-25 01:44:01 +00:00
if ( ! empty ( $sect -> mods )) {
2003-05-24 00:27:45 +00:00
//For each mod inside section
foreach ( $sect -> mods as $keym => $mod ) {
2007-07-28 09:23:32 +00:00
// Yu: This part is called repeatedly for every instance,
// so it is necessary to set the granular flag and check isset()
2006-10-05 04:05:07 +00:00
// when the first instance of this type of mod is processed.
2007-07-28 09:23:32 +00:00
2007-06-13 09:06:44 +00:00
//if (!isset($restore->mods[$mod->type]->granular) && isset($restore->mods[$mod->type]->instances) && is_array($restore->mods[$mod->type]->instances)) {
2007-07-28 09:23:32 +00:00
2007-06-13 09:06:44 +00:00
if ( ! isset ( $restore -> mods [ $mod -> type ] -> granular )) {
2007-07-28 09:23:32 +00:00
if ( isset ( $restore -> mods [ $mod -> type ] -> instances ) && is_array ( $restore -> mods [ $mod -> type ] -> instances )) {
2007-06-13 09:06:44 +00:00
// This defines whether we want to restore specific
// instances of the modules (granular restore), or
// whether we don't care and just want to restore
// all module instances (non-granular).
$restore -> mods [ $mod -> type ] -> granular = true ;
} else {
$restore -> mods [ $mod -> type ] -> granular = false ;
}
2006-10-05 04:05:07 +00:00
}
2007-07-28 09:23:32 +00:00
//Check if we've to restore this module (and instance)
if ( ! empty ( $restore -> mods [ $mod -> type ] -> restore )) {
2006-10-04 09:01:50 +00:00
if ( empty ( $restore -> mods [ $mod -> type ] -> granular ) // we don't care about per instance
2007-07-28 09:23:32 +00:00
|| ( array_key_exists ( $mod -> instance , $restore -> mods [ $mod -> type ] -> instances )
2006-01-13 03:45:31 +00:00
&& ! empty ( $restore -> mods [ $mod -> type ] -> instances [ $mod -> instance ] -> restore ))) {
2007-07-28 09:23:32 +00:00
2006-01-13 03:45:31 +00:00
//Get the module id from modules
$module = get_record ( " modules " , " name " , $mod -> type );
if ( $module ) {
2007-08-15 10:43:25 +00:00
$course_module = new object ();
2006-01-13 03:45:31 +00:00
$course_module -> course = $restore -> course_id ;
$course_module -> module = $module -> id ;
$course_module -> section = $newid ;
$course_module -> added = $mod -> added ;
$course_module -> score = $mod -> score ;
$course_module -> indent = $mod -> indent ;
$course_module -> visible = $mod -> visible ;
2007-08-14 20:35:04 +00:00
$course_module -> groupmode = $mod -> groupmode ;
2007-08-15 10:43:25 +00:00
if ( $mod -> groupingid and $grouping = backup_getid ( $restore -> backup_unique_code , " groupings " , $mod -> groupingid )) {
$course_module -> groupingid = $grouping -> new_id ;
} else {
$course_module -> groupingid = 0 ;
}
2007-08-14 20:35:04 +00:00
$course_module -> groupmembersonly = $mod -> groupmembersonly ;
2006-01-13 03:45:31 +00:00
$course_module -> instance = 0 ;
//NOTE: The instance (new) is calculated and updated in db in the
// final step of the restore. We don't know it yet.
2006-09-20 20:31:09 +00:00
//print_object($course_module); //Debug
2006-01-13 03:45:31 +00:00
//Save it to db
2006-10-04 09:01:50 +00:00
2007-07-28 09:23:32 +00:00
$newidmod = insert_record ( " course_modules " , $course_module );
2006-01-13 03:45:31 +00:00
if ( $newidmod ) {
//save old and new module id
//In the info field, we save the original instance of the module
//to use it later
backup_putid ( $restore -> backup_unique_code , " course_modules " ,
$keym , $newidmod , $mod -> instance );
2007-07-28 09:23:32 +00:00
2006-08-25 02:37:54 +00:00
$restore -> mods [ $mod -> type ] -> instances [ $mod -> instance ] -> restored_as_course_module = $newidmod ;
2003-05-24 00:27:45 +00:00
} else {
2006-01-13 03:45:31 +00:00
$status = false ;
}
//Now, calculate the sequence field
if ( $status ) {
if ( $sequence ) {
$sequence .= " , " . $newidmod ;
} else {
$sequence = $newidmod ;
}
2003-05-24 00:27:45 +00:00
}
2006-01-13 03:45:31 +00:00
} else {
$status = false ;
2003-05-24 00:27:45 +00:00
}
}
}
}
}
}
//If all is OK, update sequence field in course_sections
if ( $status ) {
2003-09-22 08:30:22 +00:00
if ( isset ( $sequence )) {
2007-08-15 10:43:25 +00:00
$update_rec = new object ();
2003-09-22 08:30:22 +00:00
$update_rec -> id = $newid ;
$update_rec -> sequence = $sequence ;
$status = update_record ( " course_sections " , $update_rec );
}
2003-05-24 00:27:45 +00:00
}
}
} else {
$status = false ;
}
return $status ;
}
2005-02-07 17:52:58 +00:00
2006-12-11 15:47:23 +00:00
//Called to set up any course-format specific data that may be in the file
function restore_set_format_data ( $restore , $xml_file ) {
global $CFG , $db ;
2007-07-28 09:23:32 +00:00
2006-12-11 15:47:23 +00:00
$status = true ;
//Check it exists
if ( ! file_exists ( $xml_file )) {
return false ;
}
//Load data from XML to info
if ( ! ( $info = restore_read_xml_formatdata ( $xml_file ))) {
return false ;
}
//Process format data if there is any
if ( isset ( $info -> format_data )) {
if ( ! $format = get_field ( 'course' , 'format' , 'id' , $restore -> course_id )) {
return false ;
}
// If there was any data then it must have a restore method
$file = $CFG -> dirroot . " /course/format/ $format /restorelib.php " ;
if ( ! file_exists ( $file )) {
return false ;
}
require_once ( $file );
$function = $format . '_restore_format_data' ;
if ( ! function_exists ( $function )) {
return false ;
}
return $function ( $restore , $info -> format_data );
}
2007-07-28 09:23:32 +00:00
2006-12-11 15:47:23 +00:00
// If we got here then there's no data, but that's cool
return true ;
}
2007-07-28 09:23:32 +00:00
//This function creates all the metacourse data from xml, notifying
2005-02-07 17:52:58 +00:00
//about each incidence
function restore_create_metacourse ( $restore , $xml_file ) {
global $CFG , $db ;
$status = true ;
//Check it exists
if ( ! file_exists ( $xml_file )) {
$status = false ;
}
//Get info from xml
if ( $status ) {
//Load data from XML to info
$info = restore_read_xml_metacourse ( $xml_file );
}
//Process info about metacourse
if ( $status and $info ) {
//Process child records
2006-06-06 17:27:15 +00:00
if ( ! empty ( $info -> childs )) {
2005-02-07 17:52:58 +00:00
foreach ( $info -> childs as $child ) {
$dbcourse = false ;
$dbmetacourse = false ;
//Check if child course exists in destination server
//(by id in the same server or by idnumber and shortname in other server)
2005-02-07 17:58:50 +00:00
if ( $restore -> original_wwwroot == $CFG -> wwwroot ) {
2005-02-07 17:52:58 +00:00
//Same server, lets see by id
$dbcourse = get_record ( 'course' , 'id' , $child -> id );
} else {
//Different server, lets see by idnumber and shortname, and only ONE record
$dbcount = count_records ( 'course' , 'idnumber' , $child -> idnumber , 'shortname' , $child -> shortname );
if ( $dbcount == 1 ) {
$dbcourse = get_record ( 'course' , 'idnumber' , $child -> idnumber , 'shortname' , $child -> shortname );
}
}
//If child course has been found, insert data
if ( $dbcourse ) {
$dbmetacourse -> child_course = $dbcourse -> id ;
$dbmetacourse -> parent_course = $restore -> course_id ;
$status = insert_record ( 'course_meta' , $dbmetacourse );
} else {
//Child course not found, notice!
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<ul><li>' . get_string ( 'childcoursenotfound' ) . ' (' . $child -> id . '/' . $child -> idnumber . '/' . $child -> shortname . ')</li></ul>' ;
}
2005-02-07 17:52:58 +00:00
}
}
//Now, recreate student enrolments...
sync_metacourse ( $restore -> course_id );
}
//Process parent records
2006-06-06 17:27:15 +00:00
if ( ! empty ( $info -> parents )) {
2005-02-07 17:52:58 +00:00
foreach ( $info -> parents as $parent ) {
$dbcourse = false ;
$dbmetacourse = false ;
//Check if parent course exists in destination server
//(by id in the same server or by idnumber and shortname in other server)
2005-02-07 17:58:50 +00:00
if ( $restore -> original_wwwroot == $CFG -> wwwroot ) {
2005-02-07 17:52:58 +00:00
//Same server, lets see by id
$dbcourse = get_record ( 'course' , 'id' , $parent -> id );
} else {
//Different server, lets see by idnumber and shortname, and only ONE record
$dbcount = count_records ( 'course' , 'idnumber' , $parent -> idnumber , 'shortname' , $parent -> shortname );
if ( $dbcount == 1 ) {
$dbcourse = get_record ( 'course' , 'idnumber' , $parent -> idnumber , 'shortname' , $parent -> shortname );
}
}
//If parent course has been found, insert data if it is a metacourse
if ( $dbcourse ) {
if ( $dbcourse -> metacourse ) {
$dbmetacourse -> parent_course = $dbcourse -> id ;
$dbmetacourse -> child_course = $restore -> course_id ;
$status = insert_record ( 'course_meta' , $dbmetacourse );
//Now, recreate student enrolments in parent course
sync_metacourse ( $dbcourse -> id );
} else {
2006-01-15 21:09:13 +00:00
//Parent course isn't metacourse, notice!
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<ul><li>' . get_string ( 'parentcoursenotmetacourse' ) . ' (' . $parent -> id . '/' . $parent -> idnumber . '/' . $parent -> shortname . ')</li></ul>' ;
}
2005-02-07 17:52:58 +00:00
}
} else {
//Parent course not found, notice!
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<ul><li>' . get_string ( 'parentcoursenotfound' ) . ' (' . $parent -> id . '/' . $parent -> idnumber . '/' . $parent -> shortname . ')</li></ul>' ;
}
2005-02-07 17:52:58 +00:00
}
}
}
}
return $status ;
}
2007-07-28 09:23:32 +00:00
//This function creates all the gradebook data from xml, notifying
2005-04-22 00:26:22 +00:00
//about each incidence
function restore_create_gradebook ( $restore , $xml_file ) {
2007-08-20 04:15:49 +00:00
global $CFG , $db , $SESSION ;
2005-04-22 00:26:22 +00:00
$status = true ;
//Check it exists
if ( ! file_exists ( $xml_file )) {
2007-05-29 09:00:48 +00:00
return false ;
2005-04-22 00:26:22 +00:00
}
2007-07-28 09:23:32 +00:00
2007-05-29 09:00:48 +00:00
// Get info from xml
// info will contain the number of record to process
$info = restore_read_xml_gradebook ( $restore , $xml_file );
2005-10-16 11:32:57 +00:00
2007-05-29 09:00:48 +00:00
// If we have info, then process
if ( $info <= 0 ) {
2007-07-28 09:23:32 +00:00
return $status ;
2007-05-29 09:00:48 +00:00
}
2007-07-28 09:23:32 +00:00
2007-05-29 09:00:48 +00:00
// Count how many we have
$categoriescount = count_records ( 'backup_ids' , 'backup_code' , $restore -> backup_unique_code , 'table_name' , 'grade_categories' );
$itemscount = count_records ( 'backup_ids' , 'backup_code' , $restore -> backup_unique_code , 'table_name' , 'grade_items' );
2007-10-24 07:41:45 +00:00
$letterscount = count_records ( 'backup_ids' , 'backup_code' , $restore -> backup_unique_code , 'table_name' , 'grade_letters' );
2007-05-29 09:00:48 +00:00
$outcomecount = count_records ( 'backup_ids' , 'backup_code' , $restore -> backup_unique_code , 'table_name' , 'grade_outcomes' );
2007-08-01 05:55:36 +00:00
$outcomescoursescount = count_records ( 'backup_ids' , 'backup_code' , $restore -> backup_unique_code , 'table_name' , 'grade_outcomes_courses' );
2007-08-08 08:42:28 +00:00
$gchcount = count_records ( 'backup_ids' , 'backup_code' , $restore -> backup_unique_code , 'table_name' , 'grade_categories_history' );
$gghcount = count_records ( 'backup_ids' , 'backup_code' , $restore -> backup_unique_code , 'table_name' , 'grade_grades_history' );
$gihcount = count_records ( 'backup_ids' , 'backup_code' , $restore -> backup_unique_code , 'table_name' , 'grade_items_history' );
$gohcount = count_records ( 'backup_ids' , 'backup_code' , $restore -> backup_unique_code , 'table_name' , 'grade_outcomes_history' );
2007-07-28 09:23:32 +00:00
2007-06-13 09:06:44 +00:00
// we need to know if all grade items that were backed up are being restored
2007-07-28 09:23:32 +00:00
// if that is not the case, we do not restore grade categories nor gradeitems of category type or course type
2007-06-13 09:06:44 +00:00
// i.e. the aggregated grades of that category
2007-07-28 09:23:32 +00:00
2007-06-13 09:06:44 +00:00
$restoreall = true ; // set to false if any grade_item is not selected/restored
2007-07-28 09:23:32 +00:00
2007-09-05 15:46:16 +00:00
if ( $recs = get_records_select ( " backup_ids " , " table_name = 'grade_items' AND backup_code = ' $restore->backup_unique_code ' " , " old_id " , " old_id " )) {
2007-06-13 09:06:44 +00:00
foreach ( $recs as $rec ) {
2007-07-28 09:23:32 +00:00
if ( $data = backup_getid ( $restore -> backup_unique_code , 'grade_items' , $rec -> old_id )) {
2007-06-13 09:06:44 +00:00
$info = $data -> info ;
2007-07-28 09:23:32 +00:00
// do not restore if this grade_item is a mod, and
2007-06-13 09:06:44 +00:00
$itemtype = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'ITEMTYPE' ][ '0' ][ '#' ]);
2007-07-28 09:23:32 +00:00
2007-06-13 09:06:44 +00:00
if ( $itemtype == 'mod' ) {
2007-07-28 09:23:32 +00:00
$iteminstance = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'ITEMINSTANCE' ][ '0' ][ '#' ]);
2007-06-13 09:06:44 +00:00
$itemmodule = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'ITEMMODULE' ][ '0' ][ '#' ]);
if ( ! restore_userdata_selected ( $restore , $itemmodule , $iteminstance )) {
// module instance not selected when restored using granular
// we are not restoring all grade items, set flag to false
// so that we do not process grade categories and related grade items/grades
$restoreall = false ;
break ;
}
}
}
2007-08-10 05:22:20 +00:00
}
2007-06-13 09:06:44 +00:00
}
2007-07-28 09:23:32 +00:00
2007-05-29 09:00:48 +00:00
// return if nothing to restore
2007-08-08 08:42:28 +00:00
if ( ! $itemscount && ! $categoriescount && ! $outcomecount ) {
2007-07-28 09:23:32 +00:00
return $status ;
2007-05-29 09:00:48 +00:00
}
2007-06-13 09:06:44 +00:00
2007-05-29 09:00:48 +00:00
// Start ul
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<ul>' ;
}
2007-08-22 09:02:32 +00:00
// fetch the course grade item
require_once ( $CFG -> libdir . '/grade/grade_item.php' );
require_once ( $CFG -> libdir . '/grade/grade_category.php' );
require_once ( $CFG -> libdir . '/gradelib.php' );
$courseitem = grade_item :: fetch_course_item ( $restore -> course_id );
$coursecategory = grade_category :: fetch_course_category ( $restore -> course_id );
2007-05-29 09:00:48 +00:00
// Number of records to get in every chunk
$recordset_size = 2 ;
// Flag to mark if we must continue
$continue = true ;
2005-04-22 00:26:22 +00:00
2007-05-31 09:00:09 +00:00
// Process categories
2007-06-13 09:06:44 +00:00
if ( $categoriescount && $continue && $restoreall ) {
2007-05-29 09:00:48 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<li>' . get_string ( 'gradecategories' , 'grades' ) . '</li>' ;
}
$counter = 0 ;
while ( $counter < $categoriescount ) {
2007-05-31 09:00:09 +00:00
// Fetch recordset_size records in each iteration
2007-05-29 09:00:48 +00:00
$recs = get_records_select ( " backup_ids " , " table_name = 'grade_categories' AND backup_code = ' $restore->backup_unique_code ' " ,
" old_id " ,
2007-09-05 15:46:16 +00:00
" old_id " ,
2007-05-29 09:00:48 +00:00
$counter ,
$recordset_size );
if ( $recs ) {
foreach ( $recs as $rec ) {
2007-05-31 09:00:09 +00:00
// Get the full record from backup_ids
2007-05-29 09:00:48 +00:00
$data = backup_getid ( $restore -> backup_unique_code , 'grade_categories' , $rec -> old_id );
if ( $data ) {
2007-05-31 09:00:09 +00:00
// Now get completed xmlized object
2007-05-29 09:00:48 +00:00
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now build the GRADE_PREFERENCES record structure
2007-07-28 09:23:32 +00:00
$dbrec -> courseid = $restore -> course_id ;
2007-08-22 09:02:32 +00:00
// categories are not backed up during import.
// however, depth 1 categories needs to be skipped during restore into exisiting course
2007-07-28 09:23:32 +00:00
2007-05-31 09:00:09 +00:00
// get the new grade category parent
2007-08-22 09:02:32 +00:00
//if (!empty($info['GRADE_CATEGORY']['#']['PARENT']['0']['#']) && $info['GRADE_CATEGORY']['#']['PARENT']['0']['#'] != '$@NULL@$') {
$parent = backup_getid ( $restore -> backup_unique_code , 'grade_categories' , backup_todb ( $info [ 'GRADE_CATEGORY' ][ '#' ][ 'PARENT' ][ '0' ][ '#' ]));
if ( isset ( $parent -> new_id )) {
2007-05-31 09:00:09 +00:00
$dbrec -> parent = $parent -> new_id ;
2007-08-22 09:02:32 +00:00
} else {
// orphans should get adopted by course category
$dbrec -> parent = $coursecategory -> id ;
2007-05-31 09:00:09 +00:00
}
2007-08-22 09:02:32 +00:00
//}
2007-05-31 09:00:09 +00:00
2007-05-29 09:00:48 +00:00
$dbrec -> fullname = backup_todb ( $info [ 'GRADE_CATEGORY' ][ '#' ][ 'FULLNAME' ][ '0' ][ '#' ]);
$dbrec -> aggregation = backup_todb ( $info [ 'GRADE_CATEGORY' ][ '#' ][ 'AGGREGATION' ][ '0' ][ '#' ]);
$dbrec -> keephigh = backup_todb ( $info [ 'GRADE_CATEGORY' ][ '#' ][ 'KEEPHIGH' ][ '0' ][ '#' ]);
$dbrec -> droplow = backup_todb ( $info [ 'GRADE_CATEGORY' ][ '#' ][ 'DROPLOW' ][ '0' ][ '#' ]);
2007-10-10 08:28:43 +00:00
$dbrec -> aggregateonlygraded = backup_todb ( $info [ 'GRADE_CATEGORY' ][ '#' ][ 'AGGREGATEONLYGRADED' ][ '0' ][ '#' ]);
2007-08-06 12:05:45 +00:00
$dbrec -> aggregateoutcomes = backup_todb ( $info [ 'GRADE_CATEGORY' ][ '#' ][ 'AGGREGATEOUTCOMES' ][ '0' ][ '#' ]);
2007-10-10 08:28:43 +00:00
$dbrec -> aggregatesubcats = backup_todb ( $info [ 'GRADE_CATEGORY' ][ '#' ][ 'AGGREGATESUBCATS' ][ '0' ][ '#' ]);
$dbrec -> timecreated = backup_todb ( $info [ 'GRADE_CATEGORY' ][ '#' ][ 'TIMECREATED' ][ '0' ][ '#' ]);
$dbrec -> timemodified = backup_todb ( $info [ 'GRADE_CATEGORY' ][ '#' ][ 'TIMEMODIFIED' ][ '0' ][ '#' ]);
2007-05-29 09:00:48 +00:00
//Structure is equal to db, insert record
//if the fullname doesn't exist
if ( ! $prerec = get_record ( 'grade_categories' , 'courseid' , $dbrec -> courseid , 'fullname' , $dbrec -> fullname )) {
$newid = insert_record ( 'grade_categories' , $dbrec );
2007-07-28 09:23:32 +00:00
$status = backup_putid ( $restore -> backup_unique_code , 'grade_categories' , $rec -> old_id , $newid );
2007-05-31 09:00:09 +00:00
// update this record so we can put in the right paths
// this can only be done after we got the new id
$dbrec -> id = $newid ;
include_once ( $CFG -> dirroot . '/lib/grade/grade_category.php' );
// rebuild the path, we need only parents info
2007-07-28 09:23:32 +00:00
// the order of restoring should ensure that the parent and grandparent(s)
2007-05-31 09:00:09 +00:00
// are already restored
$dbrec -> path = grade_category :: build_path ( $dbrec );
// this is not needed in the xml because
// given this parent and grandparent(s) we can recalculate the depth
2007-06-28 13:20:30 +00:00
$dbrec -> depth = substr_count ( $dbrec -> path , '/' );
2007-05-31 09:00:09 +00:00
update_record ( 'grade_categories' , $dbrec );
2007-05-29 09:00:48 +00:00
} else {
2007-05-31 09:00:09 +00:00
// if fullname already exists, we should keep the current grade category
2007-07-28 09:23:32 +00:00
$status = backup_putid ( $restore -> backup_unique_code , 'grade_categories' , $rec -> old_id , $rec -> oldid );
2007-05-29 09:00:48 +00:00
}
}
//Increment counters
$counter ++ ;
//Do some output
if ( $counter % 1 == 0 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 20 == 0 ) {
echo " <br /> " ;
}
}
backup_flush ( 300 );
2006-01-15 21:09:13 +00:00
}
2005-04-22 00:26:22 +00:00
}
2007-05-29 09:00:48 +00:00
}
}
}
2005-04-22 00:26:22 +00:00
2007-10-24 07:41:45 +00:00
// Process letters
$context = get_context_instance ( CONTEXT_COURSE , $restore -> course_id );
// respect current grade letters if defined
if ( $letterscount && $continue && ! record_exists ( 'grade_letters' , 'contextid' , $context -> id )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<li>' . get_string ( 'gradeletters' , 'grades' ) . '</li>' ;
}
$counter = 0 ;
while ( $counter < $letterscount ) {
// Fetch recordset_size records in each iteration
$recs = get_records_select ( " backup_ids " , " table_name = 'grade_letters' AND backup_code = ' $restore->backup_unique_code ' " ,
" old_id " ,
" old_id " ,
$counter ,
$recordset_size );
if ( $recs ) {
foreach ( $recs as $rec ) {
// Get the full record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , 'grade_letters' , $rec -> old_id );
if ( $data ) {
// Now get completed xmlized object
$info = $data -> info ;
$dbrec -> contextid = $context -> id ;
$dbrec -> lowerboundary = backup_todb ( $info [ 'GRADE_LETTER' ][ '#' ][ 'LOWERBOUNDARY' ][ '0' ][ '#' ]);
$dbrec -> letter = backup_todb ( $info [ 'GRADE_LETTER' ][ '#' ][ 'LETTER' ][ '0' ][ '#' ]);
// course might already have grade letters defined, if so, skip
insert_record ( 'grade_letters' , $dbrec );
}
$counter ++ ;
}
}
}
}
2007-05-29 09:00:48 +00:00
// process outcomes
if ( $outcomecount && $continue ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<li>' . get_string ( 'gradeoutcomes' , 'grades' ) . '</li>' ;
}
$counter = 0 ;
while ( $counter < $outcomecount ) {
//Fetch recordset_size records in each iteration
$recs = get_records_select ( " backup_ids " , " table_name = 'grade_outcomes' AND backup_code = ' $restore->backup_unique_code ' " ,
" old_id " ,
2007-09-05 15:46:16 +00:00
" old_id " ,
2007-05-29 09:00:48 +00:00
$counter ,
$recordset_size );
if ( $recs ) {
foreach ( $recs as $rec ) {
//Get the full record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , 'grade_outcomes' , $rec -> old_id );
if ( $data ) {
//Now get completed xmlized object
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now build the GRADE_PREFERENCES record structure
2007-07-31 08:26:17 +00:00
if ( $info [ 'GRADE_OUTCOME' ][ '#' ][ 'COURSEID' ][ '0' ][ '#' ]) {
2007-08-09 21:50:59 +00:00
$dbrec -> courseid = $restore -> course_id ;
2007-07-31 08:26:17 +00:00
} else {
$dbrec -> courseid = NULL ;
}
2007-05-29 09:00:48 +00:00
$dbrec -> shortname = backup_todb ( $info [ 'GRADE_OUTCOME' ][ '#' ][ 'SHORTNAME' ][ '0' ][ '#' ]);
$dbrec -> fullname = backup_todb ( $info [ 'GRADE_OUTCOME' ][ '#' ][ 'FULLNAME' ][ '0' ][ '#' ]);
2007-07-28 09:23:32 +00:00
2007-05-29 09:00:48 +00:00
if ( $info [ 'GRADE_OUTCOME' ][ '#' ][ 'SCALEID' ][ '0' ][ '#' ]) {
$scale = backup_getid ( $restore -> backup_unique_code , " scale " , backup_todb ( $info [ 'GRADE_OUTCOME' ][ '#' ][ 'SCALEID' ][ '0' ][ '#' ]));
2007-07-31 09:04:36 +00:00
$dbrec -> scaleid = $scale -> new_id ;
2007-05-29 09:00:48 +00:00
}
2007-10-10 08:28:43 +00:00
$dbrec -> description = backup_todb ( $info [ 'GRADE_OUTCOME' ][ '#' ][ 'DESCRIPTION' ][ '0' ][ '#' ]);
$dbrec -> timecreated = backup_todb ( $info [ 'GRADE_OUTCOME' ][ '#' ][ 'TIMECREATED' ][ '0' ][ '#' ]);
$dbrec -> timemodified = backup_todb ( $info [ 'GRADE_OUTCOME' ][ '#' ][ 'TIMEMODIFIED' ][ '0' ][ '#' ]);
2007-07-28 09:23:32 +00:00
$modifier = backup_getid ( $restore -> backup_unique_code , " user " , backup_todb ( $info [ 'GRADE_OUTCOME' ][ '#' ][ 'USERMODIFIED' ][ '0' ][ '#' ]));
2007-07-31 09:04:36 +00:00
$dbrec -> usermodified = $modifier -> new_id ;
2007-07-28 09:23:32 +00:00
2007-05-29 09:00:48 +00:00
// Structure is equal to db, insert record
2007-08-09 21:50:59 +00:00
// If the shortname doesn't exist
2007-07-31 09:04:36 +00:00
if ( empty ( $info [ 'GRADE_OUTCOME' ][ '#' ][ 'COURSEID' ][ '0' ][ '#' ])) {
2007-08-09 21:50:59 +00:00
$prerec = get_record_sql ( " SELECT * FROM { $CFG -> prefix } grade_outcomes
2007-07-31 09:04:36 +00:00
WHERE courseid IS NULL
AND shortname = '$dbrec->shortname' " );
2007-07-31 08:26:17 +00:00
} else {
2007-07-31 09:04:36 +00:00
$prerec = get_record ( 'grade_outcomes' , 'courseid' , $restore -> course_id , 'shortname' , $dbrec -> shortname );
2007-07-31 08:26:17 +00:00
}
2007-08-09 21:50:59 +00:00
2007-07-31 09:04:36 +00:00
if ( ! $prerec ) {
2007-07-31 08:26:17 +00:00
$newid = insert_record ( 'grade_outcomes' , $dbrec );
} else {
2007-08-09 21:50:59 +00:00
$newid = $prerec -> id ;
2007-07-31 08:26:17 +00:00
}
2007-08-09 21:50:59 +00:00
2007-07-31 08:26:17 +00:00
if ( $newid ) {
backup_putid ( $restore -> backup_unique_code , " grade_outcomes " , $rec -> old_id , $newid );
2007-05-29 09:00:48 +00:00
}
}
//Increment counters
$counter ++ ;
//Do some output
if ( $counter % 1 == 0 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 20 == 0 ) {
echo " <br /> " ;
2006-01-15 21:09:13 +00:00
}
2005-04-22 00:26:22 +00:00
}
2007-05-29 09:00:48 +00:00
backup_flush ( 300 );
2005-04-22 00:26:22 +00:00
}
}
2007-05-29 09:00:48 +00:00
}
}
}
2007-07-28 09:23:32 +00:00
2007-08-01 05:55:36 +00:00
// process outcomescourses
if ( $outcomescoursescount && $continue ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<li>' . get_string ( 'gradeoutcomescourses' , 'grades' ) . '</li>' ;
}
$counter = 0 ;
while ( $counter < $outcomescoursescount ) {
//Fetch recordset_size records in each iteration
$recs = get_records_select ( " backup_ids " , " table_name = 'grade_outcomes_courses' AND backup_code = ' $restore->backup_unique_code ' " ,
" old_id " ,
2007-09-05 15:46:16 +00:00
" old_id " ,
2007-08-01 05:55:36 +00:00
$counter ,
$recordset_size );
if ( $recs ) {
foreach ( $recs as $rec ) {
//Get the full record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , 'grade_outcomes_courses' , $rec -> old_id );
if ( $data ) {
//Now get completed xmlized object
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
$oldoutcomesid = backup_todb ( $info [ 'GRADE_OUTCOMES_COURSE' ][ '#' ][ 'OUTCOMEID' ][ '0' ][ '#' ]);
2007-08-09 21:50:59 +00:00
$newoutcome = backup_getid ( $restore -> backup_unique_code , " grade_outcomes " , $oldoutcomesid );
2007-08-01 05:55:36 +00:00
unset ( $dbrec );
$dbrec -> courseid = $restore -> course_id ;
$dbrec -> outcomeid = $newoutcome -> new_id ;
insert_record ( 'grade_outcomes_courses' , $dbrec );
}
//Increment counters
$counter ++ ;
//Do some output
if ( $counter % 1 == 0 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 20 == 0 ) {
echo " <br /> " ;
}
}
backup_flush ( 300 );
}
}
}
}
}
2007-09-22 11:39:59 +00:00
// Process grade items (grade_grade)
2007-05-29 09:00:48 +00:00
if ( $itemscount && $continue ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<li>' . get_string ( 'gradeitems' , 'grades' ) . '</li>' ;
}
$counter = 0 ;
2007-05-30 05:32:47 +00:00
$counteritems = 0 ;
while ( $counteritems < $itemscount ) {
2007-05-29 09:00:48 +00:00
//Fetch recordset_size records in each iteration
$recs = get_records_select ( " backup_ids " , " table_name = 'grade_items' AND backup_code = ' $restore->backup_unique_code ' " ,
" old_id " ,
2007-09-05 15:46:16 +00:00
" old_id " ,
2007-05-30 05:32:47 +00:00
$counteritems ,
2007-05-29 09:00:48 +00:00
$recordset_size );
2007-08-20 04:15:49 +00:00
2007-05-29 09:00:48 +00:00
if ( $recs ) {
foreach ( $recs as $rec ) {
//Get the full record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , 'grade_items' , $rec -> old_id );
if ( $data ) {
//Now get completed xmlized object
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
2007-07-28 09:23:32 +00:00
2007-05-29 09:00:48 +00:00
$dbrec -> courseid = $restore -> course_id ;
2007-08-20 04:15:49 +00:00
if ( isset ( $SESSION -> restore -> importing )) {
// if we are importing, points all grade_items to the course category
$coursecat = get_record ( 'grade_categories' , 'courseid' , $restore -> course_id , 'depth' , 1 );
$dbrec -> categoryid = $coursecat -> id ;
2007-08-22 09:02:32 +00:00
} else if ( ! empty ( $info [ 'GRADE_ITEM' ][ '#' ][ 'CATEGORYID' ][ '0' ][ '#' ]) && $info [ 'GRADE_ITEM' ][ '#' ][ 'CATEGORYID' ][ '0' ][ '#' ] != '$@NULL@$' ) {
2007-05-31 09:00:09 +00:00
$category = backup_getid ( $restore -> backup_unique_code , 'grade_categories' , backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'CATEGORYID' ][ '0' ][ '#' ]));
2007-11-07 01:11:41 +00:00
if ( ! empty ( $category -> new_id )) {
2007-08-22 09:02:32 +00:00
$dbrec -> categoryid = $category -> new_id ;
} else {
// this could be restoring into existing course, and grade item points to the old course grade item (category)
// which was never imported. In this case we just point them to the new course item
$dbrec -> categoryid = $coursecategory -> id ;
}
2007-05-29 09:00:48 +00:00
}
2005-04-22 00:26:22 +00:00
2007-05-29 09:00:48 +00:00
$dbrec -> itemname = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'ITEMNAME' ][ '0' ][ '#' ]);
2007-05-30 06:23:21 +00:00
$dbrec -> itemtype = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'ITEMTYPE' ][ '0' ][ '#' ]);
2007-05-29 09:00:48 +00:00
$dbrec -> itemmodule = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'ITEMMODULE' ][ '0' ][ '#' ]);
/// this needs to point to either the new mod id
/// or the category id
2007-07-28 09:23:32 +00:00
$iteminstance = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'ITEMINSTANCE' ][ '0' ][ '#' ]);
// do not restore if this grade_item is a mod, and
2007-05-30 06:23:21 +00:00
if ( $dbrec -> itemtype == 'mod' ) {
2007-05-30 08:45:13 +00:00
2007-05-30 06:38:23 +00:00
// iteminstance should point to new mod
2007-07-28 09:23:32 +00:00
2007-08-09 08:58:15 +00:00
$mod = backup_getid ( $restore -> backup_unique_code , $dbrec -> itemmodule , $iteminstance );
$dbrec -> iteminstance = $mod -> new_id ;
2007-05-30 06:38:23 +00:00
} else if ( $dbrec -> itemtype == 'category' ) {
// the item instance should point to the new grade category
2007-07-28 09:23:32 +00:00
2007-06-13 09:06:44 +00:00
// only proceed if we are restoring all grade items
2007-08-20 04:15:49 +00:00
// need to skip for imports
if ( $restoreall && ! isset ( $SESSION -> restore -> importing )) {
2007-07-28 09:23:32 +00:00
$category = backup_getid ( $restore -> backup_unique_code , 'grade_categories' , $iteminstance );
2007-06-13 09:06:44 +00:00
$dbrec -> iteminstance = $category -> new_id ;
} else {
2007-07-28 09:23:32 +00:00
// otherwise we can safely ignore this grade item and subsequent
2007-06-13 09:06:44 +00:00
// grade_raws, grade_finals etc
2007-08-20 04:15:49 +00:00
$counteritems ++ ;
2007-07-28 09:23:32 +00:00
continue ;
}
} elseif ( $dbrec -> itemtype == 'course' ) { // We don't restore course type to avoid duplicate course items
2007-08-22 09:02:32 +00:00
if ( $restoreall && ! isset ( $SESSION -> restore -> importing ) && $restore -> restoreto == 2 ) {
2007-07-28 09:23:32 +00:00
// TODO any special code needed here to restore course item without duplicating it?
2007-07-31 08:26:17 +00:00
// find the course category with depth 1, and course id = current course id
2007-08-22 09:02:32 +00:00
// this would have been already restored
$counteritems ++ ;
continue ;
2007-07-28 09:23:32 +00:00
} else {
2007-08-20 04:15:49 +00:00
$counteritems ++ ;
2007-07-28 09:23:32 +00:00
continue ;
2007-06-13 09:06:44 +00:00
}
2007-05-30 06:23:21 +00:00
}
2007-07-28 09:23:32 +00:00
2007-05-29 09:00:48 +00:00
$dbrec -> itemnumber = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'ITEMNUMBER' ][ '0' ][ '#' ]);
$dbrec -> iteminfo = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'ITEMINFO' ][ '0' ][ '#' ]);
$dbrec -> idnumber = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'IDNUMBER' ][ '0' ][ '#' ]);
2007-10-10 08:28:43 +00:00
$dbrec -> gradetype = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'GRADETYPE' ][ '0' ][ '#' ]);
2007-06-23 16:33:17 +00:00
$dbrec -> calculation = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'CALCULATION' ][ '0' ][ '#' ]);
2007-05-29 09:00:48 +00:00
$dbrec -> grademax = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'GRADEMAX' ][ '0' ][ '#' ]);
$dbrec -> grademin = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'GRADEMIN' ][ '0' ][ '#' ]);
/// needs to be restored first
2007-07-28 09:23:32 +00:00
2007-09-18 04:03:02 +00:00
if ( backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'SCALEID' ][ '0' ][ '#' ])) {
2007-05-29 09:00:48 +00:00
$scale = backup_getid ( $restore -> backup_unique_code , " scale " , backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'SCALEID' ][ '0' ][ '#' ]));
2007-07-31 08:26:17 +00:00
$dbrec -> scaleid = $scale -> new_id ;
2007-05-29 09:00:48 +00:00
}
2007-07-28 09:23:32 +00:00
2007-05-29 09:00:48 +00:00
/// needs to be restored first
2007-10-10 08:28:43 +00:00
/// TODO
if ( backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'OUTCOMEID' ][ '0' ][ '#' ])) {
$outcome = backup_getid ( $restore -> backup_unique_code , " grade_outcomes " , backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'OUTCOMEID' ][ '0' ][ '#' ]));
$dbrec -> outcomeid = $outcome -> new_id ;
}
2007-08-09 21:50:59 +00:00
2007-05-29 09:00:48 +00:00
$dbrec -> gradepass = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'GRADEPASS' ][ '0' ][ '#' ]);
$dbrec -> multfactor = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'MULTFACTOR' ][ '0' ][ '#' ]);
$dbrec -> plusfactor = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'PLUSFACTOR' ][ '0' ][ '#' ]);
2007-10-10 08:28:43 +00:00
$dbrec -> aggregationcoef = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'AGGREGATIONCOEF' ][ '0' ][ '#' ]);
$dbrec -> display = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'DISPLAY' ][ '0' ][ '#' ]);
$dbrec -> decimals = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'DECIMALS' ][ '0' ][ '#' ]);
2007-07-28 09:23:32 +00:00
$dbrec -> hidden = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'HIDDEN' ][ '0' ][ '#' ]);
$dbrec -> locked = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'LOCKED' ][ '0' ][ '#' ]);
$dbrec -> locktime = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'LOCKTIME' ][ '0' ][ '#' ]);
2007-09-18 04:03:02 +00:00
$dbrec -> needsupdate = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'NEEDSUPDATE' ][ '0' ][ '#' ]);
$dbrec -> timecreated = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'TIMECREATED' ][ '0' ][ '#' ]);
$dbrec -> timemodified = backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'TIMEMODIFIED' ][ '0' ][ '#' ]);
2007-07-28 09:23:32 +00:00
2007-05-30 05:32:47 +00:00
// get the current sortorder, add 1 to it and use that
if ( $lastitem = get_record_sql ( " SELECT sortorder, id FROM { $CFG -> prefix } grade_items
WHERE courseid = $restore -> course_id
2007-05-30 08:45:13 +00:00
ORDER BY sortorder DESC " , true)) {
2007-05-30 05:32:47 +00:00
// we just need the first one
$dbrec -> sortorder = $lastitem -> sortorder + 1 ;
} else {
2007-05-30 08:45:13 +00:00
// this is the first grade_item
2007-07-31 08:26:17 +00:00
$dbrec -> sortorder = 1 ;
2007-05-30 05:32:47 +00:00
}
2007-08-07 07:15:48 +00:00
// always insert, since modules restored to existing courses are always inserted
2007-05-30 08:45:13 +00:00
$itemid = insert_record ( 'grade_items' , $dbrec );
2007-08-07 07:15:48 +00:00
if ( $itemid ) {
backup_putid ( $restore -> backup_unique_code , 'grade_items' , backup_todb ( $info [ 'GRADE_ITEM' ][ '#' ][ 'ID' ][ '0' ][ '#' ]), $itemid );
}
2007-08-20 04:15:49 +00:00
2007-09-22 11:39:59 +00:00
// no need to restore grades if user data is not selected
2007-08-20 06:20:53 +00:00
if ( $dbrec -> itemtype == 'mod' && ! restore_userdata_selected ( $restore , $dbrec -> itemmodule , $iteminstance )) {
2007-08-20 04:15:49 +00:00
// module instance not selected when restored using granular
// skip this item
$counteritems ++ ;
continue ;
}
2007-09-22 11:39:59 +00:00
/// now, restore grade_grades
2007-06-20 23:06:29 +00:00
if ( ! empty ( $info [ 'GRADE_ITEM' ][ '#' ][ 'GRADE_GRADES' ][ '0' ][ '#' ]) && ( $grades = $info [ 'GRADE_ITEM' ][ '#' ][ 'GRADE_GRADES' ][ '0' ][ '#' ][ 'GRADE' ])) {
2007-05-29 09:00:48 +00:00
//Iterate over items
2007-06-20 23:06:29 +00:00
for ( $i = 0 ; $i < sizeof ( $grades ); $i ++ ) {
$ite_info = $grades [ $i ];
2007-05-30 08:45:13 +00:00
//traverse_xmlize($ite_info);
//Debug
2007-05-29 09:00:48 +00:00
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now build the GRADE_ITEM record structure
2007-06-20 23:06:29 +00:00
$grade = new object ();
$grade -> itemid = $itemid ;
2007-07-28 09:23:32 +00:00
$user = backup_getid ( $restore -> backup_unique_code , " user " , backup_todb ( $ite_info [ '#' ][ 'USERID' ][ '0' ][ '#' ]));
2007-06-20 23:06:29 +00:00
$grade -> userid = $user -> new_id ;
$grade -> rawgrade = backup_todb ( $ite_info [ '#' ][ 'RAWGRADE' ][ '0' ][ '#' ]);
$grade -> rawgrademax = backup_todb ( $ite_info [ '#' ][ 'RAWGRADEMAX' ][ '0' ][ '#' ]);
$grade -> rawgrademin = backup_todb ( $ite_info [ '#' ][ 'RAWGRADEMIN' ][ '0' ][ '#' ]);
2007-05-29 09:00:48 +00:00
// need to find scaleid
2007-09-18 04:03:02 +00:00
if ( backup_todb ( $ite_info [ '#' ][ 'RAWSCALEID' ][ '0' ][ '#' ])) {
2007-06-20 23:06:29 +00:00
$scale = backup_getid ( $restore -> backup_unique_code , " scale " , backup_todb ( $ite_info [ '#' ][ 'RAWSCALEID' ][ '0' ][ '#' ]));
$grade -> rawscaleid = $scale -> new_id ;
2005-10-16 11:32:57 +00:00
}
2007-10-10 08:28:43 +00:00
if ( backup_todb ( $ite_info [ '#' ][ 'USERMODIFIED' ][ '0' ][ '#' ])) {
if ( $modifier = backup_getid ( $restore -> backup_unique_code , " user " , backup_todb ( $ite_info [ '#' ][ 'USERMODIFIED' ][ '0' ][ '#' ]))) {
$grade -> usermodified = $modifier -> new_id ;
}
}
2007-06-20 23:06:29 +00:00
$grade -> finalgrade = backup_todb ( $ite_info [ '#' ][ 'FINALGRADE' ][ '0' ][ '#' ]);
$grade -> hidden = backup_todb ( $ite_info [ '#' ][ 'HIDDEN' ][ '0' ][ '#' ]);
$grade -> locked = backup_todb ( $ite_info [ '#' ][ 'LOCKED' ][ '0' ][ '#' ]);
$grade -> locktime = backup_todb ( $ite_info [ '#' ][ 'LOCKTIME' ][ '0' ][ '#' ]);
$grade -> exported = backup_todb ( $ite_info [ '#' ][ 'EXPORTED' ][ '0' ][ '#' ]);
2007-07-11 18:06:23 +00:00
$grade -> overridden = backup_todb ( $ite_info [ '#' ][ 'OVERRIDDEN' ][ '0' ][ '#' ]);
2007-07-21 14:24:39 +00:00
$grade -> excluded = backup_todb ( $ite_info [ '#' ][ 'EXCLUDED' ][ '0' ][ '#' ]);
2007-09-22 11:39:59 +00:00
$grade -> feedback = backup_todb ( $ite_info [ '#' ][ 'FEEDBACK' ][ '0' ][ '#' ]);
$grade -> feedbackformat = backup_todb ( $ite_info [ '#' ][ 'FEEDBACKFORMAT' ][ '0' ][ '#' ]);
$grade -> information = backup_todb ( $ite_info [ '#' ][ 'INFORMATION' ][ '0' ][ '#' ]);
$grade -> informationformat = backup_todb ( $ite_info [ '#' ][ 'INFORMATIONFORMAT' ][ '0' ][ '#' ]);
2007-10-10 08:28:43 +00:00
$grade -> timecreated = backup_todb ( $ite_info [ '#' ][ 'TIMECREATED' ][ '0' ][ '#' ]);
$grade -> timemodified = backup_todb ( $ite_info [ '#' ][ 'TIMEMODIFIED' ][ '0' ][ '#' ]);
2007-07-31 08:26:17 +00:00
$newid = insert_record ( 'grade_grades' , $grade );
2007-08-09 08:58:15 +00:00
2007-08-07 07:15:48 +00:00
if ( $newid ) {
backup_putid ( $restore -> backup_unique_code , " grade_grades " , backup_todb ( $ite_info [ '#' ][ 'ID' ][ '0' ][ '#' ]), $newid );
}
2005-10-16 11:32:57 +00:00
$counter ++ ;
2007-05-29 09:00:48 +00:00
if ( $counter % 20 == 0 ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
2007-05-29 09:00:48 +00:00
if ( $counter % 400 == 0 ) {
2006-01-15 21:09:13 +00:00
echo " <br /> " ;
}
2005-04-22 00:26:22 +00:00
}
2005-10-16 11:32:57 +00:00
backup_flush ( 300 );
2005-04-22 00:26:22 +00:00
}
}
}
}
2007-05-30 05:32:47 +00:00
$counteritems ++ ; // increment item count
2005-04-22 00:26:22 +00:00
}
}
2007-07-28 09:23:32 +00:00
2005-04-22 00:26:22 +00:00
}
2007-05-29 09:00:48 +00:00
}
2007-08-08 08:42:28 +00:00
// process histories
2007-09-18 04:03:02 +00:00
if ( $gchcount && $continue && ! isset ( $SESSION -> restore -> importing ) && $restore -> restore_gradebook_history ) {
2007-08-08 08:42:28 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<li>' . get_string ( 'gradecategoryhistory' , 'grades' ) . '</li>' ;
}
$counter = 0 ;
while ( $counter < $gchcount ) {
//Fetch recordset_size records in each iteration
$recs = get_records_select ( " backup_ids " , " table_name = 'grade_categories_history' AND backup_code = ' $restore->backup_unique_code ' " ,
" old_id " ,
2007-09-05 15:46:16 +00:00
" old_id " ,
2007-08-08 08:42:28 +00:00
$counter ,
$recordset_size );
if ( $recs ) {
foreach ( $recs as $rec ) {
//Get the full record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , 'grade_categories_history' , $rec -> old_id );
if ( $data ) {
//Now get completed xmlized object
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
2007-08-09 21:50:59 +00:00
//$GLOBALS['traverse_array']=""; //Debug
2007-08-09 08:58:15 +00:00
$oldobj = backup_getid ( $restore -> backup_unique_code , " grade_categories " , backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'OLDID' ][ '0' ][ '#' ]));
if ( empty ( $oldobj -> new_id )) {
// if the old object is not being restored, can't restoring its history
$counter ++ ;
2007-08-09 21:50:59 +00:00
continue ;
2007-08-09 08:58:15 +00:00
}
2007-08-09 21:50:59 +00:00
$dbrec -> oldid = $oldobj -> new_id ;
$dbrec -> action = backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'ACTION' ][ '0' ][ '#' ]);
2007-08-08 08:42:28 +00:00
$dbrec -> source = backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'SOURCE' ][ '0' ][ '#' ]);
2007-08-09 08:58:15 +00:00
$dbrec -> timemodified = backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'TIMEMODIFIED' ][ '0' ][ '#' ]);
2007-08-09 21:50:59 +00:00
2007-08-09 08:58:15 +00:00
// loggeduser might not be restored, e.g. admin
if ( $oldobj = backup_getid ( $restore -> backup_unique_code , " user " , backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'LOGGEDUSER' ][ '0' ][ '#' ]))) {
$dbrec -> loggeduser = $oldobj -> new_id ;
2007-08-09 21:50:59 +00:00
}
2007-08-09 08:58:15 +00:00
// this item might not have a parent at all, do not skip it if no parent is specified
if ( backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'PARENT' ][ '0' ][ '#' ])) {
2007-08-09 21:50:59 +00:00
$oldobj = backup_getid ( $restore -> backup_unique_code , " grade_categories " , backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'PARENT' ][ '0' ][ '#' ]));
2007-08-09 08:58:15 +00:00
if ( empty ( $oldobj -> new_id )) {
// if the parent category not restored
$counter ++ ;
2007-08-09 21:50:59 +00:00
continue ;
}
}
2007-08-09 08:58:15 +00:00
$dbrec -> parent = $oldobj -> new_id ;
2007-08-09 21:50:59 +00:00
$dbrec -> depth = backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'DEPTH' ][ '0' ][ '#' ]);
2007-08-09 08:58:15 +00:00
// path needs to be rebuilt
if ( $path = backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'PATH' ][ '0' ][ '#' ])) {
// to preserve the path and make it work, we need to replace the categories one by one
// we first get the list of categories in current path
if ( $paths = explode ( " / " , $path )) {
$newpath = '' ;
foreach ( $paths as $catid ) {
if ( $catid ) {
// find the new corresponding path
$oldpath = backup_getid ( $restore -> backup_unique_code , " grade_categories " , $catid );
$newpath .= " / $oldpath->new_id " ;
}
}
$dbrec -> path = $newpath ;
}
}
2007-08-08 08:42:28 +00:00
$dbrec -> fullname = backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'FULLNAME' ][ '0' ][ '#' ]);
$dbrec -> aggregation = backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'AGGRETGATION' ][ '0' ][ '#' ]);
$dbrec -> keephigh = backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'KEEPHIGH' ][ '0' ][ '#' ]);
2007-08-09 21:50:59 +00:00
$dbrec -> droplow = backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'DROPLOW' ][ '0' ][ '#' ]);
2007-10-10 08:28:43 +00:00
$dbrec -> aggregateonlygraded = backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'AGGREGATEONLYGRADED' ][ '0' ][ '#' ]);
$dbrec -> aggregateoutcomes = backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'AGGREGATEOUTCOMES' ][ '0' ][ '#' ]);
$dbrec -> aggregatesubcats = backup_todb ( $info [ 'GRADE_CATEGORIES_HISTORY' ][ '#' ][ 'AGGREGATESUBCATS' ][ '0' ][ '#' ]);
2007-08-08 08:42:28 +00:00
$dbrec -> courseid = $restore -> course_id ;
insert_record ( 'grade_categories_history' , $dbrec );
unset ( $dbrec );
}
//Increment counters
$counter ++ ;
//Do some output
if ( $counter % 1 == 0 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 20 == 0 ) {
echo " <br /> " ;
}
}
backup_flush ( 300 );
}
}
}
}
}
// process histories
2007-09-18 04:03:02 +00:00
if ( $gghcount && $continue && ! isset ( $SESSION -> restore -> importing ) && $restore -> restore_gradebook_history ) {
2007-08-08 08:42:28 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<li>' . get_string ( 'gradegradeshistory' , 'grades' ) . '</li>' ;
}
$counter = 0 ;
while ( $counter < $gghcount ) {
//Fetch recordset_size records in each iteration
$recs = get_records_select ( " backup_ids " , " table_name = 'grade_grades_history' AND backup_code = ' $restore->backup_unique_code ' " ,
" old_id " ,
2007-09-05 15:46:16 +00:00
" old_id " ,
2007-08-08 08:42:28 +00:00
$counter ,
$recordset_size );
if ( $recs ) {
foreach ( $recs as $rec ) {
//Get the full record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , 'grade_grades_history' , $rec -> old_id );
if ( $data ) {
//Now get completed xmlized object
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
2007-08-09 08:58:15 +00:00
$oldobj = backup_getid ( $restore -> backup_unique_code , " grade_grades " , backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'OLDID' ][ '0' ][ '#' ]));
if ( empty ( $oldobj -> new_id )) {
// if the old object is not being restored, can't restoring its history
$counter ++ ;
2007-08-09 21:50:59 +00:00
continue ;
2007-08-09 08:58:15 +00:00
}
$dbrec -> oldid = $oldobj -> new_id ;
$dbrec -> action = backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'ACTION' ][ '0' ][ '#' ]);
2007-08-08 08:42:28 +00:00
$dbrec -> source = backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'SOURCE' ][ '0' ][ '#' ]);
2007-08-09 08:58:15 +00:00
$dbrec -> timemodified = backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'TIMEMODIFIED' ][ '0' ][ '#' ]);
if ( $oldobj = backup_getid ( $restore -> backup_unique_code , " user " , backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'LOGGEDUSER' ][ '0' ][ '#' ]))) {
$dbrec -> loggeduser = $oldobj -> new_id ;
}
2007-10-10 08:28:43 +00:00
2007-08-09 08:58:15 +00:00
$oldobj = backup_getid ( $restore -> backup_unique_code , " grade_items " , backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'ITEMID' ][ '0' ][ '#' ]));
$dbrec -> itemid = $oldobj -> new_id ;
if ( empty ( $dbrec -> itemid )) {
$counter ++ ;
continue ; // grade item not being restored
}
$oldobj = backup_getid ( $restore -> backup_unique_code , " user " , backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'USERID' ][ '0' ][ '#' ]));
$dbrec -> userid = $oldobj -> new_id ;
$dbrec -> rawgrade = backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'RAWGRADE' ][ '0' ][ '#' ]);
2007-08-08 08:42:28 +00:00
$dbrec -> rawgrademax = backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'RAWGRADEMAX' ][ '0' ][ '#' ]);
$dbrec -> rawgrademin = backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'RAWGRADEMIN' ][ '0' ][ '#' ]);
2007-08-09 08:58:15 +00:00
if ( $oldobj = backup_getid ( $restore -> backup_unique_code , " user " , backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'USERMODIFIED' ][ '0' ][ '#' ]))) {
$dbrec -> usermodified = $oldobj -> new_id ;
}
2007-10-10 08:28:43 +00:00
if ( backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'RAWSCALEID' ][ '0' ][ '#' ])) {
$scale = backup_getid ( $restore -> backup_unique_code , " scale " , backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'RAWSCALEID' ][ '0' ][ '#' ]));
$dbrec -> rawscaleid = $scale -> new_id ;
}
2007-08-08 08:42:28 +00:00
$dbrec -> finalgrade = backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'FINALGRADE' ][ '0' ][ '#' ]);
$dbrec -> hidden = backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'HIDDEN' ][ '0' ][ '#' ]);
$dbrec -> locked = backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'LOCKED' ][ '0' ][ '#' ]);
$dbrec -> locktime = backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'LOCKTIME' ][ '0' ][ '#' ]);
$dbrec -> exported = backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'EXPORTED' ][ '0' ][ '#' ]);
$dbrec -> overridden = backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'OVERRIDDEN' ][ '0' ][ '#' ]);
$dbrec -> excluded = backup_todb ( $info [ 'GRADE_GRADES_HISTORY' ][ '#' ][ 'EXCLUDED' ][ '0' ][ '#' ]);
$dbrec -> feedback = backup_todb ( $info [ 'GRADE_TEXT_HISTORY' ][ '#' ][ 'FEEDBACK' ][ '0' ][ '#' ]);
2007-08-09 21:50:59 +00:00
$dbrec -> feedbackformat = backup_todb ( $info [ 'GRADE_TEXT_HISTORY' ][ '#' ][ 'FEEDBACKFORMAT' ][ '0' ][ '#' ]);
2007-09-22 11:39:59 +00:00
$dbrec -> information = backup_todb ( $info [ 'GRADE_TEXT_HISTORY' ][ '#' ][ 'INFORMATION' ][ '0' ][ '#' ]);
$dbrec -> informationformat = backup_todb ( $info [ 'GRADE_TEXT_HISTORY' ][ '#' ][ 'INFORMATIONFORMAT' ][ '0' ][ '#' ]);
2007-08-09 08:58:15 +00:00
2007-09-22 11:39:59 +00:00
insert_record ( 'grade_grades_history' , $dbrec );
2007-08-08 08:42:28 +00:00
unset ( $dbrec );
}
//Increment counters
$counter ++ ;
//Do some output
if ( $counter % 1 == 0 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 20 == 0 ) {
echo " <br /> " ;
}
}
backup_flush ( 300 );
}
}
}
}
}
// process histories
2007-09-22 11:39:59 +00:00
2007-09-18 04:03:02 +00:00
if ( $gihcount && $continue && ! isset ( $SESSION -> restore -> importing ) && $restore -> restore_gradebook_history ) {
2007-08-08 08:42:28 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<li>' . get_string ( 'gradeitemshistory' , 'grades' ) . '</li>' ;
}
$counter = 0 ;
while ( $counter < $gihcount ) {
//Fetch recordset_size records in each iteration
$recs = get_records_select ( " backup_ids " , " table_name = 'grade_items_history' AND backup_code = ' $restore->backup_unique_code ' " ,
" old_id " ,
2007-09-05 15:46:16 +00:00
" old_id " ,
2007-08-08 08:42:28 +00:00
$counter ,
$recordset_size );
if ( $recs ) {
foreach ( $recs as $rec ) {
//Get the full record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , 'grade_items_history' , $rec -> old_id );
if ( $data ) {
//Now get completed xmlized object
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
2007-08-09 08:58:15 +00:00
2007-08-09 21:50:59 +00:00
$oldobj = backup_getid ( $restore -> backup_unique_code , " grade_items " , backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'OLDID' ][ '0' ][ '#' ]));
2007-08-09 08:58:15 +00:00
if ( empty ( $oldobj -> new_id )) {
// if the old object is not being restored, can't restoring its history
$counter ++ ;
2007-08-09 21:50:59 +00:00
continue ;
2007-08-09 08:58:15 +00:00
}
$dbrec -> oldid = $oldobj -> new_id ;
2007-08-08 08:42:28 +00:00
$dbrec -> action = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'ACTION' ][ '0' ][ '#' ]);
$dbrec -> source = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'SOURCE' ][ '0' ][ '#' ]);
2007-08-09 08:58:15 +00:00
$dbrec -> timemodified = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'TIMEMODIFIED' ][ '0' ][ '#' ]);
if ( $oldobj = backup_getid ( $restore -> backup_unique_code , " user " , backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'LOGGEDUSER' ][ '0' ][ '#' ]))) {
$dbrec -> loggeduser = $oldobj -> new_id ;
2007-08-09 21:50:59 +00:00
}
2007-10-10 08:28:43 +00:00
$dbrec -> courseid = $restore -> course_id ;
2007-08-09 08:58:15 +00:00
$oldobj = backup_getid ( $restore -> backup_unique_code , 'grade_categories' , backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'CATEGORYID' ][ '0' ][ '#' ]));
2007-08-09 21:50:59 +00:00
$oldobj -> categoryid = $category -> new_id ;
2007-08-09 08:58:15 +00:00
if ( empty ( $oldobj -> categoryid )) {
$counter ++ ;
2007-08-09 21:50:59 +00:00
continue ; // category not restored
2007-08-09 08:58:15 +00:00
}
2007-08-09 21:50:59 +00:00
2007-08-08 08:42:28 +00:00
$dbrec -> itemname = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'ITEMNAME' ][ '0' ][ '#' ]);
$dbrec -> itemtype = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'ITEMTYPE' ][ '0' ][ '#' ]);
$dbrec -> itemmodule = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'ITEMMODULE' ][ '0' ][ '#' ]);
2007-08-09 21:50:59 +00:00
2007-08-09 08:58:15 +00:00
// code from grade_items restore
$iteminstance = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'ITEMINSTANCE' ][ '0' ][ '#' ]);
// do not restore if this grade_item is a mod, and
if ( $dbrec -> itemtype == 'mod' ) {
if ( ! restore_userdata_selected ( $restore , $dbrec -> itemmodule , $iteminstance )) {
// module instance not selected when restored using granular
// skip this item
$counter ++ ;
continue ;
}
// iteminstance should point to new mod
$mod = backup_getid ( $restore -> backup_unique_code , $dbrec -> itemmodule , $iteminstance );
$dbrec -> iteminstance = $mod -> new_id ;
} else if ( $dbrec -> itemtype == 'category' ) {
// the item instance should point to the new grade category
// only proceed if we are restoring all grade items
if ( $restoreall ) {
$category = backup_getid ( $restore -> backup_unique_code , 'grade_categories' , $iteminstance );
$dbrec -> iteminstance = $category -> new_id ;
} else {
// otherwise we can safely ignore this grade item and subsequent
// grade_raws, grade_finals etc
continue ;
}
} elseif ( $dbrec -> itemtype == 'course' ) { // We don't restore course type to avoid duplicate course items
if ( $restoreall ) {
// TODO any special code needed here to restore course item without duplicating it?
// find the course category with depth 1, and course id = current course id
2007-08-09 21:50:59 +00:00
// this would have been already restored
2007-08-09 08:58:15 +00:00
$cat = get_record ( 'grade_categories' , 'depth' , 1 , 'courseid' , $restore -> course_id );
$dbrec -> iteminstance = $cat -> id ;
2007-08-09 21:50:59 +00:00
2007-08-09 08:58:15 +00:00
} else {
$counter ++ ;
continue ;
}
}
2007-08-08 08:42:28 +00:00
$dbrec -> itemnumber = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'ITEMNUMBER' ][ '0' ][ '#' ]);
2007-08-09 21:50:59 +00:00
$dbrec -> iteminfo = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'ITEMINFO' ][ '0' ][ '#' ]);
2007-08-08 08:42:28 +00:00
$dbrec -> idnumber = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'IDNUMBER' ][ '0' ][ '#' ]);
$dbrec -> calculation = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'CALCULATION' ][ '0' ][ '#' ]);
$dbrec -> gradetype = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'GRADETYPE' ][ '0' ][ '#' ]);
$dbrec -> grademax = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'GRADEMAX' ][ '0' ][ '#' ]);
$dbrec -> grademin = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'GRADEMIN' ][ '0' ][ '#' ]);
2007-08-09 08:58:15 +00:00
if ( $oldobj = backup_getid ( $restore -> backup_unique_code , " scale " , backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'SCALEID' ][ '0' ][ '#' ]))) {
// scaleid is optional
$dbrec -> scaleid = $oldobj -> new_id ;
}
if ( $oldobj = backup_getid ( $restore -> backup_unique_code , " grade_outcomes " , backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'OUTCOMEID' ][ '0' ][ '#' ]))) {
// outcome is optional
$dbrec -> outcomeid = $oldobj -> new_id ;
}
2007-08-08 08:42:28 +00:00
$dbrec -> gradepass = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'GRADEPASS' ][ '0' ][ '#' ]);
$dbrec -> multfactor = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'MULTFACTOR' ][ '0' ][ '#' ]);
2007-08-09 21:50:59 +00:00
$dbrec -> plusfactor = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'PLUSFACTOR' ][ '0' ][ '#' ]);
2007-08-08 08:42:28 +00:00
$dbrec -> aggregationcoef = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'AGGREGATIONCOEF' ][ '0' ][ '#' ]);
$dbrec -> sortorder = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'SORTORDER' ][ '0' ][ '#' ]);
2007-10-10 08:28:43 +00:00
$dbrec -> display = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'DISPLAY' ][ '0' ][ '#' ]);
$dbrec -> decimals = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'DECIMALS' ][ '0' ][ '#' ]);
2007-08-08 08:42:28 +00:00
$dbrec -> hidden = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'HIDDEN' ][ '0' ][ '#' ]);
$dbrec -> locked = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'LOCKED' ][ '0' ][ '#' ]);
$dbrec -> locktime = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'LOCKTIME' ][ '0' ][ '#' ]);
2007-08-09 21:50:59 +00:00
$dbrec -> needsupdate = backup_todb ( $info [ 'GRADE_ITEM_HISTORY' ][ '#' ][ 'NEEDSUPDATE' ][ '0' ][ '#' ]);
2007-08-08 08:42:28 +00:00
insert_record ( 'grade_items_history' , $dbrec );
unset ( $dbrec );
}
//Increment counters
$counter ++ ;
//Do some output
if ( $counter % 1 == 0 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 20 == 0 ) {
echo " <br /> " ;
}
}
backup_flush ( 300 );
}
}
}
}
}
// process histories
2007-09-18 04:03:02 +00:00
if ( $gohcount && $continue && ! isset ( $SESSION -> restore -> importing ) && $restore -> restore_gradebook_history ) {
2007-08-08 08:42:28 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<li>' . get_string ( 'gradeoutcomeshistory' , 'grades' ) . '</li>' ;
}
$counter = 0 ;
while ( $counter < $gohcount ) {
//Fetch recordset_size records in each iteration
$recs = get_records_select ( " backup_ids " , " table_name = 'grade_outcomes_history' AND backup_code = ' $restore->backup_unique_code ' " ,
" old_id " ,
2007-09-05 15:46:16 +00:00
" old_id " ,
2007-08-08 08:42:28 +00:00
$counter ,
$recordset_size );
if ( $recs ) {
foreach ( $recs as $rec ) {
//Get the full record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , 'grade_outcomes_history' , $rec -> old_id );
if ( $data ) {
//Now get completed xmlized object
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
2007-08-09 08:58:15 +00:00
$oldobj = backup_getid ( $restore -> backup_unique_code , " grade_outcomes " , backup_todb ( $info [ 'GRADE_OUTCOME_HISTORY' ][ '#' ][ 'OLDID' ][ '0' ][ '#' ]));
if ( empty ( $oldobj -> new_id )) {
// if the old object is not being restored, can't restoring its history
$counter ++ ;
2007-08-09 21:50:59 +00:00
continue ;
2007-08-09 08:58:15 +00:00
}
2007-08-09 21:50:59 +00:00
$dbrec -> oldid = $oldobj -> new_id ;
2007-08-08 08:42:28 +00:00
$dbrec -> action = backup_todb ( $info [ 'GRADE_OUTCOME_HISTORY' ][ '#' ][ 'ACTION' ][ '0' ][ '#' ]);
$dbrec -> source = backup_todb ( $info [ 'GRADE_OUTCOME_HISTORY' ][ '#' ][ 'SOURCE' ][ '0' ][ '#' ]);
2007-08-09 08:58:15 +00:00
$dbrec -> timemodified = backup_todb ( $info [ 'GRADE_OUTCOME_HISTORY' ][ '#' ][ 'TIMEMODIFIED' ][ '0' ][ '#' ]);
if ( $oldobj = backup_getid ( $restore -> backup_unique_code , " user " , backup_todb ( $info [ 'GRADE_OUTCOME_HISTORY' ][ '#' ][ 'LOGGEDUSER' ][ '0' ][ '#' ]))) {
$dbrec -> loggeduser = $oldobj -> new_id ;
}
2007-10-10 08:28:43 +00:00
$dbrec -> courseid = $restore -> course_id ;
2007-08-08 08:42:28 +00:00
$dbrec -> shortname = backup_todb ( $info [ 'GRADE_OUTCOME_HISTORY' ][ '#' ][ 'SHORTNAME' ][ '0' ][ '#' ]);
2007-08-09 21:50:59 +00:00
$dbrec -> fullname = backup_todb ( $info [ 'GRADE_OUTCOME_HISTORY' ][ '#' ][ 'FULLNAME' ][ '0' ][ '#' ]);
2007-08-09 08:58:15 +00:00
$oldobj = backup_getid ( $restore -> backup_unique_code , " scale " , backup_todb ( $info [ 'GRADE_OUTCOME_HISTORY' ][ '#' ][ 'SCALEID' ][ '0' ][ '#' ]));
$dbrec -> scaleid = $oldobj -> new_id ;
2007-08-08 08:42:28 +00:00
$dbrec -> description = backup_todb ( $info [ 'GRADE_OUTCOME_HISTORY' ][ '#' ][ 'DESCRIPTION' ][ '0' ][ '#' ]);
2007-08-09 21:50:59 +00:00
2007-08-08 08:42:28 +00:00
insert_record ( 'grade_outcomes_history' , $dbrec );
unset ( $dbrec );
}
//Increment counters
$counter ++ ;
//Do some output
if ( $counter % 1 == 0 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 20 == 0 ) {
echo " <br /> " ;
}
}
backup_flush ( 300 );
}
}
}
}
}
2007-05-29 09:00:48 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
//End ul
echo '</ul>' ;
}
2007-07-28 09:23:32 +00:00
return $status ;
2005-04-22 00:26:22 +00:00
}
2003-05-25 22:58:13 +00:00
//This function creates all the user, user_students, user_teachers
//user_course_creators and user_admins from xml
function restore_create_users ( $restore , $xml_file ) {
2003-06-12 17:38:36 +00:00
global $CFG , $db ;
2003-05-25 22:58:13 +00:00
$status = true ;
//Check it exists
if ( ! file_exists ( $xml_file )) {
$status = false ;
}
//Get info from xml
if ( $status ) {
//info will contain the old_id of every user
//in backup_ids->info will be the real info (serialized)
$info = restore_read_xml_users ( $restore , $xml_file );
}
//Now, get evey user_id from $info and user data from $backup_ids
//and create the necessary records (users, user_students, user_teachers
//user_course_creators and user_admins
2003-10-07 14:01:23 +00:00
if ( ! empty ( $info -> users )) {
2007-01-16 00:56:15 +00:00
// Grab mnethosts keyed by wwwroot, to map to id
2007-07-28 09:23:32 +00:00
$mnethosts = get_records ( 'mnet_host' , '' , '' ,
2007-01-16 00:56:15 +00:00
'wwwroot' , 'wwwroot, id' );
2007-02-14 09:54:08 +00:00
$languages = get_list_of_languages ();
2003-05-25 22:58:13 +00:00
foreach ( $info -> users as $userid ) {
2007-07-28 09:23:32 +00:00
$rec = backup_getid ( $restore -> backup_unique_code , " user " , $userid );
2003-06-20 19:42:20 +00:00
$user = $rec -> info ;
2003-08-25 01:44:01 +00:00
2005-01-23 23:24:58 +00:00
//Now, recode some languages (Moodle 1.5)
if ( $user -> lang == 'ma_nt' ) {
$user -> lang = 'mi_nt' ;
}
2007-02-14 09:54:08 +00:00
//If language does not exist here - use site default
if ( ! array_key_exists ( $user -> lang , $languages )) {
$user -> lang = $CFG -> lang ;
2007-07-28 09:23:32 +00:00
}
2007-02-14 09:54:08 +00:00
2003-05-25 22:58:13 +00:00
//Check if it's admin and coursecreator
2003-08-25 01:44:01 +00:00
$is_admin = ! empty ( $user -> roles [ 'admin' ]);
$is_coursecreator = ! empty ( $user -> roles [ 'coursecreator' ]);
2003-05-25 22:58:13 +00:00
//Check if it's teacher and student
2003-08-25 01:44:01 +00:00
$is_teacher = ! empty ( $user -> roles [ 'teacher' ]);
$is_student = ! empty ( $user -> roles [ 'student' ]);
2003-09-14 21:43:34 +00:00
//Check if it's needed
$is_needed = ! empty ( $user -> roles [ 'needed' ]);
2003-08-25 01:44:01 +00:00
//Calculate if it is a course user
2003-09-14 21:43:34 +00:00
//Has role teacher or student or needed
$is_course_user = ( $is_teacher or $is_student or $is_needed );
2003-08-25 01:44:01 +00:00
2007-01-16 00:56:15 +00:00
//Calculate mnethostid
if ( empty ( $user -> mnethosturl ) || $user -> mnethosturl === $CFG -> wwwroot ) {
$user -> mnethostid = $CFG -> mnet_localhost_id ;
} else {
// fast url-to-id lookups
2007-01-17 01:00:08 +00:00
if ( isset ( $mnethosts [ $user -> mnethosturl ])) {
$user -> mnethostid = $mnethosts [ $user -> mnethosturl ] -> id ;
2007-07-28 09:23:32 +00:00
} else {
// should not happen, as we check in restore_chech.php
2007-01-16 00:56:15 +00:00
// but handle the error if it does
error ( " This backup file contains external Moodle Network Hosts that are not configured locally. " );
}
}
unset ( $user -> mnethosturl );
2003-05-25 23:37:07 +00:00
//To store new ids created
$newid = null ;
//check if it exists (by username) and get its id
2003-05-25 22:58:13 +00:00
$user_exists = true ;
2007-07-28 09:23:32 +00:00
$user_data = get_record ( " user " , " username " , addslashes ( $user -> username ),
2007-01-16 00:56:15 +00:00
'mnethostid' , $user -> mnethostid );
2003-05-25 23:37:07 +00:00
if ( ! $user_data ) {
2003-05-25 22:58:13 +00:00
$user_exists = false ;
2003-05-25 23:37:07 +00:00
} else {
$newid = $user_data -> id ;
2003-05-25 22:58:13 +00:00
}
2004-02-08 19:27:23 +00:00
//Flags to see if we have to create the user, roles and preferences
2003-05-25 22:58:13 +00:00
$create_user = true ;
$create_roles = true ;
2004-02-08 19:27:23 +00:00
$create_preferences = true ;
2003-05-25 22:58:13 +00:00
//If we are restoring course users and it isn't a course user
if ( $restore -> users == 1 and ! $is_course_user ) {
//If only restoring course_users and user isn't a course_user, inform to $backup_ids
$status = backup_putid ( $restore -> backup_unique_code , " user " , $userid , null , 'notincourse' );
$create_user = false ;
$create_roles = false ;
2004-02-08 19:27:23 +00:00
$create_preferences = false ;
2003-05-25 22:58:13 +00:00
}
if ( $user_exists and $create_user ) {
//If user exists mark its newid in backup_ids (the same than old)
2003-05-25 23:37:07 +00:00
$status = backup_putid ( $restore -> backup_unique_code , " user " , $userid , $newid , 'exists' );
2003-05-25 22:58:13 +00:00
$create_user = false ;
}
//Here, if create_user, do it
if ( $create_user ) {
2004-03-10 17:10:26 +00:00
//Unset the id because it's going to be inserted with a new one
unset ( $user -> id );
2007-10-20 19:25:10 +00:00
// relink the descriptions
2007-10-20 19:31:51 +00:00
$user -> description = stripslashes ( backup_todb ( $user -> description ));
2004-08-28 10:26:06 +00:00
2007-10-20 20:57:06 +00:00
if ( ! empty ( $CFG -> disableuserimages )) {
$user -> picture = 0 ;
}
2004-08-28 10:26:06 +00:00
//We need to analyse the AUTH field to recode it:
2007-07-28 09:23:32 +00:00
// - if the field isn't set, we are in a pre 1.4 backup and we'll
2007-02-20 17:09:20 +00:00
// use manual
if ( empty ( $user -> auth )) {
if ( $CFG -> registerauth == 'email' ) {
$user -> auth = 'email' ;
} else {
$user -> auth = 'manual' ;
}
2004-08-28 10:26:06 +00:00
}
2005-01-30 11:39:12 +00:00
//We need to process the POLICYAGREED field to recalculate it:
// - if the destination site is different (by wwwroot) reset it.
// - if the destination site is the same (by wwwroot), leave it unmodified
if ( $restore -> original_wwwroot != $CFG -> wwwroot ) {
$user -> policyagreed = 0 ;
} else {
//Nothing to do, we are in the same server
}
2005-02-15 18:37:08 +00:00
//Check if the theme exists in destination server
$themes = get_list_of_themes ();
if ( ! in_array ( $user -> theme , $themes )) {
$user -> theme = '' ;
}
2003-05-25 22:58:13 +00:00
//We are going to create the user
//The structure is exactly as we need
2007-10-20 19:25:10 +00:00
$newid = insert_record ( " user " , addslashes_recursive ( $user ));
2003-05-25 22:58:13 +00:00
//Put the new id
2003-05-26 00:07:56 +00:00
$status = backup_putid ( $restore -> backup_unique_code , " user " , $userid , $newid , " new " );
2003-05-25 22:58:13 +00:00
}
//Here, if create_roles, do it as necessary
if ( $create_roles ) {
2003-09-14 21:43:34 +00:00
//Get the newid and current info from backup_ids
2003-05-25 22:58:13 +00:00
$data = backup_getid ( $restore -> backup_unique_code , " user " , $userid );
$newid = $data -> new_id ;
2003-05-26 00:07:56 +00:00
$currinfo = $data -> info . " , " ;
2003-08-25 15:47:37 +00:00
2007-07-28 09:23:32 +00:00
//Now, depending of the role, create records in user_studentes and user_teacher
2003-05-25 22:58:13 +00:00
//and/or mark it in backup_ids
2007-07-28 09:23:32 +00:00
2003-08-25 15:47:37 +00:00
if ( $is_admin ) {
//If the record (user_admins) doesn't exists
2006-10-03 08:54:46 +00:00
//Only put status in backup_ids
$currinfo = $currinfo . " admin, " ;
$status = backup_putid ( $restore -> backup_unique_code , " user " , $userid , $newid , $currinfo );
2007-07-28 09:23:32 +00:00
}
2003-08-25 15:47:37 +00:00
if ( $is_coursecreator ) {
//If the record (user_coursecreators) doesn't exists
2006-10-03 08:54:46 +00:00
//Only put status in backup_ids
$currinfo = $currinfo . " coursecreator, " ;
$status = backup_putid ( $restore -> backup_unique_code , " user " , $userid , $newid , $currinfo );
2007-07-28 09:23:32 +00:00
}
2003-09-14 21:43:34 +00:00
if ( $is_needed ) {
//Only put status in backup_ids
$currinfo = $currinfo . " needed, " ;
$status = backup_putid ( $restore -> backup_unique_code , " user " , $userid , $newid , $currinfo );
}
2003-05-25 22:58:13 +00:00
if ( $is_teacher ) {
//If the record (teacher) doesn't exists
2007-07-28 09:23:32 +00:00
//Put status in backup_ids
2006-10-03 08:54:46 +00:00
$currinfo = $currinfo . " teacher, " ;
$status = backup_putid ( $restore -> backup_unique_code , " user " , $userid , $newid , $currinfo );
//Set course and user
$user -> roles [ 'teacher' ] -> course = $restore -> course_id ;
$user -> roles [ 'teacher' ] -> userid = $newid ;
//Need to analyse the enrol field
// - if it isn't set, set it to $CFG->enrol
// - if we are in a different server (by wwwroot), set it to $CFG->enrol
// - if we are in the same server (by wwwroot), maintain it unmodified.
if ( empty ( $user -> roles [ 'teacher' ] -> enrol )) {
$user -> roles [ 'teacher' ] -> enrol = $CFG -> enrol ;
} else if ( $restore -> original_wwwroot != $CFG -> wwwroot ) {
$user -> roles [ 'teacher' ] -> enrol = $CFG -> enrol ;
} else {
//Nothing to do. Leave it unmodified
2007-07-28 09:23:32 +00:00
}
2006-10-03 08:54:46 +00:00
$rolesmapping = $restore -> rolesmapping ;
$context = get_context_instance ( CONTEXT_COURSE , $restore -> course_id );
if ( $user -> roles [ 'teacher' ] -> editall ) {
role_assign ( $rolesmapping [ 'defaultteacheredit' ],
2007-07-28 09:23:32 +00:00
$newid ,
0 ,
$context -> id ,
$user -> roles [ 'teacher' ] -> timestart ,
$user -> roles [ 'teacher' ] -> timeend ,
0 ,
2006-10-03 08:54:46 +00:00
$user -> roles [ 'teacher' ] -> enrol );
2007-07-28 09:23:32 +00:00
// editting teacher
2006-10-03 08:54:46 +00:00
} else {
// non editting teacher
role_assign ( $rolesmapping [ 'defaultteacher' ],
2007-07-28 09:23:32 +00:00
$newid ,
0 ,
$context -> id ,
$user -> roles [ 'teacher' ] -> timestart ,
$user -> roles [ 'teacher' ] -> timeend ,
0 ,
2006-10-03 08:54:46 +00:00
$user -> roles [ 'teacher' ] -> enrol );
2007-07-28 09:23:32 +00:00
}
}
2003-05-25 22:58:13 +00:00
if ( $is_student ) {
2005-01-30 11:39:12 +00:00
2006-10-03 08:54:46 +00:00
//Put status in backup_ids
$currinfo = $currinfo . " student, " ;
$status = backup_putid ( $restore -> backup_unique_code , " user " , $userid , $newid , $currinfo );
//Set course and user
$user -> roles [ 'student' ] -> course = $restore -> course_id ;
$user -> roles [ 'student' ] -> userid = $newid ;
//Need to analyse the enrol field
// - if it isn't set, set it to $CFG->enrol
// - if we are in a different server (by wwwroot), set it to $CFG->enrol
// - if we are in the same server (by wwwroot), maintain it unmodified.
if ( empty ( $user -> roles [ 'student' ] -> enrol )) {
$user -> roles [ 'student' ] -> enrol = $CFG -> enrol ;
} else if ( $restore -> original_wwwroot != $CFG -> wwwroot ) {
$user -> roles [ 'student' ] -> enrol = $CFG -> enrol ;
} else {
//Nothing to do. Leave it unmodified
2007-07-28 09:23:32 +00:00
}
2006-10-03 08:54:46 +00:00
$rolesmapping = $restore -> rolesmapping ;
$context = get_context_instance ( CONTEXT_COURSE , $restore -> course_id );
2007-07-28 09:23:32 +00:00
2006-10-03 08:54:46 +00:00
role_assign ( $rolesmapping [ 'defaultstudent' ],
2007-07-28 09:23:32 +00:00
$newid ,
0 ,
$context -> id ,
$user -> roles [ 'student' ] -> timestart ,
$user -> roles [ 'student' ] -> timeend ,
0 ,
2006-10-03 08:54:46 +00:00
$user -> roles [ 'student' ] -> enrol );
2003-05-25 22:58:13 +00:00
}
if ( ! $is_course_user ) {
2003-05-26 00:07:56 +00:00
//If the record (user) doesn't exists
if ( ! record_exists ( " user " , " id " , $newid )) {
//Put status in backup_ids
$currinfo = $currinfo . " user, " ;
$status = backup_putid ( $restore -> backup_unique_code , " user " , $userid , $newid , $currinfo );
}
2003-05-25 22:58:13 +00:00
}
}
2004-02-08 19:27:23 +00:00
//Here, if create_preferences, do it as necessary
if ( $create_preferences ) {
2004-09-12 01:34:24 +00:00
//echo "Checking for preferences of user ".$user->username."<br />"; //Debug
2004-02-08 19:27:23 +00:00
//Get user new id from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , " user " , $userid );
$newid = $data -> new_id ;
if ( isset ( $user -> user_preferences )) {
2004-09-12 01:34:24 +00:00
//echo "Preferences exist in backup file<br />"; //Debug
2004-02-08 19:27:23 +00:00
foreach ( $user -> user_preferences as $user_preference ) {
2004-09-12 01:34:24 +00:00
//echo $user_preference->name." = ".$user_preference->value."<br />"; //Debug
2004-02-08 19:27:23 +00:00
//We check if that user_preference exists in DB
if ( ! record_exists ( " user_preferences " , " userid " , $newid , " name " , $user_preference -> name )) {
2004-09-12 01:34:24 +00:00
//echo "Creating it<br />"; //Debug
2004-02-08 19:27:23 +00:00
//Prepare the record and insert it
$user_preference -> userid = $newid ;
$status = insert_record ( " user_preferences " , $user_preference );
}
}
}
}
2003-05-25 22:58:13 +00:00
}
}
2007-07-28 09:23:32 +00:00
2003-05-25 22:58:13 +00:00
return $status ;
}
2003-05-28 19:43:11 +00:00
2005-02-13 19:09:41 +00:00
//This function creates all the structures messages and contacts
function restore_create_messages ( $restore , $xml_file ) {
global $CFG ;
$status = true ;
//Check it exists
if ( ! file_exists ( $xml_file )) {
$status = false ;
}
//Get info from xml
if ( $status ) {
//info will contain the id and name of every table
//(message, message_read and message_contacts)
//in backup_ids->info will be the real info (serialized)
$info = restore_read_xml_messages ( $restore , $xml_file );
//If we have info, then process messages & contacts
if ( $info > 0 ) {
//Count how many we have
$unreadcount = count_records ( 'backup_ids' , 'backup_code' , $restore -> backup_unique_code , 'table_name' , 'message' );
$readcount = count_records ( 'backup_ids' , 'backup_code' , $restore -> backup_unique_code , 'table_name' , 'message_read' );
$contactcount = count_records ( 'backup_ids' , 'backup_code' , $restore -> backup_unique_code , 'table_name' , 'message_contacts' );
if ( $unreadcount || $readcount || $contactcount ) {
//Start ul
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<ul>' ;
}
2005-02-13 19:09:41 +00:00
//Number of records to get in every chunk
$recordset_size = 4 ;
//Process unread
if ( $unreadcount ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<li>' . get_string ( 'unreadmessages' , 'message' ) . '</li>' ;
}
2005-02-13 19:09:41 +00:00
$counter = 0 ;
while ( $counter < $unreadcount ) {
//Fetch recordset_size records in each iteration
2007-09-05 15:46:16 +00:00
$recs = get_records_select ( " backup_ids " , " table_name = 'message' AND backup_code = ' $restore->backup_unique_code ' " , " old_id " , " old_id " , $counter , $recordset_size );
2005-02-13 19:09:41 +00:00
if ( $recs ) {
foreach ( $recs as $rec ) {
//Get the full record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , " message " , $rec -> old_id );
if ( $data ) {
//Now get completed xmlized object
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now build the MESSAGE record structure
2007-08-15 10:43:25 +00:00
$dbrec = new object ();
2005-02-13 19:09:41 +00:00
$dbrec -> useridfrom = backup_todb ( $info [ 'MESSAGE' ][ '#' ][ 'USERIDFROM' ][ '0' ][ '#' ]);
$dbrec -> useridto = backup_todb ( $info [ 'MESSAGE' ][ '#' ][ 'USERIDTO' ][ '0' ][ '#' ]);
$dbrec -> message = backup_todb ( $info [ 'MESSAGE' ][ '#' ][ 'MESSAGE' ][ '0' ][ '#' ]);
$dbrec -> format = backup_todb ( $info [ 'MESSAGE' ][ '#' ][ 'FORMAT' ][ '0' ][ '#' ]);
$dbrec -> timecreated = backup_todb ( $info [ 'MESSAGE' ][ '#' ][ 'TIMECREATED' ][ '0' ][ '#' ]);
$dbrec -> messagetype = backup_todb ( $info [ 'MESSAGE' ][ '#' ][ 'MESSAGETYPE' ][ '0' ][ '#' ]);
//We have to recode the useridfrom field
$user = backup_getid ( $restore -> backup_unique_code , " user " , $dbrec -> useridfrom );
if ( $user ) {
//echo "User ".$dbrec->useridfrom." to user ".$user->new_id."<br />"; //Debug
$dbrec -> useridfrom = $user -> new_id ;
}
//We have to recode the useridto field
$user = backup_getid ( $restore -> backup_unique_code , " user " , $dbrec -> useridto );
if ( $user ) {
//echo "User ".$dbrec->useridto." to user ".$user->new_id."<br />"; //Debug
$dbrec -> useridto = $user -> new_id ;
}
//Check if the record doesn't exist in DB!
$exist = get_record ( 'message' , 'useridfrom' , $dbrec -> useridfrom ,
'useridto' , $dbrec -> useridto ,
'timecreated' , $dbrec -> timecreated );
if ( ! $exist ) {
//Not exist. Insert
$status = insert_record ( 'message' , $dbrec );
} else {
//Duplicate. Do nothing
}
}
//Do some output
$counter ++ ;
if ( $counter % 10 == 0 ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 200 == 0 ) {
echo " <br /> " ;
}
2005-02-13 19:09:41 +00:00
}
backup_flush ( 300 );
}
}
}
}
}
//Process read
if ( $readcount ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<li>' . get_string ( 'readmessages' , 'message' ) . '</li>' ;
}
2005-02-13 19:09:41 +00:00
$counter = 0 ;
while ( $counter < $readcount ) {
//Fetch recordset_size records in each iteration
2007-09-05 15:46:16 +00:00
$recs = get_records_select ( " backup_ids " , " table_name = 'message_read' AND backup_code = ' $restore->backup_unique_code ' " , " old_id " , " old_id " , $counter , $recordset_size );
2005-02-13 19:09:41 +00:00
if ( $recs ) {
foreach ( $recs as $rec ) {
//Get the full record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , " message_read " , $rec -> old_id );
if ( $data ) {
//Now get completed xmlized object
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now build the MESSAGE_READ record structure
$dbrec -> useridfrom = backup_todb ( $info [ 'MESSAGE' ][ '#' ][ 'USERIDFROM' ][ '0' ][ '#' ]);
$dbrec -> useridto = backup_todb ( $info [ 'MESSAGE' ][ '#' ][ 'USERIDTO' ][ '0' ][ '#' ]);
$dbrec -> message = backup_todb ( $info [ 'MESSAGE' ][ '#' ][ 'MESSAGE' ][ '0' ][ '#' ]);
$dbrec -> format = backup_todb ( $info [ 'MESSAGE' ][ '#' ][ 'FORMAT' ][ '0' ][ '#' ]);
$dbrec -> timecreated = backup_todb ( $info [ 'MESSAGE' ][ '#' ][ 'TIMECREATED' ][ '0' ][ '#' ]);
$dbrec -> messagetype = backup_todb ( $info [ 'MESSAGE' ][ '#' ][ 'MESSAGETYPE' ][ '0' ][ '#' ]);
$dbrec -> timeread = backup_todb ( $info [ 'MESSAGE' ][ '#' ][ 'TIMEREAD' ][ '0' ][ '#' ]);
$dbrec -> mailed = backup_todb ( $info [ 'MESSAGE' ][ '#' ][ 'MAILED' ][ '0' ][ '#' ]);
//We have to recode the useridfrom field
$user = backup_getid ( $restore -> backup_unique_code , " user " , $dbrec -> useridfrom );
if ( $user ) {
//echo "User ".$dbrec->useridfrom." to user ".$user->new_id."<br />"; //Debug
$dbrec -> useridfrom = $user -> new_id ;
}
//We have to recode the useridto field
$user = backup_getid ( $restore -> backup_unique_code , " user " , $dbrec -> useridto );
if ( $user ) {
//echo "User ".$dbrec->useridto." to user ".$user->new_id."<br />"; //Debug
$dbrec -> useridto = $user -> new_id ;
}
//Check if the record doesn't exist in DB!
$exist = get_record ( 'message_read' , 'useridfrom' , $dbrec -> useridfrom ,
'useridto' , $dbrec -> useridto ,
'timecreated' , $dbrec -> timecreated );
if ( ! $exist ) {
//Not exist. Insert
$status = insert_record ( 'message_read' , $dbrec );
} else {
//Duplicate. Do nothing
}
}
//Do some output
$counter ++ ;
if ( $counter % 10 == 0 ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 200 == 0 ) {
echo " <br /> " ;
}
2005-02-13 19:09:41 +00:00
}
backup_flush ( 300 );
}
}
}
}
}
//Process contacts
if ( $contactcount ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-10-07 20:47:54 +00:00
echo '<li>' . moodle_strtolower ( get_string ( 'contacts' , 'message' )) . '</li>' ;
2006-01-15 21:09:13 +00:00
}
2005-02-13 19:09:41 +00:00
$counter = 0 ;
while ( $counter < $contactcount ) {
//Fetch recordset_size records in each iteration
2007-09-05 15:46:16 +00:00
$recs = get_records_select ( " backup_ids " , " table_name = 'message_contacts' AND backup_code = ' $restore->backup_unique_code ' " , " old_id " , " old_id " , $counter , $recordset_size );
2005-02-13 19:09:41 +00:00
if ( $recs ) {
foreach ( $recs as $rec ) {
//Get the full record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , " message_contacts " , $rec -> old_id );
if ( $data ) {
//Now get completed xmlized object
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now build the MESSAGE_CONTACTS record structure
$dbrec -> userid = backup_todb ( $info [ 'CONTACT' ][ '#' ][ 'USERID' ][ '0' ][ '#' ]);
$dbrec -> contactid = backup_todb ( $info [ 'CONTACT' ][ '#' ][ 'CONTACTID' ][ '0' ][ '#' ]);
$dbrec -> blocked = backup_todb ( $info [ 'CONTACT' ][ '#' ][ 'BLOCKED' ][ '0' ][ '#' ]);
//We have to recode the userid field
$user = backup_getid ( $restore -> backup_unique_code , " user " , $dbrec -> userid );
if ( $user ) {
//echo "User ".$dbrec->userid." to user ".$user->new_id."<br />"; //Debug
$dbrec -> userid = $user -> new_id ;
}
//We have to recode the contactid field
$user = backup_getid ( $restore -> backup_unique_code , " user " , $dbrec -> contactid );
if ( $user ) {
//echo "User ".$dbrec->contactid." to user ".$user->new_id."<br />"; //Debug
$dbrec -> contactid = $user -> new_id ;
}
//Check if the record doesn't exist in DB!
$exist = get_record ( 'message_contacts' , 'userid' , $dbrec -> userid ,
'contactid' , $dbrec -> contactid );
if ( ! $exist ) {
//Not exist. Insert
$status = insert_record ( 'message_contacts' , $dbrec );
} else {
//Duplicate. Do nothing
}
}
//Do some output
$counter ++ ;
if ( $counter % 10 == 0 ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 200 == 0 ) {
echo " <br /> " ;
}
2005-02-13 19:09:41 +00:00
}
backup_flush ( 300 );
}
}
}
}
}
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
//End ul
echo '</ul>' ;
}
2005-02-13 19:09:41 +00:00
}
}
}
return $status ;
}
2003-06-28 23:18:37 +00:00
//This function creates all the categories and questions
2007-07-28 09:23:32 +00:00
//from xml
2003-06-28 23:18:37 +00:00
function restore_create_questions ( $restore , $xml_file ) {
global $CFG , $db ;
$status = true ;
//Check it exists
if ( ! file_exists ( $xml_file )) {
$status = false ;
}
//Get info from xml
if ( $status ) {
//info will contain the old_id of every category
//in backup_ids->info will be the real info (serialized)
$info = restore_read_xml_questions ( $restore , $xml_file );
}
//Now, if we have anything in info, we have to restore that
//categories/questions
if ( $info ) {
if ( $info !== true ) {
2007-08-09 21:50:59 +00:00
$status = $status && restore_question_categories ( $info , $restore );
2003-06-28 23:18:37 +00:00
}
} else {
$status = false ;
2007-07-28 09:23:32 +00:00
}
2003-06-28 23:18:37 +00:00
return $status ;
}
2003-08-18 00:00:22 +00:00
//This function creates all the scales
function restore_create_scales ( $restore , $xml_file ) {
global $CFG , $db ;
$status = true ;
//Check it exists
if ( ! file_exists ( $xml_file )) {
$status = false ;
}
//Get info from xml
if ( $status ) {
//scales will contain the old_id of every scale
//in backup_ids->info will be the real info (serialized)
$scales = restore_read_xml_scales ( $restore , $xml_file );
}
//Now, if we have anything in scales, we have to restore that
//scales
if ( $scales ) {
2005-02-14 17:40:07 +00:00
//Get admin->id for later use
$admin = get_admin ();
$adminid = $admin -> id ;
2003-08-18 00:00:22 +00:00
if ( $scales !== true ) {
//Iterate over each scale
foreach ( $scales as $scale ) {
//Get record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , " scale " , $scale -> id );
//Init variables
$create_scale = false ;
if ( $data ) {
//Now get completed xmlized object
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now build the SCALE record structure
2007-08-14 20:35:04 +00:00
$sca = new object ();
2003-08-18 00:00:22 +00:00
$sca -> courseid = backup_todb ( $info [ 'SCALE' ][ '#' ][ 'COURSEID' ][ '0' ][ '#' ]);
$sca -> userid = backup_todb ( $info [ 'SCALE' ][ '#' ][ 'USERID' ][ '0' ][ '#' ]);
$sca -> name = backup_todb ( $info [ 'SCALE' ][ '#' ][ 'NAME' ][ '0' ][ '#' ]);
$sca -> scale = backup_todb ( $info [ 'SCALE' ][ '#' ][ 'SCALETEXT' ][ '0' ][ '#' ]);
$sca -> description = backup_todb ( $info [ 'SCALE' ][ '#' ][ 'DESCRIPTION' ][ '0' ][ '#' ]);
$sca -> timemodified = backup_todb ( $info [ 'SCALE' ][ '#' ][ 'TIMEMODIFIED' ][ '0' ][ '#' ]);
2003-08-18 13:07:02 +00:00
//Now search if that scale exists (by scale field) in course 0 (Standar scale)
//or in restore->course_id course (Personal scale)
if ( $sca -> courseid == 0 ) {
$course_to_search = 0 ;
} else {
$course_to_search = $restore -> course_id ;
}
2007-08-09 21:50:59 +00:00
2007-08-01 06:24:15 +00:00
// scale is not course unique, use get_record_sql to suppress warning
2007-08-09 21:50:59 +00:00
2007-08-01 06:24:15 +00:00
$sca_db = get_record_sql ( " SELECT * FROM { $CFG -> prefix } scale
WHERE scale = '$sca->scale'
2007-08-09 21:50:59 +00:00
AND courseid = $course_to_search " , true);
2003-08-18 00:00:22 +00:00
//If it doesn't exist, create
if ( ! $sca_db ) {
$create_scale = true ;
2007-07-28 09:23:32 +00:00
}
2003-08-18 00:00:22 +00:00
//If we must create the scale
if ( $create_scale ) {
//Me must recode the courseid if it's <> 0 (common scale)
if ( $sca -> courseid != 0 ) {
$sca -> courseid = $restore -> course_id ;
}
//We must recode the userid
$user = backup_getid ( $restore -> backup_unique_code , " user " , $sca -> userid );
if ( $user ) {
$sca -> userid = $user -> new_id ;
} else {
//Assign it to admin
2005-02-14 17:40:07 +00:00
$sca -> userid = $adminid ;
2003-08-18 00:00:22 +00:00
}
//The structure is equal to the db, so insert the scale
$newid = insert_record ( " scale " , $sca );
} else {
//get current scale id
$newid = $sca_db -> id ;
}
if ( $newid ) {
//We have the newid, update backup_ids
backup_putid ( $restore -> backup_unique_code , " scale " ,
$scale -> id , $newid );
}
}
}
}
} else {
$status = false ;
2007-07-28 09:23:32 +00:00
}
2003-08-18 00:00:22 +00:00
return $status ;
}
2004-01-25 20:57:58 +00:00
//This function creates all the groups
function restore_create_groups ( $restore , $xml_file ) {
2007-09-05 19:19:34 +00:00
global $CFG ;
2004-01-25 20:57:58 +00:00
//Check it exists
if ( ! file_exists ( $xml_file )) {
2007-08-14 20:35:04 +00:00
return false ;
2004-01-25 20:57:58 +00:00
}
//Get info from xml
2007-08-14 20:35:04 +00:00
if ( ! $groups = restore_read_xml_groups ( $restore , $xml_file )) {
2004-02-13 23:28:45 +00:00
//groups will contain the old_id of every group
2004-01-25 20:57:58 +00:00
//in backup_ids->info will be the real info (serialized)
2007-08-14 20:35:04 +00:00
return false ;
2004-01-25 20:57:58 +00:00
2007-08-14 20:35:04 +00:00
} else if ( $groups === true ) {
return true ;
}
2007-07-28 09:23:32 +00:00
2007-08-14 20:35:04 +00:00
$status = true ;
2005-02-15 18:37:08 +00:00
2007-08-14 20:35:04 +00:00
//Iterate over each group
foreach ( $groups as $group ) {
//Get record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , " groups " , $group -> id );
if ( $data ) {
//Now get completed xmlized object
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now build the GROUP record structure
$gro = new Object ();
$gro -> courseid = $restore -> course_id ;
$gro -> name = backup_todb ( $info [ 'GROUP' ][ '#' ][ 'NAME' ][ '0' ][ '#' ]);
$gro -> description = backup_todb ( $info [ 'GROUP' ][ '#' ][ 'DESCRIPTION' ][ '0' ][ '#' ]);
if ( isset ( $info [ 'GROUP' ][ '#' ][ 'ENROLMENTKEY' ][ '0' ][ '#' ])) {
$gro -> enrolmentkey = backup_todb ( $info [ 'GROUP' ][ '#' ][ 'ENROLMENTKEY' ][ '0' ][ '#' ]);
} else {
$gro -> enrolmentkey = backup_todb ( $info [ 'GROUP' ][ '#' ][ 'PASSWORD' ][ '0' ][ '#' ]);
}
$gro -> picture = backup_todb ( $info [ 'GROUP' ][ '#' ][ 'PICTURE' ][ '0' ][ '#' ]);
$gro -> hidepicture = backup_todb ( $info [ 'GROUP' ][ '#' ][ 'HIDEPICTURE' ][ '0' ][ '#' ]);
$gro -> timecreated = backup_todb ( $info [ 'GROUP' ][ '#' ][ 'TIMECREATED' ][ '0' ][ '#' ]);
$gro -> timemodified = backup_todb ( $info [ 'GROUP' ][ '#' ][ 'TIMEMODIFIED' ][ '0' ][ '#' ]);
2007-08-14 00:50:00 +00:00
2007-08-14 20:35:04 +00:00
//Now search if that group exists (by name and description field) in
2007-09-05 19:19:34 +00:00
//restore->course_id course
//Going to compare LOB columns so, use the cross-db sql_compare_text() in both sides.
$description_clause = '' ;
if ( ! empty ( $gro -> description )) { /// Only for groups having a description
$literal_description = " ' " . $gro -> description . " ' " ;
$description_clause = " AND " .
sql_compare_text ( 'description' ) . " = " .
sql_compare_text ( $literal_description );
}
2007-09-05 23:08:52 +00:00
if ( ! $gro_db = get_record_sql ( " SELECT *
2007-09-05 19:19:34 +00:00
FROM { $CFG -> prefix } groups
WHERE courseid = $restore -> course_id AND
2007-11-26 03:21:46 +00:00
name = '{$gro->name}' " . $description_clause , true)) {
2007-08-14 20:35:04 +00:00
//If it doesn't exist, create
$newid = insert_record ( 'groups' , $gro );
2007-08-14 00:50:00 +00:00
2007-08-14 20:35:04 +00:00
} else {
//get current group id
$newid = $gro_db -> id ;
}
if ( $newid ) {
//We have the newid, update backup_ids
backup_putid ( $restore -> backup_unique_code , " groups " , $group -> id , $newid );
} else {
$status = false ;
continue ;
2004-01-25 20:57:58 +00:00
}
2007-08-14 20:35:04 +00:00
//Now restore members in the groups_members, only if
//users are included
if ( $restore -> users != 2 ) {
if ( ! restore_create_groups_members ( $newid , $info , $restore )) {
$status = false ;
}
2005-03-07 23:40:25 +00:00
}
2004-01-25 20:57:58 +00:00
}
2007-07-28 09:23:32 +00:00
}
2007-08-14 20:35:04 +00:00
//Now, restore group_files
if ( $status ) {
$status = restore_group_files ( $restore );
}
return $status ;
2004-01-25 20:57:58 +00:00
}
//This function restores the groups_members
function restore_create_groups_members ( $group_id , $info , $restore ) {
2007-02-16 14:45:57 +00:00
if ( ! isset ( $info [ 'GROUP' ][ '#' ][ 'MEMBERS' ][ '0' ][ '#' ][ 'MEMBER' ])) {
//OK, some groups have no members.
2007-08-14 20:35:04 +00:00
return true ;
2007-02-16 14:45:57 +00:00
}
2004-01-25 20:57:58 +00:00
//Get the members array
$members = $info [ 'GROUP' ][ '#' ][ 'MEMBERS' ][ '0' ][ '#' ][ 'MEMBER' ];
2007-08-14 20:35:04 +00:00
$status = true ;
2004-01-25 20:57:58 +00:00
//Iterate over members
for ( $i = 0 ; $i < sizeof ( $members ); $i ++ ) {
$mem_info = $members [ $i ];
2004-01-29 00:08:25 +00:00
//traverse_xmlize($mem_info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
2004-01-25 20:57:58 +00:00
//Now, build the GROUPS_MEMBERS record structure
2007-01-20 09:28:26 +00:00
$group_member = new Object ();
2004-01-25 20:57:58 +00:00
$group_member -> groupid = $group_id ;
$group_member -> userid = backup_todb ( $mem_info [ '#' ][ 'USERID' ][ '0' ][ '#' ]);
$group_member -> timeadded = backup_todb ( $mem_info [ '#' ][ 'TIMEADDED' ][ '0' ][ '#' ]);
2007-08-14 00:50:00 +00:00
$newid = false ;
2004-01-25 20:57:58 +00:00
//We have to recode the userid field
2007-08-14 20:35:04 +00:00
if ( ! $user = backup_getid ( $restore -> backup_unique_code , " user " , $group_member -> userid )) {
$status = false ;
continue ;
}
2007-08-14 00:50:00 +00:00
2007-08-14 20:35:04 +00:00
$group_member -> userid = $user -> new_id ;
//The structure is equal to the db, so insert the groups_members
if ( ! insert_record ( " groups_members " , $group_member )) {
$status = false ;
continue ;
2004-01-25 20:57:58 +00:00
}
2007-01-20 09:28:26 +00:00
//Do some output
if (( $i + 1 ) % 50 == 0 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if (( $i + 1 ) % 1000 == 0 ) {
echo " <br /> " ;
}
}
backup_flush ( 300 );
}
}
return $status ;
}
2007-07-28 09:23:32 +00:00
2007-01-20 09:28:26 +00:00
//This function creates all the groupings
function restore_create_groupings ( $restore , $xml_file ) {
//Check it exists
if ( ! file_exists ( $xml_file )) {
2007-08-14 20:35:04 +00:00
return false ;
2007-01-20 09:28:26 +00:00
}
//Get info from xml
2007-08-14 20:35:04 +00:00
if ( ! $groupings = restore_read_xml_groupings ( $restore , $xml_file )) {
return false ;
} else if ( $groupings === true ) {
return true ;
2007-01-20 09:28:26 +00:00
}
2007-08-14 20:35:04 +00:00
$status = true ;
2007-01-20 09:28:26 +00:00
2007-08-14 20:35:04 +00:00
//Iterate over each group
foreach ( $groupings as $grouping ) {
if ( $data = backup_getid ( $restore -> backup_unique_code , " groupings " , $grouping -> id )) {
//Now get completed xmlized object
$info = $data -> info ;
//Now build the GROUPING record structure
$gro = new Object ();
///$gro->id = backup_todb($info['GROUPING']['#']['ID']['0']['#']);
$gro -> courseid = $restore -> course_id ;
$gro -> name = backup_todb ( $info [ 'GROUPING' ][ '#' ][ 'NAME' ][ '0' ][ '#' ]);
$gro -> description = backup_todb ( $info [ 'GROUPING' ][ '#' ][ 'DESCRIPTION' ][ '0' ][ '#' ]);
$gro -> configdata = backup_todb ( $info [ 'GROUPING' ][ '#' ][ 'CONFIGDATA' ][ '0' ][ '#' ]);
$gro -> timecreated = backup_todb ( $info [ 'GROUPING' ][ '#' ][ 'TIMECREATED' ][ '0' ][ '#' ]);
//Now search if that group exists (by name and description field) in
if ( $gro_db = get_record ( 'groupings' , 'courseid' , $restore -> course_id , 'name' , $gro -> name , 'description' , $gro -> description )) {
//get current group id
$newid = $gro_db -> id ;
2007-08-14 00:50:00 +00:00
2007-08-14 20:35:04 +00:00
} else {
//The structure is equal to the db, so insert the grouping
if ( ! $newid = insert_record ( 'groupings' , $gro )) {
$status = false ;
continue ;
2007-07-28 09:23:32 +00:00
}
2007-01-20 09:28:26 +00:00
}
2007-08-14 20:35:04 +00:00
//We have the newid, update backup_ids
backup_putid ( $restore -> backup_unique_code , " groupings " ,
$grouping -> id , $newid );
}
}
// now fix the defaultgroupingid in course
$course = get_record ( 'course' , 'id' , $restore -> course_id );
if ( $course -> defaultgroupingid ) {
if ( $grouping = backup_getid ( $restore -> backup_unique_code , " groupings " , $course -> defaultgroupingid )) {
set_field ( 'course' , 'defaultgroupingid' , $grouping -> new_id , 'id' , $course -> id );
} else {
set_field ( 'course' , 'defaultgroupingid' , 0 , 'id' , $course -> id );
2007-01-20 09:28:26 +00:00
}
2007-07-28 09:23:32 +00:00
}
2007-08-14 00:50:00 +00:00
return $status ;
2007-01-20 09:28:26 +00:00
}
2007-07-28 09:23:32 +00:00
2007-08-14 20:35:04 +00:00
//This function creates all the groupingsgroups
2007-08-14 00:50:00 +00:00
function restore_create_groupings_groups ( $restore , $xml_file ) {
2007-08-14 20:35:04 +00:00
//Check it exists
if ( ! file_exists ( $xml_file )) {
return false ;
}
//Get info from xml
if ( ! $groupingsgroups = restore_read_xml_groupings_groups ( $restore , $xml_file )) {
return false ;
2007-01-20 09:28:26 +00:00
2007-08-14 20:35:04 +00:00
} else if ( $groupingsgroups === true ) {
return true ;
}
2007-01-20 09:28:26 +00:00
$status = true ;
2007-08-14 20:35:04 +00:00
//Iterate over each group
foreach ( $groupingsgroups as $groupinggroup ) {
if ( $data = backup_getid ( $restore -> backup_unique_code , " groupingsgroups " , $groupinggroup -> id )) {
//Now get completed xmlized object
$info = $data -> info ;
//Now build the GROUPING record structure
$gro_member = new Object ();
$gro_member -> groupingid = backup_todb ( $info [ 'GROUPINGGROUP' ][ '#' ][ 'GROUPINGID' ][ '0' ][ '#' ]);
$gro_member -> groupid = backup_todb ( $info [ 'GROUPINGGROUP' ][ '#' ][ 'GROUPID' ][ '0' ][ '#' ]);
$gro_member -> timeadded = backup_todb ( $info [ 'GROUPINGGROUP' ][ '#' ][ 'TIMEADDED' ][ '0' ][ '#' ]);
if ( ! $grouping = backup_getid ( $restore -> backup_unique_code , " groupings " , $gro_member -> groupingid )) {
$status = false ;
continue ;
}
2007-01-20 09:28:26 +00:00
2007-08-14 20:35:04 +00:00
if ( ! $group = backup_getid ( $restore -> backup_unique_code , " groups " , $gro_member -> groupid )) {
$status = false ;
continue ;
}
2007-01-20 09:28:26 +00:00
2007-08-14 20:35:04 +00:00
$gro_member -> groupid = $group -> new_id ;
$gro_member -> groupingid = $grouping -> new_id ;
if ( ! get_record ( 'groupings_groups' , 'groupid' , $gro_member -> groupid , 'groupingid' , $gro_member -> groupingid )) {
if ( ! insert_record ( 'groupings_groups' , $gro_member )) {
$status = false ;
2006-01-15 21:09:13 +00:00
}
2004-01-25 20:57:58 +00:00
}
}
}
return $status ;
}
2004-02-21 01:30:22 +00:00
//This function creates all the course events
function restore_create_events ( $restore , $xml_file ) {
global $CFG , $db ;
$status = true ;
//Check it exists
if ( ! file_exists ( $xml_file )) {
$status = false ;
}
//Get info from xml
if ( $status ) {
//events will contain the old_id of every event
//in backup_ids->info will be the real info (serialized)
$events = restore_read_xml_events ( $restore , $xml_file );
}
2005-02-28 00:55:52 +00:00
//Get admin->id for later use
$admin = get_admin ();
$adminid = $admin -> id ;
2006-10-17 10:05:41 +00:00
2004-02-21 01:30:22 +00:00
//Now, if we have anything in events, we have to restore that
//events
if ( $events ) {
if ( $events !== true ) {
//Iterate over each event
foreach ( $events as $event ) {
//Get record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , " event " , $event -> id );
//Init variables
$create_event = false ;
if ( $data ) {
//Now get completed xmlized object
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
2006-10-17 10:05:41 +00:00
//if necessary, write to restorelog and adjust date/time fields
if ( $restore -> course_startdateoffset ) {
restore_log_date_changes ( 'Events' , $restore , $info [ 'EVENT' ][ '#' ], array ( 'TIMESTART' ));
}
2004-02-21 01:30:22 +00:00
//Now build the EVENT record structure
$eve -> name = backup_todb ( $info [ 'EVENT' ][ '#' ][ 'NAME' ][ '0' ][ '#' ]);
$eve -> description = backup_todb ( $info [ 'EVENT' ][ '#' ][ 'DESCRIPTION' ][ '0' ][ '#' ]);
2004-04-27 19:51:12 +00:00
$eve -> format = backup_todb ( $info [ 'EVENT' ][ '#' ][ 'FORMAT' ][ '0' ][ '#' ]);
2004-02-21 01:30:22 +00:00
$eve -> courseid = $restore -> course_id ;
$eve -> groupid = backup_todb ( $info [ 'EVENT' ][ '#' ][ 'GROUPID' ][ '0' ][ '#' ]);
$eve -> userid = backup_todb ( $info [ 'EVENT' ][ '#' ][ 'USERID' ][ '0' ][ '#' ]);
2005-04-22 23:49:48 +00:00
$eve -> repeatid = backup_todb ( $info [ 'EVENT' ][ '#' ][ 'REPEATID' ][ '0' ][ '#' ]);
2004-02-21 01:30:22 +00:00
$eve -> modulename = " " ;
2007-07-23 10:20:15 +00:00
if ( ! empty ( $info [ 'EVENT' ][ '#' ][ 'MODULENAME' ])) {
$eve -> modulename = backup_todb ( $info [ 'EVENT' ][ '#' ][ 'MODULENAME' ][ '0' ][ '#' ]);
2007-07-28 09:23:32 +00:00
}
2004-02-21 01:30:22 +00:00
$eve -> instance = 0 ;
2007-07-28 09:23:32 +00:00
$eve -> eventtype = backup_todb ( $info [ 'EVENT' ][ '#' ][ 'EVENTTYPE' ][ '0' ][ '#' ]);
2004-02-21 01:30:22 +00:00
$eve -> timestart = backup_todb ( $info [ 'EVENT' ][ '#' ][ 'TIMESTART' ][ '0' ][ '#' ]);
$eve -> timeduration = backup_todb ( $info [ 'EVENT' ][ '#' ][ 'TIMEDURATION' ][ '0' ][ '#' ]);
2004-05-06 22:17:45 +00:00
$eve -> visible = backup_todb ( $info [ 'EVENT' ][ '#' ][ 'VISIBLE' ][ '0' ][ '#' ]);
2004-02-21 01:30:22 +00:00
$eve -> timemodified = backup_todb ( $info [ 'EVENT' ][ '#' ][ 'TIMEMODIFIED' ][ '0' ][ '#' ]);
2007-05-24 12:09:49 +00:00
//Now search if that event exists (by name, description, timestart fields) in
//restore->course_id course
$eve_db = get_record_select ( " event " ,
" courseid= { $eve -> courseid } AND name=' { $eve -> name } ' AND description=' { $eve -> description } ' AND timestart= $eve->timestart " );
2004-02-21 01:30:22 +00:00
//If it doesn't exist, create
if ( ! $eve_db ) {
$create_event = true ;
}
//If we must create the event
if ( $create_event ) {
//We must recode the userid
$user = backup_getid ( $restore -> backup_unique_code , " user " , $eve -> userid );
if ( $user ) {
$eve -> userid = $user -> new_id ;
} else {
//Assign it to admin
2005-02-28 00:55:52 +00:00
$eve -> userid = $adminid ;
2004-02-21 01:30:22 +00:00
}
2005-04-22 23:49:48 +00:00
//We must recode the repeatid if the event has it
if ( ! empty ( $eve -> repeatid )) {
$repeat_rec = backup_getid ( $restore -> backup_unique_code , " event_repeatid " , $eve -> repeatid );
if ( $repeat_rec ) { //Exists, so use it...
$eve -> repeatid = $repeat_rec -> new_id ;
} else { //Doesn't exists, calculate the next and save it
$oldrepeatid = $eve -> repeatid ;
$max_rec = get_record_sql ( 'SELECT 1, MAX(repeatid) AS repeatid FROM ' . $CFG -> prefix . 'event' );
$eve -> repeatid = empty ( $max_rec ) ? 1 : $max_rec -> repeatid + 1 ;
backup_putid ( $restore -> backup_unique_code , " event_repeatid " , $oldrepeatid , $eve -> repeatid );
}
}
2007-07-28 09:23:32 +00:00
2004-02-21 01:30:22 +00:00
//We have to recode the groupid field
2005-06-03 16:46:28 +00:00
$group = backup_getid ( $restore -> backup_unique_code , " groups " , $eve -> groupid );
2004-02-21 01:30:22 +00:00
if ( $group ) {
$eve -> groupid = $group -> new_id ;
2004-04-27 22:37:01 +00:00
} else {
//Assign it to group 0
2004-04-28 22:29:39 +00:00
$eve -> groupid = 0 ;
2004-02-21 01:30:22 +00:00
}
//The structure is equal to the db, so insert the event
$newid = insert_record ( " event " , $eve );
2004-02-22 22:22:58 +00:00
} else {
//get current event id
$newid = $eve_db -> id ;
2004-02-21 01:30:22 +00:00
}
if ( $newid ) {
//We have the newid, update backup_ids
backup_putid ( $restore -> backup_unique_code , " event " ,
$event -> id , $newid );
}
}
}
}
} else {
$status = false ;
2007-07-28 09:23:32 +00:00
}
2004-02-21 01:30:22 +00:00
return $status ;
}
2004-04-01 23:31:56 +00:00
//This function decode things to make restore multi-site fully functional
//It does this conversions:
2004-07-15 23:04:22 +00:00
// - $@FILEPHP@$ ---|------------> $CFG->wwwroot/file.php/courseid (slasharguments on)
// |------------> $CFG->wwwroot/file.php?file=/courseid (slasharguments off)
2004-04-24 00:40:45 +00:00
//
//Note: Inter-activities linking is being implemented as a final
2007-07-28 09:23:32 +00:00
//step in the restore execution, because we need to have it
2004-04-24 00:40:45 +00:00
//finished to know all the oldid, newid equivaleces
2004-04-01 23:31:56 +00:00
function restore_decode_absolute_links ( $content ) {
2007-07-28 09:23:32 +00:00
global $CFG , $restore ;
2004-04-24 00:40:45 +00:00
2007-08-10 05:22:20 +00:00
// MDL-10770
// This function was replacing null with empty string
// Nullity check is added in backup_todb(), this function will no longer not be called from backup_todb() if content is null
// I noticed some parts of the restore code is calling this directly instead of calling backup_todb(), so just in case
// 3rd party mod etc are doing the same
if ( $content === NULL ) {
2007-08-14 20:35:04 +00:00
return NULL ;
2007-08-10 05:22:20 +00:00
}
2007-08-14 20:35:04 +00:00
2004-04-24 00:40:45 +00:00
//Now decode wwwroot and file.php calls
2004-05-06 22:17:45 +00:00
$search = array ( " $ @FILEPHP@ $ " );
2004-07-15 23:04:22 +00:00
//Check for the status of the slasharguments config variable
$slash = $CFG -> slasharguments ;
2007-07-28 09:23:32 +00:00
2004-07-15 23:04:22 +00:00
//Build the replace string as needed
if ( $slash == 1 ) {
$replace = array ( $CFG -> wwwroot . " /file.php/ " . $restore -> course_id );
} else {
$replace = array ( $CFG -> wwwroot . " /file.php?file=/ " . $restore -> course_id );
}
2007-07-28 09:23:32 +00:00
2004-04-01 23:31:56 +00:00
$result = str_replace ( $search , $replace , $content );
2006-09-18 13:24:45 +00:00
if ( $result != $content && debugging ()) { //Debug
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-04-11 15:34:29 +00:00
echo '<br /><hr />' . s ( $content ) . '<br />changed to<br />' . s ( $result ) . '<hr /><br />' ; //Debug
2006-01-15 21:09:13 +00:00
}
2004-04-24 00:40:45 +00:00
} //Debug
2004-04-01 23:31:56 +00:00
return $result ;
}
2003-05-28 19:43:11 +00:00
//This function restores the userfiles from the temp (user_files) directory to the
//dataroot/users directory
function restore_user_files ( $restore ) {
global $CFG ;
$status = true ;
2004-01-25 20:57:58 +00:00
$counter = 0 ;
2007-10-12 19:13:18 +00:00
// 'users' is the old users folder, 'user' is the new one, with a new hierarchy. Detect which one is here and treat accordingly
2003-05-28 19:43:11 +00:00
//in CFG->dataroot
2007-10-12 19:13:18 +00:00
$dest_dir = $CFG -> dataroot . " /user " ;
2003-05-28 19:43:11 +00:00
$status = check_dir_exists ( $dest_dir , true );
//Now, we iterate over "user_files" records to check if that user dir must be
//copied (and renamed) to the "users" dir.
$rootdir = $CFG -> dataroot . " /temp/backup/ " . $restore -> backup_unique_code . " /user_files " ;
2007-10-12 19:13:18 +00:00
2003-05-28 19:43:11 +00:00
//Check if directory exists
2007-10-12 19:13:18 +00:00
$userlist = array ();
if ( is_dir ( $rootdir ) && ( $list = list_directories ( $rootdir ))) {
$counter = 0 ;
foreach ( $list as $dir ) {
// If there are directories in this folder, we are in the new user hierarchy
if ( $newlist = list_directories ( " $rootdir / $dir " )) {
2007-10-20 20:57:06 +00:00
foreach ( $newlist as $olduserid ) {
$userlist [ $olduserid ] = " $rootdir / $dir / $olduserid " ;
2007-10-12 19:13:18 +00:00
}
} else {
2007-10-20 20:57:06 +00:00
$userlist [ $dir ] = " $rootdir / $dir " ;
2007-10-12 19:13:18 +00:00
}
}
2007-10-20 20:57:06 +00:00
foreach ( $userlist as $olduserid => $backup_location ) {
2007-10-12 19:13:18 +00:00
//Look for dir like username in backup_ids
//If that user exists in backup_ids
2007-10-20 20:57:06 +00:00
if ( $user = backup_getid ( $restore -> backup_unique_code , " user " , $olduserid )) {
2007-10-12 19:13:18 +00:00
//Only if user has been created now or if it existed previously, but he hasn't got an image (see bug 1123)
2007-10-20 20:57:06 +00:00
$newuserdir = make_user_directory ( $user -> new_id , true ); // Doesn't create the folder, just returns the location
2007-10-12 19:13:18 +00:00
2007-10-20 20:57:06 +00:00
// restore images if new user or image does not exist yet
if ( ! empty ( $user -> new ) or ! check_dir_exists ( $newuserdir )) {
if ( make_user_directory ( $user -> new_id )) { // Creates the folder
2007-10-12 19:13:18 +00:00
$status = backup_copy_file ( $backup_location , $newuserdir , true );
$counter ++ ;
}
//Do some output
if ( $counter % 2 == 0 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 40 == 0 ) {
echo " <br /> " ;
2003-06-21 22:37:57 +00:00
}
}
2007-10-12 19:13:18 +00:00
backup_flush ( 300 );
2003-05-28 19:43:11 +00:00
}
}
}
}
}
//If status is ok and whe have dirs created, returns counter to inform
if ( $status and $counter ) {
return $counter ;
} else {
return $status ;
}
}
2005-03-07 23:40:25 +00:00
//This function restores the groupfiles from the temp (group_files) directory to the
//dataroot/groups directory
function restore_group_files ( $restore ) {
global $CFG ;
$status = true ;
$counter = 0 ;
//First, we check to "groups" exists and create is as necessary
//in CFG->dataroot
$dest_dir = $CFG -> dataroot . '/groups' ;
$status = check_dir_exists ( $dest_dir , true );
//Now, we iterate over "group_files" records to check if that user dir must be
//copied (and renamed) to the "groups" dir.
$rootdir = $CFG -> dataroot . " /temp/backup/ " . $restore -> backup_unique_code . " /group_files " ;
//Check if directory exists
if ( is_dir ( $rootdir )) {
$list = list_directories ( $rootdir );
if ( $list ) {
//Iterate
$counter = 0 ;
foreach ( $list as $dir ) {
//Look for dir like groupid in backup_ids
$data = get_record ( " backup_ids " , " backup_code " , $restore -> backup_unique_code ,
" table_name " , " groups " ,
" old_id " , $dir );
//If that group exists in backup_ids
if ( $data ) {
if ( ! file_exists ( $dest_dir . " / " . $data -> new_id )) {
2005-06-16 02:33:42 +00:00
$status = backup_copy_file ( $rootdir . " / " . $dir , $dest_dir . " / " . $data -> new_id , true );
2005-03-07 23:40:25 +00:00
$counter ++ ;
}
//Do some output
if ( $counter % 2 == 0 ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 40 == 0 ) {
echo " <br /> " ;
}
2005-03-07 23:40:25 +00:00
}
backup_flush ( 300 );
2007-07-28 09:23:32 +00:00
}
2005-03-07 23:40:25 +00:00
}
}
}
}
//If status is ok and whe have dirs created, returns counter to inform
if ( $status and $counter ) {
return $counter ;
} else {
return $status ;
}
}
2003-05-28 19:43:11 +00:00
//This function restores the course files from the temp (course_files) directory to the
//dataroot/course_id directory
function restore_course_files ( $restore ) {
global $CFG ;
$status = true ;
2007-07-28 09:23:32 +00:00
2004-01-25 20:57:58 +00:00
$counter = 0 ;
2003-05-28 19:43:11 +00:00
//First, we check to "course_id" exists and create is as necessary
//in CFG->dataroot
$dest_dir = $CFG -> dataroot . " / " . $restore -> course_id ;
$status = check_dir_exists ( $dest_dir , true );
//Now, we iterate over "course_files" records to check if that file/dir must be
//copied to the "dest_dir" dir.
$rootdir = $CFG -> dataroot . " /temp/backup/ " . $restore -> backup_unique_code . " /course_files " ;
//Check if directory exists
if ( is_dir ( $rootdir )) {
$list = list_directories_and_files ( $rootdir );
if ( $list ) {
//Iterate
$counter = 0 ;
foreach ( $list as $dir ) {
2007-07-28 09:23:32 +00:00
//Copy the dir to its new location
2003-05-28 19:43:11 +00:00
//Only if destination file/dir doesn exists
if ( ! file_exists ( $dest_dir . " / " . $dir )) {
$status = backup_copy_file ( $rootdir . " / " . $dir ,
2005-06-16 02:33:42 +00:00
$dest_dir . " / " . $dir , true );
2003-05-28 19:43:11 +00:00
$counter ++ ;
}
2003-06-21 22:37:57 +00:00
//Do some output
2007-07-28 09:23:32 +00:00
if ( $counter % 2 == 0 ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
2007-07-28 09:23:32 +00:00
if ( $counter % 40 == 0 ) {
2006-01-15 21:09:13 +00:00
echo " <br /> " ;
}
2003-06-21 22:37:57 +00:00
}
backup_flush ( 300 );
}
2003-05-28 19:43:11 +00:00
}
}
}
//If status is ok and whe have dirs created, returns counter to inform
if ( $status and $counter ) {
return $counter ;
} else {
return $status ;
}
}
2007-07-28 09:23:32 +00:00
2007-08-09 21:50:59 +00:00
//This function restores the site files from the temp (site_files) directory to the
//dataroot/SITEID directory
function restore_site_files ( $restore ) {
global $CFG ;
$status = true ;
$counter = 0 ;
//First, we check to "course_id" exists and create is as necessary
//in CFG->dataroot
$dest_dir = $CFG -> dataroot . " / " . SITEID ;
$status = check_dir_exists ( $dest_dir , true );
//Now, we iterate over "site_files" files to check if that file/dir must be
//copied to the "dest_dir" dir.
$rootdir = $CFG -> dataroot . " /temp/backup/ " . $restore -> backup_unique_code . " /site_files " ;
//Check if directory exists
if ( is_dir ( $rootdir )) {
$list = list_directories_and_files ( $rootdir );
if ( $list ) {
//Iterate
$counter = 0 ;
foreach ( $list as $dir ) {
//Copy the dir to its new location
//Only if destination file/dir doesn exists
if ( ! file_exists ( $dest_dir . " / " . $dir )) {
$status = backup_copy_file ( $rootdir . " / " . $dir ,
$dest_dir . " / " . $dir , true );
$counter ++ ;
}
//Do some output
if ( $counter % 2 == 0 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 40 == 0 ) {
echo " <br /> " ;
}
}
backup_flush ( 300 );
}
}
}
}
//If status is ok and whe have dirs created, returns counter to inform
if ( $status and $counter ) {
return $counter ;
} else {
return $status ;
}
}
2003-05-17 17:34:30 +00:00
2003-05-30 21:32:04 +00:00
//This function creates all the structures for every module in backup file
//Depending what has been selected.
function restore_create_modules ( $restore , $xml_file ) {
global $CFG ;
$status = true ;
//Check it exists
if ( ! file_exists ( $xml_file )) {
$status = false ;
}
//Get info from xml
if ( $status ) {
2003-05-30 22:55:40 +00:00
//info will contain the id and modtype of every module
2003-05-30 21:32:04 +00:00
//in backup_ids->info will be the real info (serialized)
$info = restore_read_xml_modules ( $restore , $xml_file );
}
2003-05-30 22:55:40 +00:00
//Now, if we have anything in info, we have to restore that mods
//from backup_ids (calling every mod restore function)
if ( $info ) {
2003-06-20 19:42:20 +00:00
if ( $info !== true ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<ul>' ;
}
2003-06-20 19:42:20 +00:00
//Iterate over each module
foreach ( $info as $mod ) {
2006-10-04 09:01:50 +00:00
if ( empty ( $restore -> mods [ $mod -> modtype ] -> granular ) // We don't care about per instance, i.e. restore all instances.
2007-07-28 09:23:32 +00:00
|| ( array_key_exists ( $mod -> id , $restore -> mods [ $mod -> modtype ] -> instances )
2006-01-13 03:45:31 +00:00
&& ! empty ( $restore -> mods [ $mod -> modtype ] -> instances [ $mod -> id ] -> restore ))) {
$modrestore = $mod -> modtype . " _restore_mods " ;
2006-10-04 09:01:50 +00:00
if ( function_exists ( $modrestore )) { //Debug
2007-08-28 16:30:39 +00:00
// we want to restore all mods even when one fails
// incorrect code here ignored any errors during module restore in 1.6-1.8
$status = $status && $modrestore ( $mod , $restore );
2006-01-13 03:45:31 +00:00
} else {
//Something was wrong. Function should exist.
$status = false ;
}
2003-06-20 19:42:20 +00:00
}
2003-05-31 15:21:39 +00:00
}
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</ul>' ;
}
2003-05-31 15:21:39 +00:00
}
} else {
$status = false ;
}
2003-06-28 23:18:37 +00:00
return $status ;
2003-05-31 15:21:39 +00:00
}
2004-02-13 23:28:45 +00:00
//This function creates all the structures for every log in backup file
//Depending what has been selected.
function restore_create_logs ( $restore , $xml_file ) {
2007-07-28 09:23:32 +00:00
2004-02-13 23:28:45 +00:00
global $CFG , $db ;
//Number of records to get in every chunk
$recordset_size = 4 ;
//Counter, points to current record
$counter = 0 ;
//To count all the recods to restore
$count_logs = 0 ;
2007-07-28 09:23:32 +00:00
2004-02-13 23:28:45 +00:00
$status = true ;
2007-07-28 09:23:32 +00:00
//Check it exists
if ( ! file_exists ( $xml_file )) {
2004-02-13 23:28:45 +00:00
$status = false ;
}
//Get info from xml
if ( $status ) {
//count_logs will contain the number of logs entries to process
//in backup_ids->info will be the real info (serialized)
$count_logs = restore_read_xml_logs ( $restore , $xml_file );
}
2007-07-28 09:23:32 +00:00
2004-02-13 23:28:45 +00:00
//Now, if we have records in count_logs, we have to restore that logs
//from backup_ids. This piece of code makes calls to:
// - restore_log_course() if it's a course log
// - restore_log_user() if it's a user log
// - restore_log_module() if it's a module log.
//And all is segmented in chunks to allow large recordsets to be restored !!
if ( $count_logs > 0 ) {
while ( $counter < $count_logs ) {
//Get a chunk of records
//Take old_id twice to avoid adodb limitation
2007-09-05 15:46:16 +00:00
$logs = get_records_select ( " backup_ids " , " table_name = 'log' AND backup_code = ' $restore->backup_unique_code ' " , " old_id " , " old_id " , $counter , $recordset_size );
2004-02-13 23:28:45 +00:00
//We have logs
if ( $logs ) {
//Iterate
foreach ( $logs as $log ) {
//Get the full record from backup_ids
$data = backup_getid ( $restore -> backup_unique_code , " log " , $log -> old_id );
if ( $data ) {
//Now get completed xmlized object
$info = $data -> info ;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now build the LOG record structure
2007-08-15 10:43:25 +00:00
$dblog = new object ();
2004-02-13 23:28:45 +00:00
$dblog -> time = backup_todb ( $info [ 'LOG' ][ '#' ][ 'TIME' ][ '0' ][ '#' ]);
$dblog -> userid = backup_todb ( $info [ 'LOG' ][ '#' ][ 'USERID' ][ '0' ][ '#' ]);
$dblog -> ip = backup_todb ( $info [ 'LOG' ][ '#' ][ 'IP' ][ '0' ][ '#' ]);
$dblog -> course = $restore -> course_id ;
$dblog -> module = backup_todb ( $info [ 'LOG' ][ '#' ][ 'MODULE' ][ '0' ][ '#' ]);
$dblog -> cmid = backup_todb ( $info [ 'LOG' ][ '#' ][ 'CMID' ][ '0' ][ '#' ]);
$dblog -> action = backup_todb ( $info [ 'LOG' ][ '#' ][ 'ACTION' ][ '0' ][ '#' ]);
$dblog -> url = backup_todb ( $info [ 'LOG' ][ '#' ][ 'URL' ][ '0' ][ '#' ]);
$dblog -> info = backup_todb ( $info [ 'LOG' ][ '#' ][ 'INFO' ][ '0' ][ '#' ]);
//We have to recode the userid field
$user = backup_getid ( $restore -> backup_unique_code , " user " , $dblog -> userid );
if ( $user ) {
2004-09-12 01:34:24 +00:00
//echo "User ".$dblog->userid." to user ".$user->new_id."<br />"; //Debug
2004-02-13 23:28:45 +00:00
$dblog -> userid = $user -> new_id ;
}
//We have to recode the cmid field (if module isn't "course" or "user")
if ( $dblog -> module != " course " and $dblog -> module != " user " ) {
$cm = backup_getid ( $restore -> backup_unique_code , " course_modules " , $dblog -> cmid );
if ( $cm ) {
2004-09-12 01:34:24 +00:00
//echo "Module ".$dblog->cmid." to module ".$cm->new_id."<br />"; //Debug
2004-02-13 23:28:45 +00:00
$dblog -> cmid = $cm -> new_id ;
2004-02-15 00:54:56 +00:00
} else {
$dblog -> cmid = 0 ;
2004-02-13 23:28:45 +00:00
}
}
//print_object ($dblog); //Debug
//Now, we redirect to the needed function to make all the work
if ( $dblog -> module == " course " ) {
//It's a course log,
$stat = restore_log_course ( $restore , $dblog );
} elseif ( $dblog -> module == " user " ) {
//It's a user log,
$stat = restore_log_user ( $restore , $dblog );
} else {
//It's a module log,
$stat = restore_log_module ( $restore , $dblog );
}
}
//Do some output
$counter ++ ;
if ( $counter % 10 == 0 ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 200 == 0 ) {
echo " <br /> " ;
}
2004-02-13 23:28:45 +00:00
}
backup_flush ( 300 );
}
}
} else {
//We never should arrive here
$counter = $count_logs ;
$status = false ;
}
}
}
return $status ;
}
//This function inserts a course log record, calculating the URL field as necessary
function restore_log_course ( $restore , $log ) {
$status = true ;
$toinsert = false ;
2004-09-12 01:34:24 +00:00
//echo "<hr />Before transformations<br />"; //Debug
2004-02-13 23:28:45 +00:00
//print_object($log); //Debug
//Depending of the action, we recode different things
switch ( $log -> action ) {
case " view " :
$log -> url = " view.php?id= " . $log -> course ;
$log -> info = $log -> course ;
$toinsert = true ;
break ;
2005-08-03 19:04:05 +00:00
case " guest " :
$log -> url = " view.php?id= " . $log -> course ;
$toinsert = true ;
break ;
2004-02-13 23:28:45 +00:00
case " user report " :
//recode the info field (it's the user id)
$user = backup_getid ( $restore -> backup_unique_code , " user " , $log -> info );
if ( $user ) {
$log -> info = $user -> new_id ;
//Now, extract the mode from the url field
$mode = substr ( strrchr ( $log -> url , " = " ), 1 );
2005-08-03 19:04:05 +00:00
$log -> url = " user.php?id= " . $log -> course . " &user= " . $log -> info . " &mode= " . $mode ;
2004-02-13 23:28:45 +00:00
$toinsert = true ;
}
break ;
case " add mod " :
//Extract the course_module from the url field
$cmid = substr ( strrchr ( $log -> url , " = " ), 1 );
//recode the course_module to see it it has been restored
$cm = backup_getid ( $restore -> backup_unique_code , " course_modules " , $cmid );
if ( $cm ) {
$cmid = $cm -> new_id ;
//Extract the module name and the module id from the info field
$modname = strtok ( $log -> info , " " );
$modid = strtok ( " " );
//recode the module id to see if it has been restored
$mod = backup_getid ( $restore -> backup_unique_code , $modname , $modid );
if ( $mod ) {
$modid = $mod -> new_id ;
//Now I have everything so reconstruct url and info
$log -> info = $modname . " " . $modid ;
$log -> url = " ../mod/ " . $modname . " /view.php?id= " . $cmid ;
$toinsert = true ;
}
}
break ;
case " update mod " :
//Extract the course_module from the url field
$cmid = substr ( strrchr ( $log -> url , " = " ), 1 );
//recode the course_module to see it it has been restored
$cm = backup_getid ( $restore -> backup_unique_code , " course_modules " , $cmid );
if ( $cm ) {
$cmid = $cm -> new_id ;
//Extract the module name and the module id from the info field
$modname = strtok ( $log -> info , " " );
$modid = strtok ( " " );
//recode the module id to see if it has been restored
$mod = backup_getid ( $restore -> backup_unique_code , $modname , $modid );
if ( $mod ) {
$modid = $mod -> new_id ;
//Now I have everything so reconstruct url and info
$log -> info = $modname . " " . $modid ;
$log -> url = " ../mod/ " . $modname . " /view.php?id= " . $cmid ;
$toinsert = true ;
}
}
break ;
case " delete mod " :
$log -> url = " view.php?id= " . $log -> course ;
$toinsert = true ;
break ;
case " update " :
$log -> url = " edit.php?id= " . $log -> course ;
$log -> info = " " ;
$toinsert = true ;
break ;
case " unenrol " :
//recode the info field (it's the user id)
$user = backup_getid ( $restore -> backup_unique_code , " user " , $log -> info );
if ( $user ) {
$log -> info = $user -> new_id ;
$log -> url = " view.php?id= " . $log -> course ;
$toinsert = true ;
}
break ;
case " enrol " :
//recode the info field (it's the user id)
$user = backup_getid ( $restore -> backup_unique_code , " user " , $log -> info );
if ( $user ) {
$log -> info = $user -> new_id ;
$log -> url = " view.php?id= " . $log -> course ;
$toinsert = true ;
}
break ;
case " editsection " :
//Extract the course_section from the url field
$secid = substr ( strrchr ( $log -> url , " = " ), 1 );
//recode the course_section to see if it has been restored
$sec = backup_getid ( $restore -> backup_unique_code , " course_sections " , $secid );
if ( $sec ) {
$secid = $sec -> new_id ;
//Now I have everything so reconstruct url and info
$log -> url = " editsection.php?id= " . $secid ;
$toinsert = true ;
}
break ;
case " new " :
$log -> url = " view.php?id= " . $log -> course ;
$log -> info = " " ;
$toinsert = true ;
break ;
2004-08-27 03:38:39 +00:00
case " recent " :
2004-08-27 00:24:05 +00:00
$log -> url = " recent.php?id= " . $log -> course ;
$log -> info = " " ;
$toinsert = true ;
break ;
2006-06-04 00:03:12 +00:00
case " report log " :
$log -> url = " report/log/index.php?id= " . $log -> course ;
$log -> info = $log -> course ;
$toinsert = true ;
break ;
case " report live " :
$log -> url = " report/log/live.php?id= " . $log -> course ;
$log -> info = $log -> course ;
$toinsert = true ;
break ;
case " report outline " :
$log -> url = " report/outline/index.php?id= " . $log -> course ;
$log -> info = $log -> course ;
$toinsert = true ;
break ;
case " report participation " :
$log -> url = " report/participation/index.php?id= " . $log -> course ;
$log -> info = $log -> course ;
$toinsert = true ;
break ;
case " report stats " :
$log -> url = " report/stats/index.php?id= " . $log -> course ;
$log -> info = $log -> course ;
$toinsert = true ;
break ;
2004-02-13 23:28:45 +00:00
default :
2006-03-28 23:31:12 +00:00
echo " action ( " . $log -> module . " - " . $log -> action . " ) unknown. Not restored<br /> " ; //Debug
2004-02-13 23:28:45 +00:00
break ;
}
2004-09-12 01:34:24 +00:00
//echo "After transformations<br />"; //Debug
2004-02-13 23:28:45 +00:00
//print_object($log); //Debug
//Now if $toinsert is set, insert the record
if ( $toinsert ) {
2004-09-12 01:34:24 +00:00
//echo "Inserting record<br />"; //Debug
2004-02-13 23:28:45 +00:00
$status = insert_record ( " log " , $log );
}
return $status ;
}
//This function inserts a user log record, calculating the URL field as necessary
function restore_log_user ( $restore , $log ) {
$status = true ;
$toinsert = false ;
2007-07-28 09:23:32 +00:00
2004-09-12 01:34:24 +00:00
//echo "<hr />Before transformations<br />"; //Debug
2004-02-13 23:28:45 +00:00
//print_object($log); //Debug
2007-07-28 09:23:32 +00:00
//Depending of the action, we recode different things
2004-02-13 23:28:45 +00:00
switch ( $log -> action ) {
case " view " :
//recode the info field (it's the user id)
$user = backup_getid ( $restore -> backup_unique_code , " user " , $log -> info );
if ( $user ) {
$log -> info = $user -> new_id ;
2005-08-03 19:04:05 +00:00
$log -> url = " view.php?id= " . $log -> info . " &course= " . $log -> course ;
2004-02-13 23:28:45 +00:00
$toinsert = true ;
}
break ;
2004-02-21 01:30:22 +00:00
case " change password " :
//recode the info field (it's the user id)
$user = backup_getid ( $restore -> backup_unique_code , " user " , $log -> info );
if ( $user ) {
$log -> info = $user -> new_id ;
2005-08-03 19:04:05 +00:00
$log -> url = " view.php?id= " . $log -> info . " &course= " . $log -> course ;
$toinsert = true ;
}
break ;
case " login " :
//recode the info field (it's the user id)
$user = backup_getid ( $restore -> backup_unique_code , " user " , $log -> info );
if ( $user ) {
$log -> info = $user -> new_id ;
$log -> url = " view.php?id= " . $log -> info . " &course= " . $log -> course ;
$toinsert = true ;
}
break ;
case " logout " :
//recode the info field (it's the user id)
$user = backup_getid ( $restore -> backup_unique_code , " user " , $log -> info );
if ( $user ) {
$log -> info = $user -> new_id ;
$log -> url = " view.php?id= " . $log -> info . " &course= " . $log -> course ;
2004-02-21 01:30:22 +00:00
$toinsert = true ;
}
break ;
2004-02-13 23:28:45 +00:00
case " view all " :
$log -> url = " view.php?id= " . $log -> course ;
$log -> info = " " ;
$toinsert = true ;
case " update " :
2007-07-28 09:23:32 +00:00
//We split the url by ampersand char
2004-02-13 23:28:45 +00:00
$first_part = strtok ( $log -> url , " & " );
//Get data after the = char. It's the user being updated
$userid = substr ( strrchr ( $first_part , " = " ), 1 );
//Recode the user
$user = backup_getid ( $restore -> backup_unique_code , " user " , $userid );
if ( $user ) {
$log -> info = " " ;
2005-08-03 19:04:05 +00:00
$log -> url = " view.php?id= " . $user -> new_id . " &course= " . $log -> course ;
2004-02-13 23:28:45 +00:00
$toinsert = true ;
}
break ;
default :
2006-03-28 23:31:12 +00:00
echo " action ( " . $log -> module . " - " . $log -> action . " ) unknown. Not restored<br /> " ; //Debug
2004-02-13 23:28:45 +00:00
break ;
}
2004-09-12 01:34:24 +00:00
//echo "After transformations<br />"; //Debug
2004-02-13 23:28:45 +00:00
//print_object($log); //Debug
//Now if $toinsert is set, insert the record
if ( $toinsert ) {
2004-09-12 01:34:24 +00:00
//echo "Inserting record<br />"; //Debug
2004-02-13 23:28:45 +00:00
$status = insert_record ( " log " , $log );
}
return $status ;
}
//This function inserts a module log record, calculating the URL field as necessary
function restore_log_module ( $restore , $log ) {
$status = true ;
2004-02-15 00:54:56 +00:00
$toinsert = false ;
2004-09-12 01:34:24 +00:00
//echo "<hr />Before transformations<br />"; //Debug
2004-02-15 00:54:56 +00:00
//print_object($log); //Debug
//Now we see if the required function in the module exists
$function = $log -> module . " _restore_logs " ;
if ( function_exists ( $function )) {
//Call the function
$log = $function ( $restore , $log );
//If everything is ok, mark the insert flag
if ( $log ) {
$toinsert = true ;
}
}
2004-02-13 23:28:45 +00:00
2004-09-12 01:34:24 +00:00
//echo "After transformations<br />"; //Debug
2004-02-15 00:54:56 +00:00
//print_object($log); //Debug
//Now if $toinsert is set, insert the record
if ( $toinsert ) {
2004-09-12 01:34:24 +00:00
//echo "Inserting record<br />"; //Debug
2004-02-15 00:54:56 +00:00
$status = insert_record ( " log " , $log );
}
2004-02-13 23:28:45 +00:00
return $status ;
}
2003-05-31 15:21:39 +00:00
//This function adjusts the instance field into course_modules. It's executed after
//modules restore. There, we KNOW the new instance id !!
function restore_check_instances ( $restore ) {
global $CFG ;
$status = true ;
2003-05-30 22:55:40 +00:00
2003-05-31 15:21:39 +00:00
//We are going to iterate over each course_module saved in backup_ids
2003-06-20 19:42:20 +00:00
$course_modules = get_records_sql ( " SELECT old_id,new_id
2003-05-31 15:21:39 +00:00
FROM { $CFG -> prefix } backup_ids
WHERE backup_code = '$restore->backup_unique_code' AND
table_name = 'course_modules' " );
if ( $course_modules ) {
foreach ( $course_modules as $cm ) {
2003-06-20 19:42:20 +00:00
//Get full record, using backup_getids
$cm_module = backup_getid ( $restore -> backup_unique_code , " course_modules " , $cm -> old_id );
2003-05-31 15:21:39 +00:00
//Now we are going to the REAL course_modules to get its type (field module)
2003-06-20 19:42:20 +00:00
$module = get_record ( " course_modules " , " id " , $cm_module -> new_id );
2003-05-31 15:21:39 +00:00
if ( $module ) {
//We know the module type id. Get the name from modules
$type = get_record ( " modules " , " id " , $module -> module );
if ( $type ) {
//We know the type name and the old_id. Get its new_id
//from backup_ids. It's the instance !!!
2003-06-20 19:42:20 +00:00
$instance = backup_getid ( $restore -> backup_unique_code , $type -> name , $cm_module -> info );
2003-05-31 15:21:39 +00:00
if ( $instance ) {
//We have the new instance, so update the record in course_modules
$module -> instance = $instance -> new_id ;
2006-09-20 20:31:09 +00:00
//print_object ($module); //Debug
2003-05-31 15:21:39 +00:00
$status = update_record ( " course_modules " , $module );
} else {
$status = false ;
}
} else {
$status = false ;
}
} else {
$status = false ;
}
}
2003-05-30 22:55:40 +00:00
}
2003-05-31 15:21:39 +00:00
return $status ;
2003-05-30 21:32:04 +00:00
}
2003-05-16 23:57:35 +00:00
//=====================================================================================
//== ==
//== XML Functions (SAX) ==
//== ==
//=====================================================================================
//This is the class used to do all the xml parse
class MoodleParser {
var $level = 0 ; //Level we are
2003-06-20 19:42:20 +00:00
var $counter = 0 ; //Counter
2003-05-16 23:57:35 +00:00
var $tree = array (); //Array of levels we are
var $content = " " ; //Content under current level
var $todo = " " ; //What we hav to do when parsing
2003-05-30 22:55:40 +00:00
var $info = " " ; //Information collected. Temp storage. Used to return data after parsing.
var $temp = " " ; //Temp storage.
2003-05-16 23:57:35 +00:00
var $preferences = " " ; //Preferences about what to load !!
var $finished = false ; //Flag to say xml_parse to stop
2003-05-17 17:34:30 +00:00
//This function is used to get the current contents property value
2006-03-03 22:22:07 +00:00
//They are trimed (and converted from utf8 if needed)
2003-05-17 17:34:30 +00:00
function getContents () {
2006-11-11 17:23:20 +00:00
return trim ( $this -> content );
2003-05-17 17:34:30 +00:00
}
2007-07-28 09:23:32 +00:00
2003-05-17 11:40:27 +00:00
//This is the startTag handler we use where we are reading the info zone (todo="INFO")
function startElementInfo ( $parser , $tagName , $attrs ) {
//Refresh properties
$this -> level ++ ;
$this -> tree [ $this -> level ] = $tagName ;
2003-06-12 17:38:36 +00:00
//Output something to avoid browser timeouts...
backup_flush ();
2003-05-17 11:40:27 +00:00
//Check if we are into INFO zone
//if ($this->tree[2] == "INFO") //Debug
2004-09-12 01:34:24 +00:00
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
2003-05-17 11:40:27 +00:00
}
2003-05-16 23:57:35 +00:00
2006-09-25 09:10:19 +00:00
//This is the startTag handler we use where we are reading the info zone (todo="INFO")
function startElementRoles ( $parser , $tagName , $attrs ) {
//Refresh properties
$this -> level ++ ;
$this -> tree [ $this -> level ] = $tagName ;
//Output something to avoid browser timeouts...
backup_flush ();
//Check if we are into INFO zone
//if ($this->tree[2] == "INFO") //Debug
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
}
2003-05-17 17:34:30 +00:00
//This is the startTag handler we use where we are reading the course header zone (todo="COURSE_HEADER")
function startElementCourseHeader ( $parser , $tagName , $attrs ) {
//Refresh properties
$this -> level ++ ;
$this -> tree [ $this -> level ] = $tagName ;
2003-06-12 17:38:36 +00:00
//Output something to avoid browser timeouts...
backup_flush ();
2003-05-17 17:34:30 +00:00
//Check if we are into COURSE_HEADER zone
//if ($this->tree[3] == "HEADER") //Debug
2004-09-12 01:34:24 +00:00
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
2003-05-17 17:34:30 +00:00
}
2004-10-29 17:07:11 +00:00
//This is the startTag handler we use where we are reading the blocks zone (todo="BLOCKS")
function startElementBlocks ( $parser , $tagName , $attrs ) {
2007-07-28 09:23:32 +00:00
//Refresh properties
2004-10-29 17:07:11 +00:00
$this -> level ++ ;
2007-07-28 09:23:32 +00:00
$this -> tree [ $this -> level ] = $tagName ;
2004-10-29 17:07:11 +00:00
//Output something to avoid browser timeouts...
backup_flush ();
//Check if we are into BLOCKS zone
//if ($this->tree[3] == "BLOCKS") //Debug
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
2007-11-15 05:00:44 +00:00
//If we are under a BLOCK tag under a BLOCKS zone, accumule it
if ( isset ( $this -> tree [ 4 ]) and isset ( $this -> tree [ 3 ])) { //
if ( $this -> tree [ 4 ] == " BLOCK " and $this -> tree [ 3 ] == " BLOCKS " ) {
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= " < " . $tagName . " > " ;
}
}
2004-10-29 17:07:11 +00:00
}
2003-05-24 00:27:45 +00:00
//This is the startTag handler we use where we are reading the sections zone (todo="SECTIONS")
function startElementSections ( $parser , $tagName , $attrs ) {
2007-07-28 09:23:32 +00:00
//Refresh properties
2003-05-24 00:27:45 +00:00
$this -> level ++ ;
2007-07-28 09:23:32 +00:00
$this -> tree [ $this -> level ] = $tagName ;
2003-05-24 00:27:45 +00:00
2003-06-12 17:38:36 +00:00
//Output something to avoid browser timeouts...
backup_flush ();
2003-05-24 00:27:45 +00:00
//Check if we are into SECTIONS zone
//if ($this->tree[3] == "SECTIONS") //Debug
2004-09-12 01:34:24 +00:00
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
2003-05-24 00:27:45 +00:00
}
2005-02-07 17:52:58 +00:00
2006-12-11 15:47:23 +00:00
//This is the startTag handler we use where we are reading the optional format data zone (todo="FORMATDATA")
function startElementFormatData ( $parser , $tagName , $attrs ) {
2007-07-28 09:23:32 +00:00
//Refresh properties
2006-12-11 15:47:23 +00:00
$this -> level ++ ;
2007-07-28 09:23:32 +00:00
$this -> tree [ $this -> level ] = $tagName ;
2006-12-11 15:47:23 +00:00
//Output something to avoid browser timeouts...
backup_flush ();
//Accumulate all the data inside this tag
if ( isset ( $this -> tree [ 3 ]) && $this -> tree [ 3 ] == " FORMATDATA " ) {
if ( ! isset ( $this -> temp )) {
$this -> temp = '' ;
}
$this -> temp .= " < " . $tagName . " > " ;
}
2007-07-28 09:23:32 +00:00
2006-12-11 15:47:23 +00:00
//Check if we are into FORMATDATA zone
//if ($this->tree[3] == "FORMATDATA") //Debug
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
}
2005-02-07 17:52:58 +00:00
//This is the startTag handler we use where we are reading the metacourse zone (todo="METACOURSE")
function startElementMetacourse ( $parser , $tagName , $attrs ) {
2007-07-28 09:23:32 +00:00
//Refresh properties
2005-02-07 17:52:58 +00:00
$this -> level ++ ;
2007-07-28 09:23:32 +00:00
$this -> tree [ $this -> level ] = $tagName ;
2005-02-07 17:52:58 +00:00
//Output something to avoid browser timeouts...
backup_flush ();
//Check if we are into METACOURSE zone
//if ($this->tree[3] == "METACOURSE") //Debug
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
}
2005-04-22 00:26:22 +00:00
//This is the startTag handler we use where we are reading the gradebook zone (todo="GRADEBOOK")
function startElementGradebook ( $parser , $tagName , $attrs ) {
//Refresh properties
$this -> level ++ ;
$this -> tree [ $this -> level ] = $tagName ;
//Output something to avoid browser timeouts...
backup_flush ();
//Check if we are into GRADEBOOK zone
//if ($this->tree[3] == "GRADEBOOK") //Debug
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
//If we are under a GRADE_PREFERENCE, GRADE_LETTER or GRADE_CATEGORY tag under a GRADEBOOK zone, accumule it
if ( isset ( $this -> tree [ 5 ]) and isset ( $this -> tree [ 3 ])) {
2007-10-24 07:41:45 +00:00
if (( $this -> tree [ 5 ] == " GRADE_ITEM " || $this -> tree [ 5 ] == " GRADE_CATEGORY " || $this -> tree [ 5 ] == " GRADE_LETTER " || $this -> tree [ 5 ] == " GRADE_OUTCOME " || $this -> tree [ 5 ] == " GRADE_OUTCOMES_COURSE " || $this -> tree [ 5 ] == " GRADE_CATEGORIES_HISTORY " || $this -> tree [ 5 ] == " GRADE_GRADES_HISTORY " || $this -> tree [ 5 ] == " GRADE_TEXT_HISTORY " || $this -> tree [ 5 ] == " GRADE_ITEM_HISTORY " || $this -> tree [ 5 ] == " GRADE_OUTCOME_HISTORY " ) && ( $this -> tree [ 3 ] == " GRADEBOOK " )) {
2007-08-09 21:50:59 +00:00
2005-04-22 00:26:22 +00:00
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= " < " . $tagName . " > " ;
}
}
}
2007-07-28 09:23:32 +00:00
2003-05-25 22:58:13 +00:00
//This is the startTag handler we use where we are reading the user zone (todo="USERS")
function startElementUsers ( $parser , $tagName , $attrs ) {
2007-07-28 09:23:32 +00:00
//Refresh properties
2003-05-25 22:58:13 +00:00
$this -> level ++ ;
2007-07-28 09:23:32 +00:00
$this -> tree [ $this -> level ] = $tagName ;
2003-06-12 17:38:36 +00:00
2007-07-28 09:23:32 +00:00
//Check if we are into USERS zone
2003-05-25 22:58:13 +00:00
//if ($this->tree[3] == "USERS") //Debug
2004-09-12 01:34:24 +00:00
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
2003-05-25 22:58:13 +00:00
}
2003-05-24 00:27:45 +00:00
2005-02-13 19:09:41 +00:00
//This is the startTag handler we use where we are reading the messages zone (todo="MESSAGES")
function startElementMessages ( $parser , $tagName , $attrs ) {
//Refresh properties
$this -> level ++ ;
$this -> tree [ $this -> level ] = $tagName ;
//Output something to avoid browser timeouts...
backup_flush ();
//Check if we are into MESSAGES zone
//if ($this->tree[3] == "MESSAGES") //Debug
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
//If we are under a MESSAGE tag under a MESSAGES zone, accumule it
if ( isset ( $this -> tree [ 4 ]) and isset ( $this -> tree [ 3 ])) {
if (( $this -> tree [ 4 ] == " MESSAGE " || $this -> tree [ 5 ] == " CONTACT " ) and ( $this -> tree [ 3 ] == " MESSAGES " )) {
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= " < " . $tagName . " > " ;
}
}
}
2003-06-28 23:18:37 +00:00
//This is the startTag handler we use where we are reading the questions zone (todo="QUESTIONS")
function startElementQuestions ( $parser , $tagName , $attrs ) {
//Refresh properties
$this -> level ++ ;
$this -> tree [ $this -> level ] = $tagName ;
2003-07-03 23:18:13 +00:00
//if ($tagName == "QUESTION_CATEGORY" && $this->tree[3] == "QUESTION_CATEGORIES") { //Debug
// echo "<P>QUESTION_CATEGORY: ".strftime ("%X",time()),"-"; //Debug
//} //Debug
2003-06-28 23:18:37 +00:00
//Output something to avoid browser timeouts...
backup_flush ();
//Check if we are into QUESTION_CATEGORIES zone
//if ($this->tree[3] == "QUESTION_CATEGORIES") //Debug
2004-09-12 01:34:24 +00:00
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
2003-06-28 23:18:37 +00:00
//If we are under a QUESTION_CATEGORY tag under a QUESTION_CATEGORIES zone, accumule it
2003-08-25 01:44:01 +00:00
if ( isset ( $this -> tree [ 4 ]) and isset ( $this -> tree [ 3 ])) {
if (( $this -> tree [ 4 ] == " QUESTION_CATEGORY " ) and ( $this -> tree [ 3 ] == " QUESTION_CATEGORIES " )) {
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= " < " . $tagName . " > " ;
}
2003-06-28 23:18:37 +00:00
}
}
2003-08-18 00:00:22 +00:00
//This is the startTag handler we use where we are reading the scales zone (todo="SCALES")
function startElementScales ( $parser , $tagName , $attrs ) {
2007-07-28 09:23:32 +00:00
//Refresh properties
2003-08-18 00:00:22 +00:00
$this -> level ++ ;
$this -> tree [ $this -> level ] = $tagName ;
//if ($tagName == "SCALE" && $this->tree[3] == "SCALES") { //Debug
// echo "<P>SCALE: ".strftime ("%X",time()),"-"; //Debug
//} //Debug
//Output something to avoid browser timeouts...
backup_flush ();
//Check if we are into SCALES zone
//if ($this->tree[3] == "SCALES") //Debug
2004-09-12 01:34:24 +00:00
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
2003-08-18 00:00:22 +00:00
//If we are under a SCALE tag under a SCALES zone, accumule it
2003-08-25 01:44:01 +00:00
if ( isset ( $this -> tree [ 4 ]) and isset ( $this -> tree [ 3 ])) {
if (( $this -> tree [ 4 ] == " SCALE " ) and ( $this -> tree [ 3 ] == " SCALES " )) {
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= " < " . $tagName . " > " ;
}
2003-08-18 00:00:22 +00:00
}
}
2004-01-25 20:57:58 +00:00
function startElementGroups ( $parser , $tagName , $attrs ) {
//Refresh properties
$this -> level ++ ;
$this -> tree [ $this -> level ] = $tagName ;
//if ($tagName == "GROUP" && $this->tree[3] == "GROUPS") { //Debug
// echo "<P>GROUP: ".strftime ("%X",time()),"-"; //Debug
//} //Debug
//Output something to avoid browser timeouts...
backup_flush ();
//Check if we are into GROUPS zone
//if ($this->tree[3] == "GROUPS") //Debug
2004-09-12 01:34:24 +00:00
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
2004-01-25 20:57:58 +00:00
//If we are under a GROUP tag under a GROUPS zone, accumule it
if ( isset ( $this -> tree [ 4 ]) and isset ( $this -> tree [ 3 ])) {
if (( $this -> tree [ 4 ] == " GROUP " ) and ( $this -> tree [ 3 ] == " GROUPS " )) {
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= " < " . $tagName . " > " ;
}
}
}
2007-07-28 09:23:32 +00:00
2007-08-14 20:35:04 +00:00
function startElementGroupings ( $parser , $tagName , $attrs ) {
2007-01-20 09:28:26 +00:00
//Refresh properties
$this -> level ++ ;
$this -> tree [ $this -> level ] = $tagName ;
//if ($tagName == "GROUPING" && $this->tree[3] == "GROUPINGS") { //Debug
// echo "<P>GROUPING: ".strftime ("%X",time()),"-"; //Debug
//} //Debug
//Output something to avoid browser timeouts...
backup_flush ();
//Check if we are into GROUPINGS zone
//if ($this->tree[3] == "GROUPINGS") //Debug
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
//If we are under a GROUPING tag under a GROUPINGS zone, accumule it
if ( isset ( $this -> tree [ 4 ]) and isset ( $this -> tree [ 3 ])) {
if (( $this -> tree [ 4 ] == " GROUPING " ) and ( $this -> tree [ 3 ] == " GROUPINGS " )) {
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= " < " . $tagName . " > " ;
}
}
}
2004-01-25 20:57:58 +00:00
2007-08-14 20:35:04 +00:00
function startElementGroupingsGroups ( $parser , $tagName , $attrs ) {
//Refresh properties
$this -> level ++ ;
$this -> tree [ $this -> level ] = $tagName ;
//if ($tagName == "GROUPINGGROUP" && $this->tree[3] == "GROUPINGSGROUPS") { //Debug
// echo "<P>GROUPINGSGROUP: ".strftime ("%X",time()),"-"; //Debug
//} //Debug
//Output something to avoid browser timeouts...
backup_flush ();
//Check if we are into GROUPINGSGROUPS zone
//if ($this->tree[3] == "GROUPINGSGROUPS") //Debug
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
//If we are under a GROUPINGGROUP tag under a GROUPINGSGROUPS zone, accumule it
if ( isset ( $this -> tree [ 4 ]) and isset ( $this -> tree [ 3 ])) {
if (( $this -> tree [ 4 ] == " GROUPINGGROUP " ) and ( $this -> tree [ 3 ] == " GROUPINGSGROUPS " )) {
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= " < " . $tagName . " > " ;
}
}
}
2004-02-21 01:30:22 +00:00
//This is the startTag handler we use where we are reading the events zone (todo="EVENTS")
function startElementEvents ( $parser , $tagName , $attrs ) {
//Refresh properties
$this -> level ++ ;
$this -> tree [ $this -> level ] = $tagName ;
//if ($tagName == "EVENT" && $this->tree[3] == "EVENTS") { //Debug
// echo "<P>EVENT: ".strftime ("%X",time()),"-"; //Debug
//} //Debug
//Output something to avoid browser timeouts...
backup_flush ();
//Check if we are into EVENTS zone
//if ($this->tree[3] == "EVENTS") //Debug
2004-09-12 01:34:24 +00:00
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
2004-02-21 01:30:22 +00:00
//If we are under a EVENT tag under a EVENTS zone, accumule it
if ( isset ( $this -> tree [ 4 ]) and isset ( $this -> tree [ 3 ])) {
if (( $this -> tree [ 4 ] == " EVENT " ) and ( $this -> tree [ 3 ] == " EVENTS " )) {
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= " < " . $tagName . " > " ;
}
}
}
2003-05-30 21:32:04 +00:00
//This is the startTag handler we use where we are reading the modules zone (todo="MODULES")
function startElementModules ( $parser , $tagName , $attrs ) {
//Refresh properties
$this -> level ++ ;
$this -> tree [ $this -> level ] = $tagName ;
2003-06-12 17:38:36 +00:00
2003-07-07 19:20:52 +00:00
//if ($tagName == "MOD" && $this->tree[3] == "MODULES") { //Debug
// echo "<P>MOD: ".strftime ("%X",time()),"-"; //Debug
//} //Debug
2003-06-20 19:42:20 +00:00
2003-06-12 17:38:36 +00:00
//Output something to avoid browser timeouts...
backup_flush ();
2003-05-30 21:32:04 +00:00
//Check if we are into MODULES zone
//if ($this->tree[3] == "MODULES") //Debug
2004-09-12 01:34:24 +00:00
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
2003-06-12 17:38:36 +00:00
2003-05-30 21:32:04 +00:00
//If we are under a MOD tag under a MODULES zone, accumule it
2003-08-25 01:44:01 +00:00
if ( isset ( $this -> tree [ 4 ]) and isset ( $this -> tree [ 3 ])) {
if (( $this -> tree [ 4 ] == " MOD " ) and ( $this -> tree [ 3 ] == " MODULES " )) {
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= " < " . $tagName . " > " ;
}
2003-05-30 21:32:04 +00:00
}
}
2004-02-13 23:28:45 +00:00
//This is the startTag handler we use where we are reading the logs zone (todo="LOGS")
function startElementLogs ( $parser , $tagName , $attrs ) {
//Refresh properties
$this -> level ++ ;
$this -> tree [ $this -> level ] = $tagName ;
//if ($tagName == "LOG" && $this->tree[3] == "LOGS") { //Debug
// echo "<P>LOG: ".strftime ("%X",time()),"-"; //Debug
//} //Debug
//Output something to avoid browser timeouts...
backup_flush ();
//Check if we are into LOGS zone
//if ($this->tree[3] == "LOGS") //Debug
2004-09-12 01:34:24 +00:00
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br />\n"; //Debug
2004-02-13 23:28:45 +00:00
//If we are under a LOG tag under a LOGS zone, accumule it
if ( isset ( $this -> tree [ 4 ]) and isset ( $this -> tree [ 3 ])) {
if (( $this -> tree [ 4 ] == " LOG " ) and ( $this -> tree [ 3 ] == " LOGS " )) {
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= " < " . $tagName . " > " ;
}
}
}
2003-05-17 11:40:27 +00:00
//This is the startTag default handler we use when todo is undefined
2003-05-16 23:57:35 +00:00
function startElement ( $parser , $tagName , $attrs ) {
$this -> level ++ ;
2003-05-17 08:56:53 +00:00
$this -> tree [ $this -> level ] = $tagName ;
2003-06-12 17:38:36 +00:00
//Output something to avoid browser timeouts...
backup_flush ();
2004-09-12 01:34:24 +00:00
echo $this -> level . str_repeat ( " " , $this -> level * 2 ) . " < " . $tagName . " ><br /> \n " ; //Debug
2003-05-16 23:57:35 +00:00
}
2007-07-28 09:23:32 +00:00
2003-05-17 11:40:27 +00:00
//This is the endTag handler we use where we are reading the info zone (todo="INFO")
function endElementInfo ( $parser , $tagName ) {
//Check if we are into INFO zone
if ( $this -> tree [ 2 ] == " INFO " ) {
//if (trim($this->content)) //Debug
2004-09-12 01:34:24 +00:00
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n"; //Debug
2003-05-17 11:40:27 +00:00
//Dependig of different combinations, do different things
if ( $this -> level == 3 ) {
switch ( $tagName ) {
case " NAME " :
2003-05-17 17:34:30 +00:00
$this -> info -> backup_name = $this -> getContents ();
2003-05-17 11:40:27 +00:00
break ;
case " MOODLE_VERSION " :
2003-05-17 17:34:30 +00:00
$this -> info -> backup_moodle_version = $this -> getContents ();
2003-05-17 11:40:27 +00:00
break ;
case " MOODLE_RELEASE " :
2003-05-17 17:34:30 +00:00
$this -> info -> backup_moodle_release = $this -> getContents ();
2003-05-17 11:40:27 +00:00
break ;
case " BACKUP_VERSION " :
2003-05-17 17:34:30 +00:00
$this -> info -> backup_backup_version = $this -> getContents ();
2003-05-17 11:40:27 +00:00
break ;
case " BACKUP_RELEASE " :
2003-05-17 17:34:30 +00:00
$this -> info -> backup_backup_release = $this -> getContents ();
2003-05-17 11:40:27 +00:00
break ;
case " DATE " :
2003-05-17 17:34:30 +00:00
$this -> info -> backup_date = $this -> getContents ();
2003-05-17 11:40:27 +00:00
break ;
2004-05-06 23:20:25 +00:00
case " ORIGINAL_WWWROOT " :
$this -> info -> original_wwwroot = $this -> getContents ();
break ;
2007-01-16 03:28:57 +00:00
case " MNET_EXTERNALUSERS " :
$this -> info -> mnet_externalusers = $this -> getContents ();
break ;
2003-05-17 11:40:27 +00:00
}
}
if ( $this -> tree [ 3 ] == " DETAILS " ) {
if ( $this -> level == 4 ) {
switch ( $tagName ) {
2005-02-07 17:52:58 +00:00
case " METACOURSE " :
$this -> info -> backup_metacourse = $this -> getContents ();
break ;
2003-05-17 11:40:27 +00:00
case " USERS " :
2003-05-17 17:34:30 +00:00
$this -> info -> backup_users = $this -> getContents ();
2003-05-17 11:40:27 +00:00
break ;
case " LOGS " :
2003-05-17 17:34:30 +00:00
$this -> info -> backup_logs = $this -> getContents ();
2003-05-17 11:40:27 +00:00
break ;
case " USERFILES " :
2003-05-17 17:34:30 +00:00
$this -> info -> backup_user_files = $this -> getContents ();
2003-05-17 11:40:27 +00:00
break ;
case " COURSEFILES " :
2003-05-17 17:34:30 +00:00
$this -> info -> backup_course_files = $this -> getContents ();
2003-05-17 11:40:27 +00:00
break ;
2007-08-09 21:50:59 +00:00
case " SITEFILES " :
$this -> info -> backup_site_files = $this -> getContents ();
break ;
2005-02-13 19:09:41 +00:00
case " MESSAGES " :
$this -> info -> backup_messages = $this -> getContents ();
break ;
2004-10-29 17:07:11 +00:00
case 'BLOCKFORMAT' :
$this -> info -> backup_block_format = $this -> getContents ();
break ;
2003-05-17 11:40:27 +00:00
}
}
if ( $this -> level == 5 ) {
switch ( $tagName ) {
case " NAME " :
2003-05-17 17:34:30 +00:00
$this -> info -> tempName = $this -> getContents ();
2003-05-17 11:40:27 +00:00
break ;
case " INCLUDED " :
2003-05-17 17:34:30 +00:00
$this -> info -> mods [ $this -> info -> tempName ] -> backup = $this -> getContents ();
break ;
case " USERINFO " :
$this -> info -> mods [ $this -> info -> tempName ] -> userinfo = $this -> getContents ();
2003-05-17 11:40:27 +00:00
break ;
}
}
2006-01-13 03:45:31 +00:00
if ( $this -> level == 7 ) {
switch ( $tagName ) {
case " ID " :
$this -> info -> tempId = $this -> getContents ();
$this -> info -> mods [ $this -> info -> tempName ] -> instances [ $this -> info -> tempId ] -> id = $this -> info -> tempId ;
break ;
case " NAME " :
$this -> info -> mods [ $this -> info -> tempName ] -> instances [ $this -> info -> tempId ] -> name = $this -> getContents ();
break ;
case " INCLUDED " :
$this -> info -> mods [ $this -> info -> tempName ] -> instances [ $this -> info -> tempId ] -> backup = $this -> getContents ();
break ;
case " USERINFO " :
$this -> info -> mods [ $this -> info -> tempName ] -> instances [ $this -> info -> tempId ] -> userinfo = $this -> getContents ();
break ;
}
}
2003-05-17 11:40:27 +00:00
}
2003-05-17 17:34:30 +00:00
}
2003-05-17 11:40:27 +00:00
2005-04-22 00:26:22 +00:00
//Stop parsing if todo = INFO and tagName = INFO (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $tagName == " INFO " ) {
$this -> finished = true ;
}
2003-05-16 23:57:35 +00:00
2003-05-17 17:34:30 +00:00
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
2003-05-17 11:40:27 +00:00
2007-07-28 09:23:32 +00:00
}
2006-09-25 09:10:19 +00:00
function endElementRoles ( $parser , $tagName ) {
//Check if we are into INFO zone
if ( $this -> tree [ 2 ] == " ROLES " ) {
if ( $this -> tree [ 3 ] == " ROLE " ) {
if ( $this -> level == 4 ) {
switch ( $tagName ) {
case " NAME " :
$this -> info -> tempname = $this -> getContents ();
2007-07-28 09:23:32 +00:00
2006-09-25 09:10:19 +00:00
break ;
case " SHORTNAME " :
$this -> info -> tempshortname = $this -> getContents ();
break ;
2006-09-26 06:02:10 +00:00
case " ID " : // this is the old id
$this -> info -> tempid = $this -> getContents ();
break ;
2006-09-25 09:10:19 +00:00
}
}
if ( $this -> level == 6 ) {
switch ( $tagName ) {
case " NAME " :
2006-09-26 06:02:10 +00:00
$this -> info -> roles [ $this -> info -> tempid ] -> name = $this -> info -> tempname ;
$this -> info -> roles [ $this -> info -> tempid ] -> shortname = $this -> info -> tempshortname ;
2007-07-28 09:23:32 +00:00
2006-09-25 09:10:19 +00:00
$this -> info -> tempcapname = $this -> getContents ();
2006-09-26 06:02:10 +00:00
$this -> info -> roles [ $this -> info -> tempid ] -> capabilities [ $this -> info -> tempcapname ] -> name = $this -> getContents ();
2006-09-25 09:10:19 +00:00
break ;
case " PERMISSION " :
2006-09-26 06:02:10 +00:00
$this -> info -> roles [ $this -> info -> tempid ] -> capabilities [ $this -> info -> tempcapname ] -> permission = $this -> getContents ();
2006-09-25 09:10:19 +00:00
break ;
case " TIMEMODIFIED " :
2006-09-26 06:02:10 +00:00
$this -> info -> roles [ $this -> info -> tempid ] -> capabilities [ $this -> info -> tempcapname ] -> timemodified = $this -> getContents ();
2006-09-25 09:10:19 +00:00
break ;
case " MODIFIERID " :
2006-09-26 06:02:10 +00:00
$this -> info -> roles [ $this -> info -> tempid ] -> capabilities [ $this -> info -> tempcapname ] -> modifierid = $this -> getContents ();
2006-09-25 09:10:19 +00:00
break ;
}
}
}
}
//Stop parsing if todo = INFO and tagName = INFO (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $tagName == " ROLES " ) {
$this -> finished = true ;
}
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
2006-10-05 04:05:07 +00:00
}
2003-05-17 11:40:27 +00:00
2003-05-17 17:34:30 +00:00
//This is the endTag handler we use where we are reading the course_header zone (todo="COURSE_HEADER")
function endElementCourseHeader ( $parser , $tagName ) {
//Check if we are into COURSE_HEADER zone
if ( $this -> tree [ 3 ] == " HEADER " ) {
//if (trim($this->content)) //Debug
2004-09-12 01:34:24 +00:00
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n"; //Debug
2003-05-17 17:34:30 +00:00
//Dependig of different combinations, do different things
if ( $this -> level == 4 ) {
switch ( $tagName ) {
case " ID " :
$this -> info -> course_id = $this -> getContents ();
break ;
case " PASSWORD " :
$this -> info -> course_password = $this -> getContents ();
break ;
case " FULLNAME " :
$this -> info -> course_fullname = $this -> getContents ();
break ;
case " SHORTNAME " :
$this -> info -> course_shortname = $this -> getContents ();
break ;
2004-06-24 22:41:00 +00:00
case " IDNUMBER " :
$this -> info -> course_idnumber = $this -> getContents ();
break ;
2003-05-17 17:34:30 +00:00
case " SUMMARY " :
$this -> info -> course_summary = $this -> getContents ();
break ;
case " FORMAT " :
$this -> info -> course_format = $this -> getContents ();
break ;
2003-08-20 07:32:24 +00:00
case " SHOWGRADES " :
$this -> info -> course_showgrades = $this -> getContents ();
break ;
2004-04-20 23:28:46 +00:00
case " BLOCKINFO " :
$this -> info -> blockinfo = $this -> getContents ();
break ;
2003-05-17 17:34:30 +00:00
case " NEWSITEMS " :
$this -> info -> course_newsitems = $this -> getContents ();
break ;
case " TEACHER " :
$this -> info -> course_teacher = $this -> getContents ();
break ;
case " TEACHERS " :
$this -> info -> course_teachers = $this -> getContents ();
break ;
case " STUDENT " :
$this -> info -> course_student = $this -> getContents ();
break ;
case " STUDENTS " :
$this -> info -> course_students = $this -> getContents ();
break ;
case " GUEST " :
$this -> info -> course_guest = $this -> getContents ();
break ;
2003-07-27 21:29:22 +00:00
case " STARTDATE " :
$this -> info -> course_startdate = $this -> getContents ();
2003-05-17 17:34:30 +00:00
break ;
case " NUMSECTIONS " :
$this -> info -> course_numsections = $this -> getContents ();
break ;
2004-05-07 22:39:37 +00:00
//case "SHOWRECENT": INFO: This is out in 1.3
// $this->info->course_showrecent = $this->getContents();
// break;
2003-10-07 11:58:56 +00:00
case " MAXBYTES " :
$this -> info -> course_maxbytes = $this -> getContents ();
break ;
2003-10-31 05:57:30 +00:00
case " SHOWREPORTS " :
$this -> info -> course_showreports = $this -> getContents ();
break ;
2004-01-05 00:57:23 +00:00
case " GROUPMODE " :
$this -> info -> course_groupmode = $this -> getContents ();
break ;
case " GROUPMODEFORCE " :
$this -> info -> course_groupmodeforce = $this -> getContents ();
break ;
2007-08-14 20:35:04 +00:00
case " DEFAULTGROUPINGID " :
$this -> info -> course_defaultgroupingid = $this -> getContents ();
break ;
2004-02-09 22:24:34 +00:00
case " LANG " :
$this -> info -> course_lang = $this -> getContents ();
break ;
2005-02-15 18:37:08 +00:00
case " THEME " :
$this -> info -> course_theme = $this -> getContents ();
break ;
2004-06-26 12:36:55 +00:00
case " COST " :
$this -> info -> course_cost = $this -> getContents ();
break ;
2005-07-22 17:19:52 +00:00
case " CURRENCY " :
$this -> info -> course_currency = $this -> getContents ();
break ;
2003-05-17 17:34:30 +00:00
case " MARKER " :
$this -> info -> course_marker = $this -> getContents ();
break ;
2003-07-21 07:35:58 +00:00
case " VISIBLE " :
$this -> info -> course_visible = $this -> getContents ();
break ;
2004-05-02 22:34:13 +00:00
case " HIDDENSECTIONS " :
$this -> info -> course_hiddensections = $this -> getContents ();
2004-04-27 16:37:53 +00:00
break ;
2003-05-17 17:34:30 +00:00
case " TIMECREATED " :
$this -> info -> course_timecreated = $this -> getContents ();
break ;
case " TIMEMODIFIED " :
$this -> info -> course_timemodified = $this -> getContents ();
break ;
2005-02-07 17:52:58 +00:00
case " METACOURSE " :
$this -> info -> course_metacourse = $this -> getContents ();
break ;
2007-07-16 20:18:26 +00:00
case " EXPIRENOTIFY " :
$this -> info -> course_expirynotify = $this -> getContents ();
break ;
case " NOTIFYSTUDENTS " :
$this -> info -> course_notifystudents = $this -> getContents ();
break ;
case " EXPIRYTHRESHOLD " :
$this -> info -> course_expirythreshold = $this -> getContents ();
break ;
case " ENROLLABLE " :
$this -> info -> course_enrollable = $this -> getContents ();
break ;
case " ENROLSTARTDATE " :
$this -> info -> course_enrolstartdate = $this -> getContents ();
break ;
case " ENROLENDDATE " :
$this -> info -> course_enrolenddate = $this -> getContents ();
break ;
case " ENROLPERIOD " :
$this -> info -> course_enrolperiod = $this -> getContents ();
break ;
2003-05-17 17:34:30 +00:00
}
}
if ( $this -> tree [ 4 ] == " CATEGORY " ) {
if ( $this -> level == 5 ) {
switch ( $tagName ) {
case " ID " :
$this -> info -> category -> id = $this -> getContents ();
break ;
case " NAME " :
$this -> info -> category -> name = $this -> getContents ();
break ;
}
}
}
2007-07-28 09:23:32 +00:00
2006-09-26 01:43:07 +00:00
if ( $this -> tree [ 4 ] == " ROLES_ASSIGNMENTS " ) {
if ( $this -> level == 6 ) {
switch ( $tagName ) {
case " NAME " :
$this -> info -> tempname = $this -> getContents ();
break ;
case " SHORTNAME " :
$this -> info -> tempshortname = $this -> getContents ();
break ;
2006-09-26 06:02:10 +00:00
case " ID " :
$this -> info -> tempid = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
}
2006-09-26 01:43:07 +00:00
}
2007-07-28 09:23:32 +00:00
2006-09-26 01:43:07 +00:00
if ( $this -> level == 8 ) {
switch ( $tagName ) {
case " USERID " :
2006-09-26 06:02:10 +00:00
$this -> info -> roleassignments [ $this -> info -> tempid ] -> name = $this -> info -> tempname ;
$this -> info -> roleassignments [ $this -> info -> tempid ] -> shortname = $this -> info -> tempshortname ;
2006-09-26 01:50:17 +00:00
$this -> info -> tempuser = $this -> getContents ();
2006-09-26 06:02:10 +00:00
$this -> info -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> userid = $this -> getContents ();
2006-09-26 01:43:07 +00:00
break ;
case " HIDDEN " :
2006-09-26 06:02:10 +00:00
$this -> info -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> hidden = $this -> getContents ();
2006-09-26 01:43:07 +00:00
break ;
case " TIMESTART " :
2006-09-26 06:02:10 +00:00
$this -> info -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> timestart = $this -> getContents ();
2006-09-26 01:43:07 +00:00
break ;
case " TIMEEND " :
2006-09-26 06:02:10 +00:00
$this -> info -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> timeend = $this -> getContents ();
2006-09-26 01:43:07 +00:00
break ;
case " TIMEMODIFIED " :
2006-09-26 06:02:10 +00:00
$this -> info -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> timemodified = $this -> getContents ();
2006-09-26 01:43:07 +00:00
break ;
case " MODIFIERID " :
2006-09-26 06:02:10 +00:00
$this -> info -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> modifierid = $this -> getContents ();
2006-09-26 01:43:07 +00:00
break ;
case " ENROL " :
2006-09-26 06:02:10 +00:00
$this -> info -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> enrol = $this -> getContents ();
2006-09-26 01:43:07 +00:00
break ;
case " SORTORDER " :
2006-09-26 06:02:10 +00:00
$this -> info -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> sortorder = $this -> getContents ();
2006-09-26 01:43:07 +00:00
break ;
2007-07-28 09:23:32 +00:00
2006-09-26 01:43:07 +00:00
}
}
} /// ends role_assignments
2007-07-28 09:23:32 +00:00
2006-09-26 01:43:07 +00:00
if ( $this -> tree [ 4 ] == " ROLES_OVERRIDES " ) {
if ( $this -> level == 6 ) {
switch ( $tagName ) {
case " NAME " :
$this -> info -> tempname = $this -> getContents ();
break ;
case " SHORTNAME " :
$this -> info -> tempshortname = $this -> getContents ();
2007-07-28 09:23:32 +00:00
break ;
2006-09-26 06:02:10 +00:00
case " ID " :
$this -> info -> tempid = $this -> getContents ();
2006-09-26 01:43:07 +00:00
break ;
2007-07-28 09:23:32 +00:00
}
2006-09-26 01:43:07 +00:00
}
2007-07-28 09:23:32 +00:00
2006-09-26 01:43:07 +00:00
if ( $this -> level == 8 ) {
switch ( $tagName ) {
case " NAME " :
2006-09-26 06:02:10 +00:00
$this -> info -> roleoverrides [ $this -> info -> tempid ] -> name = $this -> info -> tempname ;
$this -> info -> roleoverrides [ $this -> info -> tempid ] -> shortname = $this -> info -> tempshortname ;
2006-09-26 01:50:17 +00:00
$this -> info -> tempname = $this -> getContents (); // change to name of capability
2006-09-26 06:02:10 +00:00
$this -> info -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> name = $this -> getContents ();
2006-09-26 01:43:07 +00:00
break ;
case " PERMISSION " :
2006-09-26 06:02:10 +00:00
$this -> info -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> permission = $this -> getContents ();
2006-09-26 01:43:07 +00:00
break ;
case " TIMEMODIFIED " :
2006-09-26 06:02:10 +00:00
$this -> info -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> timemodified = $this -> getContents ();
2006-09-26 01:43:07 +00:00
break ;
case " MODIFIERID " :
2006-09-26 06:02:10 +00:00
$this -> info -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> modifierid = $this -> getContents ();
2006-09-26 01:43:07 +00:00
break ;
}
}
2007-07-28 09:23:32 +00:00
} /// ends role_overrides
2003-05-17 17:34:30 +00:00
}
//Stop parsing if todo = COURSE_HEADER and tagName = HEADER (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $tagName == " HEADER " ) {
$this -> finished = true ;
}
2005-04-22 00:26:22 +00:00
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
2003-05-17 17:34:30 +00:00
}
2005-04-22 00:26:22 +00:00
//This is the endTag handler we use where we are reading the sections zone (todo="BLOCKS")
2004-10-29 17:07:11 +00:00
function endElementBlocks ( $parser , $tagName ) {
//Check if we are into BLOCKS zone
if ( $this -> tree [ 3 ] == 'BLOCKS' ) {
//if (trim($this->content)) //Debug
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n"; //Debug
2007-11-15 05:00:44 +00:00
// Collect everything into $this->temp
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= htmlspecialchars ( trim ( $this -> content )) . " </ " . $tagName . " > " ;
2004-10-29 17:07:11 +00:00
//Dependig of different combinations, do different things
if ( $this -> level == 4 ) {
switch ( $tagName ) {
case 'BLOCK' :
//We've finalized a block, get it
$this -> info -> instances [] = $this -> info -> tempinstance ;
unset ( $this -> info -> tempinstance );
2007-11-15 05:00:44 +00:00
//Also, xmlize INSTANCEDATA and save to db
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one BLOCK)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
//echo strftime ("%X",time())."<p>"; //Debug
//traverse_xmlize($data); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Check for instancedata, is exists, then save to DB
if ( isset ( $data [ 'BLOCK' ][ '#' ][ 'INSTANCEDATA' ][ '0' ][ '#' ])) {
//Get old id
$oldid = $data [ 'BLOCK' ][ '#' ][ 'ID' ][ '0' ][ '#' ];
//Get instancedata
if ( $data = $data [ 'BLOCK' ][ '#' ][ 'INSTANCEDATA' ][ '0' ][ '#' ]) {
//Restore code calls this multiple times - so might already have the newid
if ( $newid = backup_getid ( $this -> preferences -> backup_unique_code , 'block_instance' , $oldid )) {
$newid = $newid -> new_id ;
} else {
$newid = null ;
}
//Save to DB, we will use it later
$status = backup_putid ( $this -> preferences -> backup_unique_code , 'block_instance' , $oldid , $newid , $data );
}
}
//Reset temp
unset ( $this -> temp );
2004-10-29 17:07:11 +00:00
break ;
default :
die ( $tagName );
}
}
if ( $this -> level == 5 ) {
switch ( $tagName ) {
2006-09-27 08:59:27 +00:00
case 'ID' :
$this -> info -> tempinstance -> id = $this -> getContents ();
2004-10-29 17:07:11 +00:00
case 'NAME' :
$this -> info -> tempinstance -> name = $this -> getContents ();
break ;
case 'PAGEID' :
$this -> info -> tempinstance -> pageid = $this -> getContents ();
break ;
case 'PAGETYPE' :
$this -> info -> tempinstance -> pagetype = $this -> getContents ();
break ;
case 'POSITION' :
$this -> info -> tempinstance -> position = $this -> getContents ();
break ;
case 'WEIGHT' :
$this -> info -> tempinstance -> weight = $this -> getContents ();
break ;
case 'VISIBLE' :
$this -> info -> tempinstance -> visible = $this -> getContents ();
break ;
case 'CONFIGDATA' :
$this -> info -> tempinstance -> configdata = $this -> getContents ();
break ;
2006-09-26 09:05:44 +00:00
default :
break ;
2004-10-29 17:07:11 +00:00
}
2007-07-28 09:23:32 +00:00
}
2006-09-27 08:59:27 +00:00
2006-09-26 09:05:44 +00:00
if ( $this -> tree [ 5 ] == " ROLES_ASSIGNMENTS " ) {
if ( $this -> level == 7 ) {
switch ( $tagName ) {
case " NAME " :
$this -> info -> tempname = $this -> getContents ();
break ;
case " SHORTNAME " :
$this -> info -> tempshortname = $this -> getContents ();
break ;
case " ID " :
$this -> info -> tempid = $this -> getContents (); // temp roleid
break ;
}
}
2007-07-28 09:23:32 +00:00
2006-09-26 09:05:44 +00:00
if ( $this -> level == 9 ) {
2006-09-27 08:59:27 +00:00
2006-09-26 09:05:44 +00:00
switch ( $tagName ) {
case " USERID " :
$this -> info -> tempinstance -> roleassignments [ $this -> info -> tempid ] -> name = $this -> info -> tempname ;
2007-07-28 09:23:32 +00:00
2006-09-26 09:05:44 +00:00
$this -> info -> tempinstance -> roleassignments [ $this -> info -> tempid ] -> shortname = $this -> info -> tempshortname ;
2007-07-28 09:23:32 +00:00
2006-09-26 09:05:44 +00:00
$this -> info -> tempuser = $this -> getContents ();
2007-07-28 09:23:32 +00:00
2006-09-26 09:05:44 +00:00
$this -> info -> tempinstance -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> userid = $this -> getContents ();
break ;
case " HIDDEN " :
$this -> info -> tempinstance -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> hidden = $this -> getContents ();
break ;
case " TIMESTART " :
$this -> info -> tempinstance -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> timestart = $this -> getContents ();
break ;
case " TIMEEND " :
$this -> info -> tempinstance -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> timeend = $this -> getContents ();
break ;
case " TIMEMODIFIED " :
$this -> info -> tempinstance -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> timemodified = $this -> getContents ();
break ;
case " MODIFIERID " :
$this -> info -> tempinstance -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> modifierid = $this -> getContents ();
break ;
case " ENROL " :
$this -> info -> tempinstance -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> enrol = $this -> getContents ();
break ;
case " SORTORDER " :
$this -> info -> tempinstance -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> sortorder = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
2006-09-26 09:05:44 +00:00
}
}
} /// ends role_assignments
2007-07-28 09:23:32 +00:00
2006-09-26 09:05:44 +00:00
if ( $this -> tree [ 5 ] == " ROLES_OVERRIDES " ) {
if ( $this -> level == 7 ) {
switch ( $tagName ) {
case " NAME " :
$this -> info -> tempname = $this -> getContents ();
break ;
case " SHORTNAME " :
$this -> info -> tempshortname = $this -> getContents ();
2007-07-28 09:23:32 +00:00
break ;
2006-09-26 09:05:44 +00:00
case " ID " :
$this -> info -> tempid = $this -> getContents (); // temp roleid
break ;
2007-07-28 09:23:32 +00:00
}
2006-09-26 09:05:44 +00:00
}
2007-07-28 09:23:32 +00:00
2006-09-26 09:05:44 +00:00
if ( $this -> level == 9 ) {
switch ( $tagName ) {
case " NAME " :
2007-07-28 09:23:32 +00:00
2006-09-26 09:05:44 +00:00
$this -> info -> tempinstance -> roleoverrides [ $this -> info -> tempid ] -> name = $this -> info -> tempname ;
$this -> info -> tempinstance -> roleoverrides [ $this -> info -> tempid ] -> shortname = $this -> info -> tempshortname ;
$this -> info -> tempname = $this -> getContents (); // change to name of capability
$this -> info -> tempinstance -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> name = $this -> getContents ();
break ;
case " PERMISSION " :
$this -> info -> tempinstance -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> permission = $this -> getContents ();
break ;
case " TIMEMODIFIED " :
$this -> info -> tempinstance -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> timemodified = $this -> getContents ();
break ;
case " MODIFIERID " :
$this -> info -> tempinstance -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> modifierid = $this -> getContents ();
break ;
}
}
2007-07-28 09:23:32 +00:00
} /// ends role_overrides
2004-10-29 17:07:11 +00:00
}
2007-07-28 09:23:32 +00:00
2004-10-29 17:07:11 +00:00
//Stop parsing if todo = BLOCKS and tagName = BLOCKS (en of the tag, of course)
//Speed up a lot (avoid parse all)
//WARNING: ONLY EXIT IF todo = BLOCKS (thus tree[3] = "BLOCKS") OTHERWISE
// THE BLOCKS TAG IN THE HEADER WILL TERMINATE US!
if ( $this -> tree [ 3 ] == 'BLOCKS' && $tagName == 'BLOCKS' ) {
$this -> finished = true ;
}
2005-04-22 00:26:22 +00:00
//Clear things
$this -> tree [ $this -> level ] = '' ;
$this -> level -- ;
$this -> content = " " ;
2004-10-29 17:07:11 +00:00
}
2003-05-24 00:27:45 +00:00
//This is the endTag handler we use where we are reading the sections zone (todo="SECTIONS")
function endElementSections ( $parser , $tagName ) {
//Check if we are into SECTIONS zone
if ( $this -> tree [ 3 ] == " SECTIONS " ) {
//if (trim($this->content)) //Debug
2004-09-12 01:34:24 +00:00
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n"; //Debug
2003-05-24 00:27:45 +00:00
//Dependig of different combinations, do different things
if ( $this -> level == 4 ) {
switch ( $tagName ) {
case " SECTION " :
//We've finalized a section, get it
2003-08-25 01:44:01 +00:00
$this -> info -> sections [ $this -> info -> tempsection -> id ] = $this -> info -> tempsection ;
2003-05-24 00:27:45 +00:00
unset ( $this -> info -> tempsection );
}
}
if ( $this -> level == 5 ) {
switch ( $tagName ) {
case " ID " :
$this -> info -> tempsection -> id = $this -> getContents ();
break ;
case " NUMBER " :
$this -> info -> tempsection -> number = $this -> getContents ();
break ;
case " SUMMARY " :
$this -> info -> tempsection -> summary = $this -> getContents ();
break ;
case " VISIBLE " :
$this -> info -> tempsection -> visible = $this -> getContents ();
break ;
}
}
if ( $this -> level == 6 ) {
switch ( $tagName ) {
case " MOD " :
2007-08-15 10:43:25 +00:00
if ( ! isset ( $this -> info -> tempmod -> groupmode )) {
2007-08-14 20:35:04 +00:00
$this -> info -> tempmod -> groupmode = 0 ;
}
2007-08-15 10:43:25 +00:00
if ( ! isset ( $this -> info -> tempmod -> groupingid )) {
2007-08-14 20:35:04 +00:00
$this -> info -> tempmod -> groupingid = 0 ;
}
2007-08-15 10:43:25 +00:00
if ( ! isset ( $this -> info -> tempmod -> groupmembersonly )) {
2007-08-14 20:35:04 +00:00
$this -> info -> tempmod -> groupmembersonly = 0 ;
}
2003-05-25 22:58:13 +00:00
//We've finalized a mod, get it
2007-07-28 09:23:32 +00:00
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> type =
2003-05-24 00:27:45 +00:00
$this -> info -> tempmod -> type ;
2007-07-28 09:23:32 +00:00
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> instance =
2003-05-24 00:27:45 +00:00
$this -> info -> tempmod -> instance ;
2007-07-28 09:23:32 +00:00
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> added =
2003-05-24 00:27:45 +00:00
$this -> info -> tempmod -> added ;
2007-07-28 09:23:32 +00:00
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> score =
2003-05-24 00:27:45 +00:00
$this -> info -> tempmod -> score ;
2007-07-28 09:23:32 +00:00
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> indent =
2003-09-14 16:31:33 +00:00
$this -> info -> tempmod -> indent ;
2007-07-28 09:23:32 +00:00
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> visible =
2003-05-24 00:27:45 +00:00
$this -> info -> tempmod -> visible ;
2007-07-28 09:23:32 +00:00
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> groupmode =
2004-01-22 20:27:17 +00:00
$this -> info -> tempmod -> groupmode ;
2007-08-14 20:35:04 +00:00
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> groupingid =
$this -> info -> tempmod -> groupingid ;
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> groupmembersonly =
$this -> info -> tempmod -> groupmembersonly ;
2003-05-24 00:27:45 +00:00
unset ( $this -> info -> tempmod );
}
}
if ( $this -> level == 7 ) {
switch ( $tagName ) {
case " ID " :
$this -> info -> tempmod -> id = $this -> getContents ();
break ;
case " TYPE " :
$this -> info -> tempmod -> type = $this -> getContents ();
break ;
case " INSTANCE " :
$this -> info -> tempmod -> instance = $this -> getContents ();
break ;
case " ADDED " :
$this -> info -> tempmod -> added = $this -> getContents ();
break ;
case " SCORE " :
$this -> info -> tempmod -> score = $this -> getContents ();
break ;
2003-09-14 16:31:33 +00:00
case " INDENT " :
$this -> info -> tempmod -> indent = $this -> getContents ();
break ;
2003-05-24 00:27:45 +00:00
case " VISIBLE " :
$this -> info -> tempmod -> visible = $this -> getContents ();
break ;
2004-01-22 20:27:17 +00:00
case " GROUPMODE " :
$this -> info -> tempmod -> groupmode = $this -> getContents ();
break ;
2007-08-14 00:50:00 +00:00
case " GROUPINGID " :
$this -> info -> tempmod -> groupingid = $this -> getContents ();
break ;
case " GROUPMEMBERSONLY " :
$this -> info -> tempmod -> groupmembersonly = $this -> getContents ();
break ;
2006-09-26 06:02:10 +00:00
default :
2007-08-14 00:50:00 +00:00
break ;
2003-05-24 00:27:45 +00:00
}
}
2007-07-28 09:23:32 +00:00
2006-10-04 09:01:50 +00:00
if ( isset ( $this -> tree [ 7 ]) && $this -> tree [ 7 ] == " ROLES_ASSIGNMENTS " ) {
2007-07-28 09:23:32 +00:00
2006-09-26 06:02:10 +00:00
if ( $this -> level == 9 ) {
switch ( $tagName ) {
case " NAME " :
$this -> info -> tempname = $this -> getContents ();
break ;
case " SHORTNAME " :
$this -> info -> tempshortname = $this -> getContents ();
break ;
case " ID " :
$this -> info -> tempid = $this -> getContents (); // temp roleid
break ;
2007-07-28 09:23:32 +00:00
}
2003-05-24 00:27:45 +00:00
2006-09-26 06:02:10 +00:00
}
if ( $this -> level == 11 ) {
switch ( $tagName ) {
case " USERID " :
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleassignments [ $this -> info -> tempid ] -> name = $this -> info -> tempname ;
2007-07-28 09:23:32 +00:00
2006-09-26 06:02:10 +00:00
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleassignments [ $this -> info -> tempid ] -> shortname = $this -> info -> tempshortname ;
2007-07-28 09:23:32 +00:00
2006-09-26 06:02:10 +00:00
$this -> info -> tempuser = $this -> getContents ();
2007-07-28 09:23:32 +00:00
2006-09-26 06:02:10 +00:00
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> userid = $this -> getContents ();
break ;
case " HIDDEN " :
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> hidden = $this -> getContents ();
break ;
case " TIMESTART " :
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> timestart = $this -> getContents ();
break ;
case " TIMEEND " :
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> timeend = $this -> getContents ();
break ;
case " TIMEMODIFIED " :
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> timemodified = $this -> getContents ();
break ;
case " MODIFIERID " :
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> modifierid = $this -> getContents ();
break ;
case " ENROL " :
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> enrol = $this -> getContents ();
break ;
case " SORTORDER " :
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuser ] -> sortorder = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
2006-09-26 06:02:10 +00:00
}
}
} /// ends role_assignments
2007-07-28 09:23:32 +00:00
2006-10-04 09:01:50 +00:00
if ( isset ( $this -> tree [ 7 ]) && $this -> tree [ 7 ] == " ROLES_OVERRIDES " ) {
2006-09-26 06:02:10 +00:00
if ( $this -> level == 9 ) {
switch ( $tagName ) {
case " NAME " :
$this -> info -> tempname = $this -> getContents ();
break ;
case " SHORTNAME " :
$this -> info -> tempshortname = $this -> getContents ();
2007-07-28 09:23:32 +00:00
break ;
2006-09-26 06:02:10 +00:00
case " ID " :
$this -> info -> tempid = $this -> getContents (); // temp roleid
break ;
2007-07-28 09:23:32 +00:00
}
2006-09-26 06:02:10 +00:00
}
2007-07-28 09:23:32 +00:00
2006-09-26 06:02:10 +00:00
if ( $this -> level == 11 ) {
switch ( $tagName ) {
case " NAME " :
2007-07-28 09:23:32 +00:00
2006-09-26 06:02:10 +00:00
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleoverrides [ $this -> info -> tempid ] -> name = $this -> info -> tempname ;
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleoverrides [ $this -> info -> tempid ] -> shortname = $this -> info -> tempshortname ;
$this -> info -> tempname = $this -> getContents (); // change to name of capability
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> name = $this -> getContents ();
break ;
case " PERMISSION " :
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> permission = $this -> getContents ();
break ;
case " TIMEMODIFIED " :
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> timemodified = $this -> getContents ();
break ;
case " MODIFIERID " :
$this -> info -> tempsection -> mods [ $this -> info -> tempmod -> id ] -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> modifierid = $this -> getContents ();
break ;
}
}
2007-07-28 09:23:32 +00:00
} /// ends role_overrides
2006-09-26 06:02:10 +00:00
}
2007-07-28 09:23:32 +00:00
2003-05-24 00:27:45 +00:00
//Stop parsing if todo = SECTIONS and tagName = SECTIONS (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $tagName == " SECTIONS " ) {
$this -> finished = true ;
}
2005-04-22 00:26:22 +00:00
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
2003-05-24 00:27:45 +00:00
}
2005-02-07 17:52:58 +00:00
2006-12-11 15:47:23 +00:00
//This is the endTag handler we use where we are reading the optional format data zone (todo="FORMATDATA")
function endElementFormatData ( $parser , $tagName ) {
//Check if we are into FORMATDATA zone
if ( $this -> tree [ 3 ] == 'FORMATDATA' ) {
if ( ! isset ( $this -> temp )) {
$this -> temp = '' ;
}
2007-07-28 09:23:32 +00:00
$this -> temp .= htmlspecialchars ( trim ( $this -> content )) . " </ " . $tagName . " > " ;
2006-12-11 15:47:23 +00:00
}
if ( $tagName == 'FORMATDATA' ) {
//Did we have any data? If not don't bother
if ( $this -> temp != '<FORMATDATA></FORMATDATA>' ) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
$this -> temp = '' ;
2007-07-28 09:23:32 +00:00
2006-12-11 15:47:23 +00:00
//Call to xmlize for this portion of xml data (the FORMATDATA block)
$this -> info -> format_data = xmlize ( $xml_data , 0 );
2007-07-28 09:23:32 +00:00
}
2006-12-11 15:47:23 +00:00
//Stop parsing at end of FORMATDATA
$this -> finished = true ;
}
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
}
2005-02-07 17:52:58 +00:00
//This is the endTag handler we use where we are reading the metacourse zone (todo="METACOURSE")
function endElementMetacourse ( $parser , $tagName ) {
//Check if we are into METACOURSE zone
if ( $this -> tree [ 3 ] == 'METACOURSE' ) {
//if (trim($this->content)) //Debug
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n"; //Debug
//Dependig of different combinations, do different things
if ( $this -> level == 5 ) {
switch ( $tagName ) {
case 'CHILD' :
//We've finalized a child, get it
$this -> info -> childs [] = $this -> info -> tempmeta ;
unset ( $this -> info -> tempmeta );
break ;
case 'PARENT' :
//We've finalized a parent, get it
$this -> info -> parents [] = $this -> info -> tempmeta ;
unset ( $this -> info -> tempmeta );
break ;
default :
die ( $tagName );
}
}
if ( $this -> level == 6 ) {
switch ( $tagName ) {
case 'ID' :
$this -> info -> tempmeta -> id = $this -> getContents ();
break ;
case 'IDNUMBER' :
$this -> info -> tempmeta -> idnumber = $this -> getContents ();
break ;
case 'SHORTNAME' :
$this -> info -> tempmeta -> shortname = $this -> getContents ();
break ;
}
}
}
2005-04-22 00:26:22 +00:00
//Stop parsing if todo = METACOURSE and tagName = METACOURSE (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $this -> tree [ 3 ] == 'METACOURSE' && $tagName == 'METACOURSE' ) {
$this -> finished = true ;
}
2005-02-07 17:52:58 +00:00
//Clear things
$this -> tree [ $this -> level ] = '' ;
$this -> level -- ;
$this -> content = " " ;
2005-04-22 00:26:22 +00:00
}
2005-02-07 17:52:58 +00:00
2005-04-22 00:26:22 +00:00
//This is the endTag handler we use where we are reading the gradebook zone (todo="GRADEBOOK")
function endElementGradebook ( $parser , $tagName ) {
//Check if we are into GRADEBOOK zone
if ( $this -> tree [ 3 ] == " GRADEBOOK " ) {
//if (trim($this->content)) //Debug
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n";//Debug
//Acumulate data to info (content + close tag)
//Reconvert: strip htmlchars again and trim to generate xml data
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= htmlspecialchars ( trim ( $this -> content )) . " </ " . $tagName . " > " ;
2007-05-29 09:00:48 +00:00
// We have finished outcome, grade_category or grade_item, reset accumulated
// data because they are close tags
2005-04-22 00:26:22 +00:00
if ( $this -> level == 4 ) {
$this -> temp = " " ;
}
2007-08-01 05:55:36 +00:00
//If we've finished a grade item, xmlize it an save to db
2007-05-29 09:00:48 +00:00
if (( $this -> level == 5 ) and ( $tagName == " GRADE_ITEM " )) {
2005-04-22 00:26:22 +00:00
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one PREFERENCE)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
2007-05-29 09:00:48 +00:00
$item_id = $data [ " GRADE_ITEM " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
2005-04-22 00:26:22 +00:00
$this -> counter ++ ;
//Save to db
2007-07-28 09:23:32 +00:00
$status = backup_putid ( $this -> preferences -> backup_unique_code , 'grade_items' , $item_id ,
2005-04-22 00:26:22 +00:00
null , $data );
//Create returning info
$this -> info = $this -> counter ;
//Reset temp
2007-07-28 09:23:32 +00:00
2005-04-22 00:26:22 +00:00
unset ( $this -> temp );
}
2007-05-29 09:00:48 +00:00
//If we've finished a grade_category, xmlize it an save to db
if (( $this -> level == 5 ) and ( $tagName == " GRADE_CATEGORY " )) {
2005-04-22 00:26:22 +00:00
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
2007-05-29 09:00:48 +00:00
//Call to xmlize for this portion of xml data (one CATECORY)
2005-04-22 00:26:22 +00:00
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
2007-05-29 09:00:48 +00:00
$category_id = $data [ " GRADE_CATEGORY " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
2005-04-22 00:26:22 +00:00
$this -> counter ++ ;
//Save to db
2007-05-29 09:00:48 +00:00
$status = backup_putid ( $this -> preferences -> backup_unique_code , 'grade_categories' , $category_id ,
2005-04-22 00:26:22 +00:00
null , $data );
//Create returning info
$this -> info = $this -> counter ;
//Reset temp
unset ( $this -> temp );
}
2007-10-24 07:41:45 +00:00
if (( $this -> level == 5 ) and ( $tagName == " GRADE_LETTER " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one CATECORY)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
$letter_id = $data [ " GRADE_LETTER " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
$this -> counter ++ ;
//Save to db
$status = backup_putid ( $this -> preferences -> backup_unique_code , 'grade_letters' , $letter_id ,
null , $data );
//Create returning info
$this -> info = $this -> counter ;
//Reset temp
unset ( $this -> temp );
}
2007-07-28 09:23:32 +00:00
2007-08-01 05:55:36 +00:00
//If we've finished a grade_outcome, xmlize it an save to db
2007-05-29 09:00:48 +00:00
if (( $this -> level == 5 ) and ( $tagName == " GRADE_OUTCOME " )) {
2005-04-22 00:26:22 +00:00
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one CATECORY)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
2007-05-29 09:00:48 +00:00
$outcome_id = $data [ " GRADE_OUTCOME " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
2005-04-22 00:26:22 +00:00
$this -> counter ++ ;
//Save to db
2007-05-29 09:00:48 +00:00
$status = backup_putid ( $this -> preferences -> backup_unique_code , 'grade_outcomes' , $outcome_id ,
2005-04-22 00:26:22 +00:00
null , $data );
//Create returning info
$this -> info = $this -> counter ;
//Reset temp
unset ( $this -> temp );
}
2007-08-09 21:50:59 +00:00
2007-08-01 05:55:36 +00:00
//If we've finished a grade_outcomes_course, xmlize it an save to db
if (( $this -> level == 5 ) and ( $tagName == " GRADE_OUTCOMES_COURSE " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one CATECORY)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
$outcomes_course_id = $data [ " GRADE_OUTCOMES_COURSE " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
$this -> counter ++ ;
//Save to db
$status = backup_putid ( $this -> preferences -> backup_unique_code , 'grade_outcomes_courses' , $outcomes_course_id ,
null , $data );
//Create returning info
$this -> info = $this -> counter ;
//Reset temp
2007-08-08 08:42:28 +00:00
unset ( $this -> temp );
2007-08-09 21:50:59 +00:00
}
2007-08-08 08:42:28 +00:00
if (( $this -> level == 5 ) and ( $tagName == " GRADE_CATEGORIES_HISTORY " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one PREFERENCE)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
$id = $data [ " GRADE_CATEGORIES_HISTORY " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
$this -> counter ++ ;
//Save to db
$status = backup_putid ( $this -> preferences -> backup_unique_code , 'grade_categories_history' , $id ,
null , $data );
//Create returning info
$this -> info = $this -> counter ;
//Reset temp
unset ( $this -> temp );
}
2007-08-09 21:50:59 +00:00
2007-08-08 08:42:28 +00:00
if (( $this -> level == 5 ) and ( $tagName == " GRADE_GRADES_HISTORY " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one PREFERENCE)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
2007-08-09 08:58:15 +00:00
$id = $data [ " GRADE_GRADES_HISTORY " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
2007-08-08 08:42:28 +00:00
$this -> counter ++ ;
//Save to db
$status = backup_putid ( $this -> preferences -> backup_unique_code , 'grade_grades_history' , $id ,
null , $data );
//Create returning info
$this -> info = $this -> counter ;
//Reset temp
unset ( $this -> temp );
2007-08-09 21:50:59 +00:00
}
2007-08-08 08:42:28 +00:00
if (( $this -> level == 5 ) and ( $tagName == " GRADE_ITEM_HISTORY " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one PREFERENCE)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
$id = $data [ " GRADE_ITEM_HISTORY " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
$this -> counter ++ ;
//Save to db
$status = backup_putid ( $this -> preferences -> backup_unique_code , 'grade_items_history' , $id ,
null , $data );
//Create returning info
$this -> info = $this -> counter ;
//Reset temp
unset ( $this -> temp );
2007-08-09 21:50:59 +00:00
}
2007-08-08 08:42:28 +00:00
if (( $this -> level == 5 ) and ( $tagName == " GRADE_OUTCOME_HISTORY " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one PREFERENCE)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
$id = $data [ " GRADE_OUTCOME_HISTORY " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
$this -> counter ++ ;
//Save to db
$status = backup_putid ( $this -> preferences -> backup_unique_code , 'grade_outcomes_history' , $id ,
null , $data );
//Create returning info
$this -> info = $this -> counter ;
//Reset temp
2007-08-01 05:55:36 +00:00
unset ( $this -> temp );
}
2005-04-22 00:26:22 +00:00
}
//Stop parsing if todo = GRADEBOOK and tagName = GRADEBOOK (en of the tag, of course)
2005-02-07 17:52:58 +00:00
//Speed up a lot (avoid parse all)
2005-04-22 00:26:22 +00:00
if ( $tagName == " GRADEBOOK " and $this -> level == 3 ) {
2005-02-07 17:52:58 +00:00
$this -> finished = true ;
2005-04-22 00:26:22 +00:00
$this -> counter = 0 ;
2005-02-07 17:52:58 +00:00
}
2005-04-22 00:26:22 +00:00
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
}
2007-07-28 09:23:32 +00:00
2003-05-25 22:58:13 +00:00
//This is the endTag handler we use where we are reading the users zone (todo="USERS")
function endElementUsers ( $parser , $tagName ) {
2007-07-28 09:23:32 +00:00
global $CFG ;
2003-05-25 22:58:13 +00:00
//Check if we are into USERS zone
if ( $this -> tree [ 3 ] == " USERS " ) {
//if (trim($this->content)) //Debug
2004-09-12 01:34:24 +00:00
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n"; //Debug
2003-05-25 22:58:13 +00:00
//Dependig of different combinations, do different things
if ( $this -> level == 4 ) {
switch ( $tagName ) {
case " USER " :
2003-06-20 19:42:20 +00:00
//Increment counter
$this -> counter ++ ;
2007-07-28 09:23:32 +00:00
//Save to db, only save if record not already exist
2006-09-27 08:59:27 +00:00
// if there already is an new_id for this entry, just use that new_id?
$newuser = backup_getid ( $this -> preferences -> backup_unique_code , " user " , $this -> info -> tempuser -> id );
if ( isset ( $newuser -> new_id )) {
$newid = $newuser -> new_id ;
} else {
2007-07-28 09:23:32 +00:00
$newid = null ;
2006-09-27 08:59:27 +00:00
}
2007-07-28 09:23:32 +00:00
2003-05-25 22:58:13 +00:00
backup_putid ( $this -> preferences -> backup_unique_code , " user " , $this -> info -> tempuser -> id ,
2006-09-27 08:59:27 +00:00
$newid , $this -> info -> tempuser );
2007-07-28 09:23:32 +00:00
//Do some output
2003-06-20 19:42:20 +00:00
if ( $this -> counter % 10 == 0 ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $this -> counter % 200 == 0 ) {
echo " <br /> " ;
}
2003-06-20 19:42:20 +00:00
}
backup_flush ( 300 );
}
2003-05-25 22:58:13 +00:00
//Delete temp obejct
unset ( $this -> info -> tempuser );
break ;
}
}
if ( $this -> level == 5 ) {
switch ( $tagName ) {
2007-07-28 09:23:32 +00:00
case " ID " :
2003-05-25 22:58:13 +00:00
$this -> info -> users [ $this -> getContents ()] = $this -> getContents ();
$this -> info -> tempuser -> id = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " AUTH " :
2004-08-28 10:26:06 +00:00
$this -> info -> tempuser -> auth = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " CONFIRMED " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> confirmed = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " POLICYAGREED " :
2005-01-30 11:39:12 +00:00
$this -> info -> tempuser -> policyagreed = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " DELETED " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> deleted = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " USERNAME " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> username = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " PASSWORD " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> password = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " IDNUMBER " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> idnumber = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " FIRSTNAME " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> firstname = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " LASTNAME " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> lastname = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " EMAIL " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> email = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " EMAILSTOP " :
2004-02-20 09:02:27 +00:00
$this -> info -> tempuser -> emailstop = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " ICQ " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> icq = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " SKYPE " :
2005-03-05 10:31:58 +00:00
$this -> info -> tempuser -> skype = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " AIM " :
2005-03-05 10:31:58 +00:00
$this -> info -> tempuser -> aim = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " YAHOO " :
2005-03-05 10:31:58 +00:00
$this -> info -> tempuser -> yahoo = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " MSN " :
2005-03-05 10:31:58 +00:00
$this -> info -> tempuser -> msn = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " PHONE1 " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> phone1 = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " PHONE2 " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> phone2 = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " INSTITUTION " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> institution = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " DEPARTMENT " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> department = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " ADDRESS " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> address = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " CITY " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> city = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " COUNTRY " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> country = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " LANG " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> lang = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " THEME " :
2005-02-15 18:37:08 +00:00
$this -> info -> tempuser -> theme = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " TIMEZONE " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> timezone = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " FIRSTACCESS " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> firstaccess = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " LASTACCESS " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> lastaccess = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " LASTLOGIN " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> lastlogin = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " CURRENTLOGIN " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> currentlogin = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " LASTIP " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> lastip = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " SECRET " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> secret = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " PICTURE " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> picture = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " URL " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> url = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " DESCRIPTION " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> description = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " MAILFORMAT " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> mailformat = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " MAILDIGEST " :
2004-07-23 17:10:55 +00:00
$this -> info -> tempuser -> maildigest = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " MAILDISPLAY " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> maildisplay = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " HTMLEDITOR " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> htmleditor = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " AJAX " :
2006-08-28 06:41:05 +00:00
$this -> info -> tempuser -> ajax = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " AUTOSUBSCRIBE " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> autosubscribe = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " TRACKFORUMS " :
2005-04-25 18:45:21 +00:00
$this -> info -> tempuser -> trackforums = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " MNETHOSTURL " :
2007-04-12 22:18:05 +00:00
$this -> info -> tempuser -> mnethosturl = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
case " TIMEMODIFIED " :
2003-05-25 22:58:13 +00:00
$this -> info -> tempuser -> timemodified = $this -> getContents ();
break ;
2006-09-27 08:59:27 +00:00
default :
break ;
2003-05-25 22:58:13 +00:00
}
}
2007-02-20 01:07:18 +00:00
if ( $this -> level == 6 && $this -> tree [ 5 ] != " ROLES_ASSIGNMENTS " && $this -> tree [ 5 ] != " ROLES_OVERRIDES " ) {
2003-05-25 22:58:13 +00:00
switch ( $tagName ) {
case " ROLE " :
//We've finalized a role, get it
2003-08-25 01:44:01 +00:00
$this -> info -> tempuser -> roles [ $this -> info -> temprole -> type ] = $this -> info -> temprole ;
2003-05-25 22:58:13 +00:00
unset ( $this -> info -> temprole );
break ;
2004-02-08 19:27:23 +00:00
case " USER_PREFERENCE " :
//We've finalized a user_preference, get it
$this -> info -> tempuser -> user_preferences [ $this -> info -> tempuserpreference -> name ] = $this -> info -> tempuserpreference ;
unset ( $this -> info -> tempuserpreference );
break ;
2003-05-25 22:58:13 +00:00
}
}
2007-07-28 09:23:32 +00:00
2007-02-20 01:07:18 +00:00
if ( $this -> level == 7 ) {
2003-05-25 22:58:13 +00:00
switch ( $tagName ) {
case " TYPE " :
$this -> info -> temprole -> type = $this -> getContents ();
break ;
case " AUTHORITY " :
$this -> info -> temprole -> authority = $this -> getContents ();
break ;
case " TEA_ROLE " :
$this -> info -> temprole -> tea_role = $this -> getContents ();
break ;
2003-08-16 11:31:32 +00:00
case " EDITALL " :
$this -> info -> temprole -> editall = $this -> getContents ();
break ;
2004-06-24 22:41:00 +00:00
case " TIMESTART " :
$this -> info -> temprole -> timestart = $this -> getContents ();
break ;
case " TIMEEND " :
$this -> info -> temprole -> timeend = $this -> getContents ();
break ;
2003-08-16 11:31:32 +00:00
case " TIMEMODIFIED " :
$this -> info -> temprole -> timemodified = $this -> getContents ();
break ;
2003-05-25 22:58:13 +00:00
case " TIMESTART " :
$this -> info -> temprole -> timestart = $this -> getContents ();
break ;
case " TIMEEND " :
$this -> info -> temprole -> timeend = $this -> getContents ();
break ;
case " TIME " :
$this -> info -> temprole -> time = $this -> getContents ();
break ;
2003-10-27 17:23:43 +00:00
case " TIMEACCESS " :
$this -> info -> temprole -> timeaccess = $this -> getContents ();
break ;
2005-01-30 11:39:12 +00:00
case " ENROL " :
$this -> info -> temprole -> enrol = $this -> getContents ();
break ;
2004-02-08 19:27:23 +00:00
case " NAME " :
$this -> info -> tempuserpreference -> name = $this -> getContents ();
break ;
case " VALUE " :
$this -> info -> tempuserpreference -> value = $this -> getContents ();
break ;
2006-09-27 08:59:27 +00:00
default :
break ;
2007-07-28 09:23:32 +00:00
2003-05-25 22:58:13 +00:00
}
}
2007-07-28 09:23:32 +00:00
2006-09-27 08:59:27 +00:00
if ( $this -> tree [ 5 ] == " ROLES_ASSIGNMENTS " ) {
if ( $this -> level == 7 ) {
switch ( $tagName ) {
case " NAME " :
$this -> info -> tempname = $this -> getContents ();
break ;
case " SHORTNAME " :
$this -> info -> tempshortname = $this -> getContents ();
break ;
case " ID " :
$this -> info -> tempid = $this -> getContents (); // temp roleid
break ;
}
}
2007-07-28 09:23:32 +00:00
2006-09-27 08:59:27 +00:00
if ( $this -> level == 9 ) {
switch ( $tagName ) {
case " USERID " :
$this -> info -> tempuser -> roleassignments [ $this -> info -> tempid ] -> name = $this -> info -> tempname ;
2007-07-28 09:23:32 +00:00
2006-09-27 08:59:27 +00:00
$this -> info -> tempuser -> roleassignments [ $this -> info -> tempid ] -> shortname = $this -> info -> tempshortname ;
2007-07-28 09:23:32 +00:00
2006-09-27 08:59:27 +00:00
$this -> info -> tempuserid = $this -> getContents ();
2007-07-28 09:23:32 +00:00
2006-09-27 08:59:27 +00:00
$this -> info -> tempuser -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuserid ] -> userid = $this -> getContents ();
break ;
case " HIDDEN " :
$this -> info -> tempuser -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuserid ] -> hidden = $this -> getContents ();
break ;
case " TIMESTART " :
$this -> info -> tempuser -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuserid ] -> timestart = $this -> getContents ();
break ;
case " TIMEEND " :
$this -> info -> tempuser -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuserid ] -> timeend = $this -> getContents ();
break ;
case " TIMEMODIFIED " :
$this -> info -> tempuser -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuserid ] -> timemodified = $this -> getContents ();
break ;
case " MODIFIERID " :
$this -> info -> tempuser -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuserid ] -> modifierid = $this -> getContents ();
break ;
case " ENROL " :
$this -> info -> tempuser -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuserid ] -> enrol = $this -> getContents ();
break ;
case " SORTORDER " :
$this -> info -> tempuser -> roleassignments [ $this -> info -> tempid ] -> assignments [ $this -> info -> tempuserid ] -> sortorder = $this -> getContents ();
break ;
2007-07-28 09:23:32 +00:00
2006-09-27 08:59:27 +00:00
}
}
} /// ends role_assignments
2007-07-28 09:23:32 +00:00
2006-09-27 08:59:27 +00:00
if ( $this -> tree [ 5 ] == " ROLES_OVERRIDES " ) {
if ( $this -> level == 7 ) {
switch ( $tagName ) {
case " NAME " :
$this -> info -> tempname = $this -> getContents ();
break ;
case " SHORTNAME " :
$this -> info -> tempshortname = $this -> getContents ();
2007-07-28 09:23:32 +00:00
break ;
2006-09-27 08:59:27 +00:00
case " ID " :
$this -> info -> tempid = $this -> getContents (); // temp roleid
break ;
2007-07-28 09:23:32 +00:00
}
2006-09-27 08:59:27 +00:00
}
2007-07-28 09:23:32 +00:00
2006-09-27 08:59:27 +00:00
if ( $this -> level == 9 ) {
switch ( $tagName ) {
case " NAME " :
2007-07-28 09:23:32 +00:00
2006-09-27 08:59:27 +00:00
$this -> info -> tempuser -> roleoverrides [ $this -> info -> tempid ] -> name = $this -> info -> tempname ;
$this -> info -> tempuser -> roleoverrides [ $this -> info -> tempid ] -> shortname = $this -> info -> tempshortname ;
$this -> info -> tempname = $this -> getContents (); // change to name of capability
$this -> info -> tempuser -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> name = $this -> getContents ();
break ;
case " PERMISSION " :
$this -> info -> tempuser -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> permission = $this -> getContents ();
break ;
case " TIMEMODIFIED " :
$this -> info -> tempuser -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> timemodified = $this -> getContents ();
break ;
case " MODIFIERID " :
$this -> info -> tempuser -> roleoverrides [ $this -> info -> tempid ] -> overrides [ $this -> info -> tempname ] -> modifierid = $this -> getContents ();
break ;
}
}
2007-07-28 09:23:32 +00:00
} /// ends role_overrides
2006-09-27 08:59:27 +00:00
} // closes if this->tree[3]=="users"
2003-05-25 22:58:13 +00:00
//Stop parsing if todo = USERS and tagName = USERS (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $tagName == " USERS " and $this -> level == 3 ) {
$this -> finished = true ;
2003-06-20 19:42:20 +00:00
$this -> counter = 0 ;
2003-05-25 22:58:13 +00:00
}
2007-07-28 09:23:32 +00:00
2003-05-25 22:58:13 +00:00
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
2005-04-22 00:26:22 +00:00
2003-05-25 22:58:13 +00:00
}
2003-05-24 00:27:45 +00:00
2005-02-13 19:09:41 +00:00
//This is the endTag handler we use where we are reading the messages zone (todo="MESSAGES")
function endElementMessages ( $parser , $tagName ) {
//Check if we are into MESSAGES zone
if ( $this -> tree [ 3 ] == " MESSAGES " ) {
//if (trim($this->content)) //Debug
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n";//Debug
//Acumulate data to info (content + close tag)
//Reconvert: strip htmlchars again and trim to generate xml data
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= htmlspecialchars ( trim ( $this -> content )) . " </ " . $tagName . " > " ;
//If we've finished a message, xmlize it an save to db
if (( $this -> level == 4 ) and ( $tagName == " MESSAGE " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one MESSAGE)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
//echo strftime ("%X",time())."<p>"; //Debug
//traverse_xmlize($data); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, save data to db. We'll use it later
//Get id and status from data
$message_id = $data [ " MESSAGE " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
$message_status = $data [ " MESSAGE " ][ " # " ][ " STATUS " ][ " 0 " ][ " # " ];
if ( $message_status == " READ " ) {
$table = " message_read " ;
} else {
$table = " message " ;
}
$this -> counter ++ ;
//Save to db
2007-07-28 09:23:32 +00:00
$status = backup_putid ( $this -> preferences -> backup_unique_code , $table , $message_id ,
2005-02-13 19:09:41 +00:00
null , $data );
//Create returning info
$this -> info = $this -> counter ;
//Reset temp
unset ( $this -> temp );
}
//If we've finished a contact, xmlize it an save to db
if (( $this -> level == 5 ) and ( $tagName == " CONTACT " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one MESSAGE)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
//echo strftime ("%X",time())."<p>"; //Debug
//traverse_xmlize($data); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, save data to db. We'll use it later
//Get id and status from data
$contact_id = $data [ " CONTACT " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
$this -> counter ++ ;
//Save to db
2007-07-28 09:23:32 +00:00
$status = backup_putid ( $this -> preferences -> backup_unique_code , 'message_contacts' , $contact_id ,
2005-02-13 19:09:41 +00:00
null , $data );
//Create returning info
$this -> info = $this -> counter ;
//Reset temp
unset ( $this -> temp );
}
}
//Stop parsing if todo = MESSAGES and tagName = MESSAGES (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $tagName == " MESSAGES " and $this -> level == 3 ) {
$this -> finished = true ;
$this -> counter = 0 ;
}
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
2005-04-22 00:26:22 +00:00
2005-02-13 19:09:41 +00:00
}
2007-07-28 09:23:32 +00:00
//This is the endTag handler we use where we are reading the questions zone (todo="QUESTIONS")
2003-06-28 23:18:37 +00:00
function endElementQuestions ( $parser , $tagName ) {
//Check if we are into QUESTION_CATEGORIES zone
if ( $this -> tree [ 3 ] == " QUESTION_CATEGORIES " ) {
//if (trim($this->content)) //Debug
2004-09-12 01:34:24 +00:00
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n"; //Debug
2003-06-28 23:18:37 +00:00
//Acumulate data to info (content + close tag)
//Reconvert: strip htmlchars again and trim to generate xml data
2003-08-25 01:44:01 +00:00
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
2003-06-28 23:18:37 +00:00
$this -> temp .= htmlspecialchars ( trim ( $this -> content )) . " </ " . $tagName . " > " ;
//If we've finished a mod, xmlize it an save to db
if (( $this -> level == 4 ) and ( $tagName == " QUESTION_CATEGORY " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
2003-08-18 00:00:22 +00:00
//Call to xmlize for this portion of xml data (one QUESTION_CATEGORY)
2003-07-03 23:18:13 +00:00
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
2003-07-05 22:44:29 +00:00
$data = xmlize ( $xml_data , 0 );
2003-07-03 23:18:13 +00:00
//echo strftime ("%X",time())."<p>"; //Debug
2003-06-28 23:18:37 +00:00
//traverse_xmlize($data); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, save data to db. We'll use it later
2003-08-18 00:00:22 +00:00
//Get id from data
2003-06-28 23:18:37 +00:00
$category_id = $data [ " QUESTION_CATEGORY " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
//Save to db
2006-03-12 21:17:42 +00:00
$status = backup_putid ( $this -> preferences -> backup_unique_code , " question_categories " , $category_id ,
2003-06-28 23:18:37 +00:00
null , $data );
//Create returning info
2007-08-15 10:43:25 +00:00
$ret_info = new object ();
2003-06-28 23:18:37 +00:00
$ret_info -> id = $category_id ;
$this -> info [] = $ret_info ;
//Reset temp
unset ( $this -> temp );
}
}
//Stop parsing if todo = QUESTION_CATEGORIES and tagName = QUESTION_CATEGORY (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $tagName == " QUESTION_CATEGORIES " and $this -> level == 3 ) {
$this -> finished = true ;
}
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
2005-04-22 00:26:22 +00:00
2003-06-28 23:18:37 +00:00
}
2003-08-18 00:00:22 +00:00
//This is the endTag handler we use where we are reading the scales zone (todo="SCALES")
function endElementScales ( $parser , $tagName ) {
//Check if we are into SCALES zone
if ( $this -> tree [ 3 ] == " SCALES " ) {
//if (trim($this->content)) //Debug
2004-09-12 01:34:24 +00:00
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n"; //Debug
2003-08-18 00:00:22 +00:00
//Acumulate data to info (content + close tag)
//Reconvert: strip htmlchars again and trim to generate xml data
2003-08-25 01:44:01 +00:00
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
2003-08-18 00:00:22 +00:00
$this -> temp .= htmlspecialchars ( trim ( $this -> content )) . " </ " . $tagName . " > " ;
//If we've finished a scale, xmlize it an save to db
if (( $this -> level == 4 ) and ( $tagName == " SCALE " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one SCALE)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
//echo strftime ("%X",time())."<p>"; //Debug
//traverse_xmlize($data); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, save data to db. We'll use it later
//Get id and from data
$scale_id = $data [ " SCALE " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
//Save to db
$status = backup_putid ( $this -> preferences -> backup_unique_code , " scale " , $scale_id ,
null , $data );
//Create returning info
2007-08-15 10:43:25 +00:00
$ret_info = new object ();
2003-08-18 00:00:22 +00:00
$ret_info -> id = $scale_id ;
$this -> info [] = $ret_info ;
//Reset temp
unset ( $this -> temp );
}
}
//Stop parsing if todo = SCALES and tagName = SCALE (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $tagName == " SCALES " and $this -> level == 3 ) {
$this -> finished = true ;
}
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
2005-04-22 00:26:22 +00:00
2003-08-18 00:00:22 +00:00
}
2004-01-25 20:57:58 +00:00
//This is the endTag handler we use where we are reading the groups zone (todo="GROUPS")
function endElementGroups ( $parser , $tagName ) {
//Check if we are into GROUPS zone
if ( $this -> tree [ 3 ] == " GROUPS " ) {
//if (trim($this->content)) //Debug
2004-09-12 01:34:24 +00:00
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n"; //Debug
2004-01-25 20:57:58 +00:00
//Acumulate data to info (content + close tag)
//Reconvert: strip htmlchars again and trim to generate xml data
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= htmlspecialchars ( trim ( $this -> content )) . " </ " . $tagName . " > " ;
//If we've finished a group, xmlize it an save to db
if (( $this -> level == 4 ) and ( $tagName == " GROUP " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one GROUP)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
//echo strftime ("%X",time())."<p>"; //Debug
//traverse_xmlize($data); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, save data to db. We'll use it later
//Get id and from data
$group_id = $data [ " GROUP " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
//Save to db
2005-06-03 16:46:28 +00:00
$status = backup_putid ( $this -> preferences -> backup_unique_code , " groups " , $group_id ,
2004-01-25 20:57:58 +00:00
null , $data );
//Create returning info
2007-01-20 09:28:26 +00:00
$ret_info = new Object ();
2004-01-25 20:57:58 +00:00
$ret_info -> id = $group_id ;
$this -> info [] = $ret_info ;
//Reset temp
unset ( $this -> temp );
}
}
//Stop parsing if todo = GROUPS and tagName = GROUP (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $tagName == " GROUPS " and $this -> level == 3 ) {
$this -> finished = true ;
}
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
2005-04-22 00:26:22 +00:00
2004-01-25 20:57:58 +00:00
}
2007-08-14 20:35:04 +00:00
//This is the endTag handler we use where we are reading the groupings zone (todo="GROUPINGS")
2007-08-15 10:43:25 +00:00
function endElementGroupings ( $parser , $tagName ) {
2007-08-14 20:35:04 +00:00
//Check if we are into GROUPINGS zone
2007-01-20 09:28:26 +00:00
if ( $this -> tree [ 3 ] == " GROUPINGS " ) {
//Acumulate data to info (content + close tag)
//Reconvert: strip htmlchars again and trim to generate xml data
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= htmlspecialchars ( trim ( $this -> content )) . " </ " . $tagName . " > " ;
//If we've finished a group, xmlize it an save to db
if (( $this -> level == 4 ) and ( $tagName == " GROUPING " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one GROUPING)
$data = xmlize ( $xml_data , 0 );
//Now, save data to db. We'll use it later
//Get id and from data
$grouping_id = $data [ " GROUPING " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
//Save to db
$status = backup_putid ( $this -> preferences -> backup_unique_code , " groupings " , $grouping_id ,
null , $data );
//Create returning info
$ret_info = new Object ();
$ret_info -> id = $grouping_id ;
$this -> info [] = $ret_info ;
//Reset temp
unset ( $this -> temp );
}
}
//Stop parsing if todo = GROUPINGS and tagName = GROUPING (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $tagName == " GROUPINGS " and $this -> level == 3 ) {
$this -> finished = true ;
}
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
}
2007-08-14 20:35:04 +00:00
//This is the endTag handler we use where we are reading the groupingsgroups zone (todo="GROUPINGGROUPS")
2007-08-15 10:43:25 +00:00
function endElementGroupingsGroups ( $parser , $tagName ) {
2007-08-14 20:35:04 +00:00
//Check if we are into GROUPINGSGROUPS zone
if ( $this -> tree [ 3 ] == " GROUPINGSGROUPS " ) {
//Acumulate data to info (content + close tag)
//Reconvert: strip htmlchars again and trim to generate xml data
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= htmlspecialchars ( trim ( $this -> content )) . " </ " . $tagName . " > " ;
//If we've finished a group, xmlize it an save to db
if (( $this -> level == 4 ) and ( $tagName == " GROUPINGGROUP " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one GROUPING)
$data = xmlize ( $xml_data , 0 );
//Now, save data to db. We'll use it later
//Get id and from data
$groupinggroup_id = $data [ " GROUPINGGROUP " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
//Save to db
$status = backup_putid ( $this -> preferences -> backup_unique_code , " groupingsgroups " , $groupinggroup_id ,
null , $data );
//Create returning info
$ret_info = new Object ();
$ret_info -> id = $groupinggroup_id ;
$this -> info [] = $ret_info ;
//Reset temp
unset ( $this -> temp );
}
}
//Stop parsing if todo = GROUPINGS and tagName = GROUPING (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $tagName == " GROUPINGSGROUPS " and $this -> level == 3 ) {
$this -> finished = true ;
}
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
}
2004-02-21 01:30:22 +00:00
//This is the endTag handler we use where we are reading the events zone (todo="EVENTS")
function endElementEvents ( $parser , $tagName ) {
//Check if we are into EVENTS zone
if ( $this -> tree [ 3 ] == " EVENTS " ) {
//if (trim($this->content)) //Debug
2004-09-12 01:34:24 +00:00
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n"; //Debug
2004-02-21 01:30:22 +00:00
//Acumulate data to info (content + close tag)
//Reconvert: strip htmlchars again and trim to generate xml data
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= htmlspecialchars ( trim ( $this -> content )) . " </ " . $tagName . " > " ;
//If we've finished a event, xmlize it an save to db
if (( $this -> level == 4 ) and ( $tagName == " EVENT " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one EVENT)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
//echo strftime ("%X",time())."<p>"; //Debug
//traverse_xmlize($data); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, save data to db. We'll use it later
//Get id and from data
$event_id = $data [ " EVENT " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
//Save to db
$status = backup_putid ( $this -> preferences -> backup_unique_code , " event " , $event_id ,
null , $data );
//Create returning info
2007-08-15 10:43:25 +00:00
$ret_info = new object ();
2004-02-21 01:30:22 +00:00
$ret_info -> id = $event_id ;
$this -> info [] = $ret_info ;
//Reset temp
unset ( $this -> temp );
}
}
//Stop parsing if todo = EVENTS and tagName = EVENT (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $tagName == " EVENTS " and $this -> level == 3 ) {
$this -> finished = true ;
}
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
2005-04-22 00:26:22 +00:00
2004-02-21 01:30:22 +00:00
}
2003-05-30 21:32:04 +00:00
//This is the endTag handler we use where we are reading the modules zone (todo="MODULES")
function endElementModules ( $parser , $tagName ) {
//Check if we are into MODULES zone
if ( $this -> tree [ 3 ] == " MODULES " ) {
//if (trim($this->content)) //Debug
2004-09-12 01:34:24 +00:00
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n"; //Debug
2003-05-30 21:32:04 +00:00
//Acumulate data to info (content + close tag)
2003-05-31 15:21:39 +00:00
//Reconvert: strip htmlchars again and trim to generate xml data
2003-08-25 01:44:01 +00:00
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
2003-05-31 15:21:39 +00:00
$this -> temp .= htmlspecialchars ( trim ( $this -> content )) . " </ " . $tagName . " > " ;
2003-05-30 21:32:04 +00:00
//If we've finished a mod, xmlize it an save to db
if (( $this -> level == 4 ) and ( $tagName == " MOD " )) {
//Prepend XML standard header to info gathered
2003-05-30 22:55:40 +00:00
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
2003-05-30 21:32:04 +00:00
//Call to xmlize for this portion of xml data (one MOD)
2003-07-07 19:20:52 +00:00
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
2007-07-28 09:23:32 +00:00
$data = xmlize ( $xml_data , 0 );
2003-07-07 19:20:52 +00:00
//echo strftime ("%X",time())."<p>"; //Debug
2003-05-30 21:32:04 +00:00
//traverse_xmlize($data); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, save data to db. We'll use it later
//Get id and modtype from data
$mod_id = $data [ " MOD " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
$mod_type = $data [ " MOD " ][ " # " ][ " MODTYPE " ][ " 0 " ][ " # " ];
2003-05-30 21:56:08 +00:00
//Only if we've selected to restore it
2006-10-12 06:58:14 +00:00
if ( ! empty ( $this -> preferences -> mods [ $mod_type ] -> restore )) {
2003-05-30 21:56:08 +00:00
//Save to db
2003-06-12 17:38:36 +00:00
$status = backup_putid ( $this -> preferences -> backup_unique_code , $mod_type , $mod_id ,
2003-06-20 19:42:20 +00:00
null , $data );
2003-06-12 17:38:36 +00:00
//echo "<p>id: ".$mod_id."-".$mod_type." len.: ".strlen($sla_mod_temp)." to_db: ".$status."<p>"; //Debug
2003-05-30 22:55:40 +00:00
//Create returning info
2007-08-15 10:43:25 +00:00
$ret_info = new object ();
2003-05-31 15:21:39 +00:00
$ret_info -> id = $mod_id ;
$ret_info -> modtype = $mod_type ;
$this -> info [] = $ret_info ;
2003-05-30 21:56:08 +00:00
}
2003-06-20 19:42:20 +00:00
//Reset temp
unset ( $this -> temp );
2003-05-30 21:32:04 +00:00
}
}
2006-01-15 21:09:13 +00:00
2003-05-30 21:32:04 +00:00
//Stop parsing if todo = MODULES and tagName = MODULES (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $tagName == " MODULES " and $this -> level == 3 ) {
$this -> finished = true ;
}
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
2005-04-22 00:26:22 +00:00
2003-05-30 21:32:04 +00:00
}
2004-02-13 23:28:45 +00:00
//This is the endTag handler we use where we are reading the logs zone (todo="LOGS")
function endElementLogs ( $parser , $tagName ) {
//Check if we are into LOGS zone
if ( $this -> tree [ 3 ] == " LOGS " ) {
//if (trim($this->content)) //Debug
2004-09-12 01:34:24 +00:00
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n"; //Debug
2004-02-13 23:28:45 +00:00
//Acumulate data to info (content + close tag)
//Reconvert: strip htmlchars again and trim to generate xml data
if ( ! isset ( $this -> temp )) {
$this -> temp = " " ;
}
$this -> temp .= htmlspecialchars ( trim ( $this -> content )) . " </ " . $tagName . " > " ;
//If we've finished a log, xmlize it an save to db
if (( $this -> level == 4 ) and ( $tagName == " LOG " )) {
//Prepend XML standard header to info gathered
$xml_data = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n " . $this -> temp ;
//Call to xmlize for this portion of xml data (one LOG)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize ( $xml_data , 0 );
//echo strftime ("%X",time())."<p>"; //Debug
//traverse_xmlize($data); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, save data to db. We'll use it later
//Get id and modtype from data
$log_id = $data [ " LOG " ][ " # " ][ " ID " ][ " 0 " ][ " # " ];
$log_module = $data [ " LOG " ][ " # " ][ " MODULE " ][ " 0 " ][ " # " ];
//We only save log entries from backup file if they are:
// - Course logs
// - User logs
// - Module logs about one restored module
if ( $log_module == " course " or
$log_module == " user " or
$this -> preferences -> mods [ $log_module ] -> restore ) {
//Increment counter
$this -> counter ++ ;
//Save to db
$status = backup_putid ( $this -> preferences -> backup_unique_code , " log " , $log_id ,
null , $data );
//echo "<p>id: ".$mod_id."-".$mod_type." len.: ".strlen($sla_mod_temp)." to_db: ".$status."<p>"; //Debug
//Create returning info
$this -> info = $this -> counter ;
}
//Reset temp
unset ( $this -> temp );
}
}
//Stop parsing if todo = LOGS and tagName = LOGS (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ( $tagName == " LOGS " and $this -> level == 3 ) {
$this -> finished = true ;
$this -> counter = 0 ;
}
//Clear things
$this -> tree [ $this -> level ] = " " ;
$this -> level -- ;
$this -> content = " " ;
2005-04-22 00:26:22 +00:00
2004-02-13 23:28:45 +00:00
}
2003-05-17 11:40:27 +00:00
//This is the endTag default handler we use when todo is undefined
2003-05-16 23:57:35 +00:00
function endElement ( $parser , $tagName ) {
2003-05-17 08:56:53 +00:00
if ( trim ( $this -> content )) //Debug
2004-09-12 01:34:24 +00:00
echo " C " . str_repeat ( " " ,( $this -> level + 2 ) * 2 ) . $this -> getContents () . " <br /> \n " ; //Debug
echo $this -> level . str_repeat ( " " , $this -> level * 2 ) . " </ " . $tagName . " ><br /> \n " ; //Debug
2003-05-17 11:40:27 +00:00
//Clear things
2003-05-16 23:57:35 +00:00
$this -> tree [ $this -> level ] = " " ;
2003-05-17 11:40:27 +00:00
$this -> level -- ;
2003-05-16 23:57:35 +00:00
$this -> content = " " ;
}
2003-05-17 11:40:27 +00:00
//This is the handler to read data contents (simple accumule it)
2003-05-16 23:57:35 +00:00
function characterData ( $parser , $data ) {
$this -> content .= $data ;
}
}
2007-07-28 09:23:32 +00:00
2003-05-16 23:57:35 +00:00
//This function executes the MoodleParser
function restore_read_xml ( $xml_file , $todo , $preferences ) {
2007-07-28 09:23:32 +00:00
2003-05-16 23:57:35 +00:00
$status = true ;
2004-09-13 08:17:09 +00:00
$xml_parser = xml_parser_create ( 'UTF-8' );
2003-05-16 23:57:35 +00:00
$moodle_parser = new MoodleParser ();
$moodle_parser -> todo = $todo ;
$moodle_parser -> preferences = $preferences ;
2003-07-31 16:44:52 +00:00
xml_set_object ( $xml_parser , $moodle_parser );
2003-05-17 11:40:27 +00:00
//Depending of the todo we use some element_handler or another
if ( $todo == " INFO " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementInfo " , " endElementInfo " );
2006-09-25 09:10:19 +00:00
} else if ( $todo == " ROLES " ) {
// Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementRoles " , " endElementRoles " );
2003-05-17 17:34:30 +00:00
} else if ( $todo == " COURSE_HEADER " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementCourseHeader " , " endElementCourseHeader " );
2004-10-29 17:07:11 +00:00
} else if ( $todo == 'BLOCKS' ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementBlocks " , " endElementBlocks " );
2003-05-24 00:27:45 +00:00
} else if ( $todo == " SECTIONS " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementSections " , " endElementSections " );
2006-12-11 15:47:23 +00:00
} else if ( $todo == 'FORMATDATA' ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementFormatData " , " endElementFormatData " );
2005-02-07 17:52:58 +00:00
} else if ( $todo == " METACOURSE " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementMetacourse " , " endElementMetacourse " );
2005-04-22 00:26:22 +00:00
} else if ( $todo == " GRADEBOOK " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementGradebook " , " endElementGradebook " );
2003-05-25 22:58:13 +00:00
} else if ( $todo == " USERS " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementUsers " , " endElementUsers " );
2005-02-13 19:09:41 +00:00
} else if ( $todo == " MESSAGES " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementMessages " , " endElementMessages " );
2003-06-28 23:18:37 +00:00
} else if ( $todo == " QUESTIONS " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementQuestions " , " endElementQuestions " );
2003-08-18 00:00:22 +00:00
} else if ( $todo == " SCALES " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementScales " , " endElementScales " );
2004-01-25 20:57:58 +00:00
} else if ( $todo == " GROUPS " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementGroups " , " endElementGroups " );
2007-01-20 09:28:26 +00:00
} else if ( $todo == " GROUPINGS " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementGroupings " , " endElementGroupings " );
2007-08-14 20:35:04 +00:00
} else if ( $todo == " GROUPINGSGROUPS " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementGroupingsGroups " , " endElementGroupingsGroups " );
2004-02-21 01:30:22 +00:00
} else if ( $todo == " EVENTS " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementEvents " , " endElementEvents " );
2003-05-30 21:32:04 +00:00
} else if ( $todo == " MODULES " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementModules " , " endElementModules " );
2004-02-13 23:28:45 +00:00
} else if ( $todo == " LOGS " ) {
//Define handlers to that zone
xml_set_element_handler ( $xml_parser , " startElementLogs " , " endElementLogs " );
2003-05-17 11:40:27 +00:00
} else {
//Define default handlers (must no be invoked when everything become finished)
xml_set_element_handler ( $xml_parser , " startElementInfo " , " endElementInfo " );
}
2003-05-16 23:57:35 +00:00
xml_set_character_data_handler ( $xml_parser , " characterData " );
$fp = fopen ( $xml_file , " r " )
or $status = false ;
if ( $status ) {
while ( $data = fread ( $fp , 4096 ) and ! $moodle_parser -> finished )
xml_parse ( $xml_parser , $data , feof ( $fp ))
or die ( sprintf ( " XML error: %s at line %d " ,
xml_error_string ( xml_get_error_code ( $xml_parser )),
xml_get_current_line_number ( $xml_parser )));
fclose ( $fp );
}
2003-05-17 08:56:53 +00:00
//Get info from parser
$info = $moodle_parser -> info ;
2006-01-15 21:09:13 +00:00
2003-05-17 08:56:53 +00:00
//Clear parser mem
2003-05-16 23:57:35 +00:00
xml_parser_free ( $xml_parser );
2006-01-15 21:09:13 +00:00
if ( $status && ! empty ( $info )) {
2003-05-16 23:57:35 +00:00
return $info ;
} else {
return $status ;
}
}
2005-01-27 02:35:10 +00:00
2006-01-15 21:09:13 +00:00
/**
* @ param string $errorstr passed by reference , if silent is true ,
* errorstr will be populated and this function will return false rather than calling error () or notify ()
2007-07-28 09:23:32 +00:00
* @ param boolean $noredirect ( optional ) if this is passed , this function will not print continue , or
2006-01-15 21:09:13 +00:00
* redirect to the next step in the restore process , instead will return $backup_unique_code
*/
function restore_precheck ( $id , $file , & $errorstr , $noredirect = false ) {
2007-07-28 09:23:32 +00:00
2005-01-27 19:07:51 +00:00
global $CFG , $SESSION ;
2005-01-27 02:35:10 +00:00
//Prepend dataroot to variable to have the absolute path
$file = $CFG -> dataroot . " / " . $file ;
2007-07-28 09:23:32 +00:00
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2005-01-27 02:35:10 +00:00
//Start the main table
echo " <table cellpadding= \" 5 \" > " ;
echo " <tr><td> " ;
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
//Start the mail ul
echo " <ul> " ;
}
2007-07-28 09:23:32 +00:00
//Check the file exists
2005-01-27 02:35:10 +00:00
if ( ! is_file ( $file )) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
error ( " File not exists ( $file ) " );
} else {
$errorstr = " File not exists ( $file ) " ;
return false ;
}
2005-01-27 02:35:10 +00:00
}
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
//Check the file name ends with .zip
if ( ! substr ( $file , - 4 ) == " .zip " ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
error ( " File has an incorrect extension " );
} else {
$errorstr = 'File has an incorrect extension' ;
return false ;
}
2005-01-27 02:35:10 +00:00
}
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
//Now calculate the unique_code for this restore
$backup_unique_code = time ();
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
//Now check and create the backup dir (if it doesn't exist)
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2005-02-07 23:28:52 +00:00
echo " <li> " . get_string ( " creatingtemporarystructures " ) . '</li>' ;
2005-01-27 02:35:10 +00:00
}
$status = check_and_create_backup_dir ( $backup_unique_code );
//Empty dir
if ( $status ) {
$status = clear_backup_dir ( $backup_unique_code );
}
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
//Now delete old data and directories under dataroot/temp/backup
2007-07-28 09:23:32 +00:00
if ( $status ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2005-02-07 23:28:52 +00:00
echo " <li> " . get_string ( " deletingolddata " ) . '</li>' ;
2005-01-27 02:35:10 +00:00
}
$status = backup_delete_old_data ();
}
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
//Now copy he zip file to dataroot/temp/backup/backup_unique_code
if ( $status ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2005-02-07 23:28:52 +00:00
echo " <li> " . get_string ( " copyingzipfile " ) . '</li>' ;
2005-01-27 02:35:10 +00:00
}
if ( ! $status = backup_copy_file ( $file , $CFG -> dataroot . " /temp/backup/ " . $backup_unique_code . " / " . basename ( $file ))) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Error copying backup file. Invalid name or bad perms. " );
} else {
$errorstr = " Error copying backup file. Invalid name or bad perms " ;
return false ;
}
2005-01-27 02:35:10 +00:00
}
}
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
//Now unzip the file
if ( $status ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2005-02-07 23:28:52 +00:00
echo " <li> " . get_string ( " unzippingbackup " ) . '</li>' ;
2005-01-27 02:35:10 +00:00
}
if ( ! $status = restore_unzip ( $CFG -> dataroot . " /temp/backup/ " . $backup_unique_code . " / " . basename ( $file ))) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Error unzipping backup file. Invalid zip file. " );
} else {
$errorstr = " Error unzipping backup file. Invalid zip file. " ;
return false ;
}
2005-01-27 02:35:10 +00:00
}
}
2005-02-08 07:19:49 +00:00
//Check for Blackboard backups and convert
if ( $status ){
require_once ( " $CFG->dirroot /backup/bb/restore_bb.php " );
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2007-02-16 15:46:51 +00:00
echo " <li> " . get_string ( " checkingforbbexport " ) . '</li>' ;
2006-01-15 21:09:13 +00:00
}
2005-02-08 07:19:49 +00:00
$status = blackboard_convert ( $CFG -> dataroot . " /temp/backup/ " . $backup_unique_code );
}
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
//Now check for the moodle.xml file
if ( $status ) {
$xml_file = $CFG -> dataroot . " /temp/backup/ " . $backup_unique_code . " /moodle.xml " ;
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2005-02-07 23:28:52 +00:00
echo " <li> " . get_string ( " checkingbackup " ) . '</li>' ;
2005-01-27 02:35:10 +00:00
}
if ( ! $status = restore_check_moodle_file ( $xml_file )) {
2006-04-25 22:55:29 +00:00
if ( ! is_file ( $xml_file )) {
$errorstr = 'Error checking backup file. moodle.xml not found at root level of zip file.' ;
} else {
$errorstr = 'Error checking backup file. moodle.xml is incorrect or corrupted.' ;
}
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-04-25 22:55:29 +00:00
notify ( $errorstr );
2006-01-15 21:09:13 +00:00
} else {
return false ;
}
2005-01-27 02:35:10 +00:00
}
}
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
$info = " " ;
$course_header = " " ;
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
//Now read the info tag (all)
if ( $status ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2005-02-07 23:28:52 +00:00
echo " <li> " . get_string ( " readinginfofrombackup " ) . '</li>' ;
2005-01-27 02:35:10 +00:00
}
//Reading info from file
$info = restore_read_xml_info ( $xml_file );
//Reading course_header from file
$course_header = restore_read_xml_course_header ( $xml_file );
}
2007-07-28 09:23:32 +00:00
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2005-01-27 02:35:10 +00:00
//End the main ul
2007-02-16 15:46:51 +00:00
echo " </ul> \n " ;
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
//End the main table
2005-02-07 23:28:52 +00:00
echo " </td></tr> " ;
2005-01-27 02:35:10 +00:00
echo " </table> " ;
}
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
//We compare Moodle's versions
if ( $CFG -> version < $info -> backup_moodle_version && $status ) {
2007-08-15 10:43:25 +00:00
$message = new message ();
2005-01-27 02:35:10 +00:00
$message -> serverversion = $CFG -> version ;
$message -> serverrelease = $CFG -> release ;
$message -> backupversion = $info -> backup_moodle_version ;
$message -> backuprelease = $info -> backup_moodle_release ;
2005-01-28 00:01:20 +00:00
print_simple_box ( get_string ( 'noticenewerbackup' , '' , $message ), " center " , " 70% " , '' , " 20 " , " noticebox " );
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
}
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
//Now we print in other table, the backup and the course it contains info
if ( $info and $course_header and $status ) {
//First, the course info
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
$status = restore_print_course_header ( $course_header );
}
2005-01-27 02:35:10 +00:00
//Now, the backup info
if ( $status ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
$status = restore_print_info ( $info );
}
2005-01-27 02:35:10 +00:00
}
}
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
//Save course header and info into php session
if ( $status ) {
$SESSION -> info = $info ;
$SESSION -> course_header = $course_header ;
}
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
//Finally, a little form to continue
//with some hidden fields
if ( $status ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2007-03-01 02:46:04 +00:00
echo " <br /><div style='text-align:center'> " ;
2005-01-27 02:35:10 +00:00
$hidden [ " backup_unique_code " ] = $backup_unique_code ;
$hidden [ " launch " ] = " form " ;
$hidden [ " file " ] = $file ;
$hidden [ " id " ] = $id ;
print_single_button ( " restore.php " , $hidden , get_string ( " continue " ), " post " );
2007-03-01 02:46:04 +00:00
echo " </div> " ;
2005-01-27 02:35:10 +00:00
}
else {
2006-01-15 21:09:13 +00:00
if ( empty ( $noredirect )) {
redirect ( $CFG -> wwwroot . '/backup/restore.php?backup_unique_code=' . $backup_unique_code . '&launch=form&file=' . $file . '&id=' . $id );
} else {
return $backup_unique_code ;
}
2005-01-27 02:35:10 +00:00
}
}
2007-07-28 09:23:32 +00:00
2005-01-27 02:35:10 +00:00
if ( ! $status ) {
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
error ( " An error has ocurred " );
} else {
$errorstr = " An error has occured " ; // helpful! :P
return false ;
}
2005-01-27 02:35:10 +00:00
}
return true ;
}
function restore_setup_for_check ( & $restore , $backup_unique_code ) {
global $SESSION ;
$restore -> backup_unique_code = $backup_unique_code ;
$restore -> users = 2 ; // yuk
2005-09-08 21:30:42 +00:00
$restore -> course_files = $SESSION -> restore -> restore_course_files ;
2007-08-09 21:50:59 +00:00
$restore -> site_files = $SESSION -> restore -> restore_site_files ;
2005-01-27 02:35:10 +00:00
if ( $allmods = get_records ( " modules " )) {
foreach ( $allmods as $mod ) {
$modname = $mod -> name ;
$var = " restore_ " . $modname ;
//Now check that we have that module info in the backup file
if ( isset ( $SESSION -> info -> mods [ $modname ]) && $SESSION -> info -> mods [ $modname ] -> backup == " true " ) {
2007-07-28 09:23:32 +00:00
$restore -> $var = 1 ;
2005-01-27 02:35:10 +00:00
}
}
}
2006-01-15 21:09:13 +00:00
return true ;
2005-01-27 02:35:10 +00:00
}
function backup_to_restore_array ( $backup , $k = 0 ) {
if ( is_array ( $backup ) ) {
foreach ( $backup as $key => $value ) {
$newkey = str_replace ( 'backup' , 'restore' , $key );
$restore [ $newkey ] = backup_to_restore_array ( $value , $key );
}
}
2007-07-28 09:23:32 +00:00
else if ( is_object ( $backup )) {
2005-01-27 02:35:10 +00:00
$tmp = get_object_vars ( $backup );
foreach ( $tmp as $key => $value ) {
$newkey = str_replace ( 'backup' , 'restore' , $key );
2007-07-28 09:23:32 +00:00
$restore -> $newkey = backup_to_restore_array ( $value , $key );
2005-01-27 02:35:10 +00:00
}
}
else {
$newkey = str_replace ( 'backup' , 'restore' , $k );
$restore = $backup ;
}
return $restore ;
}
2007-07-28 09:23:32 +00:00
/**
2006-01-13 03:45:31 +00:00
* compatibility function
2007-07-28 09:23:32 +00:00
* checks for per - instance backups AND
2006-01-13 03:45:31 +00:00
* older per - module backups
* and returns whether userdata has been selected .
*/
function restore_userdata_selected ( $restore , $modname , $modid ) {
// check first for per instance array
2006-11-01 03:32:04 +00:00
if ( ! empty ( $restore -> mods [ $modname ] -> granular )) { // supports per instance
2007-07-28 09:23:32 +00:00
return array_key_exists ( $modid , $restore -> mods [ $modname ] -> instances )
2006-01-13 03:45:31 +00:00
&& ! empty ( $restore -> mods [ $modname ] -> instances [ $modid ] -> userinfo );
}
2007-07-28 09:23:32 +00:00
2007-08-20 04:15:49 +00:00
//print_object($restore->mods[$modname]);
2006-01-13 03:45:31 +00:00
return ! empty ( $restore -> mods [ $modname ] -> userinfo );
}
2006-01-15 21:09:13 +00:00
function restore_execute ( & $restore , $info , $course_header , & $errorstr ) {
2007-07-28 09:23:32 +00:00
2006-10-10 03:17:49 +00:00
global $CFG , $USER ;
2007-07-28 09:23:32 +00:00
$status = true ;
2006-01-15 21:09:13 +00:00
//Checks for the required files/functions to restore every module
//and include them
if ( $allmods = get_records ( " modules " ) ) {
foreach ( $allmods as $mod ) {
$modname = $mod -> name ;
$modfile = " $CFG->dirroot /mod/ $modname /restorelib.php " ;
//If file exists and we have selected to restore that type of module
2007-07-28 09:23:32 +00:00
if (( file_exists ( $modfile )) and ! empty ( $restore -> mods [ $modname ]) and ( $restore -> mods [ $modname ] -> restore )) {
2006-01-15 21:09:13 +00:00
include_once ( $modfile );
}
}
}
if ( ! defined ( 'RESTORE_SILENTLY' )) {
//Start the main table
echo " <table cellpadding= \" 5 \" > " ;
echo " <tr><td> " ;
2007-07-28 09:23:32 +00:00
2006-01-15 21:09:13 +00:00
//Start the main ul
echo " <ul> " ;
}
2007-07-28 09:23:32 +00:00
2006-01-15 21:09:13 +00:00
//Localtion of the xml file
2006-09-25 09:10:19 +00:00
$xml_file = $CFG -> dataroot . " /temp/backup/ " . $restore -> backup_unique_code . " /moodle.xml " ;
2007-07-28 09:23:32 +00:00
2006-01-15 21:09:13 +00:00
//If we've selected to restore into new course
//create it (course)
//Saving conversion id variables into backup_tables
if ( $restore -> restoreto == 2 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2007-01-16 01:06:11 +00:00
echo '<li>' . get_string ( 'creatingnewcourse' ) . '</li>' ;
2006-01-15 21:09:13 +00:00
}
$oldidnumber = $course_header -> course_idnumber ;
if ( ! $status = restore_create_new_course ( $restore , $course_header )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Error while creating the new empty course. " );
} else {
$errorstr = " Error while creating the new empty course. " ;
return false ;
}
}
2007-07-28 09:23:32 +00:00
2006-01-15 21:09:13 +00:00
//Print course fullname and shortname and category
if ( $status ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <ul> " ;
echo " <li> " . $course_header -> course_fullname . " ( " . $course_header -> course_shortname . " ) " . '</li>' ;
echo " <li> " . get_string ( " category " ) . " : " . $course_header -> category -> name . '</li>' ;
if ( ! empty ( $oldidnumber )) {
echo " <li> " . get_string ( " nomoreidnumber " , " moodle " , $oldidnumber ) . " </li> " ;
}
2007-01-16 01:06:11 +00:00
echo " </ul> " ;
2006-01-15 21:09:13 +00:00
//Put the destination course_id
}
$restore -> course_id = $course_header -> course_id ;
}
2006-09-13 09:40:55 +00:00
if ( $status = restore_open_html ( $restore , $course_header )){
2006-10-04 14:50:50 +00:00
echo " <li>Creating the Restorelog.html in the course backup folder</li> " ;
2006-09-13 09:40:55 +00:00
}
2006-01-15 21:09:13 +00:00
} else {
$course = get_record ( " course " , " id " , $restore -> course_id );
if ( $course ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2007-07-28 09:23:32 +00:00
echo " <li> " . get_string ( " usingexistingcourse " );
2006-01-15 21:09:13 +00:00
echo " <ul> " ;
echo " <li> " . get_string ( " from " ) . " : " . $course_header -> course_fullname . " ( " . $course_header -> course_shortname . " ) " . '</li>' ;
2007-02-28 06:25:22 +00:00
echo " <li> " . get_string ( " to " ) . " : " . format_string ( $course -> fullname ) . " ( " . format_string ( $course -> shortname ) . " ) " . '</li>' ;
2006-01-15 21:09:13 +00:00
if (( $restore -> deleting )) {
echo " <li> " . get_string ( " deletingexistingcoursedata " ) . '</li>' ;
} else {
echo " <li> " . get_string ( " addingdatatoexisting " ) . '</li>' ;
}
echo " </ul></li> " ;
}
//If we have selected to restore deleting, we do it now.
if ( $restore -> deleting ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " deletingolddata " ) . '</li>' ;
}
2007-07-28 09:23:32 +00:00
$status = remove_course_contents ( $restore -> course_id , false ) and
2006-01-15 21:09:13 +00:00
delete_dir_contents ( $CFG -> dataroot . " / " . $restore -> course_id , " backupdata " );
if ( $status ) {
//Now , this situation is equivalent to the "restore to new course" one (we
//have a course record and nothing more), so define it as "to new course"
$restore -> restoreto = 2 ;
} else {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " An error occurred while deleting some of the course contents. " );
} else {
$errrostr = " An error occurred while deleting some of the course contents. " ;
return false ;
}
}
}
} else {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Error opening existing course. " );
$status = false ;
} else {
$errorstr = " Error opening existing course. " ;
return false ;
}
}
}
2007-07-28 09:23:32 +00:00
//Now create users as needed
2006-01-15 21:09:13 +00:00
if ( $status and ( $restore -> users == 0 or $restore -> users == 1 )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " creatingusers " ) . " <br /> " ;
}
if ( ! $status = restore_create_users ( $restore , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not restore users. " );
} else {
$errorstr = " Could not restore users. " ;
return false ;
}
}
2007-07-28 09:23:32 +00:00
2006-01-15 21:09:13 +00:00
//Now print info about the work done
if ( $status ) {
$recs = get_records_sql ( " select old_id, new_id from { $CFG -> prefix } backup_ids
where backup_code = '$restore->backup_unique_code' and
table_name = 'user' " );
//We've records
if ( $recs ) {
$new_count = 0 ;
$exists_count = 0 ;
$student_count = 0 ;
$teacher_count = 0 ;
$counter = 0 ;
//Iterate, filling counters
foreach ( $recs as $rec ) {
//Get full record, using backup_getids
$record = backup_getid ( $restore -> backup_unique_code , " user " , $rec -> old_id );
if ( strpos ( $record -> info , " new " ) !== false ) {
$new_count ++ ;
2007-07-28 09:23:32 +00:00
}
2006-01-15 21:09:13 +00:00
if ( strpos ( $record -> info , " exists " ) !== false ) {
$exists_count ++ ;
}
if ( strpos ( $record -> info , " student " ) !== false ) {
$student_count ++ ;
} else if ( strpos ( $record -> info , " teacher " ) !== false ) {
$teacher_count ++ ;
}
//Do some output
$counter ++ ;
if ( $counter % 10 == 0 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " . " ;
if ( $counter % 200 == 0 ) {
echo " <br /> " ;
}
}
backup_flush ( 300 );
}
}
if ( ! defined ( 'RESTORE_SILENTLY' )) {
//Now print information gathered
echo " ( " . get_string ( " new " ) . " : " . $new_count . " , " . get_string ( " existing " ) . " : " . $exists_count . " ) " ;
echo " <ul> " ;
echo " <li> " . get_string ( " students " ) . " : " . $student_count . '</li>' ;
echo " <li> " . get_string ( " teachers " ) . " : " . $teacher_count . '</li>' ;
echo " </ul> " ;
}
} else {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " No users were found! " );
} // no need to return false here, it's recoverable.
}
}
2007-07-28 09:23:32 +00:00
2007-03-01 02:46:04 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " </li> " ;
}
2006-01-15 21:09:13 +00:00
}
2007-07-28 09:23:32 +00:00
2007-08-15 10:43:25 +00:00
//Now create groups as needed
if ( $status ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " creatinggroups " );
}
if ( ! $status = restore_create_groups ( $restore , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not restore groups! " );
} else {
$errorstr = " Could not restore groups! " ;
return false ;
}
}
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
}
//Now create groupings as needed
if ( $status ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " creatinggroupings " );
}
if ( ! $status = restore_create_groupings ( $restore , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not restore groupings! " );
} else {
$errorstr = " Could not restore groupings! " ;
return false ;
}
}
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
}
//Now create groupingsgroups as needed
if ( $status ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " creatinggroupingsgroups " );
}
if ( ! $status = restore_create_groupings_groups ( $restore , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not restore groups in groupings! " );
} else {
$errorstr = " Could not restore groups in groupings! " ;
return false ;
}
}
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
}
//Now create the course_sections and their associated course_modules
//we have to do this after groups and groupings are restored, because we need the new groupings id
if ( $status ) {
//Into new course
if ( $restore -> restoreto == 2 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " creatingsections " );
}
if ( ! $status = restore_create_sections ( $restore , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Error creating sections in the existing course. " );
} else {
$errorstr = " Error creating sections in the existing course. " ;
return false ;
}
}
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
//Into existing course
} else if ( $restore -> restoreto == 0 or $restore -> restoreto == 1 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " checkingsections " );
}
if ( ! $status = restore_create_sections ( $restore , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Error creating sections in the existing course. " );
} else {
$errorstr = " Error creating sections in the existing course. " ;
return false ;
}
}
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
//Error
} else {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Neither a new course or an existing one was specified. " );
$status = false ;
} else {
$errorstr = " Neither a new course or an existing one was specified. " ;
return false ;
}
}
}
2006-01-15 21:09:13 +00:00
//Now create metacourse info
if ( $status and $restore -> metacourse ) {
//Only to new courses!
if ( $restore -> restoreto == 2 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2007-03-01 02:46:04 +00:00
echo " <li> " . get_string ( " creatingmetacoursedata " );
2006-01-15 21:09:13 +00:00
}
if ( ! $status = restore_create_metacourse ( $restore , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Error creating metacourse in the course. " );
} else {
$errorstr = " Error creating metacourse in the course. " ;
return false ;
}
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-01-15 21:09:13 +00:00
}
}
2007-07-28 09:23:32 +00:00
2006-01-15 21:09:13 +00:00
2006-03-13 00:18:38 +00:00
//Now create categories and questions as needed
2007-08-09 21:50:59 +00:00
if ( $status ) {
2006-03-13 00:18:38 +00:00
include_once ( " $CFG->dirroot /question/restorelib.php " );
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-12-19 07:00:14 +00:00
echo " <li> " . get_string ( " creatingcategoriesandquestions " );
2006-01-15 21:09:13 +00:00
echo " <ul> " ;
}
if ( ! $status = restore_create_questions ( $restore , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not restore categories and questions! " );
} else {
$errorstr = " Could not restore categories and questions! " ;
return false ;
}
}
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " </ul></li> " ;
}
}
//Now create user_files as needed
if ( $status and ( $restore -> user_files )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " copyinguserfiles " );
}
if ( ! $status = restore_user_files ( $restore )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not restore user files! " );
} else {
$errorstr = " Could not restore user files! " ;
return false ;
}
}
//If all is ok (and we have a counter)
if ( $status and ( $status !== true )) {
//Inform about user dirs created from backup
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <ul> " ;
echo " <li> " . get_string ( " userzones " ) . " : " . $status ;
echo " </li></ul> " ;
}
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-01-15 21:09:13 +00:00
}
//Now create course files as needed
if ( $status and ( $restore -> course_files )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2007-03-01 02:46:04 +00:00
echo " <li> " . get_string ( " copyingcoursefiles " );
2006-01-15 21:09:13 +00:00
}
if ( ! $status = restore_course_files ( $restore )) {
if ( empty ( $status )) {
notify ( " Could not restore course files! " );
} else {
$errorstr = " Could not restore course files! " ;
return false ;
}
}
//If all is ok (and we have a counter)
if ( $status and ( $status !== true )) {
//Inform about user dirs created from backup
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <ul> " ;
2006-12-19 07:00:14 +00:00
echo " <li> " . get_string ( " filesfolders " ) . " : " . $status . '</li>' ;
2006-01-15 21:09:13 +00:00
echo " </ul> " ;
2007-07-28 09:23:32 +00:00
}
2006-01-15 21:09:13 +00:00
}
2007-03-01 02:46:04 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " </li> " ;
}
2006-01-15 21:09:13 +00:00
}
2007-08-09 21:50:59 +00:00
//Now create site files as needed
if ( $status and ( $restore -> site_files )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( 'copyingsitefiles' );
}
if ( ! $status = restore_site_files ( $restore )) {
if ( empty ( $status )) {
notify ( " Could not restore site files! " );
} else {
$errorstr = " Could not restore site files! " ;
return false ;
}
}
//If all is ok (and we have a counter)
if ( $status and ( $status !== true )) {
//Inform about user dirs created from backup
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <ul> " ;
echo " <li> " . get_string ( " filesfolders " ) . " : " . $status . '</li>' ;
echo " </ul> " ;
}
}
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " </li> " ;
}
}
2006-01-15 21:09:13 +00:00
//Now create messages as needed
if ( $status and ( $restore -> messages )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " creatingmessagesinfo " );
}
if ( ! $status = restore_create_messages ( $restore , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not restore messages! " );
} else {
$errorstr = " Could not restore messages! " ;
return false ;
}
}
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " </li> " ;
}
}
//Now create scales as needed
if ( $status ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-12-19 07:00:14 +00:00
echo " <li> " . get_string ( " creatingscales " );
2006-01-15 21:09:13 +00:00
}
if ( ! $status = restore_create_scales ( $restore , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not restore custom scales! " );
} else {
$errorstr = " Could not restore custom scales! " ;
return false ;
}
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-01-15 21:09:13 +00:00
}
//Now create events as needed
if ( $status ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-12-19 07:00:14 +00:00
echo " <li> " . get_string ( " creatingevents " );
2006-01-15 21:09:13 +00:00
}
if ( ! $status = restore_create_events ( $restore , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not restore course events! " );
} else {
$errorstr = " Could not restore course events! " ;
return false ;
}
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-01-15 21:09:13 +00:00
}
//Now create course modules as needed
if ( $status ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-12-19 07:00:14 +00:00
echo " <li> " . get_string ( " creatingcoursemodules " );
2007-07-28 09:23:32 +00:00
}
2006-01-15 21:09:13 +00:00
if ( ! $status = restore_create_modules ( $restore , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not restore modules! " );
} else {
$errorstr = " Could not restore modules! " ;
return false ;
}
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-01-15 21:09:13 +00:00
}
//Now create gradebook as needed -- AFTER modules!!!
if ( $status ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-12-19 07:00:14 +00:00
echo " <li> " . get_string ( " creatinggradebook " );
2007-07-28 09:23:32 +00:00
}
2006-01-15 21:09:13 +00:00
if ( ! $status = restore_create_gradebook ( $restore , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not restore gradebook! " );
} else {
$errorstr = " Could not restore gradebook! " ;
return false ;
}
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-01-15 21:09:13 +00:00
}
2007-09-06 05:04:55 +00:00
2006-01-15 21:09:13 +00:00
//Bring back the course blocks -- do it AFTER the modules!!!
if ( $status ) {
//If we are deleting and bringing into a course or making a new course, same situation
if ( $restore -> restoreto == 0 || $restore -> restoreto == 2 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-12-19 07:00:14 +00:00
echo '<li>' . get_string ( 'creatingblocks' );
2006-01-15 21:09:13 +00:00
}
2006-06-03 20:18:02 +00:00
$course_header -> blockinfo = ! empty ( $course_header -> blockinfo ) ? $course_header -> blockinfo : NULL ;
2006-01-15 21:09:13 +00:00
if ( ! $status = restore_create_blocks ( $restore , $info -> backup_block_format , $course_header -> blockinfo , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( 'Error while creating the course blocks' );
} else {
$errorstr = " Error while creating the course blocks " ;
return false ;
}
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-01-15 21:09:13 +00:00
}
}
2006-12-11 15:47:23 +00:00
if ( $status ) {
//If we are deleting and bringing into a course or making a new course, same situation
if ( $restore -> restoreto == 0 || $restore -> restoreto == 2 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-12-19 07:00:14 +00:00
echo '<li>' . get_string ( 'courseformatdata' );
2006-12-11 15:47:23 +00:00
}
if ( ! $status = restore_set_format_data ( $restore , $xml_file )) {
$error = " Error while setting the course format data " ;
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( $error );
} else {
$errorstr = $error ;
return false ;
}
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-12-11 15:47:23 +00:00
}
}
2006-01-15 21:09:13 +00:00
//Now create log entries as needed
if ( $status and ( $restore -> logs )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-12-19 07:00:14 +00:00
echo " <li> " . get_string ( " creatinglogentries " );
2006-01-15 21:09:13 +00:00
}
if ( ! $status = restore_create_logs ( $restore , $xml_file )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not restore logs! " );
} else {
$errorstr = " Could not restore logs! " ;
return false ;
}
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2007-07-28 09:23:32 +00:00
}
2006-01-15 21:09:13 +00:00
//Now, if all is OK, adjust the instance field in course_modules !!
if ( $status ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-12-19 07:00:14 +00:00
echo " <li> " . get_string ( " checkinginstances " );
2006-01-15 21:09:13 +00:00
}
if ( ! $status = restore_check_instances ( $restore )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not adjust instances in course_modules! " );
} else {
$errorstr = " Could not adjust instances in course_modules! " ;
return false ;
}
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-01-15 21:09:13 +00:00
}
//Now, if all is OK, adjust activity events
if ( $status ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-12-19 07:00:14 +00:00
echo " <li> " . get_string ( " refreshingevents " );
2006-01-15 21:09:13 +00:00
}
if ( ! $status = restore_refresh_events ( $restore )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not refresh events for activities! " );
} else {
$errorstr = " Could not refresh events for activities! " ;
return false ;
}
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-01-15 21:09:13 +00:00
}
//Now, if all is OK, adjust inter-activity links
if ( $status ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " decodinginternallinks " );
}
if ( ! $status = restore_decode_content_links ( $restore )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2007-04-19 17:16:20 +00:00
notify ( " Could not decode content links! " );
2006-01-15 21:09:13 +00:00
} else {
2007-04-19 17:16:20 +00:00
$errorstr = " Could not decode content links! " ;
2006-01-15 21:09:13 +00:00
return false ;
}
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-01-15 21:09:13 +00:00
}
//Now, with backup files prior to version 2005041100,
//convert all the wiki texts in the course to markdown
if ( $status && $restore -> backup_version < 2005041100 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " convertingwikitomarkdown " );
}
if ( ! $status = restore_convert_wiki2markdown ( $restore )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not convert wiki texts to markdown! " );
} else {
$errorstr = " Could not convert wiki texts to markdown! " ;
return false ;
}
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-01-15 21:09:13 +00:00
}
2007-09-06 05:04:55 +00:00
// for moodle versions before 1.9, those grades need to be converted to use the new gradebook
// this code needs to execute *after* the course_modules are sorted out
if ( $status && $restore -> backup_version < 2007090500 ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " migratinggrades " );
}
// we need need to worry about mods that are restored
// the others in the course are not relevent
if ( ! empty ( $restore -> mods )) {
require_once ( $CFG -> dirroot . '/lib/gradelib.php' );
foreach ( $restore -> mods as $mod => $modtype ) {
if ( ! empty ( $modtype -> instances )) {
foreach ( $modtype -> instances as $modinstance ) {
$sql = " SELECT a.*, cm.idnumber as cmidnumber, m.name as modname
FROM { $CFG -> prefix } $mod a ,
{ $CFG -> prefix } course_modules cm ,
{ $CFG -> prefix } modules m
WHERE m . name = '$mod'
AND m . id = cm . module
AND cm . instance = a . id
AND cm . id = { $modinstance -> restored_as_course_module } " ;
if ( $module = get_record_sql ( $sql )) {
grade_update_mod_grades ( $module );
}
}
}
}
}
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
}
2006-01-15 21:09:13 +00:00
2006-10-10 03:17:49 +00:00
/*******************************************************************************
************* Restore of Roles and Capabilities happens here ******************
*******************************************************************************/
2007-08-28 16:30:39 +00:00
// try to restore roles even when restore is going to fail - teachers might have
// at least some role assigned - this is not correct though
$status = restore_create_roles ( $restore , $xml_file ) && $status ;
$status = restore_roles_settings ( $restore , $xml_file ) && $status ;
2006-10-10 03:17:49 +00:00
2006-01-15 21:09:13 +00:00
//Now if all is OK, update:
2007-07-28 09:23:32 +00:00
// - course modinfo field
2006-01-15 21:09:13 +00:00
// - categories table
// - add user as teacher
if ( $status ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-12-19 07:00:14 +00:00
echo " <li> " . get_string ( " checkingcourse " );
2007-07-28 09:23:32 +00:00
}
2006-01-15 21:09:13 +00:00
//modinfo field
rebuild_course_cache ( $restore -> course_id );
//categories table
2007-07-28 09:23:32 +00:00
$course = get_record ( " course " , " id " , $restore -> course_id );
2006-01-15 21:09:13 +00:00
fix_course_sortorder ();
2006-10-10 03:17:49 +00:00
// Check if the user has course update capability in the newly restored course
// there is no need to load his capabilities again, because restore_roles_settings
2007-07-28 09:23:32 +00:00
// would have loaded it anyway, if there is any assignments.
2006-10-10 03:17:49 +00:00
// fix for MDL-6831
$newcontext = get_context_instance ( CONTEXT_COURSE , $restore -> course_id );
2006-10-12 06:58:14 +00:00
if ( ! has_capability ( 'moodle/course:manageactivities' , $newcontext )) {
2007-07-28 09:23:32 +00:00
// fix for MDL-9065, use the new config setting if exists
2007-03-28 02:31:24 +00:00
if ( $CFG -> creatornewroleid ) {
role_assign ( $CFG -> creatornewroleid , $USER -> id , 0 , $newcontext -> id );
2006-10-10 03:17:49 +00:00
} else {
2007-03-28 02:31:24 +00:00
if ( $legacyteachers = get_roles_with_capability ( 'moodle/legacy:editingteacher' , CAP_ALLOW , get_context_instance ( CONTEXT_SYSTEM , SITEID ))) {
if ( $legacyteacher = array_shift ( $legacyteachers )) {
role_assign ( $legacyteacher -> id , $USER -> id , 0 , $newcontext -> id );
}
} else {
notify ( 'Could not find a legacy teacher role. You might need your moodle admin to assign a role with editing privilages to this course.' );
}
2006-10-10 03:17:49 +00:00
}
2006-01-15 21:09:13 +00:00
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-01-15 21:09:13 +00:00
}
//Cleanup temps (files and db)
if ( $status ) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
2006-12-19 07:00:14 +00:00
echo " <li> " . get_string ( " cleaningtempdata " );
2006-01-15 21:09:13 +00:00
}
if ( ! $status = clean_temp_data ( $restore )) {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not clean up temporary data from files and database " );
} else {
$errorstr = " Could not clean up temporary data from files and database " ;
return false ;
}
}
2006-12-19 07:00:14 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '</li>' ;
}
2006-01-15 21:09:13 +00:00
}
2007-08-28 16:30:39 +00:00
// this is not a critical check - the result can be ignored
if ( restore_close_html ( $restore )){
2007-03-23 06:14:40 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo '<li>Closing the Restorelog.html file.</li>' ;
}
}
else {
if ( ! defined ( 'RESTORE_SILENTLY' )) {
notify ( " Could not close the restorelog.html file " );
}
2006-09-13 09:40:55 +00:00
}
2006-01-15 21:09:13 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
//End the main ul
echo " </ul> " ;
2007-07-28 09:23:32 +00:00
2006-12-19 05:02:22 +00:00
//End the main table
2006-01-15 21:09:13 +00:00
echo " </td></tr> " ;
echo " </table> " ;
}
return $status ;
}
2006-09-13 09:40:55 +00:00
//Create, open and write header of the html log file
function restore_open_html ( $restore , $course_header ) {
global $CFG ;
2007-07-28 09:23:32 +00:00
2006-09-13 09:40:55 +00:00
$status = true ;
2007-07-28 09:23:32 +00:00
//Open file for writing
2006-10-04 14:50:50 +00:00
//First, we check the course_id backup data folder exists and create it as necessary in CFG->dataroot
if ( ! $dest_dir = make_upload_directory ( " $restore->course_id /backupdata " )) { // Backup folder
error ( " Could not create backupdata folder. The site administrator needs to fix the file permissions " );
}
2006-09-13 09:40:55 +00:00
$status = check_dir_exists ( $dest_dir , true );
2007-07-28 09:23:32 +00:00
$restorelog_file = fopen ( " $dest_dir /restorelog.html " , " a " );
2006-10-04 14:50:50 +00:00
//Add the stylesheet
2007-07-28 09:23:32 +00:00
$stylesheetshtml = '' ;
2006-10-04 14:50:50 +00:00
foreach ( $CFG -> stylesheets as $stylesheet ) {
$stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="' . $stylesheet . '" />' . " \n " ;
}
///Accessibility: added the 'lang' attribute to $direction, used in theme <html> tag.
2007-02-21 10:42:50 +00:00
$languagehtml = get_html_lang ( $dir = true );
2006-09-13 09:40:55 +00:00
//Write the header in the new logging file
fwrite ( $restorelog_file , " <!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN \" " );
fwrite ( $restorelog_file , " \" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd \" > " );
2006-10-04 14:50:50 +00:00
fwrite ( $restorelog_file , " <html dir= \" ltr \" . $languagehtml . " );
fwrite ( $restorelog_file , " <head> " );
2007-07-28 09:23:32 +00:00
fwrite ( $restorelog_file , $stylesheetshtml );
2006-09-13 09:40:55 +00:00
fwrite ( $restorelog_file , " <title> " . $course_header -> course_shortname . " Restored </title> " );
2007-01-04 23:38:17 +00:00
fwrite ( $restorelog_file , " </head><body><br/><h1>The following changes were made during the Restoration of this Course.</h1><br/><br/> " );
fwrite ( $restorelog_file , " The Course ShortName is now - " . $course_header -> course_shortname . " The FullName is now - " . $course_header -> course_fullname . " <br/><br/> " );
2006-09-13 09:40:55 +00:00
$startdate = addslashes ( $course_header -> course_startdate );
$date = usergetdate ( $startdate );
fwrite ( $restorelog_file , " The Originating Courses Start Date was " . $date [ 'weekday' ] . " , " . $date [ 'mday' ] . " " . $date [ 'month' ] . " " . $date [ 'year' ] . " " );
$startdate += $restore -> course_startdateoffset ;
$date = usergetdate ( $startdate );
2007-01-04 23:38:17 +00:00
fwrite ( $restorelog_file , " This Courses Start Date is now " . $date [ 'weekday' ] . " , " . $date [ 'mday' ] . " " . $date [ 'month' ] . " " . $date [ 'year' ] . " <br/><br/> " );
2006-09-13 09:40:55 +00:00
if ( $status ) {
return $restorelog_file ;
} else {
return false ;
}
}
//Create & close footer of the html log file
function restore_close_html ( $restore ) {
global $CFG ;
2007-07-28 09:23:32 +00:00
2006-09-13 09:40:55 +00:00
$status = true ;
2007-07-28 09:23:32 +00:00
//Open file for writing
2006-10-04 14:50:50 +00:00
//First, check that course_id/backupdata folder exists in CFG->dataroot
$dest_dir = $CFG -> dataroot . " / " . $restore -> course_id . " /backupdata " ;
2006-12-05 18:42:39 +00:00
$status = check_dir_exists ( $dest_dir , true , true );
2006-10-04 14:50:50 +00:00
$restorelog_file = fopen ( " $dest_dir /restorelog.html " , " a " );
2006-09-13 09:40:55 +00:00
//Write the footer to close the logging file
2007-01-04 23:38:17 +00:00
fwrite ( $restorelog_file , " <br/>This file was written to directly by each modules restore process. " );
fwrite ( $restorelog_file , " <br/><br/>Log complete.</body></html> " );
2007-07-28 09:23:32 +00:00
2006-09-13 09:40:55 +00:00
if ( $status ) {
return $restorelog_file ;
} else {
return false ;
}
}
2007-07-28 09:23:32 +00:00
2006-09-28 09:15:14 +00:00
/********************** Roles and Capabilities Related Functions *******************************/
2007-07-28 09:23:32 +00:00
/* Yu : Note recovering of role assignments / overrides need to take place after
users have been recovered , i . e . after we get their new_id , and after all
2006-09-28 09:15:14 +00:00
roles have been recreated or mapped . Contexts can be created on the fly .
The current order of restore is Restore ( old ) -> restore roles -> restore assignment / overrides
the order of restore among different contexts , i . e . course , mod , blocks , users should not matter
once roles and users have been restored .
*/
2007-07-28 09:23:32 +00:00
2006-09-28 09:15:14 +00:00
/**
* This function restores all the needed roles for this course
2007-07-28 09:23:32 +00:00
* i . e . roles with an assignment in any of the mods or blocks ,
2006-09-28 09:15:14 +00:00
* roles assigned on any user ( e . g . parent role ) and roles
* assigned at course levle
* This function should check for duplicate roles first
* It isn ' t now , just overwriting
*/
2006-09-25 09:10:19 +00:00
function restore_create_roles ( $restore , $xmlfile ) {
2006-10-02 08:49:07 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " creatingrolesdefinitions " ) . '</li>' ;
}
$info = restore_read_xml_roles ( $xmlfile );
2006-09-26 06:02:10 +00:00
2006-09-25 09:10:19 +00:00
$sitecontext = get_context_instance ( CONTEXT_SYSTEM , SITEID );
2006-01-15 21:09:13 +00:00
2006-09-28 09:15:14 +00:00
// the following code creates new roles
// but we could use more intelligent detection, and role mapping
// get role mapping info from $restore
2006-12-19 05:02:22 +00:00
$rolemappings = array ();
2006-09-28 09:15:14 +00:00
2006-12-19 05:02:22 +00:00
if ( ! empty ( $restore -> rolesmapping )) {
$rolemappings = $restore -> rolesmapping ;
}
2007-03-09 02:39:44 +00:00
// $info->roles will be empty for backups pre 1.7
2006-12-19 05:02:22 +00:00
if ( isset ( $info -> roles ) && $info -> roles ) {
2007-07-28 09:23:32 +00:00
2007-03-09 02:39:44 +00:00
foreach ( $info -> roles as $oldroleid => $roledata ) {
2007-07-28 09:23:32 +00:00
if ( empty ( $restore -> rolesmapping )) {
2007-03-09 02:39:44 +00:00
// if this is empty altogether, we came from import or there's no roles used in course at all
// in this case, write the same oldid as this is the same site
// no need to do mapping
$status = backup_putid ( $restore -> backup_unique_code , " role " , $oldroleid ,
2007-07-28 09:23:32 +00:00
$oldroleid ); // adding a new id
2007-03-09 02:39:44 +00:00
continue ; // do not create additonal roles;
}
// first we check if the roles are in the mappings
2006-10-02 08:49:07 +00:00
// if so, we just do a mapping i.e. update oldids table
2006-10-03 08:54:46 +00:00
if ( isset ( $rolemappings [ $oldroleid ]) && $rolemappings [ $oldroleid ]) {
$status = backup_putid ( $restore -> backup_unique_code , " role " , $oldroleid ,
2007-07-28 09:23:32 +00:00
$rolemappings [ $oldroleid ]); // adding a new id
2006-10-03 08:54:46 +00:00
} else {
2007-07-28 09:23:32 +00:00
2006-10-03 08:54:46 +00:00
// code to make new role name/short name if same role name or shortname exists
$fullname = $roledata -> name ;
$shortname = $roledata -> shortname ;
$currentfullname = " " ;
$currentshortname = " " ;
$counter = 0 ;
2007-07-28 09:23:32 +00:00
2006-10-03 08:54:46 +00:00
do {
if ( $counter ) {
$suffixfull = " " . get_string ( " copyasnoun " ) . " " . $counter ;
$suffixshort = " _ " . $counter ;
} else {
$suffixfull = " " ;
$suffixshort = " " ;
}
$currentfullname = $fullname . $suffixfull ;
// Limit the size of shortname - database column accepts <= 15 chars
$currentshortname = substr ( $shortname , 0 , 15 - strlen ( $suffixshort )) . $suffixshort ;
$coursefull = get_record ( " role " , " name " , addslashes ( $currentfullname ));
$courseshort = get_record ( " role " , " shortname " , addslashes ( $currentshortname ));
$counter ++ ;
} while ( $coursefull || $courseshort );
$roledata -> name = $currentfullname ;
2007-07-28 09:23:32 +00:00
$roledata -> shortname = $currentshortname ;
2006-10-03 08:54:46 +00:00
// done finding a unique name
2007-07-28 09:23:32 +00:00
2006-11-20 14:08:40 +00:00
$newroleid = create_role ( addslashes ( $roledata -> name ), addslashes ( $roledata -> shortname ), '' );
2006-10-03 08:54:46 +00:00
$status = backup_putid ( $restore -> backup_unique_code , " role " , $oldroleid ,
2006-09-26 06:02:10 +00:00
$newroleid ); // adding a new id
2006-10-03 08:54:46 +00:00
foreach ( $roledata -> capabilities as $capability ) {
2007-07-28 09:23:32 +00:00
2006-10-03 08:54:46 +00:00
$roleinfo = new object ();
$roleinfo = ( object ) $capability ;
$roleinfo -> contextid = $sitecontext -> id ;
$roleinfo -> capability = $capability -> name ;
$roleinfo -> roleid = $newroleid ;
2007-07-28 09:23:32 +00:00
2006-10-03 08:54:46 +00:00
insert_record ( 'role_capabilities' , $roleinfo );
}
2006-10-02 08:49:07 +00:00
}
2006-09-25 09:10:19 +00:00
}
2006-09-26 06:02:10 +00:00
}
2006-10-10 03:17:49 +00:00
return true ;
2006-09-25 09:10:19 +00:00
}
2007-07-28 09:23:32 +00:00
2006-09-28 09:15:14 +00:00
/**
* this function restores role assignments and role overrides
* in course / user / block / mod level , it passed through
* the xml file again
*/
function restore_roles_settings ( $restore , $xmlfile ) {
2006-09-25 09:10:19 +00:00
// data pulls from course, mod, user, and blocks
2007-07-28 09:23:32 +00:00
2006-09-26 06:02:10 +00:00
/*******************************************************
2006-10-02 08:49:07 +00:00
* Restoring from course level assignments *
2006-09-26 06:02:10 +00:00
*******************************************************/
2006-10-02 08:49:07 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " creatingcourseroles " ) . '</li>' ;
}
2006-09-26 06:02:10 +00:00
$course = restore_read_xml_course_header ( $xmlfile );
2007-07-28 09:23:32 +00:00
2007-03-09 02:39:44 +00:00
if ( ! isset ( $restore -> rolesmapping )) {
$isimport = true ; // course import from another course, or course with no role assignments
} else {
$isimport = false ; // course restore with role assignments
}
2007-07-28 09:23:32 +00:00
2007-03-09 02:39:44 +00:00
if ( ! empty ( $course -> roleassignments ) && ! $isimport ) {
2006-10-03 08:54:46 +00:00
$courseassignments = $course -> roleassignments ;
2006-09-26 06:02:10 +00:00
2007-07-28 09:23:32 +00:00
foreach ( $courseassignments as $oldroleid => $courseassignment ) {
2006-10-03 08:54:46 +00:00
restore_write_roleassignments ( $restore , $courseassignment -> assignments , " course " , CONTEXT_COURSE , $course -> course_id , $oldroleid );
}
2006-09-28 09:15:14 +00:00
}
/*****************************************************
2006-10-02 08:49:07 +00:00
* Restoring from course level overrides *
2007-07-28 09:23:32 +00:00
*****************************************************/
2007-03-09 02:39:44 +00:00
if ( ! empty ( $course -> roleoverrides ) && ! $isimport ) {
2006-10-03 08:54:46 +00:00
$courseoverrides = $course -> roleoverrides ;
foreach ( $courseoverrides as $oldroleid => $courseoverride ) {
// if not importing into exiting course, or creating new role, we are ok
// local course overrides to be respected (i.e. restored course overrides ignored)
2006-12-19 05:02:22 +00:00
if ( $restore -> restoreto != 1 || empty ( $restore -> rolesmapping [ $oldroleid ])) {
2006-10-03 08:54:46 +00:00
restore_write_roleoverrides ( $restore , $courseoverride -> overrides , " course " , CONTEXT_COURSE , $course -> course_id , $oldroleid );
}
2006-10-02 08:49:07 +00:00
}
2006-09-28 09:15:14 +00:00
}
2007-07-28 09:23:32 +00:00
2006-09-26 06:02:10 +00:00
/*******************************************************
2006-09-28 09:15:14 +00:00
* Restoring role assignments / overrdies *
* from module level assignments *
2007-07-28 09:23:32 +00:00
*******************************************************/
2006-10-02 08:49:07 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " creatingmodroles " ) . '</li>' ;
}
2006-09-26 09:05:44 +00:00
$sections = restore_read_xml_sections ( $xmlfile );
$secs = $sections -> sections ;
2007-07-28 09:23:32 +00:00
2006-09-26 09:05:44 +00:00
foreach ( $secs as $section ) {
if ( isset ( $section -> mods )) {
foreach ( $section -> mods as $modid => $mod ) {
2007-03-09 02:39:44 +00:00
if ( isset ( $mod -> roleassignments ) && ! $isimport ) {
2006-09-26 09:05:44 +00:00
foreach ( $mod -> roleassignments as $oldroleid => $modassignment ) {
2007-07-28 09:23:32 +00:00
restore_write_roleassignments ( $restore , $modassignment -> assignments , " course_modules " , CONTEXT_MODULE , $modid , $oldroleid );
}
}
2007-03-09 02:39:44 +00:00
// role overrides always applies, in import or backup/restore
2006-09-28 09:15:14 +00:00
if ( isset ( $mod -> roleoverrides )) {
foreach ( $mod -> roleoverrides as $oldroleid => $modoverride ) {
restore_write_roleoverrides ( $restore , $modoverride -> overrides , " course_modules " , CONTEXT_MODULE , $modid , $oldroleid );
}
}
2006-09-26 09:05:44 +00:00
}
}
}
2006-09-28 09:15:14 +00:00
/*************************************************
* Restoring assignments from blocks level *
* role assignments / overrides *
2007-07-28 09:23:32 +00:00
*************************************************/
2006-10-02 08:49:07 +00:00
if ( $restore -> restoreto != 1 ) { // skip altogether if restoring to exisitng course by adding
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " creatingblocksroles " ) . '</li>' ;
}
2007-11-15 05:00:44 +00:00
$blocks = restore_read_xml_blocks ( $restore , $xmlfile );
2006-10-02 08:49:07 +00:00
if ( isset ( $blocks -> instances )) {
foreach ( $blocks -> instances as $instance ) {
2007-03-09 02:39:44 +00:00
if ( isset ( $instance -> roleassignments ) && ! $isimport ) {
2006-10-02 08:49:07 +00:00
foreach ( $instance -> roleassignments as $oldroleid => $blockassignment ) {
restore_write_roleassignments ( $restore , $blockassignment -> assignments , " block_instance " , CONTEXT_BLOCK , $instance -> id , $oldroleid );
2007-07-28 09:23:32 +00:00
2006-10-02 08:49:07 +00:00
}
2006-09-28 09:15:14 +00:00
}
2007-03-09 02:39:44 +00:00
// likewise block overrides should always be restored like mods
2007-07-28 09:23:32 +00:00
if ( isset ( $instance -> roleoverrides )) {
2006-10-02 08:49:07 +00:00
foreach ( $instance -> roleoverrides as $oldroleid => $blockoverride ) {
restore_write_roleoverrides ( $restore , $blockoverride -> overrides , " block_instance " , CONTEXT_BLOCK , $instance -> id , $oldroleid );
}
2006-09-28 09:15:14 +00:00
}
}
}
2006-09-27 08:59:27 +00:00
}
2006-09-28 09:15:14 +00:00
/************************************************
* Restoring assignments from userid level *
* role assignments / overrides *
2007-07-28 09:23:32 +00:00
************************************************/
2006-10-02 08:49:07 +00:00
if ( ! defined ( 'RESTORE_SILENTLY' )) {
echo " <li> " . get_string ( " creatinguserroles " ) . '</li>' ;
}
2006-09-27 08:59:27 +00:00
$info = restore_read_xml_users ( $restore , $xmlfile );
2007-03-09 02:39:44 +00:00
if ( ! empty ( $info -> users ) && ! $isimport ) { // no need to restore user assignments for imports (same course)
2006-09-27 08:59:27 +00:00
//For each user, take its info from backup_ids
foreach ( $info -> users as $userid ) {
2006-09-28 09:15:14 +00:00
$rec = backup_getid ( $restore -> backup_unique_code , " user " , $userid );
2006-09-27 08:59:27 +00:00
if ( isset ( $rec -> info -> roleassignments )) {
foreach ( $rec -> info -> roleassignments as $oldroleid => $userassignment ) {
2007-07-28 09:23:32 +00:00
restore_write_roleassignments ( $restore , $userassignment -> assignments , " user " , CONTEXT_USER , $userid , $oldroleid );
2006-09-27 08:59:27 +00:00
}
}
2006-09-28 09:15:14 +00:00
if ( isset ( $rec -> info -> roleoverrides )) {
foreach ( $rec -> info -> roleoverrides as $oldroleid => $useroverride ) {
2007-07-28 09:23:32 +00:00
restore_write_roleoverrides ( $restore , $useroverride -> overrides , " user " , CONTEXT_USER , $userid , $oldroleid );
2006-09-28 09:15:14 +00:00
}
}
2006-09-27 08:59:27 +00:00
}
}
2007-07-28 09:23:32 +00:00
2006-10-10 03:17:49 +00:00
return true ;
2006-09-25 09:10:19 +00:00
}
2007-07-28 09:23:32 +00:00
2006-09-26 09:05:44 +00:00
// auxillary function to write role assignments read from xml to db
function restore_write_roleassignments ( $restore , $assignments , $table , $contextlevel , $oldid , $oldroleid ) {
2007-07-28 09:23:32 +00:00
2006-09-26 09:05:44 +00:00
$role = backup_getid ( $restore -> backup_unique_code , " role " , $oldroleid );
2007-07-28 09:23:32 +00:00
2006-09-26 09:05:44 +00:00
foreach ( $assignments as $assignment ) {
2006-09-28 09:15:14 +00:00
2006-09-26 09:05:44 +00:00
$olduser = backup_getid ( $restore -> backup_unique_code , " user " , $assignment -> userid );
2007-02-16 14:45:57 +00:00
//Oh dear, $olduser... can be an object, $obj->string or bool!
if ( ! $olduser || ( is_string ( $olduser -> info ) && $olduser -> info == " notincourse " )) { // it's possible that user is not in the course
2007-07-28 09:23:32 +00:00
continue ;
}
2006-09-26 09:05:44 +00:00
$assignment -> userid = $olduser -> new_id ; // new userid here
$oldmodifier = backup_getid ( $restore -> backup_unique_code , " user " , $assignment -> modifierid );
2006-10-31 22:46:41 +00:00
$assignment -> modifierid = ! empty ( $oldmodifier -> new_id ) ? $oldmodifier -> new_id : 0 ; // new modifier id here
2006-09-26 09:05:44 +00:00
$assignment -> roleid = $role -> new_id ; // restored new role id
2006-10-02 08:49:07 +00:00
// hack to make the correct contextid for course level imports
if ( $contextlevel == CONTEXT_COURSE ) {
$oldinstance -> new_id = $restore -> course_id ;
} else {
$oldinstance = backup_getid ( $restore -> backup_unique_code , $table , $oldid );
}
2006-09-26 09:05:44 +00:00
$newcontext = get_context_instance ( $contextlevel , $oldinstance -> new_id );
2006-09-28 09:15:14 +00:00
$assignment -> contextid = $newcontext -> id ; // new context id
2007-07-28 09:23:32 +00:00
// might already have same assignment
2007-07-19 03:37:53 +00:00
role_assign ( $assignment -> roleid , $assignment -> userid , 0 , $assignment -> contextid , $assignment -> timestart , $assignment -> timeend , $assignment -> hidden , $assignment -> enrol , $assignment -> timemodified );
2007-07-28 09:23:32 +00:00
}
2006-09-28 09:15:14 +00:00
}
2007-07-28 09:23:32 +00:00
2006-09-28 09:15:14 +00:00
// auxillary function to write role assignments read from xml to db
function restore_write_roleoverrides ( $restore , $overrides , $table , $contextlevel , $oldid , $oldroleid ) {
2007-07-28 09:23:32 +00:00
2006-09-28 09:15:14 +00:00
// it is possible to have an override not relevant to this course context.
// should be ignored(?)
if ( ! $role = backup_getid ( $restore -> backup_unique_code , " role " , $oldroleid )) {
return null ;
}
2007-07-28 09:23:32 +00:00
foreach ( $overrides as $override ) {
2006-09-28 09:15:14 +00:00
$override -> capability = $override -> name ;
$oldmodifier = backup_getid ( $restore -> backup_unique_code , " user " , $override -> modifierid );
$override -> modifierid = $oldmodifier -> new_id ? $oldmodifier -> new_id : 0 ; // new modifier id here
$override -> roleid = $role -> new_id ; // restored new role id
2007-07-28 09:23:32 +00:00
2006-10-02 08:49:07 +00:00
// hack to make the correct contextid for course level imports
if ( $contextlevel == CONTEXT_COURSE ) {
$oldinstance -> new_id = $restore -> course_id ;
} else {
$oldinstance = backup_getid ( $restore -> backup_unique_code , $table , $oldid );
}
2007-07-28 09:23:32 +00:00
2006-09-28 09:15:14 +00:00
$newcontext = get_context_instance ( $contextlevel , $oldinstance -> new_id );
2007-08-09 21:50:59 +00:00
$override -> contextid = $newcontext -> id ; // new context id
2007-08-02 08:28:29 +00:00
// use assign capability instead so we can add context to context_rel
assign_capability ( $override -> capability , $override -> permission , $override -> roleid , $override -> contextid );
2007-07-28 09:23:32 +00:00
}
2006-10-17 10:05:41 +00:00
}
//write activity date changes to the html log file, and update date values in the the xml array
2007-07-28 09:23:32 +00:00
function restore_log_date_changes ( $recordtype , & $restore , & $xml , $TAGS , $NAMETAG = 'NAME' ) {
2006-10-17 10:05:41 +00:00
2007-07-28 09:23:32 +00:00
global $CFG ;
$openlog = false ;
2006-10-17 10:05:41 +00:00
2007-07-28 09:23:32 +00:00
// loop through time fields in $TAGS
foreach ( $TAGS as $TAG ) {
2006-10-17 10:05:41 +00:00
2007-07-28 09:23:32 +00:00
// check $TAG has a sensible value
if ( ! empty ( $xml [ $TAG ][ 0 ][ '#' ]) && is_string ( $xml [ $TAG ][ 0 ][ '#' ]) && is_numeric ( $xml [ $TAG ][ 0 ][ '#' ])) {
if ( $openlog == false ) {
2006-10-17 10:05:41 +00:00
$openlog = true ; // only come through here once
2007-07-28 09:23:32 +00:00
// open file for writing
$course_dir = " $CFG->dataroot / $restore->course_id /backupdata " ;
check_dir_exists ( $course_dir , true );
2006-10-17 10:05:41 +00:00
$restorelog = fopen ( " $course_dir /restorelog.html " , " a " );
2007-07-28 09:23:32 +00:00
// start output for this record
$msg = new stdClass ();
$msg -> recordtype = $recordtype ;
$msg -> recordname = $xml [ $NAMETAG ][ 0 ][ '#' ];
fwrite ( $restorelog , get_string ( " backupdaterecordtype " , " moodle " , $msg ));
}
// write old date to $restorelog
$value = $xml [ $TAG ][ 0 ][ '#' ];
$date = usergetdate ( $value );
$msg = new stdClass ();
$msg -> TAG = $TAG ;
$msg -> weekday = $date [ 'weekday' ];
$msg -> mday = $date [ 'mday' ];
$msg -> month = $date [ 'month' ];
$msg -> year = $date [ 'year' ];
fwrite ( $restorelog , get_string ( " backupdateold " , " moodle " , $msg ));
// write new date to $restorelog
$value += $restore -> course_startdateoffset ;
$date = usergetdate ( $value );
$msg = new stdClass ();
$msg -> TAG = $TAG ;
$msg -> weekday = $date [ 'weekday' ];
$msg -> mday = $date [ 'mday' ];
$msg -> month = $date [ 'month' ];
$msg -> year = $date [ 'year' ];
fwrite ( $restorelog , get_string ( " backupdatenew " , " moodle " , $msg ));
// update $value in $xml tree for calling module
$xml [ $TAG ][ 0 ][ '#' ] = " $value " ;
}
2006-10-17 10:05:41 +00:00
}
// close the restore log, if it was opened
if ( $openlog ) {
2007-07-28 09:23:32 +00:00
fclose ( $restorelog );
2006-10-17 10:05:41 +00:00
}
}
2007-07-28 09:23:32 +00:00
?>